-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-modula.min.js
2 lines (2 loc) · 12 KB
/
jquery-modula.min.js
1
2
"use strict";!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.ResizeSensor=t()}("undefined"!=typeof window?window:this,function(){if("undefined"==typeof window)return null;var e=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(e){return window.setTimeout(e,20)};function t(e,t){var i=Object.prototype.toString.call(e),n="[object Array]"===i||"[object NodeList]"===i||"[object HTMLCollection]"===i||"[object Object]"===i||"undefined"!=typeof jQuery&&e instanceof jQuery||"undefined"!=typeof Elements&&e instanceof Elements,o=0,s=e.length;if(n)for(;o<s;o++)t(e[o]);else t(e)}function i(e){if(!e.getBoundingClientRect)return{width:e.offsetWidth,height:e.offsetHeight};var t=e.getBoundingClientRect();return{width:Math.round(t.width),height:Math.round(t.height)}}var n=function(o,s){function r(){var e,t,i=[];this.add=function(e){i.push(e)},this.call=function(){for(e=0,t=i.length;e<t;e++)i[e].call()},this.remove=function(n){var o=[];for(e=0,t=i.length;e<t;e++)i[e]!==n&&o.push(i[e]);i=o},this.length=function(){return i.length}}t(o,function(t){!function(t,n){if(t)if(t.resizedAttached)t.resizedAttached.add(n);else{t.resizedAttached=new r,t.resizedAttached.add(n),t.resizeSensor=document.createElement("div"),t.resizeSensor.dir="ltr",t.resizeSensor.className="resize-sensor";var o="position: absolute; left: -10px; top: -10px; right: 0; bottom: 0; overflow: hidden; z-index: -1; visibility: hidden;",s="position: absolute; left: 0; top: 0; transition: 0s;";t.resizeSensor.style.cssText=o,t.resizeSensor.innerHTML='<div class="resize-sensor-expand" style="'+o+'"><div style="'+s+'"></div></div><div class="resize-sensor-shrink" style="'+o+'"><div style="'+s+' width: 200%; height: 200%"></div></div>',t.appendChild(t.resizeSensor);var d=window.getComputedStyle(t).getPropertyPriority("position");"absolute"!==d&&"relative"!==d&&"fixed"!==d&&(t.style.position="relative");var c,l,a=t.resizeSensor.childNodes[0],h=a.childNodes[0],f=t.resizeSensor.childNodes[1],u=i(t),v=u.width,p=u.height,z=function(){var e=0===t.offsetWidth&&0===t.offsetHeight;if(e){var i=t.style.display;t.style.display="block"}h.style.width="100000px",h.style.height="100000px",a.scrollLeft=1e5,a.scrollTop=1e5,f.scrollLeft=1e5,f.scrollTop=1e5,e&&(t.style.display=i)};t.resizeSensor.resetSensor=z;var y=function(){l=0,c&&(v=void 0,p=void 0,t.resizedAttached&&t.resizedAttached.call())},w=function(){var n=i(t),o=n.width,s=n.height;(c=o!=v||s!=p)&&!l&&(l=e(y)),z()},g=function(e,t,i){e.attachEvent?e.attachEvent("on"+t,i):e.addEventListener(t,i)};g(a,"scroll",w),g(f,"scroll",w),e(z)}}(t,s)}),this.detach=function(e){n.detach(o,e)},this.reset=function(){o.resizeSensor.resetSensor()}};return n.reset=function(e,i){t(e,function(e){e.resizeSensor.resetSensor()})},n.detach=function(e,i){t(e,function(e){e&&(e.resizedAttached&&"function"==typeof i&&(e.resizedAttached.remove(i),e.resizedAttached.length())||e.resizeSensor&&(e.contains(e.resizeSensor)&&e.removeChild(e.resizeSensor),delete e.resizeSensor,delete e.resizedAttached))})},n});
function tg_getURLParameter(t){return decodeURIComponent((new RegExp("[?|&]"+t+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[,""])[1].replace(/\+/g,"%20"))||null}jQuery(document).on("vc-full-width-row-single vc-full-width-row",function(t,i){0<jQuery("body").find(".modula").length&&jQuery(window).trigger("modula-update")}),function(d,h,c,t){var o="modulaGallery",e={resizer:"/",margin:10,keepArea:!0,type:"creative-gallery",columns:12,gutter:10,enableTwitter:!1,enableFacebook:!1,enableGplus:!1,enablePinterest:!1,enableLinkedin:!1,lazyLoad:0};function n(t,i){this.element=t,this.$element=d(t),this.$itemsCnt=this.$element.find(".modula-items"),this.$items=this.$itemsCnt.find(".modula-item"),this.options=d.extend({},e,i),this._defaults=e,this._name=o,this.tiles=[],this.$tilesCnt=null,this.completed=!1,this.lastWidth=0,this.resizeTO=0,this.isPackeryActive=!1,this.init()}n.prototype.trunc=function(t){return Math.trunc?Math.trunc(t):(t=+t,isFinite(t)?t-t%1||(t<0?-0:0===t?t:0):t)},n.prototype.createCustomGallery=function(){var a,t=this.$element.width(),r=this,l=this.options.columns,i=c.documentElement.clientWidth;"1"==this.options.enableResponsive&&(i<=568?l=this.options.mobileColumns:i<=768&&(l=this.options.tabletColumns)),a=0<this.options.gutter?(t-this.options.gutter*(l-1))/l:Math.floor(t/l),this.$items.not(".jtg-hidden").each(function(t,i){var e,s,o,n,h={};e=d(i).data("width"),s=d(i).data("height"),12<e&&(e=12),"1"==r.options.enableResponsive&&(o=e,n=s,1==l?s=(e=1)*n/o:((e=Math.round(l*o/12))<1&&(e=1),(s=Math.round(e*n/o))<1&&(s=1))),h.width=a*e+r.options.gutter*(e-1),h.height=Math.round(a)*s+r.options.gutter*(s-1),d(i).data("size",h).addClass("tiled").addClass(h.width>h.height?"tile-h":"tile-v").data("position"),d(i).css(d(i).data("size")),d(i).find(".figc").css({width:d(i).data("size").width,height:d(i).data("size").height})}),this.isPackeryActive&&this.$itemsCnt.packery("destroy"),this.$itemsCnt.packery({itemSelector:".modula-item",gutter:parseInt(r.options.gutter),columnWidth:a,resize:!1}),this.isPackeryActive=!0},n.prototype.createGrid=function(){var s=this;this.options.width&&this.$itemsCnt.width(this.options.width),this.options.height&&this.$itemsCnt.height(this.options.height),this.$itemsCnt.data("area",this.$itemsCnt.width()*this.$itemsCnt.height()),this.lastWidth=this.$itemsCnt.width();for(var t=0;t<this.$items.not(".jtg-hidden").length;t++)this.tiles.push(s.getSlot());this.tiles.sort(function(t,i){return t.position-i.position}),this.$items.not(".jtg-hidden").each(function(t,i){var e=s.tiles[t];d(i).data("size",e).addClass("tiled").addClass(e.width>e.height?"tile-h":"tile-v").data("position")}),this.$items.each(function(t,i){d(i).css(d(i).data("size")),d(i).find(".figc").css({width:d(i).data("size").width,height:d(i).data("size").height})}),this.completed=!0},n.prototype.getSlot=function(){if(0==this.tiles.length)return e={top:0,left:0,width:this.$itemsCnt.width(),height:this.$itemsCnt.height(),area:this.$itemsCnt.width()*this.$itemsCnt.height(),position:0};for(var t=0,i=0;i<this.tiles.length;i++){(e=this.tiles[i]).area>this.tiles[t].area&&(t=i)}var e={},s=this.tiles[t];if(s.width>s.height){var o=s.width/2*this.options.randomFactor;s.prevWidth=s.width,s.width=Math.floor(s.width/2+o*(Math.random()-.5)),e={top:s.top,left:s.left+s.width+this.options.margin,width:s.prevWidth-s.width-this.options.margin,height:s.height}}else{o=s.height/2*this.options.randomFactor;s.prevHeight=s.height,s.height=Math.floor(s.height/2+o*(Math.random()-.5)),e={left:s.left,top:s.top+s.height+this.options.margin,width:s.width,height:s.prevHeight-s.height-this.options.margin}}return e.area=e.width*e.height,e.position=1e3*e.top+e.left,s.position=1e3*s.top+s.left,this.tiles[t]=s,this.tiles[t].area=s.width*s.height,e},n.prototype.reset=function(){var e=this;e.tiles=[],"custom-grid"===e.options.type?(e.createCustomGallery(),e.$itemsCnt.packery()):"creative-gallery"==this.options.type&&e.createGrid(),e.$itemsCnt.find(".pic").each(function(t,i){e.placeImage(t)}),e.lastWidth=e.$itemsCnt.width()},n.prototype.onResize=function(i){i.lastWidth!=i.$itemsCnt.width()&&(clearTimeout(i.resizeTO),i.resizeTO=setTimeout(function(){if(i.options.keepArea){var t=i.$itemsCnt.data("area");i.$itemsCnt.height(t/i.$itemsCnt.width())}i.reset()},100))},n.prototype.placeImage=function(t){var i=this.$items.eq(t),e=i.find(".pic"),s=i.data("size"),o=e.data("size");if(e.parent()!=i&&(s={width:e.parent().width(),height:e.parent().height()}),void 0!==s&&void 0!==o){var n=s.width/s.height,h=o.width/o.height,a=e.data("valign")?e.data("valign"):"middle",r=e.data("halign")?e.data("halign"):"center",l={top:"auto",bottom:"auto",left:"auto",right:"auto",width:"auto",height:"auto",margin:"0",maxWidth:"999em"};if(h<n)switch(l.width=s.width,l.left=0,a){case"top":l.top=0;break;case"middle":l.top=0-(s.width*(1/h)-s.height)/2;break;case"bottom":l.bottom=0}else switch(l.height=s.height,l.top=0,r){case"left":l.left=0;break;case"center":l.left=0-(s.height*h-s.width)/2;break;case"right":l.right=0}e.css(l)}},n.prototype.loadImage=function(t){var i=this,e=i.$items.eq(t).find(".pic"),s=new Image;s.onerror=function(){console.log("error loading image ["+t+"] : "+this.src),t+1<i.$items.length&&i.loadImage(t+1)},s.onload=function(){e.data("size",{width:this.width,height:this.height}),i.placeImage(t),i.$items.eq(t).addClass("tg-loaded"),t+1<i.$items.length&&i.loadImage(t+1)};var o=e.data("src");s.src=o,e.attr("src",o)},n.prototype.init=function(){var o=this;d(c).trigger("modula_api_before_init",[o]),this.$itemsCnt.css({position:"relative",zIndex:1,"min-height":"10px"}),this.$items.addClass("tile"),this.$items.find(".pic").removeAttr("src"),"custom-grid"===this.options.type?this.createCustomGallery():"creative-gallery"==this.options.type&&this.createGrid(),"1"!=o.options.lazyLoad&&this.loadImage(0),d(h).resize(function(){o.onResize(o)}),d(h).on("modula-update",function(){o.onResize(o)}),d(c).on("lazyloaded",function(t){var i,e,s=d(t.target);"modula"==s.data("source")&&(s.data("size",{width:s.width(),height:s.height()}),(i=s.parents(".modula-item")).addClass("tg-loaded"),e=o.$items.index(i),o.placeImage(e))}),new ResizeSensor(o.$element,function(){o.onResize(o)}),this.setupSocial(),this.options.onComplete&&this.options.onComplete(),d(c).trigger("modula_api_after_init",[o])},n.prototype.setupSocial=function(){this.options.enableTwitter&&i(this.$items,this),this.options.enableFacebook&&s(this.$items,this),this.options.enablePinterest&&a(this.$items,this),this.options.enableLinkedin&&r(this.$items,this)},n.prototype.destroy=function(){this.isPackeryActive&&(this.$itemsCnt.packery("destroy"),this.isPackeryActive=!1)};var i=function(t,s){t.find(".modula-icon-twitter").click(function(t){t.preventDefault();var i=d(this).parents(".tile:first").find(".caption"),e=s.options.twitterText||c.title;return!s.options.twitterText&&1==i.length&&0<i.text().length&&(e=d.trim(i.text())),h.open("https://twitter.com/intent/tweet?url="+encodeURI(location.href.split("#")[0])+"&text="+encodeURI(e),"ftgw","location=1,status=1,scrollbars=1,width=600,height=400").moveTo(screen.width/2-300,screen.height/2-200),!1})},s=function(t,o){t.find(".modula-icon-facebook").click(function(t){t.preventDefault();var i=d(this).parents(".tile:first").find(".pic"),e=d(this).parents(".tile:first").find(".caption");o.options.facebookText||c.title;!o.options.facebookText&&1==e.length&&0<e.text().length&&d.trim(e.text());i.attr("src");var s="//www.facebook.com/sharer.php?u="+location.href;return h.open(s,"ftgw","location=1,status=1,scrollbars=1,width=600,height=400").moveTo(screen.width/2-300,screen.height/2-200),!1})},a=function(t,n){t.find(".modula-icon-pinterest").click(function(t){t.preventDefault();var i=d(this).parents(".tile:first").find(".pic"),e=d(this).parents(".tile:first").find(".caption"),s=n.options.facebookText||c.title;!n.options.facebookText&&1==e.length&&0<e.text().length&&(s=d.trim(e.text()));var o="http://pinterest.com/pin/create/button/?url="+encodeURI(location.href)+"&description="+encodeURI(s);1==i.length&&(o+="&media="+function(t){var i=c.createElement("img");return i.src=t,t=i.src,i.src=null,t}(i.attr("src")));return h.open(o,"ftgw","location=1,status=1,scrollbars=1,width=600,height=400").moveTo(screen.width/2-300,screen.height/2-200),!1})},r=function(t,i){t.find(".modula-icon-linkedin").click(function(t){t.preventDefault();var i="//linkedin.com/shareArticle?mini=true&url="+ +encodeURI(location.href);return h.open(i,"ftgw","location=1,status=1,scrollbars=1,width=600,height=400").moveTo(screen.width/2-300,screen.height/2-200),!1})};d.fn[o]=function(i){var e,s=arguments;return i===t||"object"==typeof i?this.each(function(){d.data(this,"plugin_"+o)||d.data(this,"plugin_"+o,new n(this,i))}):"string"==typeof i&&"_"!==i[0]&&"init"!==i?(this.each(function(){var t=d.data(this,"plugin_"+o);t instanceof n&&"function"==typeof t[i]&&(e=t[i].apply(t,Array.prototype.slice.call(s,1))),"destroy"===i&&d.data(this,"plugin_"+o,null)}),e!==t?e:this):void 0}}(jQuery,window,document),jQuery(document).ready(function(e){var t=e(".modula-gallery");e.each(t,function(){var t=e(this).attr("id"),i=e(this).data("config");e("#"+t).modulaGallery(i)})});