jquery.nicescroll.js 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970
  1. /* jquery.nicescroll
  2. -- version 3.1.9
  3. -- copyright 2011-12-13 InuYaksa*2013
  4. -- licensed under the MIT
  5. --
  6. -- http://areaaperta.com/nicescroll
  7. -- https://github.com/inuyaksa/jquery.nicescroll
  8. --
  9. */
  10. (function(jQuery){
  11. // globals
  12. var domfocus = false;
  13. var mousefocus = false;
  14. var zoomactive = false;
  15. var tabindexcounter = 5000;
  16. var ascrailcounter = 2000;
  17. var $ = jQuery; // sandbox
  18. // http://stackoverflow.com/questions/2161159/get-script-path
  19. function getScriptPath() {
  20. var scripts=document.getElementsByTagName('script');
  21. var path=scripts[scripts.length-1].src.split('?')[0];
  22. return (path.split('/').length>0) ? path.split('/').slice(0,-1).join('/')+'/' : '';
  23. }
  24. var scriptpath = getScriptPath();
  25. // derived by http://blog.joelambert.co.uk/2011/06/01/a-better-settimeoutsetinterval/
  26. var setAnimationFrame = (function(){
  27. return window.requestAnimationFrame ||
  28. window.webkitRequestAnimationFrame ||
  29. window.mozRequestAnimationFrame ||
  30. window.oRequestAnimationFrame ||
  31. window.msRequestAnimationFrame ||
  32. false;
  33. })();
  34. var clearAnimationFrame = (function(){
  35. return window.cancelRequestAnimationFrame ||
  36. window.webkitCancelRequestAnimationFrame ||
  37. window.mozCancelRequestAnimationFrame ||
  38. window.oCancelRequestAnimationFrame ||
  39. window.msCancelRequestAnimationFrame ||
  40. false;
  41. })();
  42. var _globaloptions = {
  43. zindex:"auto",
  44. cursoropacitymin:0,
  45. cursoropacitymax:1,
  46. cursorcolor:"#424242",
  47. cursorwidth:"5px",
  48. cursorborder:"1px solid #fff",
  49. cursorborderradius:"5px",
  50. scrollspeed:60,
  51. mousescrollstep:8*3,
  52. touchbehavior:false,
  53. hwacceleration:true,
  54. usetransition:true,
  55. boxzoom:false,
  56. dblclickzoom:true,
  57. gesturezoom:true,
  58. grabcursorenabled:true,
  59. autohidemode:true,
  60. background:"",
  61. iframeautoresize:true,
  62. cursorminheight:32,
  63. preservenativescrolling:true,
  64. railoffset:false,
  65. bouncescroll:true,
  66. spacebarenabled:true,
  67. railpadding:{top:0,right:0,left:0,bottom:0},
  68. disableoutline:true,
  69. horizrailenabled:true,
  70. railalign:"right",
  71. railvalign:"bottom",
  72. enabletranslate3d:true,
  73. enablemousewheel:true,
  74. enablekeyboard:true,
  75. smoothscroll:true,
  76. sensitiverail:true,
  77. enablemouselockapi:true,
  78. // cursormaxheight:false,
  79. cursorfixedheight:false,
  80. directionlockdeadzone:6,
  81. hidecursordelay:400,
  82. nativeparentscrolling:true
  83. }
  84. var browserdetected = false;
  85. var getBrowserDetection = function() {
  86. if (browserdetected) return browserdetected;
  87. var domtest = document.createElement('DIV');
  88. var d = {};
  89. d.haspointerlock = "pointerLockElement" in document || "mozPointerLockElement" in document || "webkitPointerLockElement" in document;
  90. d.isopera = ("opera" in window);
  91. d.isopera12 = (d.isopera&&("getUserMedia" in navigator));
  92. d.isie = (("all" in document) && ("attachEvent" in domtest) && !d.isopera);
  93. d.isieold = (d.isie && !("msInterpolationMode" in domtest.style)); // IE6 and older
  94. d.isie7 = d.isie&&!d.isieold&&(!("documentMode" in document)||(document.documentMode==7));
  95. d.isie8 = d.isie&&("documentMode" in document)&&(document.documentMode==8);
  96. d.isie9 = d.isie&&("performance" in window)&&(document.documentMode>=9);
  97. d.isie10 = d.isie&&("performance" in window)&&(document.documentMode>=10);
  98. d.isie9mobile = /iemobile.9/i.test(navigator.userAgent); //wp 7.1 mango
  99. if (d.isie9mobile) d.isie9 = false;
  100. d.isie7mobile = (!d.isie9mobile&&d.isie7) && /iemobile/i.test(navigator.userAgent); //wp 7.0
  101. d.ismozilla = ("MozAppearance" in domtest.style);
  102. d.iswebkit = ("WebkitAppearance" in domtest.style);
  103. d.ischrome = ("chrome" in window);
  104. d.ischrome22 = (d.ischrome&&d.haspointerlock);
  105. d.cantouch = ("ontouchstart" in document.documentElement)||("ontouchstart" in window); // detection for Chrome Touch Emulation
  106. d.hasmstouch = (window.navigator.msPointerEnabled||false); // IE10+ pointer events
  107. d.ismac = /^mac$/i.test(navigator.platform);
  108. d.isios = (d.cantouch && /iphone|ipad|ipod/i.test(navigator.platform));
  109. d.isios4 = ((d.isios)&&!("seal" in Object));
  110. d.isandroid = (/android/i.test(navigator.userAgent));
  111. d.trstyle = false;
  112. d.hastransform = false;
  113. d.hastranslate3d = false;
  114. d.transitionstyle = false;
  115. d.hastransition = false;
  116. d.transitionend = false;
  117. var check = ['transform','msTransform','webkitTransform','MozTransform','OTransform'];
  118. for(var a=0;a<check.length;a++){
  119. if (typeof domtest.style[check[a]] != "undefined") {
  120. d.trstyle = check[a];
  121. break;
  122. }
  123. }
  124. d.hastransform = (d.trstyle != false);
  125. if (d.hastransform) {
  126. domtest.style[d.trstyle] = "translate3d(1px,2px,3px)";
  127. d.hastranslate3d = /translate3d/.test(domtest.style[d.trstyle]);
  128. }
  129. d.transitionstyle = false;
  130. d.prefixstyle = '';
  131. d.transitionend = false;
  132. var check = ['transition','webkitTransition','MozTransition','OTransition','OTransition','msTransition','KhtmlTransition'];
  133. var prefix = ['','-webkit-','-moz-','-o-','-o','-ms-','-khtml-'];
  134. var evs = ['transitionend','webkitTransitionEnd','transitionend','otransitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
  135. for(var a=0;a<check.length;a++) {
  136. if (check[a] in domtest.style) {
  137. d.transitionstyle = check[a];
  138. d.prefixstyle = prefix[a];
  139. d.transitionend = evs[a];
  140. break;
  141. }
  142. }
  143. d.hastransition = (d.transitionstyle);
  144. function detectCursorGrab() {
  145. var lst = ['-moz-grab','-webkit-grab','grab'];
  146. if ((d.ischrome&&!d.ischrome22)||d.isie) lst=[]; // force setting for IE returns false positive and chrome cursor bug
  147. for(var a=0;a<lst.length;a++) {
  148. var p = lst[a];
  149. domtest.style['cursor']=p;
  150. if (domtest.style['cursor']==p) return p;
  151. }
  152. return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize'; // thank you google for custom cursor!
  153. }
  154. d.cursorgrabvalue = detectCursorGrab();
  155. d.hasmousecapture = ("setCapture" in domtest);
  156. domtest = null; //memory released
  157. browserdetected = d;
  158. return d;
  159. }
  160. var NiceScrollClass = function(myopt,me) {
  161. var self = this;
  162. this.version = '3.1.9';
  163. this.name = 'nicescroll';
  164. this.me = me;
  165. this.opt = {
  166. doc:$("body"),
  167. win:false
  168. };
  169. $.extend(this.opt,_globaloptions);
  170. // Options for internal use
  171. this.opt.snapbackspeed = 80;
  172. if (myopt||false) {
  173. for(var a in self.opt) {
  174. if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
  175. }
  176. }
  177. this.doc = self.opt.doc;
  178. this.iddoc = (this.doc&&this.doc[0])?this.doc[0].id||'':'';
  179. this.ispage = /BODY|HTML/.test((self.opt.win)?self.opt.win[0].nodeName:this.doc[0].nodeName);
  180. this.haswrapper = (self.opt.win!==false);
  181. this.win = self.opt.win||(this.ispage?$(window):this.doc);
  182. this.docscroll = (this.ispage&&!this.haswrapper)?$(window):this.win;
  183. this.body = $("body");
  184. this.viewport = false;
  185. this.isfixed = false;
  186. this.iframe = false;
  187. this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
  188. this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
  189. this.forcescreen = false; //force to use screen position on events
  190. this.canshowonmouseevent = (self.opt.autohidemode!="scroll");
  191. // Events jump table
  192. this.onmousedown = false;
  193. this.onmouseup = false;
  194. this.onmousemove = false;
  195. this.onmousewheel = false;
  196. this.onkeypress = false;
  197. this.ongesturezoom = false;
  198. this.onclick = false;
  199. // Nicescroll custom events
  200. this.onscrollstart = false;
  201. this.onscrollend = false;
  202. this.onscrollcancel = false;
  203. this.onzoomin = false;
  204. this.onzoomout = false;
  205. // Let's start!
  206. this.view = false;
  207. this.page = false;
  208. this.scroll = {x:0,y:0};
  209. this.scrollratio = {x:0,y:0};
  210. this.cursorheight = 20;
  211. this.scrollvaluemax = 0;
  212. this.scrollrunning = false;
  213. this.scrollmom = false;
  214. this.observer = false;
  215. do {
  216. this.id = "ascrail"+(ascrailcounter++);
  217. } while (document.getElementById(this.id));
  218. this.rail = false;
  219. this.cursor = false;
  220. this.cursorfreezed = false;
  221. this.zoom = false;
  222. this.zoomactive = false;
  223. this.hasfocus = false;
  224. this.hasmousefocus = false;
  225. this.visibility = true;
  226. this.locked = false;
  227. this.hidden = false; // rails always hidden
  228. this.cursoractive = true; // user can interact with cursors
  229. this.nativescrollingarea = false;
  230. this.checkarea = 0;
  231. this.events = []; // event list for unbind
  232. this.saved = {};
  233. this.delaylist = {};
  234. this.synclist = {};
  235. this.lastdeltax = 0;
  236. this.lastdeltay = 0;
  237. this.detected = getBrowserDetection();
  238. var cap = $.extend({},this.detected);
  239. this.canhwscroll = (cap.hastransform&&self.opt.hwacceleration);
  240. this.ishwscroll = (this.canhwscroll&&self.haswrapper);
  241. this.istouchcapable = false; // desktop devices with touch screen support
  242. //## Check Chrome desktop with touch support
  243. if (cap.cantouch&&cap.ischrome&&!cap.isios&&!cap.isandroid) {
  244. this.istouchcapable = true;
  245. cap.cantouch = false; // parse normal desktop events
  246. }
  247. //## Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
  248. if (cap.cantouch&&cap.ismozilla&&!cap.isios) {
  249. this.istouchcapable = true;
  250. cap.cantouch = false; // parse normal desktop events
  251. }
  252. //## disable MouseLock API on user request
  253. if (!self.opt.enablemouselockapi) {
  254. cap.hasmousecapture = false;
  255. cap.haspointerlock = false;
  256. }
  257. this.delayed = function(name,fn,tm,lazy) {
  258. var dd = self.delaylist[name];
  259. var nw = (new Date()).getTime();
  260. if (!lazy&&dd&&dd.tt) return false;
  261. if (dd&&dd.tt) clearTimeout(dd.tt);
  262. if (dd&&dd.last+tm>nw&&!dd.tt) {
  263. self.delaylist[name] = {
  264. last:nw+tm,
  265. tt:setTimeout(function(){self.delaylist[name].tt=0;fn.call();},tm)
  266. }
  267. }
  268. else if (!dd||!dd.tt) {
  269. self.delaylist[name] = {
  270. last:nw,
  271. tt:0
  272. }
  273. setTimeout(function(){fn.call();},0);
  274. }
  275. };
  276. this.debounced = function(name,fn,tm) {
  277. var dd = self.delaylist[name];
  278. var nw = (new Date()).getTime();
  279. self.delaylist[name] = fn;
  280. if (!dd) {
  281. setTimeout(function(){var fn=self.delaylist[name];self.delaylist[name]=false;fn.call();},tm);
  282. }
  283. }
  284. this.synched = function(name,fn) {
  285. function requestSync() {
  286. if (self.onsync) return;
  287. setAnimationFrame(function(){
  288. self.onsync = false;
  289. for(name in self.synclist){
  290. var fn = self.synclist[name];
  291. if (fn) fn.call(self);
  292. self.synclist[name] = false;
  293. }
  294. });
  295. self.onsync = true;
  296. };
  297. self.synclist[name] = fn;
  298. requestSync();
  299. return name;
  300. };
  301. this.unsynched = function(name) {
  302. if (self.synclist[name]) self.synclist[name] = false;
  303. }
  304. this.css = function(el,pars) { // save & set
  305. for(var n in pars) {
  306. self.saved.css.push([el,n,el.css(n)]);
  307. el.css(n,pars[n]);
  308. }
  309. };
  310. this.scrollTop = function(val) {
  311. return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
  312. };
  313. this.scrollLeft = function(val) {
  314. return (typeof val == "undefined") ? self.getScrollLeft() : self.setScrollLeft(val);
  315. };
  316. // derived by by Dan Pupius www.pupius.net
  317. BezierClass = function(st,ed,spd,p1,p2,p3,p4) {
  318. this.st = st;
  319. this.ed = ed;
  320. this.spd = spd;
  321. this.p1 = p1||0;
  322. this.p2 = p2||1;
  323. this.p3 = p3||0;
  324. this.p4 = p4||1;
  325. this.ts = (new Date()).getTime();
  326. this.df = this.ed-this.st;
  327. };
  328. BezierClass.prototype = {
  329. B2:function(t){ return 3*t*t*(1-t) },
  330. B3:function(t){ return 3*t*(1-t)*(1-t) },
  331. B4:function(t){ return (1-t)*(1-t)*(1-t) },
  332. getNow:function(){
  333. var nw = (new Date()).getTime();
  334. var pc = 1-((nw-this.ts)/this.spd);
  335. var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
  336. return (pc<0) ? this.ed : this.st+Math.round(this.df*bz);
  337. },
  338. update:function(ed,spd){
  339. this.st = this.getNow();
  340. this.ed = ed;
  341. this.spd = spd;
  342. this.ts = (new Date()).getTime();
  343. this.df = this.ed-this.st;
  344. return this;
  345. }
  346. };
  347. if (this.ishwscroll) {
  348. // hw accelerated scroll
  349. this.doc.translate = {x:0,y:0,tx:"0px",ty:"0px"};
  350. //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
  351. if (cap.hastranslate3d&&cap.isios) this.doc.css("-webkit-backface-visibility","hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/
  352. //derived from http://stackoverflow.com/questions/11236090/
  353. function getMatrixValues() {
  354. var tr = self.doc.css(cap.trstyle);
  355. if (tr&&(tr.substr(0,6)=="matrix")) {
  356. return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g,'').split(/, +/);
  357. }
  358. return false;
  359. }
  360. this.getScrollTop = function(last) {
  361. if (!last) {
  362. var mtx = getMatrixValues();
  363. if (mtx) return (mtx.length==16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
  364. if (self.timerscroll&&self.timerscroll.bz) return self.timerscroll.bz.getNow();
  365. }
  366. return self.doc.translate.y;
  367. };
  368. this.getScrollLeft = function(last) {
  369. if (!last) {
  370. var mtx = getMatrixValues();
  371. if (mtx) return (mtx.length==16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
  372. if (self.timerscroll&&self.timerscroll.bh) return self.timerscroll.bh.getNow();
  373. }
  374. return self.doc.translate.x;
  375. };
  376. if (document.createEvent) {
  377. this.notifyScrollEvent = function(el) {
  378. var e = document.createEvent("UIEvents");
  379. e.initUIEvent("scroll", false, true, window, 1);
  380. el.dispatchEvent(e);
  381. };
  382. }
  383. else if (document.fireEvent) {
  384. this.notifyScrollEvent = function(el) {
  385. var e = document.createEventObject();
  386. el.fireEvent("onscroll");
  387. e.cancelBubble = true;
  388. };
  389. }
  390. else {
  391. this.notifyScrollEvent = function(el,add) {}; //NOPE
  392. }
  393. if (cap.hastranslate3d&&self.opt.enabletranslate3d) {
  394. this.setScrollTop = function(val,silent) {
  395. self.doc.translate.y = val;
  396. self.doc.translate.ty = (val*-1)+"px";
  397. self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
  398. if (!silent) self.notifyScrollEvent(self.win[0]);
  399. };
  400. this.setScrollLeft = function(val,silent) {
  401. self.doc.translate.x = val;
  402. self.doc.translate.tx = (val*-1)+"px";
  403. self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
  404. if (!silent) self.notifyScrollEvent(self.win[0]);
  405. };
  406. } else {
  407. this.setScrollTop = function(val,silent) {
  408. self.doc.translate.y = val;
  409. self.doc.translate.ty = (val*-1)+"px";
  410. self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
  411. if (!silent) self.notifyScrollEvent(self.win[0]);
  412. };
  413. this.setScrollLeft = function(val,silent) {
  414. self.doc.translate.x = val;
  415. self.doc.translate.tx = (val*-1)+"px";
  416. self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
  417. if (!silent) self.notifyScrollEvent(self.win[0]);
  418. };
  419. }
  420. } else {
  421. // native scroll
  422. this.getScrollTop = function() {
  423. return self.docscroll.scrollTop();
  424. };
  425. this.setScrollTop = function(val) {
  426. return self.docscroll.scrollTop(val);
  427. };
  428. this.getScrollLeft = function() {
  429. return self.docscroll.scrollLeft();
  430. };
  431. this.setScrollLeft = function(val) {
  432. return self.docscroll.scrollLeft(val);
  433. };
  434. }
  435. this.getTarget = function(e) {
  436. if (!e) return false;
  437. if (e.target) return e.target;
  438. if (e.srcElement) return e.srcElement;
  439. return false;
  440. };
  441. this.hasParent = function(e,id) {
  442. if (!e) return false;
  443. var el = e.target||e.srcElement||e||false;
  444. while (el && el.id != id) {
  445. el = el.parentNode||false;
  446. }
  447. return (el!==false);
  448. };
  449. function getZIndex() {
  450. var dom = self.win;
  451. if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
  452. while (dom.length>0) {
  453. if (dom[0].nodeType==9) return false;
  454. var zi = dom.css('zIndex');
  455. if (!isNaN(zi)&&zi!=0) return zi;
  456. dom = dom.parent();
  457. }
  458. return false;
  459. };
  460. //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
  461. var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
  462. function getWidthToPixel(dom,prop,chkheight) {
  463. var wd = dom.css(prop);
  464. var px = parseFloat(wd);
  465. if (isNaN(px)) {
  466. px = _convertBorderWidth[wd]||0;
  467. var brd = (px==3) ? ((chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
  468. if (self.isie8&&px) px+=1;
  469. return (brd) ? px : 0;
  470. }
  471. return px;
  472. };
  473. this.getOffset = function() {
  474. if (self.isfixed) return {top:parseFloat(self.win.css('top')),left:parseFloat(self.win.css('left'))};
  475. if (!self.viewport) return self.win.offset();
  476. var ww = self.win.offset();
  477. var vp = self.viewport.offset();
  478. return {top:ww.top-vp.top+self.viewport.scrollTop(),left:ww.left-vp.left+self.viewport.scrollLeft()};
  479. };
  480. this.updateScrollBar = function(len) {
  481. if (self.ishwscroll) {
  482. self.rail.css({height:self.win.innerHeight()});
  483. if (self.railh) self.railh.css({width:self.win.innerWidth()});
  484. } else {
  485. var wpos = self.getOffset();
  486. var pos = {top:wpos.top,left:wpos.left};
  487. pos.top+= getWidthToPixel(self.win,'border-top-width',true);
  488. var brd = (self.win.outerWidth() - self.win.innerWidth())/2;
  489. pos.left+= (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win,'border-right-width') - self.rail.width : getWidthToPixel(self.win,'border-left-width');
  490. var off = self.opt.railoffset;
  491. if (off) {
  492. if (off.top) pos.top+=off.top;
  493. if (self.rail.align&&off.left) pos.left+=off.left;
  494. }
  495. if (!self.locked) self.rail.css({top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
  496. if (self.zoom) {
  497. self.zoom.css({top:pos.top+1,left:(self.rail.align==1) ? pos.left-20 : pos.left+self.rail.width+4});
  498. }
  499. if (self.railh&&!self.locked) {
  500. var pos = {top:wpos.top,left:wpos.left};
  501. 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);
  502. var x = pos.left + getWidthToPixel(self.win,'border-left-width');
  503. self.railh.css({top:y,left:x,width:self.railh.width});
  504. }
  505. }
  506. };
  507. this.doRailClick = function(e,dbl,hr) {
  508. var fn,pg,cur,pos;
  509. if (self.rail.drag&&self.rail.drag.pt!=1) return;
  510. if (self.locked) return;
  511. if (self.rail.drag) return;
  512. self.cancelScroll();
  513. self.cancelEvent(e);
  514. if (dbl) {
  515. fn = (hr) ? self.doScrollLeft : self.doScrollTop;
  516. 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);
  517. fn(cur);
  518. } else {
  519. fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
  520. cur = (hr) ? self.scroll.x : self.scroll.y;
  521. pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
  522. pg = (hr) ? self.view.w : self.view.h;
  523. (cur>=pos) ? fn(pg) : fn(-pg);
  524. }
  525. }
  526. self.hasanimationframe = (setAnimationFrame);
  527. self.hascancelanimationframe = (clearAnimationFrame);
  528. if (!self.hasanimationframe) {
  529. setAnimationFrame=function(fn){return setTimeout(fn,16)}; // 1000/60)};
  530. clearAnimationFrame=clearInterval;
  531. }
  532. else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
  533. this.init = function() {
  534. self.saved.css = [];
  535. if (cap.isie7mobile) return true; // SORRY, DO NOT WORK!
  536. if (cap.hasmstouch) self.css((self.ispage)?$("html"):self.win,{'-ms-touch-action':'none'});
  537. self.zindex = "auto";
  538. if (!self.ispage&&self.opt.zindex=="auto") {
  539. self.zindex = getZIndex();
  540. } else {
  541. self.zindex = self.opt.zindex;
  542. }
  543. /*
  544. self.ispage = true;
  545. self.haswrapper = true;
  546. // self.win = $(window);
  547. self.docscroll = $("body");
  548. // self.doc = $("body");
  549. */
  550. if (!self.ispage || (!cap.cantouch && !cap.isieold && !cap.isie9mobile)) {
  551. var cont = self.docscroll;
  552. if (self.ispage) cont = (self.haswrapper)?self.win:self.doc;
  553. if (!cap.isie9mobile) self.css(cont,{'overflow-y':'hidden'});
  554. if (self.ispage&&cap.isie7) {
  555. if (self.doc[0].nodeName=='BODY') self.css($("html"),{'overflow-y':'hidden'}); //IE7 double scrollbar issue
  556. else if (self.doc[0].nodeName=='HTML') self.css($("body"),{'overflow-y':'hidden'}); //IE7 double scrollbar issue
  557. }
  558. if (cap.isios&&!self.ispage&&!self.haswrapper) self.css($("body"),{"-webkit-overflow-scrolling":"touch"}); //force hw acceleration
  559. var cursor = $(document.createElement('div'));
  560. cursor.css({
  561. position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
  562. 'background-color':self.opt.cursorcolor,
  563. border:self.opt.cursorborder,
  564. 'background-clip':'padding-box',
  565. '-webkit-border-radius':self.opt.cursorborderradius,
  566. '-moz-border-radius':self.opt.cursorborderradius,
  567. 'border-radius':self.opt.cursorborderradius
  568. });
  569. cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
  570. self.cursor = cursor;
  571. var rail = $(document.createElement('div'));
  572. rail.attr('id',self.id);
  573. rail.addClass('nicescroll-rails');
  574. var v,a,kp = ["left","right"]; //"top","bottom"
  575. for(var n in kp) {
  576. a=kp[n];
  577. v = self.opt.railpadding[a];
  578. (v) ? rail.css("padding-"+a,v+"px") : self.opt.railpadding[a] = 0;
  579. }
  580. rail.append(cursor);
  581. rail.width = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth()) + self.opt.railpadding['left'] + self.opt.railpadding['right'];
  582. rail.css({width:rail.width+"px",'zIndex':self.zindex,"background":self.opt.background});
  583. rail.visibility = true;
  584. rail.scrollable = true;
  585. rail.align = (self.opt.railalign=="left") ? 0 : 1;
  586. self.rail = rail;
  587. self.rail.drag = false;
  588. var zoom = false;
  589. if (self.opt.boxzoom&&!self.ispage&&!cap.isieold) {
  590. zoom = document.createElement('div');
  591. self.bind(zoom,"click",self.doZoom);
  592. self.zoom = $(zoom);
  593. self.zoom.css({"cursor":"pointer",'z-index':self.zindex,'backgroundImage':'url('+scriptpath+'zoomico.png)','height':18,'width':18,'backgroundPosition':'0px 0px'});
  594. if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
  595. if (cap.cantouch&&self.opt.gesturezoom) {
  596. self.ongesturezoom = function(e) {
  597. if (e.scale>1.5) self.doZoomIn(e);
  598. if (e.scale<0.8) self.doZoomOut(e);
  599. return self.cancelEvent(e);
  600. };
  601. self.bind(self.win,"gestureend",self.ongesturezoom);
  602. }
  603. }
  604. // init HORIZ
  605. self.railh = false;
  606. if (self.opt.horizrailenabled) {
  607. self.css(cont,{'overflow-x':'hidden'});
  608. var cursor = $(document.createElement('div'));
  609. cursor.css({
  610. position:"relative",top:0,height:self.opt.cursorwidth,width:"0px",
  611. 'background-color':self.opt.cursorcolor,
  612. border:self.opt.cursorborder,
  613. 'background-clip':'padding-box',
  614. '-webkit-border-radius':self.opt.cursorborderradius,
  615. '-moz-border-radius':self.opt.cursorborderradius,
  616. 'border-radius':self.opt.cursorborderradius
  617. });
  618. cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth());
  619. self.cursorh = cursor;
  620. var railh = $(document.createElement('div'));
  621. railh.attr('id',self.id+'-hr');
  622. railh.addClass('nicescroll-rails');
  623. railh.height = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
  624. railh.css({height:railh.height+"px",'zIndex':self.zindex,"background":self.opt.background});
  625. railh.append(cursor);
  626. railh.visibility = true;
  627. railh.scrollable = true;
  628. railh.align = (self.opt.railvalign=="top") ? 0 : 1;
  629. self.railh = railh;
  630. self.railh.drag = false;
  631. }
  632. //
  633. if (self.ispage) {
  634. rail.css({position:"fixed",top:"0px",height:"100%"});
  635. (rail.align) ? rail.css({right:"0px"}) : rail.css({left:"0px"});
  636. self.body.append(rail);
  637. if (self.railh) {
  638. railh.css({position:"fixed",left:"0px",width:"100%"});
  639. (railh.align) ? railh.css({bottom:"0px"}) : railh.css({top:"0px"});
  640. self.body.append(railh);
  641. }
  642. } else {
  643. if (self.ishwscroll) {
  644. if (self.win.css('position')=='static') self.css(self.win,{'position':'relative'});
  645. var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
  646. if (self.zoom) {
  647. self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
  648. bd.append(self.zoom);
  649. }
  650. rail.css({position:"absolute",top:0});
  651. (rail.align) ? rail.css({right:0}) : rail.css({left:0});
  652. bd.append(rail);
  653. if (railh) {
  654. railh.css({position:"absolute",left:0,bottom:0});
  655. (railh.align) ? railh.css({bottom:0}) : railh.css({top:0});
  656. bd.append(railh);
  657. }
  658. } else {
  659. self.isfixed = (self.win.css("position")=="fixed");
  660. var rlpos = (self.isfixed) ? "fixed" : "absolute";
  661. if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
  662. if (self.viewport) {
  663. self.body = self.viewport;
  664. if ((/relative|absolute/.test(self.viewport.css("position")))==false) self.css(self.viewport,{"position":"relative"});
  665. }
  666. rail.css({position:rlpos});
  667. if (self.zoom) self.zoom.css({position:rlpos});
  668. self.updateScrollBar();
  669. self.body.append(rail);
  670. if (self.zoom) self.body.append(self.zoom);
  671. if (self.railh) {
  672. railh.css({position:rlpos});
  673. self.body.append(railh);
  674. }
  675. }
  676. if (cap.isios) self.css(self.win,{'-webkit-tap-highlight-color':'rgba(0,0,0,0)','-webkit-touch-callout':'none'}); // prevent grey layer on click
  677. if (cap.isie&&self.opt.disableoutline) self.win.attr("hideFocus","true"); // IE, prevent dotted rectangle on focused div
  678. if (cap.iswebkit&&self.opt.disableoutline) self.win.css({"outline":"none"});
  679. }
  680. if (self.opt.autohidemode===false) {
  681. self.autohidedom = false;
  682. self.rail.css({opacity:self.opt.cursoropacitymax});
  683. if (self.railh) self.railh.css({opacity:self.opt.cursoropacitymax});
  684. }
  685. else if (self.opt.autohidemode===true) {
  686. self.autohidedom = $().add(self.rail);
  687. if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
  688. }
  689. else if (self.opt.autohidemode=="scroll") {
  690. self.autohidedom = $().add(self.rail);
  691. if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
  692. }
  693. else if (self.opt.autohidemode=="cursor") {
  694. self.autohidedom = $().add(self.cursor);
  695. if (self.railh) self.autohidedom=self.autohidedom.add(self.railh.cursor);
  696. }
  697. else if (self.opt.autohidemode=="hidden") {
  698. self.autohidedom = false;
  699. self.hide();
  700. self.locked = false;
  701. }
  702. if (cap.isie9mobile) {
  703. self.scrollmom = new ScrollMomentumClass2D(self);
  704. /*
  705. var trace = function(msg) {
  706. var db = $("#debug");
  707. if (isNaN(msg)&&(typeof msg != "string")) {
  708. var x = [];
  709. for(var a in msg) {
  710. x.push(a+":"+msg[a]);
  711. }
  712. msg ="{"+x.join(",")+"}";
  713. }
  714. if (db.children().length>0) {
  715. db.children().eq(0).before("<div>"+msg+"</div>");
  716. } else {
  717. db.append("<div>"+msg+"</div>");
  718. }
  719. }
  720. window.onerror = function(msg,url,ln) {
  721. trace("ERR: "+msg+" at "+ln);
  722. }
  723. */
  724. self.onmangotouch = function(e) {
  725. var py = self.getScrollTop();
  726. var px = self.getScrollLeft();
  727. if ((py == self.scrollmom.lastscrolly)&&(px == self.scrollmom.lastscrollx)) return true;
  728. // $("#debug").html('DRAG:'+py);
  729. var dfy = py-self.mangotouch.sy;
  730. var dfx = px-self.mangotouch.sx;
  731. var df = Math.round(Math.sqrt(Math.pow(dfx,2)+Math.pow(dfy,2)));
  732. if (df==0) return;
  733. var dry = (dfy<0)?-1:1;
  734. var drx = (dfx<0)?-1:1;
  735. var tm = +new Date();
  736. if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
  737. if (((tm-self.mangotouch.tm)>80)||(self.mangotouch.dry!=dry)||(self.mangotouch.drx!=drx)) {
  738. // trace('RESET+'+(tm-self.mangotouch.tm));
  739. self.scrollmom.stop();
  740. self.scrollmom.reset(px,py);
  741. self.mangotouch.sy = py;
  742. self.mangotouch.ly = py;
  743. self.mangotouch.sx = px;
  744. self.mangotouch.lx = px;
  745. self.mangotouch.dry = dry;
  746. self.mangotouch.drx = drx;
  747. self.mangotouch.tm = tm;
  748. } else {
  749. self.scrollmom.stop();
  750. self.scrollmom.update(self.mangotouch.sx-dfx,self.mangotouch.sy-dfy);
  751. var gap = tm - self.mangotouch.tm;
  752. self.mangotouch.tm = tm;
  753. // trace('MOVE:'+df+" - "+gap);
  754. var ds = Math.max(Math.abs(self.mangotouch.ly-py),Math.abs(self.mangotouch.lx-px));
  755. self.mangotouch.ly = py;
  756. self.mangotouch.lx = px;
  757. if (ds>2) {
  758. self.mangotouch.lazy = setTimeout(function(){
  759. // trace('END:'+ds+'+'+gap);
  760. self.mangotouch.lazy = false;
  761. self.mangotouch.dry = 0;
  762. self.mangotouch.drx = 0;
  763. self.mangotouch.tm = 0;
  764. self.scrollmom.doMomentum(30);
  765. },100);
  766. }
  767. }
  768. }
  769. var top = self.getScrollTop();
  770. var lef = self.getScrollLeft();
  771. self.mangotouch = {sy:top,ly:top,dry:0,sx:lef,lx:lef,drx:0,lazy:false,tm:0};
  772. self.bind(self.docscroll,"scroll",self.onmangotouch);
  773. } else {
  774. if (cap.cantouch||self.istouchcapable||self.opt.touchbehavior||cap.hasmstouch) {
  775. self.scrollmom = new ScrollMomentumClass2D(self);
  776. self.ontouchstart = function(e) {
  777. if (e.pointerType&&e.pointerType!=2) return false;
  778. if (!self.locked) {
  779. if (cap.hasmstouch) {
  780. var tg = (e.target) ? e.target : false;
  781. while (tg) {
  782. var nc = $(tg).getNiceScroll();
  783. if ((nc.length>0)&&(nc[0].me == self.me)) break;
  784. if (nc.length>0) return false;
  785. if ((tg.nodeName=='DIV')&&(tg.id==self.id)) break;
  786. tg = (tg.parentNode) ? tg.parentNode : false;
  787. }
  788. }
  789. self.cancelScroll();
  790. var tg = self.getTarget(e);
  791. if (tg) {
  792. var skp = (/INPUT/i.test(tg.nodeName))&&(/range/i.test(tg.type));
  793. if (skp) return self.stopPropagation(e);
  794. }
  795. if (!("clientX" in e) && ("changedTouches" in e)) {
  796. e.clientX = e.changedTouches[0].clientX;
  797. e.clientY = e.changedTouches[0].clientY;
  798. }
  799. if (self.forcescreen) {
  800. var le = e;
  801. var e = {"original":(e.original)?e.original:e};
  802. e.clientX = le.screenX;
  803. e.clientY = le.screenY;
  804. }
  805. self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,st:self.getScrollTop(),sl:self.getScrollLeft(),pt:2,dl:false};
  806. if (self.ispage||!self.opt.directionlockdeadzone) {
  807. self.rail.drag.dl = "f";
  808. } else {
  809. var view = {
  810. w:$(window).width(),
  811. h:$(window).height()
  812. };
  813. var page = {
  814. w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
  815. h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
  816. }
  817. var maxh = Math.max(0,page.h - view.h);
  818. var maxw = Math.max(0,page.w - view.w);
  819. if (!self.rail.scrollable&&self.railh.scrollable) self.rail.drag.ck = (maxh>0) ? "v" : false;
  820. else if (self.rail.scrollable&&!self.railh.scrollable) self.rail.drag.ck = (maxw>0) ? "h" : false;
  821. else self.rail.drag.ck = false;
  822. if (!self.rail.drag.ck) self.rail.drag.dl = "f";
  823. }
  824. if (self.opt.touchbehavior&&self.isiframe&&cap.isie) {
  825. var wp = self.win.position();
  826. self.rail.drag.x+=wp.left;
  827. self.rail.drag.y+=wp.top;
  828. }
  829. self.hasmoving = false;
  830. self.lastmouseup = false;
  831. self.scrollmom.reset(e.clientX,e.clientY);
  832. if (!cap.cantouch&&!this.istouchcapable&&!cap.hasmstouch) {
  833. var ip = (tg)?/INPUT|SELECT|TEXTAREA/i.test(tg.nodeName):false;
  834. if (!ip) {
  835. if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
  836. return self.cancelEvent(e);
  837. }
  838. if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
  839. pc = {"tg":tg,"click":false};
  840. self.preventclick = pc;
  841. }
  842. }
  843. }
  844. };
  845. self.ontouchend = function(e) {
  846. if (e.pointerType&&e.pointerType!=2) return false;
  847. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  848. self.scrollmom.doMomentum();
  849. self.rail.drag = false;
  850. if (self.hasmoving) {
  851. self.hasmoving = false;
  852. self.lastmouseup = true;
  853. self.hideCursor();
  854. if (cap.hasmousecapture) document.releaseCapture();
  855. if (!cap.cantouch) return self.cancelEvent(e);
  856. }
  857. }
  858. };
  859. var moveneedoffset = (self.opt.touchbehavior&&self.isiframe&&!cap.hasmousecapture);
  860. self.ontouchmove = function(e,byiframe) {
  861. if (e.pointerType&&e.pointerType!=2) return false;
  862. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  863. if (cap.cantouch&&(typeof e.original == "undefined")) return true; // prevent ios "ghost" events by clickable elements
  864. self.hasmoving = true;
  865. if (self.preventclick&&!self.preventclick.click) {
  866. self.preventclick.click = self.preventclick.tg.onclick||false;
  867. self.preventclick.tg.onclick = self.onpreventclick;
  868. }
  869. var ev = $.extend({"original":e},e);
  870. e = ev;
  871. if (("changedTouches" in e)) {
  872. e.clientX = e.changedTouches[0].clientX;
  873. e.clientY = e.changedTouches[0].clientY;
  874. }
  875. if (self.forcescreen) {
  876. var le = e;
  877. var e = {"original":(e.original)?e.original:e};
  878. e.clientX = le.screenX;
  879. e.clientY = le.screenY;
  880. }
  881. var ofx = ofy = 0;
  882. if (moveneedoffset&&!byiframe) {
  883. var wp = self.win.position();
  884. ofx=-wp.left;
  885. ofy=-wp.top;
  886. }
  887. var fy = e.clientY + ofy;
  888. var my = (fy-self.rail.drag.y);
  889. var fx = e.clientX + ofx;
  890. var mx = (fx-self.rail.drag.x);
  891. var ny = self.rail.drag.st-my;
  892. if (self.ishwscroll&&self.opt.bouncescroll) {
  893. if (ny<0) {
  894. ny = Math.round(ny/2);
  895. // fy = 0;
  896. }
  897. else if (ny>self.page.maxh) {
  898. ny = self.page.maxh+Math.round((ny-self.page.maxh)/2);
  899. // fy = 0;
  900. }
  901. } else {
  902. if (ny<0) {ny=0;fy=0}
  903. if (ny>self.page.maxh) {ny=self.page.maxh;fy=0}
  904. }
  905. if (self.railh&&self.railh.scrollable) {
  906. var nx = self.rail.drag.sl-mx;
  907. if (self.ishwscroll&&self.opt.bouncescroll) {
  908. if (nx<0) {
  909. nx = Math.round(nx/2);
  910. // fx = 0;
  911. }
  912. else if (nx>self.page.maxw) {
  913. nx = self.page.maxw+Math.round((nx-self.page.maxw)/2);
  914. // fx = 0;
  915. }
  916. } else {
  917. if (nx<0) {nx=0;fx=0}
  918. if (nx>self.page.maxw) {nx=self.page.maxw;fx=0}
  919. }
  920. }
  921. var grabbed = false;
  922. if (self.rail.drag.dl) {
  923. grabbed = true;
  924. if (self.rail.drag.dl=="v") nx = self.rail.drag.sl;
  925. else if (self.rail.drag.dl=="h") ny = self.rail.drag.st;
  926. } else {
  927. var ay = Math.abs(my);
  928. var ax = Math.abs(mx);
  929. var dz = self.opt.directionlockdeadzone;
  930. if (self.rail.drag.ck=="v") {
  931. if (ay>dz&&(ax<=(ay*0.3))) {
  932. self.rail.drag = false;
  933. return true;
  934. }
  935. else if (ax>dz) {
  936. self.rail.drag.dl="f";
  937. $("body").scrollTop($("body").scrollTop()); // stop iOS native scrolling (when active javascript has blocked)
  938. }
  939. }
  940. else if (self.rail.drag.ck=="h") {
  941. if (ax>dz&&(ay<=(az*0.3))) {
  942. self.rail.drag = false;
  943. return true;
  944. }
  945. else if (ay>dz) {
  946. self.rail.drag.dl="f";
  947. $("body").scrollLeft($("body").scrollLeft()); // stop iOS native scrolling (when active javascript has blocked)
  948. }
  949. }
  950. }
  951. self.synched("touchmove",function(){
  952. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  953. if (self.prepareTransition) self.prepareTransition(0);
  954. if (self.rail.scrollable) self.setScrollTop(ny);
  955. self.scrollmom.update(fx,fy);
  956. if (self.railh&&self.railh.scrollable) {
  957. self.setScrollLeft(nx);
  958. self.showCursor(ny,nx);
  959. } else {
  960. self.showCursor(ny);
  961. }
  962. if (cap.isie10) document.selection.clear();
  963. }
  964. });
  965. if (cap.ischrome&&self.istouchcapable) grabbed=false; //chrome touch emulation doesn't like!
  966. if (grabbed) return self.cancelEvent(e);
  967. }
  968. };
  969. }
  970. if (cap.cantouch||self.opt.touchbehavior) {
  971. self.onpreventclick = function(e) {
  972. if (self.preventclick) {
  973. self.preventclick.tg.onclick = self.preventclick.click;
  974. self.preventclick = false;
  975. return self.cancelEvent(e);
  976. }
  977. }
  978. self.onmousedown = self.ontouchstart;
  979. self.onmouseup = self.ontouchend;
  980. self.onclick = (cap.isios) ? false : function(e) {
  981. if (self.lastmouseup) {
  982. self.lastmouseup = false;
  983. return self.cancelEvent(e);
  984. } else {
  985. return true;
  986. }
  987. };
  988. self.onmousemove = self.ontouchmove;
  989. if (cap.cursorgrabvalue) {
  990. self.css((self.ispage)?self.doc:self.win,{'cursor':cap.cursorgrabvalue});
  991. self.css(self.rail,{'cursor':cap.cursorgrabvalue});
  992. }
  993. } else {
  994. self.onmousedown = function(e,hronly) {
  995. if (self.rail.drag&&self.rail.drag.pt!=1) return;
  996. if (self.locked) return self.cancelEvent(e);
  997. self.cancelScroll();
  998. self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,pt:1,hr:(!!hronly)};
  999. var tg = self.getTarget(e);
  1000. if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
  1001. if (self.isiframe&&!cap.hasmousecapture) {
  1002. self.saved["csspointerevents"] = self.doc.css("pointer-events");
  1003. self.css(self.doc,{"pointer-events":"none"});
  1004. }
  1005. return self.cancelEvent(e);
  1006. };
  1007. self.onmouseup = function(e) {
  1008. if (self.rail.drag) {
  1009. if (cap.hasmousecapture) document.releaseCapture();
  1010. if (self.isiframe&&!cap.hasmousecapture) self.doc.css("pointer-events",self.saved["csspointerevents"]);
  1011. if(self.rail.drag.pt!=1)return;
  1012. self.rail.drag = false;
  1013. //if (!self.rail.active) self.hideCursor();
  1014. return self.cancelEvent(e);
  1015. }
  1016. };
  1017. self.onmousemove = function(e) {
  1018. if (self.rail.drag) {
  1019. if(self.rail.drag.pt!=1)return;
  1020. if (cap.ischrome&&e.which==0) return self.onmouseup(e);
  1021. self.cursorfreezed = true;
  1022. if (self.rail.drag.hr) {
  1023. self.scroll.x = self.rail.drag.sx + (e.clientX-self.rail.drag.x);
  1024. if (self.scroll.x<0) self.scroll.x=0;
  1025. var mw = self.scrollvaluemaxw;
  1026. if (self.scroll.x>mw) self.scroll.x=mw;
  1027. } else {
  1028. self.scroll.y = self.rail.drag.sy + (e.clientY-self.rail.drag.y);
  1029. if (self.scroll.y<0) self.scroll.y=0;
  1030. var my = self.scrollvaluemax;
  1031. if (self.scroll.y>my) self.scroll.y=my;
  1032. }
  1033. self.synched('mousemove',function(){
  1034. if (self.rail.drag&&(self.rail.drag.pt==1)) {
  1035. self.showCursor();
  1036. if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x*self.scrollratio.x));
  1037. else self.doScrollTop(Math.round(self.scroll.y*self.scrollratio.y));
  1038. }
  1039. });
  1040. return self.cancelEvent(e);
  1041. }
  1042. /*
  1043. else {
  1044. self.checkarea = true;
  1045. }
  1046. */
  1047. };
  1048. }
  1049. if (cap.cantouch||self.opt.touchbehavior) {
  1050. self.bind(self.win,"mousedown",self.onmousedown);
  1051. }
  1052. if (cap.hasmstouch) {
  1053. self.css(self.rail,{'-ms-touch-action':'none'});
  1054. self.css(self.cursor,{'-ms-touch-action':'none'});
  1055. self.bind(self.win,"MSPointerDown",self.ontouchstart);
  1056. self.bind(document,"MSPointerUp",self.ontouchend);
  1057. self.bind(document,"MSPointerMove",self.ontouchmove);
  1058. self.bind(self.cursor,"MSGestureHold",function(e){e.preventDefault();});
  1059. self.bind(self.cursor,"contextmenu",function(e){e.preventDefault();});
  1060. }
  1061. if (this.istouchcapable) { //device with screen touch enabled
  1062. self.bind(self.win,"touchstart",self.ontouchstart);
  1063. self.bind(document,"touchend",self.ontouchend);
  1064. self.bind(document,"touchcancel",self.ontouchend);
  1065. self.bind(document,"touchmove",self.ontouchmove);
  1066. }
  1067. self.bind(self.cursor,"mousedown",self.onmousedown);
  1068. self.bind(self.cursor,"mouseup",self.onmouseup);
  1069. if (self.railh) {
  1070. self.bind(self.cursorh,"mousedown",function(e){self.onmousedown(e,true)});
  1071. self.bind(self.cursorh,"mouseup",function(e){
  1072. if (self.rail.drag&&self.rail.drag.pt==2) return;
  1073. self.rail.drag = false;
  1074. self.hasmoving = false;
  1075. self.hideCursor();
  1076. if (cap.hasmousecapture) document.releaseCapture();
  1077. return self.cancelEvent(e);
  1078. });
  1079. }
  1080. self.bind(document,"mouseup",self.onmouseup);
  1081. if (cap.hasmousecapture) self.bind(self.win,"mouseup",self.onmouseup);
  1082. self.bind(document,"mousemove",self.onmousemove);
  1083. if (self.onclick) self.bind(document,"click",self.onclick);
  1084. if (!cap.cantouch&&!self.opt.touchbehavior) {
  1085. self.jqbind(self.rail,"mouseenter",function() {
  1086. if (self.canshowonmouseevent) self.showCursor();
  1087. self.rail.active = true;
  1088. });
  1089. self.jqbind(self.rail,"mouseleave",function() {
  1090. self.rail.active = false;
  1091. if (!self.rail.drag) self.hideCursor();
  1092. });
  1093. if (self.opt.sensitiverail) {
  1094. self.bind(self.rail,"click",function(e){self.doRailClick(e,false,false)});
  1095. self.bind(self.rail,"dblclick",function(e){self.doRailClick(e,true,false)});
  1096. self.bind(self.cursor,"click",function(e){self.cancelEvent(e)});
  1097. self.bind(self.cursor,"dblclick",function(e){self.cancelEvent(e)});
  1098. }
  1099. if (self.railh) {
  1100. self.jqbind(self.railh,"mouseenter",function() {
  1101. if (self.canshowonmouseevent) self.showCursor();
  1102. self.rail.active = true;
  1103. });
  1104. self.jqbind(self.railh,"mouseleave",function() {
  1105. self.rail.active = false;
  1106. if (!self.rail.drag) self.hideCursor();
  1107. });
  1108. if (self.opt.sensitiverail) {
  1109. self.bind(self.railh, "click", function(e){self.doRailClick(e,false,true)});
  1110. self.bind(self.railh, "dblclick", function(e){self.doRailClick(e, true, true) });
  1111. self.bind(self.cursorh, "click", function (e) { self.cancelEvent(e) });
  1112. self.bind(self.cursorh, "dblclick", function (e) { self.cancelEvent(e) });
  1113. }
  1114. }
  1115. if (self.zoom) {
  1116. self.jqbind(self.zoom,"mouseenter",function() {
  1117. if (self.canshowonmouseevent) self.showCursor();
  1118. self.rail.active = true;
  1119. });
  1120. self.jqbind(self.zoom,"mouseleave",function() {
  1121. self.rail.active = false;
  1122. if (!self.rail.drag) self.hideCursor();
  1123. });
  1124. }
  1125. }
  1126. if (self.opt.enablemousewheel) {
  1127. if (!self.isiframe) self.bind((cap.isie&&self.ispage) ? document : self.docscroll,"mousewheel",self.onmousewheel);
  1128. self.bind(self.rail,"mousewheel",self.onmousewheel);
  1129. if (self.railh) self.bind(self.railh,"mousewheel",self.onmousewheelhr);
  1130. }
  1131. if (!self.ispage&&!cap.cantouch&&!(/HTML|BODY/.test(self.win[0].nodeName))) {
  1132. if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
  1133. self.jqbind(self.win,"focus",function(e) {
  1134. domfocus = (self.getTarget(e)).id||true;
  1135. self.hasfocus = true;
  1136. if (self.canshowonmouseevent) self.noticeCursor();
  1137. });
  1138. self.jqbind(self.win,"blur",function(e) {
  1139. domfocus = false;
  1140. self.hasfocus = false;
  1141. });
  1142. self.jqbind(self.win,"mouseenter",function(e) {
  1143. mousefocus = (self.getTarget(e)).id||true;
  1144. self.hasmousefocus = true;
  1145. if (self.canshowonmouseevent) self.noticeCursor();
  1146. });
  1147. self.jqbind(self.win,"mouseleave",function() {
  1148. mousefocus = false;
  1149. self.hasmousefocus = false;
  1150. });
  1151. };
  1152. } // !ie9mobile
  1153. //Thanks to http://www.quirksmode.org !!
  1154. self.onkeypress = function(e) {
  1155. if (self.locked&&self.page.maxh==0) return true;
  1156. e = (e) ? e : window.e;
  1157. var tg = self.getTarget(e);
  1158. if (tg&&/INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
  1159. var tp = tg.getAttribute('type')||tg.type||false;
  1160. if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
  1161. }
  1162. if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
  1163. var key = e.keyCode;
  1164. if (self.locked&&key!=27) return self.cancelEvent(e);
  1165. var ctrl = e.ctrlKey||false;
  1166. var shift = e.shiftKey || false;
  1167. var ret = false;
  1168. switch (key) {
  1169. case 38:
  1170. case 63233: //safari
  1171. self.doScrollBy(24*3);
  1172. ret = true;
  1173. break;
  1174. case 40:
  1175. case 63235: //safari
  1176. self.doScrollBy(-24*3);
  1177. ret = true;
  1178. break;
  1179. case 37:
  1180. case 63232: //safari
  1181. if (self.railh) {
  1182. (ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24*3);
  1183. ret = true;
  1184. }
  1185. break;
  1186. case 39:
  1187. case 63234: //safari
  1188. if (self.railh) {
  1189. (ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24*3);
  1190. ret = true;
  1191. }
  1192. break;
  1193. case 33:
  1194. case 63276: // safari
  1195. self.doScrollBy(self.view.h);
  1196. ret = true;
  1197. break;
  1198. case 34:
  1199. case 63277: // safari
  1200. self.doScrollBy(-self.view.h);
  1201. ret = true;
  1202. break;
  1203. case 36:
  1204. case 63273: // safari
  1205. (self.railh&&ctrl) ? self.doScrollPos(0,0) : self.doScrollTo(0);
  1206. ret = true;
  1207. break;
  1208. case 35:
  1209. case 63275: // safari
  1210. (self.railh&&ctrl) ? self.doScrollPos(self.page.maxw,self.page.maxh) : self.doScrollTo(self.page.maxh);
  1211. ret = true;
  1212. break;
  1213. case 32:
  1214. if (self.opt.spacebarenabled) {
  1215. (shift) ? self.doScrollBy(self.view.h) : self.doScrollBy(-self.view.h);
  1216. ret = true;
  1217. }
  1218. break;
  1219. case 27: // ESC
  1220. if (self.zoomactive) {
  1221. self.doZoom();
  1222. ret = true;
  1223. }
  1224. break;
  1225. }
  1226. if (ret) return self.cancelEvent(e);
  1227. }
  1228. };
  1229. if (self.opt.enablekeyboard) self.bind(document,(cap.isopera&&!cap.isopera12)?"keypress":"keydown",self.onkeypress);
  1230. self.bind(window,'resize',self.lazyResize);
  1231. self.bind(window,'orientationchange',self.lazyResize);
  1232. self.bind(window,"load",self.lazyResize);
  1233. if (cap.ischrome&&!self.ispage&&!self.haswrapper) { //chrome void scrollbar bug
  1234. var tmp=self.win.attr("style");
  1235. var ww = parseFloat(self.win.css("width"))+1;
  1236. self.win.css('width',ww);
  1237. self.synched("chromefix",function(){self.win.attr("style",tmp)});
  1238. }
  1239. // Trying a cross-browser implementation - good luck!
  1240. self.onAttributeChange = function(e) {
  1241. self.lazyResize(250);
  1242. }
  1243. if (!self.ispage&&!self.haswrapper) {
  1244. // thanks to Filip http://stackoverflow.com/questions/1882224/
  1245. if ("WebKitMutationObserver" in window) {
  1246. self.observer = new WebKitMutationObserver(function(mutations) {
  1247. mutations.forEach(self.onAttributeChange);
  1248. });
  1249. self.observer.observe(self.win[0],{attributes:true,subtree:false});
  1250. } else {
  1251. self.bind(self.win,(cap.isie&&!cap.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);
  1252. if (cap.isie9) self.win[0].attachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
  1253. }
  1254. }
  1255. //
  1256. if (!self.ispage&&self.opt.boxzoom) self.bind(window,"resize",self.resizeZoom);
  1257. if (self.istextarea) self.bind(self.win,"mouseup",self.lazyResize);
  1258. self.lazyResize(30);
  1259. }
  1260. if (this.doc[0].nodeName == 'IFRAME') {
  1261. function oniframeload(e) {
  1262. self.iframexd = false;
  1263. try {
  1264. var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
  1265. var a = doc.domain;
  1266. } catch(e){self.iframexd = true;doc=false};
  1267. if (self.iframexd) {
  1268. if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
  1269. return true; //cross-domain - I can't manage this
  1270. }
  1271. self.forcescreen = true;
  1272. if (self.isiframe) {
  1273. self.iframe = {
  1274. "doc":$(doc),
  1275. "html":self.doc.contents().find('html')[0],
  1276. "body":self.doc.contents().find('body')[0]
  1277. };
  1278. self.getContentSize = function(){
  1279. return {
  1280. w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
  1281. h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
  1282. }
  1283. }
  1284. self.docscroll = $(self.iframe.body);//$(this.contentWindow);
  1285. }
  1286. if (!cap.isios&&self.opt.iframeautoresize&&!self.isiframe) {
  1287. self.win.scrollTop(0); // reset position
  1288. self.doc.height(""); //reset height to fix browser bug
  1289. var hh=Math.max(doc.getElementsByTagName('html')[0].scrollHeight,doc.body.scrollHeight);
  1290. self.doc.height(hh);
  1291. }
  1292. self.lazyResize(30);
  1293. if (cap.isie7) self.css($(self.iframe.html),{'overflow-y':'hidden'});
  1294. //self.css($(doc.body),{'overflow-y':'hidden'});
  1295. self.css($(self.iframe.body),{'overflow-y':'hidden'});
  1296. if ('contentWindow' in this) {
  1297. self.bind(this.contentWindow,"scroll",self.onscroll); //IE8 & minor
  1298. } else {
  1299. self.bind(doc,"scroll",self.onscroll);
  1300. }
  1301. if (self.opt.enablemousewheel) {
  1302. self.bind(doc,"mousewheel",self.onmousewheel);
  1303. }
  1304. if (self.opt.enablekeyboard) self.bind(doc,(cap.isopera)?"keypress":"keydown",self.onkeypress);
  1305. if (cap.cantouch||self.opt.touchbehavior) {
  1306. self.bind(doc,"mousedown",self.onmousedown);
  1307. self.bind(doc,"mousemove",function(e){self.onmousemove(e,true)});
  1308. if (cap.cursorgrabvalue) self.css($(doc.body),{'cursor':cap.cursorgrabvalue});
  1309. }
  1310. self.bind(doc,"mouseup",self.onmouseup);
  1311. if (self.zoom) {
  1312. if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
  1313. if (self.ongesturezoom) self.bind(doc,"gestureend",self.ongesturezoom);
  1314. }
  1315. };
  1316. if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
  1317. setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
  1318. }
  1319. self.bind(this.doc,"load",oniframeload);
  1320. }
  1321. };
  1322. this.showCursor = function(py,px) {
  1323. if (self.cursortimeout) {
  1324. clearTimeout(self.cursortimeout);
  1325. self.cursortimeout = 0;
  1326. }
  1327. if (!self.rail) return;
  1328. if (self.autohidedom) {
  1329. self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
  1330. self.cursoractive = true;
  1331. }
  1332. if ((typeof py != "undefined")&&(py!==false)) {
  1333. self.scroll.y = Math.round(py * 1/self.scrollratio.y);
  1334. }
  1335. if (typeof px != "undefined") {
  1336. self.scroll.x = Math.round(px * 1/self.scrollratio.x);
  1337. }
  1338. self.cursor.css({height:self.cursorheight,top:self.scroll.y});
  1339. if (self.cursorh) {
  1340. (!self.rail.align&&self.rail.visibility) ? self.cursorh.css({width:self.cursorwidth,left:self.scroll.x+self.rail.width}) : self.cursorh.css({width:self.cursorwidth,left:self.scroll.x});
  1341. self.cursoractive = true;
  1342. }
  1343. if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});
  1344. };
  1345. this.hideCursor = function(tm) {
  1346. if (self.cursortimeout) return;
  1347. if (!self.rail) return;
  1348. if (!self.autohidedom) return;
  1349. self.cursortimeout = setTimeout(function() {
  1350. if (!self.rail.active||!self.showonmouseevent) {
  1351. self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
  1352. if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
  1353. self.cursoractive = false;
  1354. }
  1355. self.cursortimeout = 0;
  1356. },tm||self.opt.hidecursordelay);
  1357. };
  1358. this.noticeCursor = function(tm,py,px) {
  1359. self.showCursor(py,px);
  1360. if (!self.rail.active) self.hideCursor(tm);
  1361. };
  1362. this.getContentSize =
  1363. (self.ispage) ?
  1364. function(){
  1365. return {
  1366. w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
  1367. h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
  1368. }
  1369. }
  1370. : (self.haswrapper) ?
  1371. function(){
  1372. return {
  1373. w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
  1374. h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
  1375. }
  1376. }
  1377. : function() {
  1378. return {
  1379. w:self.docscroll[0].scrollWidth,
  1380. h:self.docscroll[0].scrollHeight
  1381. }
  1382. };
  1383. this.onResize = function(e,page) {
  1384. if (!self.win) return false;
  1385. if (!self.haswrapper&&!self.ispage) {
  1386. if (self.win.css('display')=='none') {
  1387. if (self.visibility) self.hideRail().hideRailHr();
  1388. return false;
  1389. } else {
  1390. if (!self.hidden&&!self.visibility) self.showRail().showRailHr();
  1391. }
  1392. }
  1393. var premaxh = self.page.maxh;
  1394. var premaxw = self.page.maxw;
  1395. var preview = {h:self.view.h,w:self.view.w};
  1396. self.view = {
  1397. w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
  1398. h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
  1399. };
  1400. self.page = (page) ? page : self.getContentSize();
  1401. self.page.maxh = Math.max(0,self.page.h - self.view.h);
  1402. self.page.maxw = Math.max(0,self.page.w - self.view.w);
  1403. if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
  1404. // test position
  1405. if (!self.ispage) {
  1406. var pos = self.win.offset();
  1407. if (self.lastposition) {
  1408. var lst = self.lastposition;
  1409. if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do
  1410. }
  1411. self.lastposition = pos;
  1412. } else {
  1413. return self; //nothing to do
  1414. }
  1415. }
  1416. if (self.page.maxh==0) {
  1417. self.hideRail();
  1418. self.scrollvaluemax = 0;
  1419. self.scroll.y = 0;
  1420. self.scrollratio.y = 0;
  1421. self.cursorheight = 0;
  1422. self.setScrollTop(0);
  1423. self.rail.scrollable = false;
  1424. } else {
  1425. self.rail.scrollable = true;
  1426. }
  1427. if (self.page.maxw==0) {
  1428. self.hideRailHr();
  1429. self.scrollvaluemaxw = 0;
  1430. self.scroll.x = 0;
  1431. self.scrollratio.x = 0;
  1432. self.cursorwidth = 0;
  1433. self.setScrollLeft(0);
  1434. self.railh.scrollable = false;
  1435. } else {
  1436. self.railh.scrollable = true;
  1437. }
  1438. self.locked = (self.page.maxh==0)&&(self.page.maxw==0);
  1439. if (self.locked) {
  1440. if (!self.ispage) self.updateScrollBar(self.view);
  1441. return false;
  1442. }
  1443. if (!self.hidden&&!self.visibility) {
  1444. self.showRail().showRailHr();
  1445. }
  1446. else if (!self.hidden&&!self.railh.visibility) self.showRailHr();
  1447. if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
  1448. self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
  1449. self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorheight);
  1450. self.cursorwidth = Math.min(self.view.w,Math.round(self.view.w * (self.view.w / self.page.w)));
  1451. self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorwidth);
  1452. self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
  1453. if (self.railh) {
  1454. self.railh.width = (self.page.maxh>0) ? (self.view.w-self.rail.width) : self.view.w;
  1455. self.scrollvaluemaxw = self.railh.width-self.cursorwidth-self.cursorh.wborder;
  1456. }
  1457. if (!self.ispage) self.updateScrollBar(self.view);
  1458. self.scrollratio = {
  1459. x:(self.page.maxw/self.scrollvaluemaxw),
  1460. y:(self.page.maxh/self.scrollvaluemax)
  1461. };
  1462. var sy = self.getScrollTop();
  1463. if (sy>self.page.maxh) {
  1464. self.doScrollTop(self.page.maxh);
  1465. } else {
  1466. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1467. self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
  1468. if (self.cursoractive) self.noticeCursor();
  1469. }
  1470. if (self.scroll.y&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
  1471. return self;
  1472. };
  1473. this.resize = self.onResize;
  1474. this.lazyResize = function(tm) { // event debounce
  1475. tm = (isNaN(tm)) ? 30 : tm;
  1476. self.delayed('resize',self.resize,tm);
  1477. return self;
  1478. }
  1479. this._bind = function(el,name,fn,bubble) { // primitive bind
  1480. self.events.push({e:el,n:name,f:fn,b:bubble,q:false});
  1481. if (el.addEventListener) {
  1482. el.addEventListener(name,fn,bubble||false);
  1483. }
  1484. else if (el.attachEvent) {
  1485. el.attachEvent("on"+name,fn);
  1486. }
  1487. else {
  1488. el["on"+name] = fn;
  1489. }
  1490. };
  1491. this.jqbind = function(dom,name,fn) { // use jquery bind for non-native events (mouseenter/mouseleave)
  1492. self.events.push({e:dom,n:name,f:fn,q:true});
  1493. $(dom).bind(name,fn);
  1494. }
  1495. this.bind = function(dom,name,fn,bubble) { // touch-oriented & fixing jquery bind
  1496. var el = ("jquery" in dom) ? dom[0] : dom;
  1497. if (el.addEventListener) {
  1498. if (cap.cantouch && /mouseup|mousedown|mousemove/.test(name)) { // touch device support
  1499. var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
  1500. self._bind(el,tt,function(e){
  1501. if (e.touches) {
  1502. if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
  1503. }
  1504. else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);} //blackberry
  1505. },bubble||false);
  1506. }
  1507. self._bind(el,name,fn,bubble||false);
  1508. if (name=='mousewheel') self._bind(el,"DOMMouseScroll",fn,bubble||false);
  1509. if (cap.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
  1510. }
  1511. else {
  1512. self._bind(el,name,function(e) {
  1513. e = e||window.event||false;
  1514. if (e) {
  1515. if (e.srcElement) e.target=e.srcElement;
  1516. }
  1517. return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
  1518. });
  1519. }
  1520. };
  1521. this._unbind = function(el,name,fn,bub) { // primitive unbind
  1522. if (el.removeEventListener) {
  1523. el.removeEventListener(name,fn,bub);
  1524. }
  1525. else if (el.detachEvent) {
  1526. el.detachEvent('on'+name,fn);
  1527. } else {
  1528. el['on'+name] = false;
  1529. }
  1530. };
  1531. this.unbindAll = function() {
  1532. for(var a=0;a<self.events.length;a++) {
  1533. var r = self.events[a];
  1534. (r.q) ? r.e.unbind(r.n,r.f) : self._unbind(r.e,r.n,r.f,r.b);
  1535. }
  1536. };
  1537. // Thanks to http://www.switchonthecode.com !!
  1538. this.cancelEvent = function(e) {
  1539. var e = (e.original) ? e.original : (e) ? e : window.event||false;
  1540. if (!e) return false;
  1541. if(e.preventDefault) e.preventDefault();
  1542. if(e.stopPropagation) e.stopPropagation();
  1543. if(e.preventManipulation) e.preventManipulation(); //IE10
  1544. e.cancelBubble = true;
  1545. e.cancel = true;
  1546. e.returnValue = false;
  1547. return false;
  1548. };
  1549. this.stopPropagation = function(e) {
  1550. var e = (e.original) ? e.original : (e) ? e : window.event||false;
  1551. if (!e) return false;
  1552. if (e.stopPropagation) return e.stopPropagation();
  1553. if (e.cancelBubble) e.cancelBubble=true;
  1554. return false;
  1555. }
  1556. this.showRail = function() {
  1557. if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
  1558. self.visibility = true;
  1559. self.rail.visibility = true;
  1560. self.rail.css('display','block');
  1561. }
  1562. return self;
  1563. };
  1564. this.showRailHr = function() {
  1565. if (!self.railh) return self;
  1566. if ((self.page.maxw!=0)&&(self.ispage||self.win.css('display')!='none')) {
  1567. self.railh.visibility = true;
  1568. self.railh.css('display','block');
  1569. }
  1570. return self;
  1571. };
  1572. this.hideRail = function() {
  1573. self.visibility = false;
  1574. self.rail.visibility = false;
  1575. self.rail.css('display','none');
  1576. return self;
  1577. };
  1578. this.hideRailHr = function() {
  1579. if (!self.railh) return self;
  1580. self.railh.visibility = false;
  1581. self.railh.css('display','none');
  1582. return self;
  1583. };
  1584. this.show = function() {
  1585. self.hidden = false;
  1586. self.locked = false;
  1587. return self.showRail().showRailHr();
  1588. };
  1589. this.hide = function() {
  1590. self.hidden = true;
  1591. self.locked = true;
  1592. return self.hideRail().hideRailHr();
  1593. };
  1594. this.toggle = function() {
  1595. return (self.hidden) ? self.show() : self.hide();
  1596. };
  1597. this.remove = function() {
  1598. self.stop();
  1599. if (self.cursortimeout) clearTimeout(self.cursortimeout);
  1600. self.doZoomOut();
  1601. self.unbindAll();
  1602. if (self.observer !== false) self.observer.disconnect();
  1603. self.events = [];
  1604. if (self.cursor) {
  1605. self.cursor.remove();
  1606. self.cursor = null;
  1607. }
  1608. if (self.cursorh) {
  1609. self.cursorh.remove();
  1610. self.cursorh = null;
  1611. }
  1612. if (self.rail) {
  1613. self.rail.remove();
  1614. self.rail = null;
  1615. }
  1616. if (self.railh) {
  1617. self.railh.remove();
  1618. self.railh = null;
  1619. }
  1620. if (self.zoom) {
  1621. self.zoom.remove();
  1622. self.zoom = null;
  1623. }
  1624. for(var a=0;a<self.saved.css.length;a++) {
  1625. var d=self.saved.css[a];
  1626. d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
  1627. }
  1628. self.saved = false;
  1629. self.me.data('__nicescroll',''); //erase all traces
  1630. self.me = null;
  1631. self.doc = null;
  1632. self.docscroll = null;
  1633. self.win = null;
  1634. return self;
  1635. };
  1636. this.scrollstart = function(fn) {
  1637. this.onscrollstart = fn;
  1638. return self;
  1639. }
  1640. this.scrollend = function(fn) {
  1641. this.onscrollend = fn;
  1642. return self;
  1643. }
  1644. this.scrollcancel = function(fn) {
  1645. this.onscrollcancel = fn;
  1646. return self;
  1647. }
  1648. this.zoomin = function(fn) {
  1649. this.onzoomin = fn;
  1650. return self;
  1651. }
  1652. this.zoomout = function(fn) {
  1653. this.onzoomout = fn;
  1654. return self;
  1655. }
  1656. this.isScrollable = function(e) {
  1657. var dom = (e.target) ? e.target : e;
  1658. if (dom.nodeName == 'OPTION') return true;
  1659. while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
  1660. var dd = $(dom);
  1661. var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
  1662. if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
  1663. dom = (dom.parentNode) ? dom.parentNode : false;
  1664. }
  1665. return false;
  1666. };
  1667. this.getViewport = function(me) {
  1668. var dom = (me&&me.parentNode) ? me.parentNode : false;
  1669. while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
  1670. var dd = $(dom);
  1671. var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
  1672. if ((/scroll|auto/.test(ov))&&(dom.clientHeight!=dom.scrollHeight)) return dd;
  1673. if (dd.getNiceScroll().length>0) return dd;
  1674. dom = (dom.parentNode) ? dom.parentNode : false;
  1675. }
  1676. return false;
  1677. };
  1678. function execScrollWheel(e,hr,chkscroll) {
  1679. var px = 0;
  1680. var py = 0;
  1681. var rt = 1;
  1682. if ("wheelDeltaY" in e) {
  1683. rt = self.opt.mousescrollstep/(16*3);
  1684. px = Math.floor(e.wheelDeltaX*rt);
  1685. py = Math.floor(e.wheelDeltaY*rt);
  1686. if (hr&&(px==0)&&py) { // classic vertical-only mousewheel + browser with x/y support
  1687. px = py;
  1688. py = 0;
  1689. }
  1690. } else {
  1691. var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
  1692. if (delta) {
  1693. (hr) ? px = Math.floor(delta*self.opt.mousescrollstep) : py = Math.floor(delta*self.opt.mousescrollstep);
  1694. }
  1695. }
  1696. if (px) {
  1697. if (self.scrollmom) {self.scrollmom.stop()}
  1698. self.lastdeltax+=px;
  1699. self.debounced("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}},120);
  1700. }
  1701. if (py) {
  1702. if (self.opt.nativeparentscrolling&&chkscroll) {
  1703. if (py<0) {
  1704. if (self.getScrollTop()>=self.page.maxh) return true;
  1705. } else {
  1706. if (self.getScrollTop()<=0) return true;
  1707. }
  1708. }
  1709. if (self.scrollmom) {self.scrollmom.stop()}
  1710. self.lastdeltay+=py;
  1711. self.debounced("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}},120);
  1712. }
  1713. return self.cancelEvent(e);
  1714. };
  1715. this.onmousewheel = function(e) {
  1716. if (self.locked) return true;
  1717. if (self.rail.drag) return self.cancelEvent(e);
  1718. if (!self.rail.scrollable) {
  1719. if (self.railh&&self.railh.scrollable) {
  1720. return self.onmousewheelhr(e);
  1721. } else {
  1722. return true;
  1723. }
  1724. }
  1725. var nw = +(new Date());
  1726. var chk = false;
  1727. if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
  1728. // self.checkarea = false;
  1729. self.nativescrollingarea = self.isScrollable(e);
  1730. chk = true;
  1731. }
  1732. self.checkarea = nw;
  1733. if (self.nativescrollingarea) return true; // this isn't my business
  1734. // if (self.locked) return self.cancelEvent(e);
  1735. var ret = execScrollWheel(e,false,chk);
  1736. if (ret) self.checkarea = 0;
  1737. return ret;
  1738. };
  1739. this.onmousewheelhr = function(e) {
  1740. if (self.locked||!self.railh.scrollable) return true;
  1741. if (self.rail.drag) return self.cancelEvent(e);
  1742. var nw = +(new Date());
  1743. var chk = false;
  1744. if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
  1745. // self.checkarea = false;
  1746. self.nativescrollingarea = self.isScrollable(e);
  1747. chk = true;
  1748. }
  1749. self.checkarea = nw;
  1750. if (self.nativescrollingarea) return true; // this isn't my business
  1751. if (self.locked) return self.cancelEvent(e);
  1752. return execScrollWheel(e,true,chk);
  1753. };
  1754. this.stop = function() {
  1755. self.cancelScroll();
  1756. if (self.scrollmon) self.scrollmon.stop();
  1757. self.cursorfreezed = false;
  1758. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1759. self.noticeCursor();
  1760. return self;
  1761. };
  1762. this.getTransitionSpeed = function(dif) {
  1763. var sp = Math.round(self.opt.scrollspeed*10);
  1764. var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
  1765. return (ex>20) ? ex : 0;
  1766. }
  1767. if (!self.opt.smoothscroll) {
  1768. this.doScrollLeft = function(x,spd) { //direct
  1769. var y = self.getScrollTop();
  1770. self.doScrollPos(x,y,spd);
  1771. }
  1772. this.doScrollTop = function(y,spd) { //direct
  1773. var x = self.getScrollLeft();
  1774. self.doScrollPos(x,y,spd);
  1775. }
  1776. this.doScrollPos = function(x,y,spd) { //direct
  1777. var nx = (x>self.page.maxw) ? self.page.maxw : x;
  1778. if (nx<0) nx=0;
  1779. var ny = (y>self.page.maxh) ? self.page.maxh : y;
  1780. if (ny<0) ny=0;
  1781. self.synched('scroll',function(){
  1782. self.setScrollTop(ny);
  1783. self.setScrollLeft(nx);
  1784. });
  1785. }
  1786. this.cancelScroll = function() {}; // direct
  1787. }
  1788. else if (self.ishwscroll&&cap.hastransition&&self.opt.usetransition) {
  1789. this.prepareTransition = function(dif,istime) {
  1790. var ex = (istime) ? ((dif>20)?dif:0) : self.getTransitionSpeed(dif);
  1791. var trans = (ex) ? cap.prefixstyle+'transform '+ex+'ms ease-out' : '';
  1792. if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
  1793. self.lasttransitionstyle = trans;
  1794. self.doc.css(cap.transitionstyle,trans);
  1795. }
  1796. return ex;
  1797. };
  1798. this.doScrollLeft = function(x,spd) { //trans
  1799. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  1800. self.doScrollPos(x,y,spd);
  1801. }
  1802. this.doScrollTop = function(y,spd) { //trans
  1803. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  1804. self.doScrollPos(x,y,spd);
  1805. }
  1806. this.doScrollPos = function(x,y,spd) { //trans
  1807. var py = self.getScrollTop();
  1808. var px = self.getScrollLeft();
  1809. if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll(); //inverted movement detection
  1810. if (self.opt.bouncescroll==false) {
  1811. if (y<0) y=0;
  1812. else if (y>self.page.maxh) y=self.page.maxh;
  1813. if (x<0) x=0;
  1814. else if (x>self.page.maxw) x=self.page.maxw;
  1815. }
  1816. if (x==self.newscrollx&&y==self.newscrolly) return false;
  1817. self.newscrolly = y;
  1818. self.newscrollx = x;
  1819. self.newscrollspeed = spd||false;
  1820. if (self.timer) return false;
  1821. self.timer = setTimeout(function(){
  1822. var top = self.getScrollTop();
  1823. var lft = self.getScrollLeft();
  1824. var dst = {};
  1825. dst.x = x-lft;
  1826. dst.y = y-top;
  1827. dst.px = lft;
  1828. dst.py = top;
  1829. var dd = Math.round(Math.sqrt(Math.pow(dst.x,2)+Math.pow(dst.y,2)));
  1830. var df = (self.newscrollspeed) ? self.newscrollspeed : dd;
  1831. var ms = self.prepareTransition(df);
  1832. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1833. if (ms>0) {
  1834. if (!self.scrollrunning&&self.onscrollstart) {
  1835. var info = {"type":"scrollstart","current":{"x":lft,"y":top},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
  1836. self.onscrollstart.call(self,info);
  1837. }
  1838. if (cap.transitionend) {
  1839. if (!self.scrollendtrapped) {
  1840. self.scrollendtrapped = true;
  1841. self.bind(self.doc,cap.transitionend,self.onScrollEnd,false); //I have got to do something usefull!!
  1842. }
  1843. } else {
  1844. if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
  1845. self.scrollendtrapped = setTimeout(self.onScrollEnd,ms); // simulate transitionend event
  1846. }
  1847. var py = top;
  1848. var px = lft;
  1849. self.timerscroll = {
  1850. bz: new BezierClass(py,self.newscrolly,ms,0,0,0.58,1),
  1851. bh: new BezierClass(px,self.newscrollx,ms,0,0,0.58,1)
  1852. };
  1853. if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop(),self.getScrollLeft())},60);
  1854. }
  1855. self.synched("doScroll-set",function(){
  1856. self.timer = 0;
  1857. if (self.scrollendtrapped) self.scrollrunning = true;
  1858. self.setScrollTop(self.newscrolly);
  1859. self.setScrollLeft(self.newscrollx);
  1860. if (!self.scrollendtrapped) self.onScrollEnd();
  1861. });
  1862. },50);
  1863. };
  1864. this.cancelScroll = function() {
  1865. if (!self.scrollendtrapped) return true;
  1866. var py = self.getScrollTop();
  1867. var px = self.getScrollLeft();
  1868. self.scrollrunning = false;
  1869. if (!cap.transitionend) clearTimeout(cap.transitionend);
  1870. self.scrollendtrapped = false;
  1871. self._unbind(self.doc,cap.transitionend,self.onScrollEnd);
  1872. self.prepareTransition(0);
  1873. self.setScrollTop(py); // fire event onscroll
  1874. if (self.railh) self.setScrollLeft(px);
  1875. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1876. self.timerscroll = false;
  1877. self.cursorfreezed = false;
  1878. //self.noticeCursor(false,py,px);
  1879. self.showCursor(py,px);
  1880. return self;
  1881. };
  1882. this.onScrollEnd = function() {
  1883. if (self.scrollendtrapped) self._unbind(self.doc,cap.transitionend,self.onScrollEnd);
  1884. self.scrollendtrapped = false;
  1885. self.prepareTransition(0);
  1886. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1887. self.timerscroll = false;
  1888. var py = self.getScrollTop();
  1889. var px = self.getScrollLeft();
  1890. self.setScrollTop(py); // fire event onscroll
  1891. if (self.railh) self.setScrollLeft(px); // fire event onscroll left
  1892. self.noticeCursor(false,py,px);
  1893. self.cursorfreezed = false;
  1894. if (py<0) py=0
  1895. else if (py>self.page.maxh) py=self.page.maxh;
  1896. if (px<0) px=0
  1897. else if (px>self.page.maxw) px=self.page.maxw;
  1898. if((py!=self.newscrolly)||(px!=self.newscrollx)) return self.doScrollPos(px,py,self.opt.snapbackspeed);
  1899. if (self.onscrollend&&self.scrollrunning) {
  1900. var info = {"type":"scrollend","current":{"x":px,"y":py},"end":{"x":self.newscrollx,"y":self.newscrolly}};
  1901. self.onscrollend.call(self,info);
  1902. }
  1903. self.scrollrunning = false;
  1904. };
  1905. } else {
  1906. this.doScrollLeft = function(x) { //no-trans
  1907. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  1908. self.doScrollPos(x,y);
  1909. }
  1910. this.doScrollTop = function(y) { //no-trans
  1911. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  1912. self.doScrollPos(x,y);
  1913. }
  1914. this.doScrollPos = function(x,y) { //no-trans
  1915. var y = ((typeof y == "undefined")||(y===false)) ? self.getScrollTop(true) : y;
  1916. if ((self.timer)&&(self.newscrolly==y)&&(self.newscrollx==x)) return true;
  1917. if (self.timer) clearAnimationFrame(self.timer);
  1918. self.timer = 0;
  1919. var py = self.getScrollTop();
  1920. var px = self.getScrollLeft();
  1921. if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll(); //inverted movement detection
  1922. self.newscrolly = y;
  1923. self.newscrollx = x;
  1924. if (!self.bouncescroll||!self.rail.visibility) {
  1925. if (self.newscrolly<0) {
  1926. self.newscrolly = 0;
  1927. }
  1928. else if (self.newscrolly>self.page.maxh) {
  1929. self.newscrolly = self.page.maxh;
  1930. }
  1931. }
  1932. if (!self.bouncescroll||!self.railh.visibility) {
  1933. if (self.newscrollx<0) {
  1934. self.newscrollx = 0;
  1935. }
  1936. else if (self.newscrollx>self.page.maxw) {
  1937. self.newscrollx = self.page.maxw;
  1938. }
  1939. }
  1940. self.dst = {};
  1941. self.dst.x = x-px;
  1942. self.dst.y = y-py;
  1943. self.dst.px = px;
  1944. self.dst.py = py;
  1945. var dst = Math.round(Math.sqrt(Math.pow(self.dst.x,2)+Math.pow(self.dst.y,2)));
  1946. self.dst.ax = self.dst.x / dst;
  1947. self.dst.ay = self.dst.y / dst;
  1948. var pa = 0;
  1949. var pe = dst;
  1950. if (self.dst.x==0) {
  1951. pa = py;
  1952. pe = y;
  1953. self.dst.ay = 1;
  1954. self.dst.py = 0;
  1955. } else if (self.dst.y==0) {
  1956. pa = px;
  1957. pe = x;
  1958. self.dst.ax = 1;
  1959. self.dst.px = 0;
  1960. }
  1961. var ms = self.getTransitionSpeed(dst);
  1962. if (ms>0) {
  1963. self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe,ms) : new BezierClass(pa,pe,ms,0,1,0,1);
  1964. } else {
  1965. self.bzscroll = false;
  1966. }
  1967. if (self.timer) return;
  1968. if ((py==self.page.maxh&&y>=self.page.maxh)||(px==self.page.maxw&&x>=self.page.maxw)) self.checkContentSize();
  1969. var sync = 1;
  1970. function scrolling() {
  1971. if (self.cancelAnimationFrame) return true;
  1972. self.scrollrunning = true;
  1973. sync = 1-sync;
  1974. if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
  1975. var done = 0;
  1976. var sc = sy = self.getScrollTop();
  1977. if (self.dst.ay) {
  1978. sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow()*self.dst.ay) : self.newscrolly;
  1979. var dr=sc-sy;
  1980. if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
  1981. self.setScrollTop(sc);
  1982. if (sc == self.newscrolly) done=1;
  1983. } else {
  1984. done=1;
  1985. }
  1986. var scx = sx = self.getScrollLeft();
  1987. if (self.dst.ax) {
  1988. scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow()*self.dst.ax) : self.newscrollx;
  1989. var dr=scx-sx;
  1990. if ((dr<0&&scx<self.newscrollx)||(dr>0&&scx>self.newscrollx)) scx = self.newscrollx;
  1991. self.setScrollLeft(scx);
  1992. if (scx == self.newscrollx) done+=1;
  1993. } else {
  1994. done+=1;
  1995. }
  1996. if (done==2) {
  1997. self.timer = 0;
  1998. self.cursorfreezed = false;
  1999. self.bzscroll = false;
  2000. self.scrollrunning = false;
  2001. if (sc<0) sc=0;
  2002. else if (sc>self.page.maxh) sc=self.page.maxh;
  2003. if (scx<0) scx=0;
  2004. else if (scx>self.page.maxw) scx=self.page.maxw;
  2005. if ((scx!=self.newscrollx)||(sc!=self.newscrolly)) self.doScrollPos(scx,sc);
  2006. else {
  2007. if (self.onscrollend) {
  2008. var info = {"type":"scrollend","current":{"x":sx,"y":sy},"end":{"x":self.newscrollx,"y":self.newscrolly}};
  2009. self.onscrollend.call(self,info);
  2010. }
  2011. }
  2012. } else {
  2013. self.timer = setAnimationFrame(scrolling)||1;
  2014. }
  2015. };
  2016. self.cancelAnimationFrame=false;
  2017. self.timer = 1;
  2018. if (self.onscrollstart&&!self.scrollrunning) {
  2019. var info = {"type":"scrollstart","current":{"x":px,"y":py},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
  2020. self.onscrollstart.call(self,info);
  2021. }
  2022. scrolling();
  2023. if ((py==self.page.maxh&&y>=py)||(px==self.page.maxw&&x>=px)) self.checkContentSize();
  2024. self.noticeCursor();
  2025. };
  2026. this.cancelScroll = function() {
  2027. if (self.timer) clearAnimationFrame(self.timer);
  2028. self.timer = 0;
  2029. self.bzscroll = false;
  2030. self.scrollrunning = false;
  2031. return self;
  2032. };
  2033. }
  2034. this.doScrollBy = function(stp,relative) {
  2035. var ny = 0;
  2036. if (relative) {
  2037. ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
  2038. } else {
  2039. var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
  2040. ny = sy-stp;
  2041. }
  2042. if (self.bouncescroll) {
  2043. var haf = Math.round(self.view.h/2);
  2044. if (ny<-haf) ny=-haf
  2045. else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
  2046. }
  2047. self.cursorfreezed = false;
  2048. py = self.getScrollTop(true);
  2049. if (ny<0&&py<=0) return self.noticeCursor();
  2050. else if (ny>self.page.maxh&&py>=self.page.maxh) {
  2051. self.checkContentSize();
  2052. return self.noticeCursor();
  2053. }
  2054. self.doScrollTop(ny);
  2055. };
  2056. this.doScrollLeftBy = function(stp,relative) {
  2057. var nx = 0;
  2058. if (relative) {
  2059. nx = Math.floor((self.scroll.x-stp)*self.scrollratio.x)
  2060. } else {
  2061. var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
  2062. nx = sx-stp;
  2063. }
  2064. if (self.bouncescroll) {
  2065. var haf = Math.round(self.view.w/2);
  2066. if (nx<-haf) nx=-haf
  2067. else if (nx>(self.page.maxw+haf)) nx = (self.page.maxw+haf);
  2068. }
  2069. self.cursorfreezed = false;
  2070. px = self.getScrollLeft(true);
  2071. if (nx<0&&px<=0) return self.noticeCursor();
  2072. else if (nx>self.page.maxw&&px>=self.page.maxw) return self.noticeCursor();
  2073. self.doScrollLeft(nx);
  2074. };
  2075. this.doScrollTo = function(pos,relative) {
  2076. var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
  2077. if (ny<0) ny=0
  2078. else if (ny>self.page.maxh) ny = self.page.maxh;
  2079. self.cursorfreezed = false;
  2080. self.doScrollTop(pos);
  2081. };
  2082. this.checkContentSize = function() {
  2083. var pg = self.getContentSize();
  2084. if ((pg.h!=self.page.h)||(pg.w!=self.page.w)) self.resize(false,pg);
  2085. };
  2086. self.onscroll = function(e) {
  2087. if (self.rail.drag) return;
  2088. if (!self.cursorfreezed) {
  2089. self.synched('scroll',function(){
  2090. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  2091. if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
  2092. self.noticeCursor();
  2093. });
  2094. }
  2095. };
  2096. self.bind(self.docscroll,"scroll",self.onscroll);
  2097. this.doZoomIn = function(e) {
  2098. if (self.zoomactive) return;
  2099. self.zoomactive = true;
  2100. self.zoomrestore = {
  2101. style:{}
  2102. };
  2103. var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
  2104. var win = self.win[0].style;
  2105. for(var a in lst) {
  2106. var pp = lst[a];
  2107. self.zoomrestore.style[pp] = (typeof win[pp]!='undefined') ? win[pp] : '';
  2108. }
  2109. self.zoomrestore.style.width = self.win.css('width');
  2110. self.zoomrestore.style.height = self.win.css('height');
  2111. self.zoomrestore.padding = {
  2112. w:self.win.outerWidth()-self.win.width(),
  2113. h:self.win.outerHeight()-self.win.height()
  2114. };
  2115. if (cap.isios4) {
  2116. self.zoomrestore.scrollTop = $(window).scrollTop();
  2117. $(window).scrollTop(0);
  2118. }
  2119. self.win.css({
  2120. "position":(cap.isios4)?"absolute":"fixed",
  2121. "top":0,
  2122. "left":0,
  2123. "z-index":parseInt(self.zindex)+100,
  2124. "margin":"0px"
  2125. });
  2126. var bkg = self.win.css("backgroundColor");
  2127. if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
  2128. self.rail.css({"z-index":parseInt(self.zindex)+110});
  2129. self.zoom.css({"z-index":parseInt(self.zindex)+112});
  2130. self.zoom.css('backgroundPosition','0px -18px');
  2131. self.resizeZoom();
  2132. if (self.onzoomin) self.onzoomin.call(self);
  2133. return self.cancelEvent(e);
  2134. };
  2135. this.doZoomOut = function(e) {
  2136. if (!self.zoomactive) return;
  2137. self.zoomactive = false;
  2138. self.win.css("margin","");
  2139. self.win.css(self.zoomrestore.style);
  2140. if (cap.isios4) {
  2141. $(window).scrollTop(self.zoomrestore.scrollTop);
  2142. }
  2143. self.rail.css({"z-index":self.zindex});
  2144. self.zoom.css({"z-index":self.zindex});
  2145. self.zoomrestore = false;
  2146. self.zoom.css('backgroundPosition','0px 0px');
  2147. self.onResize();
  2148. if (self.onzoomout) self.onzoomout.call(self);
  2149. return self.cancelEvent(e);
  2150. };
  2151. this.doZoom = function(e) {
  2152. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  2153. };
  2154. this.resizeZoom = function() {
  2155. if (!self.zoomactive) return;
  2156. var py = self.getScrollTop(); //preserve scrolling position
  2157. self.win.css({
  2158. width:$(window).width()-self.zoomrestore.padding.w+"px",
  2159. height:$(window).height()-self.zoomrestore.padding.h+"px"
  2160. });
  2161. self.onResize();
  2162. self.setScrollTop(Math.min(self.page.maxh,py));
  2163. };
  2164. this.init();
  2165. $.nicescroll.push(this);
  2166. };
  2167. // Inspired by the work of Kin Blas
  2168. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  2169. var ScrollMomentumClass2D = function(nc) {
  2170. var self = this;
  2171. this.nc = nc;
  2172. this.lastx = 0;
  2173. this.lasty = 0;
  2174. this.speedx = 0;
  2175. this.speedy = 0;
  2176. this.lasttime = 0;
  2177. this.steptime = 0;
  2178. this.snapx = false;
  2179. this.snapy = false;
  2180. this.demulx = 0;
  2181. this.demuly = 0;
  2182. this.lastscrollx = -1;
  2183. this.lastscrolly = -1;
  2184. this.chkx = 0;
  2185. this.chky = 0;
  2186. this.timer = 0;
  2187. this.time = function() {
  2188. return +new Date();//beautifull hack
  2189. };
  2190. this.reset = function(px,py) {
  2191. self.stop();
  2192. var now = self.time();
  2193. self.steptime = 0;
  2194. self.lasttime = now;
  2195. self.speedx = 0;
  2196. self.speedy = 0;
  2197. self.lastx = px;
  2198. self.lasty = py;
  2199. self.lastscrollx = -1;
  2200. self.lastscrolly = -1;
  2201. };
  2202. this.update = function(px,py) {
  2203. var now = self.time();
  2204. self.steptime = now - self.lasttime;
  2205. self.lasttime = now;
  2206. var dy = py - self.lasty;
  2207. var dx = px - self.lastx;
  2208. var sy = self.nc.getScrollTop();
  2209. var sx = self.nc.getScrollLeft();
  2210. var newy = sy + dy;
  2211. var newx = sx + dx;
  2212. self.snapx = (newx<0)||(newx>self.nc.page.maxw);
  2213. self.snapy = (newy<0)||(newy>self.nc.page.maxh);
  2214. self.speedx = dx;
  2215. self.speedy = dy;
  2216. self.lastx = px;
  2217. self.lasty = py;
  2218. };
  2219. this.stop = function() {
  2220. self.nc.unsynched("domomentum2d");
  2221. if (self.timer) clearTimeout(self.timer);
  2222. self.timer = 0;
  2223. self.lastscrollx = -1;
  2224. self.lastscrolly = -1;
  2225. };
  2226. this.doSnapy = function(nx,ny) {
  2227. var snap = false;
  2228. if (ny<0) {
  2229. ny=0;
  2230. snap=true;
  2231. }
  2232. else if (ny>self.nc.page.maxh) {
  2233. ny=self.nc.page.maxh;
  2234. snap=true;
  2235. }
  2236. if (nx<0) {
  2237. nx=0;
  2238. snap=true;
  2239. }
  2240. else if (nx>self.nc.page.maxw) {
  2241. nx=self.nc.page.maxw;
  2242. snap=true;
  2243. }
  2244. if (snap) self.nc.doScrollPos(nx,ny,self.nc.opt.snapbackspeed);
  2245. };
  2246. this.doMomentum = function(gp) {
  2247. var t = self.time();
  2248. var l = (gp) ? t+gp : self.lasttime;
  2249. var sl = self.nc.getScrollLeft();
  2250. var st = self.nc.getScrollTop();
  2251. var pageh = self.nc.page.maxh;
  2252. var pagew = self.nc.page.maxw;
  2253. self.speedx = (pagew>0) ? Math.min(60,self.speedx) : 0;
  2254. self.speedy = (pageh>0) ? Math.min(60,self.speedy) : 0;
  2255. var chk = l && (t - l) <= 50;
  2256. if ((st<0)||(st>pageh)||(sl<0)||(sl>pagew)) chk = false;
  2257. var sy = (self.speedy && chk) ? self.speedy : false;
  2258. var sx = (self.speedx && chk) ? self.speedx : false;
  2259. if (sy||sx) {
  2260. var tm = Math.max(16,self.steptime); //timeout granularity
  2261. if (tm>50) { // do smooth
  2262. var xm = tm/50;
  2263. self.speedx*=xm;
  2264. self.speedy*=xm;
  2265. tm = 50;
  2266. }
  2267. self.demulxy = 0;
  2268. self.lastscrollx = self.nc.getScrollLeft();
  2269. self.chkx = self.lastscrollx;
  2270. self.lastscrolly = self.nc.getScrollTop();
  2271. self.chky = self.lastscrolly;
  2272. var nx = self.lastscrollx;
  2273. var ny = self.lastscrolly;
  2274. var onscroll = function(){
  2275. var df = ((self.time()-t)>600) ? 0.04 : 0.02;
  2276. if (self.speedx) {
  2277. nx = Math.floor(self.lastscrollx - (self.speedx*(1-self.demulxy)));
  2278. self.lastscrollx = nx;
  2279. if ((nx<0)||(nx>pagew)) df=0.10;
  2280. }
  2281. if (self.speedy) {
  2282. ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demulxy)));
  2283. self.lastscrolly = ny;
  2284. if ((ny<0)||(ny>pageh)) df=0.10;
  2285. }
  2286. self.demulxy = Math.min(1,self.demulxy+df);
  2287. self.nc.synched("domomentum2d",function(){
  2288. if (self.speedx) {
  2289. var scx = self.nc.getScrollLeft();
  2290. if (scx!=self.chkx) self.stop();
  2291. self.chkx=nx;
  2292. self.nc.setScrollLeft(nx);
  2293. }
  2294. if (self.speedy) {
  2295. var scy = self.nc.getScrollTop();
  2296. if (scy!=self.chky) self.stop();
  2297. self.chky=ny;
  2298. self.nc.setScrollTop(ny);
  2299. }
  2300. if(!self.timer) {
  2301. self.nc.hideCursor();
  2302. self.doSnapy(nx,ny);
  2303. }
  2304. });
  2305. if (self.demulxy<1) {
  2306. self.timer = setTimeout(onscroll,tm);
  2307. } else {
  2308. self.stop();
  2309. self.nc.hideCursor();
  2310. self.doSnapy(nx,ny);
  2311. }
  2312. };
  2313. onscroll();
  2314. } else {
  2315. self.doSnapy(self.nc.getScrollLeft(),self.nc.getScrollTop());
  2316. }
  2317. }
  2318. };
  2319. // override jQuery scrollTop
  2320. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  2321. jQuery.cssHooks["pageYOffset"] = {
  2322. get: function(elem,computed,extra) {
  2323. var nice = $.data(elem,'__nicescroll')||false;
  2324. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  2325. },
  2326. set: function(elem,value) {
  2327. var nice = $.data(elem,'__nicescroll')||false;
  2328. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
  2329. return this;
  2330. }
  2331. };
  2332. /*
  2333. $.fx.step["scrollTop"] = function(fx){
  2334. $.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
  2335. };
  2336. */
  2337. jQuery.fn.scrollTop = function(value) {
  2338. if (typeof value == "undefined") {
  2339. var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
  2340. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  2341. } else {
  2342. return this.each(function() {
  2343. var nice = $.data(this,'__nicescroll')||false;
  2344. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
  2345. });
  2346. }
  2347. }
  2348. // override jQuery scrollLeft
  2349. var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
  2350. $.cssHooks.pageXOffset = {
  2351. get: function(elem,computed,extra) {
  2352. var nice = $.data(elem,'__nicescroll')||false;
  2353. return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
  2354. },
  2355. set: function(elem,value) {
  2356. var nice = $.data(elem,'__nicescroll')||false;
  2357. (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem,value);
  2358. return this;
  2359. }
  2360. };
  2361. /*
  2362. $.fx.step["scrollLeft"] = function(fx){
  2363. $.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
  2364. };
  2365. */
  2366. jQuery.fn.scrollLeft = function(value) {
  2367. if (typeof value == "undefined") {
  2368. var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
  2369. return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
  2370. } else {
  2371. return this.each(function() {
  2372. var nice = $.data(this,'__nicescroll')||false;
  2373. (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this),value);
  2374. });
  2375. }
  2376. }
  2377. var NiceScrollArray = function(doms) {
  2378. var self = this;
  2379. this.length = 0;
  2380. this.name = "nicescrollarray";
  2381. this.each = function(fn) {
  2382. for(var a=0;a<self.length;a++) fn.call(self[a]);
  2383. return self;
  2384. };
  2385. this.push = function(nice) {
  2386. self[self.length]=nice;
  2387. self.length++;
  2388. };
  2389. this.eq = function(idx) {
  2390. return self[idx];
  2391. };
  2392. if (doms) {
  2393. for(a=0;a<doms.length;a++) {
  2394. var nice = $.data(doms[a],'__nicescroll')||false;
  2395. if (nice) {
  2396. this[this.length]=nice;
  2397. this.length++;
  2398. }
  2399. };
  2400. }
  2401. return this;
  2402. };
  2403. function mplex(el,lst,fn) {
  2404. for(var a=0;a<lst.length;a++) fn(el,lst[a]);
  2405. };
  2406. mplex(
  2407. NiceScrollArray.prototype,
  2408. ['show','hide','toggle','onResize','resize','remove','stop','doScrollPos'],
  2409. function(e,n) {
  2410. e[n] = function(){
  2411. var args = arguments;
  2412. return this.each(function(){
  2413. this[n].apply(this,args);
  2414. });
  2415. };
  2416. }
  2417. );
  2418. jQuery.fn.getNiceScroll = function(index) {
  2419. if (typeof index == "undefined") {
  2420. return new NiceScrollArray(this);
  2421. } else {
  2422. var nice = $.data(this[index],'__nicescroll')||false;
  2423. return nice;
  2424. }
  2425. };
  2426. jQuery.extend(jQuery.expr[':'], {
  2427. nicescroll: function(a) {
  2428. return ($.data(a,'__nicescroll'))?true:false;
  2429. }
  2430. });
  2431. $.fn.niceScroll = function(wrapper,opt) {
  2432. if (typeof opt=="undefined") {
  2433. if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
  2434. opt = wrapper;
  2435. wrapper = false;
  2436. }
  2437. }
  2438. var ret = new NiceScrollArray();
  2439. if (typeof opt=="undefined") opt = {};
  2440. if (wrapper||false) {
  2441. opt.doc = $(wrapper);
  2442. opt.win = $(this);
  2443. }
  2444. var docundef = !("doc" in opt);
  2445. if (!docundef&&!("win" in opt)) opt.win = $(this);
  2446. this.each(function() {
  2447. var nice = $(this).data('__nicescroll')||false;
  2448. if (!nice) {
  2449. opt.doc = (docundef) ? $(this) : opt.doc;
  2450. nice = new NiceScrollClass(opt,$(this));
  2451. $(this).data('__nicescroll',nice);
  2452. }
  2453. ret.push(nice);
  2454. });
  2455. return (ret.length==1) ? ret[0] : ret;
  2456. };
  2457. window.NiceScroll = {
  2458. getjQuery:function(){return jQuery}
  2459. };
  2460. if (!$.nicescroll) {
  2461. $.nicescroll = new NiceScrollArray();
  2462. $.nicescroll.options = _globaloptions;
  2463. }
  2464. })( jQuery );