UNPKG

lixin-web

Version:

vue and bootstrap

1,314 lines (1,135 loc) 91.2 kB
/* == malihu jquery custom scrollbar plugin == Version: 3.1.3 Plugin URI: http://manos.malihu.gr/jquery-custom-content-scroller Author: malihu Author URI: http://manos.malihu.gr License: MIT License (MIT) */ /* Copyright Manos Malihutsakis (email: manos@malihu.gr) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* The code below is fairly long, fully commented and should be normally used in development. For production, use either the minified jquery.mCustomScrollbar.min.js script or the production-ready jquery.mCustomScrollbar.concat.min.js which contains the plugin and dependencies (minified). */ (function(factory){ if(typeof module!=="undefined" && module.exports){ module.exports=factory; }else{ factory(jQuery,window,document); } }(function($){ (function(init){ var _rjs=typeof define==="function" && define.amd, /* RequireJS */ _njs=typeof module !== "undefined" && module.exports, /* NodeJS */ _dlp=("https:"==document.location.protocol) ? "https:" : "http:", /* location protocol */ _url="cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"; if(!_rjs){ if(_njs){ require("jquery-mousewheel")($); }else{ /* load jquery-mousewheel plugin (via CDN) if it's not present or not loaded via RequireJS (works when mCustomScrollbar fn is called on window load) */ $.event.special.mousewheel || $("head").append(decodeURI("%3Cscript src="+_dlp+"//"+_url+"%3E%3C/script%3E")); } } init(); }(function(){ /* ---------------------------------------- PLUGIN NAMESPACE, PREFIX, DEFAULT SELECTOR(S) ---------------------------------------- */ var pluginNS="mCustomScrollbar", pluginPfx="mCS", defaultSelector=".mCustomScrollbar", /* ---------------------------------------- DEFAULT OPTIONS ---------------------------------------- */ defaults={ /* set element/content width/height programmatically values: boolean, pixels, percentage option default ------------------------------------- setWidth false setHeight false */ /* set the initial css top property of content values: string (e.g. "-100px", "10%" etc.) */ setTop:0, /* set the initial css left property of content values: string (e.g. "-100px", "10%" etc.) */ setLeft:0, /* scrollbar axis (vertical and/or horizontal scrollbars) values (string): "y", "x", "yx" */ axis:"y", /* position of scrollbar relative to content values (string): "inside", "outside" ("outside" requires elements with position:relative) */ scrollbarPosition:"inside", /* scrolling inertia values: integer (milliseconds) */ scrollInertia:950, /* auto-adjust scrollbar dragger length values: boolean */ autoDraggerLength:true, /* auto-hide scrollbar when idle values: boolean option default ------------------------------------- autoHideScrollbar false */ /* auto-expands scrollbar on mouse-over and dragging values: boolean option default ------------------------------------- autoExpandScrollbar false */ /* always show scrollbar, even when there's nothing to scroll values: integer (0=disable, 1=always show dragger rail and buttons, 2=always show dragger rail, dragger and buttons), boolean */ alwaysShowScrollbar:0, /* scrolling always snaps to a multiple of this number in pixels values: integer, array ([y,x]) option default ------------------------------------- snapAmount null */ /* when snapping, snap with this number in pixels as an offset values: integer */ snapOffset:0, /* mouse-wheel scrolling */ mouseWheel:{ /* enable mouse-wheel scrolling values: boolean */ enable:true, /* scrolling amount in pixels values: "auto", integer */ scrollAmount:"auto", /* mouse-wheel scrolling axis the default scrolling direction when both vertical and horizontal scrollbars are present values (string): "y", "x" */ axis:"y", /* prevent the default behaviour which automatically scrolls the parent element(s) when end of scrolling is reached values: boolean option default ------------------------------------- preventDefault null */ /* the reported mouse-wheel delta value. The number of lines (translated to pixels) one wheel notch scrolls. values: "auto", integer "auto" uses the default OS/browser value */ deltaFactor:"auto", /* normalize mouse-wheel delta to -1 or 1 (disables mouse-wheel acceleration) values: boolean option default ------------------------------------- normalizeDelta null */ /* invert mouse-wheel scrolling direction values: boolean option default ------------------------------------- invert null */ /* the tags that disable mouse-wheel when cursor is over them */ disableOver:["select","option","keygen","datalist","textarea"] }, /* scrollbar buttons */ scrollButtons:{ /* enable scrollbar buttons values: boolean option default ------------------------------------- enable null */ /* scrollbar buttons scrolling type values (string): "stepless", "stepped" */ scrollType:"stepless", /* scrolling amount in pixels values: "auto", integer */ scrollAmount:"auto" /* tabindex of the scrollbar buttons values: false, integer option default ------------------------------------- tabindex null */ }, /* keyboard scrolling */ keyboard:{ /* enable scrolling via keyboard values: boolean */ enable:true, /* keyboard scrolling type values (string): "stepless", "stepped" */ scrollType:"stepless", /* scrolling amount in pixels values: "auto", integer */ scrollAmount:"auto" }, /* enable content touch-swipe scrolling values: boolean, integer, string (number) integer values define the axis-specific minimum amount required for scrolling momentum */ contentTouchScroll:25, /* enable/disable document (default) touch-swipe scrolling */ documentTouchScroll:true, /* advanced option parameters */ advanced:{ /* auto-expand content horizontally (for "x" or "yx" axis) values: boolean, integer (the value 2 forces the non scrollHeight/scrollWidth method, the value 3 forces the scrollHeight/scrollWidth method) option default ------------------------------------- autoExpandHorizontalScroll null */ /* auto-scroll to elements with focus */ autoScrollOnFocus:"input,textarea,select,button,datalist,keygen,a[tabindex],area,object,[contenteditable='true']", /* auto-update scrollbars on content, element or viewport resize should be true for fluid layouts/elements, adding/removing content dynamically, hiding/showing elements, content with images etc. values: boolean */ updateOnContentResize:true, /* auto-update scrollbars each time each image inside the element is fully loaded values: "auto", boolean */ updateOnImageLoad:"auto", /* auto-update scrollbars based on the amount and size changes of specific selectors useful when you need to update the scrollbar(s) automatically, each time a type of element is added, removed or changes its size values: boolean, string (e.g. "ul li" will auto-update scrollbars each time list-items inside the element are changed) a value of true (boolean) will auto-update scrollbars each time any element is changed option default ------------------------------------- updateOnSelectorChange null */ /* extra selectors that'll allow scrollbar dragging upon mousemove/up, pointermove/up, touchend etc. (e.g. "selector-1, selector-2") option default ------------------------------------- extraDraggableSelectors null */ /* extra selectors that'll release scrollbar dragging upon mouseup, pointerup, touchend etc. (e.g. "selector-1, selector-2") option default ------------------------------------- releaseDraggableSelectors null */ /* auto-update timeout values: integer (milliseconds) */ autoUpdateTimeout:60 }, /* scrollbar theme values: string (see CSS/plugin URI for a list of ready-to-use themes) */ theme:"light", /* user defined callback functions */ callbacks:{ /* Available callbacks: callback default ------------------------------------- onCreate null onInit null onScrollStart null onScroll null onTotalScroll null onTotalScrollBack null whileScrolling null onOverflowY null onOverflowX null onOverflowYNone null onOverflowXNone null onImageLoad null onSelectorChange null onBeforeUpdate null onUpdate null */ onTotalScrollOffset:0, onTotalScrollBackOffset:0, alwaysTriggerOffsets:true } /* add scrollbar(s) on all elements matching the current selector, now and in the future values: boolean, string string values: "on" (enable), "once" (disable after first invocation), "off" (disable) liveSelector values: string (selector) option default ------------------------------------- live false liveSelector null */ }, /* ---------------------------------------- VARS, CONSTANTS ---------------------------------------- */ totalInstances=0, /* plugin instances amount */ liveTimers={}, /* live option timers */ oldIE=(window.attachEvent && !window.addEventListener) ? 1 : 0, /* detect IE < 9 */ touchActive=false,touchable, /* global touch vars (for touch and pointer events) */ /* general plugin classes */ classes=[ "mCSB_dragger_onDrag","mCSB_scrollTools_onDrag","mCS_img_loaded","mCS_disabled","mCS_destroyed","mCS_no_scrollbar", "mCS-autoHide","mCS-dir-rtl","mCS_no_scrollbar_y","mCS_no_scrollbar_x","mCS_y_hidden","mCS_x_hidden","mCSB_draggerContainer", "mCSB_buttonUp","mCSB_buttonDown","mCSB_buttonLeft","mCSB_buttonRight" ], /* ---------------------------------------- METHODS ---------------------------------------- */ methods={ /* plugin initialization method creates the scrollbar(s), plugin data object and options ---------------------------------------- */ init:function(options){ var options=$.extend(true,{},defaults,options), selector=_selector.call(this); /* validate selector */ /* if live option is enabled, monitor for elements matching the current selector and apply scrollbar(s) when found (now and in the future) */ if(options.live){ var liveSelector=options.liveSelector || this.selector || defaultSelector, /* live selector(s) */ $liveSelector=$(liveSelector); /* live selector(s) as jquery object */ if(options.live==="off"){ /* disable live if requested usage: $(selector).mCustomScrollbar({live:"off"}); */ removeLiveTimers(liveSelector); return; } liveTimers[liveSelector]=setTimeout(function(){ /* call mCustomScrollbar fn on live selector(s) every half-second */ $liveSelector.mCustomScrollbar(options); if(options.live==="once" && $liveSelector.length){ /* disable live after first invocation */ removeLiveTimers(liveSelector); } },500); }else{ removeLiveTimers(liveSelector); } /* options backward compatibility (for versions < 3.0.0) and normalization */ options.setWidth=(options.set_width) ? options.set_width : options.setWidth; options.setHeight=(options.set_height) ? options.set_height : options.setHeight; options.axis=(options.horizontalScroll) ? "x" : _findAxis(options.axis); options.scrollInertia=options.scrollInertia>0 && options.scrollInertia<17 ? 17 : options.scrollInertia; if(typeof options.mouseWheel!=="object" && options.mouseWheel==true){ /* old school mouseWheel option (non-object) */ options.mouseWheel={enable:true,scrollAmount:"auto",axis:"y",preventDefault:false,deltaFactor:"auto",normalizeDelta:false,invert:false} } options.mouseWheel.scrollAmount=!options.mouseWheelPixels ? options.mouseWheel.scrollAmount : options.mouseWheelPixels; options.mouseWheel.normalizeDelta=!options.advanced.normalizeMouseWheelDelta ? options.mouseWheel.normalizeDelta : options.advanced.normalizeMouseWheelDelta; options.scrollButtons.scrollType=_findScrollButtonsType(options.scrollButtons.scrollType); _theme(options); /* theme-specific options */ /* plugin constructor */ return $(selector).each(function(){ var $this=$(this); if(!$this.data(pluginPfx)){ /* prevent multiple instantiations */ /* store options and create objects in jquery data */ $this.data(pluginPfx,{ idx:++totalInstances, /* instance index */ opt:options, /* options */ scrollRatio:{y:null,x:null}, /* scrollbar to content ratio */ overflowed:null, /* overflowed axis */ contentReset:{y:null,x:null}, /* object to check when content resets */ bindEvents:false, /* object to check if events are bound */ tweenRunning:false, /* object to check if tween is running */ sequential:{}, /* sequential scrolling object */ langDir:$this.css("direction"), /* detect/store direction (ltr or rtl) */ cbOffsets:null, /* object to check whether callback offsets always trigger */ /* object to check how scrolling events where last triggered "internal" (default - triggered by this script), "external" (triggered by other scripts, e.g. via scrollTo method) usage: object.data("mCS").trigger */ trigger:null, /* object to check for changes in elements in order to call the update method automatically */ poll:{size:{o:0,n:0},img:{o:0,n:0},change:{o:0,n:0}} }); var d=$this.data(pluginPfx),o=d.opt, /* HTML data attributes */ htmlDataAxis=$this.data("mcs-axis"),htmlDataSbPos=$this.data("mcs-scrollbar-position"),htmlDataTheme=$this.data("mcs-theme"); if(htmlDataAxis){o.axis=htmlDataAxis;} /* usage example: data-mcs-axis="y" */ if(htmlDataSbPos){o.scrollbarPosition=htmlDataSbPos;} /* usage example: data-mcs-scrollbar-position="outside" */ if(htmlDataTheme){ /* usage example: data-mcs-theme="minimal" */ o.theme=htmlDataTheme; _theme(o); /* theme-specific options */ } _pluginMarkup.call(this); /* add plugin markup */ if(d && o.callbacks.onCreate && typeof o.callbacks.onCreate==="function"){o.callbacks.onCreate.call(this);} /* callbacks: onCreate */ $("#mCSB_"+d.idx+"_container img:not(."+classes[2]+")").addClass(classes[2]); /* flag loaded images */ methods.update.call(null,$this); /* call the update method */ } }); }, /* ---------------------------------------- */ /* plugin update method updates content and scrollbar(s) values, events and status ---------------------------------------- usage: $(selector).mCustomScrollbar("update"); */ update:function(el,cb){ var selector=el || _selector.call(this); /* validate selector */ return $(selector).each(function(){ var $this=$(this); if($this.data(pluginPfx)){ /* check if plugin has initialized */ var d=$this.data(pluginPfx),o=d.opt, mCSB_container=$("#mCSB_"+d.idx+"_container"), mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; if(!mCSB_container.length){return;} if(d.tweenRunning){_stop($this);} /* stop any running tweens while updating */ if(cb && d && o.callbacks.onBeforeUpdate && typeof o.callbacks.onBeforeUpdate==="function"){o.callbacks.onBeforeUpdate.call(this);} /* callbacks: onBeforeUpdate */ /* if element was disabled or destroyed, remove class(es) */ if($this.hasClass(classes[3])){$this.removeClass(classes[3]);} if($this.hasClass(classes[4])){$this.removeClass(classes[4]);} /* css flexbox fix, detect/set max-height */ mCustomScrollBox.css("max-height","none"); if(mCustomScrollBox.height()!==$this.height()){mCustomScrollBox.css("max-height",$this.height());} _expandContentHorizontally.call(this); /* expand content horizontally */ if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){ mCSB_container.css("width",_contentWidth(mCSB_container)); } d.overflowed=_overflowed.call(this); /* determine if scrolling is required */ _scrollbarVisibility.call(this); /* show/hide scrollbar(s) */ /* auto-adjust scrollbar dragger length analogous to content */ if(o.autoDraggerLength){_setDraggerLength.call(this);} _scrollRatio.call(this); /* calculate and store scrollbar to content ratio */ _bindEvents.call(this); /* bind scrollbar events */ /* reset scrolling position and/or events */ var to=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)]; if(o.axis!=="x"){ /* y/yx axis */ if(!d.overflowed[0]){ /* y scrolling is not required */ _resetContentPosition.call(this); /* reset content position */ if(o.axis==="y"){ _unbindEvents.call(this); }else if(o.axis==="yx" && d.overflowed[1]){ _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"}); } }else if(mCSB_dragger[0].height()>mCSB_dragger[0].parent().height()){ _resetContentPosition.call(this); /* reset content position */ }else{ /* y scrolling is required */ _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"}); d.contentReset.y=null; } } if(o.axis!=="y"){ /* x/yx axis */ if(!d.overflowed[1]){ /* x scrolling is not required */ _resetContentPosition.call(this); /* reset content position */ if(o.axis==="x"){ _unbindEvents.call(this); }else if(o.axis==="yx" && d.overflowed[0]){ _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"}); } }else if(mCSB_dragger[1].width()>mCSB_dragger[1].parent().width()){ _resetContentPosition.call(this); /* reset content position */ }else{ /* x scrolling is required */ _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"}); d.contentReset.x=null; } } /* callbacks: onImageLoad, onSelectorChange, onUpdate */ if(cb && d){ if(cb===2 && o.callbacks.onImageLoad && typeof o.callbacks.onImageLoad==="function"){ o.callbacks.onImageLoad.call(this); }else if(cb===3 && o.callbacks.onSelectorChange && typeof o.callbacks.onSelectorChange==="function"){ o.callbacks.onSelectorChange.call(this); }else if(o.callbacks.onUpdate && typeof o.callbacks.onUpdate==="function"){ o.callbacks.onUpdate.call(this); } } _autoUpdate.call(this); /* initialize automatic updating (for dynamic content, fluid layouts etc.) */ } }); }, /* ---------------------------------------- */ /* plugin scrollTo method triggers a scrolling event to a specific value ---------------------------------------- usage: $(selector).mCustomScrollbar("scrollTo",value,options); */ scrollTo:function(val,options){ /* prevent silly things like $(selector).mCustomScrollbar("scrollTo",undefined); */ if(typeof val=="undefined" || val==null){return;} var selector=_selector.call(this); /* validate selector */ return $(selector).each(function(){ var $this=$(this); if($this.data(pluginPfx)){ /* check if plugin has initialized */ var d=$this.data(pluginPfx),o=d.opt, /* method default options */ methodDefaults={ trigger:"external", /* method is by default triggered externally (e.g. from other scripts) */ scrollInertia:o.scrollInertia, /* scrolling inertia (animation duration) */ scrollEasing:"mcsEaseInOut", /* animation easing */ moveDragger:false, /* move dragger instead of content */ timeout:60, /* scroll-to delay */ callbacks:true, /* enable/disable callbacks */ onStart:true, onUpdate:true, onComplete:true }, methodOptions=$.extend(true,{},methodDefaults,options), to=_arr.call(this,val),dur=methodOptions.scrollInertia>0 && methodOptions.scrollInertia<17 ? 17 : methodOptions.scrollInertia; /* translate yx values to actual scroll-to positions */ to[0]=_to.call(this,to[0],"y"); to[1]=_to.call(this,to[1],"x"); /* check if scroll-to value moves the dragger instead of content. Only pixel values apply on dragger (e.g. 100, "100px", "-=100" etc.) */ if(methodOptions.moveDragger){ to[0]*=d.scrollRatio.y; to[1]*=d.scrollRatio.x; } methodOptions.dur=_isTabHidden() ? 0 : dur; //skip animations if browser tab is hidden setTimeout(function(){ /* do the scrolling */ if(to[0]!==null && typeof to[0]!=="undefined" && o.axis!=="x" && d.overflowed[0]){ /* scroll y */ methodOptions.dir="y"; methodOptions.overwrite="all"; _scrollTo($this,to[0].toString(),methodOptions); } if(to[1]!==null && typeof to[1]!=="undefined" && o.axis!=="y" && d.overflowed[1]){ /* scroll x */ methodOptions.dir="x"; methodOptions.overwrite="none"; _scrollTo($this,to[1].toString(),methodOptions); } },methodOptions.timeout); } }); }, /* ---------------------------------------- */ /* plugin stop method stops scrolling animation ---------------------------------------- usage: $(selector).mCustomScrollbar("stop"); */ stop:function(){ var selector=_selector.call(this); /* validate selector */ return $(selector).each(function(){ var $this=$(this); if($this.data(pluginPfx)){ /* check if plugin has initialized */ _stop($this); } }); }, /* ---------------------------------------- */ /* plugin disable method temporarily disables the scrollbar(s) ---------------------------------------- usage: $(selector).mCustomScrollbar("disable",reset); reset (boolean): resets content position to 0 */ disable:function(r){ var selector=_selector.call(this); /* validate selector */ return $(selector).each(function(){ var $this=$(this); if($this.data(pluginPfx)){ /* check if plugin has initialized */ var d=$this.data(pluginPfx); _autoUpdate.call(this,"remove"); /* remove automatic updating */ _unbindEvents.call(this); /* unbind events */ if(r){_resetContentPosition.call(this);} /* reset content position */ _scrollbarVisibility.call(this,true); /* show/hide scrollbar(s) */ $this.addClass(classes[3]); /* add disable class */ } }); }, /* ---------------------------------------- */ /* plugin destroy method completely removes the scrollbar(s) and returns the element to its original state ---------------------------------------- usage: $(selector).mCustomScrollbar("destroy"); */ destroy:function(){ var selector=_selector.call(this); /* validate selector */ return $(selector).each(function(){ var $this=$(this); if($this.data(pluginPfx)){ /* check if plugin has initialized */ var d=$this.data(pluginPfx),o=d.opt, mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), scrollbar=$(".mCSB_"+d.idx+"_scrollbar"); if(o.live){removeLiveTimers(o.liveSelector || $(selector).selector);} /* remove live timers */ _autoUpdate.call(this,"remove"); /* remove automatic updating */ _unbindEvents.call(this); /* unbind events */ _resetContentPosition.call(this); /* reset content position */ $this.removeData(pluginPfx); /* remove plugin data object */ _delete(this,"mcs"); /* delete callbacks object */ /* remove plugin markup */ scrollbar.remove(); /* remove scrollbar(s) first (those can be either inside or outside plugin's inner wrapper) */ mCSB_container.find("img."+classes[2]).removeClass(classes[2]); /* remove loaded images flag */ mCustomScrollBox.replaceWith(mCSB_container.contents()); /* replace plugin's inner wrapper with the original content */ /* remove plugin classes from the element and add destroy class */ $this.removeClass(pluginNS+" _"+pluginPfx+"_"+d.idx+" "+classes[6]+" "+classes[7]+" "+classes[5]+" "+classes[3]).addClass(classes[4]); } }); } /* ---------------------------------------- */ }, /* ---------------------------------------- FUNCTIONS ---------------------------------------- */ /* validates selector (if selector is invalid or undefined uses the default one) */ _selector=function(){ return (typeof $(this)!=="object" || $(this).length<1) ? defaultSelector : this; }, /* -------------------- */ /* changes options according to theme */ _theme=function(obj){ var fixedSizeScrollbarThemes=["rounded","rounded-dark","rounded-dots","rounded-dots-dark"], nonExpandedScrollbarThemes=["rounded-dots","rounded-dots-dark","3d","3d-dark","3d-thick","3d-thick-dark","inset","inset-dark","inset-2","inset-2-dark","inset-3","inset-3-dark"], disabledScrollButtonsThemes=["minimal","minimal-dark"], enabledAutoHideScrollbarThemes=["minimal","minimal-dark"], scrollbarPositionOutsideThemes=["minimal","minimal-dark"]; obj.autoDraggerLength=$.inArray(obj.theme,fixedSizeScrollbarThemes) > -1 ? false : obj.autoDraggerLength; obj.autoExpandScrollbar=$.inArray(obj.theme,nonExpandedScrollbarThemes) > -1 ? false : obj.autoExpandScrollbar; obj.scrollButtons.enable=$.inArray(obj.theme,disabledScrollButtonsThemes) > -1 ? false : obj.scrollButtons.enable; obj.autoHideScrollbar=$.inArray(obj.theme,enabledAutoHideScrollbarThemes) > -1 ? true : obj.autoHideScrollbar; obj.scrollbarPosition=$.inArray(obj.theme,scrollbarPositionOutsideThemes) > -1 ? "outside" : obj.scrollbarPosition; }, /* -------------------- */ /* live option timers removal */ removeLiveTimers=function(selector){ if(liveTimers[selector]){ clearTimeout(liveTimers[selector]); _delete(liveTimers,selector); } }, /* -------------------- */ /* normalizes axis option to valid values: "y", "x", "yx" */ _findAxis=function(val){ return (val==="yx" || val==="xy" || val==="auto") ? "yx" : (val==="x" || val==="horizontal") ? "x" : "y"; }, /* -------------------- */ /* normalizes scrollButtons.scrollType option to valid values: "stepless", "stepped" */ _findScrollButtonsType=function(val){ return (val==="stepped" || val==="pixels" || val==="step" || val==="click") ? "stepped" : "stepless"; }, /* -------------------- */ /* generates plugin markup */ _pluginMarkup=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, expandClass=o.autoExpandScrollbar ? " "+classes[1]+"_expand" : "", scrollbar=["<div id='mCSB_"+d.idx+"_scrollbar_vertical' class='mCSB_scrollTools mCSB_"+d.idx+"_scrollbar mCS-"+o.theme+" mCSB_scrollTools_vertical"+expandClass+"'><div class='"+classes[12]+"'><div id='mCSB_"+d.idx+"_dragger_vertical' class='mCSB_dragger' style='position:absolute;' oncontextmenu='return false;'><div class='mCSB_dragger_bar' /></div><div class='mCSB_draggerRail' /></div></div>","<div id='mCSB_"+d.idx+"_scrollbar_horizontal' class='mCSB_scrollTools mCSB_"+d.idx+"_scrollbar mCS-"+o.theme+" mCSB_scrollTools_horizontal"+expandClass+"'><div class='"+classes[12]+"'><div id='mCSB_"+d.idx+"_dragger_horizontal' class='mCSB_dragger' style='position:absolute;' oncontextmenu='return false;'><div class='mCSB_dragger_bar' /></div><div class='mCSB_draggerRail' /></div></div>"], wrapperClass=o.axis==="yx" ? "mCSB_vertical_horizontal" : o.axis==="x" ? "mCSB_horizontal" : "mCSB_vertical", scrollbars=o.axis==="yx" ? scrollbar[0]+scrollbar[1] : o.axis==="x" ? scrollbar[1] : scrollbar[0], contentWrapper=o.axis==="yx" ? "<div id='mCSB_"+d.idx+"_container_wrapper' class='mCSB_container_wrapper' />" : "", autoHideClass=o.autoHideScrollbar ? " "+classes[6] : "", scrollbarDirClass=(o.axis!=="x" && d.langDir==="rtl") ? " "+classes[7] : ""; if(o.setWidth){$this.css("width",o.setWidth);} /* set element width */ if(o.setHeight){$this.css("height",o.setHeight);} /* set element height */ o.setLeft=(o.axis!=="y" && d.langDir==="rtl") ? "989999px" : o.setLeft; /* adjust left position for rtl direction */ $this.addClass(pluginNS+" _"+pluginPfx+"_"+d.idx+autoHideClass+scrollbarDirClass).wrapInner("<div id='mCSB_"+d.idx+"' class='mCustomScrollBox mCS-"+o.theme+" "+wrapperClass+"'><div id='mCSB_"+d.idx+"_container' class='mCSB_container' style='position:relative; top:"+o.setTop+"; left:"+o.setLeft+";' dir="+d.langDir+" /></div>"); var mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"); if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){ mCSB_container.css("width",_contentWidth(mCSB_container)); } if(o.scrollbarPosition==="outside"){ if($this.css("position")==="static"){ /* requires elements with non-static position */ $this.css("position","relative"); } $this.css("overflow","visible"); mCustomScrollBox.addClass("mCSB_outside").after(scrollbars); }else{ mCustomScrollBox.addClass("mCSB_inside").append(scrollbars); mCSB_container.wrap(contentWrapper); } _scrollButtons.call(this); /* add scrollbar buttons */ /* minimum dragger length */ var mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; mCSB_dragger[0].css("min-height",mCSB_dragger[0].height()); mCSB_dragger[1].css("min-width",mCSB_dragger[1].width()); }, /* -------------------- */ /* calculates content width */ _contentWidth=function(el){ var val=[el[0].scrollWidth,Math.max.apply(Math,el.children().map(function(){return $(this).outerWidth(true);}).get())],w=el.parent().width(); return val[0]>w ? val[0] : val[1]>w ? val[1] : "100%"; }, /* -------------------- */ /* expands content horizontally */ _expandContentHorizontally=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, mCSB_container=$("#mCSB_"+d.idx+"_container"); if(o.advanced.autoExpandHorizontalScroll && o.axis!=="y"){ /* calculate scrollWidth */ mCSB_container.css({"width":"auto","min-width":0,"overflow-x":"scroll"}); var w=Math.ceil(mCSB_container[0].scrollWidth); if(o.advanced.autoExpandHorizontalScroll===3 || (o.advanced.autoExpandHorizontalScroll!==2 && w>mCSB_container.parent().width())){ mCSB_container.css({"width":w,"min-width":"100%","overflow-x":"inherit"}); }else{ /* wrap content with an infinite width div and set its position to absolute and width to auto. Setting width to auto before calculating the actual width is important! We must let the browser set the width as browser zoom values are impossible to calculate. */ mCSB_container.css({"overflow-x":"inherit","position":"absolute"}) .wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />") .css({ /* set actual width, original position and un-wrap */ /* get the exact width (with decimals) and then round-up. Using jquery outerWidth() will round the width value which will mess up with inner elements that have non-integer width */ "width":(Math.ceil(mCSB_container[0].getBoundingClientRect().right+0.4)-Math.floor(mCSB_container[0].getBoundingClientRect().left)), "min-width":"100%", "position":"relative" }).unwrap(); } } }, /* -------------------- */ /* adds scrollbar buttons */ _scrollButtons=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, mCSB_scrollTools=$(".mCSB_"+d.idx+"_scrollbar:first"), tabindex=!_isNumeric(o.scrollButtons.tabindex) ? "" : "tabindex='"+o.scrollButtons.tabindex+"'", btnHTML=[ "<a href='#' class='"+classes[13]+"' oncontextmenu='return false;' "+tabindex+" />", "<a href='#' class='"+classes[14]+"' oncontextmenu='return false;' "+tabindex+" />", "<a href='#' class='"+classes[15]+"' oncontextmenu='return false;' "+tabindex+" />", "<a href='#' class='"+classes[16]+"' oncontextmenu='return false;' "+tabindex+" />" ], btn=[(o.axis==="x" ? btnHTML[2] : btnHTML[0]),(o.axis==="x" ? btnHTML[3] : btnHTML[1]),btnHTML[2],btnHTML[3]]; if(o.scrollButtons.enable){ mCSB_scrollTools.prepend(btn[0]).append(btn[1]).next(".mCSB_scrollTools").prepend(btn[2]).append(btn[3]); } }, /* -------------------- */ /* auto-adjusts scrollbar dragger length */ _setDraggerLength=function(){ var $this=$(this),d=$this.data(pluginPfx), mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], ratio=[mCustomScrollBox.height()/mCSB_container.outerHeight(false),mCustomScrollBox.width()/mCSB_container.outerWidth(false)], l=[ parseInt(mCSB_dragger[0].css("min-height")),Math.round(ratio[0]*mCSB_dragger[0].parent().height()), parseInt(mCSB_dragger[1].css("min-width")),Math.round(ratio[1]*mCSB_dragger[1].parent().width()) ], h=oldIE && (l[1]<l[0]) ? l[0] : l[1],w=oldIE && (l[3]<l[2]) ? l[2] : l[3]; mCSB_dragger[0].css({ "height":h,"max-height":(mCSB_dragger[0].parent().height()-10) }).find(".mCSB_dragger_bar").css({"line-height":l[0]+"px"}); mCSB_dragger[1].css({ "width":w,"max-width":(mCSB_dragger[1].parent().width()-10) }); }, /* -------------------- */ /* calculates scrollbar to content ratio */ _scrollRatio=function(){ var $this=$(this),d=$this.data(pluginPfx), mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], scrollAmount=[mCSB_container.outerHeight(false)-mCustomScrollBox.height(),mCSB_container.outerWidth(false)-mCustomScrollBox.width()], ratio=[ scrollAmount[0]/(mCSB_dragger[0].parent().height()-mCSB_dragger[0].height()), scrollAmount[1]/(mCSB_dragger[1].parent().width()-mCSB_dragger[1].width()) ]; d.scrollRatio={y:ratio[0],x:ratio[1]}; }, /* -------------------- */ /* toggles scrolling classes */ _onDragClasses=function(el,action,xpnd){ var expandClass=xpnd ? classes[0]+"_expanded" : "", scrollbar=el.closest(".mCSB_scrollTools"); if(action==="active"){ el.toggleClass(classes[0]+" "+expandClass); scrollbar.toggleClass(classes[1]); el[0]._draggable=el[0]._draggable ? 0 : 1; }else{ if(!el[0]._draggable){ if(action==="hide"){ el.removeClass(classes[0]); scrollbar.removeClass(classes[1]); }else{ el.addClass(classes[0]); scrollbar.addClass(classes[1]); } } } }, /* -------------------- */ /* checks if content overflows its container to determine if scrolling is required */ _overflowed=function(){ var $this=$(this),d=$this.data(pluginPfx), mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), contentHeight=d.overflowed==null ? mCSB_container.height() : mCSB_container.outerHeight(false), contentWidth=d.overflowed==null ? mCSB_container.width() : mCSB_container.outerWidth(false), h=mCSB_container[0].scrollHeight,w=mCSB_container[0].scrollWidth; if(h>contentHeight){contentHeight=h;} if(w>contentWidth){contentWidth=w;} return [contentHeight>mCustomScrollBox.height(),contentWidth>mCustomScrollBox.width()]; }, /* -------------------- */ /* resets content position to 0 */ _resetContentPosition=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; _stop($this); /* stop any current scrolling before resetting */ if((o.axis!=="x" && !d.overflowed[0]) || (o.axis==="y" && d.overflowed[0])){ /* reset y */ mCSB_dragger[0].add(mCSB_container).css("top",0); _scrollTo($this,"_resetY"); } if((o.axis!=="y" && !d.overflowed[1]) || (o.axis==="x" && d.overflowed[1])){ /* reset x */ var cx=dx=0; if(d.langDir==="rtl"){ /* adjust left position for rtl direction */ cx=mCustomScrollBox.width()-mCSB_container.outerWidth(false); dx=Math.abs(cx/d.scrollRatio.x); } mCSB_container.css("left",cx); mCSB_dragger[1].css("left",dx); _scrollTo($this,"_resetX"); } }, /* -------------------- */ /* binds scrollbar events */ _bindEvents=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt; if(!d.bindEvents){ /* check if events are already bound */ _draggable.call(this); if(o.contentTouchScroll){_contentDraggable.call(this);} _selectable.call(this); if(o.mouseWheel.enable){ /* bind mousewheel fn when plugin is available */ function _mwt(){ mousewheelTimeout=setTimeout(function(){ if(!$.event.special.mousewheel){ _mwt(); }else{ clearTimeout(mousewheelTimeout); _mousewheel.call($this[0]); } },100); } var mousewheelTimeout; _mwt(); } _draggerRail.call(this); _wrapperScroll.call(this); if(o.advanced.autoScrollOnFocus){_focus.call(this);} if(o.scrollButtons.enable){_buttons.call(this);} if(o.keyboard.enable){_keyboard.call(this);} d.bindEvents=true; } }, /* -------------------- */ /* unbinds scrollbar events */ _unbindEvents=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, namespace=pluginPfx+"_"+d.idx, sb=".mCSB_"+d.idx+"_scrollbar", sel=$("#mCSB_"+d.idx+",#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,"+sb+" ."+classes[12]+",#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal,"+sb+">a"), mCSB_container=$("#mCSB_"+d.idx+"_container"); if(o.advanced.releaseDraggableSelectors){sel.add($(o.advanced.releaseDraggableSelectors));} if(o.advanced.extraDraggableSelectors){sel.add($(o.advanced.extraDraggableSelectors));} if(d.bindEvents){ /* check if events are bound */ /* unbind namespaced events from document/selectors */ $(document).add($(!_canAccessIFrame() || top.document)).unbind("."+namespace); sel.each(function(){ $(this).unbind("."+namespace); }); /* clear and delete timeouts/objects */ clearTimeout($this[0]._focusTimeout); _delete($this[0],"_focusTimeout"); clearTimeout(d.sequential.step); _delete(d.sequential,"step"); clearTimeout(mCSB_container[0].onCompleteTimeout); _delete(mCSB_container[0],"onCompleteTimeout"); d.bindEvents=false; } }, /* -------------------- */ /* toggles scrollbar visibility */ _scrollbarVisibility=function(disabled){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, contentWrapper=$("#mCSB_"+d.idx+"_container_wrapper"), content=contentWrapper.length ? contentWrapper : $("#mCSB_"+d.idx+"_container"), scrollbar=[$("#mCSB_"+d.idx+"_scrollbar_vertical"),$("#mCSB_"+d.idx+"_scrollbar_horizontal")], mCSB_dragger=[scrollbar[0].find(".mCSB_dragger"),scrollbar[1].find(".mCSB_dragger")]; if(o.axis!=="x"){ if(d.overflowed[0] && !disabled){ scrollbar[0].add(mCSB_dragger[0]).add(scrollbar[0].children("a")).css("display","block"); content.removeClass(classes[8]+" "+classes[10]); }else{ if(o.alwaysShowScrollbar){ if(o.alwaysShowScrollbar!==2){mCSB_dragger[0].css("display","none");} content.removeClass(classes[10]); }else{ scrollbar[0].css("display","none"); content.addClass(classes[10]); } content.addClass(classes[8]); } } if(o.axis!=="y"){ if(d.overflowed[1] && !disabled){ scrollbar[1].add(mCSB_dragger[1]).add(scrollbar[1].children("a")).css("display","block"); content.removeClass(classes[9]+" "+classes[11]); }else{ if(o.alwaysShowScrollbar){ if(o.alwaysShowScrollbar!==2){mCSB_dragger[1].css("display","none");} content.removeClass(classes[11]); }else{ scrollbar[1].css("display","none"); content.addClass(classes[11]); } content.addClass(classes[9]); } } if(!d.overflowed[0] && !d.overflowed[1]){ $this.addClass(classes[5]); }else{ $this.removeClass(classes[5]); } }, /* -------------------- */ /* returns input coordinates of pointer, touch and mouse events (relative to document) */ _coordinates=function(e){ var t=e.type,o=e.target.ownerDocument!==document ? [$(frameElement).offset().top,$(frameElement).offset().left] : null, io=_canAccessIFrame() && e.target.ownerDocument!==top.document ? [$(e.view.frameElement).offset().top,$(e.view.frameElement).offset().left] : [0,0]; switch(t){ case "pointerdown": case "MSPointerDown": case "pointermove": case "MSPointerMove": case "pointerup": case "MSPointerUp": return o ? [e.originalEvent.pageY-o[0]+io[0],e.originalEvent.pageX-o[1]+io[1],false] : [e.originalEvent.pageY,e.originalEvent.pageX,false]; break; case "touchstart": case "touchmove": case "touchend": var touch=e.originalEvent.touches[0] || e.originalEvent.changedTouches[0], touches=e.originalEvent.touches.length || e.originalEvent.changedTouches.length; return e.target.ownerDocument!==document ? [touch.screenY,touch.screenX,touches>1] : [touch.pageY,touch.pageX,touches>1]; break; default: return o ? [e.pageY-o[0]+io[0],e.pageX-o[1]+io[1],false] : [e.pageY,e.pageX,false]; } }, /* -------------------- */ /* SCROLLBAR DRAG EVENTS scrolls content via scrollbar dragging */ _draggable=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, namespace=pluginPfx+"_"+d.idx, draggerId=["mCSB_"+d.idx+"_dragger_vertical","mCSB_"+d.idx+"_dragger_horizontal"], mCSB_container=$("#mCSB_"+d.idx+"_container"), mCSB_dragger=$("#"+draggerId[0]+",#"+draggerId[1]), draggable,dragY,dragX, rds=o.advanced.releaseDraggableSelectors ? mCSB_dragger.add($(o.advanced.releaseDraggableSelectors)) : mCSB_dragger, eds=o.advanced.extraDraggableSelectors ? $(!_canAccessIFrame() || top.document).add($(o.advanced.extraDraggableSelectors)) : $(!_canAccessIFrame() || top.document); mCSB_dragger.bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){ e.stopImmediatePropagation(); e.preventDefault(); if(!_mouseBtnLeft(e)){return;} /* left mouse button only */ touchActive=true; if(oldIE){document.onselectstart=function(){return false;}} /* disable text selection for IE < 9 */ _iframe(false); /* enable scrollbar dragging over iframes by disabling their events */ _stop($this); draggable=$(this); var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, h=draggable.height()+offset.top,w=draggable.width()+offset.left; if(y<h && y>0 && x<w && x>0){ dragY=y; dragX=x; } _onDragClasses(draggable,"active",o.autoExpandScrollbar); }).bind("touchmove."+namespace,function(e){ e.stopImmediatePropagation(); e.preventDefault(); var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; _drag(dragY,dragX,y,x); }); $(document).add(eds).bind("mousemove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace,function(e){ if(draggable){ var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; if(dragY===y && dragX===x){return;} /* has it really moved? */ _drag(dragY,dragX,y,x); } }).add(rds).bind("mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){ if(draggable){ _onDragClasses(draggable,"active",o.autoExpandScrollbar); draggable=null; } touchActive=false; if(oldIE){document.onselectstart=null;} /* enable text selection for IE < 9 */ _iframe(true); /* enable iframes events */ }); function _iframe(evt){ var el=mCSB_container.find("iframe"); if(!el.length){return;} /* check if content contains iframes */ var val=!evt ? "none" : "auto"; el.css("pointer-events",val); /* for IE11, iframe's display property should not be "block" */ } function _drag(dragY,dragX,y,x){ mCSB_container[0].idleTimer=o.scrollInertia<233 ? 250 : 0; if(draggable.attr("id")===draggerId[1]){ var dir="x",to=((draggable[0].offsetLeft-dragX)+x)*d.scrollRatio.x; }else{ var dir="y",to=((draggable[0].offsetTop-dragY)+y)*d.scrollRatio.y; } _scrollTo($this,to.toString(),{dir:dir,drag:true}); } }, /* -------------------- */ /* TOUCH SWIPE EVENTS scrolls content via touch swipe Emulates the native touch-swipe scrolling with momentum found in iOS, Android and WP devices */ _contentDraggable=function(){ var $this=$(this),d=$this.data(pluginPfx),o=d.opt, namespace=pluginPfx+"_"+d.idx, mCustomScrollBox=$("#mCSB_"+d.idx), mCSB_container=$("#mCSB_"+d.idx+"_container"), mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], draggable,dragY,dragX,touchStartY,touchStartX,touchMoveY=[],touchMoveX=[],startTime,runningTime,endTime,distance,speed,amount, durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag, iframe=mCSB_container.find("iframe"), events=[ "touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace, //start "touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace, //move "touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace //end ], touchAction=document.body.style.touchAction!==undefined; mCSB_container.bind(events[0],function(e){ _onTouchstart(e); }).bind(events[1],function(e){ _onTouchmove(e); }); mCustomScrollBox.bind(events[0],function(e){ _onTouchstart2(e); }).bind(events[2],function(e){ _onTouchend(e); }); if(iframe.length){ iframe.each(function(){ $(this).load(function(){ /* bind events on accessible iframes */ if(_canAccessIFrame(this)){ $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){ _onTouchstart(e); _onTouchstart2(e); }).bind(events[1],function(e){ _onTouchmove(e); }).bind(events[2],function(e){ _onTouchend(e); }); } }); }); } function _onTouchstart(e){ if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;} touchable=1; touchDrag=0; docDrag=0; draggable=1; $this.removeClass("mCS_touch_action"); var offset=mCSB_container.offset(); dragY=_coordinates(e)[0]-offset.top; dragX=_coordinates(e)[1]-offset.left; touchIntent=[_coordinates(e)[0],_coordinates(e)[1]]; } function _onTouchmove(e){ if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;} if(!o.documentTouchScroll){e.preventDefault();} e.stopImmediatePropagation(); if(docDrag && !touchDrag){return;} if(draggable){ runningTime=_getTime(); var offset=mCustomScrollBox.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, easing="mcsLinearOut"; touchMoveY.push(y); touchMoveX.push(x); touchIntent[2]=Math.abs(_coordinates(e)[0]-touchIntent[0]); touchIntent[3]=Math.abs(_coordinates(e