Guest User

Untitled

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