jquery.nicescroll.js 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721
  1. /* jquery.nicescroll
  2. -- version 3.7.2
  3. -- copyright 2017-06-18 InuYaksa*2017
  4. -- licensed under the MIT
  5. --
  6. -- https://nicescroll.areaaperta.com/
  7. -- https://github.com/inuyaksa/jquery.nicescroll
  8. --
  9. */
  10. (function (factory) {
  11. if (typeof define === 'function' && define.amd) {
  12. // AMD. Register as anonymous module.
  13. define(['jquery'], factory);
  14. } else if (typeof exports === 'object') {
  15. // Node/CommonJS.
  16. module.exports = factory(require('jquery'));
  17. } else {
  18. // Browser globals.
  19. factory(jQuery);
  20. }
  21. }(function (jQuery) {
  22. "use strict";
  23. // globals
  24. var domfocus = false;
  25. var mousefocus = false;
  26. var tabindexcounter = 0;
  27. var ascrailcounter = 2000;
  28. var globalmaxzindex = 0;
  29. var $ = jQuery; // sandbox
  30. var document = document;
  31. var $window = $(window);
  32. // http://stackoverflow.com/questions/2161159/get-script-path
  33. function getScriptPath() {
  34. var scripts = document.currentScript || (function () { var s = document.getElementsByTagName('script'); return (s.length) ? s[s.length - 1] : false; })();
  35. var path = scripts ? scripts.src.split('?')[0] : '';
  36. return (path.split('/').length > 0) ? path.split('/').slice(0, -1).join('/') + '/' : '';
  37. }
  38. // based on code by Paul Irish https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  39. var setAnimationFrame = (function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || false; })();
  40. var clearAnimationFrame = (function () { return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || false; })();
  41. if (!setAnimationFrame) {
  42. var anilasttime = 0;
  43. setAnimationFrame = function (callback, element) {
  44. var currTime = new Date().getTime();
  45. var timeToCall = Math.max(0, 16 - (currTime - anilasttime));
  46. var id = window.setTimeout(function () { callback(currTime + timeToCall); },
  47. timeToCall);
  48. anilasttime = currTime + timeToCall;
  49. return id;
  50. };
  51. clearAnimationFrame = function (id) {
  52. window.clearTimeout(id);
  53. };
  54. } else {
  55. if (!window.cancelAnimationFrame) clearAnimationFrame = function (id) { };
  56. }
  57. var ClsMutationObserver = window.MutationObserver || window.WebKitMutationObserver || false;
  58. var now = Date.now || function () { return new Date().getTime(); };
  59. var _globaloptions = {
  60. zindex: "auto",
  61. cursoropacitymin: 0,
  62. cursoropacitymax: 1,
  63. cursorcolor: "#424242",
  64. cursorwidth: "6px",
  65. cursorborder: "1px solid #fff",
  66. cursorborderradius: "5px",
  67. scrollspeed: 60,
  68. mousescrollstep: 8 * 3,
  69. touchbehavior: false, // deprecated
  70. emulatetouch: false, // replacing touchbehavior
  71. hwacceleration: true,
  72. usetransition: true,
  73. boxzoom: false,
  74. dblclickzoom: true,
  75. gesturezoom: true,
  76. grabcursorenabled: true,
  77. autohidemode: true,
  78. background: "",
  79. iframeautoresize: true,
  80. cursorminheight: 32,
  81. preservenativescrolling: true,
  82. railoffset: false,
  83. railhoffset: false,
  84. bouncescroll: true,
  85. spacebarenabled: true,
  86. railpadding: {
  87. top: 0,
  88. right: 0,
  89. left: 0,
  90. bottom: 0
  91. },
  92. disableoutline: true,
  93. horizrailenabled: true,
  94. railalign: "right",
  95. railvalign: "bottom",
  96. enabletranslate3d: true,
  97. enablemousewheel: true,
  98. enablekeyboard: true,
  99. smoothscroll: true,
  100. sensitiverail: true,
  101. enablemouselockapi: true,
  102. // cursormaxheight:false,
  103. cursorfixedheight: false,
  104. directionlockdeadzone: 6,
  105. hidecursordelay: 400,
  106. nativeparentscrolling: true,
  107. enablescrollonselection: true,
  108. overflowx: true,
  109. overflowy: true,
  110. cursordragspeed: 0.3,
  111. rtlmode: "auto",
  112. cursordragontouch: false,
  113. oneaxismousemode: "auto",
  114. scriptpath: getScriptPath(),
  115. preventmultitouchscrolling: true,
  116. disablemutationobserver: false,
  117. enableobserver: true,
  118. scrollbarid: false
  119. };
  120. var browserdetected = false;
  121. var getBrowserDetection = function () {
  122. if (browserdetected) return browserdetected;
  123. var _el = document.createElement('DIV'),
  124. _style = _el.style,
  125. _agent = navigator.userAgent,
  126. _platform = navigator.platform,
  127. d = {};
  128. d.haspointerlock = "pointerLockElement" in document || "webkitPointerLockElement" in document || "mozPointerLockElement" in document;
  129. d.isopera = ("opera" in window); // 12-
  130. d.isopera12 = (d.isopera && ("getUserMedia" in navigator));
  131. d.isoperamini = (Object.prototype.toString.call(window.operamini) === "[object OperaMini]");
  132. d.isie = (("all" in document) && ("attachEvent" in _el) && !d.isopera); //IE10-
  133. d.isieold = (d.isie && !("msInterpolationMode" in _style)); // IE6 and older
  134. d.isie7 = d.isie && !d.isieold && (!("documentMode" in document) || (document.documentMode === 7));
  135. d.isie8 = d.isie && ("documentMode" in document) && (document.documentMode === 8);
  136. d.isie9 = d.isie && ("performance" in window) && (document.documentMode === 9);
  137. d.isie10 = d.isie && ("performance" in window) && (document.documentMode === 10);
  138. d.isie11 = ("msRequestFullscreen" in _el) && (document.documentMode >= 11); // IE11+
  139. d.ismsedge = ("msCredentials" in window); // MS Edge 14+
  140. d.ismozilla = ("MozAppearance" in _style);
  141. d.iswebkit = !d.ismsedge && ("WebkitAppearance" in _style);
  142. d.ischrome = d.iswebkit && ("chrome" in window);
  143. d.ischrome38 = (d.ischrome && ("touchAction" in _style)); // behavior changed in touch emulation
  144. d.ischrome22 = (!d.ischrome38) && (d.ischrome && d.haspointerlock);
  145. d.ischrome26 = (!d.ischrome38) && (d.ischrome && ("transition" in _style)); // issue with transform detection (maintain prefix)
  146. d.cantouch = ("ontouchstart" in document.documentElement) || ("ontouchstart" in window); // with detection for Chrome Touch Emulation
  147. d.hasw3ctouch = (window.PointerEvent || false) && ((navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); //IE11 pointer events, following W3C Pointer Events spec
  148. d.hasmstouch = (!d.hasw3ctouch) && (window.MSPointerEvent || false); // IE10 pointer events
  149. d.ismac = /^mac$/i.test(_platform);
  150. d.isios = d.cantouch && /iphone|ipad|ipod/i.test(_platform);
  151. d.isios4 = d.isios && !("seal" in Object);
  152. d.isios7 = d.isios && ("webkitHidden" in document); //iOS 7+
  153. d.isios8 = d.isios && ("hidden" in document); //iOS 8+
  154. d.isios10 = d.isios && window.Proxy; //iOS 10+
  155. d.isandroid = (/android/i.test(_agent));
  156. d.haseventlistener = ("addEventListener" in _el);
  157. d.trstyle = false;
  158. d.hastransform = false;
  159. d.hastranslate3d = false;
  160. d.transitionstyle = false;
  161. d.hastransition = false;
  162. d.transitionend = false;
  163. d.trstyle = "transform";
  164. d.hastransform = ("transform" in _style) || (function () {
  165. var check = ['msTransform', 'webkitTransform', 'MozTransform', 'OTransform'];
  166. for (var a = 0, c = check.length; a < c; a++) {
  167. if (_style[check[a]] !== undefined) {
  168. d.trstyle = check[a];
  169. break;
  170. }
  171. }
  172. d.hastransform = (!!d.trstyle);
  173. })();
  174. if (d.hastransform) {
  175. _style[d.trstyle] = "translate3d(1px,2px,3px)";
  176. d.hastranslate3d = /translate3d/.test(_style[d.trstyle]);
  177. }
  178. d.transitionstyle = "transition";
  179. d.prefixstyle = '';
  180. d.transitionend = "transitionend";
  181. d.hastransition = ("transition" in _style) || (function () {
  182. d.transitionend = false;
  183. var check = ['webkitTransition', 'msTransition', 'MozTransition', 'OTransition', 'OTransition', 'KhtmlTransition'];
  184. var prefix = ['-webkit-', '-ms-', '-moz-', '-o-', '-o', '-khtml-'];
  185. var evs = ['webkitTransitionEnd', 'msTransitionEnd', 'transitionend', 'otransitionend', 'oTransitionEnd', 'KhtmlTransitionEnd'];
  186. for (var a = 0, c = check.length; a < c; a++) {
  187. if (check[a] in _style) {
  188. d.transitionstyle = check[a];
  189. d.prefixstyle = prefix[a];
  190. d.transitionend = evs[a];
  191. break;
  192. }
  193. }
  194. if (d.ischrome26) { // always use prefix
  195. d.prefixstyle = prefix[1];
  196. }
  197. d.hastransition = (d.transitionstyle);
  198. })();
  199. function detectCursorGrab() {
  200. var lst = ['grab', '-webkit-grab', '-moz-grab'];
  201. if ((d.ischrome && !d.ischrome38) || d.isie) lst = []; // force setting for IE returns false positive and chrome cursor bug
  202. for (var a = 0, l = lst.length; a < l; a++) {
  203. var p = lst[a];
  204. _style.cursor = p;
  205. if (_style.cursor == p) return p;
  206. }
  207. return 'url(https://cdnjs.cloudflare.com/ajax/libs/slider-pro/1.3.0/css/images/openhand.cur),n-resize'; // thanks to https://cdnjs.com/ for the openhand cursor!
  208. }
  209. d.cursorgrabvalue = detectCursorGrab();
  210. d.hasmousecapture = ("setCapture" in _el);
  211. d.hasMutationObserver = (ClsMutationObserver !== false);
  212. _el = null; //memory released
  213. browserdetected = d;
  214. return d;
  215. };
  216. var NiceScrollClass = function (myopt, me) {
  217. var self = this;
  218. this.version = '3.7.2';
  219. this.name = 'nicescroll';
  220. this.me = me;
  221. var $body = $("body");
  222. this.opt = {
  223. doc: $body,
  224. win: false
  225. };
  226. $.extend(this.opt, _globaloptions); // clone opts
  227. // Options for internal use
  228. this.opt.snapbackspeed = 80;
  229. if (myopt || false) {
  230. for (var a in self.opt) {
  231. if (myopt[a] !== undefined) self.opt[a] = myopt[a];
  232. }
  233. }
  234. if (self.opt.disablemutationobserver) ClsMutationObserver = false;
  235. this.doc = self.opt.doc;
  236. this.iddoc = (this.doc && this.doc[0]) ? this.doc[0].id || '' : '';
  237. this.ispage = /^BODY|HTML/.test((self.opt.win) ? self.opt.win[0].nodeName : this.doc[0].nodeName);
  238. this.haswrapper = (self.opt.win !== false);
  239. this.win = self.opt.win || (this.ispage ? $window : this.doc);
  240. this.docscroll = (this.ispage && !this.haswrapper) ? $window : this.win;
  241. this.body = $body;
  242. this.viewport = false;
  243. this.isfixed = false;
  244. this.iframe = false;
  245. this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
  246. this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
  247. this.forcescreen = false; //force to use screen position on events
  248. this.canshowonmouseevent = (self.opt.autohidemode != "scroll");
  249. // Events jump table
  250. this.onmousedown = false;
  251. this.onmouseup = false;
  252. this.onmousemove = false;
  253. this.onmousewheel = false;
  254. this.onkeypress = false;
  255. this.ongesturezoom = false;
  256. this.onclick = false;
  257. // Nicescroll custom events
  258. this.onscrollstart = false;
  259. this.onscrollend = false;
  260. this.onscrollcancel = false;
  261. this.onzoomin = false;
  262. this.onzoomout = false;
  263. // Let's start!
  264. this.view = false;
  265. this.page = false;
  266. this.scroll = {
  267. x: 0,
  268. y: 0
  269. };
  270. this.scrollratio = {
  271. x: 0,
  272. y: 0
  273. };
  274. this.cursorheight = 20;
  275. this.scrollvaluemax = 0;
  276. // http://dev.w3.org/csswg/css-writing-modes-3/#logical-to-physical
  277. // http://dev.w3.org/csswg/css-writing-modes-3/#svg-writing-mode
  278. if (this.opt.rtlmode == "auto") {
  279. var target = this.win[0] == window ? this.body : this.win;
  280. var writingMode = target.css("writing-mode") || target.css("-webkit-writing-mode") || target.css("-ms-writing-mode") || target.css("-moz-writing-mode");
  281. if (writingMode == "horizontal-tb" || writingMode == "lr-tb" || writingMode == "") {
  282. this.isrtlmode = (target.css("direction") == "rtl");
  283. this.isvertical = false;
  284. } else {
  285. this.isrtlmode = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl" || writingMode == "rl-tb");
  286. this.isvertical = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl");
  287. }
  288. } else {
  289. this.isrtlmode = (this.opt.rtlmode === true);
  290. this.isvertical = false;
  291. }
  292. // this.checkrtlmode = false;
  293. this.scrollrunning = false;
  294. this.scrollmom = false;
  295. this.observer = false; // observer div changes
  296. this.observerremover = false; // observer on parent for remove detection
  297. this.observerbody = false; // observer on body for position change
  298. if (self.opt.scrollbarid === false) {
  299. do {
  300. this.id = "ascrail" + (ascrailcounter++);
  301. } while (document.getElementById(this.id));
  302. } else {
  303. this.id = self.opt.scrollbarid;
  304. }
  305. this.rail = false;
  306. this.cursor = false;
  307. this.cursorfreezed = false;
  308. this.selectiondrag = false;
  309. this.zoom = false;
  310. this.zoomactive = false;
  311. this.hasfocus = false;
  312. this.hasmousefocus = false;
  313. this.visibility = true;
  314. this.railslocked = false; // locked by resize
  315. this.locked = false; // prevent lost of locked status sets by user
  316. this.hidden = false; // rails always hidden
  317. this.cursoractive = true; // user can interact with cursors
  318. this.wheelprevented = false; //prevent mousewheel event
  319. this.overflowx = self.opt.overflowx;
  320. this.overflowy = self.opt.overflowy;
  321. this.nativescrollingarea = false;
  322. this.checkarea = 0;
  323. this.events = []; // event list for unbind
  324. this.saved = {}; // style saved
  325. this.delaylist = {};
  326. this.synclist = {};
  327. this.lastdeltax = 0;
  328. this.lastdeltay = 0;
  329. this.detected = getBrowserDetection();
  330. var cap = $.extend({}, this.detected);
  331. this.canhwscroll = (cap.hastransform && self.opt.hwacceleration);
  332. this.ishwscroll = (this.canhwscroll && self.haswrapper);
  333. if (!this.isrtlmode) {
  334. this.hasreversehr = false;
  335. } else if (this.isvertical) { // RTL mode with reverse horizontal axis
  336. this.hasreversehr = !(cap.iswebkit || cap.isie || cap.isie11);
  337. } else {
  338. this.hasreversehr = !(cap.iswebkit || (cap.isie && !cap.isie10 && !cap.isie11));
  339. }
  340. this.istouchcapable = false; // desktop devices with touch screen support
  341. //## Check WebKit-based desktop with touch support
  342. //## + Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
  343. if (!cap.cantouch && (cap.hasw3ctouch || cap.hasmstouch)) { // desktop device with multiple input
  344. this.istouchcapable = true;
  345. } else if (cap.cantouch && !cap.isios && !cap.isandroid && (cap.iswebkit || cap.ismozilla)) {
  346. this.istouchcapable = true;
  347. // cap.cantouch = false; // parse normal desktop events
  348. }
  349. //## disable MouseLock API on user request
  350. if (!self.opt.enablemouselockapi) {
  351. cap.hasmousecapture = false;
  352. cap.haspointerlock = false;
  353. }
  354. this.debounced = function (name, fn, tm) {
  355. if (!self) return;
  356. var dd = self.delaylist[name] || false;
  357. if (!dd) {
  358. //fixed loop call fn:checkSelectionScroll
  359. //fn.call(self);
  360. self.delaylist[name] = {
  361. h: setAnimationFrame(function () {
  362. self.delaylist[name].fn.call(self);
  363. self.delaylist[name] = false;
  364. }, tm)
  365. };
  366. fn.call(self);
  367. }
  368. self.delaylist[name].fn = fn;
  369. };
  370. var _onsync = false;
  371. this.synched = function (name, fn) {
  372. function requestSync() {
  373. if (_onsync) return;
  374. setAnimationFrame(function () {
  375. if (!self) return;
  376. _onsync = false;
  377. for (var nn in self.synclist) {
  378. var fn = self.synclist[nn];
  379. if (fn) fn.call(self);
  380. self.synclist[nn] = false;
  381. }
  382. });
  383. _onsync = true;
  384. }
  385. self.synclist[name] = fn;
  386. requestSync();
  387. return name;
  388. };
  389. this.unsynched = function (name) {
  390. if (self.synclist[name]) self.synclist[name] = false;
  391. };
  392. this.css = function (el, pars) { // save & set
  393. for (var n in pars) {
  394. self.saved.css.push([el, n, el.css(n)]);
  395. el.css(n, pars[n]);
  396. }
  397. };
  398. this.scrollTop = function (val) {
  399. return (val === undefined) ? self.getScrollTop() : self.setScrollTop(val);
  400. };
  401. this.scrollLeft = function (val) {
  402. return (val === undefined) ? self.getScrollLeft() : self.setScrollLeft(val);
  403. };
  404. // derived by by Dan Pupius www.pupius.net
  405. var BezierClass = function (st, ed, spd, p1, p2, p3, p4) {
  406. this.st = st;
  407. this.ed = ed;
  408. this.spd = spd;
  409. this.p1 = p1 || 0;
  410. this.p2 = p2 || 1;
  411. this.p3 = p3 || 0;
  412. this.p4 = p4 || 1;
  413. this.ts = now();
  414. this.df = this.ed - this.st;
  415. };
  416. BezierClass.prototype = {
  417. B2: function (t) {
  418. return 3 * t * t * (1 - t);
  419. },
  420. B3: function (t) {
  421. return 3 * t * (1 - t) * (1 - t);
  422. },
  423. B4: function (t) {
  424. return (1 - t) * (1 - t) * (1 - t);
  425. },
  426. getNow: function () {
  427. var nw = now();
  428. var pc = 1 - ((nw - this.ts) / this.spd);
  429. var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
  430. return (pc < 0) ? this.ed : this.st + Math.round(this.df * bz);
  431. },
  432. update: function (ed, spd) {
  433. this.st = this.getNow();
  434. this.ed = ed;
  435. this.spd = spd;
  436. this.ts = now();
  437. this.df = this.ed - this.st;
  438. return this;
  439. }
  440. };
  441. //derived from http://stackoverflow.com/questions/11236090/
  442. function getMatrixValues() {
  443. var tr = self.doc.css(cap.trstyle);
  444. if (tr && (tr.substr(0, 6) == "matrix")) {
  445. return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g, '').split(/, +/);
  446. }
  447. return false;
  448. }
  449. if (this.ishwscroll) {
  450. // hw accelerated scroll
  451. this.doc.translate = {
  452. x: 0,
  453. y: 0,
  454. tx: "0px",
  455. ty: "0px"
  456. };
  457. //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
  458. if (cap.hastranslate3d && cap.isios) this.doc.css("-webkit-backface-visibility", "hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/
  459. this.getScrollTop = function (last) {
  460. if (!last) {
  461. var mtx = getMatrixValues();
  462. if (mtx) return (mtx.length == 16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
  463. if (self.timerscroll && self.timerscroll.bz) return self.timerscroll.bz.getNow();
  464. }
  465. return self.doc.translate.y;
  466. };
  467. this.getScrollLeft = function (last) {
  468. if (!last) {
  469. var mtx = getMatrixValues();
  470. if (mtx) return (mtx.length == 16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
  471. if (self.timerscroll && self.timerscroll.bh) return self.timerscroll.bh.getNow();
  472. }
  473. return self.doc.translate.x;
  474. };
  475. this.notifyScrollEvent = function (el) {
  476. var e = document.createEvent("UIEvents");
  477. e.initUIEvent("scroll", false, true, window, 1);
  478. e.niceevent = true;
  479. el.dispatchEvent(e);
  480. };
  481. var cxscrollleft = (this.isrtlmode) ? 1 : -1;
  482. if (cap.hastranslate3d && self.opt.enabletranslate3d) {
  483. this.setScrollTop = function (val, silent) {
  484. self.doc.translate.y = val;
  485. self.doc.translate.ty = (val * -1) + "px";
  486. self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)");
  487. if (!silent) self.notifyScrollEvent(self.win[0]);
  488. };
  489. this.setScrollLeft = function (val, silent) {
  490. self.doc.translate.x = val;
  491. self.doc.translate.tx = (val * cxscrollleft) + "px";
  492. self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)");
  493. if (!silent) self.notifyScrollEvent(self.win[0]);
  494. };
  495. } else {
  496. this.setScrollTop = function (val, silent) {
  497. self.doc.translate.y = val;
  498. self.doc.translate.ty = (val * -1) + "px";
  499. self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
  500. if (!silent) self.notifyScrollEvent(self.win[0]);
  501. };
  502. this.setScrollLeft = function (val, silent) {
  503. self.doc.translate.x = val;
  504. self.doc.translate.tx = (val * cxscrollleft) + "px";
  505. self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
  506. if (!silent) self.notifyScrollEvent(self.win[0]);
  507. };
  508. }
  509. } else {
  510. // native scroll
  511. this.getScrollTop = function () {
  512. return self.docscroll.scrollTop();
  513. };
  514. this.setScrollTop = function (val) {
  515. return setTimeout(function () { (self) && self.docscroll.scrollTop(val) }, 1);
  516. };
  517. this.getScrollLeft = function () {
  518. var val;
  519. if (!self.hasreversehr) {
  520. val = self.docscroll.scrollLeft();
  521. } else if (self.detected.ismozilla) {
  522. val = self.page.maxw - Math.abs(self.docscroll.scrollLeft());
  523. } else {
  524. val = self.page.maxw - self.docscroll.scrollLeft();
  525. }
  526. return val;
  527. };
  528. this.setScrollLeft = function (val) {
  529. return setTimeout(function () {
  530. if (!self) return;
  531. if (self.hasreversehr) {
  532. if (self.detected.ismozilla) {
  533. val = -(self.page.maxw - val);
  534. } else {
  535. val = self.page.maxw - val;
  536. }
  537. }
  538. return self.docscroll.scrollLeft(val);
  539. }, 1);
  540. };
  541. }
  542. this.getTarget = function (e) {
  543. if (!e) return false;
  544. if (e.target) return e.target;
  545. if (e.srcElement) return e.srcElement;
  546. return false;
  547. };
  548. this.hasParent = function (e, id) {
  549. if (!e) return false;
  550. var el = e.target || e.srcElement || e || false;
  551. while (el && el.id != id) {
  552. el = el.parentNode || false;
  553. }
  554. return (el !== false);
  555. };
  556. function getZIndex() {
  557. var dom = self.win;
  558. if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
  559. while (dom.length > 0) {
  560. if (dom[0].nodeType == 9) return false;
  561. var zi = dom.css('zIndex');
  562. if (!isNaN(zi) && zi != 0) return parseInt(zi);
  563. dom = dom.parent();
  564. }
  565. return false;
  566. }
  567. //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
  568. var _convertBorderWidth = {
  569. "thin": 1,
  570. "medium": 3,
  571. "thick": 5
  572. };
  573. function getWidthToPixel(dom, prop, chkheight) {
  574. var wd = dom.css(prop);
  575. var px = parseFloat(wd);
  576. if (isNaN(px)) {
  577. px = _convertBorderWidth[wd] || 0;
  578. var brd = (px == 3) ? ((chkheight) ? (self.win.outerHeight() - self.win.innerHeight()) : (self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
  579. if (self.isie8 && px) px += 1;
  580. return (brd) ? px : 0;
  581. }
  582. return px;
  583. }
  584. this.getDocumentScrollOffset = function () {
  585. return {
  586. top: window.pageYOffset || document.documentElement.scrollTop,
  587. left: window.pageXOffset || document.documentElement.scrollLeft
  588. };
  589. };
  590. this.getOffset = function () {
  591. if (self.isfixed) {
  592. var ofs = self.win.offset(); // fix Chrome auto issue (when right/bottom props only)
  593. var scrl = self.getDocumentScrollOffset();
  594. ofs.top -= scrl.top;
  595. ofs.left -= scrl.left;
  596. return ofs;
  597. }
  598. var ww = self.win.offset();
  599. if (!self.viewport) return ww;
  600. var vp = self.viewport.offset();
  601. return {
  602. top: ww.top - vp.top,// + self.viewport.scrollTop(),
  603. left: ww.left - vp.left // + self.viewport.scrollLeft()
  604. };
  605. };
  606. this.updateScrollBar = function (len) {
  607. var pos, off;
  608. if (self.ishwscroll) {
  609. self.rail.css({ //**
  610. height: self.win.innerHeight() - (self.opt.railpadding.top + self.opt.railpadding.bottom)
  611. });
  612. if (self.railh) self.railh.css({ //**
  613. width: self.win.innerWidth() - (self.opt.railpadding.left + self.opt.railpadding.right)
  614. });
  615. } else {
  616. var wpos = self.getOffset();
  617. pos = {
  618. top: wpos.top,
  619. left: wpos.left - (self.opt.railpadding.left + self.opt.railpadding.right)
  620. };
  621. pos.top += getWidthToPixel(self.win, 'border-top-width', true);
  622. pos.left += (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win, 'border-right-width') - self.rail.width : getWidthToPixel(self.win, 'border-left-width');
  623. off = self.opt.railoffset;
  624. if (off) {
  625. if (off.top) pos.top += off.top;
  626. if (off.left) pos.left += off.left;
  627. }
  628. if (!self.railslocked) self.rail.css({
  629. top: pos.top,
  630. left: pos.left,
  631. height: ((len) ? len.h : self.win.innerHeight()) - (self.opt.railpadding.top + self.opt.railpadding.bottom)
  632. });
  633. if (self.zoom) {
  634. self.zoom.css({
  635. top: pos.top + 1,
  636. left: (self.rail.align == 1) ? pos.left - 20 : pos.left + self.rail.width + 4
  637. });
  638. }
  639. if (self.railh && !self.railslocked) {
  640. pos = {
  641. top: wpos.top,
  642. left: wpos.left
  643. };
  644. off = self.opt.railhoffset;
  645. if (off) {
  646. if (off.top) pos.top += off.top;
  647. if (off.left) pos.left += off.left;
  648. }
  649. var y = (self.railh.align) ? pos.top + getWidthToPixel(self.win, 'border-top-width', true) + self.win.innerHeight() - self.railh.height : pos.top + getWidthToPixel(self.win, 'border-top-width', true);
  650. var x = pos.left + getWidthToPixel(self.win, 'border-left-width');
  651. self.railh.css({
  652. top: y - (self.opt.railpadding.top + self.opt.railpadding.bottom),
  653. left: x,
  654. width: self.railh.width
  655. });
  656. }
  657. }
  658. };
  659. this.doRailClick = function (e, dbl, hr) {
  660. var fn, pg, cur, pos;
  661. if (self.railslocked) return;
  662. self.cancelEvent(e);
  663. if (!("pageY" in e)) {
  664. e.pageX = e.clientX + document.documentElement.scrollLeft;
  665. e.pageY = e.clientY + document.documentElement.scrollTop;
  666. }
  667. if (dbl) {
  668. fn = (hr) ? self.doScrollLeft : self.doScrollTop;
  669. cur = (hr) ? ((e.pageX - self.railh.offset().left - (self.cursorwidth / 2)) * self.scrollratio.x) : ((e.pageY - self.rail.offset().top - (self.cursorheight / 2)) * self.scrollratio.y);
  670. fn(cur);
  671. } else {
  672. fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
  673. cur = (hr) ? self.scroll.x : self.scroll.y;
  674. pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
  675. pg = (hr) ? self.view.w : self.view.h;
  676. fn((cur >= pos) ? pg : -pg);// (cur >= pos) ? fn(pg): fn(-pg);
  677. }
  678. };
  679. self.hasanimationframe = ("requestAnimationFrame" in window);
  680. self.hascancelanimationframe = ("cancelAnimationFrame" in window);
  681. this.init = function () {
  682. self.saved.css = [];
  683. if (cap.isoperamini) return true; // SORRY, DO NOT WORK!
  684. if (cap.isandroid && !("hidden" in document)) return true; // Android 3- SORRY, DO NOT WORK!
  685. self.opt.emulatetouch = self.opt.emulatetouch || self.opt.touchbehavior; // mantain compatibility with "touchbehavior"
  686. var _scrollyhidden = { 'overflow-y': 'hidden' };
  687. if (cap.isie11 || cap.isie10) _scrollyhidden['-ms-overflow-style'] = 'none'; // IE 10 & 11 is always a world apart!
  688. self.zindex = "auto";
  689. if (!self.ispage && self.opt.zindex == "auto") {
  690. self.zindex = getZIndex() || "auto";
  691. } else {
  692. self.zindex = self.opt.zindex;
  693. }
  694. if (!self.ispage && self.zindex != "auto" && self.zindex > globalmaxzindex) {
  695. globalmaxzindex = self.zindex;
  696. }
  697. if (self.isie && self.zindex == 0 && self.opt.zindex == "auto") { // fix IE auto == 0
  698. self.zindex = "auto";
  699. }
  700. if (!self.ispage || (!cap.cantouch && !cap.isieold)) {
  701. var cont = self.docscroll;
  702. if (self.ispage) cont = (self.haswrapper) ? self.win : self.doc;
  703. self.css(cont, _scrollyhidden);
  704. if (self.ispage && (cap.isie11 || cap.isie)) { // IE 7-11
  705. self.css($("html"), _scrollyhidden);
  706. }
  707. if (cap.isios && !self.ispage && !self.haswrapper) self.css($body, {
  708. "-webkit-overflow-scrolling": "touch"
  709. }); //force hw acceleration
  710. var cursor = $(document.createElement('div'));
  711. cursor.css({
  712. position: "relative",
  713. top: 0,
  714. "float": "right",
  715. width: self.opt.cursorwidth,
  716. height: 0,
  717. 'background-color': self.opt.cursorcolor,
  718. border: self.opt.cursorborder,
  719. 'background-clip': 'padding-box',
  720. '-webkit-border-radius': self.opt.cursorborderradius,
  721. '-moz-border-radius': self.opt.cursorborderradius,
  722. 'border-radius': self.opt.cursorborderradius
  723. });
  724. cursor.addClass('nicescroll-cursors');
  725. self.cursor = cursor;
  726. var rail = $(document.createElement('div'));
  727. rail.attr('id', self.id);
  728. rail.addClass('nicescroll-rails nicescroll-rails-vr');
  729. var v, a, kp = ["left", "right", "top", "bottom"]; //**
  730. for (var n in kp) {
  731. a = kp[n];
  732. v = self.opt.railpadding[a];
  733. (v) ? rail.css("padding-" + a, v + "px") : self.opt.railpadding[a] = 0;
  734. }
  735. rail.append(cursor);
  736. rail.width = Math.max(parseFloat(self.opt.cursorwidth), cursor.outerWidth());
  737. rail.css({
  738. width: rail.width + "px",
  739. zIndex: self.zindex,
  740. background: self.opt.background,
  741. cursor: "default"
  742. });
  743. rail.visibility = true;
  744. rail.scrollable = true;
  745. rail.align = (self.opt.railalign == "left") ? 0 : 1;
  746. self.rail = rail;
  747. self.rail.drag = false;
  748. var zoom = false;
  749. if (self.opt.boxzoom && !self.ispage && !cap.isieold) {
  750. zoom = document.createElement('div');
  751. self.bind(zoom, "click", self.doZoom);
  752. self.bind(zoom, "mouseenter", function () {
  753. self.zoom.css('opacity', self.opt.cursoropacitymax);
  754. });
  755. self.bind(zoom, "mouseleave", function () {
  756. self.zoom.css('opacity', self.opt.cursoropacitymin);
  757. });
  758. self.zoom = $(zoom);
  759. self.zoom.css({
  760. cursor: "pointer",
  761. zIndex: self.zindex,
  762. backgroundImage: 'url(' + self.opt.scriptpath + 'zoomico.png)',
  763. height: 18,
  764. width: 18,
  765. backgroundPosition: '0 0'
  766. });
  767. if (self.opt.dblclickzoom) self.bind(self.win, "dblclick", self.doZoom);
  768. if (cap.cantouch && self.opt.gesturezoom) {
  769. self.ongesturezoom = function (e) {
  770. if (e.scale > 1.5) self.doZoomIn(e);
  771. if (e.scale < 0.8) self.doZoomOut(e);
  772. return self.cancelEvent(e);
  773. };
  774. self.bind(self.win, "gestureend", self.ongesturezoom);
  775. }
  776. }
  777. // init HORIZ
  778. self.railh = false;
  779. var railh;
  780. if (self.opt.horizrailenabled) {
  781. self.css(cont, {
  782. overflowX: 'hidden'
  783. });
  784. var cursor = $(document.createElement('div'));
  785. cursor.css({
  786. position: "absolute",
  787. top: 0,
  788. height: self.opt.cursorwidth,
  789. width: 0,
  790. backgroundColor: self.opt.cursorcolor,
  791. border: self.opt.cursorborder,
  792. backgroundClip: 'padding-box',
  793. '-webkit-border-radius': self.opt.cursorborderradius,
  794. '-moz-border-radius': self.opt.cursorborderradius,
  795. 'border-radius': self.opt.cursorborderradius
  796. });
  797. if (cap.isieold) cursor.css('overflow', 'hidden'); //IE6 horiz scrollbar issue
  798. // cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth()); // **
  799. cursor.addClass('nicescroll-cursors');
  800. self.cursorh = cursor;
  801. railh = $(document.createElement('div'));
  802. railh.attr('id', self.id + '-hr');
  803. railh.addClass('nicescroll-rails nicescroll-rails-hr');
  804. railh.height = Math.max(parseFloat(self.opt.cursorwidth), cursor.outerHeight());
  805. railh.css({
  806. height: railh.height + "px",
  807. 'zIndex': self.zindex,
  808. "background": self.opt.background
  809. });
  810. railh.append(cursor);
  811. railh.visibility = true;
  812. railh.scrollable = true;
  813. railh.align = (self.opt.railvalign == "top") ? 0 : 1;
  814. self.railh = railh;
  815. self.railh.drag = false;
  816. }
  817. //
  818. if (self.ispage) {
  819. rail.css({
  820. position: "fixed",
  821. top: 0,
  822. height: "100%"
  823. });
  824. (rail.align) ? rail.css({
  825. right: 0
  826. }) : rail.css({
  827. left: 0
  828. });
  829. self.body.append(rail);
  830. if (self.railh) {
  831. railh.css({
  832. position: "fixed",
  833. left: 0,
  834. width: "100%"
  835. });
  836. (railh.align) ? railh.css({
  837. bottom: 0
  838. }) : railh.css({
  839. top: 0
  840. });
  841. self.body.append(railh);
  842. }
  843. } else {
  844. if (self.ishwscroll) {
  845. if (self.win.css('position') == 'static') self.css(self.win, {
  846. 'position': 'relative'
  847. });
  848. var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
  849. $(bd).scrollTop(0).scrollLeft(0); // fix rail position if content already scrolled
  850. if (self.zoom) {
  851. self.zoom.css({
  852. position: "absolute",
  853. top: 1,
  854. right: 0,
  855. "margin-right": rail.width + 4
  856. });
  857. bd.append(self.zoom);
  858. }
  859. rail.css({
  860. position: "absolute",
  861. top: 0
  862. });
  863. (rail.align) ? rail.css({
  864. right: 0
  865. }) : rail.css({
  866. left: 0
  867. });
  868. bd.append(rail);
  869. if (railh) {
  870. railh.css({
  871. position: "absolute",
  872. left: 0,
  873. bottom: 0
  874. });
  875. (railh.align) ? railh.css({
  876. bottom: 0
  877. }) : railh.css({
  878. top: 0
  879. });
  880. bd.append(railh);
  881. }
  882. } else {
  883. self.isfixed = (self.win.css("position") == "fixed");
  884. var rlpos = (self.isfixed) ? "fixed" : "absolute";
  885. if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
  886. if (self.viewport) {
  887. self.body = self.viewport;
  888. if ((/fixed|absolute/.test(self.viewport.css("position"))) == false) self.css(self.viewport, {
  889. "position": "relative"
  890. });
  891. }
  892. rail.css({
  893. position: rlpos
  894. });
  895. if (self.zoom) self.zoom.css({
  896. position: rlpos
  897. });
  898. self.updateScrollBar();
  899. self.body.append(rail);
  900. if (self.zoom) self.body.append(self.zoom);
  901. if (self.railh) {
  902. railh.css({
  903. position: rlpos
  904. });
  905. self.body.append(railh);
  906. }
  907. }
  908. if (cap.isios) self.css(self.win, {
  909. '-webkit-tap-highlight-color': 'rgba(0,0,0,0)',
  910. '-webkit-touch-callout': 'none'
  911. }); // prevent grey layer on click
  912. if (cap.isie && self.opt.disableoutline) self.win.attr("hideFocus", "true"); // IE, prevent dotted rectangle on focused div
  913. if (cap.iswebkit && self.opt.disableoutline) self.win.css('outline', 'none'); // Webkit outline
  914. }
  915. if (self.opt.autohidemode === false) {
  916. self.autohidedom = false;
  917. self.rail.css({
  918. opacity: self.opt.cursoropacitymax
  919. });
  920. if (self.railh) self.railh.css({
  921. opacity: self.opt.cursoropacitymax
  922. });
  923. } else if ((self.opt.autohidemode === true) || (self.opt.autohidemode === "leave")) {
  924. self.autohidedom = $().add(self.rail);
  925. if (cap.isie8) self.autohidedom = self.autohidedom.add(self.cursor);
  926. if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
  927. if (self.railh && cap.isie8) self.autohidedom = self.autohidedom.add(self.cursorh);
  928. } else if (self.opt.autohidemode == "scroll") {
  929. self.autohidedom = $().add(self.rail);
  930. if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
  931. } else if (self.opt.autohidemode == "cursor") {
  932. self.autohidedom = $().add(self.cursor);
  933. if (self.railh) self.autohidedom = self.autohidedom.add(self.cursorh);
  934. } else if (self.opt.autohidemode == "hidden") {
  935. self.autohidedom = false;
  936. self.hide();
  937. self.railslocked = false;
  938. }
  939. if (cap.cantouch || self.istouchcapable || self.opt.emulatetouch || cap.hasmstouch) {
  940. self.scrollmom = new ScrollMomentumClass2D(self);
  941. self.ontouchstart = function (e) {
  942. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  943. self.hasmoving = false;
  944. if (!self.railslocked) {
  945. var tg;
  946. if (cap.hasmstouch) {
  947. tg = (e.target) ? e.target : false;
  948. while (tg) {
  949. var nc = $(tg).getNiceScroll();
  950. if ((nc.length > 0) && (nc[0].me == self.me)) break;
  951. if (nc.length > 0) return false;
  952. if ((tg.nodeName == 'DIV') && (tg.id == self.id)) break;
  953. tg = (tg.parentNode) ? tg.parentNode : false;
  954. }
  955. }
  956. e.stopPropagation();
  957. self.cancelScroll();
  958. tg = self.getTarget(e);
  959. if (tg) {
  960. var skp = (/INPUT/i.test(tg.nodeName)) && (/range/i.test(tg.type));
  961. if (skp) return self.stopPropagation(e);
  962. }
  963. if (!("clientX" in e) && ("changedTouches" in e)) {
  964. e.clientX = e.changedTouches[0].clientX;
  965. e.clientY = e.changedTouches[0].clientY;
  966. }
  967. if (self.forcescreen) {
  968. var le = e;
  969. e = {
  970. "original": (e.original) ? e.original : e
  971. };
  972. e.clientX = le.screenX;
  973. e.clientY = le.screenY;
  974. }
  975. self.rail.drag = {
  976. x: e.clientX,
  977. y: e.clientY,
  978. sx: self.scroll.x,
  979. sy: self.scroll.y,
  980. st: self.getScrollTop(),
  981. sl: self.getScrollLeft(),
  982. pt: 2,
  983. dl: false,
  984. tg: tg
  985. };
  986. if (self.ispage || !self.opt.directionlockdeadzone) {
  987. self.rail.drag.dl = "f";
  988. } else {
  989. var view = {
  990. w: $window.width(),
  991. h: $window.height()
  992. };
  993. var page = {
  994. w: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
  995. h: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
  996. };
  997. var maxh = Math.max(0, page.h - view.h);
  998. var maxw = Math.max(0, page.w - view.w);
  999. if (!self.rail.scrollable && self.railh.scrollable) self.rail.drag.ck = (maxh > 0) ? "v" : false;
  1000. else if (self.rail.scrollable && !self.railh.scrollable) self.rail.drag.ck = (maxw > 0) ? "h" : false;
  1001. else self.rail.drag.ck = false;
  1002. if (!self.rail.drag.ck) self.rail.drag.dl = "f";
  1003. }
  1004. if (self.opt.emulatetouch && self.isiframe && cap.isie) {
  1005. var wp = self.win.position();
  1006. self.rail.drag.x += wp.left;
  1007. self.rail.drag.y += wp.top;
  1008. }
  1009. self.hasmoving = false;
  1010. self.lastmouseup = false;
  1011. self.scrollmom.reset(e.clientX, e.clientY);
  1012. if (!cap.cantouch && !this.istouchcapable && !e.pointerType) {
  1013. var ip = (tg) ? /INPUT|SELECT|BUTTON|TEXTAREA/i.test(tg.nodeName) : false;
  1014. if (!ip) {
  1015. if (!self.ispage && cap.hasmousecapture) tg.setCapture();
  1016. if (self.opt.emulatetouch) {
  1017. if (tg.onclick && !(tg._onclick || false)) { // intercept DOM0 onclick event
  1018. tg._onclick = tg.onclick;
  1019. tg.onclick = function (e) {
  1020. if (self.hasmoving) return false;
  1021. tg._onclick.call(this, e);
  1022. };
  1023. }
  1024. return self.cancelEvent(e);
  1025. }
  1026. return self.stopPropagation(e);
  1027. }
  1028. if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
  1029. self.preventclick = {
  1030. "tg": tg,
  1031. "click": false
  1032. };
  1033. }
  1034. }
  1035. }
  1036. };
  1037. self.ontouchend = function (e) {
  1038. if (!self.rail.drag) return true;
  1039. if (self.rail.drag.pt == 2) {
  1040. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  1041. /*
  1042. if (!self.hasmoving) {
  1043. if (e.type === "mouseup") {
  1044. var tg = self.rail.drag.tg;
  1045. setTimeout(function () {
  1046. tg && $(tg).trigger("click");
  1047. }, 20);
  1048. }
  1049. }
  1050. */
  1051. self.rail.drag = false;
  1052. if (self.hasmoving) {
  1053. self.scrollmom.doMomentum();
  1054. self.lastmouseup = true;
  1055. self.hideCursor();
  1056. if (cap.hasmousecapture) document.releaseCapture();
  1057. if (!cap.cantouch) return self.cancelEvent(e);
  1058. }
  1059. }
  1060. else if (self.rail.drag.pt == 1) {
  1061. return self.onmouseup(e);
  1062. }
  1063. };
  1064. var moveneedoffset = (self.opt.emulatetouch && self.isiframe && !cap.hasmousecapture);
  1065. self.ontouchmove = function (e, byiframe) {
  1066. if (!self.rail.drag) return false;
  1067. if (e.targetTouches && self.opt.preventmultitouchscrolling) {
  1068. if (e.targetTouches.length > 1) return false; // multitouch
  1069. }
  1070. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  1071. if (self.rail.drag.pt == 2) {
  1072. if (("changedTouches" in e)) {
  1073. e.clientX = e.changedTouches[0].clientX;
  1074. e.clientY = e.changedTouches[0].clientY;
  1075. }
  1076. if (self.rail.drag.y === e.clientY && self.rail.drag.x === e.clientX) return false; // prevent first useless move event
  1077. if (!self.hasmoving) self.triggerScrollStart(e.clientX,e.clientY,0,0,0);
  1078. self.hasmoving = true;
  1079. if (self.preventclick && !self.preventclick.click) {
  1080. self.preventclick.click = self.preventclick.tg.onclick || false;
  1081. self.preventclick.tg.onclick = self.onpreventclick;
  1082. }
  1083. var ofy, ofx;
  1084. ofx = ofy = 0;
  1085. if (moveneedoffset && !byiframe) {
  1086. var wp = self.win.position();
  1087. ofx = -wp.left;
  1088. ofy = -wp.top;
  1089. }
  1090. var fy = e.clientY + ofy;
  1091. var my = (fy - self.rail.drag.y);
  1092. var fx = e.clientX + ofx;
  1093. var mx = (fx - self.rail.drag.x);
  1094. var ny = self.rail.drag.st - my;
  1095. if (self.ishwscroll && self.opt.bouncescroll) {
  1096. if (ny < 0) {
  1097. ny = Math.round(ny / 2);
  1098. } else if (ny > self.page.maxh) {
  1099. ny = self.page.maxh + Math.round((ny - self.page.maxh) / 2);
  1100. }
  1101. } else {
  1102. if (ny < 0) {
  1103. ny = 0;
  1104. fy = 0;
  1105. }
  1106. if (ny > self.page.maxh) {
  1107. ny = self.page.maxh;
  1108. fy = 0;
  1109. }
  1110. }
  1111. var nx;
  1112. if (self.railh && self.railh.scrollable) {
  1113. nx = (self.isrtlmode) ? mx - self.rail.drag.sl : self.rail.drag.sl - mx;
  1114. if (self.ishwscroll && self.opt.bouncescroll) {
  1115. if (nx < 0) {
  1116. nx = Math.round(nx / 2);
  1117. } else if (nx > self.page.maxw) {
  1118. nx = self.page.maxw + Math.round((nx - self.page.maxw) / 2);
  1119. }
  1120. } else {
  1121. if (nx < 0) {
  1122. nx = 0;
  1123. fx = 0;
  1124. }
  1125. if (nx > self.page.maxw) {
  1126. nx = self.page.maxw;
  1127. fx = 0;
  1128. }
  1129. }
  1130. }
  1131. var grabbed = false;
  1132. if (self.rail.drag.dl) {
  1133. grabbed = true;
  1134. if (self.rail.drag.dl == "v") nx = self.rail.drag.sl;
  1135. else if (self.rail.drag.dl == "h") ny = self.rail.drag.st;
  1136. } else {
  1137. var ay = Math.abs(my);
  1138. var ax = Math.abs(mx);
  1139. var dz = self.opt.directionlockdeadzone;
  1140. if (self.rail.drag.ck == "v") {
  1141. if (ay > dz && (ax <= (ay * 0.3))) {
  1142. self.rail.drag = false;
  1143. return true;
  1144. } else if (ax > dz) {
  1145. self.rail.drag.dl = "f";
  1146. $body.scrollTop($body.scrollTop()); // stop iOS native scrolling (when active javascript has blocked)
  1147. }
  1148. } else if (self.rail.drag.ck == "h") {
  1149. if (ax > dz && (ay <= (ax * 0.3))) {
  1150. self.rail.drag = false;
  1151. return true;
  1152. } else if (ay > dz) {
  1153. self.rail.drag.dl = "f";
  1154. $body.scrollLeft($body.scrollLeft()); // stop iOS native scrolling (when active javascript has blocked)
  1155. }
  1156. }
  1157. }
  1158. self.synched("touchmove", function () {
  1159. if (self.rail.drag && (self.rail.drag.pt == 2)) {
  1160. if (self.prepareTransition) self.prepareTransition(0);
  1161. if (self.rail.scrollable) self.setScrollTop(ny);
  1162. self.scrollmom.update(fx, fy);
  1163. if (self.railh && self.railh.scrollable) {
  1164. self.setScrollLeft(nx);
  1165. self.showCursor(ny, nx);
  1166. } else {
  1167. self.showCursor(ny);
  1168. }
  1169. if (cap.isie10) document.selection.clear();
  1170. }
  1171. });
  1172. if (cap.ischrome && self.istouchcapable) grabbed = false; //chrome touch emulation doesn't like!
  1173. if (grabbed) return self.cancelEvent(e);
  1174. }
  1175. else if (self.rail.drag.pt == 1) { // drag on cursor
  1176. return self.onmousemove(e);
  1177. }
  1178. };
  1179. self.ontouchstartCursor = function (e, hronly) {
  1180. if (self.rail.drag && self.rail.drag.pt != 3) return;
  1181. if (self.locked) return self.cancelEvent(e);
  1182. self.cancelScroll();
  1183. self.rail.drag = {
  1184. x: e.touches[0].clientX,
  1185. y: e.touches[0].clientY,
  1186. sx: self.scroll.x,
  1187. sy: self.scroll.y,
  1188. pt: 3,
  1189. hr: (!!hronly)
  1190. };
  1191. var tg = self.getTarget(e);
  1192. if (!self.ispage && cap.hasmousecapture) tg.setCapture();
  1193. if (self.isiframe && !cap.hasmousecapture) {
  1194. self.saved["csspointerevents"] = self.doc.css("pointer-events");
  1195. self.css(self.doc, { "pointer-events": "none" });
  1196. }
  1197. return self.cancelEvent(e);
  1198. };
  1199. self.ontouchendCursor = function (e) {
  1200. if (self.rail.drag) {
  1201. if (cap.hasmousecapture) document.releaseCapture();
  1202. if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved["csspointerevents"]);
  1203. if (self.rail.drag.pt != 3) return;
  1204. self.rail.drag = false;
  1205. return self.cancelEvent(e);
  1206. }
  1207. };
  1208. self.ontouchmoveCursor = function (e) {
  1209. if (self.rail.drag) {
  1210. if (self.rail.drag.pt != 3) return;
  1211. self.cursorfreezed = true;
  1212. if (self.rail.drag.hr) {
  1213. self.scroll.x = self.rail.drag.sx + (e.touches[0].clientX - self.rail.drag.x);
  1214. if (self.scroll.x < 0) self.scroll.x = 0;
  1215. var mw = self.scrollvaluemaxw;
  1216. if (self.scroll.x > mw) self.scroll.x = mw;
  1217. } else {
  1218. self.scroll.y = self.rail.drag.sy + (e.touches[0].clientY - self.rail.drag.y);
  1219. if (self.scroll.y < 0) self.scroll.y = 0;
  1220. var my = self.scrollvaluemax;
  1221. if (self.scroll.y > my) self.scroll.y = my;
  1222. }
  1223. self.synched('touchmove', function () {
  1224. if (self.rail.drag && (self.rail.drag.pt == 3)) {
  1225. self.showCursor();
  1226. if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x * self.scrollratio.x), self.opt.cursordragspeed);
  1227. else self.doScrollTop(Math.round(self.scroll.y * self.scrollratio.y), self.opt.cursordragspeed);
  1228. }
  1229. });
  1230. return self.cancelEvent(e);
  1231. }
  1232. };
  1233. }
  1234. self.onmousedown = function (e, hronly) {
  1235. if (self.rail.drag && self.rail.drag.pt != 1) return;
  1236. if (self.railslocked) return self.cancelEvent(e);
  1237. self.cancelScroll();
  1238. self.rail.drag = {
  1239. x: e.clientX,
  1240. y: e.clientY,
  1241. sx: self.scroll.x,
  1242. sy: self.scroll.y,
  1243. pt: 1,
  1244. hr: hronly || false
  1245. };
  1246. var tg = self.getTarget(e);
  1247. if (!self.ispage && cap.hasmousecapture) tg.setCapture();
  1248. if (self.isiframe && !cap.hasmousecapture) {
  1249. self.saved.csspointerevents = self.doc.css("pointer-events");
  1250. self.css(self.doc, {
  1251. "pointer-events": "none"
  1252. });
  1253. }
  1254. self.hasmoving = false;
  1255. return self.cancelEvent(e);
  1256. };
  1257. self.onmouseup = function (e) {
  1258. if (self.rail.drag) {
  1259. if (self.rail.drag.pt != 1) return true;
  1260. if (cap.hasmousecapture) document.releaseCapture();
  1261. if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents);
  1262. self.rail.drag = false;
  1263. if (self.hasmoving) self.triggerScrollEnd(); // TODO - check &&!self.scrollrunning
  1264. return self.cancelEvent(e);
  1265. }
  1266. };
  1267. self.onmousemove = function (e) {
  1268. if (self.rail.drag) {
  1269. if (self.rail.drag.pt !== 1) return;
  1270. if (cap.ischrome && e.which === 0) return self.onmouseup(e);
  1271. self.cursorfreezed = true;
  1272. self.hasmoving = true;
  1273. if (self.rail.drag.hr) {
  1274. self.scroll.x = self.rail.drag.sx + (e.clientX - self.rail.drag.x);
  1275. if (self.scroll.x < 0) self.scroll.x = 0;
  1276. var mw = self.scrollvaluemaxw;
  1277. if (self.scroll.x > mw) self.scroll.x = mw;
  1278. } else {
  1279. self.scroll.y = self.rail.drag.sy + (e.clientY - self.rail.drag.y);
  1280. if (self.scroll.y < 0) self.scroll.y = 0;
  1281. var my = self.scrollvaluemax;
  1282. if (self.scroll.y > my) self.scroll.y = my;
  1283. }
  1284. self.synched('mousemove', function () {
  1285. if (self.rail.drag && (self.rail.drag.pt == 1)) {
  1286. self.showCursor();
  1287. if (self.rail.drag.hr) {
  1288. if (self.hasreversehr) {
  1289. self.doScrollLeft(self.scrollvaluemaxw - Math.round(self.scroll.x * self.scrollratio.x), self.opt.cursordragspeed);
  1290. } else {
  1291. self.doScrollLeft(Math.round(self.scroll.x * self.scrollratio.x), self.opt.cursordragspeed);
  1292. }
  1293. }
  1294. else self.doScrollTop(Math.round(self.scroll.y * self.scrollratio.y), self.opt.cursordragspeed);
  1295. }
  1296. });
  1297. return self.cancelEvent(e);
  1298. }
  1299. else {
  1300. self.checkarea = 0;
  1301. }
  1302. };
  1303. if (cap.cantouch || self.opt.emulatetouch) {
  1304. self.onpreventclick = function (e) {
  1305. if (self.preventclick) {
  1306. self.preventclick.tg.onclick = self.preventclick.click;
  1307. self.preventclick = false;
  1308. return self.cancelEvent(e);
  1309. }
  1310. };
  1311. //self.bind(self.win, "mousedown", self.ontouchstart); // control content dragging <-- REENABLE!!
  1312. self.onclick = (cap.isios) ? false : function (e) { // it needs to check IE11 ???
  1313. if (self.lastmouseup) {
  1314. self.lastmouseup = false;
  1315. return self.cancelEvent(e);
  1316. } else {
  1317. return true;
  1318. }
  1319. };
  1320. if (self.opt.grabcursorenabled && cap.cursorgrabvalue) {
  1321. self.css((self.ispage) ? self.doc : self.win, {
  1322. 'cursor': cap.cursorgrabvalue
  1323. });
  1324. self.css(self.rail, {
  1325. 'cursor': cap.cursorgrabvalue
  1326. });
  1327. }
  1328. } else {
  1329. var checkSelectionScroll = function (e) {
  1330. if (!self.selectiondrag) return;
  1331. if (e) {
  1332. var ww = self.win.outerHeight();
  1333. var df = (e.pageY - self.selectiondrag.top);
  1334. if (df > 0 && df < ww) df = 0;
  1335. if (df >= ww) df -= ww;
  1336. self.selectiondrag.df = df;
  1337. }
  1338. if (self.selectiondrag.df == 0) return;
  1339. var rt = -Math.floor(self.selectiondrag.df / 6) * 2;
  1340. self.doScrollBy(rt);
  1341. self.debounced("doselectionscroll", function () {
  1342. checkSelectionScroll();
  1343. }, 50);
  1344. };
  1345. if ("getSelection" in document) { // A grade - Major browsers
  1346. self.hasTextSelected = function () {
  1347. return (document.getSelection().rangeCount > 0);
  1348. };
  1349. } else if ("selection" in document) { //IE9-
  1350. self.hasTextSelected = function () {
  1351. return (document.selection.type != "None");
  1352. };
  1353. } else {
  1354. self.hasTextSelected = function () { // no support
  1355. return false;
  1356. };
  1357. }
  1358. self.onselectionstart = function (e) {
  1359. /* More testing - severe chrome issues
  1360. if (!self.haswrapper&&(e.which&&e.which==2)) { // fool browser to manage middle button scrolling
  1361. self.win.css({'overflow':'auto'});
  1362. setTimeout(function(){
  1363. self.win.css({'overflow':''});
  1364. },10);
  1365. return true;
  1366. }
  1367. */
  1368. if (self.ispage) return;
  1369. self.selectiondrag = self.win.offset();
  1370. };
  1371. self.onselectionend = function (e) {
  1372. self.selectiondrag = false;
  1373. };
  1374. self.onselectiondrag = function (e) {
  1375. if (!self.selectiondrag) return;
  1376. if (self.hasTextSelected()) self.debounced("selectionscroll", function () {
  1377. checkSelectionScroll(e);
  1378. }, 250);
  1379. };
  1380. }
  1381. if (cap.hasw3ctouch) { //IE11+
  1382. self.css((self.ispage) ? $("html") : self.win, { 'touch-action': 'none' });
  1383. self.css(self.rail, {
  1384. 'touch-action': 'none'
  1385. });
  1386. self.css(self.cursor, {
  1387. 'touch-action': 'none'
  1388. });
  1389. self.bind(self.win, "pointerdown", self.ontouchstart);
  1390. self.bind(document, "pointerup", self.ontouchend);
  1391. self.bind(document, "pointermove", self.ontouchmove);
  1392. } else if (cap.hasmstouch) { //IE10
  1393. self.css((self.ispage) ? $("html") : self.win, { '-ms-touch-action': 'none' });
  1394. self.css(self.rail, {
  1395. '-ms-touch-action': 'none'
  1396. });
  1397. self.css(self.cursor, {
  1398. '-ms-touch-action': 'none'
  1399. });
  1400. self.bind(self.win, "MSPointerDown", self.ontouchstart);
  1401. self.bind(document, "MSPointerUp", self.ontouchend);
  1402. self.bind(document, "MSPointerMove", self.ontouchmove);
  1403. self.bind(self.cursor, "MSGestureHold", function (e) {
  1404. e.preventDefault();
  1405. });
  1406. self.bind(self.cursor, "contextmenu", function (e) {
  1407. e.preventDefault();
  1408. });
  1409. } else if (cap.cantouch) { // smartphones/touch devices
  1410. self.bind(self.win, "touchstart", self.ontouchstart, false, true);
  1411. self.bind(document, "touchend", self.ontouchend, false, true);
  1412. self.bind(document, "touchcancel", self.ontouchend, false, true);
  1413. self.bind(document, "touchmove", self.ontouchmove, false, true);
  1414. }
  1415. if (self.opt.emulatetouch) {
  1416. self.bind(self.win, "mousedown", self.ontouchstart, false, true);
  1417. self.bind(document, "mouseup", self.ontouchend, false, true);
  1418. self.bind(document, "mousemove", self.ontouchmove, false, true);
  1419. }
  1420. if (self.opt.cursordragontouch || (!cap.cantouch && !self.opt.emulatetouch)) {
  1421. self.rail.css({
  1422. cursor: "default"
  1423. });
  1424. self.railh && self.railh.css({
  1425. cursor: "default"
  1426. });
  1427. self.jqbind(self.rail, "mouseenter", function () {
  1428. if (!self.ispage && !self.win.is(":visible")) return false;
  1429. if (self.canshowonmouseevent) self.showCursor();
  1430. self.rail.active = true;
  1431. });
  1432. self.jqbind(self.rail, "mouseleave", function () {
  1433. self.rail.active = false;
  1434. if (!self.rail.drag) self.hideCursor();
  1435. });
  1436. if (self.opt.sensitiverail) {
  1437. self.bind(self.rail, "click", function (e) {
  1438. self.doRailClick(e, false, false);
  1439. });
  1440. self.bind(self.rail, "dblclick", function (e) {
  1441. self.doRailClick(e, true, false);
  1442. });
  1443. self.bind(self.cursor, "click", function (e) {
  1444. self.cancelEvent(e);
  1445. });
  1446. self.bind(self.cursor, "dblclick", function (e) {
  1447. self.cancelEvent(e);
  1448. });
  1449. }
  1450. if (self.railh) {
  1451. self.jqbind(self.railh, "mouseenter", function () {
  1452. if (!self.ispage && !self.win.is(":visible")) return false;
  1453. if (self.canshowonmouseevent) self.showCursor();
  1454. self.rail.active = true;
  1455. });
  1456. self.jqbind(self.railh, "mouseleave", function () {
  1457. self.rail.active = false;
  1458. if (!self.rail.drag) self.hideCursor();
  1459. });
  1460. if (self.opt.sensitiverail) {
  1461. self.bind(self.railh, "click", function (e) {
  1462. self.doRailClick(e, false, true);
  1463. });
  1464. self.bind(self.railh, "dblclick", function (e) {
  1465. self.doRailClick(e, true, true);
  1466. });
  1467. self.bind(self.cursorh, "click", function (e) {
  1468. self.cancelEvent(e);
  1469. });
  1470. self.bind(self.cursorh, "dblclick", function (e) {
  1471. self.cancelEvent(e);
  1472. });
  1473. }
  1474. }
  1475. }
  1476. if (self.opt.cursordragontouch && (this.istouchcapable || cap.cantouch)) {
  1477. self.bind(self.cursor, "touchstart", self.ontouchstartCursor);
  1478. self.bind(self.cursor, "touchmove", self.ontouchmoveCursor);
  1479. self.bind(self.cursor, "touchend", self.ontouchendCursor);
  1480. self.cursorh && self.bind(self.cursorh, "touchstart", function (e) {
  1481. self.ontouchstartCursor(e, true);
  1482. });
  1483. self.cursorh && self.bind(self.cursorh, "touchmove", self.ontouchmoveCursor);
  1484. self.cursorh && self.bind(self.cursorh, "touchend", self.ontouchendCursor);
  1485. }
  1486. if (!cap.cantouch && !self.opt.emulatetouch) {
  1487. self.bind((cap.hasmousecapture) ? self.win : document, "mouseup", self.onmouseup);
  1488. self.bind(document, "mousemove", self.onmousemove);
  1489. if (self.onclick) self.bind(document, "click", self.onclick);
  1490. self.bind(self.cursor, "mousedown", self.onmousedown);
  1491. self.bind(self.cursor, "mouseup", self.onmouseup);
  1492. if (self.railh) {
  1493. self.bind(self.cursorh, "mousedown", function (e) {
  1494. self.onmousedown(e, true);
  1495. });
  1496. self.bind(self.cursorh, "mouseup", self.onmouseup);
  1497. }
  1498. if (!self.ispage && self.opt.enablescrollonselection) {
  1499. self.bind(self.win[0], "mousedown", self.onselectionstart);
  1500. self.bind(document, "mouseup", self.onselectionend);
  1501. self.bind(self.cursor, "mouseup", self.onselectionend);
  1502. if (self.cursorh) self.bind(self.cursorh, "mouseup", self.onselectionend);
  1503. self.bind(document, "mousemove", self.onselectiondrag);
  1504. }
  1505. if (self.zoom) {
  1506. self.jqbind(self.zoom, "mouseenter", function () {
  1507. if (self.canshowonmouseevent) self.showCursor();
  1508. self.rail.active = true;
  1509. });
  1510. self.jqbind(self.zoom, "mouseleave", function () {
  1511. self.rail.active = false;
  1512. if (!self.rail.drag) self.hideCursor();
  1513. });
  1514. }
  1515. } else {
  1516. self.bind((cap.hasmousecapture) ? self.win : document, "mouseup", self.ontouchend);
  1517. if (self.onclick) self.bind(document, "click", self.onclick);
  1518. if (self.opt.cursordragontouch) {
  1519. self.bind(self.cursor, "mousedown", self.onmousedown);
  1520. self.bind(self.cursor, "mouseup", self.onmouseup);
  1521. self.cursorh && self.bind(self.cursorh, "mousedown", function (e) {
  1522. self.onmousedown(e, true);
  1523. });
  1524. self.cursorh && self.bind(self.cursorh, "mouseup", self.onmouseup);
  1525. } else {
  1526. self.bind(self.rail, "mousedown", function (e) { e.preventDefault(); }); // prevent text selection
  1527. self.railh && self.bind(self.railh, "mousedown", function (e) { e.preventDefault(); });
  1528. }
  1529. }
  1530. if (self.opt.enablemousewheel) {
  1531. if (!self.isiframe) self.mousewheel((cap.isie && self.ispage) ? document : self.win, self.onmousewheel);
  1532. self.mousewheel(self.rail, self.onmousewheel);
  1533. if (self.railh) self.mousewheel(self.railh, self.onmousewheelhr);
  1534. }
  1535. if (!self.ispage && !cap.cantouch && !(/HTML|^BODY/.test(self.win[0].nodeName))) {
  1536. if (!self.win.attr("tabindex")) self.win.attr({
  1537. "tabindex": ++tabindexcounter
  1538. });
  1539. // self.jqbind(self.win, "focus", function (e) {
  1540. self.bind(self.win, "focus", function (e) { // better using native events
  1541. domfocus = (self.getTarget(e)).id || true;
  1542. self.hasfocus = true;
  1543. if (self.canshowonmouseevent) self.noticeCursor();
  1544. });
  1545. // self.jqbind(self.win, "blur", function (e) {
  1546. self.bind(self.win, "blur", function (e) { // *
  1547. domfocus = false;
  1548. self.hasfocus = false;
  1549. });
  1550. // self.jqbind(self.win, "mouseenter", function (e) {
  1551. self.bind(self.win, "mouseenter", function (e) { // *
  1552. mousefocus = (self.getTarget(e)).id || true;
  1553. self.hasmousefocus = true;
  1554. if (self.canshowonmouseevent) self.noticeCursor();
  1555. });
  1556. //self.jqbind(self.win, "mouseleave", function (e) {
  1557. self.bind(self.win, "mouseleave", function (e) { // *
  1558. mousefocus = false;
  1559. self.hasmousefocus = false;
  1560. if (!self.rail.drag) self.hideCursor();
  1561. });
  1562. }
  1563. //Thanks to http://www.quirksmode.org !!
  1564. self.onkeypress = function (e) {
  1565. if (self.railslocked && self.page.maxh == 0) return true;
  1566. e = (e) ? e : window.e;
  1567. var tg = self.getTarget(e);
  1568. if (tg && /INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
  1569. var tp = tg.getAttribute('type') || tg.type || false;
  1570. if ((!tp) || !(/submit|button|cancel/i.tp)) return true;
  1571. }
  1572. if ($(tg).attr('contenteditable')) return true;
  1573. if (self.hasfocus || (self.hasmousefocus && !domfocus) || (self.ispage && !domfocus && !mousefocus)) {
  1574. var key = e.keyCode;
  1575. if (self.railslocked && key != 27) return self.cancelEvent(e);
  1576. var ctrl = e.ctrlKey || false;
  1577. var shift = e.shiftKey || false;
  1578. var ret = false;
  1579. switch (key) {
  1580. case 38:
  1581. case 63233: //safari
  1582. self.doScrollBy(24 * 3);
  1583. ret = true;
  1584. break;
  1585. case 40:
  1586. case 63235: //safari
  1587. self.doScrollBy(-24 * 3);
  1588. ret = true;
  1589. break;
  1590. case 37:
  1591. case 63232: //safari
  1592. if (self.railh) {
  1593. (ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24 * 3);
  1594. ret = true;
  1595. }
  1596. break;
  1597. case 39:
  1598. case 63234: //safari
  1599. if (self.railh) {
  1600. (ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24 * 3);
  1601. ret = true;
  1602. }
  1603. break;
  1604. case 33:
  1605. case 63276: // safari
  1606. self.doScrollBy(self.view.h);
  1607. ret = true;
  1608. break;
  1609. case 34:
  1610. case 63277: // safari
  1611. self.doScrollBy(-self.view.h);
  1612. ret = true;
  1613. break;
  1614. case 36:
  1615. case 63273: // safari
  1616. (self.railh && ctrl) ? self.doScrollPos(0, 0) : self.doScrollTo(0);
  1617. ret = true;
  1618. break;
  1619. case 35:
  1620. case 63275: // safari
  1621. (self.railh && ctrl) ? self.doScrollPos(self.page.maxw, self.page.maxh) : self.doScrollTo(self.page.maxh);
  1622. ret = true;
  1623. break;
  1624. case 32:
  1625. if (self.opt.spacebarenabled) {
  1626. (shift) ? self.doScrollBy(self.view.h) : self.doScrollBy(-self.view.h);
  1627. ret = true;
  1628. }
  1629. break;
  1630. case 27: // ESC
  1631. if (self.zoomactive) {
  1632. self.doZoom();
  1633. ret = true;
  1634. }
  1635. break;
  1636. }
  1637. if (ret) return self.cancelEvent(e);
  1638. }
  1639. };
  1640. if (self.opt.enablekeyboard) self.bind(document, (cap.isopera && !cap.isopera12) ? "keypress" : "keydown", self.onkeypress);
  1641. self.bind(document, "keydown", function (e) {
  1642. var ctrl = e.ctrlKey || false;
  1643. if (ctrl) self.wheelprevented = true;
  1644. });
  1645. self.bind(document, "keyup", function (e) {
  1646. var ctrl = e.ctrlKey || false;
  1647. if (!ctrl) self.wheelprevented = false;
  1648. });
  1649. self.bind(window, "blur", function (e) {
  1650. self.wheelprevented = false;
  1651. });
  1652. self.bind(window, 'resize', self.lazyResize);
  1653. self.bind(window, 'orientationchange', self.lazyResize);
  1654. self.bind(window, "load", self.lazyResize);
  1655. if (cap.ischrome && !self.ispage && !self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
  1656. var tmp = self.win.attr("style");
  1657. var ww = parseFloat(self.win.css("width")) + 1;
  1658. self.win.css('width', ww);
  1659. self.synched("chromefix", function () {
  1660. self.win.attr("style", tmp);
  1661. });
  1662. }
  1663. // Trying a cross-browser implementation - good luck!
  1664. self.onAttributeChange = function (e) {
  1665. self.lazyResize(self.isieold ? 250 : 30);
  1666. };
  1667. if (self.opt.enableobserver) {
  1668. if ((!self.isie11) && (ClsMutationObserver !== false)) { // IE11 crashes #568
  1669. self.observerbody = new ClsMutationObserver(function (mutations) {
  1670. mutations.forEach(function (mut) {
  1671. if (mut.type == "attributes") {
  1672. return ($body.hasClass("modal-open") && $body.hasClass("modal-dialog") && !$.contains($('.modal-dialog')[0], self.doc[0])) ? self.hide() : self.show(); // Support for Bootstrap modal; Added check if the nice scroll element is inside a modal
  1673. }
  1674. });
  1675. if (self.me.clientWidth != self.page.width || self.me.clientHeight != self.page.height) return self.lazyResize(30);
  1676. });
  1677. self.observerbody.observe(document.body, {
  1678. childList: true,
  1679. subtree: true,
  1680. characterData: false,
  1681. attributes: true,
  1682. attributeFilter: ['class']
  1683. });
  1684. }
  1685. if (!self.ispage && !self.haswrapper) {
  1686. // redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
  1687. if (ClsMutationObserver !== false) {
  1688. self.observer = new ClsMutationObserver(function (mutations) {
  1689. mutations.forEach(self.onAttributeChange);
  1690. });
  1691. self.observer.observe(self.win[0], {
  1692. childList: true,
  1693. characterData: false,
  1694. attributes: true,
  1695. subtree: false
  1696. });
  1697. self.observerremover = new ClsMutationObserver(function (mutations) {
  1698. mutations.forEach(function (mo) {
  1699. if (mo.removedNodes.length > 0) {
  1700. for (var dd in mo.removedNodes) {
  1701. if (!!self && (mo.removedNodes[dd] == self.win[0])) return self.remove();
  1702. }
  1703. }
  1704. });
  1705. });
  1706. self.observerremover.observe(self.win[0].parentNode, {
  1707. childList: true,
  1708. characterData: false,
  1709. attributes: false,
  1710. subtree: false
  1711. });
  1712. } else {
  1713. self.bind(self.win, (cap.isie && !cap.isie9) ? "propertychange" : "DOMAttrModified", self.onAttributeChange);
  1714. if (cap.isie9) self.win[0].attachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
  1715. self.bind(self.win, "DOMNodeRemoved", function (e) {
  1716. if (e.target == self.win[0]) self.remove();
  1717. });
  1718. }
  1719. }
  1720. }
  1721. //
  1722. if (!self.ispage && self.opt.boxzoom) self.bind(window, "resize", self.resizeZoom);
  1723. if (self.istextarea) {
  1724. self.bind(self.win, "keydown", self.lazyResize);
  1725. self.bind(self.win, "mouseup", self.lazyResize);
  1726. }
  1727. // self.checkrtlmode = true;
  1728. self.lazyResize(30);
  1729. }
  1730. if (this.doc[0].nodeName == 'IFRAME') {
  1731. var oniframeload = function () {
  1732. self.iframexd = false;
  1733. var doc;
  1734. try {
  1735. doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
  1736. var a = doc.domain;
  1737. } catch (e) {
  1738. self.iframexd = true;
  1739. doc = false;
  1740. }
  1741. if (self.iframexd) {
  1742. if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
  1743. return true; //cross-domain - I can't manage this
  1744. }
  1745. self.forcescreen = true;
  1746. if (self.isiframe) {
  1747. self.iframe = {
  1748. "doc": $(doc),
  1749. "html": self.doc.contents().find('html')[0],
  1750. "body": self.doc.contents().find('body')[0]
  1751. };
  1752. self.getContentSize = function () {
  1753. return {
  1754. w: Math.max(self.iframe.html.scrollWidth, self.iframe.body.scrollWidth),
  1755. h: Math.max(self.iframe.html.scrollHeight, self.iframe.body.scrollHeight)
  1756. };
  1757. };
  1758. self.docscroll = $(self.iframe.body); //$(this.contentWindow);
  1759. }
  1760. if (!cap.isios && self.opt.iframeautoresize && !self.isiframe) {
  1761. self.win.scrollTop(0); // reset position
  1762. self.doc.height(""); //reset height to fix browser bug
  1763. var hh = Math.max(doc.getElementsByTagName('html')[0].scrollHeight, doc.body.scrollHeight);
  1764. self.doc.height(hh);
  1765. }
  1766. self.lazyResize(30);
  1767. //if (cap.isie7) self.css($(self.iframe.html), _scrollyhidden);
  1768. self.css($(self.iframe.body), _scrollyhidden);
  1769. if (cap.isios && self.haswrapper) {
  1770. self.css($(doc.body), {
  1771. '-webkit-transform': 'translate3d(0,0,0)'
  1772. }); // avoid iFrame content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/
  1773. }
  1774. if ('contentWindow' in this) {
  1775. self.bind(this.contentWindow, "scroll", self.onscroll); //IE8 & minor
  1776. } else {
  1777. self.bind(doc, "scroll", self.onscroll);
  1778. }
  1779. if (self.opt.enablemousewheel) {
  1780. self.mousewheel(doc, self.onmousewheel);
  1781. }
  1782. if (self.opt.enablekeyboard) self.bind(doc, (cap.isopera) ? "keypress" : "keydown", self.onkeypress);
  1783. if (cap.cantouch) {
  1784. self.bind(doc, "touchstart", self.ontouchstart);
  1785. self.bind(doc, "touchmove", self.ontouchmove);
  1786. }
  1787. else if (self.opt.emulatetouch) {
  1788. self.bind(doc, "mousedown", self.ontouchstart);
  1789. self.bind(doc, "mousemove", function (e) {
  1790. return self.ontouchmove(e, true);
  1791. });
  1792. if (self.opt.grabcursorenabled && cap.cursorgrabvalue) self.css($(doc.body), {
  1793. 'cursor': cap.cursorgrabvalue
  1794. });
  1795. }
  1796. self.bind(doc, "mouseup", self.ontouchend);
  1797. if (self.zoom) {
  1798. if (self.opt.dblclickzoom) self.bind(doc, 'dblclick', self.doZoom);
  1799. if (self.ongesturezoom) self.bind(doc, "gestureend", self.ongesturezoom);
  1800. }
  1801. };
  1802. if (this.doc[0].readyState && this.doc[0].readyState == "complete") {
  1803. setTimeout(function () {
  1804. oniframeload.call(self.doc[0], false);
  1805. }, 500);
  1806. }
  1807. self.bind(this.doc, "load", oniframeload);
  1808. }
  1809. };
  1810. this.showCursor = function (py, px) {
  1811. if (self.cursortimeout) {
  1812. clearTimeout(self.cursortimeout);
  1813. self.cursortimeout = 0;
  1814. }
  1815. if (!self.rail) return;
  1816. if (self.autohidedom) {
  1817. self.autohidedom.stop().css({
  1818. opacity: self.opt.cursoropacitymax
  1819. });
  1820. self.cursoractive = true;
  1821. }
  1822. if (!self.rail.drag || self.rail.drag.pt != 1) {
  1823. if (py !== undefined && py !== false) {
  1824. self.scroll.y = Math.round(py * 1 / self.scrollratio.y);
  1825. }
  1826. if (px !== undefined) {
  1827. self.scroll.x = Math.round(px * 1 / self.scrollratio.x);
  1828. }
  1829. }
  1830. self.cursor.css({
  1831. height: self.cursorheight,
  1832. top: self.scroll.y
  1833. });
  1834. if (self.cursorh) {
  1835. var lx = (self.hasreversehr) ? self.scrollvaluemaxw - self.scroll.x : self.scroll.x;
  1836. (!self.rail.align && self.rail.visibility) ? self.cursorh.css({
  1837. width: self.cursorwidth,
  1838. left: lx + self.rail.width
  1839. }) : self.cursorh.css({
  1840. width: self.cursorwidth,
  1841. left: lx
  1842. });
  1843. self.cursoractive = true;
  1844. }
  1845. if (self.zoom) self.zoom.stop().css({
  1846. opacity: self.opt.cursoropacitymax
  1847. });
  1848. };
  1849. this.hideCursor = function (tm) {
  1850. if (self.cursortimeout) return;
  1851. if (!self.rail) return;
  1852. if (!self.autohidedom) return;
  1853. if (self.hasmousefocus && self.opt.autohidemode == "leave") return;
  1854. self.cursortimeout = setTimeout(function () {
  1855. if (!self.rail.active || !self.showonmouseevent) {
  1856. self.autohidedom.stop().animate({
  1857. opacity: self.opt.cursoropacitymin
  1858. });
  1859. if (self.zoom) self.zoom.stop().animate({
  1860. opacity: self.opt.cursoropacitymin
  1861. });
  1862. self.cursoractive = false;
  1863. }
  1864. self.cursortimeout = 0;
  1865. }, tm || self.opt.hidecursordelay);
  1866. };
  1867. this.noticeCursor = function (tm, py, px) {
  1868. self.showCursor(py, px);
  1869. if (!self.rail.active) self.hideCursor(tm);
  1870. };
  1871. this.getContentSize =
  1872. (self.ispage) ?
  1873. function () {
  1874. return {
  1875. w: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
  1876. h: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
  1877. };
  1878. } : (self.haswrapper) ?
  1879. function () {
  1880. return {
  1881. w: self.doc[0].offsetWidth,
  1882. h: self.doc[0].offsetHeight
  1883. };
  1884. } : function () {
  1885. return {
  1886. w: self.docscroll[0].scrollWidth,
  1887. h: self.docscroll[0].scrollHeight
  1888. };
  1889. };
  1890. this.onResize = function (e, page) {
  1891. if (!self || !self.win) return false;
  1892. if (!self.haswrapper && !self.ispage) {
  1893. if (self.win.css('display') == 'none') {
  1894. if (self.visibility) self.hideRail().hideRailHr();
  1895. return false;
  1896. } else {
  1897. if (!self.hidden && !self.visibility) self.showRail().showRailHr();
  1898. }
  1899. }
  1900. var premaxh = self.page.maxh;
  1901. var premaxw = self.page.maxw;
  1902. var preview = {
  1903. h: self.view.h,
  1904. w: self.view.w
  1905. };
  1906. self.view = {
  1907. w: (self.ispage) ? self.win.width() : self.win[0].clientWidth,
  1908. h: (self.ispage) ? self.win.height() : self.win[0].clientHeight
  1909. };
  1910. self.page = (page) ? page : self.getContentSize();
  1911. self.page.maxh = Math.max(0, self.page.h - self.view.h);
  1912. self.page.maxw = Math.max(0, self.page.w - self.view.w);
  1913. if ((self.page.maxh == premaxh) && (self.page.maxw == premaxw) && (self.view.w == preview.w) && (self.view.h == preview.h)) {
  1914. // test position
  1915. if (!self.ispage) {
  1916. var pos = self.win.offset();
  1917. if (self.lastposition) {
  1918. var lst = self.lastposition;
  1919. if ((lst.top == pos.top) && (lst.left == pos.left)) return self; //nothing to do
  1920. }
  1921. self.lastposition = pos;
  1922. } else {
  1923. return self; //nothing to do
  1924. }
  1925. }
  1926. if (self.page.maxh === 0) {
  1927. self.hideRail();
  1928. self.scrollvaluemax = 0;
  1929. self.scroll.y = 0;
  1930. self.scrollratio.y = 0;
  1931. self.cursorheight = 0;
  1932. self.setScrollTop(0);
  1933. if (self.rail) self.rail.scrollable = false;
  1934. } else {
  1935. self.page.maxh -= (self.opt.railpadding.top + self.opt.railpadding.bottom); //**
  1936. self.rail.scrollable = true;
  1937. }
  1938. if (self.page.maxw === 0) {
  1939. self.hideRailHr();
  1940. self.scrollvaluemaxw = 0;
  1941. self.scroll.x = 0;
  1942. self.scrollratio.x = 0;
  1943. self.cursorwidth = 0;
  1944. self.setScrollLeft(0);
  1945. if (self.railh) {
  1946. self.railh.scrollable = false;
  1947. }
  1948. } else {
  1949. self.page.maxw -= (self.opt.railpadding.left + self.opt.railpadding.right); //**
  1950. if (self.railh) self.railh.scrollable = (self.opt.horizrailenabled);
  1951. }
  1952. self.railslocked = (self.locked) || ((self.page.maxh === 0) && (self.page.maxw === 0));
  1953. if (self.railslocked) {
  1954. if (!self.ispage) self.updateScrollBar(self.view);
  1955. return false;
  1956. }
  1957. if (!self.hidden && !self.visibility) {
  1958. self.showRail().showRailHr();
  1959. }
  1960. else if (self.railh && (!self.hidden && !self.railh.visibility)) self.showRailHr();
  1961. if (self.istextarea && self.win.css('resize') && self.win.css('resize') != 'none') self.view.h -= 20;
  1962. self.cursorheight = Math.min(self.view.h, Math.round(self.view.h * (self.view.h / self.page.h)));
  1963. self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight, self.cursorheight);
  1964. self.cursorwidth = Math.min(self.view.w, Math.round(self.view.w * (self.view.w / self.page.w)));
  1965. self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight, self.cursorwidth);
  1966. self.scrollvaluemax = self.view.h - self.cursorheight - (self.opt.railpadding.top + self.opt.railpadding.bottom); // - self.cursor.hborder //**
  1967. if (self.railh) {
  1968. self.railh.width = (self.page.maxh > 0) ? (self.view.w - self.rail.width) : self.view.w;
  1969. self.scrollvaluemaxw = self.railh.width - self.cursorwidth - (self.opt.railpadding.left + self.opt.railpadding.right); // - self.cursorh.wborder //**
  1970. }
  1971. /*
  1972. if (self.checkrtlmode&&self.railh) {
  1973. self.checkrtlmode = false;
  1974. if (self.opt.rtlmode&&self.scroll.x==0) self.setScrollLeft(self.page.maxw);
  1975. }
  1976. */
  1977. if (!self.ispage) self.updateScrollBar(self.view);
  1978. self.scrollratio = {
  1979. x: (self.page.maxw / self.scrollvaluemaxw),
  1980. y: (self.page.maxh / self.scrollvaluemax)
  1981. };
  1982. var sy = self.getScrollTop();
  1983. if (sy > self.page.maxh) {
  1984. self.doScrollTop(self.page.maxh);
  1985. } else {
  1986. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  1987. self.scroll.x = Math.round(self.getScrollLeft() * (1 / self.scrollratio.x));
  1988. if (self.cursoractive) self.noticeCursor();
  1989. }
  1990. if (self.scroll.y && (self.getScrollTop() == 0)) self.doScrollTo(Math.floor(self.scroll.y * self.scrollratio.y));
  1991. return self;
  1992. };
  1993. this.resize = self.onResize;
  1994. this.hlazyresize = 0;
  1995. this.lazyResize = function (tm) { // event debounce
  1996. if (!self.haswrapper) self.hide();
  1997. if (self.hlazyresize) clearTimeout(self.hlazyresize);
  1998. self.hlazyresize = setTimeout(function () {
  1999. if (self) { self.resize(); self.show(); } // this form mandatory for uglify
  2000. }, 240);
  2001. return self;
  2002. };
  2003. // derived by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
  2004. function _modernWheelEvent(dom, name, fn, bubble) {
  2005. self._bind(dom, name, function (e) {
  2006. var e = (e) ? e : window.event;
  2007. var event = {
  2008. original: e,
  2009. target: e.target || e.srcElement,
  2010. type: "wheel",
  2011. deltaMode: e.type == "MozMousePixelScroll" ? 0 : 1,
  2012. deltaX: 0,
  2013. deltaZ: 0,
  2014. preventDefault: function () {
  2015. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  2016. return false;
  2017. },
  2018. stopImmediatePropagation: function () {
  2019. (e.stopImmediatePropagation) ? e.stopImmediatePropagation() : e.cancelBubble = true;
  2020. }
  2021. };
  2022. if (name == "mousewheel") {
  2023. e.wheelDeltaX && (event.deltaX = -1 / 40 * e.wheelDeltaX);
  2024. e.wheelDeltaY && (event.deltaY = -1 / 40 * e.wheelDeltaY);
  2025. !event.deltaY && !event.deltaX && (event.deltaY = -1 / 40 * e.wheelDelta);
  2026. } else {
  2027. event.deltaY = e.detail;
  2028. }
  2029. return fn.call(dom, event);
  2030. }, bubble);
  2031. }
  2032. this.jqbind = function (dom, name, fn) { // use jquery bind for non-native events (mouseenter/mouseleave)
  2033. self.events.push({
  2034. e: dom,
  2035. n: name,
  2036. f: fn,
  2037. q: true
  2038. });
  2039. $(dom).bind(name, fn);
  2040. };
  2041. this.mousewheel = function (dom, fn, bubble) { // bind mousewheel
  2042. var el = ("jquery" in dom) ? dom[0] : dom;
  2043. if ("onwheel" in document.createElement("div")) { // Modern browsers support "wheel"
  2044. self._bind(el, "wheel", fn, bubble || false);
  2045. } else {
  2046. var wname = (document.onmousewheel !== undefined) ? "mousewheel" : "DOMMouseScroll"; // older Webkit+IE support or older Firefox
  2047. _modernWheelEvent(el, wname, fn, bubble || false);
  2048. if (wname == "DOMMouseScroll") _modernWheelEvent(el, "MozMousePixelScroll", fn, bubble || false); // Firefox legacy
  2049. }
  2050. };
  2051. var passiveSupported = false;
  2052. if (cap.haseventlistener) { // W3C standard event model
  2053. // thanks to https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  2054. try { var options = Object.defineProperty({}, "passive", { get: function () { passiveSupported = !0 } }); window.addEventListener("test", null, options) } catch (err) { }
  2055. this.cancelEvent = function (e) {
  2056. if (!e) return false;
  2057. var e = (e.original) ? e.original : e;
  2058. if (e.cancelable) e.preventDefault();
  2059. e.stopPropagation();
  2060. if (e.preventManipulation) e.preventManipulation(); //IE10
  2061. return false;
  2062. };
  2063. this.stopPropagation = function (e) {
  2064. if (!e) return false;
  2065. var e = (e.original) ? e.original : e;
  2066. e.stopPropagation();
  2067. return false;
  2068. };
  2069. } else {
  2070. // inspired from https://gist.github.com/jonathantneal/2415137
  2071. Event.prototype.preventDefault = function () {
  2072. this.returnValue = false;
  2073. };
  2074. Event.prototype.stopPropagation = function () {
  2075. this.cancelBubble = true;
  2076. };
  2077. window.constructor.prototype.addEventListener = document.constructor.prototype.addEventListener = Element.prototype.addEventListener = function (type, listener, useCapture) {
  2078. this.attachEvent("on" + type, listener);
  2079. }
  2080. window.constructor.prototype.removeEventListener = document.constructor.prototype.removeEventListener = Element.prototype.removeEventListener = function (type, listener, useCapture) {
  2081. this.detachEvent("on" + type, listener);
  2082. }
  2083. // Thanks to http://www.switchonthecode.com !!
  2084. this.cancelEvent = function (e) {
  2085. var e = window.event || false;
  2086. if (!e) return false;
  2087. e.cancelBubble = true;
  2088. e.cancel = true;
  2089. e.returnValue = false;
  2090. return false;
  2091. };
  2092. this.stopPropagation = function (e) {
  2093. var e = window.event || false;
  2094. if (!e) return false;
  2095. e.cancelBubble = true;
  2096. return false;
  2097. };
  2098. }
  2099. this.bind = function (dom, name, fn, bubble, active) { // W3C
  2100. var el = ("jquery" in dom) ? dom[0] : dom;
  2101. self._bind(el, name, fn, bubble || false, active || false);
  2102. };
  2103. this._bind = function (el, name, fn, bubble, active) { // primitive bind
  2104. self.events.push({
  2105. e: el,
  2106. n: name,
  2107. f: fn,
  2108. b: bubble,
  2109. q: false
  2110. });
  2111. (passiveSupported && active) ? el.addEventListener(name, fn, { passive: false, capture: bubble }) : el.addEventListener(name, fn, bubble || false);
  2112. };
  2113. this._unbind = function (el, name, fn, bub) { // primitive unbind
  2114. el.removeEventListener(name, fn, bub);
  2115. };
  2116. this.unbindAll = function () {
  2117. for (var a = 0; a < self.events.length; a++) {
  2118. var r = self.events[a];
  2119. (r.q) ? r.e.unbind(r.n, r.f) : self._unbind(r.e, r.n, r.f, r.b);
  2120. }
  2121. };
  2122. this.showRail = function () {
  2123. if ((self.page.maxh != 0) && (self.ispage || self.win.css('display') != 'none')) {
  2124. self.visibility = true;
  2125. self.rail.visibility = true;
  2126. self.rail.css('display', 'block');
  2127. }
  2128. return self;
  2129. };
  2130. this.showRailHr = function () {
  2131. if (!self.railh) return self;
  2132. if ((self.page.maxw != 0) && (self.ispage || self.win.css('display') != 'none')) {
  2133. self.railh.visibility = true;
  2134. self.railh.css('display', 'block');
  2135. }
  2136. return self;
  2137. };
  2138. this.hideRail = function () {
  2139. self.visibility = false;
  2140. self.rail.visibility = false;
  2141. self.rail.css('display', 'none');
  2142. return self;
  2143. };
  2144. this.hideRailHr = function () {
  2145. if (!self.railh) return self;
  2146. self.railh.visibility = false;
  2147. self.railh.css('display', 'none');
  2148. return self;
  2149. };
  2150. this.show = function () {
  2151. self.hidden = false;
  2152. self.railslocked = false;
  2153. return self.showRail().showRailHr();
  2154. };
  2155. this.hide = function () {
  2156. self.hidden = true;
  2157. self.railslocked = true;
  2158. return self.hideRail().hideRailHr();
  2159. };
  2160. this.toggle = function () {
  2161. return (self.hidden) ? self.show() : self.hide();
  2162. };
  2163. this.remove = function () {
  2164. self.stop();
  2165. if (self.cursortimeout) clearTimeout(self.cursortimeout);
  2166. for (var n in self.delaylist) if (self.delaylist[n]) clearAnimationFrame(self.delaylist[n].h);
  2167. self.doZoomOut();
  2168. self.unbindAll();
  2169. if (cap.isie9) self.win[0].detachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
  2170. if (self.observer !== false) self.observer.disconnect();
  2171. if (self.observerremover !== false) self.observerremover.disconnect();
  2172. if (self.observerbody !== false) self.observerbody.disconnect();
  2173. self.events = null;
  2174. if (self.cursor) {
  2175. self.cursor.remove();
  2176. }
  2177. if (self.cursorh) {
  2178. self.cursorh.remove();
  2179. }
  2180. if (self.rail) {
  2181. self.rail.remove();
  2182. }
  2183. if (self.railh) {
  2184. self.railh.remove();
  2185. }
  2186. if (self.zoom) {
  2187. self.zoom.remove();
  2188. }
  2189. for (var a = 0; a < self.saved.css.length; a++) {
  2190. var d = self.saved.css[a];
  2191. d[0].css(d[1], (d[2] === undefined) ? '' : d[2]);
  2192. }
  2193. self.saved = false;
  2194. self.me.data('__nicescroll', ''); //erase all traces
  2195. // memory leak fixed by GianlucaGuarini - thanks a lot!
  2196. // remove the current nicescroll from the $.nicescroll array & normalize array
  2197. var lst = $.nicescroll;
  2198. lst.each(function (i) {
  2199. if (!this) return;
  2200. if (this.id === self.id) {
  2201. delete lst[i];
  2202. for (var b = ++i; b < lst.length; b++ , i++) lst[i] = lst[b];
  2203. lst.length--;
  2204. if (lst.length) delete lst[lst.length];
  2205. }
  2206. });
  2207. for (var i in self) {
  2208. self[i] = null;
  2209. delete self[i];
  2210. }
  2211. self = null;
  2212. };
  2213. this.scrollstart = function (fn) {
  2214. this.onscrollstart = fn;
  2215. return self;
  2216. };
  2217. this.scrollend = function (fn) {
  2218. this.onscrollend = fn;
  2219. return self;
  2220. };
  2221. this.scrollcancel = function (fn) {
  2222. this.onscrollcancel = fn;
  2223. return self;
  2224. };
  2225. this.zoomin = function (fn) {
  2226. this.onzoomin = fn;
  2227. return self;
  2228. };
  2229. this.zoomout = function (fn) {
  2230. this.onzoomout = fn;
  2231. return self;
  2232. };
  2233. this.isScrollable = function (e) {
  2234. var dom = (e.target) ? e.target : e;
  2235. if (dom.nodeName == 'OPTION') return true;
  2236. while (dom && (dom.nodeType == 1) && (dom !== this.me[0]) && !(/^BODY|HTML/.test(dom.nodeName))) {
  2237. var dd = $(dom);
  2238. var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
  2239. if (/scroll|auto/.test(ov)) return (dom.clientHeight != dom.scrollHeight);
  2240. dom = (dom.parentNode) ? dom.parentNode : false;
  2241. }
  2242. return false;
  2243. };
  2244. this.getViewport = function (me) {
  2245. var dom = (me && me.parentNode) ? me.parentNode : false;
  2246. while (dom && (dom.nodeType == 1) && !(/^BODY|HTML/.test(dom.nodeName))) {
  2247. var dd = $(dom);
  2248. if (/fixed|absolute/.test(dd.css("position"))) return dd;
  2249. var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
  2250. if ((/scroll|auto/.test(ov)) && (dom.clientHeight != dom.scrollHeight)) return dd;
  2251. if (dd.getNiceScroll().length > 0) return dd;
  2252. dom = (dom.parentNode) ? dom.parentNode : false;
  2253. }
  2254. return false; //(dom) ? $(dom) : false;
  2255. };
  2256. this.triggerScrollStart = function (px,py,x,y,ms) {
  2257. var info = {
  2258. "type": "scrollstart",
  2259. "current": {
  2260. "x": px,
  2261. "y": py
  2262. },
  2263. "request": {
  2264. "x": x,
  2265. "y": y
  2266. },
  2267. "end": {
  2268. "x": self.newscrollx,
  2269. "y": self.newscrolly
  2270. },
  2271. "speed": ms
  2272. };
  2273. self.onscrollstart.call(self, info);
  2274. };
  2275. this.triggerScrollEnd = function () {
  2276. if (!self.onscrollend) return;
  2277. var px = self.getScrollLeft();
  2278. var py = self.getScrollTop();
  2279. var info = {
  2280. type: "scrollend",
  2281. current: {
  2282. x: px,
  2283. y: py
  2284. },
  2285. end: {
  2286. x: px,
  2287. y: py
  2288. }
  2289. };
  2290. self.onscrollend.call(self, info);
  2291. };
  2292. function execScrollWheel(e, hr, chkscroll) {
  2293. var px, py;
  2294. if (e.deltaMode == 0) { // PIXEL
  2295. px = -Math.floor(e.deltaX * (self.opt.mousescrollstep / (18 * 3)));
  2296. py = -Math.floor(e.deltaY * (self.opt.mousescrollstep / (18 * 3)));
  2297. } else if (e.deltaMode == 1) { // LINE
  2298. px = -Math.floor(e.deltaX * self.opt.mousescrollstep);
  2299. py = -Math.floor(e.deltaY * self.opt.mousescrollstep);
  2300. }
  2301. if (hr && self.opt.oneaxismousemode && (px === 0) && py) { // classic vertical-only mousewheel + browser with x/y support
  2302. px = py;
  2303. py = 0;
  2304. if (chkscroll) {
  2305. var hrend = (px < 0) ? (self.getScrollLeft() >= self.page.maxw) : (self.getScrollLeft() <= 0);
  2306. if (hrend) { // preserve vertical scrolling
  2307. py = px;
  2308. px = 0;
  2309. }
  2310. }
  2311. }
  2312. // invert horizontal direction for rtl mode
  2313. if (self.isrtlmode) px = -px;
  2314. if (px) {
  2315. if (self.scrollmom) {
  2316. self.scrollmom.stop();
  2317. } else {
  2318. if (px < 0) { // fix apple magic mouse swipe back/forward
  2319. if (self.getScrollLeft() >= self.page.maxw) return true;
  2320. } else {
  2321. if (self.getScrollLeft() <= 0) return true;
  2322. }
  2323. }
  2324. self.lastdeltax += px;
  2325. self.debounced("mousewheelx", function () {
  2326. var dt = self.lastdeltax;
  2327. self.lastdeltax = 0;
  2328. if (!self.rail.drag) {
  2329. self.doScrollLeftBy(dt);
  2330. }
  2331. }, 15);
  2332. }
  2333. if (py) {
  2334. if (self.opt.nativeparentscrolling && chkscroll && !self.ispage && !self.zoomactive) {
  2335. if (py < 0) {
  2336. if (self.getScrollTop() >= self.page.maxh) return true;
  2337. } else {
  2338. if (self.getScrollTop() <= 0) return true;
  2339. }
  2340. }
  2341. if (self.scrollmom) {
  2342. self.scrollmom.stop();
  2343. }
  2344. self.lastdeltay += py;
  2345. // self.debounced("mousewheely", function() {
  2346. self.synched("mousewheely", function () {
  2347. var dt = self.lastdeltay;
  2348. self.lastdeltay = 0;
  2349. if (!self.rail.drag) {
  2350. self.doScrollBy(dt);
  2351. }
  2352. }, 15);
  2353. }
  2354. e.stopImmediatePropagation();
  2355. return e.preventDefault();
  2356. }
  2357. this.onmousewheel = function (e) {
  2358. if (self.wheelprevented) return;
  2359. if (self.railslocked) {
  2360. self.debounced("checkunlock", self.resize, 250);
  2361. return true;
  2362. }
  2363. if (self.rail.drag) return self.cancelEvent(e);
  2364. if (self.opt.oneaxismousemode === "auto" && e.deltaX !== 0) self.opt.oneaxismousemode = false; // check two-axis mouse support (not very elegant)
  2365. if (self.opt.oneaxismousemode && e.deltaX === 0) {
  2366. if (!self.rail.scrollable) {
  2367. if (self.railh && self.railh.scrollable) {
  2368. return self.onmousewheelhr(e);
  2369. } else {
  2370. return true;
  2371. }
  2372. }
  2373. }
  2374. var nw = now();
  2375. var chk = false;
  2376. if (self.opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
  2377. self.nativescrollingarea = self.isScrollable(e);
  2378. chk = true;
  2379. }
  2380. self.checkarea = nw;
  2381. if (self.nativescrollingarea) return true; // this isn't my business
  2382. var ret = execScrollWheel(e, false, chk);
  2383. if (ret) self.checkarea = 0;
  2384. return ret;
  2385. };
  2386. this.onmousewheelhr = function (e) {
  2387. if (self.wheelprevented) return;
  2388. if (self.railslocked || !self.railh.scrollable) return true;
  2389. if (self.rail.drag) return self.cancelEvent(e);
  2390. var nw = now();
  2391. var chk = false;
  2392. if (self.opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
  2393. self.nativescrollingarea = self.isScrollable(e);
  2394. chk = true;
  2395. }
  2396. self.checkarea = nw;
  2397. if (self.nativescrollingarea) return true; // this is not my business
  2398. if (self.railslocked) return self.cancelEvent(e);
  2399. return execScrollWheel(e, true, chk);
  2400. };
  2401. this.stop = function () {
  2402. self.cancelScroll();
  2403. if (self.scrollmon) self.scrollmon.stop();
  2404. self.cursorfreezed = false;
  2405. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  2406. self.noticeCursor();
  2407. return self;
  2408. };
  2409. this.getTransitionSpeed = function (dif) {
  2410. var sp = Math.round(self.opt.scrollspeed * 10);
  2411. var ex = Math.min(sp, Math.round((dif / 20) * self.opt.scrollspeed));
  2412. return (ex > 20) ? ex : 0;
  2413. };
  2414. if (!self.opt.smoothscroll) {
  2415. this.doScrollLeft = function (x, spd) { //direct
  2416. var y = self.getScrollTop();
  2417. self.doScrollPos(x, y, spd);
  2418. };
  2419. this.doScrollTop = function (y, spd) { //direct
  2420. var x = self.getScrollLeft();
  2421. self.doScrollPos(x, y, spd);
  2422. };
  2423. this.doScrollPos = function (x, y, spd) { //direct
  2424. var nx = (x > self.page.maxw) ? self.page.maxw : x;
  2425. if (nx < 0) nx = 0;
  2426. var ny = (y > self.page.maxh) ? self.page.maxh : y;
  2427. if (ny < 0) ny = 0;
  2428. self.synched('scroll', function () {
  2429. self.setScrollTop(ny);
  2430. self.setScrollLeft(nx);
  2431. });
  2432. };
  2433. this.cancelScroll = function () { }; // direct
  2434. } else if (self.ishwscroll && cap.hastransition && self.opt.usetransition && !!self.opt.smoothscroll) {
  2435. this.prepareTransition = function (dif, istime) {
  2436. var ex = (istime) ? ((dif > 20) ? dif : 0) : self.getTransitionSpeed(dif);
  2437. var trans = (ex) ? cap.prefixstyle + 'transform ' + ex + 'ms ease-out' : '';
  2438. if (!self.lasttransitionstyle || self.lasttransitionstyle != trans) {
  2439. self.lasttransitionstyle = trans;
  2440. self.doc.css(cap.transitionstyle, trans);
  2441. }
  2442. return ex;
  2443. };
  2444. this.doScrollLeft = function (x, spd) { //trans
  2445. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  2446. self.doScrollPos(x, y, spd);
  2447. };
  2448. this.doScrollTop = function (y, spd) { //trans
  2449. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  2450. self.doScrollPos(x, y, spd);
  2451. };
  2452. this.doScrollPos = function (x, y, spd) { //trans
  2453. var py = self.getScrollTop();
  2454. var px = self.getScrollLeft();
  2455. if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection
  2456. if (self.opt.bouncescroll == false) {
  2457. if (y < 0) y = 0;
  2458. else if (y > self.page.maxh) y = self.page.maxh;
  2459. if (x < 0) x = 0;
  2460. else if (x > self.page.maxw) x = self.page.maxw;
  2461. }
  2462. if (self.scrollrunning && x == self.newscrollx && y == self.newscrolly) return false;
  2463. self.newscrolly = y;
  2464. self.newscrollx = x;
  2465. self.newscrollspeed = spd || false;
  2466. if (self.timer) return false;
  2467. self.timer = setTimeout(function () {
  2468. var top = self.getScrollTop();
  2469. var lft = self.getScrollLeft();
  2470. var dst = {};
  2471. dst.x = x - lft;
  2472. dst.y = y - top;
  2473. dst.px = lft;
  2474. dst.py = top;
  2475. var dd = Math.round(Math.sqrt(Math.pow(dst.x, 2) + Math.pow(dst.y, 2)));
  2476. var ms = (self.newscrollspeed && self.newscrollspeed > 1) ? self.newscrollspeed : self.getTransitionSpeed(dd);
  2477. if (self.newscrollspeed && self.newscrollspeed <= 1) ms *= self.newscrollspeed;
  2478. self.prepareTransition(ms, true);
  2479. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2480. if (ms > 0) {
  2481. if (!self.scrollrunning && self.onscrollstart) {
  2482. self.triggerScrollStart(lft,top,x,y,ms);
  2483. }
  2484. if (cap.transitionend) {
  2485. if (!self.scrollendtrapped) {
  2486. self.scrollendtrapped = true;
  2487. self.bind(self.doc, cap.transitionend, self.onScrollTransitionEnd, false); //I have got to do something usefull!!
  2488. }
  2489. } else {
  2490. if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
  2491. self.scrollendtrapped = setTimeout(self.onScrollTransitionEnd, ms); // simulate transitionend event
  2492. }
  2493. var py = top;
  2494. var px = lft;
  2495. self.timerscroll = {
  2496. bz: new BezierClass(py, self.newscrolly, ms, 0, 0, 0.58, 1),
  2497. bh: new BezierClass(px, self.newscrollx, ms, 0, 0, 0.58, 1)
  2498. };
  2499. if (!self.cursorfreezed) self.timerscroll.tm = setInterval(function () {
  2500. self.showCursor(self.getScrollTop(), self.getScrollLeft());
  2501. }, 60);
  2502. }
  2503. self.synched("doScroll-set", function () {
  2504. self.timer = 0;
  2505. if (self.scrollendtrapped) self.scrollrunning = true;
  2506. self.setScrollTop(self.newscrolly);
  2507. self.setScrollLeft(self.newscrollx);
  2508. if (!self.scrollendtrapped) self.onScrollTransitionEnd();
  2509. });
  2510. }, 50);
  2511. };
  2512. this.cancelScroll = function () {
  2513. if (!self.scrollendtrapped) return true;
  2514. var py = self.getScrollTop();
  2515. var px = self.getScrollLeft();
  2516. self.scrollrunning = false;
  2517. if (!cap.transitionend) clearTimeout(cap.transitionend);
  2518. self.scrollendtrapped = false;
  2519. self._unbind(self.doc[0], cap.transitionend, self.onScrollTransitionEnd);
  2520. self.prepareTransition(0);
  2521. self.setScrollTop(py); // fire event onscroll
  2522. if (self.railh) self.setScrollLeft(px);
  2523. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2524. self.timerscroll = false;
  2525. self.cursorfreezed = false;
  2526. self.showCursor(py, px);
  2527. return self;
  2528. };
  2529. this.onScrollTransitionEnd = function () {
  2530. if (self.scrollendtrapped) self._unbind(self.doc[0], cap.transitionend, self.onScrollTransitionEnd);
  2531. self.scrollendtrapped = false;
  2532. self.prepareTransition(0);
  2533. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2534. self.timerscroll = false;
  2535. var py = self.getScrollTop();
  2536. var px = self.getScrollLeft();
  2537. self.setScrollTop(py); // fire event onscroll
  2538. if (self.railh) self.setScrollLeft(px); // fire event onscroll left
  2539. self.noticeCursor(false, py, px);
  2540. self.cursorfreezed = false;
  2541. if (py < 0) py = 0;
  2542. else if (py > self.page.maxh) py = self.page.maxh;
  2543. if (px < 0) px = 0;
  2544. else if (px > self.page.maxw) px = self.page.maxw;
  2545. if ((py != self.newscrolly) || (px != self.newscrollx)) return self.doScrollPos(px, py, self.opt.snapbackspeed);
  2546. if (self.onscrollend && self.scrollrunning) {
  2547. self.triggerScrollEnd();
  2548. }
  2549. self.scrollrunning = false;
  2550. };
  2551. } else {
  2552. this.doScrollLeft = function (x, spd) { //no-trans
  2553. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  2554. self.doScrollPos(x, y, spd);
  2555. };
  2556. this.doScrollTop = function (y, spd) { //no-trans
  2557. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  2558. self.doScrollPos(x, y, spd);
  2559. };
  2560. this.doScrollPos = function (x, y, spd) { //no-trans
  2561. var y = (y === undefined || y === false) ? self.getScrollTop(true) : y;
  2562. if ((self.timer) && (self.newscrolly == y) && (self.newscrollx == x)) return true;
  2563. if (self.timer) clearAnimationFrame(self.timer);
  2564. self.timer = 0;
  2565. var py = self.getScrollTop();
  2566. var px = self.getScrollLeft();
  2567. if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection
  2568. self.newscrolly = y;
  2569. self.newscrollx = x;
  2570. if (!self.bouncescroll || !self.rail.visibility) {
  2571. if (self.newscrolly < 0) {
  2572. self.newscrolly = 0;
  2573. } else if (self.newscrolly > self.page.maxh) {
  2574. self.newscrolly = self.page.maxh;
  2575. }
  2576. }
  2577. if (!self.bouncescroll || !self.railh.visibility) {
  2578. if (self.newscrollx < 0) {
  2579. self.newscrollx = 0;
  2580. } else if (self.newscrollx > self.page.maxw) {
  2581. self.newscrollx = self.page.maxw;
  2582. }
  2583. }
  2584. self.dst = {};
  2585. self.dst.x = x - px;
  2586. self.dst.y = y - py;
  2587. self.dst.px = px;
  2588. self.dst.py = py;
  2589. var dst = Math.round(Math.sqrt(Math.pow(self.dst.x, 2) + Math.pow(self.dst.y, 2)));
  2590. self.dst.ax = self.dst.x / dst;
  2591. self.dst.ay = self.dst.y / dst;
  2592. var pa = 0;
  2593. var pe = dst;
  2594. if (self.dst.x == 0) {
  2595. pa = py;
  2596. pe = y;
  2597. self.dst.ay = 1;
  2598. self.dst.py = 0;
  2599. } else if (self.dst.y == 0) {
  2600. pa = px;
  2601. pe = x;
  2602. self.dst.ax = 1;
  2603. self.dst.px = 0;
  2604. }
  2605. var ms = self.getTransitionSpeed(dst);
  2606. if (spd && spd <= 1) ms *= spd;
  2607. if (ms > 0) {
  2608. self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe, ms) : new BezierClass(pa, pe, ms, 0, 1, 0, 1);
  2609. } else {
  2610. self.bzscroll = false;
  2611. }
  2612. if (self.timer) return;
  2613. if ((py == self.page.maxh && y >= self.page.maxh) || (px == self.page.maxw && x >= self.page.maxw)) self.checkContentSize();
  2614. var sync = 1;
  2615. function scrolling() {
  2616. if (self.cancelAnimationFrame) return true;
  2617. self.scrollrunning = true;
  2618. sync = 1 - sync;
  2619. if (sync) return (self.timer = setAnimationFrame(scrolling) || 1);
  2620. var done = 0;
  2621. var sx, sy;
  2622. var sc = sy = self.getScrollTop();
  2623. if (self.dst.ay) {
  2624. sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow() * self.dst.ay) : self.newscrolly;
  2625. var dr = sc - sy;
  2626. if ((dr < 0 && sc < self.newscrolly) || (dr > 0 && sc > self.newscrolly)) sc = self.newscrolly;
  2627. self.setScrollTop(sc);
  2628. if (sc == self.newscrolly) done = 1;
  2629. } else {
  2630. done = 1;
  2631. }
  2632. var scx = sx = self.getScrollLeft();
  2633. if (self.dst.ax) {
  2634. scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow() * self.dst.ax) : self.newscrollx;
  2635. var dr = scx - sx;
  2636. if ((dr < 0 && scx < self.newscrollx) || (dr > 0 && scx > self.newscrollx)) scx = self.newscrollx;
  2637. self.setScrollLeft(scx);
  2638. if (scx == self.newscrollx) done += 1;
  2639. } else {
  2640. done += 1;
  2641. }
  2642. if (done == 2) {
  2643. self.timer = 0;
  2644. self.cursorfreezed = false;
  2645. self.bzscroll = false;
  2646. self.scrollrunning = false;
  2647. if (sc < 0) sc = 0;
  2648. else if (sc > self.page.maxh) sc = Math.max(0, self.page.maxh);
  2649. if (scx < 0) scx = 0;
  2650. else if (scx > self.page.maxw) scx = self.page.maxw;
  2651. if ((scx != self.newscrollx) || (sc != self.newscrolly)) self.doScrollPos(scx, sc);
  2652. else {
  2653. if (self.onscrollend) {
  2654. self.triggerScrollEnd();
  2655. }
  2656. }
  2657. } else {
  2658. self.timer = setAnimationFrame(scrolling) || 1;
  2659. }
  2660. }
  2661. self.cancelAnimationFrame = false;
  2662. self.timer = 1;
  2663. if (self.onscrollstart && !self.scrollrunning) {
  2664. self.triggerScrollStart(px,py,x,y,ms);
  2665. }
  2666. scrolling();
  2667. if ((py == self.page.maxh && y >= py) || (px == self.page.maxw && x >= px)) self.checkContentSize();
  2668. self.noticeCursor();
  2669. };
  2670. this.cancelScroll = function () {
  2671. if (self.timer) clearAnimationFrame(self.timer);
  2672. self.timer = 0;
  2673. self.bzscroll = false;
  2674. self.scrollrunning = false;
  2675. return self;
  2676. };
  2677. }
  2678. this.doScrollBy = function (stp, relative) {
  2679. var ny = 0;
  2680. if (relative) {
  2681. ny = Math.floor((self.scroll.y - stp) * self.scrollratio.y);
  2682. } else {
  2683. var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
  2684. ny = sy - stp;
  2685. }
  2686. if (self.bouncescroll) {
  2687. var haf = Math.round(self.view.h / 2);
  2688. if (ny < -haf) ny = -haf;
  2689. else if (ny > (self.page.maxh + haf)) ny = (self.page.maxh + haf);
  2690. }
  2691. self.cursorfreezed = false;
  2692. var py = self.getScrollTop(true);
  2693. if (ny < 0 && py <= 0) return self.noticeCursor();
  2694. else if (ny > self.page.maxh && py >= self.page.maxh) {
  2695. self.checkContentSize();
  2696. return self.noticeCursor();
  2697. }
  2698. self.doScrollTop(ny);
  2699. };
  2700. this.doScrollLeftBy = function (stp, relative) {
  2701. var nx = 0;
  2702. if (relative) {
  2703. nx = Math.floor((self.scroll.x - stp) * self.scrollratio.x);
  2704. } else {
  2705. var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
  2706. nx = sx - stp;
  2707. }
  2708. if (self.bouncescroll) {
  2709. var haf = Math.round(self.view.w / 2);
  2710. if (nx < -haf) nx = -haf;
  2711. else if (nx > (self.page.maxw + haf)) nx = (self.page.maxw + haf);
  2712. }
  2713. self.cursorfreezed = false;
  2714. var px = self.getScrollLeft(true);
  2715. if (nx < 0 && px <= 0) return self.noticeCursor();
  2716. else if (nx > self.page.maxw && px >= self.page.maxw) return self.noticeCursor();
  2717. self.doScrollLeft(nx);
  2718. };
  2719. this.doScrollTo = function (pos, relative) {
  2720. var ny = (relative) ? Math.round(pos * self.scrollratio.y) : pos;
  2721. if (ny < 0) ny = 0;
  2722. else if (ny > self.page.maxh) ny = self.page.maxh;
  2723. self.cursorfreezed = false;
  2724. self.doScrollTop(pos);
  2725. };
  2726. this.checkContentSize = function () {
  2727. var pg = self.getContentSize();
  2728. if ((pg.h != self.page.h) || (pg.w != self.page.w)) self.resize(false, pg);
  2729. };
  2730. self.onscroll = function (e) {
  2731. if (self.rail.drag) return;
  2732. if (!self.cursorfreezed) {
  2733. self.synched('scroll', function () {
  2734. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  2735. if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1 / self.scrollratio.x));
  2736. self.noticeCursor();
  2737. });
  2738. }
  2739. //self.triggerScrollEnd();
  2740. };
  2741. self.bind(self.docscroll, "scroll", self.onscroll);
  2742. this.doZoomIn = function (e) {
  2743. if (self.zoomactive) return;
  2744. self.zoomactive = true;
  2745. self.zoomrestore = {
  2746. style: {}
  2747. };
  2748. var lst = ['position', 'top', 'left', 'zIndex', 'backgroundColor', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight'];
  2749. var win = self.win[0].style;
  2750. for (var a in lst) {
  2751. var pp = lst[a];
  2752. self.zoomrestore.style[pp] = (win[pp] !== undefined) ? win[pp] : '';
  2753. }
  2754. self.zoomrestore.style.width = self.win.css('width');
  2755. self.zoomrestore.style.height = self.win.css('height');
  2756. self.zoomrestore.padding = {
  2757. w: self.win.outerWidth() - self.win.width(),
  2758. h: self.win.outerHeight() - self.win.height()
  2759. };
  2760. if (cap.isios4) {
  2761. self.zoomrestore.scrollTop = $window.scrollTop();
  2762. $window.scrollTop(0);
  2763. }
  2764. self.win.css({
  2765. position: (cap.isios4) ? "absolute" : "fixed",
  2766. top: 0,
  2767. left: 0,
  2768. zIndex: globalmaxzindex + 100,
  2769. margin: 0
  2770. });
  2771. var bkg = self.win.css("backgroundColor");
  2772. if (bkg == "" || /transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor", "#fff");
  2773. self.rail.css({
  2774. zIndex: globalmaxzindex + 101
  2775. });
  2776. self.zoom.css({
  2777. zIndex: globalmaxzindex + 102
  2778. });
  2779. self.zoom.css('backgroundPosition', '0 -18px');
  2780. self.resizeZoom();
  2781. if (self.onzoomin) self.onzoomin.call(self);
  2782. return self.cancelEvent(e);
  2783. };
  2784. this.doZoomOut = function (e) {
  2785. if (!self.zoomactive) return;
  2786. self.zoomactive = false;
  2787. self.win.css("margin", "");
  2788. self.win.css(self.zoomrestore.style);
  2789. if (cap.isios4) {
  2790. $window.scrollTop(self.zoomrestore.scrollTop);
  2791. }
  2792. self.rail.css({
  2793. "z-index": self.zindex
  2794. });
  2795. self.zoom.css({
  2796. "z-index": self.zindex
  2797. });
  2798. self.zoomrestore = false;
  2799. self.zoom.css('backgroundPosition', '0 0');
  2800. self.onResize();
  2801. if (self.onzoomout) self.onzoomout.call(self);
  2802. return self.cancelEvent(e);
  2803. };
  2804. this.doZoom = function (e) {
  2805. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  2806. };
  2807. this.resizeZoom = function () {
  2808. if (!self.zoomactive) return;
  2809. var py = self.getScrollTop(); //preserve scrolling position
  2810. self.win.css({
  2811. width: $window.width() - self.zoomrestore.padding.w + "px",
  2812. height: $window.height() - self.zoomrestore.padding.h + "px"
  2813. });
  2814. self.onResize();
  2815. self.setScrollTop(Math.min(self.page.maxh, py));
  2816. };
  2817. this.init();
  2818. $.nicescroll.push(this);
  2819. };
  2820. // Inspired by the work of Kin Blas
  2821. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  2822. var ScrollMomentumClass2D = function (nc) {
  2823. var self = this;
  2824. this.nc = nc;
  2825. this.lastx = 0;
  2826. this.lasty = 0;
  2827. this.speedx = 0;
  2828. this.speedy = 0;
  2829. this.lasttime = 0;
  2830. this.steptime = 0;
  2831. this.snapx = false;
  2832. this.snapy = false;
  2833. this.demulx = 0;
  2834. this.demuly = 0;
  2835. this.lastscrollx = -1;
  2836. this.lastscrolly = -1;
  2837. this.chkx = 0;
  2838. this.chky = 0;
  2839. this.timer = 0;
  2840. this.reset = function (px, py) {
  2841. self.stop();
  2842. self.steptime = 0;
  2843. self.lasttime = now();
  2844. self.speedx = 0;
  2845. self.speedy = 0;
  2846. self.lastx = px;
  2847. self.lasty = py;
  2848. self.lastscrollx = -1;
  2849. self.lastscrolly = -1;
  2850. };
  2851. this.update = function (px, py) {
  2852. var tm = now();
  2853. self.steptime = tm - self.lasttime;
  2854. self.lasttime = tm;
  2855. var dy = py - self.lasty;
  2856. var dx = px - self.lastx;
  2857. var sy = self.nc.getScrollTop();
  2858. var sx = self.nc.getScrollLeft();
  2859. var newy = sy + dy;
  2860. var newx = sx + dx;
  2861. self.snapx = (newx < 0) || (newx > self.nc.page.maxw);
  2862. self.snapy = (newy < 0) || (newy > self.nc.page.maxh);
  2863. self.speedx = dx;
  2864. self.speedy = dy;
  2865. self.lastx = px;
  2866. self.lasty = py;
  2867. };
  2868. this.stop = function () {
  2869. self.nc.unsynched("domomentum2d");
  2870. if (self.timer) clearTimeout(self.timer);
  2871. self.timer = 0;
  2872. self.lastscrollx = -1;
  2873. self.lastscrolly = -1;
  2874. };
  2875. this.doSnapy = function (nx, ny) {
  2876. var snap = false;
  2877. if (ny < 0) {
  2878. ny = 0;
  2879. snap = true;
  2880. } else if (ny > self.nc.page.maxh) {
  2881. ny = self.nc.page.maxh;
  2882. snap = true;
  2883. }
  2884. if (nx < 0) {
  2885. nx = 0;
  2886. snap = true;
  2887. } else if (nx > self.nc.page.maxw) {
  2888. nx = self.nc.page.maxw;
  2889. snap = true;
  2890. }
  2891. (snap) ? self.nc.doScrollPos(nx, ny, self.nc.opt.snapbackspeed) : self.nc.triggerScrollEnd();
  2892. };
  2893. this.doMomentum = function (gp) {
  2894. var t = now();
  2895. var l = (gp) ? t + gp : self.lasttime;
  2896. var sl = self.nc.getScrollLeft();
  2897. var st = self.nc.getScrollTop();
  2898. var pageh = self.nc.page.maxh;
  2899. var pagew = self.nc.page.maxw;
  2900. self.speedx = (pagew > 0) ? Math.min(60, self.speedx) : 0;
  2901. self.speedy = (pageh > 0) ? Math.min(60, self.speedy) : 0;
  2902. var chk = l && (t - l) <= 60;
  2903. if ((st < 0) || (st > pageh) || (sl < 0) || (sl > pagew)) chk = false;
  2904. var sy = (self.speedy && chk) ? self.speedy : false;
  2905. var sx = (self.speedx && chk) ? self.speedx : false;
  2906. if (sy || sx) {
  2907. var tm = Math.max(16, self.steptime); //timeout granularity
  2908. if (tm > 50) { // do smooth
  2909. var xm = tm / 50;
  2910. self.speedx *= xm;
  2911. self.speedy *= xm;
  2912. tm = 50;
  2913. }
  2914. self.demulxy = 0;
  2915. self.lastscrollx = self.nc.getScrollLeft();
  2916. self.chkx = self.lastscrollx;
  2917. self.lastscrolly = self.nc.getScrollTop();
  2918. self.chky = self.lastscrolly;
  2919. var nx = self.lastscrollx;
  2920. var ny = self.lastscrolly;
  2921. var onscroll = function () {
  2922. var df = ((now() - t) > 600) ? 0.04 : 0.02;
  2923. if (self.speedx) {
  2924. nx = Math.floor(self.lastscrollx - (self.speedx * (1 - self.demulxy)));
  2925. self.lastscrollx = nx;
  2926. if ((nx < 0) || (nx > pagew)) df = 0.10;
  2927. }
  2928. if (self.speedy) {
  2929. ny = Math.floor(self.lastscrolly - (self.speedy * (1 - self.demulxy)));
  2930. self.lastscrolly = ny;
  2931. if ((ny < 0) || (ny > pageh)) df = 0.10;
  2932. }
  2933. self.demulxy = Math.min(1, self.demulxy + df);
  2934. self.nc.synched("domomentum2d", function () {
  2935. if (self.speedx) {
  2936. var scx = self.nc.getScrollLeft();
  2937. // if (scx != self.chkx) self.stop();
  2938. self.chkx = nx;
  2939. self.nc.setScrollLeft(nx);
  2940. }
  2941. if (self.speedy) {
  2942. var scy = self.nc.getScrollTop();
  2943. // if (scy != self.chky) self.stop();
  2944. self.chky = ny;
  2945. self.nc.setScrollTop(ny);
  2946. }
  2947. if (!self.timer) {
  2948. self.nc.hideCursor();
  2949. self.doSnapy(nx, ny);
  2950. }
  2951. });
  2952. if (self.demulxy < 1) {
  2953. self.timer = setTimeout(onscroll, tm);
  2954. } else {
  2955. self.stop();
  2956. self.nc.hideCursor();
  2957. self.doSnapy(nx, ny);
  2958. }
  2959. };
  2960. onscroll();
  2961. } else {
  2962. self.doSnapy(self.nc.getScrollLeft(), self.nc.getScrollTop());
  2963. }
  2964. };
  2965. };
  2966. // override jQuery scrollTop
  2967. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  2968. jQuery.cssHooks.pageYOffset = {
  2969. get: function (elem, computed, extra) {
  2970. var nice = $.data(elem, '__nicescroll') || false;
  2971. return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  2972. },
  2973. set: function (elem, value) {
  2974. var nice = $.data(elem, '__nicescroll') || false;
  2975. (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem, value);
  2976. return this;
  2977. }
  2978. };
  2979. /*
  2980. $.fx.step["scrollTop"] = function(fx){
  2981. $.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
  2982. };
  2983. */
  2984. jQuery.fn.scrollTop = function (value) {
  2985. if (value === undefined) {
  2986. var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
  2987. return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  2988. } else {
  2989. return this.each(function () {
  2990. var nice = $.data(this, '__nicescroll') || false;
  2991. (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this), value);
  2992. });
  2993. }
  2994. };
  2995. // override jQuery scrollLeft
  2996. var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
  2997. $.cssHooks.pageXOffset = {
  2998. get: function (elem, computed, extra) {
  2999. var nice = $.data(elem, '__nicescroll') || false;
  3000. return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
  3001. },
  3002. set: function (elem, value) {
  3003. var nice = $.data(elem, '__nicescroll') || false;
  3004. (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem, value);
  3005. return this;
  3006. }
  3007. };
  3008. /*
  3009. $.fx.step["scrollLeft"] = function(fx){
  3010. $.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
  3011. };
  3012. */
  3013. jQuery.fn.scrollLeft = function (value) {
  3014. if (value === undefined) {
  3015. var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
  3016. return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
  3017. } else {
  3018. return this.each(function () {
  3019. var nice = $.data(this, '__nicescroll') || false;
  3020. (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this), value);
  3021. });
  3022. }
  3023. };
  3024. var NiceScrollArray = function (doms) {
  3025. var self = this;
  3026. this.length = 0;
  3027. this.name = "nicescrollarray";
  3028. this.each = function (fn) {
  3029. $.each(self, fn);
  3030. return self;
  3031. };
  3032. this.push = function (nice) {
  3033. self[self.length] = nice;
  3034. self.length++;
  3035. };
  3036. this.eq = function (idx) {
  3037. return self[idx];
  3038. };
  3039. if (doms) {
  3040. for (var a = 0; a < doms.length; a++) {
  3041. var nice = $.data(doms[a], '__nicescroll') || false;
  3042. if (nice) {
  3043. this[this.length] = nice;
  3044. this.length++;
  3045. }
  3046. }
  3047. }
  3048. return this;
  3049. };
  3050. function mplex(el, lst, fn) {
  3051. for (var a = 0, l = lst.length; a < l; a++) fn(el, lst[a]);
  3052. }
  3053. mplex(
  3054. NiceScrollArray.prototype, ['show', 'hide', 'toggle', 'onResize', 'resize', 'remove', 'stop', 'doScrollPos'],
  3055. function (e, n) {
  3056. e[n] = function () {
  3057. var args = arguments;
  3058. return this.each(function () {
  3059. this[n].apply(this, args);
  3060. });
  3061. };
  3062. }
  3063. );
  3064. jQuery.fn.getNiceScroll = function (index) {
  3065. if (index === undefined) {
  3066. return new NiceScrollArray(this);
  3067. } else {
  3068. return this[index] && $.data(this[index], '__nicescroll') || false;
  3069. }
  3070. };
  3071. jQuery.expr[':'].nicescroll = function (a) {
  3072. return $.data(a, '__nicescroll') !== undefined;
  3073. };
  3074. $.fn.niceScroll = function (wrapper, _opt) {
  3075. if (_opt === undefined && typeof wrapper == "object" && !("jquery" in wrapper)) {
  3076. _opt = wrapper;
  3077. wrapper = false;
  3078. }
  3079. var ret = new NiceScrollArray();
  3080. this.each(function () {
  3081. var $this = $(this);
  3082. var opt = $.extend({}, _opt); // cloning
  3083. if (wrapper || false) {
  3084. var wrp = $(wrapper);
  3085. opt.doc = (wrp.length > 1) ? $(wrapper, $this) : wrp;
  3086. opt.win = $this;
  3087. }
  3088. var docundef = !("doc" in opt);
  3089. if (!docundef && !("win" in opt)) opt.win = $this;
  3090. var nice = $this.data('__nicescroll') || false;
  3091. if (!nice) {
  3092. opt.doc = opt.doc || $this;
  3093. nice = new NiceScrollClass(opt, $this);
  3094. $this.data('__nicescroll', nice);
  3095. }
  3096. ret.push(nice);
  3097. });
  3098. return (ret.length === 1) ? ret[0] : ret;
  3099. };
  3100. window.NiceScroll = {
  3101. getjQuery: function () {
  3102. return jQuery;
  3103. }
  3104. };
  3105. if (!$.nicescroll) {
  3106. $.nicescroll = new NiceScrollArray();
  3107. $.nicescroll.options = _globaloptions;
  3108. }
  3109. }));