Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. // -------------------------------------------------------------------------------------------
  2. // Avia AJAX Portfolio
  3. // -------------------------------------------------------------------------------------------
  4.  
  5. (function($)
  6. {
  7. "use strict";
  8. $.avia_utilities = $.avia_utilities || {};
  9.  
  10.  
  11. // -------------------------------------------------------------------------------------------
  12. //Portfolio sorting
  13. // -------------------------------------------------------------------------------------------
  14.  
  15. $.fn.avia_iso_sort = function(options)
  16. {
  17. return this.each(function()
  18. {
  19. var the_body = $('body'),
  20. container = $(this),
  21. portfolio_id = container.data('portfolio-id'),
  22. parentContainer = container.parents('.entry-content-wrapper, .avia-fullwidth-portfolio'),
  23. filter = parentContainer.find('.sort_width_container[data-portfolio-id="' + portfolio_id + '"]').find('#js_sort_items').css({visibility:"visible", opacity:0}),
  24. links = filter.find('a'),
  25. imgParent = container.find('.grid-image'),
  26. isoActive = false,
  27. items = $('.post-entry', container),
  28. is_originLeft = the_body.hasClass('rtl') ? false : true;
  29.  
  30. function applyIso()
  31. {
  32. container.addClass('isotope_activated').isotope({
  33. layoutMode : 'fitRows', itemSelector : '.flex_column', originLeft: is_originLeft
  34. });
  35.  
  36. container.isotope( 'on', 'layoutComplete', function()
  37. {
  38. container.css({overflow:'visible'});
  39. the_body.trigger('av_resize_finished');
  40. });
  41.  
  42. isoActive = true;
  43. setTimeout(function(){ parentContainer.addClass('avia_sortable_active'); }, 0);
  44. };
  45.  
  46. links.bind('click',function()
  47. {
  48. var current = $(this),
  49. selector = current.data('filter'),
  50. linktext = current.html(),
  51. activeCat = parentContainer.find('.av-current-sort-title');
  52.  
  53. if(activeCat.length) activeCat.html(linktext);
  54.  
  55. links.removeClass('active_sort');
  56. current.addClass('active_sort');
  57. container.attr('id', 'grid_id_'+selector);
  58.  
  59. parentContainer.find('.open_container .ajax_controlls .avia_close').trigger('click');
  60. //container.css({overflow:'hidden'})
  61. container.isotope({ layoutMode : 'fitRows', itemSelector : '.flex_column' , filter: '.'+selector, originLeft: is_originLeft });
  62.  
  63. return false;
  64. });
  65.  
  66. // update columnWidth on window resize
  67. $(window).on( 'debouncedresize', function()
  68. {
  69. applyIso();
  70. });
  71.  
  72. $.avia_utilities.preload({container: container, single_callback: function()
  73. {
  74. filter.animate({opacity:1}, 400); applyIso();
  75.  
  76. //call a second time to for the initial resizing
  77. setTimeout(function(){ applyIso(); });
  78.  
  79. imgParent.css({height:'auto'}).each(function(i)
  80. {
  81. var currentLink = $(this);
  82.  
  83. setTimeout(function()
  84. {
  85. currentLink.animate({opacity:1},1500);
  86. }, (100 * i));
  87. });
  88. }
  89. });
  90.  
  91. });
  92. };
  93.  
  94.  
  95.  
  96.  
  97.  
  98. $.fn.avia_portfolio_preview = function(passed_options)
  99. {
  100. var win = $(window),
  101. the_body = $('body'),
  102. isMobile = $.avia_utilities.isMobile,
  103. defaults =
  104. {
  105. open_in: '.portfolio-details-inner',
  106. easing: 'easeOutQuint',
  107. timing: 800,
  108. transition: 'slide' // 'fade' or 'slide'
  109. },
  110.  
  111. options = $.extend({}, defaults, passed_options);
  112.  
  113. return this.each(function()
  114. {
  115. var container = $(this),
  116. portfolio_id = container.data('portfolio-id'),
  117. target_wrap = $('.portfolio_preview_container[data-portfolio-id="' + portfolio_id + '"]'),
  118. target_container = target_wrap.find(options.open_in),
  119. items = container.find('.grid-entry'),
  120. content_retrieved = {},
  121. is_open = false,
  122. animating = false,
  123. index_open = false,
  124. ajax_call = false,
  125. methods,
  126. controls,
  127. loader = $.avia_utilities.loading();
  128.  
  129. methods =
  130. {
  131. load_item: function(e)
  132. {
  133. e.preventDefault();
  134.  
  135. var link = $(this),
  136. post_container = link.parents('.post-entry:eq(0)'),
  137. post_id = "ID_" + post_container.data('ajax-id'),
  138. clickedIndex = items.index(post_container);
  139.  
  140. //check if current item is the clicked item or if we are currently animating
  141. if(post_id === is_open || animating == true)
  142. {
  143. return false;
  144. }
  145.  
  146. animating = true;
  147.  
  148. container.find('.active_portfolio_item').removeClass('active_portfolio_item');
  149. post_container.addClass('active_portfolio_item');
  150. loader.show();
  151.  
  152. methods.ajax_get_contents(post_id, clickedIndex);
  153. },
  154.  
  155. scroll_top: function()
  156. {
  157. setTimeout(function()
  158. {
  159. var target_offset = target_wrap.offset().top - 175,
  160. window_offset = win.scrollTop();
  161.  
  162. if(window_offset > target_offset || target_offset - window_offset > 100 )
  163. {
  164. $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target_offset }, options.timing, options.easing);
  165. }
  166. },10);
  167. },
  168.  
  169. attach_item: function(post_id)
  170. {
  171. content_retrieved[post_id] = $(content_retrieved[post_id]).appendTo(target_container);
  172. ajax_call = true;
  173. },
  174.  
  175. remove_video: function()
  176. {
  177. var del = target_wrap.find('iframe, .avia-video').parents('.ajax_slide:not(.open_slide)');
  178.  
  179. if(del.length > 0)
  180. {
  181. del.remove();
  182. content_retrieved["ID_" + del.data('slideId')] = undefined;
  183. }
  184. },
  185.  
  186. show_item: function(post_id, clickedIndex)
  187. {
  188.  
  189. //check if current item is the clicked item or if we are currently animating
  190. if(post_id === is_open)
  191. {
  192. return false;
  193. }
  194. animating = true;
  195.  
  196.  
  197. loader.hide();
  198.  
  199. if(false === is_open)
  200. {
  201. target_wrap.addClass('open_container');
  202. content_retrieved[post_id].addClass('open_slide');
  203.  
  204. methods.scroll_top();
  205.  
  206. target_wrap.css({display:'none'}).slideDown(options.timing, options.easing, function()
  207. {
  208. if(ajax_call)
  209. {
  210. $.avia_utilities.activate_shortcode_scripts(content_retrieved[post_id]);
  211. $.avia_utilities.avia_ajax_call(content_retrieved[post_id]);
  212. the_body.trigger('av_resize_finished');
  213. ajax_call = false;
  214. }
  215.  
  216. methods.remove_video();
  217. the_body.trigger('av_resize_finished');
  218. });
  219.  
  220. index_open = clickedIndex;
  221. is_open = post_id;
  222. animating = false;
  223.  
  224.  
  225.  
  226. }
  227. else
  228. {
  229. methods.scroll_top();
  230.  
  231. var initCSS = { zIndex:3 },
  232. easing = options.easing;
  233.  
  234. if(index_open > clickedIndex) { initCSS.left = '-110%'; }
  235. if(options.transition === 'fade'){ initCSS.left = '0%'; initCSS.opacity = 0; easing = 'easeOutQuad'; }
  236.  
  237. //fixate height for container during animation
  238. target_container.height(target_container.height()); //outerHeight = border problems?
  239.  
  240. content_retrieved[post_id].css(initCSS).avia_animate({'left':"0%", opacity:1}, options.timing, easing);
  241. content_retrieved[is_open].avia_animate({opacity:0}, options.timing, easing, function()
  242. {
  243. content_retrieved[is_open].attr({'style':""}).removeClass('open_slide');
  244. content_retrieved[post_id].addClass('open_slide');
  245. //+ 2 fixes border problem (slides move up and down 2 px on transition)
  246. target_container.avia_animate({height: content_retrieved[post_id].outerHeight() + 2}, options.timing/2, options.easing, function()
  247. {
  248. target_container.attr({'style':""});
  249. is_open = post_id;
  250. index_open = clickedIndex;
  251. animating = false;
  252.  
  253. methods.remove_video();
  254. if(ajax_call)
  255. {
  256. the_body.trigger('av_resize_finished');
  257. $.avia_utilities.activate_shortcode_scripts(content_retrieved[post_id]);
  258. $.avia_utilities.avia_ajax_call(content_retrieved[post_id]);
  259. ajax_call = false;
  260. }
  261.  
  262. });
  263.  
  264. });
  265. }
  266. },
  267.  
  268. ajax_get_contents: function(post_id, clickedIndex)
  269. {
  270. if(content_retrieved[post_id] !== undefined)
  271. {
  272. methods.show_item(post_id, clickedIndex);
  273. return;
  274. }
  275.  
  276. content_retrieved[post_id] = $('#avia-tmpl-portfolio-preview-' + post_id.replace(/ID_/,"")).html();
  277.  
  278. //this line is necessary to prevent w3 total cache from messing up the portfolio if inline js is compressed
  279. content_retrieved[post_id] = content_retrieved[post_id].replace('/*<![CDATA[*/','').replace('*]]>','');
  280.  
  281. methods.attach_item(post_id);
  282.  
  283. $.avia_utilities.preload({container: content_retrieved[post_id] , single_callback: function(){ methods.show_item(post_id, clickedIndex); }});
  284. },
  285.  
  286. add_controls: function()
  287. {
  288. controls = target_wrap.find('.ajax_controlls');
  289.  
  290. target_wrap.avia_keyboard_controls({27:'.avia_close', 37:'.ajax_previous', 39:'.ajax_next'});
  291. //target_wrap.avia_swipe_trigger({prev:'.ajax_previous', next:'.ajax_next'});
  292.  
  293. items.each(function(){
  294.  
  295. var current = $(this), overlay;
  296.  
  297. current.addClass('no_combo').bind('click', function(event)
  298. {
  299. overlay = current.find('.slideshow_overlay');
  300.  
  301. if(overlay.length)
  302. {
  303. event.stopPropagation();
  304. methods.load_item.apply(current.find('a:eq(0)'));
  305. return false;
  306. }
  307. });
  308.  
  309.  
  310. });
  311. },
  312.  
  313. control_click: function()
  314. {
  315. var showItem,
  316. activeID = container.find('.active_portfolio_item').data('ajax-id'),
  317. active = container.find('.post-entry-'+activeID);
  318.  
  319. switch(this.hash)
  320. {
  321. case '#next':
  322.  
  323. showItem = active.nextAll('.post-entry:visible:eq(0)').find('a:eq(0)');
  324. if(!showItem.length) { showItem = $('.post-entry:visible:eq(0)', container).find('a:eq(0)'); }
  325. showItem.trigger('click');
  326.  
  327. break;
  328. case '#prev':
  329.  
  330. showItem = active.prevAll('.post-entry:visible:eq(0)').find('a:eq(0)');
  331. if(!showItem.length) { showItem = $('.post-entry:visible:last', container).find('a:eq(0)'); }
  332. showItem.trigger('click');
  333.  
  334. break;
  335. case '#close':
  336.  
  337. animating = true;
  338.  
  339. target_wrap.slideUp( options.timing, options.easing, function()
  340. {
  341. container.find('.active_portfolio_item').removeClass('active_portfolio_item');
  342. content_retrieved[is_open].attr({'style':""}).removeClass('open_slide');
  343. target_wrap.removeClass('open_container');
  344. animating = is_open = index_open = false;
  345. methods.remove_video();
  346. the_body.trigger('av_resize_finished');
  347. });
  348.  
  349. break;
  350. }
  351. return false;
  352. },
  353.  
  354.  
  355. resize_reset: function()
  356. {
  357. if(is_open === false)
  358. {
  359. target_container.html('');
  360. content_retrieved = [];
  361. }
  362. }
  363. };
  364.  
  365. methods.add_controls();
  366.  
  367. container.on("click", "a", methods.load_item);
  368. controls.on("click", "a", methods.control_click);
  369. if(jQuery.support.leadingWhitespace) { win.bind('debouncedresize', methods.resize_reset); }
  370.  
  371. });
  372. };
  373. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement