Skip to content

Add arrays and variable argument length to Element.insert. #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/prototype/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@
}

/**
* Element.insert(@element, content) -> Element
* Element.insert(@element, content [, content, ...]) -> Element
* - content (String | Element | Object): The content to insert.
*
* Inserts content `above`, `below`, at the `top`, and/or at the `bottom` of
Expand All @@ -901,6 +901,7 @@
* - ...any object with a `toElement` method: The method is called and the resulting element used
* - ...any object with a `toHTML` method: The method is called and the resulting HTML string
* is parsed and rendered
* - ...an array with any of the above as alements or an array
*
* The `content` argument can be the content to insert, in which case the
* implied insertion point is `bottom`, or an object that specifies one or
Expand Down Expand Up @@ -935,13 +936,24 @@
**/
function insert(element, insertions) {
element = $(element);

if (isContent(insertions))

if ( arguments.length > 2 ) {
insertions = Array.prototype.slice.call( arguments, 1 );
}

if ( Object.isArray( insertions ) ) {
for( var i = 0; i < insertions.length; ++i ) {
insert( element, insertions[i] );
}
return element;
}

if ( isContent(insertions) )
insertions = { bottom: insertions };

for (var position in insertions)
insertContentAt(element, insertions[position], position);

return element;
}

Expand Down Expand Up @@ -3478,4 +3490,4 @@
if (window.attachEvent)
window.attachEvent('onunload', destroyCache_IE);

})(this);
})(this);