UNPKG

gallerygrid

Version:

A simple and lightweight image gallery grid layouter

1 lines 2.23 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.GalleryGrid=e()}}(function(){return function e(t,i,n){function r(h,d){if(!i[h]){if(!t[h]){var u="function"==typeof require&&require;if(!d&&u)return u(h,!0);if(o)return o(h,!0);var a=new Error("Cannot find module '"+h+"'");throw a.code="MODULE_NOT_FOUND",a}var f=i[h]={exports:{}};t[h][0].call(f.exports,function(e){var i=t[h][1][e];return r(i?i:e)},f,f.exports,e,t,i,n)}return i[h].exports}for(var o="function"==typeof require&&require,h=0;h<n.length;h++)r(n[h]);return r}({1:[function(e,t,i){var n=function(t,i){$=$||jQuery||e("jquery");var n={border:0,targetHeight:250,minWidth:0,updateOnResize:!0,itemSelector:"img"};t=$(t),this.container=t,i=$.extend(n,i),this.options=i;var r=t.innerWidth();$(window).resize(function(){i.updateOnResize&&a()});var o=function(){var e=[],n=0,o=0,h=0,u=0,a=0;t.children().each(function(t,f){var l=$(i.itemSelector,f);return!l.length||(u=l.data("width"),a=l.data("height"),null==u&&(u=l[0].naturalWidth),null==a&&(a=l[0].naturalHeight),e.push({element:f,width:u,height:a}),u*=i.targetHeight/a,n+=u+2*i.border,o=r/n*i.targetHeight,void(o<i.targetHeight&&(d(e,r,o,!1),e.length=0,n=0,h=o)))}),e.length>0&&d(e,r,0===h?i.targetHeight:h,!0)},h=null,d=function(e,t,n,r){var o=0,d=[];$.each(e,function(e,t){var r=t.height/n;t.width=Math.round(t.width/r),t.height=Math.round(n),o+=t.width+2*i.border,d.push(t)});var u=t-o;if(u&&!r){var a=d.length;$.each(d,function(e,t){var i=Math.ceil(u/(a-e));t.width+=i,u-=i})}var f=r&&h&&d.length<h.length,l=3;$.each(d,function(e,t){f&&(Math.abs(h[e].width-t.width)<=l?t.width=h[e].width:f=!1),$(i.itemSelector,t.element).css({width:t.width+"px",height:t.height+"px"})}),h=d},u=function(){t.find(i.itemSelector).css({width:"",height:""})},a=function(e){e=e||!1;var n=t.innerWidth();return n<i.minWidth?void(r>=i.minWidth&&u()):void((e||n!==r)&&(r=n,o()))};this.apply=function(){r>=i.minWidth&&o()},this.update=function(e){a(e)},this.clear=function(){u()}};t.exports=n},{jquery:void 0}]},{},[1])(1)});