-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr.scroll.min.js
1 lines (1 loc) · 7.34 KB
/
tr.scroll.min.js
1
if(!TR){var TR={}}if(!TR.MouseMove){TR.MouseMove={x:0,y:0}}if(document.querySelector("mousemove_tr")===null){document.className+=" mousemove_tr";document.addEventListener("mousemove",function(a){TR.MouseMove.x=a.clientX||a.pageX;TR.MouseMove.y=a.clientY||a.pageY},false)}TR.NiceScroll=function(d,b){this.mOptions={};this.mOptions.Debug=false;this.mOptions.ScrollInnerSizeMin=20;this.mOptions.ForceScrollingMax=5;this.mOptions.EnableForceScrolling=true;this.mOptions.SensibilityTouch=10;this.mIdChild=d;this.mInterval=undefined;this.mForceScrollingCount=0;this.mTouchMouse={y:0};this.mTouchMouseStart={x:0,y:0};if(b){var a=this;for(var c in b){a.mOptions[c]=b[c]}}};TR.NiceScroll.prototype.Debug=function(a){if(this.mOptions.Debug){console.log("[NiceScroll] ",arguments)}};TR.NiceScroll.prototype.Remove=function(){var d=jQuery(this.mIdChild);var c=d.parent();var b=c.parent();if(!b.hasClass("NodeNiceScroll")){return}c.insertBefore(b);b.remove();if(this.mInterval!=undefined){window.clearInterval(this.mInterval);this.mInterval=undefined}c.css("overflow","auto");var a=c.prev();if(!a){return}if(!a.hasClass("tr_scrollbar")){return}a.remove();d.unbind("mousewheel.tr_scroll");d.unbind("touchstart.tr_scroll");d.unbind("touchend.tr_scroll");d.unbind("touchmove.tr_scroll")};TR.NiceScroll.prototype.Add=function(){this.Remove();var c=this;var j=jQuery(this.mIdChild);var f=j.parent();var i=f.scrollTop();var l='<div class="NodeNiceScroll" style="position:relative;"></div>';jQuery(l).insertBefore(f);f.prev().append(f);f.scrollTop(i);if(c.mOptions.Debug){if(j.length){c.Debug("TR.NiceScroll.Add -> "+this.mIdChild+" is found and attached")}else{c.Debug("ERROR: TR.NiceScroll.Add -> "+this.mIdChild+" is NOT found")}}function e(m){return a((m.deltaY*200),true,false)}j.unbind("mousewheel.tr_scroll").bind("mousewheel.tr_scroll",function(m){if(e(m)){return false}return true});j.unbind("touchstart.tr_scroll").children().bind("touchstart.tr_scroll",function(n){c.Debug("touchstart.tr_scroll");c.mTouchMouseStart.x=n.originalEvent.changedTouches[0].pageX;c.mTouchMouseStart.y=c.mTouchMouse.y=n.originalEvent.changedTouches[0].pageY;jQuery(this).unbind("touchmove.tr_scroll").bind("touchmove.tr_scroll",function(o){c.Debug("touchmove",o.originalEvent.changedTouches[0].pageY-c.mTouchMouse.y+" px");if(a((o.originalEvent.changedTouches[0].pageY-c.mTouchMouse.y),false,false)){c.mTouchMouse.y=o.originalEvent.changedTouches[0].pageY;return false}return true});function m(){jQuery(this).unbind("touchend.tr_scroll").unbind("touchcancel.tr_scroll")}jQuery(this).unbind("touchend.tr_scroll").bind("touchend.tr_scroll",function(o){c.Debug("touchend");if(o.originalEvent.changedTouches[0].pageY<(c.mTouchMouseStart.y+c.mOptions.SensibilityTouch)&&o.originalEvent.changedTouches[0].pageY>(c.mTouchMouseStart.y-c.mOptions.SensibilityTouch)){if(o.originalEvent.changedTouches[0].pageX<(c.mTouchMouseStart.x+c.mOptions.SensibilityTouch)&&o.originalEvent.changedTouches[0].pageX>(c.mTouchMouseStart.x-c.mOptions.SensibilityTouch)){c.Debug("touchend.tr_scroll",c.mTouchMouseStart.x,c.mTouchMouseStart.y);document.elementFromPoint(c.mTouchMouseStart.x,c.mTouchMouseStart.y).click()}}m.call(this);return true});jQuery(this).unbind("touchcancel.tr_scroll").bind("touchcancel.tr_scroll",function(o){c.Debug("touchcancel");m.call(this);return true});return false});function a(v,q,x){var t=f.innerHeight();var n=j.outerHeight();var w=f.prev();if(!w){return}if(!w.hasClass("tr_scrollbar")){return}var r=w.find(".tr_scrollbar_inner");var s=f.scrollTop();if(c.mOptions.Debug){c.Debug("_pixels:",v);c.Debug("tCurrentTopPos:",s);c.Debug("tParentHeight:",t);c.Debug("tChildHeight:",n);c.Debug("tChildHeight-tParentHeight:",n-t)}var p=((t)-((t/n)*t));if(p+c.mOptions.ScrollInnerSizeMin>t){p=t-c.mOptions.ScrollInnerSizeMin}if(q){if(x){var u=-r.position().top;var m=(-u)-v;c.Debug("tScrollBarInnerPositionTop:",u);if(m<0){m=0}else{if(m>p){m=p}}r.css({top:m+"px"});var o=m/p*(n-t);f.scrollTop(o)}else{var u=-f.scrollTop();var m=(-u)-v;c.Debug("tScrollBarInnerPositionTop:",u);if(m<0){m=0}else{if(m>(n-t)){m=(n-t)}}f.stop().animate({scrollTop:m},100,"linear");var o=m/(n-t)*p;r.stop().animate({top:o},100,"linear")}}else{var u=-f.scrollTop();var m=(-u)-v;c.Debug("tScrollBarInnerPositionTop:",u);if(m<0){m=0}else{if(m>(n-t)){m=(n-t)}}f.scrollTop(m);var o=m/(n-t)*p;r.css({top:o+"px"})}if(s===f.scrollTop()){if(c.mOptions.EnableForceScrolling){++c.mForceScrollingCount;if(c.mForceScrollingCount>c.mOptions.ForceScrollingMax){c.mForceScrollingCount=0;return false}}return true}c.mForceScrollingCount=0;return true}var g=this.mIdChild;function k(){var w=f.prev();if(w&&w.hasClass("tr_scrollbar")){w.remove()}f.css("overflow","hidden");var r=f.innerHeight();var u=0;var m=j.outerHeight();if(r<m){u+=parseFloat(f.css("border-top-width"));var v="";v+='<div class="tr_scrollbar tr_scrollbar_invible" style="height:'+r+"px;margin-top:"+u+'px" onmouseover="TR.SetScrollBarBigger(\''+g+"')\" onmouseout=\"TR.SetScrollBarSmaller('"+g+"')\">";v+='<div class="tr_scrollbar_background" style="height:'+r+'px;">';v+='<div class="tr_scrollbar_inner" style="height:'+(r/m)*100+'%">';v+="</div>";v+="</div>";v+="</div>";jQuery(v).insertBefore(f);var s=false;var n=TR.MouseMove.y;var w=f.prev();if(!w){return}if(!w.hasClass("tr_scrollbar")){return}var q=w.find(".tr_scrollbar_inner");var t=0;var o=w.children(".tr_scrollbar_background");if(q.height()<c.mOptions.ScrollInnerSizeMin){q.height(c.mOptions.ScrollInnerSizeMin)}w.css({"margin-left":(f.outerWidth()-parseFloat(f.css("border-left-width"))-parseFloat(f.css("border-right-width"))+parseFloat(f.css("margin-left"))-30)+"px"});var p=0;a(0,true,false);o.click(function(z){if(TR.MouseMove.y<q.offset().top){a(o.height()*0.8,true,false)}else{a(-o.height()*0.8,true,false)}return false});w.bind("mousewheel",function(z){e(z);return false});q.mousedown(function(){p=1;n=TR.MouseMove.y;t=q.position().top;s=true;jQuery("body").append('<div class="tr_scrollbar_scrolling_dontloose_focus tr_scrollbar_invible"></div>');jQuery(".tr_scrollbar_scrolling_dontloose_focus").css("position","fixed").css("top",(w.offset().top-200)+"px").css("left",w.offset().left-200+"px").css("height",(r+400)+"px").css("width","440px");jQuery("body").addClass("tr_forbid_selection");jQuery(".tr_scrollbar_scrolling_dontloose_focus").mouseup(function(){y()}).mouseleave(function(){y()}).mousemove(function(){if(s){x();TR.SetScrollBarBigger(g,true)}n=TR.MouseMove.y})});function y(){s=false;jQuery(".tr_scrollbar_scrolling_dontloose_focus").remove();jQuery("body").removeClass("tr_forbid_selection");TR.SetScrollBarSmaller(g)}function x(){a(n-TR.MouseMove.y,true,true)}}}var b=-1;var d=-1;var h=-1;this.mInterval=setInterval(function(){if((b!=j.width())||(d!=j.innerHeight())||(h!=f.innerHeight())){b=j.width();d=j.innerHeight();h=f.innerHeight();k()}},500);k()};TR.SetScrollBarBigger=function(d,b){b=b||false;var e=jQuery(d);var c=e.parent();var a=c.prev();if(!a){return}if(!a.hasClass("tr_scrollbar")){return}a.find(".tr_scrollbar_background").addClass("tr_scrollbar_width_hover");a.find(".tr_scrollbar_inner").addClass("tr_scrollbar_width_hover");if(b){a.find(".tr_scrollbar_inner").addClass("tr_scrollbar_inner_hover")}};TR.SetScrollBarSmaller=function(c){var d=jQuery(c);var b=d.parent();var a=b.prev();if(!a){return}if(!a.hasClass("tr_scrollbar")){return}a.find(".tr_scrollbar_background").removeClass("tr_scrollbar_width_hover");a.find(".tr_scrollbar_inner").removeClass("tr_scrollbar_width_hover").removeClass("tr_scrollbar_inner_hover")};