From 79bb76c8a78c2b83429829db88db7f2f5869144e Mon Sep 17 00:00:00 2001 From: Gilbert Pellegrom Date: Thu, 15 May 2014 11:48:28 +0100 Subject: [PATCH] v1.2.0 * [Changed] iFrames and inline HTML now need a data-lightbox-type * [Changed] Nivo Lightbox now checks for content before overriding links * [Fixed] IE10 YouTube bug * [Fixed] Code cleanup --- changelog.txt | 8 +- nivo-lightbox.css | 4 +- nivo-lightbox.js | 406 +++++++++++++++++++++---------------------- nivo-lightbox.min.js | 16 +- 4 files changed, 213 insertions(+), 221 deletions(-) diff --git a/changelog.txt b/changelog.txt index 2bc6632..94ebc15 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,11 @@ *** Nivo Lightbox Changelog *** +2014.05.15 - version 1.2.0 + * [Changed] iFrames and inline HTML now need a data-lightbox-type + * [Changed] Nivo Lightbox now checks for content before overriding links + * [Fixed] IE10 YouTube bug + * [Fixed] Code cleanup + 2013.12.11 - version 1.1 * [New] Added the clickOverlayToClose setting * [New] Uppercase image extensions are now supported @@ -9,4 +15,4 @@ * [Fixed] Inline content overflow bug 2013.08.01 - version 1.0 - * Initial release \ No newline at end of file + * Initial release diff --git a/nivo-lightbox.css b/nivo-lightbox.css index 2948349..f46886f 100644 --- a/nivo-lightbox.css +++ b/nivo-lightbox.css @@ -1,5 +1,5 @@ /* - * Nivo Lightbox v1.1 + * Nivo Lightbox v1.2.0 * http://dev7studios.com/nivo-lightbox * * Copyright 2013, Dev7studios @@ -202,4 +202,4 @@ -moz-transform: translateZ(0); -ms-transform: translateZ(0); transform: translateZ(0); -} \ No newline at end of file +} diff --git a/nivo-lightbox.js b/nivo-lightbox.js index 29582cc..b39e594 100644 --- a/nivo-lightbox.js +++ b/nivo-lightbox.js @@ -1,5 +1,5 @@ /* - * Nivo Lightbox v1.1 + * Nivo Lightbox v1.2.0 * http://dev7studios.com/nivo-lightbox * * Copyright 2013, Dev7studios @@ -11,18 +11,18 @@ var pluginName = 'nivoLightbox', defaults = { - effect: 'fade', - theme: 'default', - keyboardNav: true, - clickOverlayToClose: true, - onInit: function(){}, - beforeShowLightbox: function(){}, - afterShowLightbox: function(lightbox){}, - beforeHideLightbox: function(){}, - afterHideLightbox: function(){}, - onPrev: function(element){}, - onNext: function(element){}, - errorMessage: 'The requested content cannot be loaded. Please try again later.' + effect: 'fade', + theme: 'default', + keyboardNav: true, + clickOverlayToClose: true, + onInit: function(){}, + beforeShowLightbox: function(){}, + afterShowLightbox: function(lightbox){}, + beforeHideLightbox: function(){}, + afterHideLightbox: function(){}, + onPrev: function(element){}, + onNext: function(element){}, + errorMessage: 'The requested content cannot be loaded. Please try again later.' }; function NivoLightbox(element, options){ @@ -48,19 +48,19 @@ // Setup the click this.$el.on('click', function(e){ - $this.showLightbox( 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'); + 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'); }); } @@ -68,19 +68,16 @@ }, - showLightbox: function( e ){ - var $this = this; - this.options.beforeShowLightbox.call(this); + showLightbox: function(e){ + var $this = this, + currentLink = this.$el; - var currentLink = this.$el; - - // check content - var check = this.checkContent( currentLink ); - - if ( ! check ) return; + // 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'); @@ -90,49 +87,49 @@ this.processContent( content, currentLink ); - // Nav - if(this.$el.attr('data-lightbox-gallery')){ - var $this = this, - galleryItems = $('[data-lightbox-gallery="'+ this.$el.attr('data-lightbox-gallery') +'"]'); + // Nav + if(this.$el.attr('data-lightbox-gallery')){ + var galleryItems = $('[data-lightbox-gallery="'+ this.$el.attr('data-lightbox-gallery') +'"]'); - $('.nivo-lightbox-nav').show(); + $('.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(); - $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(); - $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 + $('.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(); + $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(); + $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; - var href = link.attr('href'); + var $this = this, + href = link.attr('href'), + video = href.match(/(youtube|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/); - if(href.match(/\.(jpeg|jpg|gif|png)$/i) != null){ + if(href.match(/\.(jpeg|jpg|gif|png)$/i) !== null){ return true; } // Video (Youtube/Vimeo) - else if(video = href.match(/(youtube|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/)){ + else if(video){ return true; } // AJAX @@ -152,21 +149,23 @@ }, processContent: function(content, link){ - var $this = this; - var href = link.attr('href'); - 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 }); - img.one('load', function() { + var $this = this, + href = link.attr('href'), + video = href.match(/(youtube|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 }); + img.one('load', function() { var wrap = $('
'); - wrap.append(img); + wrap.append(img); content.html(wrap).removeClass('nivo-lightbox-loading'); // Vertically center images @@ -186,43 +185,42 @@ img.error(function() { var wrap = $('

'+ $this.options.errorMessage +'

'); - content.html(wrap).removeClass('nivo-lightbox-loading'); + content.html(wrap).removeClass('nivo-lightbox-loading'); }); - } - // Video (Youtube/Vimeo) - else if(video = href.match(/(youtube|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/)){ - var src = '', - classTerm = 'nivo-lightbox-video'; - - if(video[1] == 'youtube'){ - src = 'http://www.youtube.com/embed/'+ video[4]; - classTerm = 'nivo-lightbox-youtube'; - } - if(video[1] == 'youtu'){ - src = 'http://www.youtube.com/embed/'+ video[3]; - classTerm = 'nivo-lightbox-youtube'; - } - if(video[1] == 'vimeo'){ - src = 'http://player.vimeo.com/video/'+ video[3]; - classTerm = 'nivo-lightbox-vimeo'; - } - - if(src){ - var iframe = $('