-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.blutack.min.js
1 lines (1 loc) · 3.34 KB
/
jquery.blutack.min.js
1
(function(){"use strict";function t(t){var e=i(w(t));return void 0===e||null===e}function i(t){return t.data("tackProps")}function e(t,i){t.data("tackProps",i)}function n(i){if(t(this)){var n=w(this),o=i.offsetTop,s=n.offset(),a=s.top-o,f=n.css("position")||"static",r={offsetTop:parseInt(o,10),offsetLeft:"static"!=f?s.left:"auto",tackAt:a,proxyId:b+x,keepWithin:i.keepWithin?w(i.keepWithin):null,height:n.outerHeight(),initial:{position:f,width:i.freezeWidth?n.css("width"):"auto",top:n.css("top")||"auto",right:n.css("right"),left:n.css("left"),"float":n.css("float")},options:i};e(n,r),m[a]?m[a].free.push(n):m[a]={free:[n],tacked:[]},x+=1,W+=1,y.push(this),1!=W||I||(I=!0,l()),c()}}function o(){var t,n=w(this),o=i(n)||{},s=n.hasClass(T)?"tacked":"free",a=m[o.tackAt];if(a)for(t=a[s].length-1;t>=0;t--)if(a[s][t].get(0)==this){a[s].splice(t,1),f(n),e(n,null),W-=1,w("#"+o.proxyId).remove();break}for(var t=y.length-1;t>=0;t--)if(y[t]==this){y.splice(t,1);break}}function s(t){var e=i(t),n=w("#"+e.proxyId),o=!n.length;o&&(n=w('<div id="'+e.proxyId+'"></div>'),n.insertBefore(t)),u(t),t.css({position:"fixed",top:e.offsetTop,left:e.offsetLeft,right:"auto"}).addClass(T).data("isPinched",!1),o&&n.height(e.height).css(e.initial),n.show()}function a(t,e){var n=i(t);t.css({top:n.offsetTop+e}).data("isPinched",!0)}function f(t){var e=i(t);w("#"+e.proxyId).hide(),t.css(e.initial).removeClass(T)}function r(){var t=i(w(this)),e=t?t.options:null;return t?(o.apply(this),n.apply(this,[e]),void 0):!1}function h(t,e){var n,o=i(t),f=o.keepWithin;f&&(n=f.offset().top+f.height()-e-(o.height+o.offsetTop),0>n?a(t,n):t.data("isPinched")&&n>=0&&s(t))}function c(t){if(g)clearTimeout(g);else{var i=P.height();i!=v&&(v=i,C())}g=setTimeout(function(){g=null},300);var e,n,o,a,r,c,u=w(window).scrollTop(),l=t&&void 0!==d?u>d?"down":"up":null;if(t&&(d=u),!W)return!1;for(r in m)if(m.hasOwnProperty(r)){if(r=Number(r),e=m[r],o=e.tacked,a=e.free,"up"!=l&&u>r&&!e.fixing){for(e.fixing=!0,c=a.length-1;c>=0;c--)n=a.pop(),s(n),o.push(n);e.fixing=!1}else if("down"!=l&&r>=u&&!e.fixing){for(e.fixing=!0,c=o.length-1;c>=0;c--)n=o.pop(),f(n),a.push(n);e.fixing=!1}for(c=o.length-1;c>=0;c--)h(o[c],u)}}function u(t){var e=i(t),n=e.initial.width!="auto"?e.initial.width:t.parent().width()-(t.outerWidth()-t.width());t.width(n)}function l(){W&&(v=P.height(),w(window).scroll(c),w(window).on("resize",C),w("body").on("orientationchange",C).on("touchend",c))}function p(t,i){var e,n,o,s,a,f={offsetTop:0,freezeWidth:!1},r=(w(t).data("blutack-options")||"").split(";"),h={};for(a=r.length-1;a>=0;a--)e=r[a].split(":"),e.length==2&&(n=w.trim(e[0]),f[n]!==void 0&&(o=w.trim(e[1]),s=o.match(/d+/),s&&s.length==o.length?o=Number(o):"false"===o?o=!1:"true"===o&&(o=!0),h[n]=o));return w.extend({},f,h,i)}var d,g,v,k=this,w=k.jQuery,y=[],m={},x=0,b="blutack-proxy-",T="blutacked",W=0,I=!1,P=w(document);if(w.fn.blutack)return!1;var C=function(){var t;return function(){clearTimeout(t),t=setTimeout(function(){var t,e,s=[];for(e=y.length-1;e>=0;e--)t=y[e],s.push({elem:t,options:i(w(t)).options}),o.apply(t);for(e=s.length-1;e>=0;e--)n.apply(s[e].elem,[s[e].options])},200)}}();w.fn.blutack=function(t){return"remove"==t?this.each(function(){o.apply(this)}):"retack"==t?this.each(function(){r.apply(this)}):"tacked"==t?this.hasClass(T):this.each(function(){n.apply(this,[p(this,t)])})},w(document).ready(function(){w(".blutack").blutack()})}).call(this);