/* * nivo lightbox v1.3.1 * http://dev7studios.com/nivo-lightbox * * copyright 2013, dev7studios * free to use and abuse under the mit license. * http://www.opensource.org/licenses/mit-license.php */ ;(function($, window, document, undefined){ var pluginname = 'nivolightbox', defaults = { effect: 'fade', theme: 'default', keyboardnav: true, clickimgtoclose: false, clickoverlaytoclose: true, oninit: function(){}, beforeshowlightbox: function(){}, aftershowlightbox: function(lightbox){}, beforehidelightbox: function(){}, afterhidelightbox: function(){}, beforeprev: function(element){}, onprev: function(element){}, beforenext: function(element){}, onnext: function(element){}, errormessage: 'the requested content cannot be loaded. please try again later.' }; function nivolightbox(element, options){ this.el = element; this.$el = $(this.el); this.options = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginname; this.init(); } nivolightbox.prototype = { init: function(){ var $this = this; // need this so we don't use css transitions in mobile if(!$('html').hasclass('nivo-lightbox-notouch')) $('html').addclass('nivo-lightbox-notouch'); if('ontouchstart' in document) $('html').removeclass('nivo-lightbox-notouch'); // setup the click this.$el.on('click', function(e){ $this.showlightbox(e); }); // keyboardnav if(this.options.keyboardnav){ $('body').off('keyup').on('keyup', function(e){ var code = (e.keycode ? e.keycode : e.which); // escape if(code == 27) $this.destructlightbox(); // left if(code == 37) $('.nivo-lightbox-prev').trigger('click'); // right if(code == 39) $('.nivo-lightbox-next').trigger('click'); }); } this.options.oninit.call(this); }, showlightbox: function(e){ var $this = this, currentlink = this.$el; // check content var check = this.checkcontent(currentlink); if(!check) return; e.preventdefault(); this.options.beforeshowlightbox.call(this); var lightbox = this.constructlightbox(); if(!lightbox) return; var content = lightbox.find('.nivo-lightbox-content'); if(!content) return; $('body').addclass('nivo-lightbox-body-effect-'+ this.options.effect); this.processcontent( content, currentlink ); // nav if(this.$el.attr('data-lightbox-gallery')){ var galleryitems = $('[data-lightbox-gallery="'+ this.$el.attr('data-lightbox-gallery') +'"]'); $('.nivo-lightbox-nav').show(); // prev $('.nivo-lightbox-prev').off('click').on('click', function(e){ e.preventdefault(); var index = galleryitems.index(currentlink); currentlink = galleryitems.eq(index - 1); if(!$(currentlink).length) currentlink = galleryitems.last(); $.when($this.options.beforeprev.call(this, [ currentlink ])).done(function(){ $this.processcontent(content, currentlink); $this.options.onprev.call(this, [ currentlink ]); }); }); // next $('.nivo-lightbox-next').off('click').on('click', function(e){ e.preventdefault(); var index = galleryitems.index(currentlink); currentlink = galleryitems.eq(index + 1); if(!$(currentlink).length) currentlink = galleryitems.first(); $.when($this.options.beforenext.call(this, [ currentlink ])).done(function(){ $this.processcontent(content, currentlink); $this.options.onnext.call(this, [ currentlink ]); }); }); } settimeout(function(){ lightbox.addclass('nivo-lightbox-open'); $this.options.aftershowlightbox.call(this, [ lightbox ]); }, 1); // for css transitions }, checkcontent: function( link ) { var $this = this, href = link.attr('href'), video = href.match(/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/); if(href.match(/\.(jpeg|jpg|gif|png)$/i) !== null){ return true; } // video (youtube/vimeo) else if(video){ return true; } // ajax else if(link.attr('data-lightbox-type') == 'ajax'){ return true; } // inline html else if(href.substring(0, 1) == '#' && link.attr('data-lightbox-type') == 'inline'){ return true; } // iframe (default) else if(link.attr('data-lightbox-type') == 'iframe'){ return true; } return false; }, processcontent: function(content, link){ var $this = this, href = link.attr('href'), video = href.match(/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/); content.html('').addclass('nivo-lightbox-loading'); // is hidpi? if(this.ishidpi() && link.attr('data-lightbox-hidpi')){ href = link.attr('data-lightbox-hidpi'); } // image if(href.match(/\.(jpeg|jpg|gif|png)$/i) !== null){ var img = $('', { src: href, 'class': 'nivo-lightbox-image-display' }); img.one('load', function() { var wrap = $('
'); wrap.append(img); content.html(wrap).removeclass('nivo-lightbox-loading'); // vertically center images wrap.css({ 'line-height': $('.nivo-lightbox-content').height() +'px', 'height': $('.nivo-lightbox-content').height() +'px' // for firefox }); $(window).resize(function() { wrap.css({ 'line-height': $('.nivo-lightbox-content').height() +'px', 'height': $('.nivo-lightbox-content').height() +'px' // for firefox }); }); }).each(function() { if(this.complete) $(this).load(); }); img.error(function() { var wrap = $(''+ $this.options.errormessage +'