Skip to content

Instantly share code, notes, and snippets.

@fgrehm

fgrehm/gist:4251894

Created Dec 10, 2012
Embed
What would you like to do?
Inserts a new element in order
$.fn.insertInOrder = (newElement, iterator) ->
$container = $(this)
$siblings = $container.children()
$newElement = $(newElement)
if $siblings.length == 0
$container.append($newElement)
return this
index = _.sortedIndex $siblings, newElement, iterator
if index == $siblings.length
$container.append $newElement
else
$($siblings[index]).before($newElement)
this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.