1(function(jQuery) { 2 var $; 3 if (!jQuery) { 4 alert("Message from UberGrid: jQuery not found!"); 5 } else if (parseInt(jQuery().jquery.replace(/\./g, "")) < 172) { 6 alert("Message from UberGrid You have jQuery < 1.7.2. Please upgrade your jQuery or enable \"Force new jQuery version\" option at UberGrid settings page."); 7 } else { 8 if (!Packery) { 9 alert("Message from UberGrid: Packery library is not loaded. Please contact UberGrid developer for help."); 10 } else { 11 $ = jQuery; 12 var LightboxAdapter, 13 bind = function(fn, me) { 14 return function() { 15 return fn.apply(me, arguments); 16 }; 17 }; 18 19LightboxAdapter = (function() { 20 function LightboxAdapter(grid, $el) { 21 this.onPrevSlide = bind(this.onPrevSlide, this); 22 this.onNextSlide = bind(this.onNextSlide, this); 23 this.onAfterClose = bind(this.onAfterClose, this); 24 this.onKeyUp = bind(this.onKeyUp, this); 25 this.onDeeplinkOpened = bind(this.onDeeplinkOpened, this); 26 this.setHash = bind(this.setHash, this);
27 this.getSlug = bind(this.getSlug, this); 28 this.getId = bind(this.getId, this); 29 this.getLightboxImageHeight = bind(this.getLightboxImageHeight, this); 30 this.getLightboxImageWidth = bind(this.getLightboxImageWidth, this); 31 this.getLightboxImageTitle = bind(this.getLightboxImageTitle, this); 32 this.getLightboxImageCaption = bind(this.getLightboxImageCaption, this); 33 this.getLightboxImageThumbnailUrl = bind(this.getLightboxImageThumbnailUrl, this); 34 this.getLightboxImageUrl = bind(this.getLightboxImageUrl, this); 35 this.onImageClicked = bind(this.onImageClicked, this); 36 this.getLightboxLinks = bind(this.getLightboxLinks, this); 37 this.getLightboxImages = bind(this.getLightboxImages, this); 38 this.reset = bind(this.reset, this); 39 this.addImages = bind(this.addImages, this); 40 this.clickImage = bind(this.clickImage, this); 41 this.loadDeepLink = bind(this.loadDeepLink, this); 42 this.checkForDeeplink = bind(this.checkForDeeplink, this); 43 this.grid = grid; 44 this.$el = $el; 45 this.reset(); 46 this.checkForDeeplink(); 47 } 48 49 LightboxAdapter.prototype.checkForDeeplink = function() { 50 var gridId, image; 51 if (location.hash.match(/^#\d+\-/)) { 52 gridId = location.hash.replace(/^#/, '').replace(/[^\d]+.*$/, ''); 53 if (gridId !== this.getId()) { 54 return; 55 } 56 image = location.hash.replace(/^.*\//, ''); 57 this.loadDeepLink(image); 58 return delete this.prevHash; 59 } 60 }; 61 62 LightboxAdapter.prototype.loadDeepLink = function(image) { 63 return this.clickImage(image); 64 }; 65 66 LightboxAdapter.prototype.clickImage = function(image) { 67 var cell, i, len, ref; 68 ref = this.getLightboxLinks().closest('.uber-grid-cell'); 69 for (i = 0, len = ref.length; i < len; i++) { 70 cell = ref[i]; 71 if (jQuery(cell).attr('data-slug') === image) { 72 jQuery(cell).find('a.uber-grid-lightbox').click(); 73 return; 74 } 75 } 76 }; 77 78 LightboxAdapter.prototype.addImages = function(images) {}; 79 80 LightboxAdapter.prototype.reset = function() { 81 this.getLightboxLinks().off('click'); 82 return this.getLightboxLinks().on('click', this.onImageClicked); 83 }; 84 85 LightboxAdapter.prototype.imageSelector = '.uber-grid-cell:has(a.uber-grid-cell-wrapper.uber-grid-lightbox), .uber-grid-cell:has(a.uber-grid-hover.uber-grid-lightbox)'; 86 87 LightboxAdapter.prototype.linkSelector = '.uber-grid-cell a.uber-grid-cell-wrapper.uber-grid-lightbox, .uber-grid-cell a.uber-grid-hover.uber-grid-lightbox'; 88 89 LightboxAdapter.prototype.getLightboxImages = function() { 90 return this.$el.find(this.imageSelector); 91 }; 92 93 LightboxAdapter.prototype.getLightboxLinks = function() { 94 return this.$el.find(this.linkSelector); 95 }; 96 97 LightboxAdapter.prototype.onImageClicked = function(event) { 98 var cell; 99 event.stopPropagation(); 100 event.preventDefault(); 101 cell = jQuery(event.target).closest('.uber-grid-cell'); 102 this.scrollTop = jQuery(document).scrollTop(); 103 return this.setHash(cell); 104 }; 105 106 LightboxAdapter.prototype.getLightboxImageUrl = function(el) { 107 return jQuery(el).find('a.uber-grid-cell-wrapper, a.uber-grid-hover').attr('href'); 108 }; 109 110 LightboxAdapter.prototype.getLightboxImageThumbnailUrl = function(el) { 111 return jQuery(el).find('img.uber-grid-cell-image').attr('src'); 112 }; 113 114 LightboxAdapter.prototype.getLightboxImageCaption = function(el) { 115 return jQuery(el).find('.uber-grid-lightbox-content div').html(); 116 }; 117 118 LightboxAdapter.prototype.getLightboxImageTitle = function(el) { 119 return jQuery(el).find('.uber-grid-lightbox-content h3').html(); 120 }; 121 122 LightboxAdapter.prototype.getLightboxImageWidth = function(el) { 123 return jQuery(el).find('img.uber-grid-image').data('lightbox-width'); 124 }; 125 126 LightboxAdapter.prototype.getLightboxImageHeight = function(el) { 127 return jQuery(el).find('img.uber-grid-image').data('lightbox-width'); 128 }; 129 130 LightboxAdapter.prototype.getId = function() { 131 return this.$el.attr('id').replace('uber-grid-', ''); 132 }; 133 134 LightboxAdapter.prototype.getSlug = function() { 135 return this.$el.closest('.uber-grid-wrapper').attr('data-slug'); 136 }; 137 138 LightboxAdapter.prototype.setHash = function(cell) { 139 var id, slug;
140 slug = cell.attr('data-slug'); 141 id = this.getId(); 142 this.prevHash = location.hash; 143 return location.hash = id + "-" + (this.getSlug()) + "/" + slug; 144 }; 145 146 LightboxAdapter.prototype.resetHash = function() { 147 if (this.prevHash) { 148 location.hash = this.prevHash; 149 delete this.prevHash; 150 } else { 151 location.hash = '#'; 152 } 153 if (this.scrollTop && this.scrollTop > 0) { 154 return jQuery(document).scrollTop(this.scrollTop); 155 } 156 }; 157 158 LightboxAdapter.prototype.onDeeplinkOpened = function() {}; 159 160 LightboxAdapter.prototype.onKeyUp = function(event) { 161 if (event.keyCode === 37) { 162 return this.onPrevSlide(); 163 } else if (event.keyCode === 39) { 164 return this.onNextSlide(); 165 } else if (event.keyCode === 27) { 166 return this.onAfterClose(); 167 } 168 }; 169 170 LightboxAdapter.prototype.onAfterClose = function() { 171 jQuery(window).off('keyup', this.onKeyup); 172 return this.resetHash(); 173 }; 174 175 LightboxAdapter.prototype.onNextSlide = function() { 176 var lightboxLinks; 177 this.currentIndex += 1; 178 lightboxLinks = this.getLightboxLinks(); 179 if (this.currentIndex === lightboxLinks.length) { 180 this.currentIndex = lightboxLinks.length - 1; 181 } 182 return this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 183 }; 184 185 LightboxAdapter.prototype.onPrevSlide = function() { 186 this.currentIndex -= 1; 187 if (this.currentIndex < 0) { 188 this.currentIndex = 0; 189 } 190 return this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 191 }; 192 193 return LightboxAdapter; 194 195})(); 196 197var FooBoxAdapter, 198 bind = function(fn, me) { 199 return function() { 200 return fn.apply(me, arguments); 201 }; 202 }, 203 extend = function(child, parent) { 204 for (var key in parent) { 205 if (hasProp.call(parent, key)) child[key] = parent[key]; 206 } 207 208 function ctor() { 209 this.constructor = child; 210 } 211 ctor.prototype = parent.prototype; 212 child.prototype = new ctor(); 213 child.__super__ = parent.prototype; 214 return child; 215 }, 216 hasProp = {}.hasOwnProperty; 217 218FooBoxAdapter = (function(superClass) { 219 extend(FooBoxAdapter, superClass); 220 221 function FooBoxAdapter(grid, $el) { 222 this.reset = bind(this.reset, this); 223 if (!$el.foobox) { 224 alert("Foobox is not detected!"); 225 return; 226 } 227 FooBoxAdapter.__super__.constructor.call(this, grid, $el); 228 this.reset(); 229 } 230 231 FooBoxAdapter.prototype.reset = function() { 232 var fooboxOptions, i, image, images, len, ref; 233 FooBoxAdapter.__super__.reset.call(this); 234 ref = images = this.getLightboxImages(); 235 for (i = 0, len = ref.length; i < len; i++) { 236 image = ref[i]; 237 image = jQuery(image); 238 image.find('.uber-grid-hover').data({ 239 width: this.getLightboxImageWidth(image), 240 height: this.getLightboxImageHeight(image) 241 }); 242 image.attr('title', this.getLightboxImageCaption(image)); 243 image.find('img').attr('alt', this.getLightboxImageTitle(image)); 244 } 245 fooboxOptions = { 246 selector: this.imageSelector 247 }; 248 if (window.FOOBOX.o) { 249 fooboxOptions = jQuery.extend(window.FOOBOX.o, { 250 deeplinking: false, 251 affiliate: false, 252 slideshow: { 253 enabled: true 254 }, 255 selector: this.linkSelector 256 }); 257 } 258 return this.$el.foobox(fooboxOptions).on('foobox.afterLoad', (function(_this) { 259 return function(event) { 260 return _this.setHash(images.eq(event.fb.item.index).closest('.uber-grid-cell')); 261 }; 262 })(this)).on('foobox.close', (function(_this) { 263 return function() { 264 return _this.resetHash(); 265 }; 266 })(this)); 267 }; 268 269 return FooBoxAdapter; 270 271})(LightboxAdapter); 272 273var iLightboxAdapter, 274 bind = function(fn, me) { 275 return function() { 276 return fn.apply(me, arguments); 277 }; 278 }, 279 extend = function(child, parent) { 280 for (var key in parent) { 281 if (hasProp.call(parent, key)) child[key] = parent[key]; 282 } 283 284 function ctor() { 285 this.constructor = child; 286 } 287 ctor.prototype = parent.prototype; 288 child.prototype = new ctor(); 289 child.__super__ = parent.prototype; 290 return child; 291 }, 292 hasProp = {}.hasOwnProperty; 293 294iLightboxAdapter = (function(superClass) { 295 extend(iLightboxAdapter, superClass); 296 297 function iLightboxAdapter(grid, $el, lightboxOptions) { 298 this.onImageClicked = bind(this.onImageClicked, this); 299 if (!jQuery.iLightBox) { 300 alert('iLightbox not detected. Please install end enable iLightbox plugin.'); 301 } 302 iLightboxAdapter.__super__.constructor.call(this, grid, $el); 303 this.options = lightboxOptions; 304 } 305 306 iLightboxAdapter.prototype.onImageClicked = function(event) { 307 var elements, index, lightboxImages, options; 308 iLightboxAdapter.__super__.onImageClicked.call(this, event); 309 event.preventDefault(); 310 elements = this.getLightboxImages(); 311 lightboxImages = jQuery.map(elements, (function(_this) { 312 return function(el) { 313 return { 314 title: _this.getLightboxImageTitle(el), 315 url: _this.getLightboxImageUrl(el), 316 caption: _this.getLightboxImageCaption(el), 317 thumbnail: _this.getLightboxImageThumbnailUrl(el) 318 }; 319 }; 320 })(this)); 321 this.currentIndex = index = elements.index(jQuery(event.target).closest('.uber-grid-cell')); 322 options = jQuery.extend(this.options, ILIGHTBOX.options && eval("(" + rawurldecode(ILIGHTBOX.options) + ")") || {}); 323 return jQuery.iLightBox(lightboxImages, jQuery.extend({ 324 startFrom: index, 325 callback: { 326 onAfterChange: (function(_this) { 327 return function(instance) { 328 _this.currentIndex = instance.currentItem; 329 return _this.setHash(elements.eq(_this.currentIndex).closest('.uber-grid-cell')); 330 }; 331 })(this), 332 onHide: (function(_this) { 333 return function() { 334 return _this.resetHash(); 335 }; 336 })(this) 337 } 338 }, options)); 339 }; 340 341 return iLightboxAdapter; 342 343})(LightboxAdapter); 344 345var JetpackAdapter, 346 bind = function(fn, me) { 347 return function() { 348 return fn.apply(me, arguments); 349 }; 350 }, 351 extend = function(child, parent) { 352 for (var key in parent) { 353 if (hasProp.call(parent, key)) child[key] = parent[key]; 354 } 355 356 function ctor() { 357 this.constructor = child; 358 } 359 ctor.prototype = parent.prototype; 360 child.prototype = new ctor(); 361 child.__super__ = parent.prototype; 362 return child; 363 }, 364 hasProp = {}.hasOwnProperty; 365 366JetpackAdapter = (function(superClass) { 367 extend(JetpackAdapter, superClass); 368 369 function JetpackAdapter(grid, $el) { 370 this.onPrevSlide = bind(this.onPrevSlide, this); 371 this.onNextSlide = bind(this.onNextSlide, this); 372 this.onAfterClose = bind(this.onAfterClose, this); 373 this.setHashFromCurrentIndex = bind(this.setHashFromCurrentIndex, this); 374 this.onImageClicked = bind(this.onImageClicked, this); 375 this.reset = bind(this.reset, this); 376 JetpackAdapter.__super__.constructor.call(this, grid, $el); 377 this.$el.data('carousel-extra', { 378 blog_id: 1, 379 permalink: 'http://awesome-gallery.dev' 380 }); 381 } 382 383 JetpackAdapter.prototype.reset = function() { 384 var i, image, image_id, img, len, link, ref, results; 385 JetpackAdapter.__super__.reset.apply(this, arguments); 386 ref = this.getLightboxImages().addClass('tiled-gallery-item'); 387 results = []; 388 for (i = 0, len = ref.length; i < len; i++) { 389 image = ref[i]; 390 image = jQuery(image); 391 img = image.find('img.uber-grid-cell-image'); 392 link = image.closest('.uber-grid-cell').find('a.uber-grid-hover, a.uber-grid-cell-content, a.uber-grid-lightbox'); 393 image_id = link.data('lightbox-image-id'); 394 results.push(img.data({ 395 'orig-file': link.attr('href'), 396 'orig-size': img.data('lightbox-width') + "," + img.data('lightbox-height'), 397 'large-file': link.attr('href'), 398 'medium-file': link.attr('href'), 399 'small-file': link.attr('href'), 400 'image-title': image.find('.uber-grid-lightbox-content h3').html(), 401 'image-description': image.find('.uber-grid-lightbox-content div').html(), 402 'image-meta': {}, 403 'attachment-id': image_id ? image_id : 'asg-hack', 404 'comments-opened': image_id ? 1 : null 405 })); 406 } 407 return results; 408 }; 409 410 JetpackAdapter.prototype.onImageClicked = function(event) { 411 JetpackAdapter.__super__.onImageClicked.call(this, event); 412 event.preventDefault(); 413 this.currentIndex = this.getLightboxImages().index(jQuery(event.target).closest('.uber-grid-cell')); 414 if (this.$el.jp_carousel) { 415 this.$el.jp_carousel({ 416 start_index: this.currentIndex, 417 'items_selector': ".tiled-gallery-item img.uber-grid-cell-image" 418 }); 419 return setTimeout(this.setHashFromCurrentIndex, 400); 420 } else { 421 return jQuery(document).ready((function(_this) { 422 return function() { 423 return setTimeout((function() { 424 return _this.$el.jp_carousel({ 425 start_index: _this.currentIndex, 426 'items_selector': ".tiled-gallery-item img.uber-grid-cell-image" 427 }); 428 }), setTimeout(_this.setHashFromCurrentIndex, 600), 500); 429 }; 430 })(this)); 431 } 432 }; 433 434 JetpackAdapter.prototype.setHashFromCurrentIndex = function() { 435 this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 436 jQuery(document).on('click', '.jp-carousel-next-button', this.onNextSlide); 437 jQuery(document).on('click', '.jp-carousel-previous-button', this.onPrevSlide); 438 jQuery(document).on('keyup', this.onKeyUp); 439 return jQuery(document).on('click', '.jp-carousel-close-hint', this.onAfterClose); 440 }; 441 442 JetpackAdapter.prototype.onAfterClose = function() { 443 JetpackAdapter.__super__.onAfterClose.apply(this, arguments); 444 return jQuery(document).off('keyup', this.onKeyUp); 445 }; 446 447 JetpackAdapter.prototype.onNextSlide = function() { 448 var lightboxLinks; 449 this.currentIndex += 1; 450 lightboxLinks = this.getLightboxLinks(); 451 if (this.currentIndex === lightboxLinks.length) { 452 this.currentIndex = 0; 453 } 454 return setTimeout(((function(_this) { 455 return function() { 456 return _this.setHash(_this.getLightboxLinks().eq(_this.currentIndex).closest('.uber-grid-cell')); 457 }; 458 })(this)), 400); 459 }; 460 461 JetpackAdapter.prototype.onPrevSlide = function() { 462 this.currentIndex -= 1; 463 if (this.currentIndex < 0) { 464 this.currentIndex = this.getLightboxLinks().size() - 1; 465 } 466 return this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 467 }; 468 469 return JetpackAdapter; 470 471})(LightboxAdapter); 472 473var MagnificPopupAdapter, 474 bind = function(fn, me) { 475 return function() { 476 return fn.apply(me, arguments); 477 }; 478 }, 479 extend = function(child, parent) { 480 for (var key in parent) { 481 if (hasProp.call(parent, key)) child[key] = parent[key]; 482 } 483 484 function ctor() { 485 this.constructor = child; 486 } 487 ctor.prototype = parent.prototype; 488 child.prototype = new ctor(); 489 child.__super__ = parent.prototype; 490 return child; 491 }, 492 hasProp = {}.hasOwnProperty; 493 494MagnificPopupAdapter = (function(superClass) { 495 extend(MagnificPopupAdapter, superClass); 496 497 function MagnificPopupAdapter(grid, $el) { 498 this.onImageClicked = bind(this.onImageClicked, this); 499 MagnificPopupAdapter.__super__.constructor.call(this, grid, $el); 500 } 501 502 MagnificPopupAdapter.prototype.onImageClicked = function(event) { 503 var _this, index, items, masterPopupSettings, settings; 504 _this = this; 505 MagnificPopupAdapter.__super__.onImageClicked.call(this, event); 506 event.preventDefault(); 507 event.stopPropagation(); 508 masterPopupSettings = { 509 gallery: { 510 enabled: true, 511 navigateByImgClick: true, 512 preload: [1, 1] 513 }, 514 closeBtnInside: true, 515 mainClass: 'mfp-fade', 516 closeMarkup: '<button title="%title%" type="button" class="mfp-close"></button>' 517 }; 518 items = this.getLightboxLinks(); 519 index = items.index(jQuery(event.target).closest('a.uber-grid-lightbox')); 520 settings = jQuery.extend(masterPopupSettings, { 521 items: jQuery.map(items, function(item) { 522 var isImage, isInline; 523 isImage = function() {
524 return item.attr('href').match(/(\.jpe?g|\.png|\.gif)$/i); 525 }; 526 isInline = function() { 527 return item.attr('href').match(/^#/); 528 }; 529 item = jQuery(item); 530 settings = { 531 src: item.attr('href') 532 }; 533 if (isInline()) { 534 settings.type = 'inline'; 535 if (settings.src === '#') { 536 settings.src = jQuery(item.closest('div.uber-grid-cell').find('.uber-grid-lightbox-content-wrapper').html()); 537 } 538 } else if (isImage()) { 539 settings.type = 'image'; 540 } else { 541 settings.type = 'iframe'; 542 } 543 settings.ubergridCell = item.closest('div.uber-grid-cell'); 544 return settings; 545 }), 546 image: { 547 titleSrc: function() { 548 if (this.currItem.data.ubergridCell.find('.uber-grid-lightbox-content-wrapper').size()) { 549 return this.currItem.data.ubergridCell.find('.uber-grid-lightbox-content-wrapper').html(); 550 } 551 return ''; 552 }, 553 markup: '<div class="mfp-figure">' + '<div class="mfp-close"></div>' + '<figure>' + '<div class="mfp-img"></div>' + '<div class="mfp-uber-grid-border"></div>' + '<figcaption>' + '<div class="mfp-bottom-bar">' + '<div class="mfp-title"></div>' + '<div class="mfp-counter"></div>' + '</div>' + '</figcaption>' + '</figure>' + '</div>' 554 }, 555 callbacks: { 556 open: (function() { 557 jQuery('.mfp-wrap').addClass('mfp-uber-grid'); 558 return this._lastFocusedEl = null; 559 }), 560 markupParse: (function(template) { 561 return template.find('.mfp-counter').remove(); 562 }), 563 afterClose: (function(_this) { 564 return function() { 565 _this.resetHash(); 566 return _this.enableSetHash = false; 567 }; 568 })(this), 569 afterChange: function() { 570 if (!UberGrid.isTouchDevice()) { 571 jQuery('.mfp-bottom-bar').addClass('uber-grid-visible').height(); 572 setTimeout((function() { 573 return jQuery('.mfp-bottom-bar').removeClass('uber-grid-visible'); 574 }), 1500); 575 } 576 if (_this.enableSetHash) { 577 _this.setHash(this.currItem.data.ubergridCell); 578 } 579 return _this.enableSetHash = true; 580 } 581 } 582 }); 583 jQuery.magnificPopup.open(settings, index); 584 return jQuery('.mfp-bottom-bar').addClass('uber-grid-visible').height(); 585 }; 586 587 return MagnificPopupAdapter; 588 589})(LightboxAdapter); 590 591var PrettyPhotoAdapter, 592 bind = function(fn, me) { 593 return function() { 594 return fn.apply(me, arguments); 595 }; 596 }, 597 extend = function(child, parent) { 598 for (var key in parent) { 599 if (hasProp.call(parent, key)) child[key] = parent[key]; 600 } 601 602 function ctor() { 603 this.constructor = child; 604 } 605 ctor.prototype = parent.prototype; 606 child.prototype = new ctor(); 607 child.__super__ = parent.prototype; 608 return child; 609 }, 610 hasProp = {}.hasOwnProperty; 611 612PrettyPhotoAdapter = (function(superClass) { 613 extend(PrettyPhotoAdapter, superClass); 614 615 function PrettyPhotoAdapter(grid, $el, lightboxOptions) { 616 this.onPrevSlide = bind(this.onPrevSlide, this); 617 this.onNextSlide = bind(this.onNextSlide, this); 618 this.onImageClicked = bind(this.onImageClicked, this); 619 this.onKeyUp = bind(this.onKeyUp, this); 620 this.reset = bind(this.reset, this); 621 if (!jQuery.fn.prettyPhoto) { 622 alert('PrettyPhoto is not detected. Please check if your theme loads a custom jQuery.'); 623 return; 624 } 625 this.options = lightboxOptions; 626 PrettyPhotoAdapter.__super__.constructor.call(this, grid, $el); 627 } 628 629 PrettyPhotoAdapter.prototype.reset = function() { 630 var cell, i, image, len, link, ref, results; 631 PrettyPhotoAdapter.__super__.reset.apply(this, arguments); 632 this.getLightboxLinks().prettyPhoto({ 633 hook: 'data-lightbox', 634 deeplinking: false 635 }); 636 jQuery(document).bind('keydown.prettyphoto', this.onKeyUp); 637 ref = this.getLightboxLinks(); 638 results = []; 639 for (i = 0, len = ref.length; i < len; i++) { 640 link = ref[i]; 641 link = jQuery(link); 642 cell = link.closest('.uber-grid-cell'); 643 image = cell.find('img.uber-grid-cell-image'); 644 if (link.is('.uber-grid-hover')) { 645 image = image.clone().css('display', 'none'); 646 link.append(image); 647 } 648 results.push(image.attr('alt', cell.find('.uber-grid-lightbox-content h3').html()).attr('title', cell.find('.uber-grid-lightbox-content div').html())); 649 } 650 return results; 651 }; 652 653 PrettyPhotoAdapter.prototype.onKeyUp = function(event) { 654 if (event.keyCode === 37) { 655 return this.onPrevSlide(); 656 } else if (event.keyCode === 39) { 657 return this.onNextSlide(); 658 } else if (event.keyCode === 27) { 659 return this.resetHash(); 660 } 661 }; 662 663 PrettyPhotoAdapter.prototype.onImageClicked = function(event) { 664 this.currentIndex = this.getLightboxLinks().index(jQuery(event.target)); 665 jQuery(window).on('click', '.pp_previous', this.onPrevSlide); 666 jQuery(window).on('click', '.pp_next', this.onNextSlide); 667 return PrettyPhotoAdapter.__super__.onImageClicked.call(this, event); 668 }; 669 670 PrettyPhotoAdapter.prototype.onNextSlide = function() { 671 var lightboxLinks; 672 this.currentIndex += 1; 673 lightboxLinks = this.getLightboxLinks(); 674 if (this.currentIndex === lightboxLinks.length) { 675 this.currentIndex = lightboxLinks.length - 1; 676 } 677 return this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 678 }; 679 680 PrettyPhotoAdapter.prototype.onPrevSlide = function() { 681 this.currentIndex -= 1; 682 if (this.currentIndex < 0) { 683 this.currentIndex = 0; 684 } 685 return this.setHash(this.getLightboxLinks().eq(this.currentIndex).closest('.uber-grid-cell')); 686 }; 687 688 return PrettyPhotoAdapter; 689 690})(LightboxAdapter); 691 692var SwipeboxAdapter, 693 bind = function(fn, me) { 694 return function() { 695 return fn.apply(me, arguments); 696 }; 697 }, 698 extend = function(child, parent) { 699 for (var key in parent) { 700 if (hasProp.call(parent, key)) child[key] = parent[key]; 701 } 702 703 function ctor() { 704 this.constructor = child; 705 } 706 ctor.prototype = parent.prototype; 707 child.prototype = new ctor(); 708 child.__super__ = parent.prototype; 709 return child; 710 }, 711 hasProp = {}.hasOwnProperty; 712 713SwipeboxAdapter = (function(superClass) { 714 extend(SwipeboxAdapter, superClass); 715 716 function SwipeboxAdapter(grid, $el) { 717 this.onImageClicked = bind(this.onImageClicked, this); 718 SwipeboxAdapter.__super__.constructor.call(this, grid, $el); 719 } 720 721 SwipeboxAdapter.prototype.onImageClicked = function(event) { 722 var elements, lightboxImages; 723 SwipeboxAdapter.__super__.onImageClicked.call(this, event); 724 event.preventDefault(); 725 lightboxImages = jQuery.map(elements = this.getLightboxImages(), (function(_this) { 726 return function(image) { 727 image = jQuery(image); 728 return { 729 href: image.find('a.uber-grid-cell-wrapper, a.uber-grid-hover').attr('href'), 730 title: function() { 731 return image.find('.uber-grid-lightbox-content').html(); 732 } 733 }; 734 }; 735 })(this)); 736 this.currentIndex = elements.index(jQuery(event.target).closest('.uber-grid-cell')); 737 jQuery.swipebox(lightboxImages, { 738 initialIndexOnArray: this.currentIndex, 739 afterClose: this.onAfterClose 740 }); 741 jQuery('#swipebox-next').click(this.onNextSlide); 742 jQuery('#swipebox-prev').click(this.onPrevSlide); 743 return jQuery(window).on('keyup', this.onKeyUp); 744 }; 745 746 return SwipeboxAdapter; 747 748})(LightboxAdapter); 749 750var UberboxAdapter, 751 extend = function(child, parent) { 752 for (var key in parent) { 753 if (hasProp.call(parent, key)) child[key] = parent[key]; 754 } 755 756 function ctor() { 757 this.constructor = child; 758 } 759 ctor.prototype = parent.prototype; 760 child.prototype = new ctor(); 761 child.__super__ = parent.prototype; 762 return child; 763 }, 764 hasProp = {}.hasOwnProperty; 765 766UberboxAdapter = (function(superClass) { 767 extend(UberboxAdapter, superClass); 768 769 function UberboxAdapter() { 770 return UberboxAdapter.__super__.constructor.apply(this, arguments); 771 } 772 773 UberboxAdapter.prototype.onImageClicked = function(e) { 774 var box, hasThumbnails, havingThumbnails, index, items; 775 UberboxAdapter.__super__.onImageClicked.call(this, e); 776 items = this.getLightboxLinks(); 777 index = items.index(jQuery(e.target).closest('a.uber-grid-lightbox')); 778 havingThumbnails = _.filter(this.getItems(), (function(_this) { 779 return function(item) { 780 return !!item.thumbnail; 781 }; 782 })(this)); 783 hasThumbnails = havingThumbnails.length > items.length / 2; 784 box = Uberbox.show(this.getItems(), { 785 orientation: 'horizontal', 786 current: index, 787 carousel: true 788 }); 789 return box.on('close', (function(_this) { 790 return function() { 791 box.off('close'); 792 return _this.resetHash(); 793 }; 794 })(this)); 795 }; 796 797 UberboxAdapter.prototype.getItems = function() { 798 var items, thumbnailCount; 799 items = this.grid.cells.filter(function(cell) { 800 return cell.$el.find('>a, a.uber-grid-hover').hasClass('uber-grid-lightbox'); 801 }); 802 thumbnailCount = 0; 803 items = items.map((function(_this) { 804 return function(cell) { 805 var config, id, url; 806 config = { 807 url: cell.model.get('image_url'), 808 thumbnail: cell.model.get('thumbnail_url'), 809 title: cell.model.get('title'), 810 description: cell.model.get('description'), 811 description_style: cell.model.get('description_style'), 812 download_url: cell.model.get('download_url'), 813 share: true 814 }; 815 url = cell.model.get('image_url'); 816 if (id = cell.model.get('grid_id')) { 817 config.type = "ajax"; 818 config.url = _this.grid.options.ajaxurl + "?action=uber_grid_render_grid&id=" + id; 819 config.ajax = true; 820 delete config.title; 821 delete config.description; 822 config.description_style = 'none'; 823 } 824 return config; 825 }; 826 })(this)); 827 return items; 828 }; 829 830 return UberboxAdapter; 831 832})(LightboxAdapter); 833 834var CellCollection, CellModel, UberGridModel, 835 extend = function(child, parent) { 836 for (var key in parent) { 837 if (hasProp.call(parent, key)) child[key] = parent[key]; 838 } 839 840 function ctor() { 841 this.constructor = child; 842 } 843 ctor.prototype = parent.prototype; 844 child.prototype = new ctor(); 845 child.__super__ = parent.prototype; 846 return child; 847 }, 848 hasProp = {}.hasOwnProperty, 849 bind = function(fn, me) { 850 return function() { 851 return fn.apply(me, arguments); 852 }; 853 }; 854 855CellModel = (function(superClass) { 856 extend(CellModel, superClass); 857 858 function CellModel() { 859 return CellModel.__super__.constructor.apply(this, arguments); 860 } 861 862 CellModel.prototype.matchesFilter = function(filter) { 863 return (_.indexOf(this.get('tags'), filter.toLowerCase())) !== -1; 864 }; 865 866 CellModel.prototype.show = function() { 867 return this.trigger('show'); 868 }; 869 870 CellModel.prototype.hide = function() { 871 return this.trigger('hide'); 872 }; 873 874 return CellModel; 875 876})(Backbone.Model); 877 878CellCollection = (function(superClass) { 879 extend(CellCollection, superClass); 880
881 function CellCollection() { 882 return CellCollection.__super__.constructor.apply(this, arguments); 883 } 884 885 return CellCollection; 886 887})(Backbone.Collection); 888 889UberGridModel = (function(superClass) { 890 extend(UberGridModel, superClass); 891 892 function UberGridModel() { 893 this.onCellsChanged = bind(this.onCellsChanged, this); 894 this.onFilterChanged = bind(this.onFilterChanged, this); 895 this.applyFiltering = bind(this.applyFiltering, this); 896 return UberGridModel.__super__.constructor.apply(this, arguments); 897 } 898 899 UberGridModel.prototype.defaults = { 900 page: 1 901 }; 902 903 UberGridModel.prototype.initialize = function() { 904 this.set('cells', new CellCollection()); 905 this.set('all_cells', new CellCollection()); 906 this.on('change:filter', this.onFilterChanged); 907 this.on('change:page', this.applyFiltering); 908 this.on('change:cells', this.onCellsChanged); 909 return this.on('change:all_cells', (function(_this) { 910 return function() { 911 return _this.onFilterChanged(); 912 }; 913 })(this)); 914 }; 915 916 UberGridModel.prototype.applyFiltering = function() { 917 var cells, pagination; 918 cells = this.get('all_cells'); 919 cells = this.getFilteredCells(); 920 pagination = this.get('pagination'); 921 if (pagination.enable && cells.length > pagination.per_page) { 922 if (pagination.style === 'pagination') { 923 cells = cells.slice(pagination.per_page * (this.get('page') - 1), pagination.per_page * this.get('page')); 924 } else { 925 if (pagination.per_page * this.get('page') >= cells.length) { 926 this.trigger('end'); 927 } 928 cells = cells.slice(0, pagination.per_page * this.get('page')); 929 } 930 } 931 return this.set('cells', cells); 932 }; 933 934 UberGridModel.prototype.getFilteredCells = function() { 935 return _.filter(this.get('all_cells'), (function(_this) { 936 return function(cell) { 937 var filter; 938 filter = _this.get('filter'); 939 if (!filter || filter === "") { 940 return true; 941 } 942 return cell.matchesFilter(filter); 943 }; 944 })(this)); 945 }; 946 947 UberGridModel.prototype.loadMore = function() { 948 return this.set('page', this.get('page') + 1); 949 }; 950 951 UberGridModel.prototype.calculatePages = function() { 952 return this.set('pages', Math.ceil(this.getFilteredCells().length / this.get('pagination').per_page)); 953 }; 954 955 UberGridModel.prototype.onFilterChanged = function() { 956 this.calculatePages(); 957 this.set('page', 1); 958 return this.applyFiltering(); 959 }; 960 961 UberGridModel.prototype.onCellsChanged = function() { 962 var cell, i, j, len, len1, oldCells, results, toHide, toShow; 963 oldCells = this.previous('cells'); 964 if (oldCells) { 965 toShow = _.difference(this.get('cells'), oldCells); 966 toHide = _.difference(oldCells, this.get('cells')); 967 } else { 968 toShow = this.get('cells'); 969 toHide = []; 970 } 971 for (i = 0, len = toShow.length; i < len; i++) { 972 cell = toShow[i]; 973 cell.show(); 974 } 975 results = []; 976 for (j = 0, len1 = toHide.length; j < len1; j++) { 977 cell = toHide[j]; 978 results.push(cell.hide()); 979 } 980 return results; 981 }; 982 983 return UberGridModel; 984 985})(Backbone.Model); 986 987var UberGridCell, 988 bind = function(fn, me) { 989 return function() { 990 return fn.apply(me, arguments); 991 }; 992 }, 993 extend = function(child, parent) { 994 for (var key in parent) { 995 if (hasProp.call(parent, key)) child[key] = parent[key]; 996 } 997 998 function ctor() { 999 this.constructor = child; 1000 } 1001 ctor.prototype = parent.prototype; 1002 child.prototype = new ctor(); 1003 child.__super__ = parent.prototype; 1004 return child; 1005 }, 1006 hasProp = {}.hasOwnProperty; 1007 1008UberGridCell = (function(superClass) { 1009 extend(UberGridCell, superClass); 1010 1011 function UberGridCell() { 1012 this.onLinkClicked = bind(this.onLinkClicked, this); 1013 return UberGridCell.__super__.constructor.apply(this, arguments); 1014 } 1015 1016 UberGridCell.prototype.events = { 1017 'click a.uber-grid-hover, a.uber-grid-cell-wrapper': 'onLinkClicked' 1018 }; 1019 1020 UberGridCell.prototype.initialize = function(el) { 1021 this.$el.data('uber-grid-cell', this); 1022 this.model.set(this.readAttributes()); 1023 this.listenTo(this.model, 'show', (function(_this) { 1024 return function() { 1025 return _this.show(); 1026 }; 1027 })(this)); 1028 this.listenTo(this.model, 'hide', (function(_this) { 1029 return function() { 1030 return _this.hide(); 1031 }; 1032 })(this)); 1033 if (this.model.get('has_hover')) { 1034 this.$el.mouseleave((function(_this) { 1035 return function() { 1036 return _this.$el.removeClass('uber-grid-hover-active'); 1037 }; 1038 })(this)); 1039 } 1040 if (window.devicePixelRatio !== undefined && window.devicePixelRatio > 1 && this.$el.not(".uber-grid-photon")) { 1041 return this.$el.find(".uber-grid-cell-image").each(function(index, image) { 1042 var src2x; 1043 src2x = jQuery(image).attr("src") + "&zoom=" + window.devicePixelRatio; 1044 return jQuery(image).attr("src", src2x).attr('data-at2x', src2x); 1045 }); 1046 } 1047 }; 1048 1049 UberGridCell.prototype.readAttributes = function() { 1050 var attr; 1051 return attr = { 1052 description: this.$('.uber-grid-lightbox-content-wrapper').html(), 1053 description_style: this.getDescriptionStyle(), 1054 has_hover: this.$('.uber-grid-hover').size > 0, 1055 has_link: this.$('a.uber-grid-hover, a.uber-grid-cell-wrapper').size() > 0, 1056 thumbnail_url: this.getThumbnailUrl(), 1057 image_url: this.$('a.uber-grid-cell-wrapper, a.uber-grid-hover').attr('href'),
1058 download_url: this.getDownloadUrl(), 1059 title: this.$('.uber-grid-lightbox-content-wrapper h3.uber-grid-lightbox-title').html(), 1060 tags: this.getTags(), 1061 grid_id: this.getGridId() 1062 }; 1063 }; 1064 1065 UberGridCell.prototype.getTags = function() { 1066 var tags; 1067 tags = this.$el.attr('data-tags'); 1068 if (!tags) { 1069 return []; 1070 } 1071 return _.compact(tags.split(',')).map((function(_this) { 1072 return function(tag) { 1073 return tag.trim().toLowerCase(); 1074 }; 1075 })(this)); 1076 }; 1077 1078 UberGridCell.prototype.onLinkClicked = function(event) { 1079 if (!UberGrid.isTouchDevice()) { 1080 return; 1081 } 1082 if (!this.$el.closest('.uber-grid').hasClass('uber-grid-mobile-hover')) { 1083 return; 1084 } 1085 if (this.$el.hasClass('uber-grid-hover-active')) { 1086 return; 1087 } 1088 this.$el.addClass('uber-grid-hover-active'); 1089 event.preventDefault(); 1090 return event.stopPropagation(); 1091 }; 1092 1093 UberGridCell.prototype.show = function() { 1094 return this.$el.addClass('uber-grid-visible'); 1095 }; 1096 1097 UberGridCell.prototype.hide = function() { 1098 return this.$el.removeClass('uber-grid-visible'); 1099 }; 1100 1101 UberGridCell.prototype.getGridId = function() { 1102 return this.$('.uber-grid-cell-content').attr('data-lightbox-grid-id'); 1103 }; 1104 1105 UberGridCell.prototype.getThumbnailUrl = function() { 1106 var image; 1107 image = this.$('.uber-grid-cell-image'); 1108 if (image.length > 0) { 1109 return image.attr('src'); 1110 } 1111 return this.$('.uber-grid-cell-content').attr('data-lightbox-thumbnail'); 1112 }; 1113 1114 UberGridCell.prototype.getImageUrl = function() { 1115 return this.$('a.uber-grid-cell-wrapper, a.uber-grid-hover').attr('href'); 1116 }; 1117 1118 UberGridCell.prototype.getDownloadUrl = function() { 1119 return this.$('.uber-grid-cell-content').attr('data-lightbox-download-url'); 1120 }; 1121 1122 UberGridCell.prototype.getDescriptionStyle = function() { 1123 var style; 1124 if (style = this.$('.uber-grid-lightbox-content-wrapper').attr('data-style')) { 1125 return style; 1126 } 1127 return void 0; 1128 }; 1129 1130 return UberGridCell; 1131 1132})(Backbone.View); 1133 1134var UberGridFilters, 1135 bind = function(fn, me) { 1136 return function() { 1137 return fn.apply(me, arguments); 1138 }; 1139 }, 1140 extend = function(child, parent) { 1141 for (var key in parent) { 1142 if (hasProp.call(parent, key)) child[key] = parent[key]; 1143 } 1144 1145 function ctor() { 1146 this.constructor = child; 1147 } 1148 ctor.prototype = parent.prototype; 1149 child.prototype = new ctor(); 1150 child.__super__ = parent.prototype; 1151 return child; 1152 }, 1153 hasProp = {}.hasOwnProperty; 1154 1155UberGridFilters = (function(superClass) { 1156 extend(UberGridFilters, superClass); 1157 1158 function UberGridFilters() { 1159 this.onFilterClicked = bind(this.onFilterClicked, this); 1160 return UberGridFilters.__super__.constructor.apply(this, arguments); 1161 } 1162 1163 UberGridFilters.prototype.events = { 1164 "click > div a": 'onFilterClicked' 1165 }; 1166 1167 UberGridFilters.prototype.initialize = function() { 1168 UberGridFilters.__super__.initialize.apply(this, arguments); 1169 this.listenTo(this.model, 'change:filter', this.onFilterChanged); 1170 return this.activateFirst(); 1171 }; 1172 1173 UberGridFilters.prototype.activateFirst = function() { 1174 return this.$("> div:first-child").addClass("active"); 1175 }; 1176 1177 UberGridFilters.prototype.deactivateAll = function() { 1178 return this.$("> div").removeClass("active"); 1179 }; 1180 1181 UberGridFilters.prototype.onFilterChanged = function() { 1182 var attr, i, len, link, ref, results; 1183 this.deactivateAll(); 1184 ref = this.$('a'); 1185 results = []; 1186 for (i = 0, len = ref.length; i < len; i++) { 1187 link = ref[i]; 1188 attr = jQuery(link).attr('href').toLowerCase(); 1189 if (attr === "#" + this.model.get('filter').toLowerCase()) { 1190 results.push(jQuery(link).parent().addClass('active')); 1191 } else { 1192 results.push(void 0); 1193 } 1194 } 1195 return results; 1196 }; 1197 1198 UberGridFilters.prototype.onFilterClicked = function(event) { 1199 var a, tag; 1200 event.preventDefault(); 1201 a = jQuery(event.target); 1202 this.deactivateAll(); 1203 a.parent().addClass("active"); 1204 tag = a.attr("href").replace(/^#/, ""); 1205 return this.model.set('filter', tag); 1206 }; 1207 1208 return UberGridFilters; 1209 1210})(Backbone.View); 1211 1212var UberGridPagination, 1213 bind = function(fn, me) { 1214 return function() { 1215 return fn.apply(me, arguments); 1216 }; 1217 }, 1218 extend = function(child, parent) { 1219 for (var key in parent) { 1220 if (hasProp.call(parent, key)) child[key] = parent[key]; 1221 } 1222 1223 function ctor() { 1224 this.constructor = child; 1225 } 1226 ctor.prototype = parent.prototype; 1227 child.prototype = new ctor(); 1228 child.__super__ = parent.prototype; 1229 return child; 1230 }, 1231 hasProp = {}.hasOwnProperty; 1232 1233UberGridPagination = (function(superClass) { 1234 extend(UberGridPagination, superClass); 1235 1236 function UberGridPagination() { 1237 this.onPageClicked = bind(this.onPageClicked, this); 1238 this.onLoadMoreClicked = bind(this.onLoadMoreClicked, this); 1239 this.onModelEnd = bind(this.onModelEnd, this); 1240 this.render = bind(this.render, this); 1241 return UberGridPagination.__super__.constructor.apply(this, arguments); 1242 } 1243 1244 UberGridPagination.prototype.events = { 1245 'click .uber-grid-pagination-page:not(.uber-grid-current)': 'onPageClicked', 1246 'click .uber-grid-load-more': 'onLoadMoreClicked' 1247 }; 1248 1249 UberGridPagination.prototype.initialize = function(options) { 1250 UberGridPagination.__super__.initialize.apply(this, arguments); 1251 this.options = options; 1252 this.model.on('change:pages', this.render); 1253 this.listenTo(this.model, 'end', this.onModelEnd); 1254 return this.activateFirst(); 1255 }; 1256 1257 UberGridPagination.prototype.render = function() { 1258 if (this.options.style === 'pagination') { 1259 return this.renderPagination(); 1260 } else { 1261 return this.renderLoadMore(); 1262 } 1263 }; 1264 1265 UberGridPagination.prototype.onModelEnd = function() { 1266 return this.$el.hide(); 1267 }; 1268 1269 UberGridPagination.prototype.renderLoadMore = function() { 1270 if (this.model.get('pages') < 2) { 1271 return this.$el.hide(); 1272 } else { 1273 this.$el.show(); 1274 return this.$el.html(jQuery('<div />').append(jQuery('<a class="uber-grid-load-more" href="#load-more"></a>').text(this.options.load_more))); 1275 } 1276 }; 1277 1278 UberGridPagination.prototype.renderPagination = function() { 1279 var a, i, j, ref; 1280 console.info(this.$el); 1281 this.$('.uber-grid-pagination-page').remove(); 1282 if (this.model.get('pages') < 2) { 1283 return this.$el.hide(); 1284 } else { 1285 for (i = j = 1, ref = this.model.get('pages'); 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) { 1286 a = jQuery("<a />").attr('href', '#ubergrid-page-' + i).text(i); 1287 this.$el.append(jQuery('<div class="uber-grid-pagination-page" />').append(a)); 1288 } 1289 this.activateFirst(); 1290 return this.$el.show(); 1291 } 1292 }; 1293 1294 UberGridPagination.prototype.activateFirst = function() { 1295 return this.$('.uber-grid-pagination-page').eq(0).addClass('uber-grid-current'); 1296 }; 1297 1298 UberGridPagination.prototype.deactivateAll = function() { 1299 return this.$('.uber-grid-pagination-page').removeClass('uber-grid-current'); 1300 }; 1301 1302 UberGridPagination.prototype.onLoadMoreClicked = function(e) { 1303 e.preventDefault(); 1304 return this.model.loadMore(); 1305 }; 1306 1307 UberGridPagination.prototype.onPageClicked = function(e) { 1308 var page; 1309 e.preventDefault();
1310 page = parseInt(jQuery(e.target).attr('href').replace('#ubergrid-page-', '')); 1311 this.deactivateAll(); 1312 jQuery(e.target).parent().addClass('uber-grid-current'); 1313 return this.model.set('page', parseInt(page)); 1314 }; 1315 1316 return UberGridPagination; 1317 1318})(Backbone.View); 1319 1320var UberGrid, UberGridGrid, 1321 bind = function(fn, me) { 1322 return function() { 1323 return fn.apply(me, arguments); 1324 }; 1325 }, 1326 extend = function(child, parent) { 1327 for (var key in parent) { 1328 if (hasProp.call(parent, key)) child[key] = parent[key]; 1329 } 1330 1331 function ctor() { 1332 this.constructor = child; 1333 } 1334 ctor.prototype = parent.prototype; 1335 child.prototype = new ctor(); 1336 child.__super__ = parent.prototype; 1337 return child; 1338 }, 1339 hasProp = {}.hasOwnProperty, 1340 indexOf = [].indexOf || function(item) { 1341 for (var i = 0, l = this.length; i < l; i++) { 1342 if (i in this && this[i] === item) return i; 1343 } 1344 return -1; 1345 }; 1346 1347UberGrid = (function(superClass) { 1348 extend(UberGrid, superClass); 1349 1350 function UberGrid() { 1351 this.initLightbox = bind(this.initLightbox, this); 1352 return UberGrid.__super__.constructor.apply(this, arguments); 1353 } 1354 1355 UberGrid.isTouchDevice = function() { 1356 var ua; 1357 ua = navigator.userAgent; 1358 return !!(indexOf.call(document, 'createTouch') >= 0 || screen.width <= 699 || ua.match(/(iPhone|iPod|iPad)/) || ua.match(/BlackBerry/) || ua.match(/Android/)); 1359 }; 1360 1361 UberGrid.prototype.getId = function() { 1362 return this.$el.attr("id").replace("uber-grid-wrapper-", ""); 1363 }; 1364 1365 UberGrid.prototype.initialize = function(options) { 1366 var triggered; 1367 UberGrid.__super__.initialize.apply(this, arguments); 1368 this.options = options; 1369 this.model = new UberGridModel({ 1370 id: this.getId(), 1371 pagination: this.options.pagination 1372 }); 1373 this.ui = { 1374 pagination: this.$(".uber-grid-pagination"), 1375 grid: this.$('.uber-grid'), 1376 filters: this.$('.uber-grid-filters') 1377 }; 1378 this.cells = this.buildCells(); 1379 this.grid = new UberGridGrid(_.extend(this.options, { 1380 el: this.ui.grid, 1381 model: this.model, 1382 cells: this.cells 1383 })); 1384 this.filters = new UberGridFilters(_.extend(this.options, { 1385 el: this.ui.filters, 1386 model: this.model 1387 })); 1388 triggered = false; 1389 if (this.options.pagination.enable) { 1390 this.model.set({ 1391 per_page: this.options.per_page 1392 }); 1393 this.pagination = new UberGridPagination(_.extend(this.options.pagination, { 1394 el: this.ui.pagination, 1395 model: this.model 1396 })); 1397 } 1398 if (this.options.default_filter) { 1399 this.model.set({ 1400 filter: this.options.default_filter 1401 }); 1402 } 1403 this.model.set('all_cells', _.pluck(this.cells, 'model')); 1404 this.grid.reveal(); 1405 return this.initLightbox(); 1406 }; 1407 1408 UberGrid.prototype.getCellElements = function() { 1409 return this.ui.grid.find(">div"); 1410 }; 1411 1412 UberGrid.prototype.buildCells = function() { 1413 var cells; 1414 cells = []; 1415 this.getCellElements().each((function(_this) { 1416 return function(index, el) { 1417 return cells.push(new UberGridCell({ 1418 el: jQuery(el), 1419 model: new CellModel 1420 })); 1421 }; 1422 })(this)); 1423 return cells; 1424 }; 1425 1426 UberGrid.prototype.initLightbox = function() { 1427 var $grid, lightbox_options; 1428 lightbox_options = this.options.lightbox.lightbox_options; 1429 $grid = this.grid.$el; 1430 this.lightboxAdapter = (function() { 1431 switch (this.options.lightbox) { 1432 case 'uberbox': 1433 return new UberboxAdapter(this, $grid, lightbox_options); 1434 case 'magnific-popup': 1435 return new MagnificPopupAdapter(this, $grid, lightbox_options); 1436 case 'swipebox': 1437 return new SwipeboxAdapter(this, $grid, lightbox_options); 1438 case 'prettyphoto': 1439 return new PrettyPhotoAdapter(this, $grid, lightbox_options); 1440 case 'ilightbox': 1441 return new iLightboxAdapter(this, $grid, lightbox_options); 1442 case 'jetpack': 1443 return new JetpackAdapter(this, $grid, lightbox_options); 1444 case 'foobox': 1445 return new FooBoxAdapter(this, $grid, lightbox_options); 1446 default: 1447 return null; 1448 } 1449 }).call(this); 1450 this.lightboxAdapter.reset(); 1451 }; 1452 1453 return UberGrid; 1454 1455})(Backbone.View); 1456 1457UberGridGrid = (function(superClass) { 1458 extend(UberGridGrid, superClass); 1459 1460 function UberGridGrid() { 1461 this.updateLayout = bind(this.updateLayout, this); 1462 this.reveal = bind(this.reveal, this); 1463 this.onCellsChanged = bind(this.onCellsChanged, this); 1464 return UberGridGrid.__super__.constructor.apply(this, arguments); 1465 } 1466 1467 UberGridGrid.prototype.initialize = function(options) { 1468 this.options = options; 1469 this.cellMapping = {}; 1470 this.cells = options.cells; 1471 this.createMapping(); 1472 jQuery(window).on('resize', _.debounce(this.updateLayout)); 1473 return this.model.on('change:cells', this.onCellsChanged); 1474 }; 1475 1476 UberGridGrid.prototype.createMapping = function() { 1477 var cell, i, len, ref, results; 1478 ref = this.cells; 1479 results = []; 1480 for (i = 0, len = ref.length; i < len; i++) { 1481 cell = ref[i]; 1482 results.push(this.cellMapping[cell.model.cid] = cell); 1483 } 1484 return results; 1485 }; 1486 1487 UberGridGrid.prototype.onCellsChanged = function() { 1488 if (!this.packery) { 1489 this.packery = new Packery(this.$el[0], { 1490 transitionDuration: "0", 1491 gutter: parseInt(this.options.gutter), 1492 itemSelector: '.uber-grid-cell.uber-grid-visible' 1493 }); 1494 } else { 1495 this.packery.reloadItems(); 1496 } 1497 return this.updateLayout(); 1498 }; 1499 1500 UberGridGrid.prototype.reveal = function() { 1501 if (!this.$el.is(':visible') || this.$el.width() < 50) { 1502 return setTimeout(this.reveal, 500); 1503 } else { 1504 this.model.applyFiltering(); 1505 this.updateLayout(); 1506 return setTimeout(((function(_this) { 1507 return function() { 1508 _this.model.applyFiltering(); 1509 return _this.updateLayout(); 1510 }; 1511 })(this)), 400); 1512 } 1513 }; 1514 1515 UberGridGrid.prototype.updateLayout = function() { 1516 var baseCellWidth, border, calculatedCellHeight, cellHeight, cellWidth, columns, gutter, i, len, maxWidth, options, ref, title, titleHeight, width; 1517 options = this.options; 1518 width = void 0; 1519 cellWidth = void 0; 1520 cellHeight = void 0; 1521 gutter = void 0; 1522 border = void 0; 1523 maxWidth = parseInt(this.options.max_width); 1524 width = jQuery(window).width(); 1525 if (width > 768) { 1526 cellWidth = options.size.width; 1527 cellHeight = options.size.height; 1528 gutter = options.gutter; 1529 border = options.cell_border; 1530 } else if (width > 440) { 1531 cellWidth = options.size768.width; 1532 cellHeight = options.size768.height; 1533 gutter = options.gutter_768; 1534 border = options.cell_border_768; 1535 } else { 1536 cellWidth = options.size440.width; 1537 cellHeight = options.size440.height; 1538 gutter = options.gutter_440; 1539 border = options.cell_border_440; 1540 } 1541 width = this.$el.width(); 1542 if (!isNaN(maxWidth) && maxWidth > 0 && width > maxWidth) { 1543 width = maxWidth; 1544 } 1545 baseCellWidth = cellWidth = parseInt(cellWidth); 1546 gutter = parseInt(gutter); 1547 border = parseInt(border); 1548 if (isNaN(gutter)) { 1549 gutter = 0; 1550 } 1551 if (isNaN(border)) { 1552 border = 0; 1553 } 1554 if (this.options.autosize && this.options.autosize !== "0") { 1555 columns = Math.ceil((width + gutter) / (cellWidth + gutter + 2 * border)); 1556 if (columns > 2 && columns % 2 === 1 && this.$(".r1c2, .r2c2").size() > 0 && this.$(".r1c1, .r2c1").size() === 0) { 1557 columns += 1; 1558 } 1559 if (columns > this.$(".r1c2, .r2c2").size() * 2 + this.$(".r1c1, .r2c1").size()) { 1560 columns = this.$(".r1c2, .r2c2").size() * 2 + this.$(".r1c1, .r2c1").size(); 1561 } 1562 cellWidth = Math.floor((width + gutter) / columns) - gutter - border * 2; 1563 if (cellWidth > baseCellWidth) { 1564 cellWidth = baseCellWidth; 1565 } 1566 if (columns === 2 && cellWidth * 2 + border * 2 + gutter > width) { 1567 cellWidth = (width - gutter + border * 2) / 2; 1568 } 1569 calculatedCellHeight = Math.floor(cellHeight * cellWidth / baseCellWidth); 1570 this.$(".uber-grid-cells-wrapper").width(width); 1571 this.$(".uber-grid-cell.r1c1, .uber-grid-cell.r1c1 .uber-grid-cell-wrapper").width(cellWidth); 1572 this.$(".uber-grid-cell.r1c1 .uber-grid-cell-wrapper").height(calculatedCellHeight); 1573 this.$(".uber-grid-cell.r1c2, .uber-grid-cell.r1c2 .uber-grid-cell-wrapper").width(cellWidth * 2 + gutter + border * 2); 1574 this.$(".uber-grid-cell.r1c2 .uber-grid-cell-wrapper").height(calculatedCellHeight); 1575 this.$(".uber-grid-cell.r2c1, .uber-grid-cell.r2c1 .uber-grid-cell-wrapper").width(cellWidth); 1576 this.$(".uber-grid-cell.r2c1 .uber-grid-cell-wrapper").height(cellHeight * cellWidth / baseCellWidth * 2 + gutter + border * 2); 1577 this.$(".uber-grid-cell.r2c2, .uber-grid-cell.r2c2 .uber-grid-cell-wrapper").width(cellWidth * 2 + gutter + border * 2); 1578 this.$(".uber-grid-cell.r2c2 .uber-grid-cell-wrapper").height(cellHeight * cellWidth / baseCellWidth * 2 + gutter + border * 2); 1579 ref = this.$('.uber-grid-cell-title-wrapper.uber-grid-title-position-center'); 1580 for (i = 0, len = ref.length; i < len; i++) { 1581 title = ref[i]; 1582 titleHeight = jQuery(title).find('.uber-grid-cell-title').height() / 2; 1583 jQuery(title).find('.uber-grid-cell-title').css('margin-top', "-" + titleHeight.toString() + "px"); 1584 } 1585 this.packery.columnWidth = cellWidth; 1586 this.$el.find(".uber-grid-cells-wrapper").width(width); 1587 } else { 1588 columns = Math.floor((width + gutter) / (cellWidth + gutter + 2 * border)); 1589 if (columns > 4 && columns % 2 === 1 && this.$(".r1c2, .r2c2").size() > 0 && this.$(".r1c1, .r2c1").size() === 0) { 1590 columns -= 1; 1591 } 1592 if (columns > this.$(".r1c2, .r2c2").size() * 2 + this.$(".r1c1, .r2c1").size()) { 1593 columns = this.$(".r1c2, .r2c2").size() * 2 + this.$(".r1c1, .r2c1").size(); 1594 } 1595 width = columns * (cellWidth + border * 2) + (columns - 1) * gutter; 1596 this.$el.find(".uber-grid-cells-wrapper").width(width); 1597 } 1598 this.packery.gutter = this.packery.options.gutter = gutter; 1599 return this.packery.layout(); 1600 }; 1601 1602 return UberGridGrid; 1603 1604}
1604)(Backbone.View); 1605 1606 window.UberGrid = UberGrid; 1607 } 1608 } 1609})(window.uberGridjQuery || window.jQuery || 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.