jquery.nicescroll.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. /* jquery.nicescroll
  2. -- version 2.9.6
  3. -- copyright 2011-12 InuYaksa*2012
  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 NiceScrollClass = function(myopt,me) {
  43. var self = this;
  44. this.version = '2.9.6';
  45. this.name = 'nicescroll';
  46. this.me = me;
  47. this.opt = {
  48. doc:$("body"),
  49. win:false,
  50. zindex:9000,
  51. cursoropacitymin:0,
  52. cursoropacitymax:1,
  53. cursorcolor:"#424242",
  54. cursorwidth:"5px",
  55. cursorborder:"1px solid #fff",
  56. cursorborderradius:"5px",
  57. scrollspeed:60,
  58. mousescrollstep:8*5,
  59. touchbehavior:false,
  60. hwacceleration:true,
  61. usetransition:true,
  62. boxzoom:false,
  63. dblclickzoom:true,
  64. gesturezoom:true,
  65. grabcursorenabled:true,
  66. autohidemode:true,
  67. background:"",
  68. iframeautoresize:true,
  69. cursorminheight:20,
  70. preservenativescrolling:true,
  71. railoffset:false,
  72. bouncescroll:false,
  73. spacebarenabled:true,
  74. railpadding:{top:0,right:0,left:0,bottom:0},
  75. disableoutline:true
  76. };
  77. if (myopt||false) {
  78. for(var a in self.opt) {
  79. if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
  80. }
  81. }
  82. this.doc = self.opt.doc;
  83. this.iddoc = (this.doc&&this.doc[0])?this.doc[0].id||'':'';
  84. this.ispage = /BODY|HTML/.test((self.opt.win)?self.opt.win[0].nodeName:this.doc[0].nodeName);
  85. this.haswrapper = (self.opt.win!==false);
  86. this.win = self.opt.win||(this.ispage?$(window):this.doc);
  87. this.docscroll = (this.ispage&&!this.haswrapper)?$(window):this.win;
  88. this.body = $("body");
  89. this.iframe = false;
  90. this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
  91. this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
  92. // Events jump table
  93. this.onmousedown = false;
  94. this.onmouseup = false;
  95. this.onmousemove = false;
  96. this.onmousewheel = false;
  97. this.onkeypress = false;
  98. this.ongesturezoom = false;
  99. this.onclick = false;
  100. // Let's start!
  101. this.view = false;
  102. this.page = false;
  103. this.observer = false;
  104. this.scroll = {x:0,y:0};
  105. this.scrollratio = {x:0,y:0};
  106. this.cursorheight = 20;
  107. this.scrollvaluemax = 0;
  108. this.scrollmom = false;
  109. do {
  110. this.id = "ascrail"+(ascrailcounter++);
  111. } while (document.getElementById(this.id));
  112. this.rail = false;
  113. this.cursor = false;
  114. this.cursorfreezed = false;
  115. this.zoom = false;
  116. this.zoomactive = false;
  117. this.hasfocus = false;
  118. this.hasmousefocus = false;
  119. this.visibility = true;
  120. this.locked = false;
  121. this.hidden = false; // rails always hidden
  122. this.nativescrollingarea = false;
  123. this.events = []; // event list for unbind
  124. this.saved = {};
  125. this.delaylist = {};
  126. this.synclist = {};
  127. this.lastdelta = 0;
  128. var domtest = document.createElement('DIV');
  129. this.isopera = ("opera" in window);
  130. this.isie = (("all" in document) && ("attachEvent" in domtest) && !this.isopera);
  131. this.isieold = (this.isie && !("msInterpolationMode" in domtest.style)); // IE6 and older
  132. this.isie7 = this.isie&&!this.isieold&&(!("documentMode" in document)||(document.documentMode==7));
  133. this.isie8 = this.isie&&("documentMode" in document)&&(document.documentMode==8);
  134. this.isie9 = this.isie&&("performance" in window)&&(document.documentMode>=9);
  135. this.isie9mobile = /iemobile.9/i.test(navigator.userAgent); //wp 7.1 mango
  136. this.isie7mobile = (!this.isie9mobile&&this.isie7) && /iemobile/i.test(navigator.userAgent); //wp 7.0
  137. this.ismozilla = ("MozAppearance" in domtest.style);
  138. this.ischrome = ("chrome" in window);
  139. this.cantouch = ("ontouchstart" in document.documentElement);
  140. this.hasmstouch = (window.navigator.msPointerEnabled||false); // IE10+ pointer events - EXPERIMENTAL
  141. /* alternative methods to detect touch support */
  142. /* thanks modernizr.github.com/Modernizr/touch.html */
  143. // if (!this.cantouch) this.cantouch = (typeof TouchEvent != "undefined"); // NOT READY -> testing session (false positive on chrome19)
  144. /* */
  145. this.isios = (this.cantouch && /iphone|ipad|ipod/i.test(navigator.platform));
  146. this.isios4 = ((this.isios)&&!("seal" in Object));
  147. if (self.opt.hwacceleration) { // if you dont need dont bother to look for
  148. this.trstyle = (window.opera) ? 'OTransform' : (document.all) ? 'msTransform' : (domtest.style.webkitTransform!==undefined) ? 'webkitTransform' : (domtest.style.MozTransform!==undefined) ? 'MozTransform' : false;
  149. if (this.trstyle && typeof domtest.style[this.trstyle] == "undefined") this.trstyle = false;
  150. this.hastransform = (this.trstyle != false);
  151. if (this.hastransform) {
  152. domtest.style[this.trstyle] = "translate3d(1px,2px,3px)";
  153. this.hastranslate3d = /translate3d/.test(domtest.style[this.trstyle]);
  154. }
  155. this.transitionstyle = false;
  156. this.prefixstyle = '';
  157. this.transitionend = false;
  158. var check = ['transition','webkitTransition','MozTransition','OTransition','msTransition','KhtmlTransition'];
  159. var prefix = ['','-webkit-','-moz-','-o-','-ms-','-khtml-'];
  160. var evs = ['transitionEnd','webkitTransitionEnd','transitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
  161. for(var a=0;a<check.length;a++) {
  162. if (check[a] in domtest.style) {
  163. this.transitionstyle = check[a];
  164. this.prefixstyle = prefix[a];
  165. this.transitionend = evs[a];
  166. break;
  167. }
  168. }
  169. this.hastransition = (this.transitionstyle);
  170. } else {
  171. this.trstyle = false;
  172. this.hastransform = false;
  173. this.hastranslate3d = false;
  174. this.transitionstyle = false;
  175. this.hastransition = false;
  176. this.transitionend = false;
  177. }
  178. this.cursorgrabvalue = '';
  179. if (self.opt.grabcursorenabled&&self.opt.touchbehavior) { // check grab cursor support
  180. function detectCursorGrab() {
  181. // thank you google for custom cursor!
  182. var lst = ['-moz-grab','-webkit-grab','grab'];
  183. if (self.ischrome||self.isie) lst=[]; // force setting for IE returns false positive and chrome cursor bug
  184. for(var a=0;a<lst.length;a++) {
  185. var p = lst[a];
  186. domtest.style['cursor']=p;
  187. if (domtest.style['cursor']==p) return p;
  188. }
  189. return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize';
  190. }
  191. this.cursorgrabvalue = detectCursorGrab();
  192. }
  193. domtest = null; //memory released
  194. this.ishwscroll = (self.hastransform)&&(self.opt.hwacceleration)&&(self.haswrapper);
  195. this.delayed = function(name,fn,tm) {
  196. var dd = self.delaylist[name];
  197. var nw = (new Date()).getTime();
  198. if (dd&&dd.tt) return false;
  199. if (dd&&dd.last+tm>nw&&!dd.tt) {
  200. self.delaylist[name] = {
  201. last:nw+tm,
  202. tt:setTimeout(function(){self.delaylist[name].tt=0;fn.call();},tm)
  203. }
  204. }
  205. else if (!dd||!dd.tt) {
  206. self.delaylist[name] = {
  207. last:nw,
  208. tt:0
  209. }
  210. setTimeout(function(){fn.call();},0);
  211. }
  212. };
  213. this.requestSync = function() {
  214. if (self.onsync) return;
  215. setAnimationFrame(function(){
  216. self.onsync = false;
  217. for(name in self.synclist){
  218. var fn = self.synclist[name];
  219. if (fn) fn.call(self);
  220. self.synclist[name] = false;
  221. }
  222. });
  223. self.onsync = true;
  224. };
  225. this.synched = function(name,fn) {
  226. self.synclist[name] = fn;
  227. self.requestSync();
  228. };
  229. this.css = function(el,pars) { // save & set
  230. for(var n in pars) {
  231. self.saved.css.push([el,n,el.css(n)]);
  232. el.css(n,pars[n]);
  233. }
  234. };
  235. this.scrollTop = function(val) {
  236. return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
  237. };
  238. // derived by by Dan Pupius www.pupius.net
  239. BezierClass = function(st,ed,spd,p1,p2,p3,p4) {
  240. this.st = st;
  241. this.ed = ed;
  242. this.spd = spd;
  243. this.p1 = p1||0;
  244. this.p2 = p2||1;
  245. this.p3 = p3||0;
  246. this.p4 = p4||1;
  247. this.ts = (new Date()).getTime();
  248. this.df = this.ed-this.st;
  249. };
  250. BezierClass.prototype = {
  251. B2:function(t){ return 3*t*t*(1-t) },
  252. B3:function(t){ return 3*t*(1-t)*(1-t) },
  253. B4:function(t){ return (1-t)*(1-t)*(1-t) },
  254. getNow:function(){
  255. var nw = (new Date()).getTime();
  256. var pc = 1-((nw-this.ts)/this.spd);
  257. var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
  258. return (pc<0) ? this.ed : this.st+Math.round(this.df*bz);
  259. },
  260. update:function(ed,spd){
  261. this.st = this.getNow();
  262. this.ed = ed;
  263. this.spd = spd;
  264. this.ts = (new Date()).getTime();
  265. this.df = this.ed-this.st;
  266. return this;
  267. }
  268. };
  269. if (this.ishwscroll) {
  270. // hw accelerated scroll
  271. this.doc.translate = {x:0,y:0};
  272. if (this.hastranslate3d) this.doc.css(this.prefixstyle+"backface-visibility","hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/
  273. this.getScrollTop = function(last) {
  274. if (self.timerscroll&&!last) {
  275. return self.timerscroll.bz.getNow();
  276. } else {
  277. return self.doc.translate.y;
  278. }
  279. };
  280. if (document.createEvent) {
  281. this.notifyScrollEvent = function(el) {
  282. var e = document.createEvent("UIEvents");
  283. e.initUIEvent("scroll", false, true, window, 1);
  284. el.dispatchEvent(e);
  285. };
  286. }
  287. else if (document.fireEvent) {
  288. this.notifyScrollEvent = function(el) {
  289. var e = document.createEventObject();
  290. el.fireEvent("onscroll");
  291. e.cancelBubble = true;
  292. };
  293. }
  294. else {
  295. this.notifyScrollEvent = function(el) {}; //NOPE
  296. }
  297. if (this.hastranslate3d) {
  298. this.setScrollTop = function(val,silent) {
  299. self.doc.css(self.trstyle,"translate3d(0px,"+(val*-1)+"px,0px)");
  300. self.doc.translate.y = val;
  301. if (!silent) self.notifyScrollEvent(self.win[0]);
  302. };
  303. } else {
  304. this.setScrollTop = function(val,silent) {
  305. self.doc.css(self.trstyle,"translate(0px,"+(val*-1)+"px)");
  306. self.doc.translate.y = val;
  307. if (!silent) self.notifyScrollEvent(self.win[0]);
  308. };
  309. }
  310. } else {
  311. // native scroll
  312. this.getScrollTop = function() {
  313. return self.docscroll.scrollTop();
  314. };
  315. this.setScrollTop = function(val) {
  316. return self.docscroll.scrollTop(val);
  317. };
  318. }
  319. this.getTarget = function(e) {
  320. if (!e) return false;
  321. if (e.target) return e.target;
  322. if (e.srcElement) return e.srcElement;
  323. return false;
  324. };
  325. this.hasParent = function(e,id) {
  326. if (!e) return false;
  327. var el = e.target||e.srcElement||e||false;
  328. while (el && el.id != id) {
  329. el = el.parentNode||false;
  330. }
  331. return (el!==false);
  332. };
  333. //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
  334. var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
  335. function getWidthToPixel(dom,prop,chkheight) {
  336. var wd = dom.css(prop);
  337. var px = parseFloat(wd);
  338. if (isNaN(px)) {
  339. px = _convertBorderWidth[wd]||0;
  340. var brd = (px==3) ? ((chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
  341. if (self.isie8&&px) px+=1;
  342. return (brd) ? px : 0;
  343. /*
  344. switch (wd) {
  345. case "thin":
  346. px = (self.isie8) ? 1 : 2;
  347. break;
  348. case "medium":
  349. var brd = (chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth()); //DON'T TRUST CSS
  350. px = (brd) ? ((self.isie8) ? 3 : 4) : 0;
  351. break;
  352. case "thick":
  353. px = (self.isie8) ? 5 : 6;
  354. break;
  355. }
  356. */
  357. }
  358. return px;
  359. };
  360. this.updateScrollBar = function(len) {
  361. if (self.ishwscroll) {
  362. self.rail.css({height:self.win.innerHeight()});
  363. } else {
  364. var pos = self.win.offset();
  365. pos.top+= getWidthToPixel(self.win,'border-top-width',true);
  366. // var brd = (self.win.outerWidth() - self.win.innerWidth());
  367. pos.left+= self.win.outerWidth() - getWidthToPixel(self.win,'border-right-width',false) - self.rail.width;
  368. var off = self.opt.railoffset;
  369. if (off) {
  370. if (off.top) pos.top+=off.top;
  371. if (off.left) pos.left+=off.left;
  372. }
  373. self.rail.css({top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
  374. if (self.zoom) self.zoom.css({top:pos.top+1,left:pos.left-20});
  375. }
  376. };
  377. self.hasanimationframe = (setAnimationFrame);
  378. self.hascancelanimationframe = (clearAnimationFrame);
  379. if (!self.hasanimationframe) {
  380. setAnimationFrame=function(fn){return setTimeout(fn,16)}; // 1000/60)};
  381. clearAnimationFrame=clearInterval;
  382. }
  383. else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
  384. this.init = function() {
  385. self.saved.css = [];
  386. if (self.isie7mobile) return true; // SORRY, DO NOT WORK!
  387. // if (self.hasmstouch) $("html").css('-ms-content-zooming','none');
  388. if (self.hasmstouch) self.css((self.ispage)?$("html"):self.win,{'-ms-touch-action':'none'});
  389. if (!self.ispage || (!self.cantouch && !self.isieold && !self.isie9mobile)) {
  390. var cont = self.docscroll;
  391. if (self.ispage) cont = (self.haswrapper)?self.win:self.doc;
  392. if (!self.isie9mobile) self.css(cont,{'overflow-y':'hidden'});
  393. if (self.ispage&&self.isie7&&self.win[0].nodeName=='BODY') self.css($("html"),{'overflow-y':'hidden'}); //IE7 double scrollbar issue
  394. var cursor = $(document.createElement('div'));
  395. cursor.css({
  396. position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
  397. 'background-color':self.opt.cursorcolor,
  398. border:self.opt.cursorborder,
  399. 'background-clip':'padding-box',
  400. '-webkit-border-radius':self.opt.cursorborderradius,
  401. '-moz-border-radius':self.opt.cursorborderradius,
  402. 'border-radius':self.opt.cursorborderradius
  403. });
  404. cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
  405. self.cursor = cursor;
  406. var rail = $(document.createElement('div'));
  407. rail.attr('id',self.id);
  408. rail.width = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth());
  409. rail.css({width:rail.width+"px",'zIndex':(self.ispage)?self.opt.zindex:self.opt.zindex+2,"background":self.opt.background});
  410. var kp = ["top","bottom","left","right"];
  411. for(var a in kp) {
  412. var v = self.opt.railpadding[a];
  413. if (v) rail.css("padding-"+a,v+"px");
  414. }
  415. rail.append(cursor);
  416. self.rail = rail;
  417. self.rail.drag = false;
  418. var zoom = false;
  419. if (self.opt.boxzoom&&!self.ispage&&!self.isieold) {
  420. zoom = document.createElement('div');
  421. self.bind(zoom,"click",self.doZoom);
  422. self.zoom = $(zoom);
  423. self.zoom.css({"cursor":"pointer",'z-index':self.opt.zindex,'backgroundImage':'url('+scriptpath+'zoomico.png)','height':18,'width':18,'backgroundPosition':'0px 0px'});
  424. if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
  425. if (self.cantouch&&self.opt.gesturezoom) {
  426. self.ongesturezoom = function(e) {
  427. if (e.scale>1.5) self.doZoomIn(e);
  428. if (e.scale<0.8) self.doZoomOut(e);
  429. return self.cancelEvent(e);
  430. };
  431. self.bind(self.win,"gestureend",self.ongesturezoom);
  432. }
  433. }
  434. if (self.ispage) {
  435. rail.css({position:"fixed",top:"0px",right:"0px",height:"100%"});
  436. self.body.append(rail);
  437. } else {
  438. if (self.ishwscroll) {
  439. if (self.win.css('position')=='static') self.css(self.win,{'position':'relative'});
  440. var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
  441. if (self.zoom) {
  442. self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
  443. bd.append(self.zoom);
  444. }
  445. rail.css({position:"absolute",top:0,right:0});
  446. bd.append(rail);
  447. } else {
  448. rail.css({position:"absolute"});
  449. if (self.zoom) self.zoom.css({position:"absolute"});
  450. self.updateScrollBar();
  451. self.body.append(rail);
  452. if (self.zoom) self.body.append(self.zoom);
  453. }
  454. if (self.isios) self.css(self.win,{'-webkit-tap-highlight-color':'rgba(0,0,0,0)','-webkit-touch-callout':'none'}); // prevent grey layer on click
  455. }
  456. if (self.opt.autohidemode===false) {
  457. self.autohidedom = false;
  458. }
  459. else if (self.opt.autohidemode===true) {
  460. self.autohidedom = self.rail;
  461. }
  462. else if (self.opt.autohidemode=="cursor") {
  463. self.autohidedom = self.cursor;
  464. }
  465. if (self.isie9mobile) {
  466. self.scrollmom = {
  467. y:new ScrollMomentumClass(self)
  468. };
  469. self.onmangotouch = function(e) {
  470. var py = self.getScrollTop();
  471. if (py == self.scrollmom.y.lastscrolly) return true;
  472. var df = py-self.mangotouch.sy;
  473. if (df==0) return;
  474. var dr = (df<0)?-1:1;
  475. var tm = (new Date()).getTime();
  476. if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
  477. if (((tm-self.mangotouch.tm)>60)||(self.mangotouch.dry!=dr)) {
  478. self.scrollmom.y.stop();
  479. self.scrollmom.y.reset(py);
  480. self.mangotouch.sy = py;
  481. self.mangotouch.ly = py;
  482. self.mangotouch.dry = dr;
  483. self.mangotouch.tm = tm;
  484. } else {
  485. self.scrollmom.y.stop();
  486. self.scrollmom.y.update(self.mangotouch.sy-df);
  487. var gap = tm - self.mangotouch.tm;
  488. self.mangotouch.tm = tm;
  489. var px = Math.abs(self.mangotouch.ly-py);
  490. self.mangotouch.ly = py;
  491. if (px>2) {
  492. self.mangotouch.lazy = setTimeout(function(){
  493. self.mangotouch.lazy = false;
  494. self.mangotouch.dry = 0;
  495. self.mangotouch.tm = 0;
  496. self.scrollmom.y.doMomentum(gap);
  497. },80);
  498. }
  499. }
  500. }
  501. var top = self.getScrollTop()
  502. self.mangotouch = {sy:top,ly:top,dry:0,lazy:false,tm:0};
  503. self.bind(self.docscroll,"scroll",self.onmangotouch);
  504. } else {
  505. if (self.cantouch||self.opt.touchbehavior||self.hasmstouch) {
  506. self.scrollmom = {
  507. y:new ScrollMomentumClass(self)
  508. };
  509. self.ontouchstart = function(e) {
  510. if (e.pointerType&&e.pointerType!=2) return false;
  511. if (!self.locked) {
  512. if (self.hasmstouch) {
  513. var tg = (e.target) ? e.target : false;
  514. while (tg) {
  515. var nc = $(tg).getNiceScroll();
  516. if ((nc.length>0)&&(nc[0].me == self.me)) break;
  517. if (nc.length>0) return false;
  518. if ((tg.nodeName=='DIV')&&(tg.id==self.id)) break;
  519. tg = (tg.parentNode) ? tg.parentNode : false;
  520. }
  521. }
  522. self.cancelScroll();
  523. self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,st:self.getScrollTop(),pt:2};
  524. self.hasmoving = false;
  525. self.lastmouseup = false;
  526. self.scrollmom.y.reset(e.clientY);
  527. if (!self.cantouch&&!self.hasmstouch) {
  528. var tg = self.getTarget(e);
  529. var ip = (tg)?/INPUT|SELECT|TEXTAREA/i.test(tg.nodeName):false;
  530. if (!ip) return self.cancelEvent(e);
  531. if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
  532. pc = {"tg":tg,"click":false};
  533. self.preventclick = pc;
  534. }
  535. }
  536. }
  537. };
  538. self.ontouchend = function(e) {
  539. if (e.pointerType&&e.pointerType!=2) return false;
  540. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  541. self.scrollmom.y.doMomentum();
  542. self.rail.drag = false;
  543. if (self.hasmoving) {
  544. self.hasmoving = false;
  545. self.lastmouseup = true;
  546. self.hideCursor();
  547. if (!self.cantouch) return self.cancelEvent(e);
  548. }
  549. }
  550. };
  551. self.ontouchmove = function(e) {
  552. if (e.pointerType&&e.pointerType!=2) return false;
  553. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  554. if (self.cantouch&&(typeof e.original == "undefined")) return true; // prevent ios "ghost" events by clickable elements
  555. self.hasmoving = true;
  556. if (self.preventclick&&!self.preventclick.click) {
  557. self.preventclick.click = self.preventclick.tg.onclick||false;
  558. self.preventclick.tg.onclick = self.onpreventclick;
  559. }
  560. var fy = e.clientY;
  561. var my = (fy-self.rail.drag.y);
  562. var ny = self.rail.drag.st-my;
  563. if (self.ishwscroll) {
  564. if (ny<0) {
  565. ny = Math.round(ny/2);
  566. fy = 0;
  567. }
  568. else if (ny>self.page.maxh) {
  569. ny = self.page.maxh+Math.round((ny-self.page.maxh)/2);
  570. fy = 0;
  571. }
  572. } else {
  573. if (ny<0) ny=0;
  574. if (ny>self.page.maxh) ny=self.page.maxh;
  575. }
  576. self.synched("touchmove",function(){
  577. if (self.rail.drag&&(self.rail.drag.pt==2)) {
  578. if (self.prepareTransition) self.prepareTransition(0);
  579. self.setScrollTop(ny);
  580. self.showCursor(ny);
  581. self.scrollmom.y.update(fy);
  582. }
  583. });
  584. return self.cancelEvent(e);
  585. }
  586. };
  587. }
  588. if (self.cantouch||self.opt.touchbehavior) {
  589. self.onpreventclick = function(e) {
  590. if (self.preventclick) {
  591. self.preventclick.tg.onclick = self.preventclick.click;
  592. self.preventclick = false;
  593. return self.cancelEvent(e);
  594. }
  595. }
  596. self.onmousedown = self.ontouchstart;
  597. self.onmouseup = self.ontouchend;
  598. self.onclick = (self.isios) ? false : function(e) {
  599. if (self.lastmouseup) {
  600. self.lastmouseup = false;
  601. return self.cancelEvent(e);
  602. } else {
  603. return true;
  604. }
  605. };
  606. self.onmousemove = self.ontouchmove;
  607. if (self.cursorgrabvalue) {
  608. self.css((self.ispage)?self.doc:self.win,{'cursor':self.cursorgrabvalue});
  609. self.css(self.rail,{'cursor':self.cursorgrabvalue});
  610. }
  611. } else {
  612. self.onmousedown = function(e) {
  613. if (self.rail.drag&&self.rail.drag.pt!=1) return;
  614. if (self.locked) return self.cancelEvent(e);
  615. self.cancelScroll();
  616. self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,pt:1};
  617. return self.cancelEvent(e);
  618. };
  619. self.onmouseup = function(e) {
  620. if (self.rail.drag) {
  621. if(self.rail.drag.pt!=1)return;
  622. self.rail.drag = false;
  623. return self.cancelEvent(e);
  624. }
  625. };
  626. self.onmousemove = function(e) {
  627. if (self.rail.drag) {
  628. if(self.rail.drag.pt!=1)return;
  629. self.scroll.y = self.rail.drag.sy + (e.clientY-self.rail.drag.y);
  630. if (self.scroll.y<0) self.scroll.y=0;
  631. var my = self.scrollvaluemax;
  632. if (self.scroll.y>my) self.scroll.y=my;
  633. self.synched('mousemove',function(){
  634. if (self.rail.drag&&(self.rail.drag.pt==1)) {
  635. self.showCursor();
  636. self.cursorfreezed = true;
  637. self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));
  638. }
  639. });
  640. return self.cancelEvent(e);
  641. } else {
  642. self.checkarea = true;
  643. }
  644. };
  645. }
  646. if (self.cantouch||self.opt.touchbehavior) {
  647. self.bind(self.win,"mousedown",self.onmousedown);
  648. }
  649. if (self.hasmstouch) {
  650. self.css(self.rail,{'-ms-touch-action':'none'});
  651. self.css(self.cursor,{'-ms-touch-action':'none'});
  652. self.bind(self.win,"MSPointerDown",self.ontouchstart);
  653. self.bind(document,"MSPointerUp",self.ontouchend);
  654. self.bind(document,"MSPointerMove",self.ontouchmove);
  655. self.bind(self.cursor,"MSGestureHold",function(e){e.preventDefault();});
  656. self.bind(self.cursor,"contextmenu",function(e){e.preventDefault();});
  657. }
  658. self.bind(self.cursor,"mousedown",self.onmousedown);
  659. self.bind(self.cursor,"mouseup",function(e) {
  660. if (self.rail.drag&&self.rail.drag.pt==2) return;
  661. self.rail.drag = false;
  662. self.hasmoving = false;
  663. self.hideCursor();
  664. return self.cancelEvent(e);
  665. });
  666. self.bind(document,"mouseup",self.onmouseup);
  667. self.bind(document,"mousemove",self.onmousemove);
  668. if (self.onclick) self.bind(document,"click",self.onclick);
  669. if (!self.cantouch) {
  670. self.rail.mouseenter(function() {
  671. self.showCursor();
  672. self.rail.active = true;
  673. });
  674. self.rail.mouseleave(function() {
  675. self.rail.active = false;
  676. if (!self.rail.drag) self.hideCursor();
  677. });
  678. if (!self.isiframe) self.bind((self.isie&&self.ispage) ? document : self.docscroll,"mousewheel",self.onmousewheel);
  679. self.bind(self.rail,"mousewheel",self.onmousewheel);
  680. }
  681. if (self.zoom) {
  682. self.zoom.mouseenter(function() {
  683. self.showCursor();
  684. self.rail.active = true;
  685. });
  686. self.zoom.mouseleave(function() {
  687. self.rail.active = false;
  688. if (!self.rail.drag) self.hideCursor();
  689. });
  690. }
  691. if (!self.ispage&&!self.cantouch&&!(/HTML|BODY/.test(self.win[0].nodeName))) {
  692. if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
  693. if (self.ischrome&&self.opt.disableoutline) self.win.css({"outline":"none"});
  694. self.win.focus(function(e) {
  695. domfocus = (self.getTarget(e)).id||true;
  696. self.hasfocus = true;
  697. self.noticeCursor();
  698. });
  699. self.win.blur(function(e) {
  700. domfocus = false;
  701. self.hasfocus = false;
  702. });
  703. self.win.mouseenter(function(e) {
  704. mousefocus = (self.getTarget(e)).id||true;
  705. self.hasmousefocus = true;
  706. self.noticeCursor();
  707. });
  708. self.win.mouseleave(function() {
  709. mousefocus = false;
  710. self.hasmousefocus = false;
  711. });
  712. };
  713. } // !ie9mobile
  714. //Thanks to http://www.quirksmode.org !!
  715. self.onkeypress = function(e) {
  716. if (self.locked&&self.page.maxh==0) return true;
  717. e = (e) ? e : window.e;
  718. var tg = self.getTarget(e);
  719. if (tg&&/INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
  720. var tp = tg.getAttribute('type')||tg.type||false;
  721. if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
  722. }
  723. if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
  724. var key = e.keyCode;
  725. if (self.locked&&key!=27) return self.cancelEvent(e);
  726. var ret = false;
  727. switch (key) {
  728. case 38:
  729. case 63233: //safari
  730. self.doScrollBy(24*3);
  731. ret = true;
  732. break;
  733. case 40:
  734. case 63235: //safari
  735. self.doScrollBy(-24*3);
  736. ret = true;
  737. break;
  738. case 33:
  739. case 63276: // safari
  740. self.doScrollBy(self.view.h);
  741. ret = true;
  742. break;
  743. case 34:
  744. case 63277: // safari
  745. self.doScrollBy(-self.view.h);
  746. ret = true;
  747. break;
  748. case 36:
  749. case 63273: // safari
  750. self.doScrollTo(0);
  751. ret = true;
  752. break;
  753. case 35:
  754. case 63275: // safari
  755. self.doScrollTo(self.page.maxh);
  756. ret = true;
  757. break;
  758. case 32:
  759. if (self.opt.spacebarenabled) {
  760. self.doScrollBy(-self.view.h);
  761. ret = true;
  762. }
  763. break;
  764. case 27: // ESC
  765. if (self.zoomactive) {
  766. self.doZoom();
  767. ret = true;
  768. }
  769. break;
  770. }
  771. if (ret) return self.cancelEvent(e);
  772. }
  773. };
  774. self.bind(document,(self.isopera)?"keypress":"keydown",self.onkeypress);
  775. self.bind(window,'resize',self.resize);
  776. self.bind(window,'orientationchange',self.resize);
  777. self.bind(window,"load",self.resize);
  778. // Trying a cross-browser implementation - good luck!
  779. self.onAttributeChange = function(e) {
  780. self.lazyResize();
  781. }
  782. if (!self.ispage&&!self.haswrapper) {
  783. // thanks to Filip http://stackoverflow.com/questions/1882224/
  784. if ("WebKitMutationObserver" in window) {
  785. self.observer = new WebKitMutationObserver(function(mutations) {
  786. mutations.forEach(self.onAttributeChange);
  787. });
  788. self.observer.observe(self.win[0],{attributes:true,subtree:false});
  789. } else {
  790. self.bind(self.win,(self.isie&&!self.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);
  791. if (self.isie9) self.win[0].attachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
  792. }
  793. }
  794. //
  795. if (!self.ispage&&self.opt.boxzoom) self.bind(window,"resize",self.resizeZoom);
  796. if (self.istextarea) self.bind(self.win,"mouseup",self.resize);
  797. self.resize();
  798. }
  799. if (this.doc[0].nodeName == 'IFRAME') {
  800. function oniframeload(e) {
  801. self.iframexd = false;
  802. try {
  803. var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
  804. var a = doc.domain;
  805. } catch(e){self.iframexd = true;doc=false};
  806. if (self.iframexd) return true; //cross-domain - I can't manage this
  807. if (self.isiframe) {
  808. self.iframe = {
  809. html:self.doc.contents().find('html')[0],
  810. body:self.doc.contents().find('body')[0]
  811. };
  812. self.getContentSize = function(){
  813. return {
  814. w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
  815. h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
  816. }
  817. }
  818. self.docscroll = $(this.contentWindow);
  819. }
  820. if (self.opt.iframeautoresize&&!self.isiframe) {
  821. self.win.scrollTop(0); // reset position
  822. self.doc.height(""); //reset height to fix browser bug
  823. var hh=Math.max(doc.getElementsByTagName('html')[0].scrollHeight,doc.body.scrollHeight);
  824. self.doc.height(hh);
  825. }
  826. self.resize();
  827. if (self.isie7) self.css($(doc).find('html'),{'overflow-y':'hidden'});
  828. self.css($(doc.body),{'overflow-y':'hidden'});
  829. if ('contentWindow' in this) {
  830. self.bind(this.contentWindow,"scroll",self.onscroll); //IE8 & minor
  831. } else {
  832. self.bind(doc,"scroll",self.onscroll);
  833. }
  834. self.bind(doc,"mouseup",self.onmouseup);
  835. self.bind(doc,"mousewheel",self.onmousewheel);
  836. self.bind(doc,(self.isopera)?"keypress":"keydown",self.onkeypress);
  837. if (self.cantouch||self.opt.touchbehavior) {
  838. self.bind(doc,"mousedown",self.onmousedown);
  839. if (self.cursorgrabvalue) self.css($(doc.body),{'cursor':self.cursorgrabvalue});
  840. }
  841. self.bind(doc,"mousemove",self.onmousemove);
  842. if (self.zoom) {
  843. if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
  844. if (self.ongesturezoom) self.bind(doc,"gestureend",self.ongesturezoom);
  845. }
  846. };
  847. if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
  848. setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
  849. }
  850. self.bind(this.doc,"load",oniframeload);
  851. }
  852. };
  853. this.showCursor = function(py) {
  854. if (self.cursortimeout) {
  855. clearTimeout(self.cursortimeout);
  856. self.cursortimeout = 0;
  857. }
  858. if (!self.rail) return;
  859. if (self.autohidedom) self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
  860. if (typeof py != "undefined") {
  861. self.scroll.y = Math.round(py * 1/self.scrollratio.y);
  862. }
  863. self.cursor.css({height:self.cursorheight,top:self.scroll.y});
  864. if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});
  865. };
  866. this.hideCursor = function(tm) {
  867. if (self.cursortimeout) return;
  868. if (!self.rail) return;
  869. if (!self.autohidedom) return;
  870. self.cursortimeout = setTimeout(function() {
  871. if (!self.rail.active) {
  872. self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
  873. if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
  874. }
  875. self.cursortimeout = 0;
  876. },tm||400);
  877. };
  878. this.noticeCursor = function(tm,py) {
  879. self.showCursor(py);
  880. self.hideCursor(tm);
  881. };
  882. this.getContentSize =
  883. (self.ispage) ?
  884. function(){
  885. return {
  886. w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
  887. h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
  888. }
  889. }
  890. : (self.haswrapper) ?
  891. function(){
  892. return {
  893. w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
  894. h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
  895. }
  896. }
  897. : function() {
  898. return {
  899. w:self.docscroll[0].scrollWidth,
  900. h:self.docscroll[0].scrollHeight
  901. }
  902. };
  903. this.onResize = function(e,page) {
  904. if (!self.haswrapper&&!self.ispage) {
  905. if (self.win.css('display')=='none') {
  906. if (self.visibility) self.hideRail();
  907. return false;
  908. } else {
  909. if (!self.visibility&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
  910. if (!self.hidden&&!self.visibility) self.showRail();
  911. }
  912. }
  913. var premaxh = self.page.maxh;
  914. var premaxw = self.page.maxw;
  915. var preview = {h:self.view.h,w:self.view.w};
  916. self.view = {
  917. w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
  918. h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
  919. };
  920. self.page = (page) ? page : self.getContentSize();
  921. self.page.maxh = Math.max(0,self.page.h - self.view.h);
  922. self.page.maxw = Math.max(0,self.page.w - self.view.w);
  923. if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
  924. // test position
  925. if (!self.ispage) {
  926. var pos = self.win.offset();
  927. if (self.lastposition) {
  928. var lst = self.lastposition;
  929. if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do
  930. }
  931. self.lastposition = pos;
  932. } else {
  933. return self; //nothing to do
  934. }
  935. }
  936. if (self.page.maxh==0) {
  937. self.hideRail();
  938. self.scrollvaluemax = 0;
  939. self.scroll.y = 0;
  940. self.scrollratio = {x:0,y:0};
  941. self.cursorheight = 0;
  942. self.locked = true;
  943. self.setScrollTop(0);
  944. return false;
  945. }
  946. else if (!self.hidden&&!self.visibility) {
  947. self.showRail();
  948. self.locked = false;
  949. }
  950. if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
  951. if (!self.ispage) self.updateScrollBar(self.view);
  952. self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
  953. self.cursorheight = Math.max(self.opt.cursorminheight,self.cursorheight);
  954. self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
  955. self.scrollratio = {
  956. x:0,
  957. y:(self.page.maxh/self.scrollvaluemax)
  958. };
  959. var sy = self.getScrollTop();
  960. if (sy>self.page.maxh) {
  961. self.doScroll(self.page.maxh);
  962. } else {
  963. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  964. self.noticeCursor();
  965. }
  966. return self;
  967. };
  968. this.resize = this.onResize; // hide internal method -- in future name can change
  969. this.lazyResize = function() {
  970. self.delayed('resize',self.resize,250);
  971. }
  972. this._bind = function(el,name,fn,bubble) { // primitive bind
  973. self.events.push({e:el,n:name,f:fn});
  974. if (el.addEventListener) {
  975. el.addEventListener(name,fn,bubble||false);
  976. }
  977. else if (el.attachEvent) {
  978. el.attachEvent("on"+name,fn);
  979. }
  980. else {
  981. el["on"+name] = fn;
  982. }
  983. };
  984. this.bind = function(dom,name,fn,bubble) { // touch-oriented & fixing jquery bind
  985. var el = ("jquery" in dom) ? dom[0] : dom;
  986. if (el.addEventListener) {
  987. if (self.cantouch && /mouseup|mousedown|mousemove/.test(name)) { // touch device support
  988. var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
  989. self._bind(el,tt,function(e){
  990. if (e.touches) {
  991. if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
  992. }
  993. else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);} //blackberry
  994. },bubble||false);
  995. }
  996. self._bind(el,name,fn,bubble||false);
  997. if (name=='mousewheel') self._bind(el,"DOMMouseScroll",fn,bubble||false);
  998. if (self.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
  999. }
  1000. else {
  1001. self._bind(el,name,function(e) {
  1002. e = e||window.event||false;
  1003. if (e) {
  1004. if (e.srcElement) e.target=e.srcElement;
  1005. }
  1006. return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
  1007. });
  1008. }
  1009. };
  1010. this._unbind = function(el,name,fn) { // primitive unbind
  1011. if (el.removeEventListener) {
  1012. el.removeEventListener(name,fn,false);
  1013. }
  1014. else if (el.detachEvent) {
  1015. el.detachEvent('on'+name,fn);
  1016. } else {
  1017. el['on'+name] = false;
  1018. }
  1019. };
  1020. this.unbindAll = function() {
  1021. for(var a=0;a<self.events.length;a++) {
  1022. var r = self.events[a];
  1023. self._unbind(r.e,r.n,r.f);
  1024. }
  1025. };
  1026. // Thanks to http://www.switchonthecode.com !!
  1027. this.cancelEvent = function(e) {
  1028. var e = (e.original) ? e.original : (e) ? e : window.event||false;
  1029. if (!e) return false;
  1030. if(e.preventDefault) e.preventDefault();
  1031. if(e.stopPropagation) e.stopPropagation();
  1032. if(e.preventManipulation) e.preventManipulation(); //IE10
  1033. e.cancelBubble = true;
  1034. e.cancel = true;
  1035. e.returnValue = false;
  1036. return false;
  1037. };
  1038. this.showRail = function() {
  1039. if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
  1040. self.visibility = true;
  1041. self.rail.css('display','block');
  1042. }
  1043. return self;
  1044. };
  1045. this.hideRail = function() {
  1046. self.visibility = false;
  1047. self.rail.css('display','none');
  1048. return self;
  1049. };
  1050. this.show = function() {
  1051. self.hidden = false;
  1052. self.locked = false;
  1053. return self.showRail();
  1054. };
  1055. this.hide = function() {
  1056. self.hidden = true;
  1057. self.locked = true;
  1058. return self.hideRail();
  1059. };
  1060. this.remove = function() {
  1061. self.doZoomOut();
  1062. self.unbindAll();
  1063. if (self.observer !== false) {
  1064. self.observer.disconnect();
  1065. }
  1066. self.events = [];
  1067. self.rail.remove();
  1068. if (self.zoom) self.zoom.remove();
  1069. self.cursor = false;
  1070. self.rail = false;
  1071. self.zoom = false;
  1072. for(var a=0;a<self.saved.css.length;a++) {
  1073. var d=self.saved.css[a];
  1074. d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
  1075. }
  1076. self.saved = false;
  1077. self.me.data('__nicescroll',''); //erase all traces
  1078. return self;
  1079. };
  1080. this.isScrollable = function(e) {
  1081. var dom = (e.target) ? e.target : e;
  1082. while (dom&&dom.nodeName&&!(/BODY|HTML/.test(dom.nodeName))) {
  1083. var dd = $(dom);
  1084. var ov = dd.css('overflowY')||dd.css('overflow')||'';
  1085. if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
  1086. dom = (dom.parentNode) ? dom.parentNode : false;
  1087. }
  1088. return false;
  1089. };
  1090. this.onmousewheel = function(e) {
  1091. if (self.locked&&self.page.maxh==0) return true;
  1092. if (self.opt.preservenativescrolling&&self.checkarea) {
  1093. self.checkarea = false;
  1094. self.nativescrollingarea = self.isScrollable(e);
  1095. }
  1096. if (self.nativescrollingarea) return true; // this isn't my business
  1097. if (self.locked) return self.cancelEvent(e);
  1098. if (self.rail.drag) return self.cancelEvent(e);
  1099. var delta = 0;
  1100. var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
  1101. if (delta) {
  1102. if (self.scrollmom) self.scrollmom.y.stop();
  1103. self.lastdelta += (delta*self.opt.mousescrollstep);
  1104. self.synched("mousewheel",function(){if(!self.rail.drag){var dt=self.lastdelta;self.lastdelta=0;self.doScrollBy(dt)}});
  1105. }
  1106. return self.cancelEvent(e);
  1107. };
  1108. this.stop = function() {
  1109. self.cancelScroll();
  1110. if (self.scrollmon) self.scrollmon.stop();
  1111. self.cursorfreezed = false;
  1112. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1113. self.noticeCursor();
  1114. return self;
  1115. };
  1116. if (self.ishwscroll&&self.hastransition&&self.opt.usetransition) {
  1117. this.prepareTransition = function(dif,trend) {
  1118. var sp = Math.round(self.opt.scrollspeed*10);
  1119. var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
  1120. var trans = (ex>20) ? self.prefixstyle+'transform '+ex+'ms ease-out 0s' : '';
  1121. if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
  1122. self.lasttransitionstyle = trans;
  1123. self.doc.css(self.transitionstyle,trans);
  1124. }
  1125. return ex;
  1126. };
  1127. this.doScroll = function(y,spd) { //trans
  1128. var sy = self.getScrollTop();
  1129. if (y<0&&sy<=0) return self.noticeCursor();
  1130. else if (y>self.page.maxh&&sy>=self.page.maxh) {
  1131. self.checkContentSize();
  1132. return self.noticeCursor();
  1133. }
  1134. self.newscrolly = y;
  1135. self.newscrollspeed = spd||false;
  1136. if (self.timer) return false;
  1137. if (!self.scrollendtrapped) {
  1138. self.scrollendtrapped = true;
  1139. self.bind(self.doc,self.transitionend,self.onScrollEnd,false); //I have got to do something usefull!!
  1140. }
  1141. self.timer = setTimeout(function(){
  1142. var top = self.getScrollTop();
  1143. var dif = (self.newscrollspeed)?self.newscrollspeed:Math.abs(top-self.newscrolly);
  1144. var ms = self.prepareTransition(dif);
  1145. self.timer = setTimeout(function(){
  1146. if (self.newscrolly<0&&!self.opt.bouncescroll) self.newscrolly = 0
  1147. else if (self.newscrolly>self.page.maxh&&!self.opt.bouncescroll) self.newscrolly = self.page.maxh;
  1148. if (self.newscrolly==self.getScrollTop()) {
  1149. self.timer = 0;
  1150. self.onScrollEnd();
  1151. } else {
  1152. var py = self.getScrollTop();
  1153. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1154. if (ms>0) {
  1155. self.timerscroll = {
  1156. ts:(new Date()).getTime(),
  1157. s:self.getScrollTop(),
  1158. e:self.newscrolly,
  1159. sp:ms,
  1160. bz: new BezierClass(py,self.newscrolly,ms,0,1,0,1)
  1161. };
  1162. if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop())},60);
  1163. }
  1164. self.setScrollTop(self.newscrolly);
  1165. self.timer = 0;
  1166. }
  1167. // self.noticeCursor();
  1168. },15);
  1169. },self.opt.scrollspeed);
  1170. };
  1171. this.cancelScroll = function() {
  1172. if (!self.scrollendtrapped) return true;
  1173. var py = self.getScrollTop();
  1174. self.scrollendtrapped = false;
  1175. self._unbind(self.doc,self.transitionend,self.onScrollEnd);
  1176. self.prepareTransition(0);
  1177. self.setScrollTop(py); // fire event onscroll
  1178. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1179. self.timerscroll = false;
  1180. self.cursorfreezed = false;
  1181. // self.scrollstart = false;
  1182. self.noticeCursor(false,py);
  1183. return self;
  1184. };
  1185. this.onScrollEnd = function() {
  1186. self.scrollendtrapped = false;
  1187. self._unbind(self.doc,self.transitionend,self.onScrollEnd);
  1188. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1189. self.timerscroll = false;
  1190. self.cursorfreezed = false;
  1191. var py = self.getScrollTop();
  1192. self.setScrollTop(py); // fire event onscroll
  1193. self.noticeCursor(false,py);
  1194. if (py<0) self.doScroll(0,60)
  1195. else if (py>self.page.maxh) self.doScroll(self.page.maxh,60);
  1196. // else self.checkContentSize();
  1197. };
  1198. } else {
  1199. this.doScroll = function(y) { //no-trans
  1200. if (self.newscrolly==y) return true;
  1201. var py = self.getScrollTop();
  1202. self.newscrolly = y;
  1203. if (!self.bouncescroll) {
  1204. if (self.newscrolly<0) {
  1205. if (self.newspeedy) self.newspeedy.x = 0;
  1206. self.newscrolly = 0;
  1207. }
  1208. else if (self.newscrolly>self.page.maxh) {
  1209. if (self.newspeedy) self.newspeedy.x = self.page.maxh;
  1210. self.newscrolly = self.page.maxh;
  1211. }
  1212. }
  1213. var mg = Math.floor(Math.abs(y-py)/40);
  1214. if (mg>0) {
  1215. var ms = Math.min(10,mg)*100;
  1216. self.bzscroll = (self.bzscroll) ? self.bzscroll.update(y,ms) : new BezierClass(py,y,ms,0,1,0,1);
  1217. } else {
  1218. self.bzscroll = false;
  1219. }
  1220. if (self.timer) return;
  1221. if (py==self.page.maxh&&y>=self.page.maxh) self.checkContentSize();
  1222. var sync = 1;
  1223. function scrolling() {
  1224. if (self.cancelAnimationFrame) return true;
  1225. sync = 1-sync;
  1226. if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
  1227. var sy = self.getScrollTop();
  1228. var sc = (self.bzscroll) ? self.bzscroll.getNow() : self.newscrolly;
  1229. var dr=sc-sy;
  1230. if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
  1231. self.setScrollTop(sc);
  1232. if (sc == self.newscrolly) {
  1233. // clearAnimationFrame(self.timer);
  1234. self.timer = 0;
  1235. self.cursorfreezed = false;
  1236. self.bzscroll = false;
  1237. if (sc<0) self.doScroll(0);
  1238. else if (sc>self.page.maxh) self.doScroll(self.page.maxh);
  1239. // else self.checkContentSize();
  1240. } else {
  1241. self.timer = setAnimationFrame(scrolling)||1;
  1242. }
  1243. };
  1244. self.cancelAnimationFrame=false;
  1245. self.timer = 1;
  1246. scrolling();
  1247. if (py==self.page.maxh&&y>=py) self.checkContentSize();
  1248. self.noticeCursor();
  1249. };
  1250. this.cancelScroll = function() {
  1251. if (self.timer) clearAnimationFrame(self.timer);
  1252. self.timer = 0;
  1253. self.bzscroll = false;
  1254. return self;
  1255. };
  1256. }
  1257. this.doScrollBy = function(stp,relative) {
  1258. var ny = 0;
  1259. if (relative) {
  1260. ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
  1261. } else {
  1262. var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
  1263. ny = sy-stp;
  1264. }
  1265. if (self.bouncescroll) {
  1266. var haf = Math.round(self.view.h/2);
  1267. if (ny<-haf) ny=-haf
  1268. else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
  1269. }
  1270. self.cursorfreezed = false;
  1271. self.doScroll(ny);
  1272. };
  1273. this.doScrollTo = function(pos,relative) {
  1274. var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
  1275. if (ny<0) ny=0
  1276. else if (ny>self.page.maxh) ny = self.page.maxh;
  1277. self.cursorfreezed = false;
  1278. self.doScroll(pos);
  1279. };
  1280. this.checkContentSize = function() {
  1281. var pg = self.getContentSize();
  1282. if (pg.h!=self.page.h) self.resize(false,pg);
  1283. };
  1284. self.onscroll = function(e) {
  1285. if (self.rail.drag) return;
  1286. if (!self.cursorfreezed) {
  1287. /*
  1288. self.delayed('onscroll',function(){
  1289. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1290. self.noticeCursor();
  1291. },30);
  1292. */
  1293. self.synched('scroll',function(){
  1294. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1295. self.noticeCursor();
  1296. });
  1297. }
  1298. };
  1299. self.bind(self.docscroll,"scroll",self.onscroll);
  1300. this.doZoomIn = function(e) {
  1301. if (self.zoomactive) return;
  1302. self.zoomactive = true;
  1303. self.zoomrestore = {
  1304. style:{}
  1305. };
  1306. var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
  1307. var win = self.win[0].style;
  1308. for(var a in lst) {
  1309. var pp = lst[a];
  1310. self.zoomrestore.style[pp] = (typeof win[pp]!='undefined') ? win[pp] : '';
  1311. }
  1312. self.zoomrestore.style.width = self.win.css('width');
  1313. self.zoomrestore.style.height = self.win.css('height');
  1314. self.zoomrestore.padding = {
  1315. w:self.win.outerWidth()-self.win.width(),
  1316. h:self.win.outerHeight()-self.win.height()
  1317. };
  1318. if (self.isios4) {
  1319. self.zoomrestore.scrollTop = $(window).scrollTop();
  1320. $(window).scrollTop(0);
  1321. }
  1322. self.win.css({
  1323. "position":(self.isios4)?"absolute":"fixed",
  1324. "top":0,
  1325. "left":0,
  1326. "z-index":self.opt.zindex+100,
  1327. "margin":"0px"
  1328. });
  1329. var bkg = self.win.css("backgroundColor");
  1330. if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
  1331. self.rail.css({"z-index":self.opt.zindex+110});
  1332. self.zoom.css({"z-index":self.opt.zindex+112});
  1333. self.zoom.css('backgroundPosition','0px -18px');
  1334. self.resizeZoom();
  1335. return self.cancelEvent(e);
  1336. };
  1337. this.doZoomOut = function(e) {
  1338. if (!self.zoomactive) return;
  1339. self.zoomactive = false;
  1340. self.win.css("margin","");
  1341. self.win.css(self.zoomrestore.style);
  1342. if (self.isios4) {
  1343. $(window).scrollTop(self.zoomrestore.scrollTop);
  1344. }
  1345. self.rail.css({"z-index":(self.ispage)?self.opt.zindex:self.opt.zindex+2});
  1346. self.zoom.css({"z-index":self.opt.zindex});
  1347. self.zoomrestore = false;
  1348. self.zoom.css('backgroundPosition','0px 0px');
  1349. self.onResize();
  1350. return self.cancelEvent(e);
  1351. };
  1352. this.doZoom = function(e) {
  1353. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  1354. };
  1355. this.resizeZoom = function() {
  1356. if (!self.zoomactive) return;
  1357. var py = self.getScrollTop(); //preserve scrolling position
  1358. self.win.css({
  1359. width:$(window).width()-self.zoomrestore.padding.w+"px",
  1360. height:$(window).height()-self.zoomrestore.padding.h+"px"
  1361. });
  1362. self.onResize();
  1363. self.setScrollTop(Math.min(self.page.maxh,py));
  1364. };
  1365. this.init();
  1366. $.nicescroll.push(this);
  1367. };
  1368. // Inspired by the work of Kin Blas
  1369. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  1370. var ScrollMomentumClass = function(nc) {
  1371. var self = this;
  1372. this.nc = nc;
  1373. this.lasty = 0;
  1374. this.speedy = 0;
  1375. this.lasttime = 0;
  1376. this.snapy = false;
  1377. this.demuly = 0;
  1378. this.lastscrolly = -1;
  1379. this.chky = 0;
  1380. this.timer = 0;
  1381. this.time = function() {
  1382. return (new Date()).getTime();
  1383. };
  1384. this.reset = function(py) {
  1385. self.stop();
  1386. self.lasttime = self.time();
  1387. self.speedy = 0;
  1388. self.lasty = py;
  1389. self.lastscrolly = -1;
  1390. };
  1391. this.update = function(py) {
  1392. self.lasttime = self.time();
  1393. var dy = py - self.lasty;
  1394. var sy = nc.getScrollTop();
  1395. var newy = sy + dy;
  1396. self.snapy = (newy<0)||(newy>self.nc.page.maxh);
  1397. self.speedy = dy;
  1398. self.lasty = py;
  1399. };
  1400. this.stop = function() {
  1401. if (self.timer) {
  1402. clearTimeout(self.timer);
  1403. self.timer = 0;
  1404. self.lastscrolly = -1;
  1405. }
  1406. };
  1407. this.doSnapy = function(ny) {
  1408. if (ny<0) {
  1409. self.nc.doScroll(0,60);
  1410. }
  1411. else if (ny>self.nc.page.maxh) {
  1412. self.nc.doScroll(self.nc.page.maxh,60);
  1413. }
  1414. };
  1415. this.doMomentum = function(tm) {
  1416. var t = self.time();
  1417. var l = (tm) ? t+tm : self.lasttime;
  1418. self.speedy = Math.min(60,self.speedy);
  1419. var chk = l && (t - l) <= 50;
  1420. var sy = (self.speedy && chk) ? self.speedy : false;
  1421. if (sy) {
  1422. var tm = t-l;
  1423. var pageh = self.nc.page.maxh;
  1424. self.demuly = 0;
  1425. self.lastscrolly = self.nc.getScrollTop();
  1426. self.chky = self.lastscrolly;
  1427. var onscroll = function(){
  1428. // var ny = Math.floor(self.nc.getScrollTop() - (self.speedy*(1-self.demuly)));
  1429. var ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demuly)));
  1430. if ((ny<0)||(ny>pageh)) {
  1431. self.demuly+=0.08;
  1432. } else {
  1433. self.demuly+=0.01;
  1434. }
  1435. self.lastscrolly = ny;
  1436. self.nc.synched("domomentum",function(){
  1437. var scy = self.nc.getScrollTop();
  1438. if (scy!=self.chky) self.stop();
  1439. self.chky=ny;
  1440. self.nc.setScrollTop(ny);
  1441. if(self.timer) {
  1442. self.nc.showCursor(ny);
  1443. } else {
  1444. self.nc.hideCursor();
  1445. self.doSnapy(ny);
  1446. }
  1447. });
  1448. if(self.demuly<1) {
  1449. self.timer = setTimeout(onscroll,tm);
  1450. } else {
  1451. self.timer = 0;
  1452. // self.nc.hideCursor();
  1453. // self.doSnapy(ny);
  1454. }
  1455. };
  1456. onscroll();
  1457. } else {
  1458. if (self.snapy) {
  1459. self.doSnapy(self.nc.getScrollTop());
  1460. }
  1461. }
  1462. }
  1463. };
  1464. // override jQuery scrollTop
  1465. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  1466. $.cssHooks.scrollTop = {
  1467. get: function(elem,computed,extra) {
  1468. var nice = $.data(elem,'__nicescroll')||false;
  1469. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  1470. },
  1471. set: function(elem,value) {
  1472. var nice = $.data(elem,'__nicescroll')||false;
  1473. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
  1474. return this;
  1475. }
  1476. };
  1477. /* ====================================> TO INSPECT
  1478. $.fx.step["scrollTop"] = function(fx){
  1479. if (fx.start=='') fx.start=$.cssHooks.scrollTop.get(fx.elem);
  1480. $.cssHooks.scrollTop.set(fx.elem,fx.now+fx.unit);
  1481. };
  1482. */
  1483. jQuery.fn.scrollTop = function(value) {
  1484. if (typeof value == "undefined") {
  1485. var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
  1486. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  1487. } else {
  1488. return this.each(function() {
  1489. var nice = $.data(this,'__nicescroll')||false;
  1490. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
  1491. });
  1492. }
  1493. }
  1494. var NiceScrollArray = function(doms) {
  1495. var self = this;
  1496. this.length = 0;
  1497. this.name = "nicescrollarray";
  1498. this.each = function(fn) {
  1499. for(var a=0;a<self.length;a++) fn.call(self[a]);
  1500. return self;
  1501. };
  1502. this.push = function(nice) {
  1503. self[self.length]=nice;
  1504. self.length++;
  1505. };
  1506. this.eq = function(idx) {
  1507. return self[idx];
  1508. };
  1509. if (doms) {
  1510. for(a=0;a<doms.length;a++) {
  1511. var nice = $.data(doms[a],'__nicescroll')||false;
  1512. if (nice) {
  1513. this[this.length]=nice;
  1514. this.length++;
  1515. }
  1516. };
  1517. }
  1518. return this;
  1519. };
  1520. function mplex(el,lst,fn) {
  1521. for(var a=0;a<lst.length;a++) fn(el,lst[a]);
  1522. };
  1523. mplex(
  1524. NiceScrollArray.prototype,
  1525. ['show','hide','onResize','resize','remove','stop'],
  1526. function(e,n) {
  1527. e[n] = function(){
  1528. return this.each(function(){
  1529. this[n].call();
  1530. });
  1531. };
  1532. }
  1533. );
  1534. jQuery.fn.getNiceScroll = function(index) {
  1535. if (typeof index == "undefined") {
  1536. return new NiceScrollArray(this);
  1537. } else {
  1538. var nice = $.data(this[index],'__nicescroll')||false;
  1539. return nice;
  1540. }
  1541. };
  1542. jQuery.extend(jQuery.expr[':'], {
  1543. nicescroll: function(a) {
  1544. return ($.data(a,'__nicescroll'))?true:false;
  1545. }
  1546. });
  1547. $.fn.niceScroll = function(wrapper,opt) {
  1548. if (typeof opt=="undefined") {
  1549. if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
  1550. opt = wrapper;
  1551. wrapper = false;
  1552. }
  1553. }
  1554. var ret = new NiceScrollArray();
  1555. if (typeof opt=="undefined") opt = {};
  1556. if (wrapper||false) {
  1557. opt.doc = $(wrapper);
  1558. opt.win = $(this);
  1559. }
  1560. var docundef = !("doc" in opt);
  1561. if (!docundef&&!("win" in opt)) opt.win = $(this);
  1562. this.each(function() {
  1563. var nice = $(this).data('__nicescroll')||false;
  1564. if (!nice) {
  1565. opt.doc = (docundef) ? $(this) : opt.doc;
  1566. nice = new NiceScrollClass(opt,$(this));
  1567. $(this).data('__nicescroll',nice);
  1568. }
  1569. ret.push(nice);
  1570. });
  1571. return (ret.length==1) ? ret[0] : ret;
  1572. };
  1573. window.NiceScroll = {
  1574. getjQuery:function(){return jQuery}
  1575. };
  1576. if (!$.nicescroll) {
  1577. $.nicescroll = new NiceScrollArray();
  1578. }
  1579. })( jQuery );