(function($) { "use strict"; // ------------------------------------------------------------------------------------------- // ligthbox activation // ------------------------------------------------------------------------------------------- $.avia_utilities = $.avia_utilities || {}; $.avia_utilities.av_popup = { type: 'image', mainclass: 'avia-popup mfp-zoom-in', tloading: '', tclose: '', removaldelay: 300, //delay removal by x to allow out-animation closebtninside: true, closeoncontentclick:false, midclick: true, fixedcontentpos: false, // allows scrolling when lightbox is open but also removes any jumping because of scrollbar removal iframe: { patterns: { youtube: { index: 'youtube.com/watch', id: function(url) { //fetch the id var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/), id, params; if ( !m || !m[1] ) return null; id = m[1]; //fetch params params = url.split('/watch'); params = params[1]; return id + params; }, src: '//www.youtube.com/embed/%id%' } } }, image: { titlesrc: function(item){ var title = item.el.attr('title'); if(!title) title = item.el.find('img').attr('title'); if(!title) title = item.el.parent().next('.wp-caption-text').html(); if(typeof title == "undefined") return ""; return title; } }, gallery: { // delegate: options.autolinkelements, tprev: '', tnext: '', tcounter: '%curr% / %total%', enabled: true, preload: [1,1] // will preload 1 - before current, and 1 after the current image }, callbacks: { beforeopen: function() { //add custom css class for different styling if( this.st.el && this.st.el.data('fixed-content') ) { this.fixedcontentpos = true; } }, open: function() { //overwrite default prev + next function. add timeout for crossfade animation $.magnificpopup.instance.next = function() { var self = this; self.wrap.removeclass('mfp-image-loaded'); settimeout(function() { $.magnificpopup.proto.next.call(self); }, 120); }; $.magnificpopup.instance.prev = function() { var self = this; self.wrap.removeclass('mfp-image-loaded'); settimeout(function() { $.magnificpopup.proto.prev.call(self); }, 120); }; //add custom css class for different styling if( this.st.el && this.st.el.data('av-extra-class') ) { this.wrap.addclass( this.curritem.el.data('av-extra-class') ); } }, imageloadcomplete: function() { var self = this; settimeout(function() { self.wrap.addclass('mfp-image-loaded'); }, 16); }, change: function() { if( this.curritem.el ) { var current = this.curritem.el; this.content.find( '.av-extra-modal-content, .av-extra-modal-markup' ).remove(); if( current.data('av-extra-content') ) { var extra = current.data('av-extra-content'); this.content.append( "
" + extra + "
" ); } if( current.data('av-extra-markup') ) { var markup = current.data('av-extra-markup'); this.wrap.append( "
" + markup + "
" ); } } } } }, $.fn.avia_activate_lightbox = function(variables) { var defaults = { groups : ['.avia-slideshow', '.avia-gallery', '.av-horizontal-gallery', '.av-instagram-pics', '.portfolio-preview-image', '.portfolio-preview-content', '.isotope', '.post-entry', '.sidebar', '#main', '.main_menu', '.woocommerce-product-gallery'], autolinkelements: 'a.lightbox, a[rel^="prettyphoto"], a[rel^="lightbox"], a[href$=jpg], a[href$=png], a[href$=gif], a[href$=jpeg], a[href*=".jpg?"], a[href*=".png?"], a[href*=".gif?"], a[href*=".jpeg?"], a[href$=".mov"] , a[href$=".swf"] , a:regex(href, .vimeo\.com/[0-9]) , a[href*="youtube.com/watch"] , a[href*="screenr.com"], a[href*="iframe=true"]', videoelements : 'a[href$=".mov"] , a[href$=".swf"] , a:regex(href, .vimeo\.com/[0-9]) , a[href*="youtube.com/watch"] , a[href*="screenr.com"], a[href*="iframe=true"]', exclude : '.nolightbox, .nolightbox a, .fakelightbox, .lightbox-added, a[href*="dropbox.com"]' }, options = $.extend({}, defaults, variables), active = !$('html').is('.av-custom-lightbox'); if(!active) return this; return this.each(function() { var container = $(this), videos = $(options.videoelements, this).not(options.exclude).addclass('mfp-iframe'), /*necessary class for the correct lightbox markup*/ ajaxed = !container.is('body') && !container.is('.ajax_slide'); for (var i = 0; i < options.groups.length; i++) { container.find(options.groups[i]).each(function() { var links = $(options.autolinkelements, this); if(ajaxed) links.removeclass('lightbox-added'); links.not(options.exclude).addclass('lightbox-added').magnificpopup($.avia_utilities.av_popup); }); } }); }; })(jquery);