1jQuery.fn.sortElements = (function(){ 2 3 var sort = [].sort; 4 5 return function(comparator, getSortable) { 6 7 getSortable = getSortable || function(){return this;}; 8 9 var placements = this.map(function(){ 10 11 var sortElement = getSortable.call(this), 12 parentNode = sortElement.parentNode, 13 14 // Since the element itself will change position, we have 15 // to have some way of storing its original position in 16 // the DOM. The easiest way is to have a 'flag' node: 17 nextSibling = parentNode.insertBefore( 18 document.createTextNode(''), 19 sortElement.nextSibling 20 ); 21 22 return function() { 23 24 if (parentNode === this) { 25 throw new Error( 26 "You can't sort elements if any one is a descendant of another." 27 ); 28 } 29 30 // Insert before flag: 31 parentNode.insertBefore(this, nextSibling); 32 // Remove flag: 33 parentNode.removeChild(nextSibling); 34 35 }; 36 37 }); 38 39 return sort.call(this, comparator).each(function(i){ 40 placements[i].call(getSortable.call(this)); 41 }); 42 43 }; 44 45})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.