Advertisement
Guest User

Untitled

a guest
Oct 12th, 2023
63
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.                             var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})\/(\w{6,11})[?]?.*/), params, vid;
  54.                             m = m ? m : url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/);
  55.  
  56.                             if( !m || !m[5] )
  57.                             {
  58.                                 return null;
  59.                             }
  60.                          
  61.                             vid = m[5];
  62.  
  63.                             //fetch params
  64.                             params = url.split('?');
  65.                             params = params[1] ? "?" + params[1] : "";
  66.  
  67.                             if(m[6])
  68.                             {
  69.                                 vid = vid + (params ? params + "&h=" : "?h=") + m[6];
  70.                             }              
  71.  
  72.                             return vid + params;
  73.                         },
  74.                         src: '//player.vimeo.com/video/%id%'
  75.                     }
  76.             },
  77.             },
  78.             image: {
  79.                 titleSrc: function( item )
  80.                         {
  81.                             var title = item.el.attr('title');
  82.                             if( ! title )
  83.                             {
  84.                                 title = item.el.find('img').attr('title');
  85.                             }
  86.                             if( ! title )
  87.                             {
  88.                                 title = item.el.parent().next( '.wp-caption-text' ).html();
  89.                             }
  90.                             if( typeof title != "undefined" )
  91.                             {
  92.                                 return title;
  93.                             }
  94.  
  95.                             if( ! $( 'body' ).hasClass( 'avia-mfp-show-alt-text' ) )
  96.                             {
  97.                                 return '';
  98.                             }
  99.  
  100.                             //  @since 4.7.6.2 check for alt attribute
  101.                             var alt = item.el.attr('alt');
  102.                             if( typeof alt != "undefined" )
  103.                             {
  104.                                 return alt;
  105.                             }
  106.  
  107.                             alt = item.el.find('img').attr('alt');
  108.                             if( typeof alt != "undefined" )
  109.                             {
  110.                                 return alt;
  111.                             }
  112.  
  113.                             return '';
  114.                         }
  115.             },
  116.  
  117.             gallery: {
  118.                 // delegate:    options.autolinkElements,
  119.                 tPrev:      '',
  120.                 tNext:      '',
  121.                 tCounter:   '%curr% / %total%',
  122.                 enabled:    true,
  123.                 preload:    [1,1] // Will preload 1 - before current, and 1 after the current image
  124.             },
  125.  
  126.             callbacks:
  127.             {
  128.                 beforeOpen: function()
  129.                 {
  130.                     //add custom css class for different styling
  131.                     if( this.st.el && this.st.el.data('fixed-content') )
  132.                     {
  133.                         this.fixedContentPos = true;
  134.                     }
  135.                 },
  136.  
  137.                 open: function()
  138.                 {
  139.                     //overwrite default prev + next function. Add timeout for  crossfade animation
  140.                     $.magnificPopup.instance.next = function()
  141.                     {
  142.                         var self = this;
  143.                         self.wrap.removeClass('mfp-image-loaded');
  144.                         setTimeout(function() { $.magnificPopup.proto.next.call(self); }, 120);
  145.                     };
  146.  
  147.                     $.magnificPopup.instance.prev = function()
  148.                     {
  149.                         var self = this;
  150.                         self.wrap.removeClass('mfp-image-loaded');
  151.                         setTimeout(function() { $.magnificPopup.proto.prev.call(self); }, 120);
  152.                     };
  153.  
  154.                     //add custom css class for different styling
  155.                     if( this.st.el && this.st.el.data('av-extra-class') )
  156.                     {
  157.                         this.wrap.addClass( this.currItem.el.data('av-extra-class') );
  158.                     }
  159.  
  160.                     this.wrap.avia_swipe_trigger( {prev:'.mfp-arrow-left', next:'.mfp-arrow-right'} );
  161.                 },
  162.  
  163.                 markupParse: function( template, values, item )
  164.                 {
  165.                     if( typeof values.img_replaceWith == 'undefined' || typeof values.img_replaceWith.length == 'undefined' || values.img_replaceWith.length == 0 )
  166.                     {
  167.                         return;
  168.                     }
  169.  
  170.                     var img = $( values.img_replaceWith[0] );
  171.  
  172.                     if( typeof img.attr( 'alt' ) != 'undefined' )
  173.                     {
  174.                         return;
  175.                     }
  176.  
  177.                     var alt = item.el.attr( 'alt' );
  178.                     if( typeof alt == "undefined" )
  179.                     {
  180.                         alt = item.el.find('img').attr('alt');
  181.                     }
  182.  
  183.                     if( typeof alt != "undefined" )
  184.                     {
  185.                         img.attr( 'alt', alt );
  186.                     }
  187.  
  188.                     return;
  189.                 },
  190.  
  191.                 imageLoadComplete: function()
  192.                 {
  193.                     var self = this;
  194.                     setTimeout(function() { self.wrap.addClass('mfp-image-loaded'); }, 16);
  195.                 },
  196.                 change: function()
  197.                 {
  198.                     if( this.currItem.el )
  199.                     {
  200.                         var current = this.currItem.el;
  201.  
  202.                         this.content.find( '.av-extra-modal-content, .av-extra-modal-markup' ).remove();
  203.  
  204.                         if( current.data('av-extra-content') )
  205.                         {
  206.                             var extra = current.data('av-extra-content');
  207.                             this.content.append( "<div class='av-extra-modal-content'>" + extra + "</div>" );
  208.                         }
  209.  
  210.                         if( current.data('av-extra-markup') )
  211.                         {
  212.                             var markup = current.data('av-extra-markup');
  213.                             this.wrap.append( "<div class='av-extra-modal-markup'>" + markup + "</div>"  );
  214.                         }
  215.                     }
  216.                 }
  217.             }
  218.         };
  219.  
  220.     $.fn.avia_activate_lightbox = function(variables)
  221.     {
  222.  
  223.         var defaults = {
  224.             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'],
  225.             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"]',
  226.             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"]',
  227.             exclude         :   '.noLightbox, .noLightbox a, .fakeLightbox, .lightbox-added, a[href*="dropbox.com"]'
  228.         },
  229.  
  230.         options = $.extend({}, defaults, variables),
  231.  
  232.         active = ! $('html').is('.av-custom-lightbox');
  233.  
  234.         if( ! active)
  235.         {
  236.             return this;
  237.         }
  238.  
  239.         return this.each(function()
  240.         {
  241.             var container   = $(this),
  242.                 videos      = $(options.videoElements, this).not(options.exclude).addClass('mfp-iframe'), /*necessary class for the correct lightbox markup*/
  243.                 ajaxed      = ! container.is('body') && ! container.is('.ajax_slide');
  244.                 for( var i = 0; i < options.groups.length; i++ )
  245.                 {
  246.                     container.find(options.groups[i]).each(function()
  247.                     {
  248.                         var links = $(options.autolinkElements, this);
  249.  
  250.                         if( ajaxed )
  251.                         {
  252.                             links.removeClass('lightbox-added');
  253.                         }
  254.  
  255.                         links.not(options.exclude).addClass('lightbox-added').magnificPopup($.avia_utilities.av_popup);
  256.                     });
  257.                 }
  258.  
  259.         });
  260.     };
  261. })(jQuery);
  262.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement