jquery.mCustomScrollbar.min.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  1. /*
  2. == malihu jquery custom scrollbar plugin ==
  3. Version: 3.1.5
  4. Plugin URI: http://manos.malihu.gr/jquery-custom-content-scroller
  5. Author: malihu
  6. Author URI: http://manos.malihu.gr
  7. License: MIT License (MIT)
  8. */
  9. /*
  10. Copyright Manos Malihutsakis (email: manos@malihu.gr)
  11. Permission is hereby granted, free of charge, to any person obtaining a copy
  12. of this software and associated documentation files (the "Software"), to deal
  13. in the Software without restriction, including without limitation the rights
  14. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. copies of the Software, and to permit persons to whom the Software is
  16. furnished to do so, subject to the following conditions:
  17. The above copyright notice and this permission notice shall be included in
  18. all copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. THE SOFTWARE.
  26. */
  27. /*
  28. The code below is fairly long, fully commented and should be normally used in development.
  29. For production, use either the minified jquery.mCustomScrollbar.min.js script or
  30. the production-ready jquery.mCustomScrollbar.concat.min.js which contains the plugin
  31. and dependencies (minified).
  32. */
  33. "use strict";
  34. (function(factory){
  35. if(typeof define==="function" && define.amd){
  36. define(["jquery"],factory);
  37. }else if(typeof module!=="undefined" && module.exports){
  38. module.exports=factory;
  39. }else{
  40. factory(jQuery,window,document);
  41. }
  42. }(function($){
  43. (function(init){
  44. var _rjs=typeof define==="function" && define.amd, /* RequireJS */
  45. _njs=typeof module !== "undefined" && module.exports, /* NodeJS */
  46. _dlp=("https:"==document.location.protocol) ? "https:" : "http:", /* location protocol */
  47. _url="cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js";
  48. if(!_rjs){
  49. if(_njs){
  50. require("jquery-mousewheel")($);
  51. }else{
  52. /* load jquery-mousewheel plugin (via CDN) if it's not present or not loaded via RequireJS
  53. (works when mCustomScrollbar fn is called on window load) */
  54. $.event.special.mousewheel || $("head").append(decodeURI("%3Cscript src="+_dlp+"//"+_url+"%3E%3C/script%3E"));
  55. }
  56. }
  57. init();
  58. }(function(){
  59. /*
  60. ----------------------------------------
  61. PLUGIN NAMESPACE, PREFIX, DEFAULT SELECTOR(S)
  62. ----------------------------------------
  63. */
  64. var pluginNS="mCustomScrollbar",
  65. pluginPfx="mCS",
  66. defaultSelector=".mCustomScrollbar",
  67. /*
  68. ----------------------------------------
  69. DEFAULT OPTIONS
  70. ----------------------------------------
  71. */
  72. defaults={
  73. /*
  74. set element/content width/height programmatically
  75. values: boolean, pixels, percentage
  76. option default
  77. -------------------------------------
  78. setWidth false
  79. setHeight false
  80. */
  81. /*
  82. set the initial css top property of content
  83. values: string (e.g. "-100px", "10%" etc.)
  84. */
  85. setTop:0,
  86. /*
  87. set the initial css left property of content
  88. values: string (e.g. "-100px", "10%" etc.)
  89. */
  90. setLeft:0,
  91. /*
  92. scrollbar axis (vertical and/or horizontal scrollbars)
  93. values (string): "y", "x", "yx"
  94. */
  95. axis:"y",
  96. /*
  97. position of scrollbar relative to content
  98. values (string): "inside", "outside" ("outside" requires elements with position:relative)
  99. */
  100. scrollbarPosition:"inside",
  101. /*
  102. scrolling inertia
  103. values: integer (milliseconds)
  104. */
  105. scrollInertia:950,
  106. /*
  107. auto-adjust scrollbar dragger length
  108. values: boolean
  109. */
  110. autoDraggerLength:true,
  111. /*
  112. auto-hide scrollbar when idle
  113. values: boolean
  114. option default
  115. -------------------------------------
  116. autoHideScrollbar false
  117. */
  118. /*
  119. auto-expands scrollbar on mouse-over and dragging
  120. values: boolean
  121. option default
  122. -------------------------------------
  123. autoExpandScrollbar false
  124. */
  125. /*
  126. always show scrollbar, even when there's nothing to scroll
  127. values: integer (0=disable, 1=always show dragger rail and buttons, 2=always show dragger rail, dragger and buttons), boolean
  128. */
  129. alwaysShowScrollbar:0,
  130. /*
  131. scrolling always snaps to a multiple of this number in pixels
  132. values: integer, array ([y,x])
  133. option default
  134. -------------------------------------
  135. snapAmount null
  136. */
  137. /*
  138. when snapping, snap with this number in pixels as an offset
  139. values: integer
  140. */
  141. snapOffset:0,
  142. /*
  143. mouse-wheel scrolling
  144. */
  145. mouseWheel:{
  146. /*
  147. enable mouse-wheel scrolling
  148. values: boolean
  149. */
  150. enable:true,
  151. /*
  152. scrolling amount in pixels
  153. values: "auto", integer
  154. */
  155. scrollAmount:"auto",
  156. /*
  157. mouse-wheel scrolling axis
  158. the default scrolling direction when both vertical and horizontal scrollbars are present
  159. values (string): "y", "x"
  160. */
  161. axis:"y",
  162. /*
  163. prevent the default behaviour which automatically scrolls the parent element(s) when end of scrolling is reached
  164. values: boolean
  165. option default
  166. -------------------------------------
  167. preventDefault null
  168. */
  169. /*
  170. the reported mouse-wheel delta value. The number of lines (translated to pixels) one wheel notch scrolls.
  171. values: "auto", integer
  172. "auto" uses the default OS/browser value
  173. */
  174. deltaFactor:"auto",
  175. /*
  176. normalize mouse-wheel delta to -1 or 1 (disables mouse-wheel acceleration)
  177. values: boolean
  178. option default
  179. -------------------------------------
  180. normalizeDelta null
  181. */
  182. /*
  183. invert mouse-wheel scrolling direction
  184. values: boolean
  185. option default
  186. -------------------------------------
  187. invert null
  188. */
  189. /*
  190. the tags that disable mouse-wheel when cursor is over them
  191. */
  192. disableOver:["select","option","keygen","datalist","textarea"]
  193. },
  194. /*
  195. scrollbar buttons
  196. */
  197. scrollButtons:{
  198. /*
  199. enable scrollbar buttons
  200. values: boolean
  201. option default
  202. -------------------------------------
  203. enable null
  204. */
  205. /*
  206. scrollbar buttons scrolling type
  207. values (string): "stepless", "stepped"
  208. */
  209. scrollType:"stepless",
  210. /*
  211. scrolling amount in pixels
  212. values: "auto", integer
  213. */
  214. scrollAmount:"auto"
  215. /*
  216. tabindex of the scrollbar buttons
  217. values: false, integer
  218. option default
  219. -------------------------------------
  220. tabindex null
  221. */
  222. },
  223. /*
  224. keyboard scrolling
  225. */
  226. keyboard:{
  227. /*
  228. enable scrolling via keyboard
  229. values: boolean
  230. */
  231. enable:true,
  232. /*
  233. keyboard scrolling type
  234. values (string): "stepless", "stepped"
  235. */
  236. scrollType:"stepless",
  237. /*
  238. scrolling amount in pixels
  239. values: "auto", integer
  240. */
  241. scrollAmount:"auto"
  242. },
  243. /*
  244. enable content touch-swipe scrolling
  245. values: boolean, integer, string (number)
  246. integer values define the axis-specific minimum amount required for scrolling momentum
  247. */
  248. contentTouchScroll:25,
  249. /*
  250. enable/disable document (default) touch-swipe scrolling
  251. */
  252. documentTouchScroll:true,
  253. /*
  254. advanced option parameters
  255. */
  256. advanced:{
  257. /*
  258. auto-expand content horizontally (for "x" or "yx" axis)
  259. values: boolean, integer (the value 2 forces the non scrollHeight/scrollWidth method, the value 3 forces the scrollHeight/scrollWidth method)
  260. option default
  261. -------------------------------------
  262. autoExpandHorizontalScroll null
  263. */
  264. /*
  265. auto-scroll to elements with focus
  266. */
  267. autoScrollOnFocus:"input,textarea,select,button,datalist,keygen,a[tabindex],area,object,[contenteditable='true']",
  268. /*
  269. auto-update scrollbars on content, element or viewport resize
  270. should be true for fluid layouts/elements, adding/removing content dynamically, hiding/showing elements, content with images etc.
  271. values: boolean
  272. */
  273. updateOnContentResize:true,
  274. /*
  275. auto-update scrollbars each time each image inside the element is fully loaded
  276. values: "auto", boolean
  277. */
  278. updateOnImageLoad:"auto",
  279. /*
  280. auto-update scrollbars based on the amount and size changes of specific selectors
  281. useful when you need to update the scrollbar(s) automatically, each time a type of element is added, removed or changes its size
  282. values: boolean, string (e.g. "ul li" will auto-update scrollbars each time list-items inside the element are changed)
  283. a value of true (boolean) will auto-update scrollbars each time any element is changed
  284. option default
  285. -------------------------------------
  286. updateOnSelectorChange null
  287. */
  288. /*
  289. extra selectors that'll allow scrollbar dragging upon mousemove/up, pointermove/up, touchend etc. (e.g. "selector-1, selector-2")
  290. option default
  291. -------------------------------------
  292. extraDraggableSelectors null
  293. */
  294. /*
  295. extra selectors that'll release scrollbar dragging upon mouseup, pointerup, touchend etc. (e.g. "selector-1, selector-2")
  296. option default
  297. -------------------------------------
  298. releaseDraggableSelectors null
  299. */
  300. /*
  301. auto-update timeout
  302. values: integer (milliseconds)
  303. */
  304. autoUpdateTimeout:60
  305. },
  306. /*
  307. scrollbar theme
  308. values: string (see CSS/plugin URI for a list of ready-to-use themes)
  309. */
  310. theme:"light",
  311. /*
  312. user defined callback functions
  313. */
  314. callbacks:{
  315. /*
  316. Available callbacks:
  317. callback default
  318. -------------------------------------
  319. onCreate null
  320. onInit null
  321. onScrollStart null
  322. onScroll null
  323. onTotalScroll null
  324. onTotalScrollBack null
  325. whileScrolling null
  326. onOverflowY null
  327. onOverflowX null
  328. onOverflowYNone null
  329. onOverflowXNone null
  330. onImageLoad null
  331. onSelectorChange null
  332. onBeforeUpdate null
  333. onUpdate null
  334. */
  335. onTotalScrollOffset:0,
  336. onTotalScrollBackOffset:0,
  337. alwaysTriggerOffsets:true
  338. }
  339. /*
  340. add scrollbar(s) on all elements matching the current selector, now and in the future
  341. values: boolean, string
  342. string values: "on" (enable), "once" (disable after first invocation), "off" (disable)
  343. liveSelector values: string (selector)
  344. option default
  345. -------------------------------------
  346. live false
  347. liveSelector null
  348. */
  349. },
  350. /*
  351. ----------------------------------------
  352. VARS, CONSTANTS
  353. ----------------------------------------
  354. */
  355. totalInstances=0, /* plugin instances amount */
  356. liveTimers={}, /* live option timers */
  357. oldIE=(window.attachEvent && !window.addEventListener) ? 1 : 0, /* detect IE < 9 */
  358. touchActive=false,touchable, /* global touch vars (for touch and pointer events) */
  359. /* general plugin classes */
  360. classes=[
  361. "mCSB_dragger_onDrag","mCSB_scrollTools_onDrag","mCS_img_loaded","mCS_disabled","mCS_destroyed","mCS_no_scrollbar",
  362. "mCS-autoHide","mCS-dir-rtl","mCS_no_scrollbar_y","mCS_no_scrollbar_x","mCS_y_hidden","mCS_x_hidden","mCSB_draggerContainer",
  363. "mCSB_buttonUp","mCSB_buttonDown","mCSB_buttonLeft","mCSB_buttonRight"
  364. ],
  365. /*
  366. ----------------------------------------
  367. METHODS
  368. ----------------------------------------
  369. */
  370. methods={
  371. /*
  372. plugin initialization method
  373. creates the scrollbar(s), plugin data object and options
  374. ----------------------------------------
  375. */
  376. init:function(options){
  377. var options=$.extend(true,{},defaults,options),
  378. selector=_selector.call(this); /* validate selector */
  379. /*
  380. if live option is enabled, monitor for elements matching the current selector and
  381. apply scrollbar(s) when found (now and in the future)
  382. */
  383. if(options.live){
  384. var liveSelector=options.liveSelector || this.selector || defaultSelector, /* live selector(s) */
  385. $liveSelector=$(liveSelector); /* live selector(s) as jquery object */
  386. if(options.live==="off"){
  387. /*
  388. disable live if requested
  389. usage: $(selector).mCustomScrollbar({live:"off"});
  390. */
  391. removeLiveTimers(liveSelector);
  392. return;
  393. }
  394. liveTimers[liveSelector]=setTimeout(function(){
  395. /* call mCustomScrollbar fn on live selector(s) every half-second */
  396. $liveSelector.mCustomScrollbar(options);
  397. if(options.live==="once" && $liveSelector.length){
  398. /* disable live after first invocation */
  399. removeLiveTimers(liveSelector);
  400. }
  401. },500);
  402. }else{
  403. removeLiveTimers(liveSelector);
  404. }
  405. /* options backward compatibility (for versions < 3.0.0) and normalization */
  406. options.setWidth=(options.set_width) ? options.set_width : options.setWidth;
  407. options.setHeight=(options.set_height) ? options.set_height : options.setHeight;
  408. options.axis=(options.horizontalScroll) ? "x" : _findAxis(options.axis);
  409. options.scrollInertia=options.scrollInertia>0 && options.scrollInertia<17 ? 17 : options.scrollInertia;
  410. if(typeof options.mouseWheel!=="object" && options.mouseWheel==true){ /* old school mouseWheel option (non-object) */
  411. options.mouseWheel={enable:true,scrollAmount:"auto",axis:"y",preventDefault:false,deltaFactor:"auto",normalizeDelta:false,invert:false}
  412. }
  413. options.mouseWheel.scrollAmount=!options.mouseWheelPixels ? options.mouseWheel.scrollAmount : options.mouseWheelPixels;
  414. options.mouseWheel.normalizeDelta=!options.advanced.normalizeMouseWheelDelta ? options.mouseWheel.normalizeDelta : options.advanced.normalizeMouseWheelDelta;
  415. options.scrollButtons.scrollType=_findScrollButtonsType(options.scrollButtons.scrollType);
  416. _theme(options); /* theme-specific options */
  417. /* plugin constructor */
  418. return $(selector).each(function(){
  419. var $this=$(this);
  420. if(!$this.data(pluginPfx)){ /* prevent multiple instantiations */
  421. /* store options and create objects in jquery data */
  422. $this.data(pluginPfx,{
  423. idx:++totalInstances, /* instance index */
  424. opt:options, /* options */
  425. scrollRatio:{y:null,x:null}, /* scrollbar to content ratio */
  426. overflowed:null, /* overflowed axis */
  427. contentReset:{y:null,x:null}, /* object to check when content resets */
  428. bindEvents:false, /* object to check if events are bound */
  429. tweenRunning:false, /* object to check if tween is running */
  430. sequential:{}, /* sequential scrolling object */
  431. langDir:$this.css("direction"), /* detect/store direction (ltr or rtl) */
  432. cbOffsets:null, /* object to check whether callback offsets always trigger */
  433. /*
  434. object to check how scrolling events where last triggered
  435. "internal" (default - triggered by this script), "external" (triggered by other scripts, e.g. via scrollTo method)
  436. usage: object.data("mCS").trigger
  437. */
  438. trigger:null,
  439. /*
  440. object to check for changes in elements in order to call the update method automatically
  441. */
  442. poll:{size:{o:0,n:0},img:{o:0,n:0},change:{o:0,n:0}}
  443. });
  444. var d=$this.data(pluginPfx),o=d.opt,
  445. /* HTML data attributes */
  446. htmlDataAxis=$this.data("mcs-axis"),htmlDataSbPos=$this.data("mcs-scrollbar-position"),htmlDataTheme=$this.data("mcs-theme");
  447. if(htmlDataAxis){o.axis=htmlDataAxis;} /* usage example: data-mcs-axis="y" */
  448. if(htmlDataSbPos){o.scrollbarPosition=htmlDataSbPos;} /* usage example: data-mcs-scrollbar-position="outside" */
  449. if(htmlDataTheme){ /* usage example: data-mcs-theme="minimal" */
  450. o.theme=htmlDataTheme;
  451. _theme(o); /* theme-specific options */
  452. }
  453. _pluginMarkup.call(this); /* add plugin markup */
  454. if(d && o.callbacks.onCreate && typeof o.callbacks.onCreate==="function"){o.callbacks.onCreate.call(this);} /* callbacks: onCreate */
  455. $("#mCSB_"+d.idx+"_container img:not(."+classes[2]+")").addClass(classes[2]); /* flag loaded images */
  456. methods.update.call(null,$this); /* call the update method */
  457. }
  458. });
  459. },
  460. /* ---------------------------------------- */
  461. /*
  462. plugin update method
  463. updates content and scrollbar(s) values, events and status
  464. ----------------------------------------
  465. usage: $(selector).mCustomScrollbar("update");
  466. */
  467. update:function(el,cb){
  468. var selector=el || _selector.call(this); /* validate selector */
  469. return $(selector).each(function(){
  470. var $this=$(this);
  471. if($this.data(pluginPfx)){ /* check if plugin has initialized */
  472. var d=$this.data(pluginPfx),o=d.opt,
  473. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  474. mCustomScrollBox=$("#mCSB_"+d.idx),
  475. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")];
  476. if(!mCSB_container.length){return;}
  477. if(d.tweenRunning){_stop($this);} /* stop any running tweens while updating */
  478. if(cb && d && o.callbacks.onBeforeUpdate && typeof o.callbacks.onBeforeUpdate==="function"){o.callbacks.onBeforeUpdate.call(this);} /* callbacks: onBeforeUpdate */
  479. /* if element was disabled or destroyed, remove class(es) */
  480. if($this.hasClass(classes[3])){$this.removeClass(classes[3]);}
  481. if($this.hasClass(classes[4])){$this.removeClass(classes[4]);}
  482. /* css flexbox fix, detect/set max-height */
  483. mCustomScrollBox.css("max-height","none");
  484. if(mCustomScrollBox.height()!==$this.height()){mCustomScrollBox.css("max-height",$this.height());}
  485. _expandContentHorizontally.call(this); /* expand content horizontally */
  486. if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){
  487. mCSB_container.css("width",_contentWidth(mCSB_container));
  488. }
  489. d.overflowed=_overflowed.call(this); /* determine if scrolling is required */
  490. _scrollbarVisibility.call(this); /* show/hide scrollbar(s) */
  491. /* auto-adjust scrollbar dragger length analogous to content */
  492. if(o.autoDraggerLength){_setDraggerLength.call(this);}
  493. _scrollRatio.call(this); /* calculate and store scrollbar to content ratio */
  494. _bindEvents.call(this); /* bind scrollbar events */
  495. /* reset scrolling position and/or events */
  496. var to=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)];
  497. if(o.axis!=="x"){ /* y/yx axis */
  498. if(!d.overflowed[0]){ /* y scrolling is not required */
  499. _resetContentPosition.call(this); /* reset content position */
  500. if(o.axis==="y"){
  501. _unbindEvents.call(this);
  502. }else if(o.axis==="yx" && d.overflowed[1]){
  503. _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"});
  504. }
  505. }else if(mCSB_dragger[0].height()>mCSB_dragger[0].parent().height()){
  506. _resetContentPosition.call(this); /* reset content position */
  507. }else{ /* y scrolling is required */
  508. _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"});
  509. d.contentReset.y=null;
  510. }
  511. }
  512. if(o.axis!=="y"){ /* x/yx axis */
  513. if(!d.overflowed[1]){ /* x scrolling is not required */
  514. _resetContentPosition.call(this); /* reset content position */
  515. if(o.axis==="x"){
  516. _unbindEvents.call(this);
  517. }else if(o.axis==="yx" && d.overflowed[0]){
  518. _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"});
  519. }
  520. }else if(mCSB_dragger[1].width()>mCSB_dragger[1].parent().width()){
  521. _resetContentPosition.call(this); /* reset content position */
  522. }else{ /* x scrolling is required */
  523. _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"});
  524. d.contentReset.x=null;
  525. }
  526. }
  527. /* callbacks: onImageLoad, onSelectorChange, onUpdate */
  528. if(cb && d){
  529. if(cb===2 && o.callbacks.onImageLoad && typeof o.callbacks.onImageLoad==="function"){
  530. o.callbacks.onImageLoad.call(this);
  531. }else if(cb===3 && o.callbacks.onSelectorChange && typeof o.callbacks.onSelectorChange==="function"){
  532. o.callbacks.onSelectorChange.call(this);
  533. }else if(o.callbacks.onUpdate && typeof o.callbacks.onUpdate==="function"){
  534. o.callbacks.onUpdate.call(this);
  535. }
  536. }
  537. _autoUpdate.call(this); /* initialize automatic updating (for dynamic content, fluid layouts etc.) */
  538. }
  539. });
  540. },
  541. /* ---------------------------------------- */
  542. /*
  543. plugin scrollTo method
  544. triggers a scrolling event to a specific value
  545. ----------------------------------------
  546. usage: $(selector).mCustomScrollbar("scrollTo",value,options);
  547. */
  548. scrollTo:function(val,options){
  549. /* prevent silly things like $(selector).mCustomScrollbar("scrollTo",undefined); */
  550. if(typeof val=="undefined" || val==null){return;}
  551. var selector=_selector.call(this); /* validate selector */
  552. return $(selector).each(function(){
  553. var $this=$(this);
  554. if($this.data(pluginPfx)){ /* check if plugin has initialized */
  555. var d=$this.data(pluginPfx),o=d.opt,
  556. /* method default options */
  557. methodDefaults={
  558. trigger:"external", /* method is by default triggered externally (e.g. from other scripts) */
  559. scrollInertia:o.scrollInertia, /* scrolling inertia (animation duration) */
  560. scrollEasing:"mcsEaseInOut", /* animation easing */
  561. moveDragger:false, /* move dragger instead of content */
  562. timeout:60, /* scroll-to delay */
  563. callbacks:true, /* enable/disable callbacks */
  564. onStart:true,
  565. onUpdate:true,
  566. onComplete:true
  567. },
  568. methodOptions=$.extend(true,{},methodDefaults,options),
  569. to=_arr.call(this,val),dur=methodOptions.scrollInertia>0 && methodOptions.scrollInertia<17 ? 17 : methodOptions.scrollInertia;
  570. /* translate yx values to actual scroll-to positions */
  571. to[0]=_to.call(this,to[0],"y");
  572. to[1]=_to.call(this,to[1],"x");
  573. /*
  574. check if scroll-to value moves the dragger instead of content.
  575. Only pixel values apply on dragger (e.g. 100, "100px", "-=100" etc.)
  576. */
  577. if(methodOptions.moveDragger){
  578. to[0]*=d.scrollRatio.y;
  579. to[1]*=d.scrollRatio.x;
  580. }
  581. methodOptions.dur=_isTabHidden() ? 0 : dur; //skip animations if browser tab is hidden
  582. setTimeout(function(){
  583. /* do the scrolling */
  584. if(to[0]!==null && typeof to[0]!=="undefined" && o.axis!=="x" && d.overflowed[0]){ /* scroll y */
  585. methodOptions.dir="y";
  586. methodOptions.overwrite="all";
  587. _scrollTo($this,to[0].toString(),methodOptions);
  588. }
  589. if(to[1]!==null && typeof to[1]!=="undefined" && o.axis!=="y" && d.overflowed[1]){ /* scroll x */
  590. methodOptions.dir="x";
  591. methodOptions.overwrite="none";
  592. _scrollTo($this,to[1].toString(),methodOptions);
  593. }
  594. },methodOptions.timeout);
  595. }
  596. });
  597. },
  598. /* ---------------------------------------- */
  599. /*
  600. plugin stop method
  601. stops scrolling animation
  602. ----------------------------------------
  603. usage: $(selector).mCustomScrollbar("stop");
  604. */
  605. stop:function(){
  606. var selector=_selector.call(this); /* validate selector */
  607. return $(selector).each(function(){
  608. var $this=$(this);
  609. if($this.data(pluginPfx)){ /* check if plugin has initialized */
  610. _stop($this);
  611. }
  612. });
  613. },
  614. /* ---------------------------------------- */
  615. /*
  616. plugin disable method
  617. temporarily disables the scrollbar(s)
  618. ----------------------------------------
  619. usage: $(selector).mCustomScrollbar("disable",reset);
  620. reset (boolean): resets content position to 0
  621. */
  622. disable:function(r){
  623. var selector=_selector.call(this); /* validate selector */
  624. return $(selector).each(function(){
  625. var $this=$(this);
  626. if($this.data(pluginPfx)){ /* check if plugin has initialized */
  627. var d=$this.data(pluginPfx);
  628. _autoUpdate.call(this,"remove"); /* remove automatic updating */
  629. _unbindEvents.call(this); /* unbind events */
  630. if(r){_resetContentPosition.call(this);} /* reset content position */
  631. _scrollbarVisibility.call(this,true); /* show/hide scrollbar(s) */
  632. $this.addClass(classes[3]); /* add disable class */
  633. }
  634. });
  635. },
  636. /* ---------------------------------------- */
  637. /*
  638. plugin destroy method
  639. completely removes the scrollbar(s) and returns the element to its original state
  640. ----------------------------------------
  641. usage: $(selector).mCustomScrollbar("destroy");
  642. */
  643. destroy:function(){
  644. var selector=_selector.call(this); /* validate selector */
  645. return $(selector).each(function(){
  646. var $this=$(this);
  647. if($this.data(pluginPfx)){ /* check if plugin has initialized */
  648. var d=$this.data(pluginPfx),o=d.opt,
  649. mCustomScrollBox=$("#mCSB_"+d.idx),
  650. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  651. scrollbar=$(".mCSB_"+d.idx+"_scrollbar");
  652. if(o.live){removeLiveTimers(o.liveSelector || $(selector).selector);} /* remove live timers */
  653. _autoUpdate.call(this,"remove"); /* remove automatic updating */
  654. _unbindEvents.call(this); /* unbind events */
  655. _resetContentPosition.call(this); /* reset content position */
  656. $this.removeData(pluginPfx); /* remove plugin data object */
  657. _delete(this,"mcs"); /* delete callbacks object */
  658. /* remove plugin markup */
  659. scrollbar.remove(); /* remove scrollbar(s) first (those can be either inside or outside plugin's inner wrapper) */
  660. mCSB_container.find("img."+classes[2]).removeClass(classes[2]); /* remove loaded images flag */
  661. mCustomScrollBox.replaceWith(mCSB_container.contents()); /* replace plugin's inner wrapper with the original content */
  662. /* remove plugin classes from the element and add destroy class */
  663. $this.removeClass(pluginNS+" _"+pluginPfx+"_"+d.idx+" "+classes[6]+" "+classes[7]+" "+classes[5]+" "+classes[3]).addClass(classes[4]);
  664. }
  665. });
  666. }
  667. /* ---------------------------------------- */
  668. },
  669. /*
  670. ----------------------------------------
  671. FUNCTIONS
  672. ----------------------------------------
  673. */
  674. /* validates selector (if selector is invalid or undefined uses the default one) */
  675. _selector=function(){
  676. return (typeof $(this)!=="object" || $(this).length<1) ? defaultSelector : this;
  677. },
  678. /* -------------------- */
  679. /* changes options according to theme */
  680. _theme=function(obj){
  681. var fixedSizeScrollbarThemes=["rounded","rounded-dark","rounded-dots","rounded-dots-dark"],
  682. 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"],
  683. disabledScrollButtonsThemes=["minimal","minimal-dark"],
  684. enabledAutoHideScrollbarThemes=["minimal","minimal-dark"],
  685. scrollbarPositionOutsideThemes=["minimal","minimal-dark"];
  686. obj.autoDraggerLength=$.inArray(obj.theme,fixedSizeScrollbarThemes) > -1 ? false : obj.autoDraggerLength;
  687. obj.autoExpandScrollbar=$.inArray(obj.theme,nonExpandedScrollbarThemes) > -1 ? false : obj.autoExpandScrollbar;
  688. obj.scrollButtons.enable=$.inArray(obj.theme,disabledScrollButtonsThemes) > -1 ? false : obj.scrollButtons.enable;
  689. obj.autoHideScrollbar=$.inArray(obj.theme,enabledAutoHideScrollbarThemes) > -1 ? true : obj.autoHideScrollbar;
  690. obj.scrollbarPosition=$.inArray(obj.theme,scrollbarPositionOutsideThemes) > -1 ? "outside" : obj.scrollbarPosition;
  691. },
  692. /* -------------------- */
  693. /* live option timers removal */
  694. removeLiveTimers=function(selector){
  695. if(liveTimers[selector]){
  696. clearTimeout(liveTimers[selector]);
  697. _delete(liveTimers,selector);
  698. }
  699. },
  700. /* -------------------- */
  701. /* normalizes axis option to valid values: "y", "x", "yx" */
  702. _findAxis=function(val){
  703. return (val==="yx" || val==="xy" || val==="auto") ? "yx" : (val==="x" || val==="horizontal") ? "x" : "y";
  704. },
  705. /* -------------------- */
  706. /* normalizes scrollButtons.scrollType option to valid values: "stepless", "stepped" */
  707. _findScrollButtonsType=function(val){
  708. return (val==="stepped" || val==="pixels" || val==="step" || val==="click") ? "stepped" : "stepless";
  709. },
  710. /* -------------------- */
  711. /* generates plugin markup */
  712. _pluginMarkup=function(){
  713. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  714. expandClass=o.autoExpandScrollbar ? " "+classes[1]+"_expand" : "",
  715. 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;'><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;'><div class='mCSB_dragger_bar' /></div><div class='mCSB_draggerRail' /></div></div>"],
  716. wrapperClass=o.axis==="yx" ? "mCSB_vertical_horizontal" : o.axis==="x" ? "mCSB_horizontal" : "mCSB_vertical",
  717. scrollbars=o.axis==="yx" ? scrollbar[0]+scrollbar[1] : o.axis==="x" ? scrollbar[1] : scrollbar[0],
  718. contentWrapper=o.axis==="yx" ? "<div id='mCSB_"+d.idx+"_container_wrapper' class='mCSB_container_wrapper' />" : "",
  719. autoHideClass=o.autoHideScrollbar ? " "+classes[6] : "",
  720. scrollbarDirClass=(o.axis!=="x" && d.langDir==="rtl") ? " "+classes[7] : "";
  721. if(o.setWidth){$this.css("width",o.setWidth);} /* set element width */
  722. if(o.setHeight){$this.css("height",o.setHeight);} /* set element height */
  723. o.setLeft=(o.axis!=="y" && d.langDir==="rtl") ? "989999px" : o.setLeft; /* adjust left position for rtl direction */
  724. $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>");
  725. var mCustomScrollBox=$("#mCSB_"+d.idx),
  726. mCSB_container=$("#mCSB_"+d.idx+"_container");
  727. if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){
  728. mCSB_container.css("width",_contentWidth(mCSB_container));
  729. }
  730. if(o.scrollbarPosition==="outside"){
  731. if($this.css("position")==="static"){ /* requires elements with non-static position */
  732. $this.css("position","relative");
  733. }
  734. $this.css("overflow","visible");
  735. mCustomScrollBox.addClass("mCSB_outside").after(scrollbars);
  736. }else{
  737. mCustomScrollBox.addClass("mCSB_inside").append(scrollbars);
  738. mCSB_container.wrap(contentWrapper);
  739. }
  740. _scrollButtons.call(this); /* add scrollbar buttons */
  741. /* minimum dragger length */
  742. var mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")];
  743. mCSB_dragger[0].css("min-height",mCSB_dragger[0].height());
  744. mCSB_dragger[1].css("min-width",mCSB_dragger[1].width());
  745. },
  746. /* -------------------- */
  747. /* calculates content width */
  748. _contentWidth=function(el){
  749. var val=[el[0].scrollWidth,Math.max.apply(Math,el.children().map(function(){return $(this).outerWidth(true);}).get())],w=el.parent().width();
  750. return val[0]>w ? val[0] : val[1]>w ? val[1] : "100%";
  751. },
  752. /* -------------------- */
  753. /* expands content horizontally */
  754. _expandContentHorizontally=function(){
  755. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  756. mCSB_container=$("#mCSB_"+d.idx+"_container");
  757. if(o.advanced.autoExpandHorizontalScroll && o.axis!=="y"){
  758. /* calculate scrollWidth */
  759. mCSB_container.css({"width":"auto","min-width":0,"overflow-x":"scroll"});
  760. var w=Math.ceil(mCSB_container[0].scrollWidth);
  761. if(o.advanced.autoExpandHorizontalScroll===3 || (o.advanced.autoExpandHorizontalScroll!==2 && w>mCSB_container.parent().width())){
  762. mCSB_container.css({"width":w,"min-width":"100%","overflow-x":"inherit"});
  763. }else{
  764. /*
  765. wrap content with an infinite width div and set its position to absolute and width to auto.
  766. Setting width to auto before calculating the actual width is important!
  767. We must let the browser set the width as browser zoom values are impossible to calculate.
  768. */
  769. mCSB_container.css({"overflow-x":"inherit","position":"absolute"})
  770. .wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />")
  771. .css({ /* set actual width, original position and un-wrap */
  772. /*
  773. get the exact width (with decimals) and then round-up.
  774. Using jquery outerWidth() will round the width value which will mess up with inner elements that have non-integer width
  775. */
  776. "width":(Math.ceil(mCSB_container[0].getBoundingClientRect().right+0.4)-Math.floor(mCSB_container[0].getBoundingClientRect().left)),
  777. "min-width":"100%",
  778. "position":"relative"
  779. }).unwrap();
  780. }
  781. }
  782. },
  783. /* -------------------- */
  784. /* adds scrollbar buttons */
  785. _scrollButtons=function(){
  786. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  787. mCSB_scrollTools=$(".mCSB_"+d.idx+"_scrollbar:first"),
  788. tabindex=!_isNumeric(o.scrollButtons.tabindex) ? "" : "tabindex='"+o.scrollButtons.tabindex+"'",
  789. btnHTML=[
  790. "<a href='#' class='"+classes[13]+"' "+tabindex+" />",
  791. "<a href='#' class='"+classes[14]+"' "+tabindex+" />",
  792. "<a href='#' class='"+classes[15]+"' "+tabindex+" />",
  793. "<a href='#' class='"+classes[16]+"' "+tabindex+" />"
  794. ],
  795. btn=[(o.axis==="x" ? btnHTML[2] : btnHTML[0]),(o.axis==="x" ? btnHTML[3] : btnHTML[1]),btnHTML[2],btnHTML[3]];
  796. if(o.scrollButtons.enable){
  797. mCSB_scrollTools.prepend(btn[0]).append(btn[1]).next(".mCSB_scrollTools").prepend(btn[2]).append(btn[3]);
  798. }
  799. },
  800. /* -------------------- */
  801. /* auto-adjusts scrollbar dragger length */
  802. _setDraggerLength=function(){
  803. var $this=$(this),d=$this.data(pluginPfx),
  804. mCustomScrollBox=$("#mCSB_"+d.idx),
  805. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  806. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
  807. ratio=[mCustomScrollBox.height()/mCSB_container.outerHeight(false),mCustomScrollBox.width()/mCSB_container.outerWidth(false)],
  808. l=[
  809. parseInt(mCSB_dragger[0].css("min-height")),Math.round(ratio[0]*mCSB_dragger[0].parent().height()),
  810. parseInt(mCSB_dragger[1].css("min-width")),Math.round(ratio[1]*mCSB_dragger[1].parent().width())
  811. ],
  812. h=oldIE && (l[1]<l[0]) ? l[0] : l[1],w=oldIE && (l[3]<l[2]) ? l[2] : l[3];
  813. mCSB_dragger[0].css({
  814. "height":h,"max-height":(mCSB_dragger[0].parent().height()-10)
  815. }).find(".mCSB_dragger_bar").css({"line-height":l[0]+"px"});
  816. mCSB_dragger[1].css({
  817. "width":w,"max-width":(mCSB_dragger[1].parent().width()-10)
  818. });
  819. },
  820. /* -------------------- */
  821. /* calculates scrollbar to content ratio */
  822. _scrollRatio=function(){
  823. var $this=$(this),d=$this.data(pluginPfx),
  824. mCustomScrollBox=$("#mCSB_"+d.idx),
  825. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  826. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
  827. scrollAmount=[mCSB_container.outerHeight(false)-mCustomScrollBox.height(),mCSB_container.outerWidth(false)-mCustomScrollBox.width()],
  828. ratio=[
  829. scrollAmount[0]/(mCSB_dragger[0].parent().height()-mCSB_dragger[0].height()),
  830. scrollAmount[1]/(mCSB_dragger[1].parent().width()-mCSB_dragger[1].width())
  831. ];
  832. d.scrollRatio={y:ratio[0],x:ratio[1]};
  833. },
  834. /* -------------------- */
  835. /* toggles scrolling classes */
  836. _onDragClasses=function(el,action,xpnd){
  837. var expandClass=xpnd ? classes[0]+"_expanded" : "",
  838. scrollbar=el.closest(".mCSB_scrollTools");
  839. if(action==="active"){
  840. el.toggleClass(classes[0]+" "+expandClass); scrollbar.toggleClass(classes[1]);
  841. el[0]._draggable=el[0]._draggable ? 0 : 1;
  842. }else{
  843. if(!el[0]._draggable){
  844. if(action==="hide"){
  845. el.removeClass(classes[0]); scrollbar.removeClass(classes[1]);
  846. }else{
  847. el.addClass(classes[0]); scrollbar.addClass(classes[1]);
  848. }
  849. }
  850. }
  851. },
  852. /* -------------------- */
  853. /* checks if content overflows its container to determine if scrolling is required */
  854. _overflowed=function(){
  855. var $this=$(this),d=$this.data(pluginPfx),
  856. mCustomScrollBox=$("#mCSB_"+d.idx),
  857. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  858. contentHeight=d.overflowed==null ? mCSB_container.height() : mCSB_container.outerHeight(false),
  859. contentWidth=d.overflowed==null ? mCSB_container.width() : mCSB_container.outerWidth(false),
  860. h=mCSB_container[0].scrollHeight,w=mCSB_container[0].scrollWidth;
  861. if(h>contentHeight){contentHeight=h;}
  862. if(w>contentWidth){contentWidth=w;}
  863. return [contentHeight>mCustomScrollBox.height(),contentWidth>mCustomScrollBox.width()];
  864. },
  865. /* -------------------- */
  866. /* resets content position to 0 */
  867. _resetContentPosition=function(){
  868. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  869. mCustomScrollBox=$("#mCSB_"+d.idx),
  870. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  871. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")];
  872. _stop($this); /* stop any current scrolling before resetting */
  873. if((o.axis!=="x" && !d.overflowed[0]) || (o.axis==="y" && d.overflowed[0])){ /* reset y */
  874. mCSB_dragger[0].add(mCSB_container).css("top",0);
  875. _scrollTo($this,"_resetY");
  876. }
  877. if((o.axis!=="y" && !d.overflowed[1]) || (o.axis==="x" && d.overflowed[1])){ /* reset x */
  878. var cx=dx=0;
  879. if(d.langDir==="rtl"){ /* adjust left position for rtl direction */
  880. cx=mCustomScrollBox.width()-mCSB_container.outerWidth(false);
  881. dx=Math.abs(cx/d.scrollRatio.x);
  882. }
  883. mCSB_container.css("left",cx);
  884. mCSB_dragger[1].css("left",dx);
  885. _scrollTo($this,"_resetX");
  886. }
  887. },
  888. /* -------------------- */
  889. /* binds scrollbar events */
  890. _bindEvents=function(){
  891. var $this=$(this),d=$this.data(pluginPfx),o=d.opt;
  892. if(!d.bindEvents){ /* check if events are already bound */
  893. _draggable.call(this);
  894. if(o.contentTouchScroll){_contentDraggable.call(this);}
  895. _selectable.call(this);
  896. if(o.mouseWheel.enable){ /* bind mousewheel fn when plugin is available */
  897. function _mwt(){
  898. mousewheelTimeout=setTimeout(function(){
  899. if(!$.event.special.mousewheel){
  900. _mwt();
  901. }else{
  902. clearTimeout(mousewheelTimeout);
  903. _mousewheel.call($this[0]);
  904. }
  905. },100);
  906. }
  907. var mousewheelTimeout;
  908. _mwt();
  909. }
  910. _draggerRail.call(this);
  911. _wrapperScroll.call(this);
  912. if(o.advanced.autoScrollOnFocus){_focus.call(this);}
  913. if(o.scrollButtons.enable){_buttons.call(this);}
  914. if(o.keyboard.enable){_keyboard.call(this);}
  915. d.bindEvents=true;
  916. }
  917. },
  918. /* -------------------- */
  919. /* unbinds scrollbar events */
  920. _unbindEvents=function(){
  921. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  922. namespace=pluginPfx+"_"+d.idx,
  923. sb=".mCSB_"+d.idx+"_scrollbar",
  924. 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"),
  925. mCSB_container=$("#mCSB_"+d.idx+"_container");
  926. if(o.advanced.releaseDraggableSelectors){sel.add($(o.advanced.releaseDraggableSelectors));}
  927. if(o.advanced.extraDraggableSelectors){sel.add($(o.advanced.extraDraggableSelectors));}
  928. if(d.bindEvents){ /* check if events are bound */
  929. /* unbind namespaced events from document/selectors */
  930. $(document).add($(!_canAccessIFrame() || top.document)).unbind("."+namespace);
  931. sel.each(function(){
  932. $(this).unbind("."+namespace);
  933. });
  934. /* clear and delete timeouts/objects */
  935. clearTimeout($this[0]._focusTimeout); _delete($this[0],"_focusTimeout");
  936. clearTimeout(d.sequential.step); _delete(d.sequential,"step");
  937. clearTimeout(mCSB_container[0].onCompleteTimeout); _delete(mCSB_container[0],"onCompleteTimeout");
  938. d.bindEvents=false;
  939. }
  940. },
  941. /* -------------------- */
  942. /* toggles scrollbar visibility */
  943. _scrollbarVisibility=function(disabled){
  944. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  945. contentWrapper=$("#mCSB_"+d.idx+"_container_wrapper"),
  946. content=contentWrapper.length ? contentWrapper : $("#mCSB_"+d.idx+"_container"),
  947. scrollbar=[$("#mCSB_"+d.idx+"_scrollbar_vertical"),$("#mCSB_"+d.idx+"_scrollbar_horizontal")],
  948. mCSB_dragger=[scrollbar[0].find(".mCSB_dragger"),scrollbar[1].find(".mCSB_dragger")];
  949. if(o.axis!=="x"){
  950. if(d.overflowed[0] && !disabled){
  951. scrollbar[0].add(mCSB_dragger[0]).add(scrollbar[0].children("a")).css("display","block");
  952. content.removeClass(classes[8]+" "+classes[10]);
  953. }else{
  954. if(o.alwaysShowScrollbar){
  955. if(o.alwaysShowScrollbar!==2){mCSB_dragger[0].css("display","none");}
  956. content.removeClass(classes[10]);
  957. }else{
  958. scrollbar[0].css("display","none");
  959. content.addClass(classes[10]);
  960. }
  961. content.addClass(classes[8]);
  962. }
  963. }
  964. if(o.axis!=="y"){
  965. if(d.overflowed[1] && !disabled){
  966. scrollbar[1].add(mCSB_dragger[1]).add(scrollbar[1].children("a")).css("display","block");
  967. content.removeClass(classes[9]+" "+classes[11]);
  968. }else{
  969. if(o.alwaysShowScrollbar){
  970. if(o.alwaysShowScrollbar!==2){mCSB_dragger[1].css("display","none");}
  971. content.removeClass(classes[11]);
  972. }else{
  973. scrollbar[1].css("display","none");
  974. content.addClass(classes[11]);
  975. }
  976. content.addClass(classes[9]);
  977. }
  978. }
  979. if(!d.overflowed[0] && !d.overflowed[1]){
  980. $this.addClass(classes[5]);
  981. }else{
  982. $this.removeClass(classes[5]);
  983. }
  984. },
  985. /* -------------------- */
  986. /* returns input coordinates of pointer, touch and mouse events (relative to document) */
  987. _coordinates=function(e){
  988. var t=e.type,o=e.target.ownerDocument!==document && frameElement!==null ? [$(frameElement).offset().top,$(frameElement).offset().left] : null,
  989. io=_canAccessIFrame() && e.target.ownerDocument!==top.document && frameElement!==null ? [$(e.view.frameElement).offset().top,$(e.view.frameElement).offset().left] : [0,0];
  990. switch(t){
  991. case "pointerdown": case "MSPointerDown": case "pointermove": case "MSPointerMove": case "pointerup": case "MSPointerUp":
  992. return o ? [e.originalEvent.pageY-o[0]+io[0],e.originalEvent.pageX-o[1]+io[1],false] : [e.originalEvent.pageY,e.originalEvent.pageX,false];
  993. break;
  994. case "touchstart": case "touchmove": case "touchend":
  995. var touch=e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
  996. touches=e.originalEvent.touches.length || e.originalEvent.changedTouches.length;
  997. return e.target.ownerDocument!==document ? [touch.screenY,touch.screenX,touches>1] : [touch.pageY,touch.pageX,touches>1];
  998. break;
  999. default:
  1000. return o ? [e.pageY-o[0]+io[0],e.pageX-o[1]+io[1],false] : [e.pageY,e.pageX,false];
  1001. }
  1002. },
  1003. /* -------------------- */
  1004. /*
  1005. SCROLLBAR DRAG EVENTS
  1006. scrolls content via scrollbar dragging
  1007. */
  1008. _draggable=function(){
  1009. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1010. namespace=pluginPfx+"_"+d.idx,
  1011. draggerId=["mCSB_"+d.idx+"_dragger_vertical","mCSB_"+d.idx+"_dragger_horizontal"],
  1012. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1013. mCSB_dragger=$("#"+draggerId[0]+",#"+draggerId[1]),
  1014. draggable,dragY,dragX,
  1015. rds=o.advanced.releaseDraggableSelectors ? mCSB_dragger.add($(o.advanced.releaseDraggableSelectors)) : mCSB_dragger,
  1016. eds=o.advanced.extraDraggableSelectors ? $(!_canAccessIFrame() || top.document).add($(o.advanced.extraDraggableSelectors)) : $(!_canAccessIFrame() || top.document);
  1017. mCSB_dragger.bind("contextmenu."+namespace,function(e){
  1018. e.preventDefault(); //prevent right click
  1019. }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){
  1020. e.stopImmediatePropagation();
  1021. e.preventDefault();
  1022. if(!_mouseBtnLeft(e)){return;} /* left mouse button only */
  1023. touchActive=true;
  1024. if(oldIE){document.onselectstart=function(){return false;}} /* disable text selection for IE < 9 */
  1025. _iframe.call(mCSB_container,false); /* enable scrollbar dragging over iframes by disabling their events */
  1026. _stop($this);
  1027. draggable=$(this);
  1028. var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left,
  1029. h=draggable.height()+offset.top,w=draggable.width()+offset.left;
  1030. if(y<h && y>0 && x<w && x>0){
  1031. dragY=y;
  1032. dragX=x;
  1033. }
  1034. _onDragClasses(draggable,"active",o.autoExpandScrollbar);
  1035. }).bind("touchmove."+namespace,function(e){
  1036. e.stopImmediatePropagation();
  1037. e.preventDefault();
  1038. var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left;
  1039. _drag(dragY,dragX,y,x);
  1040. });
  1041. // $(document).add(eds).bind("mousemove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace,function(e){
  1042. // if(draggable){
  1043. // var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left;
  1044. // if(dragY===y && dragX===x){return;} /* has it really moved? */
  1045. // _drag(dragY,dragX,y,x);
  1046. // }
  1047. // }).add(rds).bind("mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){
  1048. // if(draggable){
  1049. // _onDragClasses(draggable,"active",o.autoExpandScrollbar);
  1050. // draggable=null;
  1051. // }
  1052. // touchActive=false;
  1053. // if(oldIE){document.onselectstart=null;} /* enable text selection for IE < 9 */
  1054. // _iframe.call(mCSB_container,true); /* enable iframes events */
  1055. // });
  1056. function _drag(dragY,dragX,y,x){
  1057. mCSB_container[0].idleTimer=o.scrollInertia<233 ? 250 : 0;
  1058. if(draggable.attr("id")===draggerId[1]){
  1059. var dir="x",to=((draggable[0].offsetLeft-dragX)+x)*d.scrollRatio.x;
  1060. }else{
  1061. var dir="y",to=((draggable[0].offsetTop-dragY)+y)*d.scrollRatio.y;
  1062. }
  1063. _scrollTo($this,to.toString(),{dir:dir,drag:true});
  1064. }
  1065. },
  1066. /* -------------------- */
  1067. /*
  1068. TOUCH SWIPE EVENTS
  1069. scrolls content via touch swipe
  1070. Emulates the native touch-swipe scrolling with momentum found in iOS, Android and WP devices
  1071. */
  1072. _contentDraggable=function(){
  1073. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1074. namespace=pluginPfx+"_"+d.idx,
  1075. mCustomScrollBox=$("#mCSB_"+d.idx),
  1076. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1077. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
  1078. draggable,dragY,dragX,touchStartY,touchStartX,touchMoveY=[],touchMoveX=[],startTime,runningTime,endTime,distance,speed,amount,
  1079. durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag,
  1080. iframe=mCSB_container.find("iframe"),
  1081. events=[
  1082. "touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace, //start
  1083. "touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace, //move
  1084. "touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace //end
  1085. ],
  1086. touchAction=document.body.style.touchAction!==undefined && document.body.style.touchAction!=="";
  1087. mCSB_container.bind(events[0],function(e){
  1088. _onTouchstart(e);
  1089. }).bind(events[1],function(e){
  1090. _onTouchmove(e);
  1091. });
  1092. mCustomScrollBox.bind(events[0],function(e){
  1093. _onTouchstart2(e);
  1094. }).bind(events[2],function(e){
  1095. _onTouchend(e);
  1096. });
  1097. if(iframe.length){
  1098. iframe.each(function(){
  1099. $(this).bind("load",function(){
  1100. /* bind events on accessible iframes */
  1101. if(_canAccessIFrame(this)){
  1102. $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){
  1103. _onTouchstart(e);
  1104. _onTouchstart2(e);
  1105. }).bind(events[1],function(e){
  1106. _onTouchmove(e);
  1107. }).bind(events[2],function(e){
  1108. _onTouchend(e);
  1109. });
  1110. }
  1111. });
  1112. });
  1113. }
  1114. function _onTouchstart(e){
  1115. if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;}
  1116. touchable=1; touchDrag=0; docDrag=0; draggable=1;
  1117. $this.removeClass("mCS_touch_action");
  1118. var offset=mCSB_container.offset();
  1119. dragY=_coordinates(e)[0]-offset.top;
  1120. dragX=_coordinates(e)[1]-offset.left;
  1121. touchIntent=[_coordinates(e)[0],_coordinates(e)[1]];
  1122. }
  1123. function _onTouchmove(e){
  1124. if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;}
  1125. if(!o.documentTouchScroll){e.preventDefault();}
  1126. e.stopImmediatePropagation();
  1127. if(docDrag && !touchDrag){return;}
  1128. if(draggable){
  1129. runningTime=_getTime();
  1130. var offset=mCustomScrollBox.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left,
  1131. easing="mcsLinearOut";
  1132. touchMoveY.push(y);
  1133. touchMoveX.push(x);
  1134. touchIntent[2]=Math.abs(_coordinates(e)[0]-touchIntent[0]); touchIntent[3]=Math.abs(_coordinates(e)[1]-touchIntent[1]);
  1135. if(d.overflowed[0]){
  1136. var limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(),
  1137. prevent=((dragY-y)>0 && (y-dragY)>-(limit*d.scrollRatio.y) && (touchIntent[3]*2<touchIntent[2] || o.axis==="yx"));
  1138. }
  1139. if(d.overflowed[1]){
  1140. var limitX=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(),
  1141. preventX=((dragX-x)>0 && (x-dragX)>-(limitX*d.scrollRatio.x) && (touchIntent[2]*2<touchIntent[3] || o.axis==="yx"));
  1142. }
  1143. if(prevent || preventX){ /* prevent native document scrolling */
  1144. if(!touchAction){e.preventDefault();}
  1145. touchDrag=1;
  1146. }else{
  1147. docDrag=1;
  1148. $this.addClass("mCS_touch_action");
  1149. }
  1150. if(touchAction){e.preventDefault();}
  1151. amount=o.axis==="yx" ? [(dragY-y),(dragX-x)] : o.axis==="x" ? [null,(dragX-x)] : [(dragY-y),null];
  1152. mCSB_container[0].idleTimer=250;
  1153. if(d.overflowed[0]){_drag(amount[0],durA,easing,"y","all",true);}
  1154. if(d.overflowed[1]){_drag(amount[1],durA,easing,"x",overwrite,true);}
  1155. }
  1156. }
  1157. function _onTouchstart2(e){
  1158. if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;}
  1159. touchable=1;
  1160. e.stopImmediatePropagation();
  1161. _stop($this);
  1162. startTime=_getTime();
  1163. var offset=mCustomScrollBox.offset();
  1164. touchStartY=_coordinates(e)[0]-offset.top;
  1165. touchStartX=_coordinates(e)[1]-offset.left;
  1166. touchMoveY=[]; touchMoveX=[];
  1167. }
  1168. function _onTouchend(e){
  1169. if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;}
  1170. draggable=0;
  1171. e.stopImmediatePropagation();
  1172. touchDrag=0; docDrag=0;
  1173. endTime=_getTime();
  1174. var offset=mCustomScrollBox.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left;
  1175. if((endTime-runningTime)>30){return;}
  1176. speed=1000/(endTime-startTime);
  1177. var easing="mcsEaseOut",slow=speed<2.5,
  1178. diff=slow ? [touchMoveY[touchMoveY.length-2],touchMoveX[touchMoveX.length-2]] : [0,0];
  1179. distance=slow ? [(y-diff[0]),(x-diff[1])] : [y-touchStartY,x-touchStartX];
  1180. var absDistance=[Math.abs(distance[0]),Math.abs(distance[1])];
  1181. speed=slow ? [Math.abs(distance[0]/4),Math.abs(distance[1]/4)] : [speed,speed];
  1182. var a=[
  1183. Math.abs(mCSB_container[0].offsetTop)-(distance[0]*_m((absDistance[0]/speed[0]),speed[0])),
  1184. Math.abs(mCSB_container[0].offsetLeft)-(distance[1]*_m((absDistance[1]/speed[1]),speed[1]))
  1185. ];
  1186. amount=o.axis==="yx" ? [a[0],a[1]] : o.axis==="x" ? [null,a[1]] : [a[0],null];
  1187. durB=[(absDistance[0]*4)+o.scrollInertia,(absDistance[1]*4)+o.scrollInertia];
  1188. var md=parseInt(o.contentTouchScroll) || 0; /* absolute minimum distance required */
  1189. amount[0]=absDistance[0]>md ? amount[0] : 0;
  1190. amount[1]=absDistance[1]>md ? amount[1] : 0;
  1191. if(d.overflowed[0]){_drag(amount[0],durB[0],easing,"y",overwrite,false);}
  1192. if(d.overflowed[1]){_drag(amount[1],durB[1],easing,"x",overwrite,false);}
  1193. }
  1194. function _m(ds,s){
  1195. var r=[s*1.5,s*2,s/1.5,s/2];
  1196. if(ds>90){
  1197. return s>4 ? r[0] : r[3];
  1198. }else if(ds>60){
  1199. return s>3 ? r[3] : r[2];
  1200. }else if(ds>30){
  1201. return s>8 ? r[1] : s>6 ? r[0] : s>4 ? s : r[2];
  1202. }else{
  1203. return s>8 ? s : r[3];
  1204. }
  1205. }
  1206. function _drag(amount,dur,easing,dir,overwrite,drag){
  1207. if(!amount){return;}
  1208. _scrollTo($this,amount.toString(),{dur:dur,scrollEasing:easing,dir:dir,overwrite:overwrite,drag:drag});
  1209. }
  1210. },
  1211. /* -------------------- */
  1212. /*
  1213. SELECT TEXT EVENTS
  1214. scrolls content when text is selected
  1215. */
  1216. _selectable=function(){
  1217. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential,
  1218. namespace=pluginPfx+"_"+d.idx,
  1219. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1220. wrapper=mCSB_container.parent(),
  1221. action;
  1222. mCSB_container.bind("mousedown."+namespace,function(e){
  1223. if(touchable){return;}
  1224. if(!action){action=1; touchActive=true;}
  1225. }).add(document).bind("mousemove."+namespace,function(e){
  1226. if(!touchable && action && _sel()){
  1227. var offset=mCSB_container.offset(),
  1228. y=_coordinates(e)[0]-offset.top+mCSB_container[0].offsetTop,x=_coordinates(e)[1]-offset.left+mCSB_container[0].offsetLeft;
  1229. if(y>0 && y<wrapper.height() && x>0 && x<wrapper.width()){
  1230. if(seq.step){_seq("off",null,"stepped");}
  1231. }else{
  1232. if(o.axis!=="x" && d.overflowed[0]){
  1233. if(y<0){
  1234. _seq("on",38);
  1235. }else if(y>wrapper.height()){
  1236. _seq("on",40);
  1237. }
  1238. }
  1239. if(o.axis!=="y" && d.overflowed[1]){
  1240. if(x<0){
  1241. _seq("on",37);
  1242. }else if(x>wrapper.width()){
  1243. _seq("on",39);
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }).bind("mouseup."+namespace+" dragend."+namespace,function(e){
  1249. if(touchable){return;}
  1250. if(action){action=0; _seq("off",null);}
  1251. touchActive=false;
  1252. });
  1253. function _sel(){
  1254. return window.getSelection ? window.getSelection().toString() :
  1255. document.selection && document.selection.type!="Control" ? document.selection.createRange().text : 0;
  1256. }
  1257. function _seq(a,c,s){
  1258. seq.type=s && action ? "stepped" : "stepless";
  1259. seq.scrollAmount=10;
  1260. _sequentialScroll($this,a,c,"mcsLinearOut",s ? 60 : null);
  1261. }
  1262. },
  1263. /* -------------------- */
  1264. /*
  1265. MOUSE WHEEL EVENT
  1266. scrolls content via mouse-wheel
  1267. via mouse-wheel plugin (https://github.com/brandonaaron/jquery-mousewheel)
  1268. */
  1269. _mousewheel=function(){
  1270. if(!$(this).data(pluginPfx)){return;} /* Check if the scrollbar is ready to use mousewheel events (issue: #185) */
  1271. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1272. namespace=pluginPfx+"_"+d.idx,
  1273. mCustomScrollBox=$("#mCSB_"+d.idx),
  1274. mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
  1275. iframe=$("#mCSB_"+d.idx+"_container").find("iframe");
  1276. if(iframe.length){
  1277. iframe.each(function(){
  1278. $(this).bind("load",function(){
  1279. /* bind events on accessible iframes */
  1280. if(_canAccessIFrame(this)){
  1281. $(this.contentDocument || this.contentWindow.document).bind("mousewheel."+namespace,function(e,delta){
  1282. _onMousewheel(e,delta);
  1283. });
  1284. }
  1285. });
  1286. });
  1287. }
  1288. mCustomScrollBox.bind("mousewheel."+namespace,function(e,delta){
  1289. _onMousewheel(e,delta);
  1290. });
  1291. function _onMousewheel(e,delta){
  1292. _stop($this);
  1293. if(_disableMousewheel($this,e.target)){return;} /* disables mouse-wheel when hovering specific elements */
  1294. var deltaFactor=o.mouseWheel.deltaFactor!=="auto" ? parseInt(o.mouseWheel.deltaFactor) : (oldIE && e.deltaFactor<100) ? 100 : e.deltaFactor || 100,
  1295. dur=o.scrollInertia;
  1296. if(o.axis==="x" || o.mouseWheel.axis==="x"){
  1297. var dir="x",
  1298. px=[Math.round(deltaFactor*d.scrollRatio.x),parseInt(o.mouseWheel.scrollAmount)],
  1299. amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.width() ? mCustomScrollBox.width()*0.9 : px[0],
  1300. contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetLeft),
  1301. draggerPos=mCSB_dragger[1][0].offsetLeft,
  1302. limit=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(),
  1303. dlt=o.mouseWheel.axis==="y" ? (e.deltaY || delta) : e.deltaX;
  1304. }else{
  1305. var dir="y",
  1306. px=[Math.round(deltaFactor*d.scrollRatio.y),parseInt(o.mouseWheel.scrollAmount)],
  1307. amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.height() ? mCustomScrollBox.height()*0.9 : px[0],
  1308. contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetTop),
  1309. draggerPos=mCSB_dragger[0][0].offsetTop,
  1310. limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(),
  1311. dlt=e.deltaY || delta;
  1312. }
  1313. if((dir==="y" && !d.overflowed[0]) || (dir==="x" && !d.overflowed[1])){return;}
  1314. if(o.mouseWheel.invert || e.webkitDirectionInvertedFromDevice){dlt=-dlt;}
  1315. if(o.mouseWheel.normalizeDelta){dlt=dlt<0 ? -1 : 1;}
  1316. if((dlt>0 && draggerPos!==0) || (dlt<0 && draggerPos!==limit) || o.mouseWheel.preventDefault){
  1317. e.stopImmediatePropagation();
  1318. e.preventDefault();
  1319. }
  1320. if(e.deltaFactor<5 && !o.mouseWheel.normalizeDelta){
  1321. //very low deltaFactor values mean some kind of delta acceleration (e.g. osx trackpad), so adjusting scrolling accordingly
  1322. amount=e.deltaFactor; dur=17;
  1323. }
  1324. _scrollTo($this,(contentPos-(dlt*amount)).toString(),{dir:dir,dur:dur});
  1325. }
  1326. },
  1327. /* -------------------- */
  1328. /* checks if iframe can be accessed */
  1329. _canAccessIFrameCache=new Object(),
  1330. _canAccessIFrame=function(iframe){
  1331. var result=false,cacheKey=false,html=null;
  1332. if(iframe===undefined){
  1333. cacheKey="#empty";
  1334. }else if($(iframe).attr("id")!==undefined){
  1335. cacheKey=$(iframe).attr("id");
  1336. }
  1337. if(cacheKey!==false && _canAccessIFrameCache[cacheKey]!==undefined){
  1338. return _canAccessIFrameCache[cacheKey];
  1339. }
  1340. if(!iframe){
  1341. try{
  1342. var doc=top.document;
  1343. html=doc.body.innerHTML;
  1344. }catch(err){/* do nothing */}
  1345. result=(html!==null);
  1346. }else{
  1347. try{
  1348. var doc=iframe.contentDocument || iframe.contentWindow.document;
  1349. html=doc.body.innerHTML;
  1350. }catch(err){/* do nothing */}
  1351. result=(html!==null);
  1352. }
  1353. if(cacheKey!==false){_canAccessIFrameCache[cacheKey]=result;}
  1354. return result;
  1355. },
  1356. /* -------------------- */
  1357. /* switches iframe's pointer-events property (drag, mousewheel etc. over cross-domain iframes) */
  1358. _iframe=function(evt){
  1359. var el=this.find("iframe");
  1360. if(!el.length){return;} /* check if content contains iframes */
  1361. var val=!evt ? "none" : "auto";
  1362. el.css("pointer-events",val); /* for IE11, iframe's display property should not be "block" */
  1363. },
  1364. /* -------------------- */
  1365. /* disables mouse-wheel when hovering specific elements like select, datalist etc. */
  1366. _disableMousewheel=function(el,target){
  1367. var tag=target.nodeName.toLowerCase(),
  1368. tags=el.data(pluginPfx).opt.mouseWheel.disableOver,
  1369. /* elements that require focus */
  1370. focusTags=["select","textarea"];
  1371. return $.inArray(tag,tags) > -1 && !($.inArray(tag,focusTags) > -1 && !$(target).is(":focus"));
  1372. },
  1373. /* -------------------- */
  1374. /*
  1375. DRAGGER RAIL CLICK EVENT
  1376. scrolls content via dragger rail
  1377. */
  1378. _draggerRail=function(){
  1379. var $this=$(this),d=$this.data(pluginPfx),
  1380. namespace=pluginPfx+"_"+d.idx,
  1381. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1382. wrapper=mCSB_container.parent(),
  1383. mCSB_draggerContainer=$(".mCSB_"+d.idx+"_scrollbar ."+classes[12]),
  1384. clickable;
  1385. mCSB_draggerContainer.bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){
  1386. touchActive=true;
  1387. if(!$(e.target).hasClass("mCSB_dragger")){clickable=1;}
  1388. }).bind("touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){
  1389. touchActive=false;
  1390. }).bind("click."+namespace,function(e){
  1391. if(!clickable){return;}
  1392. clickable=0;
  1393. if($(e.target).hasClass(classes[12]) || $(e.target).hasClass("mCSB_draggerRail")){
  1394. _stop($this);
  1395. var el=$(this),mCSB_dragger=el.find(".mCSB_dragger");
  1396. if(el.parent(".mCSB_scrollTools_horizontal").length>0){
  1397. if(!d.overflowed[1]){return;}
  1398. var dir="x",
  1399. clickDir=e.pageX>mCSB_dragger.offset().left ? -1 : 1,
  1400. to=Math.abs(mCSB_container[0].offsetLeft)-(clickDir*(wrapper.width()*0.9));
  1401. }else{
  1402. if(!d.overflowed[0]){return;}
  1403. var dir="y",
  1404. clickDir=e.pageY>mCSB_dragger.offset().top ? -1 : 1,
  1405. to=Math.abs(mCSB_container[0].offsetTop)-(clickDir*(wrapper.height()*0.9));
  1406. }
  1407. _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"});
  1408. }
  1409. });
  1410. },
  1411. /* -------------------- */
  1412. /*
  1413. FOCUS EVENT
  1414. scrolls content via element focus (e.g. clicking an input, pressing TAB key etc.)
  1415. */
  1416. _focus=function(){
  1417. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1418. namespace=pluginPfx+"_"+d.idx,
  1419. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1420. wrapper=mCSB_container.parent();
  1421. mCSB_container.bind("focusin."+namespace,function(e){
  1422. var el=$(document.activeElement),
  1423. nested=mCSB_container.find(".mCustomScrollBox").length,
  1424. dur=0;
  1425. if(!el.is(o.advanced.autoScrollOnFocus)){return;}
  1426. _stop($this);
  1427. clearTimeout($this[0]._focusTimeout);
  1428. $this[0]._focusTimer=nested ? (dur+17)*nested : 0;
  1429. $this[0]._focusTimeout=setTimeout(function(){
  1430. var to=[_childPos(el)[0],_childPos(el)[1]],
  1431. contentPos=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft],
  1432. isVisible=[
  1433. (contentPos[0]+to[0]>=0 && contentPos[0]+to[0]<wrapper.height()-el.outerHeight(false)),
  1434. (contentPos[1]+to[1]>=0 && contentPos[0]+to[1]<wrapper.width()-el.outerWidth(false))
  1435. ],
  1436. overwrite=(o.axis==="yx" && !isVisible[0] && !isVisible[1]) ? "none" : "all";
  1437. if(o.axis!=="x" && !isVisible[0]){
  1438. _scrollTo($this,to[0].toString(),{dir:"y",scrollEasing:"mcsEaseInOut",overwrite:overwrite,dur:dur});
  1439. }
  1440. if(o.axis!=="y" && !isVisible[1]){
  1441. _scrollTo($this,to[1].toString(),{dir:"x",scrollEasing:"mcsEaseInOut",overwrite:overwrite,dur:dur});
  1442. }
  1443. },$this[0]._focusTimer);
  1444. });
  1445. },
  1446. /* -------------------- */
  1447. /* sets content wrapper scrollTop/scrollLeft always to 0 */
  1448. _wrapperScroll=function(){
  1449. var $this=$(this),d=$this.data(pluginPfx),
  1450. namespace=pluginPfx+"_"+d.idx,
  1451. wrapper=$("#mCSB_"+d.idx+"_container").parent();
  1452. wrapper.bind("scroll."+namespace,function(e){
  1453. if(wrapper.scrollTop()!==0 || wrapper.scrollLeft()!==0){
  1454. $(".mCSB_"+d.idx+"_scrollbar").css("visibility","hidden"); /* hide scrollbar(s) */
  1455. }
  1456. });
  1457. },
  1458. /* -------------------- */
  1459. /*
  1460. BUTTONS EVENTS
  1461. scrolls content via up, down, left and right buttons
  1462. */
  1463. _buttons=function(){
  1464. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential,
  1465. namespace=pluginPfx+"_"+d.idx,
  1466. sel=".mCSB_"+d.idx+"_scrollbar",
  1467. btn=$(sel+">a");
  1468. btn.bind("contextmenu."+namespace,function(e){
  1469. e.preventDefault(); //prevent right click
  1470. }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace+" mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace+" mouseout."+namespace+" pointerout."+namespace+" MSPointerOut."+namespace+" click."+namespace,function(e){
  1471. e.preventDefault();
  1472. if(!_mouseBtnLeft(e)){return;} /* left mouse button only */
  1473. var btnClass=$(this).attr("class");
  1474. seq.type=o.scrollButtons.scrollType;
  1475. switch(e.type){
  1476. case "mousedown": case "touchstart": case "pointerdown": case "MSPointerDown":
  1477. if(seq.type==="stepped"){return;}
  1478. touchActive=true;
  1479. d.tweenRunning=false;
  1480. _seq("on",btnClass);
  1481. break;
  1482. case "mouseup": case "touchend": case "pointerup": case "MSPointerUp":
  1483. case "mouseout": case "pointerout": case "MSPointerOut":
  1484. if(seq.type==="stepped"){return;}
  1485. touchActive=false;
  1486. if(seq.dir){_seq("off",btnClass);}
  1487. break;
  1488. case "click":
  1489. if(seq.type!=="stepped" || d.tweenRunning){return;}
  1490. _seq("on",btnClass);
  1491. break;
  1492. }
  1493. function _seq(a,c){
  1494. seq.scrollAmount=o.scrollButtons.scrollAmount;
  1495. _sequentialScroll($this,a,c);
  1496. }
  1497. });
  1498. },
  1499. /* -------------------- */
  1500. /*
  1501. KEYBOARD EVENTS
  1502. scrolls content via keyboard
  1503. Keys: up arrow, down arrow, left arrow, right arrow, PgUp, PgDn, Home, End
  1504. */
  1505. _keyboard=function(){
  1506. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential,
  1507. namespace=pluginPfx+"_"+d.idx,
  1508. mCustomScrollBox=$("#mCSB_"+d.idx),
  1509. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1510. wrapper=mCSB_container.parent(),
  1511. editables="input,textarea,select,datalist,keygen,[contenteditable='true']",
  1512. iframe=mCSB_container.find("iframe"),
  1513. events=["blur."+namespace+" keydown."+namespace+" keyup."+namespace];
  1514. if(iframe.length){
  1515. iframe.each(function(){
  1516. $(this).bind("load",function(){
  1517. /* bind events on accessible iframes */
  1518. if(_canAccessIFrame(this)){
  1519. $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){
  1520. _onKeyboard(e);
  1521. });
  1522. }
  1523. });
  1524. });
  1525. }
  1526. mCustomScrollBox.attr("tabindex","0").bind(events[0],function(e){
  1527. _onKeyboard(e);
  1528. });
  1529. function _onKeyboard(e){
  1530. switch(e.type){
  1531. case "blur":
  1532. if(d.tweenRunning && seq.dir){_seq("off",null);}
  1533. break;
  1534. case "keydown": case "keyup":
  1535. var code=e.keyCode ? e.keyCode : e.which,action="on";
  1536. if((o.axis!=="x" && (code===38 || code===40)) || (o.axis!=="y" && (code===37 || code===39))){
  1537. /* up (38), down (40), left (37), right (39) arrows */
  1538. if(((code===38 || code===40) && !d.overflowed[0]) || ((code===37 || code===39) && !d.overflowed[1])){return;}
  1539. if(e.type==="keyup"){action="off";}
  1540. if(!$(document.activeElement).is(editables)){
  1541. e.preventDefault();
  1542. e.stopImmediatePropagation();
  1543. _seq(action,code);
  1544. }
  1545. }else if(code===33 || code===34){
  1546. /* PgUp (33), PgDn (34) */
  1547. if(d.overflowed[0] || d.overflowed[1]){
  1548. e.preventDefault();
  1549. e.stopImmediatePropagation();
  1550. }
  1551. if(e.type==="keyup"){
  1552. _stop($this);
  1553. var keyboardDir=code===34 ? -1 : 1;
  1554. if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){
  1555. var dir="x",to=Math.abs(mCSB_container[0].offsetLeft)-(keyboardDir*(wrapper.width()*0.9));
  1556. }else{
  1557. var dir="y",to=Math.abs(mCSB_container[0].offsetTop)-(keyboardDir*(wrapper.height()*0.9));
  1558. }
  1559. _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"});
  1560. }
  1561. }else if(code===35 || code===36){
  1562. /* End (35), Home (36) */
  1563. if(!$(document.activeElement).is(editables)){
  1564. if(d.overflowed[0] || d.overflowed[1]){
  1565. e.preventDefault();
  1566. e.stopImmediatePropagation();
  1567. }
  1568. if(e.type==="keyup"){
  1569. if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){
  1570. var dir="x",to=code===35 ? Math.abs(wrapper.width()-mCSB_container.outerWidth(false)) : 0;
  1571. }else{
  1572. var dir="y",to=code===35 ? Math.abs(wrapper.height()-mCSB_container.outerHeight(false)) : 0;
  1573. }
  1574. _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"});
  1575. }
  1576. }
  1577. }
  1578. break;
  1579. }
  1580. function _seq(a,c){
  1581. seq.type=o.keyboard.scrollType;
  1582. seq.scrollAmount=o.keyboard.scrollAmount;
  1583. if(seq.type==="stepped" && d.tweenRunning){return;}
  1584. _sequentialScroll($this,a,c);
  1585. }
  1586. }
  1587. },
  1588. /* -------------------- */
  1589. /* scrolls content sequentially (used when scrolling via buttons, keyboard arrows etc.) */
  1590. _sequentialScroll=function(el,action,trigger,e,s){
  1591. var d=el.data(pluginPfx),o=d.opt,seq=d.sequential,
  1592. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1593. once=seq.type==="stepped" ? true : false,
  1594. steplessSpeed=o.scrollInertia < 26 ? 26 : o.scrollInertia, /* 26/1.5=17 */
  1595. steppedSpeed=o.scrollInertia < 1 ? 17 : o.scrollInertia;
  1596. switch(action){
  1597. case "on":
  1598. seq.dir=[
  1599. (trigger===classes[16] || trigger===classes[15] || trigger===39 || trigger===37 ? "x" : "y"),
  1600. (trigger===classes[13] || trigger===classes[15] || trigger===38 || trigger===37 ? -1 : 1)
  1601. ];
  1602. _stop(el);
  1603. if(_isNumeric(trigger) && seq.type==="stepped"){return;}
  1604. _on(once);
  1605. break;
  1606. case "off":
  1607. _off();
  1608. if(once || (d.tweenRunning && seq.dir)){
  1609. _on(true);
  1610. }
  1611. break;
  1612. }
  1613. /* starts sequence */
  1614. function _on(once){
  1615. if(o.snapAmount){seq.scrollAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : seq.dir[0]==="x" ? o.snapAmount[1] : o.snapAmount[0];} /* scrolling snapping */
  1616. var c=seq.type!=="stepped", /* continuous scrolling */
  1617. t=s ? s : !once ? 1000/60 : c ? steplessSpeed/1.5 : steppedSpeed, /* timer */
  1618. m=!once ? 2.5 : c ? 7.5 : 40, /* multiplier */
  1619. contentPos=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)],
  1620. ratio=[d.scrollRatio.y>10 ? 10 : d.scrollRatio.y,d.scrollRatio.x>10 ? 10 : d.scrollRatio.x],
  1621. amount=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*(ratio[1]*m)) : contentPos[0]+(seq.dir[1]*(ratio[0]*m)),
  1622. px=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*parseInt(seq.scrollAmount)) : contentPos[0]+(seq.dir[1]*parseInt(seq.scrollAmount)),
  1623. to=seq.scrollAmount!=="auto" ? px : amount,
  1624. easing=e ? e : !once ? "mcsLinear" : c ? "mcsLinearOut" : "mcsEaseInOut",
  1625. onComplete=!once ? false : true;
  1626. if(once && t<17){
  1627. to=seq.dir[0]==="x" ? contentPos[1] : contentPos[0];
  1628. }
  1629. _scrollTo(el,to.toString(),{dir:seq.dir[0],scrollEasing:easing,dur:t,onComplete:onComplete});
  1630. if(once){
  1631. seq.dir=false;
  1632. return;
  1633. }
  1634. clearTimeout(seq.step);
  1635. seq.step=setTimeout(function(){
  1636. _on();
  1637. },t);
  1638. }
  1639. /* stops sequence */
  1640. function _off(){
  1641. clearTimeout(seq.step);
  1642. _delete(seq,"step");
  1643. _stop(el);
  1644. }
  1645. },
  1646. /* -------------------- */
  1647. /* returns a yx array from value */
  1648. _arr=function(val){
  1649. var o=$(this).data(pluginPfx).opt,vals=[];
  1650. if(typeof val==="function"){val=val();} /* check if the value is a single anonymous function */
  1651. /* check if value is object or array, its length and create an array with yx values */
  1652. if(!(val instanceof Array)){ /* object value (e.g. {y:"100",x:"100"}, 100 etc.) */
  1653. vals[0]=val.y ? val.y : val.x || o.axis==="x" ? null : val;
  1654. vals[1]=val.x ? val.x : val.y || o.axis==="y" ? null : val;
  1655. }else{ /* array value (e.g. [100,100]) */
  1656. vals=val.length>1 ? [val[0],val[1]] : o.axis==="x" ? [null,val[0]] : [val[0],null];
  1657. }
  1658. /* check if array values are anonymous functions */
  1659. if(typeof vals[0]==="function"){vals[0]=vals[0]();}
  1660. if(typeof vals[1]==="function"){vals[1]=vals[1]();}
  1661. return vals;
  1662. },
  1663. /* -------------------- */
  1664. /* translates values (e.g. "top", 100, "100px", "#id") to actual scroll-to positions */
  1665. _to=function(val,dir){
  1666. if(val==null || typeof val=="undefined"){return;}
  1667. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1668. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1669. wrapper=mCSB_container.parent(),
  1670. t=typeof val;
  1671. if(!dir){dir=o.axis==="x" ? "x" : "y";}
  1672. var contentLength=dir==="x" ? mCSB_container.outerWidth(false)-wrapper.width() : mCSB_container.outerHeight(false)-wrapper.height(),
  1673. contentPos=dir==="x" ? mCSB_container[0].offsetLeft : mCSB_container[0].offsetTop,
  1674. cssProp=dir==="x" ? "left" : "top";
  1675. switch(t){
  1676. case "function": /* this currently is not used. Consider removing it */
  1677. return val();
  1678. break;
  1679. case "object": /* js/jquery object */
  1680. var obj=val.jquery ? val : $(val);
  1681. if(!obj.length){return;}
  1682. return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0];
  1683. break;
  1684. case "string": case "number":
  1685. if(_isNumeric(val)){ /* numeric value */
  1686. return Math.abs(val);
  1687. }else if(val.indexOf("%")!==-1){ /* percentage value */
  1688. return Math.abs(contentLength*parseInt(val)/100);
  1689. }else if(val.indexOf("-=")!==-1){ /* decrease value */
  1690. return Math.abs(contentPos-parseInt(val.split("-=")[1]));
  1691. }else if(val.indexOf("+=")!==-1){ /* inrease value */
  1692. var p=(contentPos+parseInt(val.split("+=")[1]));
  1693. return p>=0 ? 0 : Math.abs(p);
  1694. }else if(val.indexOf("px")!==-1 && _isNumeric(val.split("px")[0])){ /* pixels string value (e.g. "100px") */
  1695. return Math.abs(val.split("px")[0]);
  1696. }else{
  1697. if(val==="top" || val==="left"){ /* special strings */
  1698. return 0;
  1699. }else if(val==="bottom"){
  1700. return Math.abs(wrapper.height()-mCSB_container.outerHeight(false));
  1701. }else if(val==="right"){
  1702. return Math.abs(wrapper.width()-mCSB_container.outerWidth(false));
  1703. }else if(val==="first" || val==="last"){
  1704. var obj=mCSB_container.find(":"+val);
  1705. return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0];
  1706. }else{
  1707. if($(val).length){ /* jquery selector */
  1708. return dir==="x" ? _childPos($(val))[1] : _childPos($(val))[0];
  1709. }else{ /* other values (e.g. "100em") */
  1710. mCSB_container.css(cssProp,val);
  1711. methods.update.call(null,$this[0]);
  1712. return;
  1713. }
  1714. }
  1715. }
  1716. break;
  1717. }
  1718. },
  1719. /* -------------------- */
  1720. /* calls the update method automatically */
  1721. _autoUpdate=function(rem){
  1722. var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
  1723. mCSB_container=$("#mCSB_"+d.idx+"_container");
  1724. if(rem){
  1725. /*
  1726. removes autoUpdate timer
  1727. usage: _autoUpdate.call(this,"remove");
  1728. */
  1729. clearTimeout(mCSB_container[0].autoUpdate);
  1730. _delete(mCSB_container[0],"autoUpdate");
  1731. return;
  1732. }
  1733. upd();
  1734. function upd(){
  1735. clearTimeout(mCSB_container[0].autoUpdate);
  1736. if($this.parents("html").length===0){
  1737. /* check element in dom tree */
  1738. $this=null;
  1739. return;
  1740. }
  1741. mCSB_container[0].autoUpdate=setTimeout(function(){
  1742. /* update on specific selector(s) length and size change */
  1743. if(o.advanced.updateOnSelectorChange){
  1744. d.poll.change.n=sizesSum();
  1745. if(d.poll.change.n!==d.poll.change.o){
  1746. d.poll.change.o=d.poll.change.n;
  1747. doUpd(3);
  1748. return;
  1749. }
  1750. }
  1751. /* update on main element and scrollbar size changes */
  1752. if(o.advanced.updateOnContentResize){
  1753. d.poll.size.n=$this[0].scrollHeight+$this[0].scrollWidth+mCSB_container[0].offsetHeight+$this[0].offsetHeight+$this[0].offsetWidth;
  1754. if(d.poll.size.n!==d.poll.size.o){
  1755. d.poll.size.o=d.poll.size.n;
  1756. doUpd(1);
  1757. return;
  1758. }
  1759. }
  1760. /* update on image load */
  1761. if(o.advanced.updateOnImageLoad){
  1762. if(!(o.advanced.updateOnImageLoad==="auto" && o.axis==="y")){ //by default, it doesn't run on vertical content
  1763. d.poll.img.n=mCSB_container.find("img").length;
  1764. if(d.poll.img.n!==d.poll.img.o){
  1765. d.poll.img.o=d.poll.img.n;
  1766. mCSB_container.find("img").each(function(){
  1767. imgLoader(this);
  1768. });
  1769. return;
  1770. }
  1771. }
  1772. }
  1773. if(o.advanced.updateOnSelectorChange || o.advanced.updateOnContentResize || o.advanced.updateOnImageLoad){upd();}
  1774. },o.advanced.autoUpdateTimeout);
  1775. }
  1776. /* a tiny image loader */
  1777. function imgLoader(el){
  1778. if($(el).hasClass(classes[2])){doUpd(); return;}
  1779. var img=new Image();
  1780. function createDelegate(contextObject,delegateMethod){
  1781. return function(){return delegateMethod.apply(contextObject,arguments);}
  1782. }
  1783. function imgOnLoad(){
  1784. this.onload=null;
  1785. $(el).addClass(classes[2]);
  1786. doUpd(2);
  1787. }
  1788. img.onload=createDelegate(img,imgOnLoad);
  1789. img.src=el.src;
  1790. }
  1791. /* returns the total height and width sum of all elements matching the selector */
  1792. function sizesSum(){
  1793. if(o.advanced.updateOnSelectorChange===true){o.advanced.updateOnSelectorChange="*";}
  1794. var total=0,sel=mCSB_container.find(o.advanced.updateOnSelectorChange);
  1795. if(o.advanced.updateOnSelectorChange && sel.length>0){sel.each(function(){total+=this.offsetHeight+this.offsetWidth;});}
  1796. return total;
  1797. }
  1798. /* calls the update method */
  1799. function doUpd(cb){
  1800. clearTimeout(mCSB_container[0].autoUpdate);
  1801. methods.update.call(null,$this[0],cb);
  1802. }
  1803. },
  1804. /* -------------------- */
  1805. /* snaps scrolling to a multiple of a pixels number */
  1806. _snapAmount=function(to,amount,offset){
  1807. return (Math.round(to/amount)*amount-offset);
  1808. },
  1809. /* -------------------- */
  1810. /* stops content and scrollbar animations */
  1811. _stop=function(el){
  1812. var d=el.data(pluginPfx),
  1813. sel=$("#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal");
  1814. sel.each(function(){
  1815. _stopTween.call(this);
  1816. });
  1817. },
  1818. /* -------------------- */
  1819. /*
  1820. ANIMATES CONTENT
  1821. This is where the actual scrolling happens
  1822. */
  1823. _scrollTo=function(el,to,options){
  1824. var d=el.data(pluginPfx),o=d.opt,
  1825. defaults={
  1826. trigger:"internal",
  1827. dir:"y",
  1828. scrollEasing:"mcsEaseOut",
  1829. drag:false,
  1830. dur:o.scrollInertia,
  1831. overwrite:"all",
  1832. callbacks:true,
  1833. onStart:true,
  1834. onUpdate:true,
  1835. onComplete:true
  1836. },
  1837. options=$.extend(defaults,options),
  1838. dur=[options.dur,(options.drag ? 0 : options.dur)],
  1839. mCustomScrollBox=$("#mCSB_"+d.idx),
  1840. mCSB_container=$("#mCSB_"+d.idx+"_container"),
  1841. wrapper=mCSB_container.parent(),
  1842. totalScrollOffsets=o.callbacks.onTotalScrollOffset ? _arr.call(el,o.callbacks.onTotalScrollOffset) : [0,0],
  1843. totalScrollBackOffsets=o.callbacks.onTotalScrollBackOffset ? _arr.call(el,o.callbacks.onTotalScrollBackOffset) : [0,0];
  1844. d.trigger=options.trigger;
  1845. if(wrapper.scrollTop()!==0 || wrapper.scrollLeft()!==0){ /* always reset scrollTop/Left */
  1846. $(".mCSB_"+d.idx+"_scrollbar").css("visibility","visible");
  1847. wrapper.scrollTop(0).scrollLeft(0);
  1848. }
  1849. if(to==="_resetY" && !d.contentReset.y){
  1850. /* callbacks: onOverflowYNone */
  1851. if(_cb("onOverflowYNone")){o.callbacks.onOverflowYNone.call(el[0]);}
  1852. d.contentReset.y=1;
  1853. }
  1854. if(to==="_resetX" && !d.contentReset.x){
  1855. /* callbacks: onOverflowXNone */
  1856. if(_cb("onOverflowXNone")){o.callbacks.onOverflowXNone.call(el[0]);}
  1857. d.contentReset.x=1;
  1858. }
  1859. if(to==="_resetY" || to==="_resetX"){return;}
  1860. if((d.contentReset.y || !el[0].mcs) && d.overflowed[0]){
  1861. /* callbacks: onOverflowY */
  1862. if(_cb("onOverflowY")){o.callbacks.onOverflowY.call(el[0]);}
  1863. d.contentReset.x=null;
  1864. }
  1865. if((d.contentReset.x || !el[0].mcs) && d.overflowed[1]){
  1866. /* callbacks: onOverflowX */
  1867. if(_cb("onOverflowX")){o.callbacks.onOverflowX.call(el[0]);}
  1868. d.contentReset.x=null;
  1869. }
  1870. if(o.snapAmount){ /* scrolling snapping */
  1871. var snapAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : options.dir==="x" ? o.snapAmount[1] : o.snapAmount[0];
  1872. to=_snapAmount(to,snapAmount,o.snapOffset);
  1873. }
  1874. switch(options.dir){
  1875. case "x":
  1876. var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_horizontal"),
  1877. property="left",
  1878. contentPos=mCSB_container[0].offsetLeft,
  1879. limit=[
  1880. mCustomScrollBox.width()-mCSB_container.outerWidth(false),
  1881. mCSB_dragger.parent().width()-mCSB_dragger.width()
  1882. ],
  1883. scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.x)],
  1884. tso=totalScrollOffsets[1],
  1885. tsbo=totalScrollBackOffsets[1],
  1886. totalScrollOffset=tso>0 ? tso/d.scrollRatio.x : 0,
  1887. totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.x : 0;
  1888. break;
  1889. case "y":
  1890. var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_vertical"),
  1891. property="top",
  1892. contentPos=mCSB_container[0].offsetTop,
  1893. limit=[
  1894. mCustomScrollBox.height()-mCSB_container.outerHeight(false),
  1895. mCSB_dragger.parent().height()-mCSB_dragger.height()
  1896. ],
  1897. scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.y)],
  1898. tso=totalScrollOffsets[0],
  1899. tsbo=totalScrollBackOffsets[0],
  1900. totalScrollOffset=tso>0 ? tso/d.scrollRatio.y : 0,
  1901. totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.y : 0;
  1902. break;
  1903. }
  1904. if(scrollTo[1]<0 || (scrollTo[0]===0 && scrollTo[1]===0)){
  1905. scrollTo=[0,0];
  1906. }else if(scrollTo[1]>=limit[1]){
  1907. scrollTo=[limit[0],limit[1]];
  1908. }else{
  1909. scrollTo[0]=-scrollTo[0];
  1910. }
  1911. if(!el[0].mcs){
  1912. _mcs(); /* init mcs object (once) to make it available before callbacks */
  1913. if(_cb("onInit")){o.callbacks.onInit.call(el[0]);} /* callbacks: onInit */
  1914. }
  1915. clearTimeout(mCSB_container[0].onCompleteTimeout);
  1916. _tweenTo(mCSB_dragger[0],property,Math.round(scrollTo[1]),dur[1],options.scrollEasing);
  1917. if(!d.tweenRunning && ((contentPos===0 && scrollTo[0]>=0) || (contentPos===limit[0] && scrollTo[0]<=limit[0]))){return;}
  1918. _tweenTo(mCSB_container[0],property,Math.round(scrollTo[0]),dur[0],options.scrollEasing,options.overwrite,{
  1919. onStart:function(){
  1920. if(options.callbacks && options.onStart && !d.tweenRunning){
  1921. /* callbacks: onScrollStart */
  1922. if(_cb("onScrollStart")){_mcs(); o.callbacks.onScrollStart.call(el[0]);}
  1923. d.tweenRunning=true;
  1924. _onDragClasses(mCSB_dragger);
  1925. d.cbOffsets=_cbOffsets();
  1926. }
  1927. },onUpdate:function(){
  1928. if(options.callbacks && options.onUpdate){
  1929. /* callbacks: whileScrolling */
  1930. if(_cb("whileScrolling")){_mcs(); o.callbacks.whileScrolling.call(el[0]);}
  1931. }
  1932. },onComplete:function(){
  1933. if(options.callbacks && options.onComplete){
  1934. if(o.axis==="yx"){clearTimeout(mCSB_container[0].onCompleteTimeout);}
  1935. var t=mCSB_container[0].idleTimer || 0;
  1936. mCSB_container[0].onCompleteTimeout=setTimeout(function(){
  1937. /* callbacks: onScroll, onTotalScroll, onTotalScrollBack */
  1938. if(_cb("onScroll")){_mcs(); o.callbacks.onScroll.call(el[0]);}
  1939. if(_cb("onTotalScroll") && scrollTo[1]>=limit[1]-totalScrollOffset && d.cbOffsets[0]){_mcs(); o.callbacks.onTotalScroll.call(el[0]);}
  1940. if(_cb("onTotalScrollBack") && scrollTo[1]<=totalScrollBackOffset && d.cbOffsets[1]){_mcs(); o.callbacks.onTotalScrollBack.call(el[0]);}
  1941. d.tweenRunning=false;
  1942. mCSB_container[0].idleTimer=0;
  1943. _onDragClasses(mCSB_dragger,"hide");
  1944. },t);
  1945. }
  1946. }
  1947. });
  1948. /* checks if callback function exists */
  1949. function _cb(cb){
  1950. return d && o.callbacks[cb] && typeof o.callbacks[cb]==="function";
  1951. }
  1952. /* checks whether callback offsets always trigger */
  1953. function _cbOffsets(){
  1954. return [o.callbacks.alwaysTriggerOffsets || contentPos>=limit[0]+tso,o.callbacks.alwaysTriggerOffsets || contentPos<=-tsbo];
  1955. }
  1956. /*
  1957. populates object with useful values for the user
  1958. values:
  1959. content: this.mcs.content
  1960. content top position: this.mcs.top
  1961. content left position: this.mcs.left
  1962. dragger top position: this.mcs.draggerTop
  1963. dragger left position: this.mcs.draggerLeft
  1964. scrolling y percentage: this.mcs.topPct
  1965. scrolling x percentage: this.mcs.leftPct
  1966. scrolling direction: this.mcs.direction
  1967. */
  1968. function _mcs(){
  1969. var cp=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft], /* content position */
  1970. dp=[mCSB_dragger[0].offsetTop,mCSB_dragger[0].offsetLeft], /* dragger position */
  1971. cl=[mCSB_container.outerHeight(false),mCSB_container.outerWidth(false)], /* content length */
  1972. pl=[mCustomScrollBox.height(),mCustomScrollBox.width()]; /* content parent length */
  1973. el[0].mcs={
  1974. content:mCSB_container, /* original content wrapper as jquery object */
  1975. top:cp[0],left:cp[1],draggerTop:dp[0],draggerLeft:dp[1],
  1976. topPct:Math.round((100*Math.abs(cp[0]))/(Math.abs(cl[0])-pl[0])),leftPct:Math.round((100*Math.abs(cp[1]))/(Math.abs(cl[1])-pl[1])),
  1977. direction:options.dir
  1978. };
  1979. /*
  1980. this refers to the original element containing the scrollbar(s)
  1981. usage: this.mcs.top, this.mcs.leftPct etc.
  1982. */
  1983. }
  1984. },
  1985. /* -------------------- */
  1986. /*
  1987. CUSTOM JAVASCRIPT ANIMATION TWEEN
  1988. Lighter and faster than jquery animate() and css transitions
  1989. Animates top/left properties and includes easings
  1990. */
  1991. _tweenTo=function(el,prop,to,duration,easing,overwrite,callbacks){
  1992. if(!el._mTween){el._mTween={top:{},left:{}};}
  1993. var callbacks=callbacks || {},
  1994. onStart=callbacks.onStart || function(){},onUpdate=callbacks.onUpdate || function(){},onComplete=callbacks.onComplete || function(){},
  1995. startTime=_getTime(),_delay,progress=0,from=el.offsetTop,elStyle=el.style,_request,tobj=el._mTween[prop];
  1996. if(prop==="left"){from=el.offsetLeft;}
  1997. var diff=to-from;
  1998. tobj.stop=0;
  1999. if(overwrite!=="none"){_cancelTween();}
  2000. _startTween();
  2001. function _step(){
  2002. if(tobj.stop){return;}
  2003. if(!progress){onStart.call();}
  2004. progress=_getTime()-startTime;
  2005. _tween();
  2006. if(progress>=tobj.time){
  2007. tobj.time=(progress>tobj.time) ? progress+_delay-(progress-tobj.time) : progress+_delay-1;
  2008. if(tobj.time<progress+1){tobj.time=progress+1;}
  2009. }
  2010. if(tobj.time<duration){tobj.id=_request(_step);}else{onComplete.call();}
  2011. }
  2012. function _tween(){
  2013. if(duration>0){
  2014. tobj.currVal=_ease(tobj.time,from,diff,duration,easing);
  2015. elStyle[prop]=Math.round(tobj.currVal)+"px";
  2016. }else{
  2017. elStyle[prop]=to+"px";
  2018. }
  2019. onUpdate.call();
  2020. }
  2021. function _startTween(){
  2022. _delay=1000/60;
  2023. tobj.time=progress+_delay;
  2024. _request=(!window.requestAnimationFrame) ? function(f){_tween(); return setTimeout(f,0.01);} : window.requestAnimationFrame;
  2025. tobj.id=_request(_step);
  2026. }
  2027. function _cancelTween(){
  2028. if(tobj.id==null){return;}
  2029. if(!window.requestAnimationFrame){clearTimeout(tobj.id);
  2030. }else{window.cancelAnimationFrame(tobj.id);}
  2031. tobj.id=null;
  2032. }
  2033. function _ease(t,b,c,d,type){
  2034. switch(type){
  2035. case "linear": case "mcsLinear":
  2036. return c*t/d + b;
  2037. break;
  2038. case "mcsLinearOut":
  2039. t/=d; t--; return c * Math.sqrt(1 - t*t) + b;
  2040. break;
  2041. case "easeInOutSmooth":
  2042. t/=d/2;
  2043. if(t<1) return c/2*t*t + b;
  2044. t--;
  2045. return -c/2 * (t*(t-2) - 1) + b;
  2046. break;
  2047. case "easeInOutStrong":
  2048. t/=d/2;
  2049. if(t<1) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b;
  2050. t--;
  2051. return c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b;
  2052. break;
  2053. case "easeInOut": case "mcsEaseInOut":
  2054. t/=d/2;
  2055. if(t<1) return c/2*t*t*t + b;
  2056. t-=2;
  2057. return c/2*(t*t*t + 2) + b;
  2058. break;
  2059. case "easeOutSmooth":
  2060. t/=d; t--;
  2061. return -c * (t*t*t*t - 1) + b;
  2062. break;
  2063. case "easeOutStrong":
  2064. return c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b;
  2065. break;
  2066. case "easeOut": case "mcsEaseOut": default:
  2067. var ts=(t/=d)*t,tc=ts*t;
  2068. return b+c*(0.499999999999997*tc*ts + -2.5*ts*ts + 5.5*tc + -6.5*ts + 4*t);
  2069. }
  2070. }
  2071. },
  2072. /* -------------------- */
  2073. /* returns current time */
  2074. _getTime=function(){
  2075. if(window.performance && window.performance.now){
  2076. return window.performance.now();
  2077. }else{
  2078. if(window.performance && window.performance.webkitNow){
  2079. return window.performance.webkitNow();
  2080. }else{
  2081. if(Date.now){return Date.now();}else{return new Date().getTime();}
  2082. }
  2083. }
  2084. },
  2085. /* -------------------- */
  2086. /* stops a tween */
  2087. _stopTween=function(){
  2088. var el=this;
  2089. if(!el._mTween){el._mTween={top:{},left:{}};}
  2090. var props=["top","left"];
  2091. for(var i=0; i<props.length; i++){
  2092. var prop=props[i];
  2093. if(el._mTween[prop].id){
  2094. if(!window.requestAnimationFrame){clearTimeout(el._mTween[prop].id);
  2095. }else{window.cancelAnimationFrame(el._mTween[prop].id);}
  2096. el._mTween[prop].id=null;
  2097. el._mTween[prop].stop=1;
  2098. }
  2099. }
  2100. },
  2101. /* -------------------- */
  2102. /* deletes a property (avoiding the exception thrown by IE) */
  2103. _delete=function(c,m){
  2104. try{delete c[m];}catch(e){c[m]=null;}
  2105. },
  2106. /* -------------------- */
  2107. /* detects left mouse button */
  2108. _mouseBtnLeft=function(e){
  2109. return !(e.which && e.which!==1);
  2110. },
  2111. /* -------------------- */
  2112. /* detects if pointer type event is touch */
  2113. _pointerTouch=function(e){
  2114. var t=e.originalEvent.pointerType;
  2115. return !(t && t!=="touch" && t!==2);
  2116. },
  2117. /* -------------------- */
  2118. /* checks if value is numeric */
  2119. _isNumeric=function(val){
  2120. return !isNaN(parseFloat(val)) && isFinite(val);
  2121. },
  2122. /* -------------------- */
  2123. /* returns element position according to content */
  2124. _childPos=function(el){
  2125. var p=el.parents(".mCSB_container");
  2126. return [el.offset().top-p.offset().top,el.offset().left-p.offset().left];
  2127. },
  2128. /* -------------------- */
  2129. /* checks if browser tab is hidden/inactive via Page Visibility API */
  2130. _isTabHidden=function(){
  2131. var prop=_getHiddenProp();
  2132. if(!prop) return false;
  2133. return document[prop];
  2134. function _getHiddenProp(){
  2135. var pfx=["webkit","moz","ms","o"];
  2136. if("hidden" in document) return "hidden"; //natively supported
  2137. for(var i=0; i<pfx.length; i++){ //prefixed
  2138. if((pfx[i]+"Hidden") in document)
  2139. return pfx[i]+"Hidden";
  2140. }
  2141. return null; //not supported
  2142. }
  2143. };
  2144. /* -------------------- */
  2145. /*
  2146. ----------------------------------------
  2147. PLUGIN SETUP
  2148. ----------------------------------------
  2149. */
  2150. /* plugin constructor functions */
  2151. $.fn[pluginNS]=function(method){ /* usage: $(selector).mCustomScrollbar(); */
  2152. if(methods[method]){
  2153. return methods[method].apply(this,Array.prototype.slice.call(arguments,1));
  2154. }else if(typeof method==="object" || !method){
  2155. return methods.init.apply(this,arguments);
  2156. }else{
  2157. $.error("Method "+method+" does not exist");
  2158. }
  2159. };
  2160. $[pluginNS]=function(method){ /* usage: $.mCustomScrollbar(); */
  2161. if(methods[method]){
  2162. return methods[method].apply(this,Array.prototype.slice.call(arguments,1));
  2163. }else if(typeof method==="object" || !method){
  2164. return methods.init.apply(this,arguments);
  2165. }else{
  2166. $.error("Method "+method+" does not exist");
  2167. }
  2168. };
  2169. /*
  2170. allow setting plugin default options.
  2171. usage: $.mCustomScrollbar.defaults.scrollInertia=500;
  2172. to apply any changed default options on default selectors (below), use inside document ready fn
  2173. e.g.: $(document).ready(function(){ $.mCustomScrollbar.defaults.scrollInertia=500; });
  2174. */
  2175. $[pluginNS].defaults=defaults;
  2176. /*
  2177. add window object (window.mCustomScrollbar)
  2178. usage: if(window.mCustomScrollbar){console.log("custom scrollbar plugin loaded");}
  2179. */
  2180. window[pluginNS]=true;
  2181. $(window).bind("load",function(){
  2182. $(defaultSelector)[pluginNS](); /* add scrollbars automatically on default selector */
  2183. /* extend jQuery expressions */
  2184. $.extend($.expr[":"],{
  2185. /* checks if element is within scrollable viewport */
  2186. mcsInView:$.expr[":"].mcsInView || function(el){
  2187. var $el=$(el),content=$el.parents(".mCSB_container"),wrapper,cPos;
  2188. if(!content.length){return;}
  2189. wrapper=content.parent();
  2190. cPos=[content[0].offsetTop,content[0].offsetLeft];
  2191. return cPos[0]+_childPos($el)[0]>=0 && cPos[0]+_childPos($el)[0]<wrapper.height()-$el.outerHeight(false) &&
  2192. cPos[1]+_childPos($el)[1]>=0 && cPos[1]+_childPos($el)[1]<wrapper.width()-$el.outerWidth(false);
  2193. },
  2194. /* checks if element or part of element is in view of scrollable viewport */
  2195. mcsInSight:$.expr[":"].mcsInSight || function(el,i,m){
  2196. var $el=$(el),elD,content=$el.parents(".mCSB_container"),wrapperView,pos,wrapperViewPct,
  2197. pctVals=m[3]==="exact" ? [[1,0],[1,0]] : [[0.9,0.1],[0.6,0.4]];
  2198. if(!content.length){return;}
  2199. elD=[$el.outerHeight(false),$el.outerWidth(false)];
  2200. pos=[content[0].offsetTop+_childPos($el)[0],content[0].offsetLeft+_childPos($el)[1]];
  2201. wrapperView=[content.parent()[0].offsetHeight,content.parent()[0].offsetWidth];
  2202. wrapperViewPct=[elD[0]<wrapperView[0] ? pctVals[0] : pctVals[1],elD[1]<wrapperView[1] ? pctVals[0] : pctVals[1]];
  2203. return pos[0]-(wrapperView[0]*wrapperViewPct[0][0])<0 && pos[0]+elD[0]-(wrapperView[0]*wrapperViewPct[0][1])>=0 &&
  2204. pos[1]-(wrapperView[1]*wrapperViewPct[1][0])<0 && pos[1]+elD[1]-(wrapperView[1]*wrapperViewPct[1][1])>=0;
  2205. },
  2206. /* checks if element is overflowed having visible scrollbar(s) */
  2207. mcsOverflow:$.expr[":"].mcsOverflow || function(el){
  2208. var d=$(el).data(pluginPfx);
  2209. if(!d){return;}
  2210. return d.overflowed[0] || d.overflowed[1];
  2211. }
  2212. });
  2213. });
  2214. }))}));