-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtailorfit-1.5.9.min.js
1 lines (1 loc) · 2.95 KB
/
tailorfit-1.5.9.min.js
1
(function(d){var b={"max-width":0,"max-height":0,"aspect-ratio":0,"x-offset":0,"y-offset":0,"v-position":"center","h-position":"center","rounding-method":"round",overflow:"contain"};d.fn.tailorfit=function(p,r){return this.each(function(){var v=d(this);var s=v.data("tailorfit")==="active";if(typeof p==="string"&&r!==undefined){v.data(p,r);if(s){q(v)}return v}else{var u=d.extend(b,p);for(var t in u){if(u.hasOwnProperty(t)){v.data(t,u[t])}}}v.data("tailorfit","active");if(s){d(window).off(".tailorfit")}v.css({position:"relative",display:"block"});d(window).on("load.tailorfit resize.tailorfit",function(){q(v)});q(v)});function q(s){var u=s.parent();var E=u.width();var M=u.height();var K=s.data("max-width");var F=s.data("max-height");var G=s.data("overflow");var t=G==="crop";if(t){u.css("overflow","hidden")}else{u.css("overflow","visible")}var z,v,A,I;var N=i(s.data("rounding-method"));if(!(K&&F)){if(!K){z=g(s.data("h-position"),E,s.width());s.css({left:N(z)})}if(!F){v=f(s.data("v-position"),M,s.height());s.css({top:N(v)})}return}var D=l(s.data("aspect-ratio"),E,M);var H=E/M;var C=l(K,E,M);var L=l(F,E,M);if(D===0){if(t){I=L;A=C}else{I=Math.min(L,M);A=Math.min(C,E)}}else{if(t){if(H>=D){A=Math.min(C,E);I=A/D}else{I=Math.min(M,L);A=I*D}}else{var J=Math.min(L,M);var B=Math.min(C,E);I=Math.min(J,B/D);A=D*I}}z=g(s.data("h-position"),E,A);v=f(s.data("v-position"),M,I);z+=l(s.data("x-offset"),E,M);v+=l(s.data("y-offset"),E,M);s.css({left:N(z),top:N(v),width:N(A),height:N(I)})}};function g(p,r,q){switch(p){case"left":return 0;case"right":return r-q;default:return(r-q)/2}}function f(p,r,q){switch(p){case"top":return 0;case"bottom":return r-q;default:return(r-q)/2}}Array.prototype.peek=function(){return this[this.length-1]};function l(r,p,q){if(a(r)){r=r.replace(/\s+/g,"");r=r.replace(/width|w/gi,p);r=r.replace(/height|h/gi,q);return h(o(r))}else{return e(r)}}function o(r){var t=[];var p=["("];r=r.match(/[\-\+\*\/\^%()]|(\d+(\.\d+)?)+/g);r.push(")");var q=0;while(p.length>0){var s=r[q++];if(m(s)){t.push(s)}else{if(s==="("){p.push(s)}else{if(s===")"){while(p.peek()!=="("){t.push(p.pop())}p.pop()}else{while(k(p.peek())){if(j(p.peek(),s)){t.push(p.pop())}else{break}}p.push(s)}}}}return t}function h(v){var q=[];var t=v.length;for(var s=0;s<t;s++){var r=v[s];if(m(r)){q.push(parseFloat(r))}else{var u=q.pop();var p=q.pop();q.push(c(p,u,r))}}return q.pop()}function c(p,r,q){p=parseFloat(p);r=parseFloat(r);switch(q[0]){case"+":return p+r;case"-":return p-r;case"*":return p*r;case"/":return p/r;case"%":return p%r;default:return Math.pow(p,r)}}function i(p){switch(p){case"round":return Math.round;case"floor":return Math.floor;default:return Math.ceil}}function n(p){switch(p){case"^":return 2;case"+":case"-":return 0;default:return 1}}function j(q,p){return n(q)>=n(p)}function e(p,q){return isNaN(p=parseFloat(p))?q||0:p}function m(p){return(/\d+(\.\d+)?/).test(p)}function k(p){return p==="+"||p==="-"||p==="*"||p==="/"||p==="^"||p==="%"}function a(p){return(/[\-\+\*\/\^%]/).test(p)}})(jQuery);