jquery.nicescroll.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  1. /* jquery.nicescroll
  2. -- version 2.9.7
  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.7';
  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.rail == false) {
  905. return false;
  906. }
  907. if (!self.haswrapper&&!self.ispage) {
  908. if (self.win.css('display')=='none') {
  909. if (self.visibility) self.hideRail();
  910. return false;
  911. } else {
  912. if (!self.visibility&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
  913. if (!self.hidden&&!self.visibility) self.showRail();
  914. }
  915. }
  916. var premaxh = self.page.maxh;
  917. var premaxw = self.page.maxw;
  918. var preview = {h:self.view.h,w:self.view.w};
  919. self.view = {
  920. w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
  921. h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
  922. };
  923. self.page = (page) ? page : self.getContentSize();
  924. self.page.maxh = Math.max(0,self.page.h - self.view.h);
  925. self.page.maxw = Math.max(0,self.page.w - self.view.w);
  926. if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
  927. // test position
  928. if (!self.ispage) {
  929. var pos = self.win.offset();
  930. if (self.lastposition) {
  931. var lst = self.lastposition;
  932. if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do
  933. }
  934. self.lastposition = pos;
  935. } else {
  936. return self; //nothing to do
  937. }
  938. }
  939. if (self.page.maxh==0) {
  940. self.hideRail();
  941. self.scrollvaluemax = 0;
  942. self.scroll.y = 0;
  943. self.scrollratio = {x:0,y:0};
  944. self.cursorheight = 0;
  945. self.locked = true;
  946. self.setScrollTop(0);
  947. return false;
  948. }
  949. else if (!self.hidden&&!self.visibility) {
  950. self.showRail();
  951. self.locked = false;
  952. }
  953. if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
  954. if (!self.ispage) self.updateScrollBar(self.view);
  955. self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
  956. self.cursorheight = Math.max(self.opt.cursorminheight,self.cursorheight);
  957. self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
  958. self.scrollratio = {
  959. x:0,
  960. y:(self.page.maxh/self.scrollvaluemax)
  961. };
  962. var sy = self.getScrollTop();
  963. if (sy>self.page.maxh) {
  964. self.doScroll(self.page.maxh);
  965. } else {
  966. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  967. self.noticeCursor();
  968. }
  969. return self;
  970. };
  971. this.resize = this.onResize; // hide internal method -- in future name can change
  972. this.lazyResize = function() {
  973. self.delayed('resize',self.resize,250);
  974. }
  975. this._bind = function(el,name,fn,bubble) { // primitive bind
  976. self.events.push({e:el,n:name,f:fn});
  977. if (el.addEventListener) {
  978. el.addEventListener(name,fn,bubble||false);
  979. }
  980. else if (el.attachEvent) {
  981. el.attachEvent("on"+name,fn);
  982. }
  983. else {
  984. el["on"+name] = fn;
  985. }
  986. };
  987. this.bind = function(dom,name,fn,bubble) { // touch-oriented & fixing jquery bind
  988. var el = ("jquery" in dom) ? dom[0] : dom;
  989. if (el.addEventListener) {
  990. if (self.cantouch && /mouseup|mousedown|mousemove/.test(name)) { // touch device support
  991. var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
  992. self._bind(el,tt,function(e){
  993. if (e.touches) {
  994. if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
  995. }
  996. else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);} //blackberry
  997. },bubble||false);
  998. }
  999. self._bind(el,name,fn,bubble||false);
  1000. if (name=='mousewheel') self._bind(el,"DOMMouseScroll",fn,bubble||false);
  1001. if (self.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
  1002. }
  1003. else {
  1004. self._bind(el,name,function(e) {
  1005. e = e||window.event||false;
  1006. if (e) {
  1007. if (e.srcElement) e.target=e.srcElement;
  1008. }
  1009. return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
  1010. });
  1011. }
  1012. };
  1013. this._unbind = function(el,name,fn) { // primitive unbind
  1014. if (el.removeEventListener) {
  1015. el.removeEventListener(name,fn,false);
  1016. }
  1017. else if (el.detachEvent) {
  1018. el.detachEvent('on'+name,fn);
  1019. } else {
  1020. el['on'+name] = false;
  1021. }
  1022. };
  1023. this.unbindAll = function() {
  1024. for(var a=0;a<self.events.length;a++) {
  1025. var r = self.events[a];
  1026. self._unbind(r.e,r.n,r.f);
  1027. }
  1028. };
  1029. // Thanks to http://www.switchonthecode.com !!
  1030. this.cancelEvent = function(e) {
  1031. var e = (e.original) ? e.original : (e) ? e : window.event||false;
  1032. if (!e) return false;
  1033. if(e.preventDefault) e.preventDefault();
  1034. if(e.stopPropagation) e.stopPropagation();
  1035. if(e.preventManipulation) e.preventManipulation(); //IE10
  1036. e.cancelBubble = true;
  1037. e.cancel = true;
  1038. e.returnValue = false;
  1039. return false;
  1040. };
  1041. this.showRail = function() {
  1042. if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
  1043. self.visibility = true;
  1044. self.rail.css('display','block');
  1045. }
  1046. return self;
  1047. };
  1048. this.hideRail = function() {
  1049. self.visibility = false;
  1050. self.rail.css('display','none');
  1051. return self;
  1052. };
  1053. this.show = function() {
  1054. self.hidden = false;
  1055. self.locked = false;
  1056. return self.showRail();
  1057. };
  1058. this.hide = function() {
  1059. self.hidden = true;
  1060. self.locked = true;
  1061. return self.hideRail();
  1062. };
  1063. this.remove = function() {
  1064. self.doZoomOut();
  1065. self.unbindAll();
  1066. if (self.observer !== false) {
  1067. self.observer.disconnect();
  1068. }
  1069. self.events = [];
  1070. self.rail.remove();
  1071. if (self.zoom) self.zoom.remove();
  1072. self.cursor = false;
  1073. self.rail = false;
  1074. self.zoom = false;
  1075. for(var a=0;a<self.saved.css.length;a++) {
  1076. var d=self.saved.css[a];
  1077. d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
  1078. }
  1079. self.saved = false;
  1080. self.me.data('__nicescroll',''); //erase all traces
  1081. return self;
  1082. };
  1083. this.isScrollable = function(e) {
  1084. var dom = (e.target) ? e.target : e;
  1085. while (dom&&dom.nodeName&&!(/BODY|HTML/.test(dom.nodeName))) {
  1086. var dd = $(dom);
  1087. var ov = dd.css('overflowY')||dd.css('overflow')||'';
  1088. if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
  1089. dom = (dom.parentNode) ? dom.parentNode : false;
  1090. }
  1091. return false;
  1092. };
  1093. this.onmousewheel = function(e) {
  1094. if (self.locked&&self.page.maxh==0) return true;
  1095. if (self.opt.preservenativescrolling&&self.checkarea) {
  1096. self.checkarea = false;
  1097. self.nativescrollingarea = self.isScrollable(e);
  1098. }
  1099. if (self.nativescrollingarea) return true; // this isn't my business
  1100. if (self.locked) return self.cancelEvent(e);
  1101. if (self.rail.drag) return self.cancelEvent(e);
  1102. var delta = 0;
  1103. var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
  1104. if (delta) {
  1105. if (self.scrollmom) self.scrollmom.y.stop();
  1106. self.lastdelta += (delta*self.opt.mousescrollstep);
  1107. self.synched("mousewheel",function(){if(!self.rail.drag){var dt=self.lastdelta;self.lastdelta=0;self.doScrollBy(dt)}});
  1108. }
  1109. return self.cancelEvent(e);
  1110. };
  1111. this.stop = function() {
  1112. self.cancelScroll();
  1113. if (self.scrollmon) self.scrollmon.stop();
  1114. self.cursorfreezed = false;
  1115. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1116. self.noticeCursor();
  1117. return self;
  1118. };
  1119. if (self.ishwscroll&&self.hastransition&&self.opt.usetransition) {
  1120. this.prepareTransition = function(dif,trend) {
  1121. var sp = Math.round(self.opt.scrollspeed*10);
  1122. var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
  1123. var trans = (ex>20) ? self.prefixstyle+'transform '+ex+'ms ease-out 0s' : '';
  1124. if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
  1125. self.lasttransitionstyle = trans;
  1126. self.doc.css(self.transitionstyle,trans);
  1127. }
  1128. return ex;
  1129. };
  1130. this.doScroll = function(y,spd) { //trans
  1131. var sy = self.getScrollTop();
  1132. if (y<0&&sy<=0) return self.noticeCursor();
  1133. else if (y>self.page.maxh&&sy>=self.page.maxh) {
  1134. self.checkContentSize();
  1135. return self.noticeCursor();
  1136. }
  1137. self.newscrolly = y;
  1138. self.newscrollspeed = spd||false;
  1139. if (self.timer) return false;
  1140. if (!self.scrollendtrapped) {
  1141. self.scrollendtrapped = true;
  1142. self.bind(self.doc,self.transitionend,self.onScrollEnd,false); //I have got to do something usefull!!
  1143. }
  1144. self.timer = setTimeout(function(){
  1145. var top = self.getScrollTop();
  1146. var dif = (self.newscrollspeed)?self.newscrollspeed:Math.abs(top-self.newscrolly);
  1147. var ms = self.prepareTransition(dif);
  1148. self.timer = setTimeout(function(){
  1149. if (self.newscrolly<0&&!self.opt.bouncescroll) self.newscrolly = 0
  1150. else if (self.newscrolly>self.page.maxh&&!self.opt.bouncescroll) self.newscrolly = self.page.maxh;
  1151. if (self.newscrolly==self.getScrollTop()) {
  1152. self.timer = 0;
  1153. self.onScrollEnd();
  1154. } else {
  1155. var py = self.getScrollTop();
  1156. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1157. if (ms>0) {
  1158. self.timerscroll = {
  1159. ts:(new Date()).getTime(),
  1160. s:self.getScrollTop(),
  1161. e:self.newscrolly,
  1162. sp:ms,
  1163. bz: new BezierClass(py,self.newscrolly,ms,0,1,0,1)
  1164. };
  1165. if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop())},60);
  1166. }
  1167. self.setScrollTop(self.newscrolly);
  1168. self.timer = 0;
  1169. }
  1170. // self.noticeCursor();
  1171. },15);
  1172. },self.opt.scrollspeed);
  1173. };
  1174. this.cancelScroll = function() {
  1175. if (!self.scrollendtrapped) return true;
  1176. var py = self.getScrollTop();
  1177. self.scrollendtrapped = false;
  1178. self._unbind(self.doc,self.transitionend,self.onScrollEnd);
  1179. self.prepareTransition(0);
  1180. self.setScrollTop(py); // fire event onscroll
  1181. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1182. self.timerscroll = false;
  1183. self.cursorfreezed = false;
  1184. // self.scrollstart = false;
  1185. self.noticeCursor(false,py);
  1186. return self;
  1187. };
  1188. this.onScrollEnd = function() {
  1189. self.scrollendtrapped = false;
  1190. self._unbind(self.doc,self.transitionend,self.onScrollEnd);
  1191. if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  1192. self.timerscroll = false;
  1193. self.cursorfreezed = false;
  1194. var py = self.getScrollTop();
  1195. self.setScrollTop(py); // fire event onscroll
  1196. self.noticeCursor(false,py);
  1197. if (py<0) self.doScroll(0,60)
  1198. else if (py>self.page.maxh) self.doScroll(self.page.maxh,60);
  1199. // else self.checkContentSize();
  1200. };
  1201. } else {
  1202. this.doScroll = function(y) { //no-trans
  1203. if (self.newscrolly==y) return true;
  1204. var py = self.getScrollTop();
  1205. self.newscrolly = y;
  1206. if (!self.bouncescroll) {
  1207. if (self.newscrolly<0) {
  1208. if (self.newspeedy) self.newspeedy.x = 0;
  1209. self.newscrolly = 0;
  1210. }
  1211. else if (self.newscrolly>self.page.maxh) {
  1212. if (self.newspeedy) self.newspeedy.x = self.page.maxh;
  1213. self.newscrolly = self.page.maxh;
  1214. }
  1215. }
  1216. var mg = Math.floor(Math.abs(y-py)/40);
  1217. if (mg>0) {
  1218. var ms = Math.min(10,mg)*100;
  1219. self.bzscroll = (self.bzscroll) ? self.bzscroll.update(y,ms) : new BezierClass(py,y,ms,0,1,0,1);
  1220. } else {
  1221. self.bzscroll = false;
  1222. }
  1223. if (self.timer) return;
  1224. if (py==self.page.maxh&&y>=self.page.maxh) self.checkContentSize();
  1225. var sync = 1;
  1226. function scrolling() {
  1227. if (self.cancelAnimationFrame) return true;
  1228. sync = 1-sync;
  1229. if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
  1230. var sy = self.getScrollTop();
  1231. var sc = (self.bzscroll) ? self.bzscroll.getNow() : self.newscrolly;
  1232. var dr=sc-sy;
  1233. if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
  1234. self.setScrollTop(sc);
  1235. if (sc == self.newscrolly) {
  1236. // clearAnimationFrame(self.timer);
  1237. self.timer = 0;
  1238. self.cursorfreezed = false;
  1239. self.bzscroll = false;
  1240. if (sc<0) self.doScroll(0);
  1241. else if (sc>self.page.maxh) self.doScroll(self.page.maxh);
  1242. // else self.checkContentSize();
  1243. } else {
  1244. self.timer = setAnimationFrame(scrolling)||1;
  1245. }
  1246. };
  1247. self.cancelAnimationFrame=false;
  1248. self.timer = 1;
  1249. scrolling();
  1250. if (py==self.page.maxh&&y>=py) self.checkContentSize();
  1251. self.noticeCursor();
  1252. };
  1253. this.cancelScroll = function() {
  1254. if (self.timer) clearAnimationFrame(self.timer);
  1255. self.timer = 0;
  1256. self.bzscroll = false;
  1257. return self;
  1258. };
  1259. }
  1260. this.doScrollBy = function(stp,relative) {
  1261. var ny = 0;
  1262. if (relative) {
  1263. ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
  1264. } else {
  1265. var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
  1266. ny = sy-stp;
  1267. }
  1268. if (self.bouncescroll) {
  1269. var haf = Math.round(self.view.h/2);
  1270. if (ny<-haf) ny=-haf
  1271. else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
  1272. }
  1273. self.cursorfreezed = false;
  1274. self.doScroll(ny);
  1275. };
  1276. this.doScrollTo = function(pos,relative) {
  1277. var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
  1278. if (ny<0) ny=0
  1279. else if (ny>self.page.maxh) ny = self.page.maxh;
  1280. self.cursorfreezed = false;
  1281. self.doScroll(pos);
  1282. };
  1283. this.checkContentSize = function() {
  1284. var pg = self.getContentSize();
  1285. if (pg.h!=self.page.h) self.resize(false,pg);
  1286. };
  1287. self.onscroll = function(e) {
  1288. if (self.rail.drag) return;
  1289. if (!self.cursorfreezed) {
  1290. /*
  1291. self.delayed('onscroll',function(){
  1292. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1293. self.noticeCursor();
  1294. },30);
  1295. */
  1296. self.synched('scroll',function(){
  1297. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  1298. self.noticeCursor();
  1299. });
  1300. }
  1301. };
  1302. self.bind(self.docscroll,"scroll",self.onscroll);
  1303. this.doZoomIn = function(e) {
  1304. if (self.zoomactive) return;
  1305. self.zoomactive = true;
  1306. self.zoomrestore = {
  1307. style:{}
  1308. };
  1309. var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
  1310. var win = self.win[0].style;
  1311. for(var a in lst) {
  1312. var pp = lst[a];
  1313. self.zoomrestore.style[pp] = (typeof win[pp]!='undefined') ? win[pp] : '';
  1314. }
  1315. self.zoomrestore.style.width = self.win.css('width');
  1316. self.zoomrestore.style.height = self.win.css('height');
  1317. self.zoomrestore.padding = {
  1318. w:self.win.outerWidth()-self.win.width(),
  1319. h:self.win.outerHeight()-self.win.height()
  1320. };
  1321. if (self.isios4) {
  1322. self.zoomrestore.scrollTop = $(window).scrollTop();
  1323. $(window).scrollTop(0);
  1324. }
  1325. self.win.css({
  1326. "position":(self.isios4)?"absolute":"fixed",
  1327. "top":0,
  1328. "left":0,
  1329. "z-index":self.opt.zindex+100,
  1330. "margin":"0px"
  1331. });
  1332. var bkg = self.win.css("backgroundColor");
  1333. if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
  1334. self.rail.css({"z-index":self.opt.zindex+110});
  1335. self.zoom.css({"z-index":self.opt.zindex+112});
  1336. self.zoom.css('backgroundPosition','0px -18px');
  1337. self.resizeZoom();
  1338. return self.cancelEvent(e);
  1339. };
  1340. this.doZoomOut = function(e) {
  1341. if (!self.zoomactive) return;
  1342. self.zoomactive = false;
  1343. self.win.css("margin","");
  1344. self.win.css(self.zoomrestore.style);
  1345. if (self.isios4) {
  1346. $(window).scrollTop(self.zoomrestore.scrollTop);
  1347. }
  1348. self.rail.css({"z-index":(self.ispage)?self.opt.zindex:self.opt.zindex+2});
  1349. self.zoom.css({"z-index":self.opt.zindex});
  1350. self.zoomrestore = false;
  1351. self.zoom.css('backgroundPosition','0px 0px');
  1352. self.onResize();
  1353. return self.cancelEvent(e);
  1354. };
  1355. this.doZoom = function(e) {
  1356. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  1357. };
  1358. this.resizeZoom = function() {
  1359. if (!self.zoomactive) return;
  1360. var py = self.getScrollTop(); //preserve scrolling position
  1361. self.win.css({
  1362. width:$(window).width()-self.zoomrestore.padding.w+"px",
  1363. height:$(window).height()-self.zoomrestore.padding.h+"px"
  1364. });
  1365. self.onResize();
  1366. self.setScrollTop(Math.min(self.page.maxh,py));
  1367. };
  1368. this.init();
  1369. $.nicescroll.push(this);
  1370. };
  1371. // Inspired by the work of Kin Blas
  1372. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  1373. var ScrollMomentumClass = function(nc) {
  1374. var self = this;
  1375. this.nc = nc;
  1376. this.lasty = 0;
  1377. this.speedy = 0;
  1378. this.lasttime = 0;
  1379. this.snapy = false;
  1380. this.demuly = 0;
  1381. this.lastscrolly = -1;
  1382. this.chky = 0;
  1383. this.timer = 0;
  1384. this.time = function() {
  1385. return (new Date()).getTime();
  1386. };
  1387. this.reset = function(py) {
  1388. self.stop();
  1389. self.lasttime = self.time();
  1390. self.speedy = 0;
  1391. self.lasty = py;
  1392. self.lastscrolly = -1;
  1393. };
  1394. this.update = function(py) {
  1395. self.lasttime = self.time();
  1396. var dy = py - self.lasty;
  1397. var sy = nc.getScrollTop();
  1398. var newy = sy + dy;
  1399. self.snapy = (newy<0)||(newy>self.nc.page.maxh);
  1400. self.speedy = dy;
  1401. self.lasty = py;
  1402. };
  1403. this.stop = function() {
  1404. if (self.timer) {
  1405. clearTimeout(self.timer);
  1406. self.timer = 0;
  1407. self.lastscrolly = -1;
  1408. }
  1409. };
  1410. this.doSnapy = function(ny) {
  1411. if (ny<0) {
  1412. self.nc.doScroll(0,60);
  1413. }
  1414. else if (ny>self.nc.page.maxh) {
  1415. self.nc.doScroll(self.nc.page.maxh,60);
  1416. }
  1417. };
  1418. this.doMomentum = function(tm) {
  1419. var t = self.time();
  1420. var l = (tm) ? t+tm : self.lasttime;
  1421. self.speedy = Math.min(60,self.speedy);
  1422. var chk = l && (t - l) <= 50;
  1423. var sy = (self.speedy && chk) ? self.speedy : false;
  1424. if (sy) {
  1425. var tm = t-l;
  1426. var pageh = self.nc.page.maxh;
  1427. self.demuly = 0;
  1428. self.lastscrolly = self.nc.getScrollTop();
  1429. self.chky = self.lastscrolly;
  1430. var onscroll = function(){
  1431. // var ny = Math.floor(self.nc.getScrollTop() - (self.speedy*(1-self.demuly)));
  1432. var ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demuly)));
  1433. if ((ny<0)||(ny>pageh)) {
  1434. self.demuly+=0.08;
  1435. } else {
  1436. self.demuly+=0.01;
  1437. }
  1438. self.lastscrolly = ny;
  1439. self.nc.synched("domomentum",function(){
  1440. var scy = self.nc.getScrollTop();
  1441. if (scy!=self.chky) self.stop();
  1442. self.chky=ny;
  1443. self.nc.setScrollTop(ny);
  1444. if(self.timer) {
  1445. self.nc.showCursor(ny);
  1446. } else {
  1447. self.nc.hideCursor();
  1448. self.doSnapy(ny);
  1449. }
  1450. });
  1451. if(self.demuly<1) {
  1452. self.timer = setTimeout(onscroll,tm);
  1453. } else {
  1454. self.timer = 0;
  1455. // self.nc.hideCursor();
  1456. // self.doSnapy(ny);
  1457. }
  1458. };
  1459. onscroll();
  1460. } else {
  1461. if (self.snapy) {
  1462. self.doSnapy(self.nc.getScrollTop());
  1463. }
  1464. }
  1465. }
  1466. };
  1467. // override jQuery scrollTop
  1468. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  1469. $.cssHooks.scrollTop = {
  1470. get: function(elem,computed,extra) {
  1471. var nice = $.data(elem,'__nicescroll')||false;
  1472. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  1473. },
  1474. set: function(elem,value) {
  1475. var nice = $.data(elem,'__nicescroll')||false;
  1476. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
  1477. return this;
  1478. }
  1479. };
  1480. /* ====================================> TO INSPECT
  1481. $.fx.step["scrollTop"] = function(fx){
  1482. if (fx.start=='') fx.start=$.cssHooks.scrollTop.get(fx.elem);
  1483. $.cssHooks.scrollTop.set(fx.elem,fx.now+fx.unit);
  1484. };
  1485. */
  1486. jQuery.fn.scrollTop = function(value) {
  1487. if (typeof value == "undefined") {
  1488. var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
  1489. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  1490. } else {
  1491. return this.each(function() {
  1492. var nice = $.data(this,'__nicescroll')||false;
  1493. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
  1494. });
  1495. }
  1496. }
  1497. var NiceScrollArray = function(doms) {
  1498. var self = this;
  1499. this.length = 0;
  1500. this.name = "nicescrollarray";
  1501. this.each = function(fn) {
  1502. for(var a=0;a<self.length;a++) fn.call(self[a]);
  1503. return self;
  1504. };
  1505. this.push = function(nice) {
  1506. self[self.length]=nice;
  1507. self.length++;
  1508. };
  1509. this.eq = function(idx) {
  1510. return self[idx];
  1511. };
  1512. if (doms) {
  1513. for(a=0;a<doms.length;a++) {
  1514. var nice = $.data(doms[a],'__nicescroll')||false;
  1515. if (nice) {
  1516. this[this.length]=nice;
  1517. this.length++;
  1518. }
  1519. };
  1520. }
  1521. return this;
  1522. };
  1523. function mplex(el,lst,fn) {
  1524. for(var a=0;a<lst.length;a++) fn(el,lst[a]);
  1525. };
  1526. mplex(
  1527. NiceScrollArray.prototype,
  1528. ['show','hide','onResize','resize','remove','stop'],
  1529. function(e,n) {
  1530. e[n] = function(){
  1531. return this.each(function(){
  1532. this[n].call();
  1533. });
  1534. };
  1535. }
  1536. );
  1537. jQuery.fn.getNiceScroll = function(index) {
  1538. if (typeof index == "undefined") {
  1539. return new NiceScrollArray(this);
  1540. } else {
  1541. var nice = $.data(this[index],'__nicescroll')||false;
  1542. return nice;
  1543. }
  1544. };
  1545. jQuery.extend(jQuery.expr[':'], {
  1546. nicescroll: function(a) {
  1547. return ($.data(a,'__nicescroll'))?true:false;
  1548. }
  1549. });
  1550. $.fn.niceScroll = function(wrapper,opt) {
  1551. if (typeof opt=="undefined") {
  1552. if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
  1553. opt = wrapper;
  1554. wrapper = false;
  1555. }
  1556. }
  1557. var ret = new NiceScrollArray();
  1558. if (typeof opt=="undefined") opt = {};
  1559. if (wrapper||false) {
  1560. opt.doc = $(wrapper);
  1561. opt.win = $(this);
  1562. }
  1563. var docundef = !("doc" in opt);
  1564. if (!docundef&&!("win" in opt)) opt.win = $(this);
  1565. this.each(function() {
  1566. var nice = $(this).data('__nicescroll')||false;
  1567. if (!nice) {
  1568. opt.doc = (docundef) ? $(this) : opt.doc;
  1569. nice = new NiceScrollClass(opt,$(this));
  1570. $(this).data('__nicescroll',nice);
  1571. }
  1572. ret.push(nice);
  1573. });
  1574. return (ret.length==1) ? ret[0] : ret;
  1575. };
  1576. window.NiceScroll = {
  1577. getjQuery:function(){return jQuery}
  1578. };
  1579. if (!$.nicescroll) {
  1580. $.nicescroll = new NiceScrollArray();
  1581. }
  1582. })( jQuery );