Skip to content

Can this mod be made into a sugar? #14

@figuerom16

Description

@figuerom16

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions