Created
August 9, 2009 12:19
-
-
Save RStankov/164751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* $(element).insert({ into: document.body }); | |
*/ | |
Element._insertionTranslations.into = function(element, node){ | |
node.appendChild(element); | |
}; | |
/* | |
* $(element).insert({ instead: element2 }) | |
*/ | |
Element._insertionTranslations.insert = function(element, node){ | |
node.parentNode.replaceChild(element, node); | |
}; | |
/* | |
* $(list).insert([item, item, item, item, item]); | |
*/ | |
Element.addMethods({ | |
insert: Element.insert.wrap(function(insert, element, insertation){ | |
if (!Object.isArray(insertation)) return insert(element, insertation); | |
element = $(element); | |
insertation.each(insert.curry(element)); | |
return element; | |
}) | |
}); | |
/* | |
* - using arguments | |
* $(list).insert(item, item, item, item, item); | |
*/ | |
Element.addMethods({ | |
insert: Element.insert.wrap(function(insert, element, insertation){ | |
if (arguments.length < 4) return insert(element, insertation); | |
element = $(element); | |
Array.prototype.slice.call(arguments, 2).each(insert.curry(element)); | |
return element; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment