You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
11 KiB
1 lines
11 KiB
!function(l,e){"function"==typeof define&&define.amd?define(["jquery"],e):e(l.jQuery)}(this,function(l){"use strict";var e={data:{index:0,name:"scrollbar"},macosx:/mac/i.test(navigator.platform),mobile:/android|webos|iphone|ipad|ipod|blackberry/i.test(navigator.userAgent),overlay:null,scroll:null,scrolls:[],webkit:/webkit/i.test(navigator.userAgent)&&!/edge\/\d+/i.test(navigator.userAgent)};e.scrolls.add=function(l){this.remove(l).push(l)},e.scrolls.remove=function(e){for(;l.inArray(e,this)>=0;)this.splice(l.inArray(e,this),1);return this};var o={autoScrollSize:!0,autoUpdate:!0,debug:!1,disableBodyScroll:!1,duration:200,ignoreMobile:!1,ignoreOverlay:!1,scrollStep:30,showArrows:!1,stepScrolling:!0,scrollx:null,scrolly:null,onDestroy:null,onInit:null,onScroll:null,onUpdate:null},s=function(s){var r;e.scroll||(e.overlay=!((r=c(!0)).height||r.width),e.scroll=c(),n(),l(window).resize(function(){var l=!1;if(e.scroll&&(e.scroll.height||e.scroll.width)){var o=c();o.height===e.scroll.height&&o.width===e.scroll.width||(e.scroll=o,l=!0)}n(l)})),this.container=s,this.namespace=".scrollbar_"+e.data.index++,this.options=l.extend({},o,window.jQueryScrollbarOptions||{}),this.scrollTo=null,this.scrollx={},this.scrolly={},s.data(e.data.name,this),e.scrolls.add(this)};s.prototype={destroy:function(){if(this.wrapper){this.container.removeData(e.data.name),e.scrolls.remove(this);var o=this.container.scrollLeft(),s=this.container.scrollTop();this.container.insertBefore(this.wrapper).css({height:"",margin:"","max-height":""}).removeClass("scroll-content scroll-scrollx_visible scroll-scrolly_visible").off(this.namespace).scrollLeft(o).scrollTop(s),this.scrollx.scroll.removeClass("scroll-scrollx_visible").find("div").andSelf().off(this.namespace),this.scrolly.scroll.removeClass("scroll-scrolly_visible").find("div").andSelf().off(this.namespace),this.wrapper.remove(),l(document).add("body").off(this.namespace),l.isFunction(this.options.onDestroy)&&this.options.onDestroy.apply(this,[this.container])}},init:function(o){var s=this,r=this.container,t=this.containerWrapper||r,i=this.namespace,n=l.extend(this.options,o||{}),c={x:this.scrollx,y:this.scrolly},d=this.wrapper,h={scrollLeft:r.scrollLeft(),scrollTop:r.scrollTop()};if(e.mobile&&n.ignoreMobile||e.overlay&&n.ignoreOverlay||e.macosx&&!e.webkit)return!1;if(d)t.css({height:"auto","margin-bottom":-1*e.scroll.height+"px","margin-right":-1*e.scroll.width+"px","max-height":""});else{if(this.wrapper=d=l("<div>").addClass("scroll-wrapper").addClass(r.attr("class")).css("position","absolute"==r.css("position")?"absolute":"relative").insertBefore(r).append(r),r.is("textarea")&&(this.containerWrapper=t=l("<div>").insertBefore(r).append(r),d.addClass("scroll-textarea")),t.addClass("scroll-content").css({height:"auto","margin-bottom":-1*e.scroll.height+"px","margin-right":-1*e.scroll.width+"px","max-height":""}),r.on("scroll"+i,function(e){l.isFunction(n.onScroll)&&n.onScroll.call(s,{maxScroll:c.y.maxScrollOffset,scroll:r.scrollTop(),size:c.y.size,visible:c.y.visible},{maxScroll:c.x.maxScrollOffset,scroll:r.scrollLeft(),size:c.x.size,visible:c.x.visible}),c.x.isVisible&&c.x.scroll.bar.css("left",r.scrollLeft()*c.x.kx+"px"),c.y.isVisible&&c.y.scroll.bar.css("top",r.scrollTop()*c.y.kx+"px")}),d.on("scroll"+i,function(){d.scrollTop(0).scrollLeft(0)}),n.disableBodyScroll){var p=function(l){a(l)?c.y.isVisible&&c.y.mousewheel(l):c.x.isVisible&&c.x.mousewheel(l)};d.on("MozMousePixelScroll"+i,p),d.on("mousewheel"+i,p),e.mobile&&d.on("touchstart"+i,function(e){var o=e.originalEvent.touches&&e.originalEvent.touches[0]||e,s=o.pageX,t=o.pageY,n=r.scrollLeft(),c=r.scrollTop();l(document).on("touchmove"+i,function(l){var e=l.originalEvent.targetTouches&&l.originalEvent.targetTouches[0]||l;r.scrollLeft(n+s-e.pageX),r.scrollTop(c+t-e.pageY),l.preventDefault()}),l(document).on("touchend"+i,function(){l(document).off(i)})})}l.isFunction(n.onInit)&&n.onInit.apply(this,[r])}l.each(c,function(e,o){var t=null,d=1,h="x"===e?"scrollLeft":"scrollTop",p=n.scrollStep,u=function(){var l=r[h]();r[h](l+p),1==d&&l+p>=f&&(l=r[h]()),-1==d&&l+p<=f&&(l=r[h]()),r[h]()==l&&t&&t()},f=0;o.scroll||(o.scroll=s._getScroll(n["scroll"+e]).addClass("scroll-"+e),n.showArrows&&o.scroll.addClass("scroll-element_arrows_visible"),o.mousewheel=function(l){if(!o.isVisible||"x"===e&&a(l))return!0;if("y"===e&&!a(l))return c.x.mousewheel(l),!0;var t=-1*l.originalEvent.wheelDelta||l.originalEvent.detail,i=o.size-o.visible-o.offset;return(t>0&&f<i||t<0&&f>0)&&((f+=t)<0&&(f=0),f>i&&(f=i),s.scrollTo=s.scrollTo||{},s.scrollTo[h]=f,setTimeout(function(){s.scrollTo&&(r.stop().animate(s.scrollTo,240,"linear",function(){f=r[h]()}),s.scrollTo=null)},1)),l.preventDefault(),!1},o.scroll.on("MozMousePixelScroll"+i,o.mousewheel).on("mousewheel"+i,o.mousewheel).on("mouseenter"+i,function(){f=r[h]()}),o.scroll.find(".scroll-arrow, .scroll-element_track").on("mousedown"+i,function(i){if(1!=i.which)return!0;d=1;var c={eventOffset:i["x"===e?"pageX":"pageY"],maxScrollValue:o.size-o.visible-o.offset,scrollbarOffset:o.scroll.bar.offset()["x"===e?"left":"top"],scrollbarSize:o.scroll.bar["x"===e?"outerWidth":"outerHeight"]()},a=0,v=0;return l(this).hasClass("scroll-arrow")?(d=l(this).hasClass("scroll-arrow_more")?1:-1,p=n.scrollStep*d,f=d>0?c.maxScrollValue:0):(d=c.eventOffset>c.scrollbarOffset+c.scrollbarSize?1:c.eventOffset<c.scrollbarOffset?-1:0,p=Math.round(.75*o.visible)*d,f=c.eventOffset-c.scrollbarOffset-(n.stepScrolling?1==d?c.scrollbarSize:0:Math.round(c.scrollbarSize/2)),f=r[h]()+f/o.kx),s.scrollTo=s.scrollTo||{},s.scrollTo[h]=n.stepScrolling?r[h]()+p:f,n.stepScrolling&&(t=function(){f=r[h](),clearInterval(v),clearTimeout(a),a=0,v=0},a=setTimeout(function(){v=setInterval(u,40)},n.duration+100)),setTimeout(function(){s.scrollTo&&(r.animate(s.scrollTo,n.duration),s.scrollTo=null)},1),s._handleMouseDown(t,i)}),o.scroll.bar.on("mousedown"+i,function(t){if(1!=t.which)return!0;var n=t["x"===e?"pageX":"pageY"],c=r[h]();return o.scroll.addClass("scroll-draggable"),l(document).on("mousemove"+i,function(l){var s=parseInt((l["x"===e?"pageX":"pageY"]-n)/o.kx,10);r[h](c+s)}),s._handleMouseDown(function(){o.scroll.removeClass("scroll-draggable"),f=r[h]()},t)}))}),l.each(c,function(l,e){var o="scroll-scroll"+l+"_visible",s="x"==l?c.y:c.x;e.scroll.removeClass(o),s.scroll.removeClass(o),t.removeClass(o)}),l.each(c,function(e,o){l.extend(o,"x"==e?{offset:parseInt(r.css("left"),10)||0,size:r.prop("scrollWidth"),visible:d.width()}:{offset:parseInt(r.css("top"),10)||0,size:r.prop("scrollHeight"),visible:d.height()})}),this._updateScroll("x",this.scrollx),this._updateScroll("y",this.scrolly),l.isFunction(n.onUpdate)&&n.onUpdate.apply(this,[r]),l.each(c,function(l,e){var o="x"===l?"left":"top",s="x"===l?"outerWidth":"outerHeight",t="x"===l?"width":"height",i=parseInt(r.css(o),10)||0,c=e.size,a=e.visible+i,d=e.scroll.size[s]()+(parseInt(e.scroll.size.css(o),10)||0);n.autoScrollSize&&(e.scrollbarSize=parseInt(d*a/c,10),e.scroll.bar.css(t,e.scrollbarSize+"px")),e.scrollbarSize=e.scroll.bar[s](),e.kx=(d-e.scrollbarSize)/(c-a)||1,e.maxScrollOffset=c-a}),r.scrollLeft(h.scrollLeft).scrollTop(h.scrollTop).trigger("scroll")},_getScroll:function(e){var o={advanced:['<div class="scroll-element">','<div class="scroll-element_corner"></div>','<div class="scroll-arrow scroll-arrow_less"></div>','<div class="scroll-arrow scroll-arrow_more"></div>','<div class="scroll-element_outer">','<div class="scroll-element_size"></div>','<div class="scroll-element_inner-wrapper">','<div class="scroll-element_inner scroll-element_track">','<div class="scroll-element_inner-bottom"></div>',"</div>","</div>",'<div class="scroll-bar">','<div class="scroll-bar_body">','<div class="scroll-bar_body-inner"></div>',"</div>",'<div class="scroll-bar_bottom"></div>','<div class="scroll-bar_center"></div>',"</div>","</div>","</div>"].join(""),simple:['<div class="scroll-element">','<div class="scroll-element_outer">','<div class="scroll-element_size"></div>','<div class="scroll-element_track"></div>','<div class="scroll-bar"></div>',"</div>","</div>"].join("")};return o[e]&&(e=o[e]),e||(e=o.simple),e="string"==typeof e?l(e).appendTo(this.wrapper):l(e),l.extend(e,{bar:e.find(".scroll-bar"),size:e.find(".scroll-element_size"),track:e.find(".scroll-element_track")}),e},_handleMouseDown:function(e,o){var s=this.namespace;return l(document).on("blur"+s,function(){l(document).add("body").off(s),e&&e()}),l(document).on("dragstart"+s,function(l){return l.preventDefault(),!1}),l(document).on("mouseup"+s,function(){l(document).add("body").off(s),e&&e()}),l("body").on("selectstart"+s,function(l){return l.preventDefault(),!1}),o&&o.preventDefault(),!1},_updateScroll:function(o,s){var r=this.container,t=this.containerWrapper||r,i="scroll-scroll"+o+"_visible",n="x"===o?this.scrolly:this.scrollx,c=parseInt(this.container.css("x"===o?"left":"top"),10)||0,a=this.wrapper,d=s.size,h=s.visible+c;s.isVisible=d-h>1,s.isVisible?(s.scroll.addClass(i),n.scroll.addClass(i),t.addClass(i)):(s.scroll.removeClass(i),n.scroll.removeClass(i),t.removeClass(i)),"y"===o&&(r.is("textarea")||d<h?t.css({height:h+e.scroll.height+"px","max-height":"none"}):t.css({"max-height":h+e.scroll.height+"px"})),s.size==r.prop("scrollWidth")&&n.size==r.prop("scrollHeight")&&s.visible==a.width()&&n.visible==a.height()&&s.offset==(parseInt(r.css("left"),10)||0)&&n.offset==(parseInt(r.css("top"),10)||0)||(l.extend(this.scrollx,{offset:parseInt(r.css("left"),10)||0,size:r.prop("scrollWidth"),visible:a.width()}),l.extend(this.scrolly,{offset:parseInt(r.css("top"),10)||0,size:this.container.prop("scrollHeight"),visible:a.height()}),this._updateScroll("x"===o?"y":"x",n))}};var r=s;l.fn.scrollbar=function(o,s){return"string"!=typeof o&&(s=o,o="init"),void 0===s&&(s=[]),l.isArray(s)||(s=[s]),this.not("body, .scroll-wrapper").each(function(){var t=l(this),i=t.data(e.data.name);(i||"init"===o)&&(i||(i=new r(t)),i[o]&&i[o].apply(i,s))}),this},l.fn.scrollbar.options=o;var t,i,n=(t=0,function(l){var o,s,r,i,c,a,d;for(o=0;o<e.scrolls.length;o++)s=(i=e.scrolls[o]).container,r=i.options,c=i.wrapper,a=i.scrollx,d=i.scrolly,(l||r.autoUpdate&&c&&c.is(":visible")&&(s.prop("scrollWidth")!=a.size||s.prop("scrollHeight")!=d.size||c.width()!=a.visible||c.height()!=d.visible))&&(i.init(),r.debug&&window.console&&console.log({scrollHeight:s.prop("scrollHeight")+":"+i.scrolly.size,scrollWidth:s.prop("scrollWidth")+":"+i.scrollx.size,visibleHeight:c.height()+":"+i.scrolly.visible,visibleWidth:c.width()+":"+i.scrollx.visible},!0));clearTimeout(t),t=setTimeout(n,300)});function c(o){if(e.webkit&&!o)return{height:0,width:0};if(!e.data.outer){var s={border:"none","box-sizing":"content-box",height:"200px",margin:"0",padding:"0",width:"200px"};e.data.inner=l("<div>").css(l.extend({},s)),e.data.outer=l("<div>").css(l.extend({left:"-1000px",overflow:"scroll",position:"absolute",top:"-1000px"},s)).append(e.data.inner).appendTo("body")}return e.data.outer.scrollLeft(1e3).scrollTop(1e3),{height:Math.ceil(e.data.outer.offset().top-e.data.inner.offset().top||0),width:Math.ceil(e.data.outer.offset().left-e.data.inner.offset().left||0)}}function a(l){var e=l.originalEvent;return(!e.axis||e.axis!==e.HORIZONTAL_AXIS)&&!e.wheelDeltaX}window.angular&&(i=window.angular).module("jQueryScrollbar",[]).provider("jQueryScrollbar",function(){var l=o;return{setOptions:function(e){i.extend(l,e)},$get:function(){return{options:i.copy(l)}}}}).directive("jqueryScrollbar",["jQueryScrollbar","$parse",function(l,e){return{restrict:"AC",link:function(o,s,r){var t=e(r.jqueryScrollbar)(o);s.scrollbar(t||l.options).on("$destroy",function(){s.scrollbar("destroy")})}}}])});
|