1/* 2 jQuery flexImages v1.0.4 3 Copyright (c) 2014 Simon Steinberger / Pixabay 4 GitHub: https://github.com/Pixabay/jQuery-flexImages 5 License: http://www.opensource.org/licenses/mit-license.php 6*/ 7 8(function ($) { 9 $.fn.flexImages = function (options) { 10 var o = $.extend({container: '.item', object: 'img', rowHeight: 180, maxRows: 0, truncate: 0}, options); 11 return this.each(function () { 12 var grid = $(this), containers = $(grid).find(o.container), items = [], t = new Date().getTime(), 13 s = window.getComputedStyle ? getComputedStyle(containers[0], null) : containers[0].currentStyle; 14 o.margin = (parseInt(s.marginLeft) || 0) + (parseInt(s.marginRight) || 0) + (Math.round(parseFloat(s.borderLeftWidth)) || 0) + (Math.round(parseFloat(s.borderRightWidth)) || 0); 15 for (j = 0; j < containers.length; j++) { 16 var c = containers[j], 17 w = parseInt(c.getAttribute('data-w')), 18 norm_w = w * (o.rowHeight / parseInt(c.getAttribute('data-h'))), // normalized width 19 obj = $(c).find(o.object); 20 items.push([c, w, norm_w, obj, obj.data('src')]); 21 } 22 makeGrid(grid, items, o); 23 $(window).off('resize.flexImages' + grid.data('flex-t')); 24 $(window).on('resize.flexImages' + t, function () { 25 makeGrid(grid, items, o); 26 }); 27 grid.data('flex-t', t) 28 }); 29 } 30 31 function makeGrid(grid, items, o, noresize) { 32 var x, new_w, ratio = 1, rows = 1, max_w = grid.width() - 2, row = [], row_width = 0, row_h = o.rowHeight; 33 if (!max_w) max_w = grid.width() - 2; // IE < 8 bug 34 35 // define inside makeGrid to access variables in scope 36 function _helper(lastRow) { 37 if (o.maxRows && rows > o.maxRows || o.truncate && lastRow && rows > 1) row[x][0].style.display = 'none'; 38 else { 39 if (row[x][4]) { 40 row[x][3].attr('src', row[x][4]); 41 row[x][4] = ''; 42 } 43 row[x][0].style.width = new_w + 'px'; 44 row[x][0].style.height = row_h + 'px'; 45 row[x][0].style.display = 'block'; 46 } 47 } 48 49 for (i = 0; i < items.length; i++) { 50 row.push(items[i]); 51 row_width += items[i][2] + o.margin; 52 if (row_width >= max_w) { 53 var margins_in_row = row.length * o.margin; 54 ratio = (max_w - margins_in_row) / (row_width - margins_in_row), row_h = Math.ceil(o.rowHeight * ratio), exact_w = 0, new_w; 55 for (x = 0; x < row.length; x++) { 56 new_w = Math.ceil(row[x][2] * ratio); 57 exact_w += new_w + o.margin; 58 if (exact_w > max_w) new_w -= exact_w - max_w; 59 _helper(); 60 } 61 // reset for next row 62 row = [], row_width = 0; 63 rows++; 64 } 65 } 66 // layout last row - match height of last row to previous row 67 for (x = 0; x < row.length; x++) { 68 new_w = Math.floor(row[x][2] * ratio), h = Math.floor(o.rowHeight * ratio); 69 _helper(true); 70 } 71 72 // scroll bars added or removed during rendering new layout? 73 if (!noresize && max_w != grid.width()) makeGrid(grid, items, o, true); 74 } 75}(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.