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