-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbar-on.min.js
1 lines (1 loc) · 3.12 KB
/
bar-on.min.js
1
$(function(){Object.defineProperty(Node.prototype,"realStyle",{get:function(){return this.currentStyle||window.getComputedStyle(this)},set:function(a){if("object"==typeof a){var b=this.style;for(var c in a)b[c]=a[c];return this}}}),$.fn.extend({barOn:function(a){return $(this).each(function(){jQuery.BarOn(this,a)}),this}}),$.extend({BarOn:function(a,b){var c,d,e=(a.to=a=$(a)).BarOn={doList:{auto:"",scroll:""},on:!0,toggle:function(){e.on?((c=$(".rBarOn",a)).length||(c=a.append('<div class="rBarOn" style="position:absolute"></div>').children(".rBarOn")),(d=$(".bBarOn",a)).length||(d=a.append('<div class="bBarOn" style="position:absolute"></div>').children(".bBarOn")),e.onDoModification(e.clearScroll),a.on({"scroll.baron":e.onScroll,"mousemove.baron":e.onHover}),$(window).on("resize.baron",e.drawScroll)):($(".rBarOn,.bBarOn",a).remove(),a.off({"scroll.baron":e.onScroll,"mousemove.baron":e.onHover}),$(window).off("resize.baron",e.drawScroll),e.onDoModification(e.restoreScroll)),e.on=!e.on},drawScroll:function(b){function f(a){return a+(a>0?.5:-.5)<<1>>1}var g,h,i,j,m,n,o,p,q,r,k=!0,l=!0;if((g=a)&&(h=a.tb)&&h[0]){c[0].realStyle=q={top:0,bottom:0,right:0,display:"none"},d[0].realStyle=r={left:0,bottom:0,right:0,display:"none"};do{for(;h&&h[0]!=a[0]&&(j=h[0].realStyle.overflow in e.doList);)e.clearScroll(null,h)?h=h.parent():null;k&&h.data("overflow-x")in e.doList&&(h.append(d),(p=h[0].scrollWidth)-(o=d.width())>2&&(r.left=f(j=h[0].scrollLeft*(1+(i=o/p)))+"px",r.bottom=f(-h[0].scrollTop+((n=h.height()+h.position().top-h.offsetParent().height())>0?n:0))+"px",r.right=f((p-o)*i-j+1)+"px",r.display="block",k=!1)),l&&h.data("overflow-y")in e.doList&&(h.append(c),(n=h[0].scrollHeight)-(m=c.height())>2&&(q.top=f(j=h[0].scrollTop*(1+(i=m/n)))+"px",q.right=f(-h[0].scrollLeft+((p=h.width()+h.position().left-h.offsetParent().width())>0?p:0))+"px",q.bottom=f((n-m)*i-j+1)+"px",q.display="block",l=!1))}while((k||l)&&h[0]!=g[0]&&(h=h.parent()));"none"!=q.display&&(n=c.parent(),c.detach(),c[0].realStyle=q,n.append(c)),"none"!=r.display&&(p=d.parent(),d.detach(),d[0].realStyle=r,p.append(d))}},onScroll:function(b,c,d){var f;a.tob&&(a.tb=a.tob.parents().filter(f=$(b.target)).length?a.tob:a.tob=f,e.drawScroll(b))},onHover:function(b){(a.tb=$(b.target))[0]!=(a.tob||[""])[0]&&(a.tob=a.tb,e.drawScroll(b))},onDoModification:function(b){$("*",a).add(a).each(b)},clearScroll:function(a,b){var c=!0,d=(b=$(b)).css("overflow-x"),f=b.data("overflow-x"),g=b.css("position"),h=b.css("overflow-y"),i=b.data("overflow-y"),j="static"==g?{position:"relative"}:{};if(d in e.doList&&"no-baron"!=f&&(b.data("overflow-x",d),j["overflow-x"]="hidden",c=!1),h in e.doList&&"no-baron"!=i&&(b.data("overflow-y",h),j["overflow-y"]="hidden",c=!1),c||b.css(j),null==a)return c},restoreScroll:function(a,b){var b=$(b),c=b.data("overflow-x"),d=b.data("overflow-y");c&&"no-baron"!=c&&b.data("overflow-x","").css("overflow-x",c),d&&"no-baron"!=d&&b.data("overflow-y","").css("overflow-y",d)}};return a.on({"BarOn.toggle":e.toggle,"BarOn.remove":function(){e.on||e.toggle(),e=null,a.off("BarOn.toggle BarOn.remove")}}),e.toggle(),("Info"in window&&Info||console).log("BarOn enter..."),e}}),$(".dragon").barOn()});