icingaweb2/public/js/vendor/freetile.js

6 lines
6.3 KiB
JavaScript

/*!
* Freetile.js v0.3.1
* A dynamic layout plugin for jQuery.
*/
(function(b){b.fn.freetile=function(c){if(typeof a[c]==="function"){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.Freetile")}}return this};var a={init:function(e){var d=this,f=a.setupOptions(d,e),g=a.newContent(f.contentToAppend);if(!f.tiled){a.setupContainerBindings(d,f)}if(f.tiled&&g){d.append(g);g.filter(f.selector||"*").filter(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}else{d.children(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}return d},append:function(e){var d=this,f=a.setupOptions(d,e),g=a.newContent(f.contentToAppend);if(f.tiled&&g){d.append(g);g.filter(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}return d},layout:function(d){var c=this,e=a.setupOptions(c,d);a.positionAll(c,e);return c},destroy:function(){var c=this,d=c.data("FreetileData");a.resetElementsStyle(c,d);b(window).off("resize",this.windowResizeCallback);c.off(d.customEvents,this.customEventsCallback);return true},setupOptions:function(d,e){var c=d.data("FreetileData");var f=b.extend(true,{},this.defaults,c,this.reset,e);d.data("FreetileData",f);f.tiled=(c!==undefined);f._animate=f.animate&&f.tiled&&b.isEmptyObject(f.contentToAppend);this.reset.callback=f.persistentCallback&&f.callback?f.callback:function(){};return f},windowResizeCallback:function(c,d,e){clearTimeout(c.data("FreetileTimeout"));c.data("FreetileTimeout",setTimeout(function(){var h=b(window),g=h.width(),f=h.height();if(g!=d||f!=e){d=g,e=f;c.freetile("layout")}},400))},customEventsCallback:function(c){clearTimeout(c.data("FreetileTimeout"));c.data("FreetileTimeout",setTimeout(function(){c.freetile("layout")},400))},setupContainerBindings:function(c,f){if(f.containerResize){var e=b(window),d=e.width(),g=e.height();e.resize(b.proxy(this.windowResizeCallback,c,c,d,g))}if(f.customEvents){c.bind(f.customEvents,b.proxy(this.customEventsCallback,c,c))}return c},newContent:function(c){if((typeof c==="object"&&!b.isEmptyObject(c))||(typeof c==="string"&&b(c).length)){return b(c)}return false},calculatePositions:function(c,d,e){d.each(function(o){var p=b(this),n=0;e.ElementWidth=p.outerWidth(true);e.ElementHeight=p.outerHeight(true);e.ElementTop=0;e.ElementIndex=o;e.IndexStart=0;e.IndexEnd=0;e.BestScore=0;e.TestedTop=0;e.TestedLeft=0;e.TestedTop=e.currentPos[0].top;for(n=1;n<e.currentPos.length&&e.currentPos[n].left<e.ElementWidth;n++){e.TestedTop=Math.max(e.TestedTop,e.currentPos[n].top)}e.ElementTop=e.TestedTop;e.IndexEnd=n;e.BestScore=e.scoreFunction(e);for(var o=1;(o<e.currentPos.length)&&(e.currentPos[o].left+e.ElementWidth<=e.containerWidth);o++){e.TestedLeft=e.currentPos[o].left;e.TestedTop=e.currentPos[o].top;for(n=o+1;(n<e.currentPos.length)&&(e.currentPos[n].left-e.currentPos[o].left<e.ElementWidth);n++){e.TestedTop=Math.max(e.TestedTop,e.currentPos[n].top)}var l=e.scoreFunction(e);if(l>e.BestScore){e.IndexStart=o;e.IndexEnd=n;e.ElementTop=e.TestedTop;e.BestScore=l}}var h=p.position(),q={left:e.currentPos[e.IndexStart].left+e.xPadding,top:e.ElementTop+e.yPadding};if(h.top!=q.top||h.left!=q.left){var k={el:p,f:"css",d:0};if(e._animate&&!p.hasClass("noanim")){var f=p.offset(),m={left:q.left+(f.left-h.left),top:q.top+(f.top-h.top)};if((f.top+e.ElementHeight>e.viewportY&&f.top<e.viewportYH||m.top+e.ElementHeight>e.viewportY&&m.top<e.viewportYH)){k.f="animate";k.d=e.currentDelay;++(e.iteration);e.currentDelay+=e.elementDelay}}k.style=q;e.styleQueue.push(k)}--(e.iteration);var r=e.currentPos[e.IndexEnd-1].top,s=e.currentPos[e.IndexEnd]?e.currentPos[e.IndexEnd].left:e.containerWidth,g=e.currentPos[e.IndexStart].left+e.ElementWidth;e.currentPos[e.IndexStart].top=e.ElementTop+e.ElementHeight;if(g<s){e.currentPos.splice(e.IndexStart+1,e.IndexEnd-e.IndexStart-1,{left:g,top:r})}else{e.currentPos.splice(e.IndexStart+1,e.IndexEnd-e.IndexStart-1)}})},prepareElements:function(c,d,e){d.each(function(){var f=b(this);if(f.is(":visible")){f.css({display:"block"})}}).css({position:"absolute"})},applyStyles:function(f){var e;for(var d=0,c=f.styleQueue.length;d<c;d++){e=f.styleQueue[d];if(e.f=="animate"){e.el.delay(e.d).animate(e.style,b.extend(true,{},f.animationOptions))}else{e.el.css(e.style)}}},positionAll:function(c,g){if(b.isEmptyObject(g.contentToAppend)){var j=g.selector?c.children(g.selector):c.children()}else{var j=g.selector?g.contentToAppend.filter(g.selector):g.contentToAppend}g.ElementsCount=j.length;if(!g.ElementsCount){c.data("FreetilePos",null);if(typeof(g.callback=="function")){g.callback(g)}c[g._animate&&g.containerAnimate?"animate":"css"]({height:"0px"});return c}var d=c.css("display")||"";var f=c.css("visibility")||"";c.css({display:"block",width:"",visibility:"hidden"});g.containerWidth=c.width();var i=c.data("FreetilePos");g.currentPos=!b.isEmptyObject(g.contentToAppend)&&i?i:[{left:0,top:0}];g.xPadding=parseInt(c.css("padding-left"),10);g.yPadding=parseInt(c.css("padding-top"),10);g.viewportY=b(window).scrollTop();g.viewportYH=g.viewportY+b(window).height();g.iteration=j.length;g.currentDelay=0;g.styleQueue=[];g.animationOptions.complete=function(){if(--(g.iteration)<=0){g.callback(g)}};a.prepareElements(c,j,g);a.calculatePositions(c,j,g);a.applyStyles(g);var h={};if(d){h.display=d}if(f){h.visibility=f}if(c.css("position")=="static"){h.position="relative"}if(g.forceWidth&&g.containerWidthStep>0){h.width=g.containerWidthStep*(parseInt(c.width()/g.containerWidthStep,10))}c.css(h);var e=b.map(g.currentPos,function(l,k){return l.top});h={height:Math.max.apply(Math,e)};if(g._animate&&g.containerAnimate){c.stop().animate(h,b.extend(true,{},g.animationOptions))}else{c.css(h)}if(g.iteration<=0){g.callback(g)}c.data("FreetilePos",g.currentPos);j.addClass("tiled");return c},resetElementsStyle:function(c,d){var e;if(b.isEmptyObject(d.contentToAppend)){e=d.selector?c.children(d.selector):c.children()}else{e=d.selector?d.contentToAppend.filter(d.selector):d.contentToAppend}e.each(function(){b(this).attr("style","")})},defaults:{selector:"*",animate:false,elementDelay:0,containerResize:true,containerAnimate:false,customEvents:"",persistentCallback:false,forceWidth:false,containerWidthStep:1,loadCheckSelector:":not(.ignore-load-check)",scoreFunction:function(c){return -(c.TestedTop)}},reset:{animationOptions:{complete:function(){}},callback:function(){},contentToAppend:{}}}})(jQuery);