1// Uberbox.js 2// version: 0.1.0 3// author: Nikolay Karev 4// license: MIT 5(function(root, factory) { 6 // Start with AMD. 7 if (typeof define === 'function' && define.amd) { 8 define(['underscore', 'jquery', 'backbone', 'backbone.marionette'], function(_, $, backbone, marionette) { 9 // Export global even in AMD case in case this script is loaded with 10 // others that may still expect a global Backbone. 11 root.Uberbox = factory(root, _, $, backbone, marionette); 12 }); 13 14 // Next for Node.js or CommonJS. jQuery may not be needed as a module. 15 } else if (typeof exports !== 'undefined') { 16 var _ = require('underscore'); 17 var backbone = require('backbone'); 18 var marionette = require('marionette'); 19 var jquery = require('jquery'); 20 factory(root, _, jquery, backbone, marionette); 21 22 // Finally, as a browser global. 23 } else { 24 root.Uberbox = factory(root, root._, (root.uberboxjQuery || root.jQuery || root.Zepto || root.ender || root.$), Backbone, Marionette); 25 } 26 27}(this, function(root, _, jQuery, Backbone, Marionette) { 28 var Uberbox, 29 bind = function(fn, me) { 30 return function() { 31 return fn.apply(me, arguments); 32 }; 33 }, 34 extend = function(child, parent) { 35 for (var key in parent) { 36 if (hasProp.call(parent, key)) child[key] = parent[key]; 37 } 38 39 function ctor() { 40 this.constructor = child; 41 } 42 ctor.prototype = parent.prototype; 43 child.prototype = new ctor(); 44 child.__super__ = parent.prototype; 45 return child; 46 }, 47 hasProp = {}.hasOwnProperty; 48 49 Uberbox = (function(superClass) { 50 extend(Uberbox, superClass); 51 52 Uberbox.instances = []; 53 54 Uberbox.prototype.template = function() { 55 return Uberbox.Templates.uberbox; 56 }; 57 58 Uberbox.prototype.regions = { 59 lightbox: '.uberbox-lightbox-wrapper', 60 carousel: '.uberbox-carousel-wrapper', 61 toolbar: '.uberbox-toolbar-wrapper' 62 }; 63 64 Uberbox.prototype.ui = {}; 65 66 Uberbox.prototype.onTouchCancel = function(e) { 67 return e.preventDefault(); 68 }; 69 70 Uberbox.prototype.isAndroid = function() { 71 return navigator.userAgent.toLowerCase().indexOf('android') !== -1; 72 }; 73 74 Uberbox.prototype.onTouchStart = function(e) { 75 if (jQuery(e.target).closest('.uberbox-toolbar-wrapper, .uberbox-prev, .uberbox-next').length > 0) { 76 return; 77 } 78 e.preventDefault(); 79 return this.touchStartedAt = { 80 pageX: e.touches[0].pageX, 81 pageY: e.touches[0].pageY 82 }; 83 }; 84 85 Uberbox.prototype.onTouchMove = function(e) { 86 var diffX, diffY, original, threshold; 87 if (!this.touchStartedAt) { 88 return; 89 } 90 e.preventDefault(); 91 threshold = 5; 92 original = e.touches[0]; 93 diffX = original.pageX - this.touchStartedAt.pageX; 94 diffY = original.pageY - this.touchStartedAt.pageX; 95 if (this.getOption('orientation') === 'horizontal' && Math.abs(diffX) > threshold) { 96 this.lightbox.currentView.currentItemView.swipeHorizontally(diffX > 0 ? diffX - threshold : diffX + threshold); 97 return e.preventDefault(); 98 } else if (this.getOption('orientation') === 'vertical' && Math.abs(diffY) > threshold) { 99 this.lightbox.currentView.currentItemView.swipeVertically(diffY > 0 ? diffY - threshold : diffY + threshold); 100 return e.preventDefault(); 101 } else { 102 this.lightbox.currentView.currentItemView.swipeBack(); 103 if (this.collection.activeItem.get('description_style') === 'mini' || this.collection.activeItem.get('description_style') === 'none') { 104 return e.preventDefault(); 105 } else { 106 return e.stopPropagation(); 107 } 108 } 109 }; 110 111 Uberbox.prototype.shouldBotherWithTouch = function(e) { 112 return this.getOption('orientation') === 'horizontal' && Math.abs() > threshold || this.getOption('orientation') === 'vertical' && Math.abs(e.pageY - this.touchStartedAt.top) > threshold; 113 }; 114 115 Uberbox.prototype.onTouchEnd = function(e) { 116 var diffX, diffY, original, threshold; 117 original = e; 118 threshold = 15; 119 original = e.changedTouches[0]; 120 diffX = original.pageX - this.touchStartedAt.pageX; 121 diffY = original.pageY - this.touchStartedAt.pageY; 122 if (this.getOption('orientation') === 'horizontal') { 123 if (diffX > threshold && this.lightbox.currentView.currentItemView.model.prev()) { 124 this.lightbox.currentView.currentItemView.swipeBack(); 125 this.lightbox.currentView.currentItemView.model.prev().activate(); 126 } 127 if (diffX < -threshold && this.lightbox.currentView.currentItemView.model.next()) { 128 this.lightbox.currentView.currentItemView.swipeBack(); 129 this.lightbox.currentView.currentItemView.model.next().activate(); 130 } 131 } 132 if (this.getOption('orientation') === 'vertical') { 133 if (diffY > threshold && this.lightbox.currentView.currentItemView.model.prev()) { 134 this.lightbox.currentView.currentItemView.swipeBack(); 135 this.lightbox.currentView.currentItemView.model.prev().activate(); 136 } 137 if (diffY < -threshold && this.lightbox.currentView.currentItemView.model.next()) { 138 this.lightbox.currentView.currentItemView.swipeBack(); 139 this.lightbox.currentView.currentItemView.model.next().activate(); 140 } 141 } 142 this.lightbox.currentView.currentItemView.swipeBack(); 143 return this.touchStartedAt = null; 144 }; 145 146 Uberbox.contentViewTypes = function() { 147 return { 148 image: { 149 condition: /\.(gif|png|jpeg|jpg)$/i, 150 "class": Uberbox.ImageObjectView 151 }, 152 youtube: { 153 condition: /((\(\/\/)?(www\.)?youtube\.com\/watch\?v=.+)|((\/\/)(www\.)?youtu\.be\/.*)/i, 154 "class": Uberbox.YoutubeObjectView 155 }, 156 vimeo: { 157 condition: /(\/\/)?vimeo\.com\/\d+/i, 158 "class": Uberbox.VimeoObjectView 159 }, 160 soundcloud: { 161 condition: /soundcloud\.com/i, 162 "class": Uberbox.SoundcloudObjectView 163 }, 164 bandcamp: { 165 condition: /bandcamp\.com/i, 166 "class": Uberbox.BandcampObjectView 167 }, 168 iframe: { 169 condition: /(\/|\.html|\.htm|\.php|.aspx)$/i, 170 "class": Uberbox.IframeObjectView 171 }, 172 gmap: { 173 condition: /(google\.(\w+)\/maps\/)|(maps\.google\.(\w+))|(goo\.gl\/maps\/)/i, 174 "class": Uberbox.GoogleMapsObjectView 175 }, 176 html: { 177 condition: function(item) { 178 return !!item.get('html'); 179 }, 180 "class": Uberbox.HTMLObjectView 181 }, 182 ajax: { 183 condition: function(item) { 184 return item.get('ajax'); 185 },
186 "class": Uberbox.AJAXOBjectView 187 }, 188 unknown: { 189 "class": Uberbox.UnknownItemView 190 } 191 }; 192 }; 193 194 Uberbox.show = function(items, options) { 195 var uberbox; 196 if (options == null) { 197 options = {}; 198 } 199 options = _.extend({ 200 current: 0, 201 orientation: 'vertical', 202 collection: new Uberbox.ItemCollection(items), 203 carousel: false 204 }, options); 205 if (!(items && items.length > 0)) { 206 return; 207 } 208 this.instances.push(uberbox = new Uberbox(options)); 209 return uberbox; 210 }; 211 212 Uberbox.close = function() { 213 var instance; 214 if (this.instances.length > 0) { 215 instance = this.instances.pop(); 216 if (Uberbox.Utils.isFullscreen()) { 217 Uberbox.Utils.exitFullscreen(); 218 } 219 return instance.remove(); 220 } 221 }; 222 223 Uberbox.getPixelRatio = function() { 224 if (window.devicePixelRatio > 0) { 225 return window.devicePixelRatio; 226 } else { 227 return 1; 228 } 229 }; 230 231 Uberbox.getObjectViewType = function(item) {
232 var condition, config, ref, type, url; 233 if (type = item.get('type')) { 234 return Uberbox.contentViewTypes()[type]['class']; 235 } 236 ref = Uberbox.contentViewTypes(); 237 for (type in ref) { 238 config = ref[type]; 239 condition = false; 240 if (config.condition) { 241 if (_.isRegExp(config.condition) && (url = item.get('url'))) { 242 condition = item.get('url').match(config.condition); 243 } 244 if (_.isFunction(config.condition)) { 245 condition = config.condition(item); 246 } 247 } else { 248 condition = true; 249 } 250 if (condition) { 251 return config["class"]; 252 } 253 } 254 return Uberbox.contentViewTypes().unknown; 255 }; 256 257 function Uberbox(options) { 258 this.onKeyDown = bind(this.onKeyDown, this); 259 this.onItemActivated = bind(this.onItemActivated, this); 260 this.onTouchEnd = bind(this.onTouchEnd, this); 261 this.onTouchMove = bind(this.onTouchMove, this); 262 this.onTouchStart = bind(this.onTouchStart, this); 263 Uberbox.__super__.constructor.call(this, _.extend({ 264 el: jQuery('<div class="uberbox" />').appendTo(jQuery('body')) 265 }, options)); 266 } 267 268 Uberbox.prototype.initialize = function() { 269 var $html, current, lightboxOptions; 270 Uberbox.__super__.initialize.apply(this, arguments); 271 this.render(); 272 this.bindUIElements(); 273 this.$el.addClass("uberbox-" + (this.getOption('orientation'))); 274 this.showOverlay(); 275 lightboxOptions = _.extend({}, this.options, { 276 root: this.$el 277 }); 278 delete lightboxOptions.el; 279 this.lightbox.show(new Uberbox.Lightbox(lightboxOptions)); 280 this.listenTo(this.lightbox.currentView, 'close', (function(_this) { 281 return function() { 282 return _this.remove(); 283 }; 284 })(this)); 285 if (this.getOption('carousel')) { 286 if (jQuery(window).width() > 1024) { 287 this.$el.addClass('uberbox-has-carousel'); 288 this.carousel.show(new Uberbox.Carousel(lightboxOptions)); 289 } 290 jQuery(window).on('resize.uberbox-main', (function(_this) { 291 return function() { 292 if (jQuery(window).width() < 1024) { 293 _this.carousel.empty(); 294 return _this.$el.removeClass('uberbox-has-carousel'); 295 } else if (!_this.carousel.currentView) { 296 _this.$el.addClass('uberbox-has-carousel'); 297 return _this.carousel.show(new Uberbox.Carousel(lightboxOptions)); 298 } 299 }; 300 })(this)); 301 } else { 302 this.$('.uberbox-carousel-wrapper').remove(); 303 } 304 this.listenTo(this.getOption('collection'), 'close', (function(_this) { 305 return function() { 306 return Uberbox.close(); 307 }; 308 })(this)); 309 this.listenTo(this.getOption('collection'), 'activate', this.onItemActivated); 310 current = this.getOption('collection').at(this.getOption('current')); 311 current.activate(); 312 jQuery('body').on('keydown', this.onKeyDown); 313 $html = jQuery('html'); 314 this.overflow = $html.css('overflow'); 315 $html.css('overflow', 'hidden'); 316 this.el.addEventListener('touchstart', this.onTouchStart); 317 this.el.addEventListener('touchend', this.onTouchEnd); 318 return this.el.addEventListener('touchmove', this.onTouchMove); 319 }; 320 321 Uberbox.prototype.onItemActivated = function(item) { 322 if (this.toolbar.currentView) { 323 this.stopListening(this.toolbar.currentView, 'close'); 324 } 325 this.toolbar.show(new Uberbox.ToolbarView({ 326 model: item 327 })); 328 this.listenTo(this.toolbar.currentView, 'close', (function(_this) { 329 return function() { 330 return _this.close(); 331 }; 332 })(this)); 333 if (!item.get('loaded')) { 334 this.showLoader(); 335 } 336 if (this.oldActiveItem) { 337 this.stopListening(this.oldActiveItem, 'load'); 338 } 339 this.oldActiveItem = item; 340 return this.listenTo(item, 'load', (function(_this) { 341 return function() { 342 return _this.hideLoader(); 343 }; 344 })(this)); 345 }; 346 347 Uberbox.prototype.hideLoader = function() { 348 if (this.showLoaderTimeout) { 349 clearTimeout(this.showLoaderTimeout); 350 this.showLoaderTimeout = null; 351 } 352 return this.$el.find('div.uberbox-loader').remove(); 353 }; 354 355 Uberbox.prototype.showLoader = function() { 356 if (this.showLoaderTimeout) { 357 return; 358 } 359 return this.showLoaderTimeout = setTimeout(((function(_this) { 360 return function() { 361 return _this.$el.append(jQuery('<div class="uberbox-loader uberbox-icon-arrows-ccw">')); 362 }; 363 })(this)), 100); 364 }; 365 366 Uberbox.prototype.remove = function() { 367 this.trigger('close'); 368 Uberbox.__super__.remove.apply(this, arguments); 369 if (Uberbox.Utils.isFullscreen()) { 370 Uberbox.Utils.exitFullscreen(); 371 } 372 this.ui.overlay.removeClass('visible'); 373 jQuery('body').off('keydown.uberbox', this.onKeyDown); 374 jQuery('html').css('overflow', this.overflow); 375 this.el.removeEventListener('touchstart', this.onTouchStart); 376 this.el.removeEventListener('touchend', this.onTouchEnd); 377 this.el.removeEventListener('touchmove', this.onTouchMove); 378 return setTimeout(((function(_this) { 379 return function() { 380 return _this.ui.overlay.remove(); 381 }; 382 })(this)), 600); 383 }; 384 385 Uberbox.prototype.onKeyDown = function(e) { 386 if (e.which === 27) { 387 e.preventDefault(); 388 this.remove(); 389 }
390 if (e.which === 37 || e.which === 38) { 391 this.collection.activatePrev(); 392 return false; 393 } 394 if (e.which === 40 || e.which === 39) { 395 this.collection.activateNext(); 396 return false; 397 } 398 }; 399 400 Uberbox.prototype.showOverlay = function() { 401 this.ui.overlay = jQuery('<div class="uberbox-overlay" />').appendTo(jQuery('body')); 402 _.defer((function(_this) { 403 return function() { 404 return _this.ui.overlay.addClass('visible'); 405 }; 406 })(this)); 407 return this.ui.overlay.on('click', (function(_this) { 408 return function() { 409 return _this.remove(); 410 }; 411 })(this)); 412 }; 413 414 return Uberbox; 415 416 })(Marionette.LayoutView); 417 418 Uberbox.Utils = (function() { 419 function Utils() {} 420 421 Utils.supportsFullScreen = function() { 422 var el, i, len, prefix, ref; 423 el = document.documentElement; 424 if (el.requestFullscreen) { 425 return true; 426 } 427 ref = ['moz', 'webkit', 'ms']; 428 for (i = 0, len = ref.length; i < len; i++) { 429 prefix = ref[i]; 430 if (el[prefix + "RequestFullScreen"]) { 431 return true; 432 } 433 } 434 return false; 435 }; 436 437 Utils.isFullscreen = function() { 438 var i, len, method, ref; 439 ref = ['fullscreenEnabled', 'webkitFullscreenEnabled', 'mozFullscreenEnabled', 'msFullscreenEnabled']; 440 for (i = 0, len = ref.length; i < len; i++) { 441 method = ref[i]; 442 if (!_.isUndefined(document[method])) { 443 return document[method]; 444 } 445 } 446 }; 447 448 Utils.enterFullscreen = function(el) { 449 var method; 450 if (!el) { 451 el = document.documentElement; 452 } 453 method = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; 454 return method.apply(el); 455 }; 456 457 Utils.exitFullscreen = function() { 458 var el, method; 459 el = document.documentElement; 460 method = el.exitFullscreen || el.mozCancelFullScreen || el.msExitFullscreen; 461 if (method) { 462 method.apply(el); 463 } 464 if (document.webkitExitFullscreen) { 465 return document.webkitExitFullscreen(); 466 } 467 }; 468 469 Utils.notification = function(options) { 470 var notification; 471 notification = jQuery('<div class="uberbox-notification" />').html(options.message).appendTo(jQuery('body')); 472 _.defer((function(_this) { 473 return function() { 474 return notification.addClass('uberbox-active'); 475 }; 476 })(this)); 477 return setTimeout(((function(_this) { 478 return function() { 479 notification.removeClass('uberbox-active'); 480 return setTimeout((function() { 481 return notification.remove(); 482 }), 600); 483 }; 484 })(this)), 4000); 485 }; 486 487 return Utils; 488 489 })(); 490 491 var extend = function(child, parent) { 492 for (var key in parent) { 493 if (hasProp.call(parent, key)) child[key] = parent[key]; 494 } 495 496 function ctor() { 497 this.constructor = child; 498 } 499 ctor.prototype = parent.prototype; 500 child.prototype = new ctor(); 501 child.__super__ = parent.prototype; 502 return child; 503 }, 504 hasProp = {}.hasOwnProperty; 505 506 Uberbox.ShareService = (function(superClass) { 507 extend(ShareService, superClass); 508 509 function ShareService() { 510 return ShareService.__super__.constructor.apply(this, arguments); 511 } 512 513 ShareService.services = { 514 facebook: { 515 url: "//www.facebook.com/share.php?v=4&src=bm&u=%url%", 516 name: 'Facebook' 517 }, 518 twitter: { 519 url: "//twitter.com/home?status=%url%", 520 name: 'Twitter' 521 }, 522 googleplus: { 523 url: "//plus.google.com/share?url=%url%", 524 name: 'Google Plus' 525 }, 526 reddit: { 527 url: "//reddit.com/submit?url=%url%", 528 name: 'Reddit' 529 }, 530 digg: { 531 url: "//digg.com/submit?phase=2&url=%url%", 532 name: 'Digg' 533 }, 534 stumbleupon: { 535 url: "http://www.stumbleupon.com/submit?url=%url%&title=%title%", 536 name: "Stumbleupon" 537 }, 538 delicious: { 539 url: "//delicious.com/post?url=%url%", 540 name: 'Delicious' 541 }, 542 pinterest: { 543 url: "https://www.pinterest.com/pin/create/button/?url=%url%&media=%image_url%&description=%description%&title=%title%", 544 name: 'Pinterest' 545 }, 546 vk: { 547 url: "http://vk.com/share.php?url=%url%", 548 name: 'VK' 549 } 550 }; 551 552 ShareService.prototype.processPseudotags = function(template, model) { 553 var tag, tags; 554 tags = { 555 url: window.location.href, 556 image_url: model.get('url'), 557 title: model.get('title') || '', 558 description: model.get('description') || '' 559 }; 560 for (tag in tags) { 561 template = template.replace("%" + tag + "%", encodeURIComponent(tags[tag])); 562 } 563 return template; 564 }; 565 566 ShareService.prototype.getShareLinkUrl = function(model) { 567 return this.processPseudotags(this.get('url'), model); 568 }; 569 570 return ShareService; 571 572 })(Backbone.Model); 573 574 Uberbox.Item = (function(superClass) { 575 extend(Item, superClass); 576 577 function Item() { 578 return Item.__super__.constructor.apply(this, arguments); 579 } 580 581 Item.prototype.defaults = { 582 description_style: 'mini', 583 download_tooltip: 'Download', 584 download_started_tooltip: 'Download started', 585 share_tooltip: 'Share', 586 fullscreen_tooltip: 'Fullscreen', 587 exit_fullscreen_tooltip: 'Exit fullscreen' 588 }; 589 590 Item.prototype.initialize = function() { 591 var share; 592 Item.__super__.initialize.apply(this, arguments); 593 if (share = this.get('share')) { 594 if (_.isBoolean(share)) { 595 share = Uberbox.ShareService.services; 596 } 597 this.set('share', _.map(share, function(config, name) { 598 return new Uberbox.ShareService(_.extend({}, { 599 slug: name 600 }, config)); 601 })); 602 } 603 if (!this.get('title') && !this.get('description')) { 604 return this.set('description_style', 'none'); 605 } 606 }; 607 608 Item.prototype.activate = function() { 609 if (this.collection.activeItem !== this) { 610 return this.trigger('activate', this); 611 } 612 }; 613 614 Item.prototype.deactivate = function() { 615 return this.trigger('deactivate'); 616 }; 617 618 Item.prototype.next = function() { 619 return this.collection.next(this); 620 }; 621 622 Item.prototype.prev = function() { 623 return this.collection.prev(this); 624 }; 625 626 Item.prototype.isActive = function() { 627 return this.collection.activeItem === this; 628 }; 629 630 Item.prototype.isNext = function() { 631 return this.collection.activeItem === this.prev(); 632 }; 633 634 Item.prototype.isPrev = function() { 635 return this.collection.activeItem === this.next(); 636 }; 637 638 Item.prototype.showDescription = function() { 639 if (this.get('description_style') === 'none') { 640 return false;
641 } 642 return !!this.get('description'); 643 }; 644 645 Item.prototype.follows = function(item) { 646 var next; 647 next = item.next(); 648 if (next === this) { 649 return true; 650 } 651 if (next) { 652 return this.follows(next); 653 } 654 return false; 655 }; 656 657 Item.prototype.precedes = function(item) { 658 var prev; 659 prev = item.prev(); 660 if (prev === this) { 661 return true; 662 } 663 if (prev) { 664 return this.precedes(prev); 665 } 666 return false; 667 }; 668 669 return Item; 670 671 })(Backbone.Model); 672 673 Uberbox.ItemCollection = (function(superClass) { 674 extend(ItemCollection, superClass); 675 676 function ItemCollection() { 677 return ItemCollection.__super__.constructor.apply(this, arguments); 678 } 679 680 ItemCollection.prototype.model = Uberbox.Item; 681 682 ItemCollection.prototype.current = null; 683 684 ItemCollection.prototype.initialize = function() { 685 ItemCollection.__super__.initialize.apply(this, arguments); 686 return this.on('activate', (function(_this) { 687 return function(item) { 688 if (_this.activeItem) { 689 _this.activeItem.deactivate(); 690 } 691 return _this.activeItem = item; 692 }; 693 })(this)); 694 }; 695 696 ItemCollection.prototype.next = function(item) { 697 var index; 698 index = this.indexOf(item); 699 if (index === this.length - 1) { 700 return null; 701 } 702 return this.at(index + 1); 703 }; 704 705 ItemCollection.prototype.prev = function(item) { 706 var index; 707 index = this.indexOf(item); 708 if (index === 0) { 709 return; 710 } 711 return this.at(index - 1); 712 }; 713 714 ItemCollection.prototype.activateNext = function() { 715 if (this.activeItem && this.activeItem.next()) { 716 return this.activeItem.next().activate(); 717 } 718 }; 719 720 ItemCollection.prototype.activatePrev = function() { 721 if (this.activeItem && this.activeItem.prev()) { 722 return this.activeItem.prev().activate(); 723 } 724 }; 725 726 return ItemCollection; 727 728 })(Backbone.Collection); 729 730 var bind = function(fn, me) { 731 return function() { 732 return fn.apply(me, arguments); 733 }; 734 }, 735 extend = function(child, parent) { 736 for (var key in parent) { 737 if (hasProp.call(parent, key)) child[key] = parent[key]; 738 } 739 740 function ctor() { 741 this.constructor = child; 742 } 743 ctor.prototype = parent.prototype; 744 child.prototype = new ctor(); 745 child.__super__ = parent.prototype; 746 return child; 747 }, 748 hasProp = {}.hasOwnProperty; 749 750 Uberbox.SlidingWindowItem = (function(superClass) { 751 extend(SlidingWindowItem, superClass); 752 753 function SlidingWindowItem() { 754 this.onClicked = bind(this.onClicked, this); 755 this.enableTransition = bind(this.enableTransition, this); 756 return SlidingWindowItem.__super__.constructor.apply(this, arguments); 757 } 758 759 SlidingWindowItem.prototype.loaded = false; 760 761 SlidingWindowItem.prototype.events = function() { 762 return { 763 click: 'onClicked' 764 }; 765 }; 766 767 SlidingWindowItem.prototype.modelEvents = { 768 activate: 'onItemActivated', 769 deactivate: 'onItemDeactivated' 770 }; 771 772 SlidingWindowItem.prototype.belongs = function() { 773 return this.top > 0 && this.left > 0 && this.width + this.left < this.getParent().width() && this.top + this.height < this.getParent().height(); 774 }; 775 776 SlidingWindowItem.prototype.initialize = function() { 777 SlidingWindowItem.__super__.initialize.apply(this, arguments); 778 this.listenToOnce(this, 'load', (function(_this) { 779 return function() { 780 _this.loaded = true; 781 _this.model.trigger('load'); 782 _this.layout(); 783 return _.defer(function() { 784 _this.enableTransition(); 785 return _this.$el.addClass('uberbox-loaded'); 786 }); 787 }; 788 })(this)); 789 this.render(); 790 this.bindUIElements(); 791 if (this.showRegions) { 792 return this.showRegions(); 793 } 794 }; 795 796 SlidingWindowItem.prototype.getTemplate = function() { 797 return this.getOption('template')(); 798 }; 799 800 SlidingWindowItem.prototype.enableTransition = function() { 801 return this.$el.addClass('uberbox-enable-transition'); 802 }; 803 804 SlidingWindowItem.prototype.getNextToScrollTo = function(item) { 805 var next; 806 if (this.model === item) { 807 return this; 808 } 809 if (next = this.getOption('next')) { 810 return next.getNextToScrollTo(item); 811 } 812 return null; 813 }; 814 815 SlidingWindowItem.prototype.getPrevToScrollTo = function(item) { 816 var next; 817 if (this.model === item) { 818 return this; 819 } 820 if (next = this.getOption('prev')) { 821 return next.getPrevToScrollTo(item); 822 } 823 return null; 824 }; 825 826 SlidingWindowItem.prototype.runAction = function(callback) { 827 if (this.loaded) { 828 return callback(); 829 } else { 830 return this.listenToOnce(this, 'load', (function(_this) { 831 return function() { 832 return callback(); 833 }; 834 })(this)); 835 } 836 }; 837 838 SlidingWindowItem.prototype.getParent = function() { 839 if (!this.parent) { 840 this.parent = this.$el.parent(); 841 } 842 return this.parent; 843 }; 844 845 SlidingWindowItem.prototype.isNext = function() { 846 return this.model.follows(this.model.collection.activeItem); 847 }; 848 849 SlidingWindowItem.prototype.isPrev = function() { 850 return this.model.precedes(this.model.collection.activeItem); 851 }; 852 853 SlidingWindowItem.prototype.isCurrent = function() { 854 return this.model.isActive(); 855 }; 856 857 SlidingWindowItem.prototype.remove = function() { 858 this.$el.removeClass('uberbox-visible'); 859 if (this.getOption('next')) { 860 this.getOption('next').options.prev = null; 861 } 862 if (this.getOption('prev')) { 863 this.getOption('prev').options.next = null; 864 } 865 return setTimeout(((function(_this) { 866 return function() { 867 return SlidingWindowItem.__super__.remove.call(_this); 868 }; 869 })(this)), 600); 870 }; 871 872 SlidingWindowItem.prototype.reveal = function() {}; 873 874 SlidingWindowItem.prototype.bindUIElements = function() { 875 SlidingWindowItem.__super__.bindUIElements.apply(this, arguments); 876 if (this.model.collection.activeItem === this.model) { 877 return this.onItemActivated(); 878 } 879 }; 880 881 SlidingWindowItem.prototype.onItemActivated = function() { 882 return this.$el.addClass('uberbox-current'); 883 }; 884 885 SlidingWindowItem.prototype.onItemDeactivated = function() { 886 return this.$el.removeClass('uberbox-current'); 887 }; 888 889 SlidingWindowItem.prototype.onClicked = function() { 890 return this.model.activate(); 891 }; 892 893 return SlidingWindowItem; 894 895 })(Marionette.LayoutView); 896 897 var extend = function(child, parent) { 898 for (var key in parent) { 899 if (hasProp.call(parent, key)) child[key] = parent[key]; 900 } 901 902 function ctor() { 903 this.constructor = child; 904 } 905 ctor.prototype = parent.prototype; 906 child.prototype = new ctor(); 907 child.__super__ = parent.prototype; 908 return child; 909 }, 910 hasProp = {}.hasOwnProperty; 911 912 Uberbox.SlidingWindow = (function(superClass) { 913 extend(SlidingWindow, superClass); 914 915 SlidingWindow.prototype.defaults = function() { 916 return { 917 orientation: 'vertical', 918 current: 0 919 }; 920 }; 921 922 function SlidingWindow(options) { 923 SlidingWindow.__super__.constructor.call(this, _.extend({}, _.result(this, 'defaults'), options)); 924 this.listenTo(this.collection, 'activate', this.onItemActivated); 925 } 926 927 SlidingWindow.prototype.onShow = function() { 928 return jQuery(window).on('resize', this.layout); 929 }; 930 931 SlidingWindow.prototype.remove = function() { 932 jQuery(window).off('resize', this.layout); 933 return SlidingWindow.__super__.remove.apply(this, arguments); 934 }; 935 936 SlidingWindow.prototype.getChildView = function(child) { 937 var childView; 938 return childView = this.getOption('childView'); 939 }; 940 941 SlidingWindow.prototype.createChildView = function(child, options) { 942 var view, viewClass; 943 if (options == null) { 944 options = {}; 945 } 946 viewClass = this.getChildViewClass(); 947 options = _.extend(_.extend({ 948 model: child, 949 orientation: this.getOption('orientation') 950 }, Marionette._getValue(this.getOption('childViewOptions'), this, [child])), options); 951 view = new viewClass(options); 952 if (options.prev && !options.next) { 953 options.prev.options.next = view; 954 view.$el.insertAfter(options.prev.$el); 955 } else if (options.next && !options.prev) { 956 options.next.options.prev = view; 957 view.$el.insertBefore(options.next.$el); 958 } else { 959 view.$el.appendTo(this.$el); 960 } 961 return view; 962 }; 963 964 return SlidingWindow; 965 966 }
966)(Marionette.View); 967 968 var extend = function(child, parent) { 969 for (var key in parent) { 970 if (hasProp.call(parent, key)) child[key] = parent[key]; 971 } 972 973 function ctor() { 974 this.constructor = child; 975 } 976 ctor.prototype = parent.prototype; 977 child.prototype = new ctor(); 978 child.__super__ = parent.prototype; 979 return child; 980 }, 981 hasProp = {}.hasOwnProperty, 982 bind = function(fn, me) { 983 return function() { 984 return fn.apply(me, arguments); 985 }; 986 }; 987 988 Uberbox.CarouselItem = (function(superClass) { 989 extend(CarouselItem, superClass); 990 991 function CarouselItem() { 992 return CarouselItem.__super__.constructor.apply(this, arguments); 993 } 994 995 CarouselItem.prototype.template = function() { 996 return Uberbox.Templates['carousel-item']; 997 }; 998 999 CarouselItem.prototype.className = 'uberbox-carousel-item'; 1000 1001 CarouselItem.prototype.padding = 15; 1002 1003 CarouselItem.prototype.ui = { 1004 image: 'img' 1005 }; 1006 1007 CarouselItem.prototype.getImageAspectRatio = function() { 1008 var aspect, image; 1009 image = this.ui.image[0]; 1010 return aspect = image.naturalWidth / image.naturalHeight; 1011 }; 1012 1013 CarouselItem.prototype.getHeightInVerticalMode = function() { 1014 return this.width / this.getImageAspectRatio(); 1015 }; 1016 1017 CarouselItem.prototype.getWidthInHorizontalMode = function() { 1018 return this.height * this.getImageAspectRatio(); 1019 }; 1020 1021 CarouselItem.prototype.bindUIElements = function() { 1022 CarouselItem.__super__.bindUIElements.apply(this, arguments); 1023 if (this.ui.image[0].complete) { 1024 _.defer((function(_this) { 1025 return function() { 1026 return _this.trigger('load'); 1027 }; 1028 })(this)); 1029 } 1030 return this.$el.find('img').on('load', (function(_this) { 1031 return function() { 1032 return _this.trigger('load'); 1033 }; 1034 })(this)); 1035 }; 1036 1037 CarouselItem.prototype.layoutContent = function() {}; 1038 1039 CarouselItem.prototype.hideLoader = function() { 1040 return this.ui.loader.remove(); 1041 }; 1042 1043 CarouselItem.prototype.layout = function() { 1044 if (this.model.isActive()) { 1045 this.calculateCoordinatesAsCurrent(); 1046 } else if (this.model.follows(this.model.collection.activeItem)) { 1047 this.calculateCoordinatesAsNext(); 1048 } else if (this.model.precedes(this.model.collection.activeItem)) { 1049 this.calculateCoordinatesAsPrev(); 1050 } 1051 if (this.loaded) { 1052 this.layoutContent(); 1053 } 1054 return this.applyLayout(); 1055 }; 1056 1057 CarouselItem.prototype.getNext = function() { 1058 return this.getOption('next'); 1059 }; 1060 1061 CarouselItem.prototype.getPrev = function() { 1062 return this.getOption('prev'); 1063 }; 1064 1065 CarouselItem.prototype.remove = function() { 1066 var next, prev; 1067 this.$el.find('img').off('load', this.onImageLoaded); 1068 this.$el.remove(); 1069 if (next = this.getOption('next')) { 1070 next.options.prev = null; 1071 } 1072 if (prev = this.getOption('prev')) { 1073 return prev.options.next = null; 1074 } 1075 }; 1076 1077 CarouselItem.prototype.fits = function() { 1078 if (this.belongs()) { 1079 return true; 1080 } 1081 if (this.top < this.getParent().height() && this.top + this.$el.height() > 0 && this.left + this.$el.width() > 0 && this.left < this.getParent().width() && this.top < this.getParent().height()) { 1082 return true; 1083 } 1084 return false; 1085 }; 1086 1087 CarouselItem.prototype.applyLayout = function() { 1088 return this.$el.css({ 1089 left: this.left, 1090 top: this.top, 1091 width: this.width, 1092 height: this.height 1093 }); 1094 }; 1095 1096 return CarouselItem; 1097 1098 })(Uberbox.SlidingWindowItem); 1099 1100 Uberbox.VerticalCarouselItem = (function(superClass) { 1101 extend(VerticalCarouselItem, superClass); 1102 1103 function VerticalCarouselItem() { 1104 return VerticalCarouselItem.__super__.constructor.apply(this, arguments); 1105 } 1106 1107 VerticalCarouselItem.prototype.calculateCoordinatesAsPrev = function() { 1108 var next; 1109 if (!(next = this.getOption('next'))) { 1110 return; 1111 } 1112 this.left = this.padding; 1113 this.width = this.getParent().width() - this.padding * 2; 1114 this.height = this.getHeightInVerticalMode(); 1115 return this.top = next.top - this.padding - this.height; 1116 }; 1117 1118 VerticalCarouselItem.prototype.calculateCoordinatesAsNext = function() { 1119 var prev; 1120 if (!(prev = this.getOption('prev'))) { 1121 return; 1122 } 1123 this.left = this.padding; 1124 this.top = this.padding + prev.top + prev.height; 1125 this.width = this.getParent().width() - this.padding * 2; 1126 return this.height = this.getHeightInVerticalMode(); 1127 }; 1128 1129 VerticalCarouselItem.prototype.calculateCoordinatesAsCurrent = function() { 1130 var top; 1131 this.width = this.getParent().width() - this.padding * 2; 1132 this.height = this.getHeightInVerticalMode(); 1133 top = this.getParent().height() / 2 - this.height / 2; 1134 this.left = this.padding; 1135 return this.top = top; 1136 }; 1137 1138 return VerticalCarouselItem; 1139 1140 })(Uberbox.CarouselItem); 1141 1142 Uberbox.HorizontalCarouselItem = (function(superClass) { 1143 extend(HorizontalCarouselItem, superClass); 1144 1145 function HorizontalCarouselItem() { 1146 return HorizontalCarouselItem.__super__.constructor.apply(this, arguments); 1147 } 1148 1149 HorizontalCarouselItem.prototype.calculateCoordinatesAsPrev = function() { 1150 var next; 1151 if (!(next = this.getOption('next'))) { 1152 return; 1153 } 1154 this.height = this.getParent().height() - this.padding * 2; 1155 this.width = this.getWidthInHorizontalMode(); 1156 this.left = next.left - this.width - this.padding; 1157 return this.top = this.padding; 1158 }; 1159 1160 HorizontalCarouselItem.prototype.calculateCoordinatesAsNext = function() { 1161 var prev; 1162 if (!(prev = this.getOption('prev'))) { 1163 return; 1164 } 1165 this.left = prev.left + prev.width + this.padding; 1166 this.top = this.padding; 1167 this.height = this.getParent().height() - this.padding * 2; 1168 return this.width = this.getWidthInHorizontalMode(); 1169 }; 1170 1171 HorizontalCarouselItem.prototype.calculateCoordinatesAsCurrent = function() { 1172 this.height = this.getParent().height() - this.padding * 2; 1173 this.width = this.getWidthInHorizontalMode(); 1174 this.left = this.getParent().width() / 2 - this.width / 2; 1175 return this.top = this.padding; 1176 }; 1177 1178 return HorizontalCarouselItem; 1179 1180 })(Uberbox.CarouselItem); 1181 1182 Uberbox.Carousel = (function(superClass) { 1183 extend(Carousel, superClass); 1184 1185 function Carousel() { 1186 this.layout = bind(this.layout, this); 1187 this.waitForFirst = bind(this.waitForFirst, this); 1188 this.waitForLast = bind(this.waitForLast, this); 1189 this.buildPrev = bind(this.buildPrev, this); 1190 this.buildNext = bind(this.buildNext, this); 1191 return Carousel.__super__.constructor.apply(this, arguments); 1192 } 1193 1194 Carousel.prototype.className = 'uberbox-carousel-content'; 1195 1196 Carousel.prototype.template = function() { 1197 return Uberbox.Templates['carousel-content']; 1198 }; 1199 1200 Carousel.prototype.render = function() { 1201 return this.$el.html(Marionette.Renderer.render(this.template)); 1202 }; 1203 1204 Carousel.prototype.getChildViewClass = function() { 1205 if (this.getOption('orientation') === 'vertical') { 1206 return Uberbox.VerticalCarouselItem; 1207 } else { 1208 return Uberbox.HorizontalCarouselItem; 1209 } 1210 }; 1211 1212 Carousel.prototype.hide = function() { 1213 var item; 1214 if (!this.currentItemView) { 1215 return; 1216 } 1217 this.currentItemView.remove(); 1218 item = this.currentItemView; 1219 while (item = item.getOption('next')) { 1220 item.remove(); 1221 } 1222 item = this.currentItemView; 1223 while (item = item.getOption('prev')) { 1224 item.remove(); 1225 } 1226 return this.currentItemView = null; 1227 }; 1228 1229 Carousel.prototype.build = function(item) {}; 1230 1231 Carousel.prototype.buildNext = function(last) { 1232 var next; 1233 if (this.belongs(last) && last.model.next() && !last.getNext()) { 1234 next = this.createChildView(last.model.next(), { 1235 prev: last 1236 }); 1237 return next.runAction((function(_this) { 1238 return function() { 1239 next.layout(); 1240 return _this.buildNext(next); 1241 }; 1242 })(this)); 1243 } 1244 }; 1245 1246 Carousel.prototype.buildPrev = function(first) { 1247 var prev; 1248 if (this.belongs(first) && first.model.prev() && !first.getPrev()) { 1249 prev = this.createChildView(first.model.prev(), { 1250 next: first 1251 }); 1252 return prev.runAction((function(_this) { 1253 return function() { 1254 prev.layout(); 1255 return _this.buildPrev(prev); 1256 }; 1257 })(this)); 1258 } 1259 }; 1260 1261 Carousel.prototype.waitForLast = function(last, lastCallback) { 1262 return last.runAction((function(_this) { 1263 return function() { 1264 if (last.getNext()) { 1265 return _this.waitForLast(last.getNext(), lastCallback); 1266 } else { 1267 return lastCallback(last); 1268 } 1269 }; 1270 })(this)); 1271 }; 1272 1273 Carousel.prototype.waitForFirst = function(first, firstCallback) { 1274 return first.runAction((function(_this) { 1275 return function() { 1276 if (first.getPrev()) { 1277 return _this.waitForFirst(first.getPrev(), firstCallback); 1278 } else { 1279 return firstCallback(first); 1280 } 1281 }; 1282 })(this)); 1283 }; 1284 1285 Carousel.prototype.isHorizontal = function() { 1286 return this.getOption('orientation') === 'horizontal'; 1287 }; 1288 1289 Carousel.prototype.fits = function(item) { 1290 var height, parent, width; 1291 parent = this.$el.parent(); 1292 if (this.isHorizontal()) { 1293 width = parent.width(); 1294 return this.translateX + item.left + item.width > 0 && this.translateX + item.left < width; 1295 } else { 1296 height = parent.height(); 1297 return this.translateY + item.top + item.height > 0 && this.translateY + item.top < height; 1298 } 1299 }; 1300 1301 Carousel.prototype.belongs = function(item) { 1302 var height, parent, width; 1303 parent = this.$el.parent(); 1304 if (this.isHorizontal()) { 1305 width = parent.width(); 1306 return this.translateX + item.left + item.width < width && this.translateX + item.left > 0; 1307 } else { 1308 height = parent.height(); 1309 return this.translateY + item.top + item.height < height && this.translateY + item.top > 0; 1310 } 1311 }; 1312 1313 Carousel.prototype.translateToCurrent = function() { 1314 var offset; 1315 if (this.isHorizontal()) { 1316 offset = this.currentItemView.left; 1317 this.translateX = this.$el.parent().width() / 2 - offset - this.currentItemView.$el.width() / 2; 1318 return this.$el.css({ 1319 transform: "translate(" + this.translateX + "px, 0px)" 1320 }); 1321 } else { 1322 offset = this.currentItemView.top; 1323 this.translateY = this.$el.parent().height() / 2 - offset - this.currentItemView.$el.height / 2; 1324 return this.$el.css({ 1325 transform: "translate(0px, " + this.translateY + "px)" 1326 }); 1327 } 1328 }; 1329 1330 Carousel.prototype.layout = function() { 1331 if (!this.currentItemView) { 1332 this.currentItemView = this.createChildView(this.collection.activeItem); 1333 } 1334 return this.currentItemView.runAction((function(_this) { 1335 return function() { 1336 _this.translateToCurrent(); 1337 _this.waitForLast(_this.currentItemView, function(last) { 1338 var results; 1339 if (last && !_this.fits(last)) { 1340 results = []; 1341 while (last && !_this.fits(last)) { 1342 last.remove(); 1343 results.push(last = last.getPrev()); 1344 } 1345 return results; 1346 } else { 1347 return _this.buildNext(last); 1348 } 1349 }); 1350 return _this.waitForFirst(_this.currentItemView, function(first) { 1351 var results; 1352 if (first && !_this.fits(first)) { 1353 results = []; 1354 while (first && !_this.fits(first)) { 1355 first.remove(); 1356 results.push(first = first.getNext()); 1357 } 1358 return results; 1359 } else { 1360 return _this.buildPrev(first); 1361 } 1362 }); 1363 }; 1364 })(this)); 1365 }; 1366 1367 Carousel.prototype.onItemActivated = function(item) { 1368 var next, prev; 1369 if (this.currentItemView && item === this.currentItemView.model) { 1370 return; 1371 } 1372 if (!this.currentItemView) { 1373 this.currentItemView = this.createChildView(item); 1374 this.currentItemView.layout(); 1375 this.layout(); 1376 return; 1377 } 1378 if (next = this.currentItemView.getNextToScrollTo(item)) { 1379 this.currentItemView = next; 1380 return this.layout(); 1381 } else if (prev = this.currentItemView.getPrevToScrollTo(item)) { 1382 this.currentItemView = prev; 1383 return this.layout(); 1384 } else { 1385 this.currentItemView.remove(); 1386 next = this.currentItemView.getOption('next'); 1387 while (next) { 1388 next.remove(); 1389 next = next.getOption('next'); 1390 } 1391 prev = this.currentItemView.getOption('prev'); 1392 while (prev) { 1393 prev.remove(); 1394 prev = prev.getOption('prev'); 1395 } 1396 this.currentItemView.layout(); 1397 this.currentItemView = this.createChildView(item); 1398 return this.layout(); 1399 } 1400 }; 1401 1402 return Carousel; 1403 1404 })(Uberbox.SlidingWindow); 1405 1406 var extend = function(child, parent) { 1407 for (var key in parent) { 1408 if (hasProp.call(parent, key)) child[key] = parent[key]; 1409 } 1410 1411 function ctor() { 1412 this.constructor = c
1412hild; 1413 } 1414 ctor.prototype = parent.prototype; 1415 child.prototype = new ctor(); 1416 child.__super__ = parent.prototype; 1417 return child; 1418 }, 1419 hasProp = {}.hasOwnProperty; 1420 1421 Uberbox.ToolbarView = (function(superClass) { 1422 extend(ToolbarView, superClass); 1423 1424 function ToolbarView() { 1425 return ToolbarView.__super__.constructor.apply(this, arguments); 1426 } 1427 1428 ToolbarView.prototype.template = function() { 1429 return Uberbox.Templates.toolbar; 1430 }; 1431 1432 ToolbarView.prototype.getTemplate = function() { 1433 return this.template(); 1434 }; 1435 1436 ToolbarView.prototype.className = 'uberbox-toolbar'; 1437 1438 ToolbarView.prototype.ui = { 1439 download: '*[data-action=download]', 1440 fullscreen: '*[data-action=fullscreen]', 1441 exitFullscreen: '*[data-action=exit-fullscreen]', 1442 close: '*[data-action=close]', 1443 share: '*[data-action=share]', 1444 shareMenu: '.uberbox-share-menu' 1445 }; 1446 1447 ToolbarView.prototype.events = { 1448 'click @ui.fullscreen': 'onFullscreenClick', 1449 'click @ui.exitFullscreen': 'onExitFullscreenClick', 1450 'click @ui.close': 'onCloseClick', 1451 'click @ui.share': 'onShareClick', 1452 'click @ui.download': 'onDownloadClick', 1453 'click .uberbox-share-overlay': 'onShareClick' 1454 }; 1455 1456 ToolbarView.prototype.serializeData = function() { 1457 return { 1458 model: this.model 1459 }; 1460 }; 1461 1462 ToolbarView.prototype.onShow = function() { 1463 return _.defer((function(_this) { 1464 return function() { 1465 return _this.$el.addClass('uberbox-visible'); 1466 }; 1467 })(this)); 1468 }; 1469 1470 ToolbarView.prototype.onFullscreenClick = function(e) { 1471 e.preventDefault(); 1472 e.stopPropagation(); 1473 this.ui.fullscreen.addClass('uberbox-disabled'); 1474 this.ui.exitFullscreen.removeClass('uberbox-disabled'); 1475 return Uberbox.Utils.enterFullscreen(document.documentElement); 1476 }; 1477 1478 ToolbarView.prototype.onDownloadClick = function(e) { 1479 return Uberbox.Utils.notification({ 1480 message: this.model.get('download_started_tooltip') 1481 }); 1482 }; 1483 1484 ToolbarView.prototype.onExitFullscreenClick = function(e) { 1485 e.preventDefault(); 1486 e.stopPropagation(); 1487 this.ui.exitFullscreen.addClass('uberbox-disabled'); 1488 this.ui.fullscreen.removeClass('uberbox-disabled'); 1489 return Uberbox.Utils.exitFullscreen(); 1490 }; 1491 1492 ToolbarView.prototype.onCloseClick = function(e) { 1493 e.preventDefault(); 1494 e.stopPropagation(); 1495 return this.model.trigger('close'); 1496 }; 1497 1498 ToolbarView.prototype.onShareClick = function(e) { 1499 if (!this.ui.share.hasClass('uberbox-active')) { 1500 this.ui.share.append(jQuery('<div class="uberbox-share-overlay">')); 1501 this.ui.share.addClass('uberbox-active'); 1502 return _.defer((function(_this) { 1503 return function() { 1504 _this.ui.share.find('.uberbox-share-overlay').addClass('uberbox-active'); 1505 return _this.ui.shareMenu.addClass('uberbox-active'); 1506 }; 1507 })(this)); 1508 } else { 1509 this.ui.share.find('.uberbox-share-overlay').removeClass('uberbox-active'); 1510 this.ui.shareMenu.removeClass('uberbox-active'); 1511 return setTimeout(((function(_this) { 1512 return function() { 1513 _this.ui.share.find('.uberbox-share-overlay').remove(); 1514 return _this.ui.share.removeClass('uberbox-active'); 1515 }; 1516 })(this)), 300); 1517 } 1518 }; 1519 1520 return ToolbarView; 1521 1522 })(Marionette.ItemView); 1523 1524 var ObjectView, 1525 bind = function(fn, me) { 1526 return function() { 1527 return fn.apply(me, arguments); 1528 }; 1529 }, 1530 extend = function(child, parent) { 1531 for (var key in parent) { 1532 if (hasProp.call(parent, key)) child[key] = parent[key]; 1533 } 1534 1535 function ctor() { 1536 this.constructor = child; 1537 } 1538 ctor.prototype = parent.prototype; 1539 child.prototype = new ctor(); 1540 child.__super__ = parent.prototype; 1541 return child; 1542 }, 1543 hasProp = {}.hasOwnProperty; 1544 1545 ObjectView = (function(superClass) { 1546 extend(ObjectView, superClass); 1547 1548 function ObjectView() { 1549 this.onObjectLoaded = bind(this.onObjectLoaded, this); 1550 this.onObjectError = bind(this.onObjectError, this); 1551 this.fadeIn = bind(this.fadeIn, this); 1552 return ObjectView.__super__.constructor.apply(this, arguments); 1553 } 1554 1555 ObjectView.prototype.supportsOversizing = false;
1556 1557 ObjectView.prototype.fadeIn = function() { 1558 this.visible = true; 1559 return this.$el.addClass('uberbox-visible'); 1560 }; 1561 1562 ObjectView.prototype.getAspectRatio = function() { 1563 return this.$el.width() / this.$el.height(); 1564 }; 1565 1566 ObjectView.prototype.isObjectLoaded = function() {}; 1567 1568 ObjectView.prototype.getObjectNaturalAspectRatio = function() {}; 1569 1570 ObjectView.prototype.layoutOversized = function() {}; 1571 1572 ObjectView.prototype.getTemplate = function() { 1573 return this.getOption('template')(); 1574 }; 1575 1576 ObjectView.prototype.getWidth = function() { 1577 return this.$el.width(); 1578 }; 1579 1580 ObjectView.prototype.getObjectNaturalAspectRatio = function() { 1581 return this.getObjectNaturalWidth() / this.getObjectNaturalHeight(); 1582 }; 1583 1584 ObjectView.prototype.onObjectError = function() { 1585 return this.trigger('error'); 1586 }; 1587 1588 ObjectView.prototype.onObjectLoaded = function() { 1589 return this.trigger('load'); 1590 }; 1591 1592 ObjectView.prototype.serializeData = function() { 1593 return { 1594 model: this.model 1595 }; 1596 }; 1597 1598 ObjectView.prototype.getOffset = function() { 1599 var offset; 1600 offset = this.$el.offset(); 1601 offset.top -= jQuery(window).scrollTop(); 1602 return offset; 1603 }; 1604 1605 return ObjectView; 1606 1607 })(Marionette.ItemView); 1608 1609 Uberbox.ImageObjectView = (function(superClass) { 1610 extend(ImageObjectView, superClass); 1611 1612 function ImageObjectView() { 1613 return ImageObjectView.__super__.constructor.apply(this, arguments); 1614 } 1615 1616 ImageObjectView.prototype.className = 'uberbox-image-content'; 1617 1618 ImageObjectView.prototype.waitForLoad = true; 1619 1620 ImageObjectView.prototype.supportsOversizing = true; 1621 1622 ImageObjectView.prototype.template = function() { 1623 return Uberbox.Templates['content-image']; 1624 }; 1625 1626 ImageObjectView.prototype.ui = { 1627 image: 'img' 1628 }; 1629 1630 ImageObjectView.prototype.bindUIElements = function() { 1631 ImageObjectView.__super__.bindUIElements.apply(this, arguments); 1632 if (this.isObjectLoaded()) { 1633 this.onObjectLoaded(); 1634 } 1635 this.ui.image.one('load.uberbox', this.onObjectLoaded); 1636 return this.ui.image.one('error.uberbox', this.onObjectError); 1637 }; 1638 1639 ImageObjectView.prototype.unbindUIElements = function() { 1640 this.ui.image.off('load.uberbox'); 1641 this.ui.image.off('error.uberbox'); 1642 return ImageObjectView.__super__.unbindUIElements.apply(this, arguments); 1643 }; 1644 1645 ImageObjectView.prototype.getObjectWidth = function() { 1646 return this.ui.image.width(); 1647 }; 1648 1649 ImageObjectView.prototype.isObjectLoaded = function() { 1650 return this.ui.image[0].complete; 1651 }; 1652 1653 ImageObjectView.prototype.getObjectNaturalWidth = function() { 1654 return this.ui.image[0].naturalWidth; 1655 }; 1656 1657 ImageObjectView.prototype.getObjectNaturalHeight = function() { 1658 return this.ui.image[0].naturalHeight; 1659 }; 1660 1661 ImageObjectView.prototype.getOffset = function() { 1662 var offset; 1663 offset = this.ui.image.offset(); 1664 return { 1665 left: offset.left, 1666 top: offset.top - jQuery(window).scrollTop() 1667 }; 1668 }; 1669 1670 ImageObjectView.prototype.getWidth = function() { 1671 return this.ui.image.width(); 1672 }; 1673 1674 return ImageObjectView; 1675 1676 })(ObjectView); 1677 1678 Uberbox.IframeObjectView = (function(superClass) { 1679 extend(IframeObjectView, superClass); 1680 1681 function IframeObjectView() { 1682 this.onWindowResized = bind(this.onWindowResized, this); 1683 return IframeObjectView.__super__.constructor.apply(this, arguments); 1684 } 1685 1686 IframeObjectView.prototype.waitForLoad = true; 1687 1688 IframeObjectView.prototype.supportsOversizing = false;
1689 1690 IframeObjectView.prototype.className = 'uberbox-iframe-content'; 1691 1692 IframeObjectView.prototype.ui = { 1693 iframe: 'iframe' 1694 }; 1695 1696 IframeObjectView.prototype.template = function() { 1697 return Uberbox.Templates['content-iframe']; 1698 }; 1699 1700 IframeObjectView.prototype.bindUIElements = function() { 1701 IframeObjectView.__super__.bindUIElements.apply(this, arguments); 1702 this.ui.iframe.one('load.uberbox', this.onObjectLoaded); 1703 if (this.isObjectLoaded()) { 1704 this.onObjectLoaded(); 1705 } 1706 jQuery(window).on('resize.uberbox', this.onWindowResized); 1707 return _.defer((function(_this) { 1708 return function() { 1709 return _this.onWindowResized(); 1710 }; 1711 })(this)); 1712 }; 1713 1714 IframeObjectView.prototype.unbindUIElements = function() { 1715 this.ui.iframe.off('load.uberbox'); 1716 return jQuery(window).off('resize.uberbox'); 1717 }; 1718 1719 IframeObjectView.prototype.getObjectWidth = function() { 1720 return this.ui.iframe.width(); 1721 }; 1722 1723 IframeObjectView.prototype.isObjectLoaded = function() { 1724 return this.ui.iframe[0].complete; 1725 }; 1726 1727 IframeObjectView.prototype.serializeData = function() { 1728 return _.extend(IframeObjectView.__super__.serializeData.apply(this, arguments), { 1729 url: this.getIframeUrl() 1730 }); 1731 }; 1732 1733 IframeObjectView.prototype.onWindowResized = function() { 1734 return this.ui.iframe.height(Math.min(this.ui.iframe.width() / this.getObjectNaturalAspectRatio(), this.$el.height())); 1735 }; 1736 1737 IframeObjectView.prototype.getIframeUrl = function() { 1738 return this.model.get('url'); 1739 }; 1740 1741 IframeObjectView.prototype.getObjectNaturalWidth = function() { 1742 return this.$el.parent().width(); 1743 }; 1744 1745 IframeObjectView.prototype.getObjectNaturalHeight = function() { 1746 return this.$el.parent().height(); 1747 }; 1748 1749 return IframeObjectView; 1750 1751 })(ObjectView); 1752 1753 Uberbox.YoutubeObjectView = (function(superClass) { 1754 extend(YoutubeObjectView, superClass); 1755 1756 function YoutubeObjectView() { 1757 return YoutubeObjectView.__super__.constructor.apply(this, arguments); 1758 } 1759 1760 YoutubeObjectView.prototype.className = 'uberbox-iframe-content uberbox-youtube-content'; 1761 1762 YoutubeObjectView.prototype.getIframeUrl = function() { 1763 return "//www.youtube.com/embed/" + (this.getVideoID()); 1764 }; 1765 1766 YoutubeObjectView.prototype.getVideoID = function() { 1767 var regex, url; 1768 url = this.model.get('url'); 1769 if (url.match(regex = /.*(\(\/\/)?(www\.)?youtube\.com\/watch\?v=/i)) { 1770 return url.replace(regex, ''); 1771 } else { 1772 return url.replace(/.*(\/\/)(www\.)?youtu\.be\/.*/i, ''); 1773 } 1774 }; 1775 1776 YoutubeObjectView.prototype.getObjectNaturalAspectRatio = function() { 1777 return 16.0 / 9.0; 1778 }; 1779 1780 return YoutubeObjectView; 1781 1782 })(Uberbox.IframeObjectView); 1783 1784 Uberbox.VimeoObjectView = (function(superClass) { 1785 extend(VimeoObjectView, superClass); 1786 1787 function VimeoObjectView() { 1788 return VimeoObjectView.__super__.constructor.apply(this, arguments); 1789 } 1790 1791 VimeoObjectView.prototype.className = 'uberbox-iframe-content uberbox-vimeo-content'; 1792 1793 VimeoObjectView.prototype.getIframeUrl = function() { 1794 return "//player.vimeo.com/video/" + (this.getVideoID()); 1795 }; 1796 1797 VimeoObjectView.prototype.getVideoID = function() { 1798 return this.model.get('url').replace(/(https?:)?(\/\/)?vimeo\.com\//i, ''); 1799 }; 1800 1801 VimeoObjectView.prototype.getObjectNaturalAspectRatio = function() { 1802 return 16.0 / 9.0; 1803 }; 1804 1805 return VimeoObjectView; 1806 1807 })(Uberbox.IframeObjectView); 1808 1809 Uberbox.GoogleMapsObjectView = (function(superClass) { 1810 extend(GoogleMapsObjectView, superClass); 1811 1812 function GoogleMapsObjectView() { 1813 return GoogleMapsObjectView.__super__.constructor.apply(this, arguments); 1814 } 1815 1816 GoogleMapsObjectView.prototype.className = 'uberbox-iframe-content uberbox-gmap-content'; 1817 1818 GoogleMapsObjectView.prototype.getIframeUrl = function() { 1819 return "https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d17445.16630767115!2d60.755398270861825!3d56.86916950021604!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sru!4v1429115765389"; 1820 }; 1821 1822 GoogleMapsObjectView.prototype.getObjectNaturalAspectRatio = function() { 1823 return this.$el.parent().width() / this.$el.parent().height(); 1824 }; 1825 1826 return GoogleMapsObjectView; 1827 1828 })(Uberbox.IframeObjectView); 1829 1830 Uberbox.SoundcloudObjectView = (function(superClass) { 1831 extend(SoundcloudObjectView, superClass); 1832 1833 function SoundcloudObjectView() { 1834 return SoundcloudObjectView.__super__.constructor.apply(this, arguments); 1835 } 1836 1837 SoundcloudObjectView.prototype.className = 'uberbox-iframe-content uberbox-soundcloud-content'; 1838 1839 SoundcloudObjectView.prototype.getIframeUrl = function() { 1840 return "//w.soundcloud.com/player/?url=" + encodeURIComponent(this.model.get('url')); 1841 }; 1842 1843 return SoundcloudObjectView; 1844 1845 })(Uberbox.IframeObjectView); 1846 1847 Uberbox.BandcampObjectView = (function(superClass) { 1848 extend(BandcampObjectView, superClass); 1849 1850 function BandcampObjectView() { 1851 return BandcampObjectView.__super__.constructor.apply(this, arguments); 1852 } 1853 1854 BandcampObjectView.prototype.className = 'uberbox-iframe-content uberbox-bandcamp-content'; 1855 1856 BandcampObjectView.prototype.getIframeUrl = function() { 1857 return this.model.get('url'); 1858 }; 1859 1860 return BandcampObjectView; 1861 1862 })(Uberbox.IframeObjectView); 1863 1864 Uberbox.HTMLObjectView = (function(superClass) { 1865 extend(HTMLObjectView, superClass); 1866 1867 function HTMLObjectView() { 1868 return HTMLObjectView.__super__.constructor.apply(this, arguments); 1869 } 1870 1871 HTMLObjectView.prototype.className = 'uberbox-html-content'; 1872 1873 HTMLObjectView.prototype.waitForLoad = false;
1874 1875 HTMLObjectView.prototype.template = function() { 1876 return Uberbox.Templates['content-html']; 1877 }; 1878 1879 HTMLObjectView.prototype.getObjectNaturalWidth = function() { 1880 return 650; 1881 }; 1882 1883 HTMLObjectView.prototype.getObjectNaturalHeight = function() { 1884 return 400; 1885 }; 1886 1887 return HTMLObjectView; 1888 1889 })(ObjectView); 1890 1891 Uberbox.AJAXOBjectView = (function(superClass) { 1892 extend(AJAXOBjectView, superClass); 1893 1894 function AJAXOBjectView() { 1895 this.layout = bind(this.layout, this); 1896 return AJAXOBjectView.__super__.constructor.apply(this, arguments); 1897 } 1898 1899 AJAXOBjectView.prototype.className = 'uberbox-ajax-content'; 1900 1901 AJAXOBjectView.prototype.waitForLoad = true; 1902 1903 AJAXOBjectView.prototype.template = function() { 1904 return Uberbox.Templates['content-html']; 1905 }; 1906 1907 AJAXOBjectView.prototype.bindUIElements = function() { 1908 AJAXOBjectView.__super__.bindUIElements.apply(this, arguments); 1909 jQuery.get(this.model.get('url'), (function(_this) { 1910 return function(response) { 1911 _this.$el.html(response); 1912 _this.trigger('load'); 1913 return _this.layout(); 1914 }; 1915 })(this)); 1916 return jQuery(window).on('resize', this.layout); 1917 }; 1918 1919 AJAXOBjectView.prototype.layout = function() { 1920 if (this.$el.height() < this.$el.parent().height()) { 1921 return this.$el.addClass('uberbox-center-vertical'); 1922 } else { 1923 return this.$el.addClass('uberbox-scroll').removeClass('uberbox-center-vertical'); 1924 } 1925 }; 1926 1927 return AJAXOBjectView; 1928 1929 })(ObjectView); 1930 1931 Uberbox.UnknownItemView = (function(superClass) { 1932 extend(UnknownItemView, superClass); 1933 1934 function UnknownItemView() { 1935 return UnknownItemView.__super__.constructor.apply(this, arguments); 1936 } 1937 1938 UnknownItemView.prototype.className = 'uberbox-unknown-content'; 1939 1940 UnknownItemView.prototype.template = function() { 1941 return Uberbox.Templates['content-unknown']; 1942 }; 1943 1944 UnknownItemView.prototype.waitForLoad = false; 1945 1946 UnknownItemView.prototype.showContent = function() {}; 1947 1948 UnknownItemView.prototype.getObjectNaturalWidth = function() { 1949 return this.$el.parent().width(); 1950 }; 1951 1952 UnknownItemView.prototype.getObjectNaturalHeight = function() { 1953 return this.$el.parent().height(); 1954 }; 1955 1956 return UnknownItemView; 1957 1958 })(ObjectView); 1959 1960 var bind = function(fn, me) { 1961 return function() { 1962 return fn.apply(me, arguments); 1963 }; 1964 }, 1965 extend = function(child, parent) { 1966 for (var key in parent) { 1967 if (hasProp.call(parent, key)) child[key] = parent[key]; 1968 } 1969 1970 function ctor() { 1971 this.constructor = child; 1972 } 1973 ctor.prototype = parent.prototype; 1974 child.prototype = new ctor(); 1975 child.__super__ = parent.prototype; 1976 return child; 1977 }, 1978 hasProp = {}.hasOwnProperty; 1979 1980 Uberbox.Lightbox = (function(superClass) { 1981 extend(Lightbox, superClass); 1982 1983 function Lightbox() { 1984 this.layout = bind(this.layout, this); 1985 return Lightbox.__super__.constructor.apply(this, arguments); 1986 } 1987 1988 Lightbox.prototype.className = 'uberbox-lightbox-content'; 1989 1990 Lightbox.prototype.template = function() { 1991 return Uberbox.Templates['lightbox-content']; 1992 }; 1993 1994 Lightbox.prototype.ui = { 1995 next: '.uberbox-next', 1996 prev: '.uberbox-prev' 1997 }; 1998 1999 Lightbox.prototype.events = { 2000 'click @ui.next': (function() { 2001 if (!this.ui.next.is('.uberbox-disabled')) { 2002 return this.currentItemView.model.next().activate(); 2003 } 2004 }), 2005 'click @ui.prev': (function() { 2006 if (!this.ui.prev.is('.uberbox-disabled')) { 2007 return this.currentItemView.model.prev().activate(); 2008 } 2009 }) 2010 }; 2011 2012 Lightbox.prototype.getChildViewClass = function() { 2013 return Uberbox.LightboxItem; 2014 }; 2015 2016 Lightbox.prototype.onShow = function() { 2017 Lightbox.__super__.onShow.apply(this, arguments); 2018 this.render(); 2019 return this.bindUIElements(); 2020 }; 2021 2022 Lightbox.prototype.render = function() { 2023 return this.$el.html(Marionette.Renderer.render(this.template)); 2024 }; 2025 2026 Lightbox.prototype.onItemActivated = function(item) { 2027 if (!this.currentItemView) { 2028 this.currentItemView = this.createChildView(item); 2029 if (item.next()) { 2030 this.nextItemView = this.createChildView(item.next(), { 2031 prev: this.currentItemView 2032 }); 2033 } 2034 if (item.prev()) { 2035 this.prevItemView = this.createChildView(item.prev(), { 2036 prev: this.currentItemView 2037 }); 2038 } 2039 } else { 2040 if (item.follows(this.currentItemView.model)) { 2041 this.scrollNext(item); 2042 } else { 2043 this.scrollPrev(item); 2044 } 2045 } 2046 if (this.currentItemView.model.next()) { 2047 this.ui.next.removeClass('uberbox-disabled'); 2048 } else { 2049 this.ui.next.addClass('uberbox-disabled'); 2050 } 2051 if (this.currentItemView.model.prev()) { 2052 return this.ui.prev.removeClass('uberbox-disabled'); 2053 } else { 2054 return this.ui.prev.addClass('uberbox-disabled'); 2055 } 2056 }; 2057 2058 Lightbox.prototype.checkPrevNext = function() {}; 2059 2060 Lightbox.prototype.scrollNext = function(item) { 2061 var current, previousCurrent; 2062 if (this.prevItemView) { 2063 this.prevItemView.remove(); 2064 } 2065 if (this.currentItemView.model.isPrev(item)) { 2066 this.prevItemView = this.currentItemView; 2067 this.prevItemView.layout(); 2068 this.currentItemView = this.nextItemView; 2069 this.currentItemView.layout(); 2070 this.currentItemView = this.nextItemView; 2071 if (this.currentItemView.model.next()) { 2072 return this.nextItemView = this.createChildView(this.currentItemView.model.next(), { 2073 prev: this.currentItemView 2074 }); 2075 } else { 2076 return this.nextItemView = null; 2077 } 2078 } else { 2079 if (this.nextItemView) { 2080 this.nextItemView.remove(); 2081 } 2082 previousCurrent = this.currentItemView; 2083 previousCurrent.layout(); 2084 setTimeout((function() { 2085 return previousCurrent.remove(); 2086 }), 500); 2087 current = this.currentItemView = this.createChildView(item); 2088 if (item.prev()) { 2089 this.prevItemView = this.createChildView(item.prev(), { 2090 next: this.currentItemView 2091 }); 2092 } 2093 if (item.next()) { 2094 return this.nextItemView = this.createChildView(item.next(), { 2095 prev: this.currentItemView 2096 }); 2097 } 2098 } 2099 }; 2100 2101 Lightbox.prototype.scrollPrev = function(item) { 2102 var current, previousCurrent; 2103 if (this.nextItemView) { 2104 this.nextItemView.remove(); 2105 } 2106 if (this.currentItemView.model.isNext(item)) { 2107 this.nextItemView = this.currentItemView; 2108 this.nextItemView.layout(); 2109 this.currentItemView = this.prevItemView; 2110 this.currentItemView.layout(); 2111 this.currentItemView = this.prevItemView; 2112 if (this.currentItemView.model.prev()) { 2113 return this.prevItemView = this.createChildView(this.currentItemView.model.prev(), { 2114 next: this.currentItemView 2115 }); 2116 } else { 2117 return this.prevItemView = null; 2118 } 2119 } else { 2120 if (this.prevItemView) { 2121 this.prevItemView.remove(); 2122 } 2123 previousCurrent = this.currentItemView; 2124 previousCurrent.layout(); 2125 setTimeout((function() { 2126 return previousCurrent.remove(); 2127 }), 500); 2128 current = this.currentItemView = this.createChildView(item); 2129 if (item.next()) { 2130 this.nextItemView = this.createChildView(item.next(), { 2131 prev: this.currentItemView 2132 }); 2133 } 2134 if (item.prev()) { 2135 return this.prevItemView = this.createChildView(item.prev(), { 2136 next: this.currentItemView 2137 }); 2138 } 2139 } 2140 }; 2141 2142 Lightbox.prototype.layout = function() { 2143 if (!this.$el.is(':visible')) { 2144 return; 2145 } 2146 this.currentItemView.layout(); 2147 return _.defer((function(_this) { 2148 return function() { 2149 if (_this.nextItemView) { 2150 _this.nextItemView.layout(); 2151 } 2152 if (_this.prevItemView) { 2153 return _this.prevItemView.layout(); 2154 } 2155 }; 2156 })(this)); 2157 }; 2158 2159 return Lightbox; 2160 2161 })(Uberbox.SlidingWindow); 2162 2163 Uberbox.LightboxItem = (function(superClass) { 2164 extend(LightboxItem, superClass); 2165 2166 function LightboxItem() { 2167 this.remove = bind(this.remove, this); 2168 this.layoutContent = bind(this.layoutContent, this); 2169 return LightboxItem.__super__.constructor.apply(this, arguments); 2170 } 2171 2172 LightboxItem.prototype.defaults = { 2173 description: { 2174 position: 'right' 2175 } 2176 }; 2177 2178 LightboxItem.prototype.template = function() { 2179 return Uberbox.Templates['lightbox-item']; 2180 }; 2181 2182 LightboxItem.prototype.className = 'uberbox-lightbox-item'; 2183 2184 LightboxItem.prototype.regions = { 2185 object: '.uberbox-item-object', 2186 description: '.uberbox-item-description' 2187 }; 2188 2189 LightboxItem.prototype.ui = { 2190 content: '> .uberbox-lightbox-item-content-wrapper', 2191 description: '.uberbox-item-description' 2192 }; 2193 2194 LightboxItem.prototype.padding = 20; 2195 2196 LightboxItem.prototype.initialize = function() { 2197 LightboxItem.__super__.initialize.apply(this, arguments); 2198 return this.once('load', (function(_this) { 2199 return function() { 2200 return _this.model.set('loaded', true); 2201 }; 2202 })(this)); 2203 }; 2204 2205 LightboxItem.prototype.serializeData = function() { 2206 return { 2207 model: this.model 2208 }; 2209 }; 2210 2211 LightboxItem.prototype.layoutContent = function() { 2212 var height, width; 2213 if (this.waitForLoad && !this.loaded) { 2214 return; 2215 } 2216 width = this.$el.width(); 2217 height = this.$el.height(); 2218 if (width === 0 || height === 0) { 2219 return; 2220 } 2221 if (this.model.get('description_style') === 'right') { 2222 return this.layoutWithDescriptionAtRight(); 2223 } else if (this.model.get('description_style') === 'mini') { 2224 return this.layoutWithMiniDescription(); 2225 } else if (this.model.get('description_style') === 'bottom') { 2226 return this.layoutWithDescriptionAtBottom(); 2227 } 2228 }; 2229 2230 LightboxItem.prototype.getOffset = function() { 2231 var offset; 2232 if (this.model.get('description_style') === 'mini') { 2233 return this.object.currentView.getOffset(); 2234 } 2235 offset = this.ui.content.offset(); 2236 offset.top -= jQuery(window).scrollTop(); 2237 return offset; 2238 }; 2239 2240 LightboxItem.prototype.getWidth = function() { 2241 if (this.model.get('description_style') === 'bottom') { 2242 return this.object.currentView.$el.width(); 2243 } 2244 if (this.model.get('description_style') === 'mini') { 2245 return this.object.currentView.getWidth(); 2246 } 2247 return this.ui.content.width(); 2248 }; 2249 2250 LightboxItem.prototype.swipeVertically = function(amount) { 2251 return this.$el.css({ 2252 transform: "translate(0, " + amount + "px)",
2253 '-webkit-transform': "translate(0, " + amount + "px)", 2254 '-moz-transform': "translate(0, " + amount + "px)" 2255 }); 2256 }; 2257 2258 LightboxItem.prototype.swipeHorizontally = function(amount) { 2259 return this.$el.css({ 2260 transform: "translate(" + amount + "px, 0)", 2261 '-webkit-transform': "translate(" + amount + "px, 0)", 2262 '-moz-transform': "translate(" + amount + "px, 0)" 2263 }); 2264 }; 2265 2266 LightboxItem.prototype.swipeBack = function() { 2267 return this.$el.css({ 2268 transform: "translate(0, 0)" 2269 }); 2270 }; 2271 2272 LightboxItem.prototype.layoutWithDescriptionAtBottom = function() { 2273 var availableAreaAspectRatio, height, objectAspectRatio, width; 2274 if (!this.object.currentView.supportsOversizing) { 2275 this.$el.addClass('uberbox-fit-height'); 2276 return; 2277 } 2278 width = this.object.$el.width(); 2279 height = this.object.$el.height(); 2280 objectAspectRatio = this.object.currentView.getObjectNaturalAspectRatio(); 2281 availableAreaAspectRatio = width / height; 2282 this.fitOversized(); 2283 if (this.$el.height() < this.$el.parent().height()) { 2284 return this.$el.addClass('uberbox-center-vertically'); 2285 } else { 2286 return this.$el.removeClass('uberbox-center-vertically'); 2287 } 2288 }; 2289 2290 LightboxItem.prototype.layoutWithMiniDescription = function() { 2291 var availableRatio, height, item, objectRatio, objectView, width; 2292 width = this.object.$el.width(); 2293 height = this.object.$el.height(); 2294 item = this.$el.closest('.uberbox-lightbox-item'); 2295 objectView = this.object.currentView; 2296 this.$el.css('margin-left', ''); 2297 if (objectView.getObjectNaturalWidth() < width && objectView.getObjectNaturalHeight() < height) { 2298 return this.fitNaturally(); 2299 } else { 2300 availableRatio = objectView.$el.width() / objectView.$el.height(); 2301 objectRatio = objectView.getObjectNaturalAspectRatio(); 2302 if (availableRatio > objectRatio) { 2303 return this.fitHeight(); 2304 } else { 2305 return this.fitWidth(); 2306 } 2307 } 2308 }; 2309 2310 LightboxItem.prototype.layoutWithDescriptionAtRight = function() { 2311 var availableAreaAspectRatio, availableAreaWidth, containerHeight, content, contentHeight, height, objectAspectRatio, width; 2312 if (!this.object.currentView.supportsOversizing) { 2313 this.$el.addClass('uberbox-skin-dark'); 2314 return; 2315 } 2316 width = this.$el.width(); 2317 height = this.$el.height(); 2318 if (jQuery(window).width() < 1024) { 2319 containerHeight = this.$('.uberbox-item-object > *').height(); 2320 contentHeight = (content = this.$('.uberbox-item-object > * > *')).height(); 2321 if (containerHeight < contentHeight) { 2322 return content.css('margin-top', -(contentHeight - containerHeight) / 2); 2323 } 2324 } else { 2325 objectAspectRatio = this.object.currentView.getObjectNaturalAspectRatio(); 2326 availableAreaWidth = width - this.ui.description.width(); 2327 availableAreaAspectRatio = availableAreaWidth / height; 2328 return this.fitOversized(); 2329 } 2330 }; 2331 2332 LightboxItem.prototype.fitHeight = function() { 2333 return this.$el.addClass('uberbox-fit-height').removeClass('uberbox-fit-width uberbox-natural-fit uberbox-fit-oversized uberbox-fit-height-oversized uberbox-fit-width-oversized'); 2334 }; 2335 2336 LightboxItem.prototype.fitWidth = function() { 2337 return this.$el.addClass('uberbox-fit-width').removeClass('uberbox-fit-height uberbox-natural-fit uberbox-fit-oversized uberbox-fit-height-oversized uberbox-fit-width-oversized'); 2338 }; 2339 2340 LightboxItem.prototype.fitNaturally = function() { 2341 return this.$el.removeClass('uberbox-fit-width uberbox-fit-height uberbox-natural-fit uberbox-fit-height-oversized uberbox-fit-width-oversized uberbox-fit-oversized').addClass('uberbox-natural-fit'); 2342 }; 2343
2344 LightboxItem.prototype.fitOversized = function() { 2345 this.$el.addClass('uberbox-fit-oversized').removeClass('uberbox-fit-width uberbox-fit-height'); 2346 if (this.object.currentView.getObjectNaturalAspectRatio() > this.object.currentView.getAspectRatio()) { 2347 return this.$el.addClass('uberbox-fit-height-oversized').removeClass('uberbox-fit-width-oversized'); 2348 } else { 2349 return this.$el.addClass('uberbox-fit-width-oversized').removeClass('uberbox-fit-height-oversized'); 2350 } 2351 }; 2352 2353 LightboxItem.prototype.showRegions = function() { 2354 var type; 2355 type = Uberbox.getObjectViewType(this.model); 2356 if (this.model.get('description') && this.model.get('description_style') !== 'none') { 2357 this.$el.addClass('uberbox-has-description'); 2358 this.$el.addClass("uberbox-description-" + (this.model.get('description_style'))); 2359 } else { 2360 this.$el.addClass('uberbox-no-description'); 2361 } 2362 this.object.show(new type(_.extend(this.options, { 2363 model: this.model 2364 }))); 2365 if (this.object.currentView.waitForLoad) { 2366 return this.listenToOnce(this.object.currentView, 'load', (function(_this) { 2367 return function() { 2368 return _this.trigger('load'); 2369 }; 2370 })(this)); 2371 } else { 2372 return _.defer((function(_this) { 2373 return function() { 2374 return _this.trigger('load'); 2375 }; 2376 })(this)); 2377 } 2378 }; 2379 2380 LightboxItem.prototype.layout = function() { 2381 if (this.isCurrent()) { 2382 this.positionAsCurrent(); 2383 } else if (this.isNext()) { 2384 this.positionAsNext(); 2385 } else if (this.isPrev()) { 2386 this.positionAsPrev(); 2387 } else { 2388 setTimeout(this.remove, 400); 2389 return; 2390 } 2391 return this.layoutContent(); 2392 }; 2393 2394 LightboxItem.prototype.isVertical = function() { 2395 return this.getOption('orientation') === 'vertical'; 2396 }; 2397 2398 LightboxItem.prototype.positionAsCurrent = function() { 2399 return this.$el.css({ 2400 transform: '' 2401 }); 2402 }; 2403 2404 LightboxItem.prototype.positionAsNext = function() { 2405 if (this.isVertical()) { 2406 return this.$el.css({ 2407 transform: "translate(0, " + (jQuery(window).height()) + "px)" 2408 }); 2409 } else { 2410 return this.$el.css({ 2411 transform: "translate(" + (jQuery(window).width()) + "px, 0)" 2412 }); 2413 } 2414 }; 2415 2416 LightboxItem.prototype.positionAsPrev = function() { 2417 if (this.isVertical()) { 2418 return this.$el.css({ 2419 transform: "translate(0, -" + (jQuery(window).height()) + "px)" 2420 }); 2421 } else { 2422 return this.$el.css({ 2423 transform: "translate(-" + (jQuery(window).width()) + "px, 0)" 2424 }); 2425 } 2426 }; 2427 2428 LightboxItem.prototype.remove = function() { 2429 if (this.model.isNext()) { 2430 this.$el.addClass('uberbox-flyout-next'); 2431 } 2432 if (this.model.isPrev()) { 2433 this.$el.addClass('uberbox-flyout-prev'); 2434 } 2435 if (this.getOption('next')) { 2436 this.getOption('next').options.prev = null; 2437 } 2438 if (this.getOption('prev')) { 2439 this.getOption('prev').options.next = null; 2440 } 2441 return setTimeout(((function(_this) { 2442 return function() { 2443 return LightboxItem.__super__.remove.call(_this); 2444 }; 2445 })(this)), 600); 2446 }; 2447 2448 return LightboxItem; 2449 2450 })(Uberbox.SlidingWindowItem); 2451 2452 if (root.Uberbox) { 2453 Uberbox.Templates = root.Uberbox.Templates; 2454 } 2455 return Uberbox; 2456}));
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.