1/** 2* @package BaGrid 3* @author Balbooa http://www.balbooa.com/ 4* @copyright Copyright @ Balbooa 5* @license http://www.gnu.org/licenses/gpl.html GNU/GPL 6*/ 7 8!function ($) { 9 10 var ba_isotope = function (element, options) { 11 this.parent = $(element); 12 this.options = options; 13 this.total = new Array(); 14 this.empty = new Array(); 15 }; 16 17 ba_isotope.prototype = { 18 init : function(){ 19 var parent = this.parent, 20 selector = this.options.selector, 21 filter = this.options.filter, 22 count = this.options.count * 1, 23 mode = this.options.mode, 24 offsetX = 0, 25 parWidth = parent.width(), 26 margin = this.options.margin * 1, 27 winSize = $(window).width(), 28 offsetY = 0, 29 n; 30 if (filter) { 31 selector = filter; 32 } 33 n = count; 34 parent.children().not(selector).hide(); 35 var childrens = parent.find(selector); 36 if (mode == 'justified') { 37 var flag = true, 38 start = 0, 39 rowWidth = 0, 40 ratio = 1, 41 lastHeight = 250; 42 while (flag) { 43 var r = 0 44 for (var i = start; i < n; i++) { 45 if (childrens[i]) { 46 var height = $(childrens[i]).find('img').attr('data-height'), 47 width = $(childrens[i]).find('img').attr('data-width'); 48 ratio = width / height; 49 width = ratio * 50; 50 rowWidth += width * 1; 51 r++ 52 } 53 } 54 if (rowWidth != parWidth) { 55 ratio = (parWidth - r * margin + margin) / rowWidth; 56 } 57 for (var i = start; i < n; i++) { 58 if (childrens[i]) { 59 var width = $(childrens[i]).find('img').attr('data-width'), 60 height = $(childrens[i]).find('img').attr('data-height'); 61 var r = width / height; 62 height = ratio * 50; 63 if (n > childrens.length && height > lastHeight) { 64 height = lastHeight; 65 } 66 width = height * r; 67 $(childrens[i]).css({ 68 'width' : width, 69 'height' : height, 70 'left' : offsetX, 71 'position' : 'absolute', 72 'display' : 'block', 73 'top' : offsetY 74 }); 75 lastHeight = height; 76 offsetX += width + margin; 77 } else { 78 flag = false; 79 } 80 } 81 if (childrens[start]) { 82 offsetY += $(childrens[start]).height() * 1 + margin * 1; 83 start = n; 84 n += count * 1; 85 offsetX = 0; 86 rowWidth = 0; 87 } 88 } 89 } else if (mode == 'random') { 90 var array = {}; 91 childrens.each(function(){ 92 var $t = $(this); 93 if (offsetX + $t.width() > parWidth) { 94 offsetX = 0; 95 } 96 if (!array[offsetX]) { 97 array[offsetX] = 0; 98 } 99 offsetY = array[offsetX]; 100 $t.css({ 101 'left' : offsetX, 102 'position' : 'absolute', 103 'display' : 'block', 104 'top' : offsetY 105 }); 106 array[offsetX] += $t.height() + margin; 107 offsetX += $t.width() + margin; 108 }); 109 } else if (winSize <= 480) { 110 var array = {}; 111 childrens.each(function(){ 112 if (offsetX + $(this).width() > parWidth) { 113 offsetX = 0; 114 } 115 for (key in array) { 116 if (array[key][offsetX]) { 117 offsetY = array[key][offsetX].y + array[key][offsetX].h; 118 } 119 } 120 $(this).css({ 121 'left' : offsetX, 122 'position' : 'absolute', 123 'display' : 'block', 124 'top' : offsetY 125 }); 126 if (!array[offsetY]) { 127 array[offsetY] = {} 128 } 129 array[offsetY][offsetX] = { 130 h : $(this).height() + margin, 131 y : offsetY 132 } 133 offsetX += $(this).width() + margin; 134 }); 135 } else { 136 var width = Math.floor((parWidth - (margin * (n - 1))) / n), 137 imgC = childrens.length, 138 imgW2 = parent.find(selector+'.width2').not('.height2').length, 139 imgH2 = parent.find(selector+'.height2').not('.width2').length, 140 imgW2H2 = parent.find(selector+'.height2.width2').length; 141 imgC += imgW2 * 2 + imgH2 * 2 * n + imgW2H2 * 4 * n; 142 for (var i = 0; i < imgC; i++) { 143 if (offsetX + width > parWidth) { 144 offsetX = 0; 145 offsetY += width + margin 146 } 147 this.total.push(offsetX+':'+offsetY) 148 offsetX += width + margin; 149 } 150 var $this = this; 151 childrens.each(function(){ 152 var type = ''; 153 if ($(this).hasClass('width2') && !$(this).hasClass('height2')) { 154 type = 'w2'; 155 } else if ($(this).hasClass('width2') && $(this).hasClass('height2')) { 156 type = 'w2h2'; 157 } else if (!$(this).hasClass('width2') && $(this).hasClass('height2')) { 158 type = 'h2'; 159 } 160 var obj = $this.checkEmpty(type, width * 2 + margin, parWidth); 161 offsetY = obj[1]; 162 $(this).css({ 163 'top' : obj[1]+'px', 164 'left' : obj[0]+'px', 165 'position' : 'absolute', 166 'display' : 'block' 167 }); 168 }); 169 } 170 setTimeout(function(){ 171 parent.trigger('show_isotope'); 172 }, 1); 173 setTimeout(function(){ 174 $(window).trigger('scroll'); 175 }, 100); 176 var max = offsetY; 177 childrens.each(function(){ 178 var top = this.style.top.replace('px', '') * 1 179 top += $(this).height() + margin; 180 if (top > max) { 181 max = top; 182 } 183 }); 184 parent.css({ 185 'position' : 'relative', 186 'height' : max 187 }); 188 }, 189 checkEmpty : function(type, width, row){ 190 var el; 191 for (var key in this.total) { 192 key *= 1; 193 el = this.total[key].split(':') 194 break; 195 } 196 delete this.total[key]; 197 if (type == 'w2') { 198 if (el[0] * 1 + width > row || !this.total[key + 1]) { 199 this.empty[key] = el[0]+':'+el[1]; 200 el = this.checkEmpty(type, width, row); 201 } else { 202 delete this.total[key + 1]; 203 for (var i in this.empty) { 204 this.total[i] = this.empty[i]; 205 } 206 this.empty = new Array(); 207 } 208 } else if (type == 'h2') { 209 if (!this.total[key + this.options.count * 1]) { 210 this.empty[key] = el[0]+':'+el[1]; 211 el = this.checkEmpty(type, width, row); 212 } else { 213 delete this.total[key + this.options.count * 1]; 214 for (var i in this.empty) { 215 this.total[i] = this.empty[i]; 216 } 217 this.empty = new Array(); 218 } 219 } else if (type == 'w2h2') { 220 if (el[0] * 1 + width > row || !this.total[key + 1] || 221 !this.total[key + this.options.count * 1] || !this.total[key + 1 + this.options.count * 1]) { 222 this.empty[key] = el[0]+':'+el[1]; 223 el = this.checkEmpty(type, width, row); 224 } else { 225 delete this.total[key + 1]; 226 delete this.total[key + this.options.count * 1]; 227 delete this.total[key + 1 + this.options.count * 1]; 228 for (var i in this.empty) { 229 this.total[i] = this.empty[i]; 230 } 231 this.empty = new Array(); 232 } 233 } 234 return el; 235 }, 236 shuffle : function(){ 237 var childrens = this.parent.children().not('input'), 238 n = childrens.length, 239 parent = this.parent; 240 var i, j, temp; 241 for (i = n - 1; i > 0; i--) { 242 j = Math.floor(Math.random() * (i + 1)); 243 temp = childrens[i]; 244 childrens[i] = childrens[j]; 245 childrens[j] = temp; 246 } 247 childrens.each( function () { 248 $(this).appendTo(parent); 249 }); 250 } 251 } 252 253 $.fn.ba_isotope = function (option) { 254 return this.each(function () { 255 var $this = $(this), 256 data = $this.data('ba_isotope'), 257 options = $.extend({}, $.fn.ba_isotope.defaults, typeof option == 'object' && option); 258 if (typeof(option) == 'object') { 259 $this.data('ba_isotope', (data = new ba_isotope(this, options))); 260 data.init(); 261 } else { 262 $this.data('ba_isotope', (data = new ba_isotope(this, $.fn.ba_isotope.defaults))); 263 data[option](); 264 } 265 }); 266 } 267 268 $.fn.ba_isotope.defaults = { 269 selector : '> div', 270 filter : '', 271 margin : 10, 272 count : 4, 273 mode : 'grid' 274 } 275 276}(window.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.