1(function($) { 2 $.fn.removeClassStartingWith = function (filter) { 3 $(this).removeClass(function (index, className) { 4 return (className.match(new RegExp("\\S*" + filter + "\\S*", 'g')) || []).join(' ') 5 }); 6 return this; 7 }; 8 9 function orderGrid(container) { 10 breakpoint = window.getComputedStyle(document.querySelector('body'), ':after').getPropertyValue('content') 11 12 //nothing to do if no breakpoint change 13 if(breakpoint == $(container).data('breakpoint')) { 14 return 15 } 16 nbRows = buildMatrix(container) 17 gridW = $(container).width() 18 singleW = $('.card.single', container).first().outerWidth() 19 doubleW = $('.card.double', container).first().outerWidth() 20 updated = false 21 for (var rank = 1; rank < nbRows; rank++) { 22 rowW = 0; 23 $('.card[data-row="' + rank + '"]', container).each(function() { 24 rowW += $(this).outerWidth() 25 }) 26 space = gridW - rowW 27 // console.log(rank + ': ' + space) 28 if(space) { //found empty space 29 nextCard = false 30 //find next 'single' card available 31 for (var i = rank + 1; i <= nbRows; i++) { 32 if(space >= doubleW) { 33 nextCard = $('.double[data-row="' + i + '"]', container).first() 34 } else { 35 nextCard = $('.single[data-row="' + i + '"]', container).first() 36 } 37 // console.log(nextCard.length) 38 if(nextCard.length) { 39 break 40 } 41 } 42 if(nextCard.length) { 43 //move it to current row 44 // console.log('move to rank ' + rank) 45 $('.card[data-row="' + rank + '"]', container).last().after(nextCard) 46 updated = true 47 buildMatrix(container) 48 } 49 } 50 if(updated) { 51 break 52 } 53 } 54 55 if(updated) { 56 setTimeout(function(){ 57 orderGrid(container) 58 }, 3000) 59 } else { 60 $(container).data('breakpoint', breakpoint) 61 } 62 } 63 64 function buildMatrix(container) { 65 var lines = [] 66 var line = [] 67 var cards = $('.card', container) 68 row = 1; 69 nbRows = 0; 70 for (var d = 0; d < cards.length; d++) { 71 72 var element = cards[d]; 73 var previous = cards[d-1]; 74 75 if(d == 0) { 76 $(element).attr('data-row', row); 77 } else { 78 if ($(element).position().top != $(previous).position().top) { 79 row ++ 80 } 81 $(element).attr('data-row', row); 82 } 83 nbRows = row; 84 } 85 return nbRows 86 } 87 88 $(document).ready(function() { 89 $('.gridlist').each(function() { 90 orderGrid(this); 91 }) 92 }); 93 94 $(window).resize(function() { 95 $('.gridlist').each(function() { 96 orderGrid(this); 97 }) 98 }); 99 100 101})(jQuery);
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.