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