PageSourceSearch

http://cricket59.com/wp-content/themes/accesspress-mag/js/lightbox/nivo-lightbox.js?ver=1.2.0

js cricket59.com collected 2026-10-05 18:42:19 UTC 13,792 bytes, 393 lines download raw bytes

1/*
2 * Nivo Lightbox v1.2.0
3 * http://dev7studios.com/nivo-lightbox
4 *
5 * Copyright 2013, Dev7studios
6 * Free to use and abuse under the MIT license.
7 * http://www.opensource.org/licenses/mit-license.php
8 */
9
10;(function($, window, document, undefined){
11
12    var pluginName = 'nivoLightbox',
13        defaults = {
14            effect: 'fade',
15            theme: 'default',
16            keyboardNav: true,
17            clickOverlayToClose: true,
18            onInit: function(){},
19            beforeShowLightbox: function(){},
20            afterShowLightbox: function(lightbox){},
21            beforeHideLightbox: function(){},
22            afterHideLightbox: function(){},
23            onPrev: function(element){},
24            onNext: function(element){},
25            errorMessage: 'The requested content cannot be loaded. Please try again later.'
26        };
27
28    function NivoLightbox(element, options){
29        this.el = element;
30        this.$el = $(this.el);
31
32        this.options = $.extend({}, defaults, options);
33
34        this._defaults = defaults;
35        this._name = pluginName;
36
37        this.init();
38    }
39
40    NivoLightbox.prototype = {
41
42        init: function(){
43			var $this = this;
44
45			// Need this so we don't use CSS transitions in mobile
46			if(!$('html').hasClass('nivo-lightbox-notouch')) $('html').addClass('nivo-lightbox-notouch');
47			if('ontouchstart' in document) $('html').removeClass('nivo-lightbox-notouch');
48
49			// Setup the click
50            this.$el.on('click', function(e){
51                $this.showLightbox(e);
52            });
53
54            // keyboardNav
55            if(this.options.keyboardNav){
56                $('body').off('keyup').on('keyup', function(e){
57                    var code = (e.keyCode ? e.keyCode : e.which);
58                    // Escape
59                    if(code == 27) $this.destructLightbox();
60                    // Left
61                    if(code == 37) $('.nivo-lightbox-prev').trigger('click');
62                    // Right
63                    if(code == 39) $('.nivo-lightbox-next').trigger('click');
64				});
65			}
66
67			this.options.onInit.call(this);
68
69        },
70
71        showLightbox: function(e){
72            var $this = this,
73                currentLink = this.$el;
74
75			// Check content
76			var check = this.checkContent(currentLink);
77			if(!check) return;
78
79			e.preventDefault();
80            this.options.beforeShowLightbox.call(this);
81            var lightbox = this.constructLightbox();
82            if(!lightbox) return;
83            var content = lightbox.find('.nivo-lightbox-content');
84            if(!content) return;
85
86            $('body').addClass('nivo-lightbox-body-effect-'+ this.options.effect);
87
88			this.processContent( content, currentLink );
89
90            // Nav
91            if(this.$el.attr('data-lightbox-gallery')){
92                var galleryItems = $('[data-lightbox-gallery="'+ this.$el.attr('data-lightbox-gallery') +'"]');
93
94                $('.nivo-lightbox-nav').show();
95
96				// Prev
97                $('.nivo-lightbox-prev').off('click').on('click', function(e){
98                    e.preventDefault();
99                    var index = galleryItems.index(currentLink);
100                    currentLink = galleryItems.eq(index - 1);
101                    if(!$(currentLink).length) currentLink = galleryItems.last();
102                    $this.processContent(content, currentLink);
103                    $this.options.onPrev.call(this, [ currentLink ]);
104                });
105
106                // Next
107                $('.nivo-lightbox-next').off('click').on('click', function(e){
108                    e.preventDefault();
109                    var index = galleryItems.index(currentLink);
110                    currentLink = galleryItems.eq(index + 1);
111                    if(!$(currentLink).length) currentLink = galleryItems.first();
112                    $this.processContent(content, currentLink);
113                    $this.options.onNext.call(this, [ currentLink ]);
114                });
115            }
116
117            setTimeout(function(){
118                lightbox.addClass('nivo-lightbox-open');
119                $this.options.afterShowLightbox.call(this, [ lightbox ]);
120            }, 1); // For CSS transitions
121        },
122
123		checkContent: function( link ) {
124			var $this = this,
125                href = link.attr('href'),
126                video = href.match(/(youtube|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/);
127
128            if(href.match(/\.(jpeg|jpg|gif|png)$/i) !== null){
129				return true;
130			}
131			// Video (Youtube/Vimeo)
132            else if(video){
133				return true;
134			}
135			// AJAX
136			else if(link.attr('data-lightbox-type') == 'ajax'){
137				return true;
138			}
139			// Inline HTML
140			else if(href.substring(0, 1) == '#' && link.attr('data-lightbox-type') == 'inline'){
141				return true;
142			}
143			// iFrame (default)
144			else if(link.attr('data-lightbox-type') == 'iframe'){
145				return true;
146			}
147
148			return false;
149		},
150
151        processContent: function(content, link){
152            var $this = this,
153                href = link.attr('href'),
154                video = href.match(/(youtube|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/);
155
156            content.html('').addClass('nivo-lightbox-loading');
157
158            // Is HiDPI?
159            if(this.isHidpi() && link.attr('data-lightbox-hidpi')){
160                href = link.attr('data-lightbox-hidpi');
161            }
162
163            // Image
164            if(href.match(/\.(jpeg|jpg|gif|png)$/i) !== null){
165                var img = $('<img>', { src: href });
166                img.one('load', function() {
167					var wrap = $('<div class="nivo-lightbox-image" />');
168                    wrap.append(img);
169					content.html(wrap).removeClass('nivo-lightbox-loading');
170
171					// Vertically center images
172					wrap.css({
173						'line-height': $('.nivo-lightbox-content').height() +'px',
174						'height': $('.nivo-lightbox-content').height() +'px' // For Firefox
175					});
176					$(window).resize(function() {
177						wrap.css({
178							'line-height': $('.nivo-lightbox-content').height() +'px',
179							'height': $('.nivo-lightbox-content').height() +'px' // For Firefox
180						});
181					});
182				}).each(function() {
183					if(this.complete) $(this).load();
184				});
185
186				img.error(function() {
187					var wrap = $('<div class="nivo-lightbox-error"><p>'+ $this.options.errorMessage +'</p></div>');
188                    content.html(wrap).removeClass('nivo-lightbox-loading');
189				});
190            }
191            // Video (Youtube/Vimeo)
192            else if(video){
193                var src = '',
194                    classTerm = 'nivo-lightbox-video';
195
196                if(video[1] == 'youtube'){
197                    src = 'http://www.youtube.com/embed/'+ video[4];
198                    classTerm = 'nivo-lightbox-youtube';
199                }
200                if(video[1] == 'youtu'){
201                    src = 'http://www.youtube.com/embed/'+ video[3];
202                    classTerm = 'nivo-lightbox-youtube';
203                }
204                if(video[1] == 'vimeo'){
205                    src = 'http://player.vimeo.com/video/'+ video[3];
206                    classTerm = 'nivo-lightbox-vimeo';
207                }
208
209                if(src){
210                    var iframeVideo = $('<iframe>', {
211                        src: src,
212                        'class': classTerm,
213                        frameborder: 0,
214                        vspace: 0,
215                        hspace: 0,
216                        scrolling: 'auto'
217                    });
218                    content.html(iframeVideo);
219                    iframeVideo.load(function(){ content.removeClass('nivo-lightbox-loading'); });
220                }
221            }
222            // AJAX
223            else if(link.attr('data-lightbox-type') == 'ajax'){
224				$.ajax({
225					url: href,
226					cache: false,
227					success: function(data) {
228						var wrap = $('<div class="nivo-lightbox-ajax" />');
229						wrap.append(data);
230						content.html(wrap).removeClass('nivo-lightbox-loading');
231
232						// Vertically center html
233						if(wrap.outerHeight() < content.height()){
234							wrap.css({
235								'position': 'relative',
236								'top': '50%',
237								'margin-top': -(wrap.outerHeight()/2) +'px'
238							});
239						}
240						$(window).resize(function() {
241							if(wrap.outerHeight() < content.height()){
242								wrap.css({
243									'position': 'relative',
244									'top': '50%',
245									'margin-top': -(wrap.outerHeight()/2) +'px'
246								});
247							}
248						});
249					},
250					error: function(){
251						var wrap = $('<div class="nivo-lightbox-error"><p>'+ $this.options.errorMessage +'</p></div>');
252                        content.html(wrap).removeClass('nivo-lightbox-loading');
253					}
254				});
255            }
256            // Inline HTML
257            else if(href.substring(0, 1) == '#' && link.attr('data-lightbox-type') == 'inline'){
258                if($(href).length){
259                    var wrap = $('<div class="nivo-lightbox-inline" />');
260					wrap.append($(href).clone().show());
261                    content.html(wrap).removeClass('nivo-lightbox-loading');
262
263                    // Vertically center html
264					if(wrap.outerHeight() < content.height()){
265						wrap.css({
266							'position': 'relative',
267							'top': '50%',
268							'margin-top': -(wrap.outerHeight()/2) +'px'
269						});
270					}
271					$(window).resize(function() {
272						if(wrap.outerHeight() < content.height()){
273							wrap.css({
274								'position': 'relative',
275								'top': '50%',
276								'margin-top': -(wrap.outerHeight()/2) +'px'
277							});
278						}
279					});
280				} else {
281					var wrapError = $('<div class="nivo-lightbox-error"><p>'+ $this.options.errorMessage +'</p></div>');
282                    content.html(wrapError).removeClass('nivo-lightbox-loading');
283				}
284            }
285            // iFrame (default)
286            else if(link.attr('data-lightbox-type') == 'iframe'){
287                var iframe = $('<iframe>', {
288                    src: href,
289                    'class': 'nivo-lightbox-item',
290                    frameborder: 0,
291                    vspace: 0,
292                    hspace: 0,
293                    scrolling: 'auto'
294                });
295                content.html(iframe);
296                iframe.load(function(){ content.removeClass('nivo-lightbox-loading'); });
297            } else {
298				return false;
299			}
300
301            // Set the title
302            if(link.attr('title')){
303                var titleWrap = $('<span>', { 'class': 'nivo-lightbox-title' });
304                titleWrap.text(link.attr('title'));
305                $('.nivo-lightbox-title-wrap').html(titleWrap);
306            } else {
307                $('.nivo-lightbox-title-wrap').html('');
308            }
309        },
310
311        constructLightbox: function(){
312            if($('.nivo-lightbox-overlay').length) return $('.nivo-lightbox-overlay');
313
314            var overlay = $('<div>', { 'class': 'nivo-lightbox-overlay nivo-lightbox-theme-'+ this.options.theme +' nivo-lightbox-effect-'+ this.options.effect });
315            var wrap = $('<div>', { 'class': 'nivo-lightbox-wrap' });
316            var content = $('<div>', { 'class': 'nivo-lightbox-content' });
317            var nav = $('<a href="#" class="nivo-lightbox-nav nivo-lightbox-prev">Previous</a><a href="#" class="nivo-lightbox-nav nivo-lightbox-next">Next</a>');
318            var close = $('<a href="#" class="nivo-lightbox-close" title="Close">Close</a>');
319            var title = $('<div>', { 'class': 'nivo-lightbox-title-wrap' });
320
321            var isMSIE = /*@cc_on!@*/0;
322            if(isMSIE) overlay.addClass('nivo-lightbox-ie');
323
324            wrap.append(content);
325            wrap.append(title);
326            overlay.append(wrap);
327            overlay.append(nav);
328            overlay.append(close);
329            $('body').append(overlay);
330
331            var $this = this;
332            if($this.options.clickOverlayToClose){
333                overlay.on('click', function(e){
334                    if(e.target === this || $(e.target).hasClass('nivo-lightbox-content') || $(e.target).hasClass('nivo-lightbox-image')){
335                        $this.destructLightbox();
336                    }
337                });
338            }
339
340            close.on('click', function(e){
341                e.preventDefault();
342                $this.destructLightbox();
343            });
344
345            return overlay;
346        },
347
348        destructLightbox: function(){
349            var $this = this;
350            this.options.beforeHideLightbox.call(this);
351
352            $('.nivo-lightbox-overlay').removeClass('nivo-lightbox-open');
353            $('.nivo-lightbox-nav').hide();
354            $('body').removeClass('nivo-lightbox-body-effect-'+ $this.options.effect);
355
356            // For IE
357            var isMSIE = /*@cc_on!@*/0;
358            if(isMSIE){
359                $('.nivo-lightbox-overlay iframe').attr("src", " ");
360                $('.nivo-lightbox-overlay iframe').remove();
361            }
362
363            // Remove click handlers
364            $('.nivo-lightbox-prev').off('click');
365            $('.nivo-lightbox-next').off('click');
366
367            // Empty content (for videos)
368            $('.nivo-lightbox-content').empty();
369
370            this.options.afterHideLightbox.call(this);
371        },
372
373        isHidpi: function(){
374			var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
375                              (min--moz-device-pixel-ratio: 1.5),\
376                              (-o-min-device-pixel-ratio: 3/2),\
377                              (min-resolution: 1.5dppx)";
378			if(window.devicePixelRatio > 1) return true;
379			if(window.matchMedia && window.matchMedia(mediaQuery).matches) return true;
380			return false;
381		}
382
383    };
384
385    $.fn[pluginName] = function(options){
386        return this.each(function(){
387            if(!$.data(this, pluginName)){
388                $.data(this, pluginName, new NivoLightbox(this, options));
389            }
390        });
391    };
392
393})(jQuery, window, document);

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.