-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheasyScroll.min.js
30 lines (30 loc) · 11.8 KB
/
easyScroll.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
easyScroll - 1.01 [03.06.16]
Author: vadimsva
Github: https://github.com/vadimsva/easyScroll
*/
$(function(){(function(a){if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))a.fn.easyScroll=function(){};else{var k=function(g,e,b,d){d=d?d:m;_options=a.fn.easyScroll._options;void 0==e&&(e=1);"up"==g?d.is("body")?b&&b==c?a(document).scrollTop(a(document).scrollTop()-_options.scrollStep*e):a(document).scrollLeft(a(document).scrollLeft()-_options.scrollStep*e):b&&b==c?d[0].scrollTop-=_options.scrollStep*e:d[0].scrollLeft-=_options.scrollStep*e:d.is("body")?
b&&b==c?a(document).scrollTop(a(document).scrollTop()+_options.scrollStep*e):a(document).scrollLeft(a(document).scrollLeft()+_options.scrollStep*e):b&&b==c?d[0].scrollTop+=_options.scrollStep*e:d[0].scrollLeft+=_options.scrollStep*e},r=function(a){return!a||a[0]==l||a.hasClass(b+"_container")?a:r(a.parent())},m,l=a(document)[0],b="easyScroll",c="vertical";a(document).mousemove(function(c){m=r(a(c.target))});var d=!1;a("html").keyup(function(a){d=!1});a("html").keydown(function(b){if(m&&!m.is(":focus")&&
!a(b.target).is(":focus")&&"TEXTAREA"!=a(b.target)[0].tagName&&"SELECT"!=a(b.target)[0].tagName&&"INPUT"!=a(b.target)[0].tagName)switch(_options=a.fn.easyScroll._options,b.which){case 17:d=!0;break;case 38:k("up",1,c);b.preventDefault();break;case 33:k("up",4,c);b.preventDefault();break;case 40:k("down",1,c);b.preventDefault();break;case 32:case 34:k("down",4,c);b.preventDefault();break;case 37:_options.scrollHorizontal&&(k("up",1,"horizontal"),b.preventDefault());break;case 39:_options.scrollHorizontal&&
(k("down",1,"horizontal"),b.preventDefault());break;case 36:_options.scrollHorizontal&&(k("up",4,"horizontal"),b.preventDefault());break;case 35:_options.scrollHorizontal&&(k("down",4,"horizontal"),b.preventDefault())}});var x=function(){var a=document.createElement("div"),e=["Khtml","Ms","O","Moz","Webkit"],b=e.length;return function(c){if(c in a.style)return!0;for(c=c.replace(/^[a-z]/,function(a){return a.toUpperCase()});b--;)if(e[b]+c in a.style)return!0;return!1}}()("transform");a.fn.easyScroll=
function(g){return this.each(function(){var e=a(this),l,m,H,I,q,v,r=0,t={init:function(){function t(d){var h="",J="";f.scrollButtons&&(d==c?(h='<div class="'+b+'_scrollBut scrollButTop">▴</div>',J='<div class="'+b+'_scrollBut scrollButBottom">▾</div>'):(h='<div class="'+b+'_scrollBut scrollButLeft">◂</div>',J='<div class="'+b+'_scrollBut scrollButRight">▸</div>'));h=a('<div class="'+b+"_scroll_"+d+" theme_"+f.theme+'">'+h+'<div class="'+b+'_slider"></div>'+J+"</div>");"HTML"==
e[0].tagName||"BODY"==e[0].tagName?(e=a("body"),h.attr("id",b+"_scrollBody_"+d),e.append(h)):e.after(h);d==c?e.css({paddingRight:h.outerWidth()+2*f.scrollOffset+"px"}):e.css({paddingBottom:h.outerHeight()+2*f.scrollOffset+"px"});f.scrollButtons&&(r=d==c?h.find("> .scrollButTop").outerHeight()+1:h.find("> .scrollButLeft").outerWidth()+1);return h}function y(d){function h(h){var u=0;if(h==c)var g=q,k=e[0].scrollHeight;else g=v,k=e[0].scrollWidth;if(e.is("body")){if(h==c){var n=a(window).height();"resize"!=
d&&"scroll"!=d&&g.css({top:f.scrollOffset+"px",right:f.scrollOffset+"px",bottom:f.scrollOffset+"px"})}else n=a(window).width(),"resize"!=d&&"scroll"!=d&&g.css({left:f.scrollOffset+"px",right:f.scrollOffset+"px",bottom:f.scrollOffset+"px"});var t=0}else{t=h==c?0:("visible"==q.css("visibility")?q.outerWidth():0)+f.scrollOffset;"TEXTAREA"==e[0].tagName&&void 0!=e.css("resize")&&"none"!=e.css("resize")&&(u=10,t=0);if(void 0!=g)var w=e.outerHeight(),p=e.outerWidth(),y=g.outerHeight(),F=g.outerWidth(),
C=parseInt(e.css("marginTop")),D=parseInt(e.css("marginBottom")),G=parseInt(e.css("marginLeft")),A=parseInt(e.css("borderTopWidth")),B=parseInt(e.css("borderLeftWidth"));if(!x)var E=parseInt(Number(e.position().top).toFixed(0)),z=parseInt(Number(e.position().left).toFixed(0));h==c?(n=w-A-parseInt(e.css("borderBottomWidth")),"scroll"!=d&&(x?(z=-w-D+A+f.scrollOffset,p=p+G-B-F-f.scrollOffset,g.css({transform:"translateX("+p+"px) translateY("+z+"px) translateZ(0.1px)",height:n-u-2*f.scrollOffset+"px"})):
(w=E+C+A+f.scrollOffset,p=z+p+G-B-F-f.scrollOffset,g.css({top:w+"px",left:p+"px",height:n-u-2*f.scrollOffset+"px"})))):(n=p-B-parseInt(e.css("borderRightWidth")),"TEXTAREA"!=e[0].tagName&&(n-=t),"scroll"!=d&&(x?(z=-D-A-y-f.scrollOffset,p=G+B+f.scrollOffset,g.css({transform:"translateX("+p+"px) translateY("+z+"px) translateZ(0.1px)",width:n-u-2*f.scrollOffset+"px"})):(w=E+C-A+w-y-f.scrollOffset,p=z+G+B+f.scrollOffset,g.css({top:w+"px",left:p+"px",width:n-u-2*f.scrollOffset+"px"}))))}void 0!=g&&(k<=
n+t?g.css({visibility:"hidden"}):(g.css({visibility:"visible"}),F=e.is("body")?h==c?a(document).scrollTop():a(document).scrollLeft():h==c?e.scrollTop():e.scrollLeft(),p=n/k*n-u-2*r,p<f.scrollMinHeight&&(p=n-u<f.scrollMinHeight?.75*n:f.scrollMinHeight),u=Number(F/(k-n-t)*(n-p-u-2*r)+r).toFixed(0),n/=p+2*r,g=g.find("> ."+b+"_slider"),h==c?(l=u,H=n,g.css({height:parseInt(Number(p).toFixed(0))-2*f.scrollOffset+"px",top:l+"px"})):(m=u,I=n,g.css({width:parseInt(Number(p).toFixed(0))-2*f.scrollOffset+"px",
left:m+"px"}))))}h(c);f.scrollHorizontal&&h("horizontal")}function C(){var a=setTimeout(function(){clearTimeout(a);y("resize")},100)}function D(g){var h=g==c?q:v;h.bind("mousewheel DOMMouseScroll",function(b){if(!d){var h=b.originalEvent,h=h.wheelDelta||-h.detail;e.is("body")?g==c?a(document).scrollTop(a(document).scrollTop()+(0>h?1:-1)*f.scrollStep):f.scrollHorizontal&&a(document).scrollLeft(a(document).scrollLeft()+(0>h?1:-1)*f.scrollStep):g==c?e[0].scrollTop+=(0>h?1:-1)*f.scrollStep:f.scrollHorizontal&&
(e[0].scrollLeft+=(0>h?1:-1)*f.scrollStep);b.preventDefault();return!1}});h.find("> ."+b+"_slider").mousedown(function(b){b.preventDefault();var d=e.is("body")?g==c?a(document).scrollTop():a(document).scrollLeft():g==c?e[0].scrollTop:e[0].scrollLeft;g==c?a(this).data("down",!0).data("y",b.clientY-d/H):a(this).data("down",!0).data("x",b.clientX-d/I);a(this).parent().addClass("active")});h.click(function(d){if(h.is(a(d.target))&&!h.find("> ."+b+"_slider").data("down")){if(g==c){var f=l;d=d.pageY-parseInt(a(this).offset().top);
var x=parseInt(h.find("> ."+b+"_slider").outerHeight())}else f=m,d=d.pageX-parseInt(a(this).offset().left),x=parseInt(h.find("> ."+b+"_slider").outerWidth());d>parseInt(f)+x?k("down",1,g,e):k("up",1,g,e)}})}function E(d){function g(a,b,c){if(c)k(b,1,d,e);else{a.mouseup(function(){clearInterval(f)});var f=setInterval(function(){k(b,1,d,e)},100)}}d==c?(q.find("> ."+b+"_scrollBut.scrollButTop").bind("mousedown click",function(b){"mousedown"==b.type?g(a(this),"up"):g(a(this),"up",!0)}),q.find("> ."+b+
"_scrollBut.scrollButBottom").bind("mousedown click",function(b){"mousedown"==b.type?g(a(this),"down"):g(a(this),"down",!0)})):(v.find("> ."+b+"_scrollBut.scrollButLeft").bind("mousedown click",function(b){"mousedown"==b.type?g(a(this),"up"):g(a(this),"up",!0)}),v.find("> ."+b+"_scrollBut.scrollButRight").bind("mousedown click",function(b){"mousedown"==b.type?g(a(this),"down"):g(a(this),"down",!0)}))}var f=a.extend({theme:"default",scrollAutoHide:!1,scrollOffset:1,scrollMinHeight:20,scrollStep:120,
scrollButtons:!1,scrollHorizontal:!1},g);a.fn.easyScroll._options=f;q=t(c);f.scrollHorizontal&&(v=t("horizontal"));var K="";f.scrollAutoHide&&(K=b+"_autoHide");e.addClass(b+"_container "+K);y();(e.is("body")?a(document):e).scroll(function(){y("scroll")});e.resize(C);e.attrchange({callback:function(){C()}});e.bind("mousewheel DOMMouseScroll",function(b){if(!d&&"auto"!=a(b.target).css("overflow")&&"scroll"!=a(b.target).css("overflow")){var c=b.originalEvent,c=c.wheelDelta||-c.detail,c=0>c?1:-1;e.is("body")?
"visible"==q.css("visibility")?a(document).scrollTop(a(document).scrollTop()+c*f.scrollStep):f.scrollHorizontal&&a(document).scrollLeft(a(document).scrollLeft()+c*f.scrollStep):"visible"==q.css("visibility")?this.scrollTop+=c*f.scrollStep:f.scrollHorizontal&&(this.scrollLeft+=c*f.scrollStep);b.preventDefault();return!1}});D(c);f.scrollHorizontal&&D("horizontal");a("html").mousemove(function(d){function g(f){var h=f==c?q:v;void 0!=h&&h.find("> ."+b+"_slider").data("down")&&(h=f==c?(d.clientY-h.find("> ."+
b+"_slider").data("y"))*H:(d.clientX-h.find("> ."+b+"_slider").data("x"))*I,e.is("body")?f==c?a(document).scrollTop(h):a(document).scrollLeft(h):f==c?e[0].scrollTop=h:e[0].scrollLeft=h)}g(c);f.scrollHorizontal&&g("horizontal")});a("html").mouseup(function(){void 0!=q&&q.find("> ."+b+"_slider").data("down")&&(q.find("> ."+b+"_slider").data("down",!1),q.removeClass("active"));f.scrollHorizontal&&void 0!=v&&v.find("> ."+b+"_slider").data("down")&&(v.find("> ."+b+"_slider").data("down",!1),v.removeClass("active"))});
f.scrollButtons&&(E(c),f.scrollHorizontal&&E("horizontal"))}};if(t[g])return t[g].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof g||!g)return t.init.apply(this,arguments)})}}})(jQuery)});
(function(a){function k(){var a=document.createElement("p"),c=!1;if(a.addEventListener)a.addEventListener("DOMAttrModified",function(){c=!0},!1);else if(a.attachEvent)a.attachEvent("onDOMAttrModified",function(){c=!0});else return!1;a.setAttribute("id","target");return c}function r(b,c){if(b){var d=this.data("attr-old-value");if(0<=c.attributeName.indexOf("style")){d.style||(d.style={});var k=c.attributeName.split(".");c.attributeName=k[0];c.oldValue=d.style[k[1]];c.newValue=k[1]+":"+this.prop("style")[a.camelCase(k[1])];
d.style[k[1]]=c.newValue}else c.oldValue=d[c.attributeName],c.newValue=this.attr(c.attributeName),d[c.attributeName]=c.newValue;this.data("attr-old-value",d)}}var m=window.MutationObserver||window.WebKitMutationObserver;a.fn.attrchange=function(a,c){if("object"==typeof a)return l._core.call(this,a);if("string"==typeof a)return l._ext.call(this,a,c)};var l={_core:function(b){var c={trackValues:!1,callback:a.noop};"function"===typeof b?c.callback=b:a.extend(c,b);c.trackValues&&this.each(function(b,
c){var d={},k;b=0;for(var l=c.attributes,m=l.length;b<m;b++)k=l.item(b),d[k.nodeName]=k.value;a(this).data("attr-old-value",d)});if(m){var d={subtree:!1,attributes:!0,attributeOldValue:c.trackValues},l=new m(function(b){b.forEach(function(b){var d=b.target;c.trackValues&&(b.newValue=a(d).attr(b.attributeName));c.callback.call(d,b)})});return this.data("attrchange-method","Mutation Observer").data("attrchange-obs",l).each(function(){l.observe(this,d)})}return k()?this.data("attrchange-method","DOMAttrModified").on("DOMAttrModified",
function(a){a.originalEvent&&(a=a.originalEvent);a.attributeName=a.attrName;a.oldValue=a.prevValue;c.callback.call(this,a)}):"onpropertychange"in document.body?this.data("attrchange-method","propertychange").on("propertychange",function(b){b.attributeName=window.event.propertyName;r.call(a(this),c.trackValues,b);c.callback.call(this,b)}):this},_ext:function(b,c){switch(b){case "disconnect":return this.each(function(){var b=a(this).data("attrchange-method");"propertychange"==b||"DOMAttrModified"==
b?a(this).off(b):"Mutation Observer"==b&&a(this).data("attrchange-obs").disconnect()}).removeData("attrchange-method")}}}})(jQuery);
(function(a,k,r){function m(){c=k.setTimeout(function(){l.each(function(){var b=a(this),c=b.width(),g=b.height(),e=a.data(this,"resize-special-event");c===e.w&&g===e.h||b.trigger("resize",[e.w=c,e.h=g])});m()},b.delay)}var l=a([]),b=a.resize=a.extend(a.resize,{}),c;b.delay=250;b.throttleWindow=!0;a.event.special.resize={setup:function(){if(!b.throttleWindow&&this.setTimeout)return!1;var c=a(this);l=l.add(c);a.data(this,"resize-special-event",{w:c.width(),h:c.height()});1===l.length&&m()},teardown:function(){if(!b.throttleWindow&&
this.setTimeout)return!1;var d=a(this);l=l.not(d);d.removeData("resize-special-event");l.length||clearTimeout(c)},add:function(c){function k(b,c,d){var l=a(this),m=a.data(this,"resize-special-event");m.w=c!==r?c:l.width();m.h=d!==r?d:l.height();g.apply(this,arguments)}if(!b.throttleWindow&&this.setTimeout)return!1;var g;if(a.isFunction(c))return g=c,k;g=c.handler;c.handler=k}}})(jQuery,this);