Files
cao_sunyata/cao_blogr/static/js/jquery-tjgallery.min.js
2022-05-20 15:35:50 +02:00

7 lines
2.4 KiB
JavaScript

/*!
* tjGallery 1.1
* http://tj-s.ru
* @copyright Tod, tod@tj-s.ru
* @license MIT License
*/
!function(o){var e={init:function(t){var l=o.extend({selector:"img",row_min_height:180,margin:5},t);return this.each(function(){var t=o(this);return t.data("tjGallery")||t.data("tjGallery",{target:t,tjGallery:l}),o(window).bind("resize.tjGallery",function(){e.clear.apply(t),i(t)}),i(t);function i(t){return t.each(function(){var t=o(this),r=t.width(),a=[],h={items:[],width:0,height:0};t.find(l.selector).each(function(){var t=o(this),i=t;if(t="IMG"!=i[0].nodeName.toUpperCase()?(i=i.find("img"),o('<div class="tjGalleryItem">').insertBefore(t).append(t)):o('<div class="tjGalleryItem">').insertBefore(i).append(i),i.length){t.css({width:"auto",float:"left",position:"relative"});var e={pic:i,container:t,original_height:i.attr("height")||i.height(),original_width:i.attr("width")||i.width()};e.aspect=e.original_width/e.original_height,e.scale=l.row_min_height/e.original_height,e.width=e.original_width*e.scale,e.height=e.original_height*e.scale;var n=s(h.items,e);r<n&&(a.push(h),h={items:[],width:0,height:0}),h.items.push(e)}}),1==h.items.length&&1<a[a.length-1].items.length?a[a.length-1].items.push(h.items[0]):(a.push(h),h.last=!0),o.each(a,function(t,n){n.scale=(r-(n.items.length-1)*l.margin)/s(n.items);var a=0;o.each(n.items,function(t,i){n.scale&&(i.width=Math.floor(i.width*n.scale),i.height=Math.floor(i.height*n.scale)),i.index=a;var e=i.pic;i.container;a++,e.css({height:parseInt(i.height)+"px",width:parseInt(i.width)+"px"}),i.container.css({height:parseInt(i.height)+"px",width:parseInt(i.width)+"px",marginTop:l.margin+"px"}),0<t?i.container.css({marginLeft:l.margin+"px"}):i.container.css({clear:"left"})})})})}function s(t,i){var e=0;return t.length&&o.each(t,function(t,i){e+=i.width}),i&&(e+=i.width),e}})},clear:function(){conteiner=this,data=conteiner.data("tjGallery"),conteiner.each(function(){o(this).find(data.tjGallery.selector).each(function(){o(this).is("img")||o(this).find("img").css({width:"auto",height:"auto"}),o(this).removeAttr("style"),o(this).appendTo(conteiner)}),o(this).find("div:empty").remove()})},destroy:function(){e.clear.apply(this),o(window).unbind(".tjGallery")}};o.fn.tjGallery=function(t){if(e[t])return e[t].apply(this,Array.prototype.slice.call(arguments,1));if("object"==typeof t||!t){return e.init.apply(this,arguments)}o.error("Method "+t+" does not exist for jQuery.tjGallery")}}(jQuery);