Advertisement
Guest User

Untitled

a guest
Sep 27th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($)
  2. {
  3.     "use strict";
  4.  
  5.     // -------------------------------------------------------------------------------------------
  6.     // Ligthbox activation
  7.     // -------------------------------------------------------------------------------------------
  8.  
  9.     $.avia_utilities = $.avia_utilities || {};
  10.  
  11.     $.avia_utilities.av_popup = {
  12.             type:               'image',
  13.             mainClass:          'avia-popup mfp-zoom-in',
  14.             tLoading:           '',
  15.             tClose:             '',
  16.             removalDelay:       300, //delay removal by X to allow out-animation
  17.             closeBtnInside:     true,
  18.             closeOnContentClick:false,
  19.             midClick:           true,
  20.             autoFocusLast:      false, // false, prevents issues with accordion slider
  21.             fixedContentPos:    $('html').hasClass('av-default-lightbox-no-scroll'), // allows scrolling when lightbox is open but also removes any jumping because of scrollbar removal
  22.             iframe: {
  23.                 patterns: {
  24.                     youtube: {
  25.                         index: 'youtube.com/watch',
  26.                         id: function(url) {
  27.  
  28.                             //fetch the id
  29.                             var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/),
  30.                                 id,
  31.                                 params;
  32.  
  33.                             if( !m || !m[1] )
  34.                             {
  35.                                 return null;
  36.                             }
  37.  
  38.                             id = m[1];
  39.  
  40.                             //fetch params
  41.                             params = url.split('/watch');
  42.                             params = params[1];
  43.  
  44.                             return id + params;
  45.                         },
  46.                         src: '//www.youtube.com/embed/%id%'
  47.                     },
  48.                     vimeo: {
  49.                         index: 'vimeo.com/',
  50.                         id: function(url) {
  51.  
  52.                             // fetch the id
  53.                             // https://kriesi.at/support/topic/vimeo-popup-inline-text-anchor-link-does-not-work/
  54.                             var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})\/(\w{6,11})[?]?.*/), id, params;
  55.                             if( !m || !m[5] )
  56.                             {
  57.                                 return null;
  58.                             }
  59.                            
  60.                             var id2 = !m[6] ? "" : "/" + m[6];
  61.                             id = m[5];
  62.  
  63.                             //fetch params
  64.                             params = url.split('?');
  65.                             params = params[1];
  66.  
  67.                             return id + id2 + '?' + params;
  68.                         },
  69.                         src: '//player.vimeo.com/video/%id%'
  70.                     }
  71.                 }
  72.             },
  73.             image: {
  74.                 titleSrc: function( item )
  75.                         {
  76.                             var title = item.el.attr('title');
  77.                             if( ! title )
  78.                             {
  79.                                 title = item.el.find('img').attr('title');
  80.                             }
  81.                             if( ! title )
  82.                             {
  83.                                 title = item.el.parent().next( '.wp-caption-text' ).html();
  84.                             }
  85.                             if( typeof title != "undefined" )
  86.                             {
  87.                                 return title;
  88.                             }
  89.  
  90.                             if( ! $( 'body' ).hasClass( 'avia-mfp-show-alt-text' ) )
  91.                             {
  92.                                 return '';
  93.                             }
  94.  
  95.                             //  @since 4.7.6.2 check for alt attribute
  96.                             var alt = item.el.attr('alt');
  97.                             if( typeof alt != "undefined" )
  98.                             {
  99.                                 return alt;
  100.                             }
  101.  
  102.                             alt = item.el.find('img').attr('alt');
  103.                             if( typeof alt != "undefined" )
  104.                             {
  105.                                 return alt;
  106.                             }
  107.  
  108.                             return '';
  109.                         }
  110.             },
  111.  
  112.             gallery: {
  113.                 // delegate:    options.autolinkElements,
  114.                 tPrev:      '',
  115.                 tNext:      '',
  116.                 tCounter:   '%curr% / %total%',
  117.                 enabled:    true,
  118.                 preload:    [1,1] // Will preload 1 - before current, and 1 after the current image
  119.             },
  120.  
  121.             callbacks:
  122.             {
  123.                 beforeOpen: function()
  124.                 {
  125.                     //add custom css class for different styling
  126.                     if( this.st.el && this.st.el.data('fixed-content') )
  127.                     {
  128.                         this.fixedContentPos = true;
  129.                     }
  130.                 },
  131.  
  132.                 open: function()
  133.                 {
  134.                     //overwrite default prev + next function. Add timeout for  crossfade animation
  135.                     $.magnificPopup.instance.next = function()
  136.                     {
  137.                         var self = this;
  138.                         self.wrap.removeClass('mfp-image-loaded');
  139.                         setTimeout(function() { $.magnificPopup.proto.next.call(self); }, 120);
  140.                     };
  141.  
  142.                     $.magnificPopup.instance.prev = function()
  143.                     {
  144.                         var self = this;
  145.                         self.wrap.removeClass('mfp-image-loaded');
  146.                         setTimeout(function() { $.magnificPopup.proto.prev.call(self); }, 120);
  147.                     };
  148.  
  149.                     //add custom css class for different styling
  150.                     if( this.st.el && this.st.el.data('av-extra-class') )
  151.                     {
  152.                         this.wrap.addClass( this.currItem.el.data('av-extra-class') );
  153.                     }
  154.  
  155.                     this.wrap.avia_swipe_trigger( {prev:'.mfp-arrow-left', next:'.mfp-arrow-right'} );
  156.                 },
  157.  
  158.                 markupParse: function( template, values, item )
  159.                 {
  160.                     if( typeof values.img_replaceWith == 'undefined' || typeof values.img_replaceWith.length == 'undefined' || values.img_replaceWith.length == 0 )
  161.                     {
  162.                         return;
  163.                     }
  164.  
  165.                     var img = $( values.img_replaceWith[0] );
  166.  
  167.                     if( typeof img.attr( 'alt' ) != 'undefined' )
  168.                     {
  169.                         return;
  170.                     }
  171.  
  172.                     var alt = item.el.attr( 'alt' );
  173.                     if( typeof alt == "undefined" )
  174.                     {
  175.                         alt = item.el.find('img').attr('alt');
  176.                     }
  177.  
  178.                     if( typeof alt != "undefined" )
  179.                     {
  180.                         img.attr( 'alt', alt );
  181.                     }
  182.  
  183.                     return;
  184.                 },
  185.  
  186.                 imageLoadComplete: function()
  187.                 {
  188.                     var self = this;
  189.                     setTimeout(function() { self.wrap.addClass('mfp-image-loaded'); }, 16);
  190.                 },
  191.                 change: function()
  192.                 {
  193.                     if( this.currItem.el )
  194.                     {
  195.                         var current = this.currItem.el;
  196.  
  197.                         this.content.find( '.av-extra-modal-content, .av-extra-modal-markup' ).remove();
  198.  
  199.                         if( current.data('av-extra-content') )
  200.                         {
  201.                             var extra = current.data('av-extra-content');
  202.                             this.content.append( "<div class='av-extra-modal-content'>" + extra + "</div>" );
  203.                         }
  204.  
  205.                         if( current.data('av-extra-markup') )
  206.                         {
  207.                             var markup = current.data('av-extra-markup');
  208.                             this.wrap.append( "<div class='av-extra-modal-markup'>" + markup + "</div>"  );
  209.                         }
  210.                     }
  211.                 }
  212.             }
  213.         };
  214.  
  215.     $.fn.avia_activate_lightbox = function(variables)
  216.     {
  217.  
  218.         var defaults = {
  219.             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'],
  220.             autolinkElements:   'a.lightbox, a[rel^="prettyPhoto"], a[rel^="lightbox"], a[href$=jpg], a[href$=webp], 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"]',
  221.             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"]',
  222.             exclude         :   '.noLightbox, .noLightbox a, .fakeLightbox, .lightbox-added, a[href*="dropbox.com"]'
  223.         },
  224.  
  225.         options = $.extend({}, defaults, variables),
  226.  
  227.         active = ! $('html').is('.av-custom-lightbox');
  228.  
  229.         if( ! active)
  230.         {
  231.             return this;
  232.         }
  233.  
  234.         return this.each(function()
  235.         {
  236.             var container   = $(this),
  237.                 videos      = $(options.videoElements, this).not(options.exclude).addClass('mfp-iframe'), /*necessary class for the correct lightbox markup*/
  238.                 ajaxed      = ! container.is('body') && ! container.is('.ajax_slide');
  239.                 for( var i = 0; i < options.groups.length; i++ )
  240.                 {
  241.                     container.find(options.groups[i]).each(function()
  242.                     {
  243.                         var links = $(options.autolinkElements, this);
  244.  
  245.                         if( ajaxed )
  246.                         {
  247.                             links.removeClass('lightbox-added');
  248.                         }
  249.  
  250.                         links.not(options.exclude).addClass('lightbox-added').magnificPopup($.avia_utilities.av_popup);
  251.                     });
  252.                 }
  253.  
  254.         });
  255.     };
  256. })(jQuery);
  257.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement