-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.500px.layout.min.js
1 lines (1 loc) · 2.34 KB
/
jquery.500px.layout.min.js
1
+function(e){"use strict";window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)};var t=function(n,r){var i=this;this.$el=e(n);this.opts=e.extend({},t.DEFAULTS,r);this.elementWidth=this.$el.width();e(window).resize(function(){this.resizeTo&&clearTimeout(this.resizeWatcher);this.resizeWatcher=setTimeout(function(){e(this).trigger("v.resize")},400)});e(window).on("v.resize",function(){var e=i.$el.width();if(i.elementWidth!==e){i.elementWidth=e;requestAnimationFrame(function(){i.render()})}})};t.DEFAULTS={margin:12,blockEl:"i",patterns:["##--##oo"],specialPatterns:[]};t.prototype.setBlockWidth=function(e){this.blockWidth=e?e:(this.$el.innerWidth()-4*this.opts.margin)/4;return this};t.prototype.setBlocks=function(){this.blocks=this.$el.find(this.opts.blockEl).get().reverse();return this};t.prototype.renderBlock=function(t,n,r,i){var s=this.opts.margin,o=this.blockWidth,u=this.blocks.pop();if(u!==undefined){e(u).css({"margin-left":t*o+(t+1)*s,"margin-top":n*o+(n+1)*s,width:r*o+(r-1)*s,height:Math.ceil(i*o+(i-1)*s),display:"inline"})}return this};t.prototype.renderCanvas=function(e,t){for(var n=0,r=t.length;n<r;n++){var i=n%4,s=e+Math.floor(n/4);if(t[n]==="o"){this.renderBlock(i,s,1,1)}else if(t[n]==="#"){this.renderBlock(i,s,2,2);t[n]=t[n+1]=t[n+4]=t[n+5]="x"}else if(t[n]==="|"){this.renderBlock(i,s,1,2);t[n]=t[n+4]="x"}else if(t[n]==="-"){this.renderBlock(i,s,2,1);t[n]=t[n+1]="x"}}return this};t.prototype.render=function(){this.setBlocks().setBlockWidth();var t=0,n=0,r;while(this.blocks.length){var i=this.blocks.length,s="";if(i===1){this.$el.append(this.opts.blockFillEl);this.blocks.push(this.opts.blockFillEl);this.blocks[1]=this.blocks[0];this.blocks[0]=this.opts.blockFillEl}if(i<6&&this.opts.specialPatterns[i-1]){s=this.opts.specialPatterns[i-1]}else{s=this.opts.patterns[n]}this.renderCanvas(t,s.split(""));n=n+2===this.opts.patterns.length?0:n+1;t+=2}r=e("i:last");this.$el.height(parseInt(r.css("height"))+parseInt(r.css("margin-top")))};e.fn.layout=function(n){return this.each(function(){var r=e(this),i=r.data("layout"),s=e.extend({},t.DEFAULTS,r.data(),typeof n=="object"&&n);!i&&r.data("layout",i=new t(this,s));requestAnimationFrame(function(){r.data("layout").render()})})};e.fn.layout.Constructor=t}(window.jQuery);