-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Description
This adds in a small modifier to pick up elementSiblings.
It's been great for picking up single tags at the same level like <input>
and <img>
. Putting some of the scripting outside of a tag like <td>
is nice for for searching a table without creating a text node.
me(selector=null, start=document, warning=true) {
if (selector == null) return $.sugar(start.currentScript.parentElement) // Just local me() in <script>
if (selector instanceof Event) return selector.currentTarget ? $.me(selector.currentTarget) : (console.warn(`Surreal: Event currentTarget is null. Please save your element because async will lose it`), null) // Events try currentTarget
// Goofy mod here.
if (typeof selector == 'string') {
if (selector === '<') return $.sugar(start.currentScript.previousElementSibling)
if (selector === '>') return $.sugar(start.currentScript.nextElementSibling)
if (isSelector(selector, start, warning)) return $.sugar(start.querySelector(selector)) // String selector.
}
if ($.isNodeList(selector)) return $.me(selector[0]) // If we got a list, just take the first element.
if ($.isNode(selector)) return $.sugar(selector) // Valid element.
return null // Invalid.
},
Is it possible to use the sugar system for this?
Metadata
Metadata
Assignees
Labels
No labels