Assuming I have a collection with a bunch of well ordered elements, what’s the common method to insert another new child at it’s abstract order-position?
Using a dom library $(new).eq($(new).data('orderPosition')); doesn’t work, because it’s not a valid index.
// Add this element to it's logic position in the collection:
<div data-order-position="10"></div>
// The collection
<div id="myCollection">
<div data-order-position="4"></div>
<div data-order-position="67"></div>
<div data-order-position="81"></div>
<div data-order-position="82"></div>
<div data-order-position="761"></div>
</div>
My real collection contains about ~400 elements.
I think that working with an array of integers is probably the most efficient method. You can maintain a constant list of the sorted elements in an array somewhere (and even continue to sort as needed):
http://jsfiddle.net/ExplosionPIlls/ULEFX/