jquery.nicescroll.js 121 KB

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