jquery.nicescroll.js 128 KB

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