jquery.nicescroll.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /* jquery.nicescroll
  2. -- version 2.5.0
  3. -- copyright 2011 InuYaksa*2011
  4. -- licensed under the MIT
  5. --
  6. -- http://areaaperta.com/nicescroll
  7. -- https://github.com/inuyaksa/jquery.nicescroll
  8. --
  9. */
  10. (function($){
  11. // globals
  12. var domfocus = false;
  13. var mousefocus = false;
  14. var zoomactive = false;
  15. var tabindexcounter = 5000;
  16. var ascrailcounter = 2000;
  17. // http://stackoverflow.com/questions/2161159/get-script-path
  18. function getScriptPath() {
  19. var scripts=document.getElementsByTagName('script');
  20. var path=scripts[scripts.length-1].src.split('?')[0];
  21. return (path.split('/').length>0) ? path.split('/').slice(0,-1).join('/')+'/' : '';
  22. }
  23. var scriptpath = getScriptPath();
  24. var NiceScrollClass = function(myopt,me) {
  25. var self = this;
  26. this.version = '2.5.0';
  27. this.name = 'nicescroll';
  28. this.me = me;
  29. this.opt = {
  30. doc:$("body"),
  31. win:false,
  32. zindex:9000,
  33. cursoropacitymin:0,
  34. cursoropacitymax:1,
  35. cursorcolor:"#424242",
  36. cursorwidth:"5px",
  37. cursorborder:"1px solid #fff",
  38. cursorborderradius:"5px",
  39. scrollspeed:60,
  40. mousescrollstep:8*6,
  41. touchbehavior:false,
  42. hwacceleration:true,
  43. usetransition:true,
  44. boxzoom:false,
  45. dblclickzoom:true,
  46. gesturezoom:true,
  47. grabcursorenabled:true,
  48. autohidemode:true,
  49. background:"",
  50. iframeautoresize:true,
  51. cursorminheight:20
  52. };
  53. if (myopt||false) {
  54. for(var a in self.opt) {
  55. if (myopt[a]!==undefined) self.opt[a] = myopt[a];
  56. }
  57. }
  58. this.id = self.opt.doc[0].id||'';
  59. this.doc = self.opt.doc;
  60. this.ispage = (self.doc[0].nodeName=='BODY'||self.doc[0].nodeName=='HTML');
  61. this.haswrapper = (self.opt.win!==false);
  62. this.win = self.opt.win||(this.ispage?$(window):this.doc);
  63. this.docscroll = this.ispage?$(window):this.win;
  64. this.iframe = false;
  65. this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
  66. this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
  67. // Events jump table
  68. this.onmousedown = false;
  69. this.onmouseup = false;
  70. this.onmousemove = false;
  71. this.onmousewheel = false;
  72. this.onkeypress = false;
  73. // Let's start!
  74. this.view = false;
  75. this.page = false;
  76. this.scroll = {x:0,y:0};
  77. this.scrollratio = {x:0,y:0};
  78. this.cursorheight = 20;
  79. this.scrollvaluemax = 0;
  80. this.scrollmom = false;
  81. do {
  82. this.id = "ascrail"+(ascrailcounter++);
  83. } while (document.getElementById(this.id));
  84. this.rail = false;
  85. this.cursor = false;
  86. this.cursorfreezed = false;
  87. this.zoom = false;
  88. this.zoomactive = false;
  89. this.hasfocus = false;
  90. this.hasmousefocus = false;
  91. this.visibility = true;
  92. this.locked = false;
  93. this.events = []; // event list for unbind
  94. this.saved = {};
  95. var domtest = document.createElement('DIV');
  96. this.isopera = ("opera" in window);
  97. this.isie = (("all" in document) && ("attachEvent" in domtest) && !this.isopera);
  98. this.isieold = (this.isie && !("msInterpolationMode" in domtest.style)); // IE6 and older
  99. this.isie7 = this.isie&&!this.isieold&&(!("documentMode" in document)||(document.documentMode==7));
  100. this.isie8 = this.isie&&("documentMode" in document)&&(document.documentMode==8);
  101. this.isie9 = this.isie&&("performance" in window)&&(document.documentMode>=9);
  102. this.ismozilla = ("MozAppearance" in domtest.style);
  103. this.cantouch = ("ontouchstart" in document.documentElement);
  104. if (this.cantouch && /iphone|ipad|ipod/i.test(navigator.platform)) {
  105. this.isios = true;
  106. this.isios4 = !("seal" in Object);
  107. } else {
  108. this.isios = false;
  109. this.isios4 = false;
  110. }
  111. if (self.opt.hwacceleration) { // if you dont need dont bother to look for
  112. this.trstyle = (window.opera) ? 'OTransform' : (document.all) ? 'msTransform' : (domtest.style.webkitTransform!==undefined) ? 'webkitTransform' : (domtest.style.MozTransform!==undefined) ? 'MozTransform' : false;
  113. if (this.trstyle && domtest.style[this.trstyle] === undefined) this.trstyle = false;
  114. this.hastransform = (this.trstyle != false);
  115. if (this.hastransform) {
  116. domtest.style[this.trstyle] = "translate3d(1px,2px,3px)";
  117. this.hastranslate3d = /translate3d/.test(domtest.style[this.trstyle]);
  118. }
  119. this.transitionstyle = false;
  120. this.prefixstyle = '';
  121. this.transitionend = false;
  122. var check = ['transition','webkitTransition','MozTransition','OTransition','msTransition','KhtmlTransition'];
  123. var prefix = ['','-webkit-','-moz-','-o-','-ms-','-khtml-'];
  124. var evs = ['transitionEnd','webkitTransitionEnd','transitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
  125. for(var a=0;a<check.length;a++) {
  126. if (check[a] in domtest.style) {
  127. this.transitionstyle = check[a];
  128. this.prefixstyle = prefix[a];
  129. this.transitionend = evs[a];
  130. break;
  131. }
  132. }
  133. this.hastransition = (this.transitionstyle);
  134. } else {
  135. this.trstyle = false;
  136. this.hastransform = false;
  137. this.hastranslate3d = false;
  138. this.transitionstyle = false;
  139. this.hastransition = false;
  140. this.transitionend = false;
  141. }
  142. this.cursorgrabvalue = '';
  143. if (self.opt.grabcursorenabled&&self.opt.touchbehavior) { // check grab cursor support
  144. function detectCursorGrab() {
  145. if (!self.isie||self.isie9) { // some old IE return false positive
  146. var lst = ['grab','-moz-grab','-webkit-grab'];
  147. for(var a=0;a<lst.length;a++) {
  148. var p = lst[a];
  149. domtest.style['cursor']=p;
  150. if (domtest.style['cursor']==p) return p;
  151. }
  152. }
  153. return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize';
  154. }
  155. this.cursorgrabvalue = detectCursorGrab();
  156. }
  157. domtest = null;
  158. this.ishwscroll = (self.hastransform)&&(self.opt.hwacceleration)&&(self.haswrapper);
  159. this.scrollTop = function(val) {
  160. return (val === undefined) ? self.getScrollTop() : self.setScrollTop(val);
  161. };
  162. if (this.ishwscroll) {
  163. // hw accelerated scroll
  164. self.doc.translate = {x:0,y:0};
  165. this.getScrollTop = function() {
  166. return self.doc.translate.y;
  167. };
  168. if (this.hastranslate3d) {
  169. this.setScrollTop = function(val,silent) {
  170. self.doc.css(self.trstyle,"translate3d(0px,"+(val*-1)+"px,0px)");
  171. self.doc.translate.y = val;
  172. if (!silent) {
  173. if (document.createEvent) {
  174. var e = document.createEvent("UIEvents");
  175. e.initUIEvent("scroll", false, true, window, 1);
  176. self.docscroll[0].dispatchEvent(e);
  177. } else {
  178. var e = document.createEventObject();
  179. self.docscroll[0].fireEvent("onscroll");
  180. e.cancelBubble = true;
  181. }
  182. }
  183. };
  184. } else {
  185. this.setScrollTop = function(val,silent) {
  186. self.doc.css(self.trstyle,"translate(0px,"+(val*-1)+"px)");
  187. self.doc.translate.y = val;
  188. if (!silent) {
  189. if (document.createEvent) {
  190. var e = document.createEvent("UIEvents");
  191. e.initUIEvent("scroll", false, true, window, 1);
  192. self.docscroll[0].dispatchEvent(e);
  193. } else {
  194. var e = document.createEventObject();
  195. self.docscroll[0].fireEvent("onscroll");
  196. e.cancelBubble = true;
  197. }
  198. }
  199. };
  200. }
  201. } else {
  202. // native scroll
  203. this.getScrollTop = function() {
  204. return self.docscroll.scrollTop();
  205. };
  206. this.setScrollTop = function(val) {
  207. return self.docscroll.scrollTop(val);
  208. };
  209. }
  210. this.getTarget = function(e) {
  211. if (!e) return false;
  212. if (e.target) return e.target;
  213. if (e.srcElement) return e.srcElement;
  214. return false;
  215. };
  216. this.hasParent = function(e,id) {
  217. if (!e) return false;
  218. var el = e.target||e.srcElement||e||false;
  219. while (el && el.id != id) {
  220. el = el.parentNode||false;
  221. }
  222. return (el!==false);
  223. };
  224. this.updateScrollBar = function(len) {
  225. if (self.ishwscroll) {
  226. self.rail.css({height:self.win.innerHeight()});
  227. } else {
  228. var pos = self.win.offset();
  229. pos.top+=2;
  230. var brd = (self.win.outerWidth() - self.win.innerWidth())/2;
  231. pos.left+= self.win.innerWidth() + brd - self.rail.width - 1;
  232. self.rail.css({position:"absolute",top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
  233. if (self.zoom) self.zoom.css({position:"absolute",top:pos.top+1,left:pos.left-20});
  234. }
  235. };
  236. // derived by http://blog.joelambert.co.uk/2011/06/01/a-better-settimeoutsetinterval/
  237. var setAnimationFrame = (function(){
  238. return window.requestAnimationFrame ||
  239. window.webkitRequestAnimationFrame ||
  240. window.mozRequestAnimationFrame ||
  241. window.oRequestAnimationFrame ||
  242. window.msRequestAnimationFrame ||
  243. false;
  244. })();
  245. var clearAnimationFrame = (function(){
  246. return window.cancelRequestAnimationFrame ||
  247. window.webkitCancelRequestAnimationFrame ||
  248. window.mozCancelRequestAnimationFrame ||
  249. window.oCancelRequestAnimationFrame ||
  250. window.msCancelRequestAnimationFrame ||
  251. false;
  252. })();
  253. self.hasanimationframe = (setAnimationFrame);
  254. self.hascancelanimationframe = (clearAnimationFrame);
  255. if (!self.hasanimationframe) {
  256. setAnimationFrame=function(fn){return setTimeout(fn,1000/60)};
  257. clearAnimationFrame=clearInterval;
  258. }
  259. else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
  260. this.init = function() {
  261. self.saved.css = [];
  262. if (self.ispage) self.saved.css.push([self.doc,'overflow-y',self.doc.css('overflow-y')]);
  263. if (!self.ispage) self.saved.css.push([self.docscroll,'overflow-y',self.docscroll.css('overflow-y')]);
  264. if (self.ispage&&self.isie7) self.saved.css.push([$("html"),'overflow-y',$("html").css('overflow-y')]);
  265. if (!self.ispage || (!self.cantouch && !self.isieold)) {
  266. (self.ispage)?self.doc.css({'overflow-y':'hidden'}):self.docscroll.css({'overflow-y':'hidden'});
  267. if (self.ispage&&self.isie7) $("html").css({'overflow-y':'hidden'}); //IE7 double scrollbar issue
  268. var cursor = $(document.createElement('div'));
  269. cursor.css({
  270. position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
  271. 'background-color':self.opt.cursorcolor,
  272. border:self.opt.cursorborder,
  273. 'background-clip':'padding-box',
  274. '-webkit-border-radius':self.opt.cursorborderradius,
  275. '-moz-border-radius':self.opt.cursorborderradius,
  276. 'border-radius':self.opt.cursorborderradius
  277. });
  278. cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
  279. self.cursor = cursor;
  280. var rail = $(document.createElement('div'));
  281. rail.attr('id',self.id);
  282. rail.width = 3+Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth());
  283. rail.css({"padding-left":"0px","padding-right":"1px",width:rail.width+"px",'zIndex':(self.ispage)?self.opt.zindex:self.opt.zindex+2,"background":self.opt.background});
  284. rail.append(cursor);
  285. self.rail = rail;
  286. var zoom = false;
  287. if (self.opt.boxzoom&&!self.ispage&&!self.isieold) {
  288. zoom = document.createElement('div');
  289. self.bind(zoom,"click",self.doZoom);
  290. self.zoom = $(zoom);
  291. self.zoom.css({"cursor":"pointer",'z-index':self.opt.zindex,'backgroundImage':'url('+scriptpath+'zoomico.png)','height':18,'width':18,'backgroundPosition':'0px 0px'});
  292. if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
  293. if (self.cantouch&&self.opt.gesturezoom) {
  294. self.bind(self.win,"gestureend",function(e) {
  295. if (e.scale>1.5) self.doZoomIn(e);
  296. if (e.scale<0.8) self.doZoomOut(e);
  297. return self.cancelEvent(e);
  298. });
  299. }
  300. }
  301. if (self.ispage) {
  302. rail.css({position:"fixed",top:"0px",right:"0px",height:"100%"});
  303. self.doc.append(rail);
  304. } else {
  305. if (self.ishwscroll) {
  306. if (self.win.css('position')=='static') self.win.css('position','relative');
  307. if (self.zoom) {
  308. self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
  309. self.win.append(self.zoom);
  310. }
  311. rail.css({position:"absolute",top:0,right:0});
  312. self.win.append(rail);
  313. } else {
  314. self.updateScrollBar();
  315. $("body").append(rail);
  316. if (self.zoom) $("body").append(self.zoom);
  317. }
  318. }
  319. if (self.opt.autohidemode===false) {
  320. self.autohidedom = false;
  321. }
  322. else if (self.opt.autohidemode===true) {
  323. self.autohidedom = self.rail;
  324. }
  325. else if (self.opt.autohidemode=="cursor") {
  326. self.autohidedom = self.cursor;
  327. }
  328. self.bind(window,'resize',self.onResize);
  329. self.bind(window,'orientationchange',self.onResize);
  330. if (!self.ispage&&!self.haswrapper) {
  331. self.bind(self.win,(self.isie&&!self.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);
  332. }
  333. if (!self.ispage&&self.opt.boxzoom) $(window).resize(self.resizeZoom);
  334. if (self.istextarea) self.win.mouseup(self.onResize);
  335. self.onResize();
  336. if (self.cantouch||self.opt.touchbehavior) {
  337. self.scrollmom = {
  338. y:new ScrollMomentumClass(self)
  339. };
  340. self.onmousedown = function(e) {
  341. if (!self.locked) {
  342. self.cancelScroll();
  343. self.rail.drag = {x:e.pageX,y:e.pageY,sx:self.scroll.x,sy:self.scroll.y,st:self.getScrollTop()};//,st:self.getScrollTop(),lx:e.pageX,ly:e.pageY,nx:e.pageX,ny:e.pageY,tt:(new Date()).getTime(),lt:(new Date()).getTime()};
  344. self.hasmoving = false;
  345. self.scrollmom.y.reset(e.pageY);
  346. if (!self.cantouch) return self.cancelEvent(e);
  347. }
  348. };
  349. self.onmouseup = function(e) {
  350. if (self.rail.drag) {
  351. // self.doScrollMomentum(self.rail.drag);
  352. self.scrollmom.y.doMomentum();
  353. self.rail.drag = false;
  354. if (self.hasmoving) {
  355. self.hasmoving = false;
  356. return self.cancelEvent(e);
  357. }
  358. }
  359. };
  360. self.onmousemove = function(e) {
  361. if (self.rail.drag) {
  362. self.hasmoving = true;
  363. var my = (e.pageY-self.rail.drag.y);
  364. /*
  365. self.rail.drag.ly = self.rail.drag.ny;
  366. self.rail.drag.ny = e.pageY;
  367. self.rail.drag.lt = (new Date()).getTime();
  368. */
  369. self.scrollmom.y.update(e.pageY);
  370. /*
  371. self.scroll.y = Math.round((self.rail.drag.st-my) * (1/self.scrollratio.y));
  372. if (self.scroll.y<0) self.scroll.y=0;
  373. if (self.scroll.y>self.scrollvaluemax) self.scroll.y=self.scrollvaluemax;
  374. */
  375. self.showCursor(self.rail.drag.st-my);
  376. if (self.prepareTransition) self.prepareTransition(0);
  377. self.setScrollTop(self.rail.drag.st-my);
  378. return self.cancelEvent(e);
  379. }
  380. };
  381. if (self.cursorgrabvalue) {
  382. self.saved.css.push([self.win,'cursor',self.win.css('cursor')]);
  383. self.win.css({'cursor':self.cursorgrabvalue});
  384. }
  385. } else {
  386. self.onmousedown = function(e) {
  387. if (self.locked) return self.cancelEvent(e);
  388. self.cancelScroll();
  389. self.rail.drag = {x:e.screenX,y:e.screenY,sx:self.scroll.x,sy:self.scroll.y};
  390. return self.cancelEvent(e);
  391. };
  392. self.onmouseup = function(e) {
  393. if (self.rail.drag) {
  394. self.rail.drag = false;
  395. return self.cancelEvent(e);
  396. }
  397. };
  398. self.onmousemove = function(e) {
  399. if (self.rail.drag) {
  400. self.scroll.y = self.rail.drag.sy + (e.screenY-self.rail.drag.y);
  401. if (self.scroll.y<0) self.scroll.y=0;
  402. var my = self.scrollvaluemax;
  403. if (self.scroll.y>my) self.scroll.y=my;
  404. self.showCursor();
  405. self.cursorfreezed = true;
  406. self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));
  407. return self.cancelEvent(e);
  408. }
  409. };
  410. }
  411. if (self.cantouch||self.opt.touchbehavior) self.bind(self.win,"mousedown",self.onmousedown);
  412. self.bind(self.win,"mouseup",self.onmouseup);
  413. self.bind(self.rail,"mousedown",self.onmousedown);
  414. self.bind(self.rail,"mouseup",function(e) {
  415. self.rail.drag = false;
  416. self.hasmoving = false;
  417. self.hideCursor();
  418. return self.cancelEvent(e);
  419. });
  420. self.bind(document,"mouseup",self.onmouseup);
  421. self.bind(document,"mousemove",self.onmousemove);
  422. if (!self.cantouch) {
  423. self.rail.mouseenter(function() {
  424. self.showCursor();
  425. self.rail.active = true;
  426. });
  427. self.rail.mouseleave(function() {
  428. self.rail.active = false;
  429. if (!self.rail.drag) self.hideCursor();
  430. });
  431. if (!self.isiframe) self.bind((self.isie&&self.ispage) ? document : self.docscroll,"mousewheel",self.onmousewheel);
  432. self.bind(self.rail,"mousewheel",self.onmousewheel);
  433. }
  434. if (!self.ispage&&!self.cantouch) {
  435. if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
  436. self.win.focus(function(e) {
  437. domfocus = (self.getTarget(e)).id||true;
  438. self.hasfocus = true;
  439. self.noticeCursor();
  440. });
  441. self.win.blur(function(e) {
  442. domfocus = false;
  443. self.hasfocus = false;
  444. });
  445. self.win.mouseenter(function(e) {
  446. mousefocus = (self.getTarget(e)).id||true;
  447. self.hasmousefocus = true;
  448. self.noticeCursor();
  449. });
  450. self.win.mouseleave(function() {
  451. mousefocus = false;
  452. self.hasmousefocus = false;
  453. });
  454. };
  455. //Thanks to http://www.quirksmode.org !!
  456. self.onkeypress = function(e) {
  457. e = (e) ? e : window.e;
  458. var tg = self.getTarget(e);
  459. if (tg&&/INPUT|TEXTAREA|SELECT/.test(tg.nodeName)) {
  460. var tp = tg.getAttribute('type')||tg.type||false;
  461. if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
  462. }
  463. if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
  464. var key = e.keyCode;
  465. if (self.locked&&key!=27) return self.cancelEvent(e);
  466. var ret = true;
  467. switch (key) {
  468. case 38:
  469. case 63233: //safari
  470. self.doScrollBy(24*3,true);
  471. ret = false;
  472. break;
  473. case 40:
  474. case 63235: //safari
  475. self.doScrollBy(-24*3,true);
  476. ret = false;
  477. break;
  478. case 33:
  479. case 63276: // safari
  480. self.doScrollBy(self.view.h,true);
  481. ret = false;
  482. break;
  483. case 34:
  484. case 63277: // safari
  485. self.doScrollBy(-self.view.h,true);
  486. ret = false;
  487. break;
  488. case 36:
  489. case 63273: // safari
  490. self.doScrollTo(0,true);
  491. ret = false;
  492. break;
  493. case 35:
  494. case 63275: // safari
  495. self.doScrollTo(self.page.maxh,true);
  496. ret = false;
  497. break;
  498. case 27: // ESC
  499. if (self.zoomactive) {
  500. self.doZoom();
  501. ret = false;
  502. }
  503. break;
  504. }
  505. if (!ret) return self.cancelEvent(e);
  506. }
  507. };
  508. self.bind(document,(self.isopera)?"keypress":"keydown",self.onkeypress);
  509. }
  510. if (this.doc[0].nodeName == 'IFRAME') {
  511. function oniframeload(e) {
  512. var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
  513. if (self.isiframe) {
  514. self.docscroll = $(doc);
  515. self.iframe = {
  516. html:self.doc.contents().find('html')[0],
  517. body:self.doc.contents().find('body')[0]
  518. };
  519. }
  520. if (self.opt.iframeautoresize&&!self.isiframe) {
  521. self.win.scrollTop(0); // reset position
  522. self.doc.height(""); //reset height to fix browser bug
  523. var cc=self.doc.contents();
  524. var hh=Math.max(cc.find('html').attr('scrollHeight'),cc.find('body').attr('scrollHeight'));
  525. self.doc.height(hh);
  526. }
  527. self.onResize();
  528. if (self.isie7) self.saved.css.push([$(doc).find('html'),'overflow-y',$(doc).find('html').css('overflow-y')]);
  529. self.saved.css.push([$(doc.body),'overflow-y',$(doc.body).css('overflow-y')]);
  530. if (self.isie7) $(doc).find('html').css({'overflow-y':'hidden'});
  531. $(doc.body).css({'overflow-y':'hidden'});
  532. if ('contentWindow' in this) {
  533. self.bind(this.contentWindow,"scroll",self.onscroll); //IE8 & minor
  534. } else {
  535. self.bind(doc,"scroll",self.onscroll);
  536. }
  537. self.bind(doc,"mouseup",self.onmouseup);
  538. self.bind(doc,"mousewheel",self.onmousewheel);
  539. self.bind(doc,(self.isopera)?"keypress":"keydown",self.onkeypress);
  540. if (self.cantouch||self.opt.touchbehavior) {
  541. self.bind(doc,"mousedown",self.onmousedown);
  542. if (self.cursorgrabvalue) {
  543. self.saved.css.push([$(doc),'cursor',$(doc).css('cursor')]);
  544. $(doc).css({'cursor':self.cursorgrabvalue});
  545. }
  546. }
  547. self.bind(doc,"mousemove",self.onmousemove);
  548. if (self.zoom) {
  549. if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
  550. if (self.cantouch&&self.opt.gesturezoom) {
  551. self.bind(doc,"gesturechange",function(e) {
  552. if (e.scale>1.5) self.doZoomIn(e);
  553. if (e.scale<0.8) self.doZoomOut(e);
  554. return self.cancelEvent(e);
  555. });
  556. }
  557. }
  558. };
  559. if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
  560. setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
  561. }
  562. this.doc.load(oniframeload);
  563. }
  564. };
  565. this.showCursor = function(py) {
  566. if (self.cursortimeout) {
  567. clearTimeout(self.cursortimeout);
  568. self.cursortimeout = 0;
  569. }
  570. if (!self.rail) return;
  571. if (self.autohidedom) self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
  572. if (typeof py != "undefined") {
  573. self.scroll.y = Math.round(py * 1/self.scrollratio.y);
  574. }
  575. self.cursor.css({height:self.cursorheight,top:self.scroll.y});
  576. if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});
  577. };
  578. this.hideCursor = function(tm) {
  579. if (self.cursortimeout) return;
  580. if (!self.rail) return;
  581. if (!self.autohidedom) return;
  582. self.cursortimeout = setTimeout(function() {
  583. if (!self.rail.active) {
  584. self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
  585. if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
  586. }
  587. self.cursortimeout = 0;
  588. },tm||800);
  589. };
  590. this.noticeCursor = function(tm) {
  591. self.showCursor();
  592. self.hideCursor(tm);
  593. };
  594. this.getContentSize = function() {
  595. var pg =
  596. (self.ispage) ?
  597. {
  598. w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
  599. h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
  600. }
  601. : (self.haswrapper) ?
  602. {
  603. w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
  604. h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
  605. }
  606. : (self.iframe) ?
  607. {
  608. w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
  609. h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
  610. }
  611. :
  612. {
  613. w:self.docscroll[0].scrollWidth,
  614. h:self.docscroll[0].scrollHeight
  615. };
  616. pg.w-=1;
  617. pg.h-=1;
  618. return pg;
  619. };
  620. this.onAttributeChange = function(e) {
  621. if (e&&e.target) {
  622. if ((e.target !== self.win[0])&&(e.target!==self.doc[0])) return true;
  623. var attr = ("attrChange" in e)?e.attrName:("propertyName" in e)?e.propertyName:false;
  624. if (attr&&/width|height|style|block/i.test(attr)) {
  625. if (self.lastattributechange) self.lastattributechange=clearTimeout(self.lastattributechange);
  626. self.lastattributechange = setTimeout(function(){
  627. self.lastattributechange = 0;
  628. self.onResize();
  629. },60);
  630. }
  631. }
  632. };
  633. this.onResize = function() {
  634. if (!self.haswrapper&&!self.ispage) {
  635. var vis = (self.win.css('display')!='none');
  636. if (vis&&!self.visibility) self.show();
  637. if (!vis&&self.visibility) self.hide();
  638. if (!self.visibility) return false;
  639. }
  640. self.view = {
  641. w:(self.ispage) ? self.win.width() : self.win.innerWidth(),
  642. h:(self.ispage) ? self.win.height() : self.win.innerHeight()
  643. };
  644. self.page = self.getContentSize();
  645. self.page.maxh = self.page.h - self.view.h;
  646. if (self.view.h>=self.page.h) {
  647. self.hide();
  648. self.scrollvaluemax = 0;
  649. self.scroll.y = 0;
  650. self.scrollratio = {x:0,y:0};
  651. self.cursorheight = 0;
  652. self.locked = true;
  653. self.setScrollTop(0);
  654. return false;
  655. }
  656. else if (!self.visibility) self.show();
  657. self.locked = false;
  658. if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
  659. if (!self.ispage) self.updateScrollBar(self.view);
  660. self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
  661. self.cursorheight = Math.max(self.opt.cursorminheight,self.cursorheight);
  662. self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder-2;
  663. self.scrollratio = {
  664. x:0,
  665. y:((self.page.h - self.view.h)/self.scrollvaluemax)
  666. };
  667. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  668. self.noticeCursor();
  669. return self;
  670. };
  671. this.resize = this.onResize; // mask internal method -- in future name can change
  672. this._bind = function(el,name,fn,bubble) { // primitive bind
  673. self.events.push({e:el,n:name,f:fn});
  674. if (el.addEventListener) {
  675. el.addEventListener(name,fn,bubble||false);
  676. }
  677. else if (el.attachEvent) {
  678. el.attachEvent("on"+name,fn);
  679. }
  680. else {
  681. el["on"+name] = fn;
  682. }
  683. };
  684. this.bind = function(dom,name,fn,bubble) { // touch-oriented & fixing jquery bind
  685. var el = (dom.length) ? dom[0] : dom;
  686. if (el.addEventListener) {
  687. if (self.cantouch && /mouseup|mousedown|mousemove/.test(name)) { // touch device support
  688. var tt = (name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
  689. self._bind(el,tt,function(e){
  690. if(e.touches.length<2){var ev=(e.touches.length>0)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
  691. },bubble||false);
  692. }
  693. self._bind(el,name,fn,bubble||false);
  694. if (name=='mousewheel') self._bind(el,"DOMMouseScroll",fn,bubble||false);
  695. if (self.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
  696. }
  697. else {
  698. self._bind(el,name,function(e) {
  699. if (e&&!("pageY" in e)&&("screenY" in e)) {
  700. e.pageX = e.screenX;
  701. e.pageY = e.screenY;
  702. }
  703. return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
  704. });
  705. }
  706. };
  707. this._unbind = function(el,name,fn) { // primitive unbind
  708. if (el.removeEventListener) {
  709. el.removeEventListener(name,fn,false);
  710. }
  711. else if (el.detachEvent) {
  712. el.detachEvent('on'+name,fn);
  713. } else {
  714. el['on'+name] = false;
  715. }
  716. };
  717. this.unbindAll = function() {
  718. for(var a=0;a<self.events.length;a++) {
  719. var r = self.events[a];
  720. self._unbind(r.e,r.n,r.f);
  721. }
  722. };
  723. // Thanks to http://www.switchonthecode.com !!
  724. this.cancelEvent = function(e) {
  725. if (self.cantouch) {
  726. e = e.original ? e.original : e||false;
  727. } else {
  728. e = e ? e : window.event||false;
  729. }
  730. if (!e) return false;
  731. if(e.stopPropagation) e.stopPropagation();
  732. if(e.preventDefault) e.preventDefault();
  733. e.cancelBubble = true;
  734. e.cancel = true;
  735. e.returnValue = false;
  736. return false;
  737. };
  738. this.show = function() {
  739. self.visibility = true;
  740. self.rail.css('display','block');
  741. return self;
  742. };
  743. this.hide = function() {
  744. self.visibility = false;
  745. self.rail.css('display','none');
  746. return self;
  747. };
  748. this.remove = function() {
  749. self.doZoomOut();
  750. self.unbindAll();
  751. self.events = [];
  752. self.rail.remove();
  753. if (self.zoom) self.zoom.remove();
  754. self.cursor = false;
  755. self.rail = false;
  756. self.zoom = false;
  757. for(var a=0;a<self.saved.css.length;a++) {
  758. var d=self.saved.css[a];
  759. d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
  760. }
  761. self.saved = false;
  762. self.me.data('__nicescroll',''); //erase all traces
  763. return self;
  764. };
  765. this.onmousewheel = function(e) {
  766. if (self.locked) return self.cancelEvent(e);
  767. e = e ? e : window.event;
  768. if (self.rail.drag) return self.cancelEvent(e);
  769. var delta = 0;
  770. var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
  771. if (delta) {
  772. if (self.scrollmom) self.scrollmom.y.stop();
  773. self.doScrollBy(delta*self.opt.mousescrollstep,true);
  774. }
  775. return self.cancelEvent(e);
  776. };
  777. this.stop = function() {
  778. self.cancelScroll();
  779. if (self.scrollmon) self.scrollmon.stop();
  780. self.cursorfreezed = false;
  781. self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  782. self.noticeCursor();
  783. return self;
  784. };
  785. if (self.ishwscroll&&self.hastransition&&self.opt.usetransition) {
  786. this.prepareTransition = function(dif,trend) {
  787. var sp = Math.round(self.opt.scrollspeed*10);
  788. var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
  789. var trans = (ex>20) ? self.prefixstyle+'transform '+ex+'ms ease-out 0s' : '';
  790. if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
  791. self.lasttransitionstyle = trans;
  792. self.doc.css(self.transitionstyle,trans);
  793. }
  794. };
  795. this.doScroll = function(y) {
  796. self.newscrolly = y;
  797. if (self.timer) return false;
  798. self.timer = setTimeout(function(){
  799. var top = self.getScrollTop();
  800. var dif = Math.abs(top-self.newscrolly);
  801. self.prepareTransition(dif)
  802. self.timer = setTimeout(function(){
  803. self.setScrollTop(self.newscrolly);
  804. self.timer = 0;
  805. },15);
  806. },self.opt.scrollspeed);
  807. self.noticeCursor();
  808. };
  809. this.cancelScroll = function() {
  810. var py = self.getScrollTop();
  811. self.prepareTransition(0);
  812. self.setScrollTop(py);
  813. self.noticeCursor();
  814. return self;
  815. };
  816. // self.bind(self.doc,'transitionend',function(e){console.log(e)},false); TEST!! Later or soon I use it! (I hope so)
  817. } else {
  818. this.doScroll = function(y) {
  819. self.newscrolly = y;
  820. var df = y-self.getScrollTop();
  821. if ((df*df)>100) {
  822. self.newspeedy = {
  823. x:y-Math.round(df/6),
  824. v:Math.round(df/6*5/8)+1
  825. };
  826. } else {
  827. self.newspeedy = false;
  828. }
  829. if (self.timer) return;
  830. var rt = 1/4;
  831. var sync = 0;
  832. var lastsync = 0;
  833. function scrolling() {
  834. if (self.cancelAnimationFrame) return true;
  835. sync=(new Date()).getTime();
  836. if (sync<lastsync) return (self.timer = setAnimationFrame(scrolling)||1);
  837. lastsync = Math.floor((new Date()).getTime()+self.opt.scrollspeed/2);
  838. sync=0;
  839. var sy = self.getScrollTop();
  840. if (self.newspeedy) {
  841. var sc = sy + self.newspeedy.v;
  842. if (self.newspeedy.v>0) {
  843. if (sc>=self.newspeedy.x) self.newspeedy = false;
  844. } else {
  845. if (sc<=self.newspeedy.x) self.newspeedy = false;
  846. }
  847. } else {
  848. var gp = self.newscrolly - self.getScrollTop();
  849. var df = (gp>0) ? Math.ceil(gp*rt) : Math.floor(gp*rt);
  850. var sc = self.getScrollTop()+df;
  851. }
  852. self.setScrollTop(sc);
  853. // if (!self.cursorfreezed) self.showCursor(sc);
  854. if (sc == self.newscrolly) {
  855. // clearAnimationFrame(self.timer);
  856. self.timer = 0;
  857. self.cursorfreezed = false;
  858. } else {
  859. self.timer = setAnimationFrame(scrolling)||1;
  860. }
  861. };
  862. self.cancelAnimationFrame=false;
  863. self.timer = setAnimationFrame(scrolling)||1;
  864. self.noticeCursor();
  865. };
  866. this.cancelScroll = function() {
  867. if (self.timer) clearAnimationFrame(self.timer);
  868. self.timer = 0;
  869. return self;
  870. };
  871. }
  872. this.doScrollBy = function(stp,absolute) {
  873. var ny = 0;
  874. if (absolute) {
  875. if (self.timer) {
  876. ny = self.newscrolly-stp;
  877. } else {
  878. ny = self.getScrollTop()-stp;
  879. }
  880. } else {
  881. ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
  882. }
  883. if (ny<0) ny=0
  884. else if (ny>self.page.maxh) ny = self.page.maxh;
  885. self.cursorfreezed = false;
  886. self.doScroll(ny);
  887. };
  888. this.doScrollTo = function(pos,absolute) {
  889. var ny = (absolute) ? pos : Math.round(pos*self.scrollratio.y);
  890. if (ny<0) ny=0
  891. else if (ny>self.page.maxh) ny = self.page.maxh;
  892. self.cursorfreezed = false;
  893. self.doScroll(pos);
  894. };
  895. self.onscroll = function(e) {
  896. var tm = (new Date()).getTime();
  897. if (!self.lastcontentcheck || self.lastcontentcheck<tm) {
  898. self.lastcontentcheck=tm+500;
  899. var pg = self.getContentSize();
  900. if (pg.h!=self.page.h) self.onResize();
  901. }
  902. if (self.rail.drag) return;
  903. if (!self.cursorfreezed) self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
  904. self.noticeCursor();
  905. };
  906. self.bind(self.docscroll,"scroll",self.onscroll);
  907. this.doZoomIn = function(e) {
  908. if (self.zoomactive) return;
  909. self.zoomactive = true;
  910. self.zoomrestore = {
  911. style:{}
  912. };
  913. var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
  914. var win = self.win[0].style;
  915. for(var a in lst) {
  916. var pp = lst[a];
  917. self.zoomrestore.style[pp] = (typeof win[pp]!='undefined') ? win[pp] : '';
  918. }
  919. self.zoomrestore.style.width = self.win.css('width');
  920. self.zoomrestore.style.height = self.win.css('height');
  921. self.zoomrestore.padding = {
  922. w:self.win.outerWidth()-self.win.width(),
  923. h:self.win.outerHeight()-self.win.height()
  924. };
  925. if (self.isios4) {
  926. self.zoomrestore.scrollTop = $(window).scrollTop();
  927. $(window).scrollTop(0);
  928. }
  929. self.win.css({
  930. "position":(self.isios4)?"absolute":"fixed",
  931. "top":0,
  932. "left":0,
  933. "z-index":self.opt.zindex+100,
  934. "margin":"0px"
  935. });
  936. var bkg = self.win.css("backgroundColor");
  937. if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
  938. self.rail.css({"z-index":self.opt.zindex+110});
  939. self.zoom.css({"z-index":self.opt.zindex+112});
  940. self.zoom.css('backgroundPosition','0px -18px');
  941. self.resizeZoom();
  942. return self.cancelEvent(e);
  943. };
  944. this.doZoomOut = function(e) {
  945. if (!self.zoomactive) return;
  946. self.zoomactive = false;
  947. self.win.css("margin","");
  948. self.win.css(self.zoomrestore.style);
  949. if (self.isios4) {
  950. $(window).scrollTop(self.zoomrestore.scrollTop);
  951. }
  952. self.rail.css({"z-index":(self.ispage)?self.opt.zindex:self.opt.zindex+2});
  953. self.zoom.css({"z-index":self.opt.zindex});
  954. self.zoomrestore = false;
  955. self.zoom.css('backgroundPosition','0px 0px');
  956. self.onResize();
  957. return self.cancelEvent(e);
  958. };
  959. this.doZoom = function(e) {
  960. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  961. };
  962. this.resizeZoom = function() {
  963. if (!self.zoomactive) return;
  964. var py = self.getScrollTop(); //preserve scrolling position
  965. self.win.css({
  966. width:$(window).width()-self.zoomrestore.padding.w+"px",
  967. height:$(window).height()-self.zoomrestore.padding.h+"px"
  968. });
  969. self.setScrollTop(py);
  970. self.onResize();
  971. };
  972. this.init();
  973. };
  974. // Inspired by the work of Kin Blas
  975. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  976. var ScrollMomentumClass = function(nc) {
  977. var self = this;
  978. this.nc = nc;
  979. this.lasty = 0;
  980. this.speedy = 0;
  981. this.lasttime = 0;
  982. this.snapy = false;
  983. this.demuly = 0;
  984. this.timer = 0;
  985. this.time = function() {
  986. return (new Date()).getTime();
  987. };
  988. this.reset = function(py) {
  989. self.stop();
  990. self.lasttime = self.time();
  991. self.speedy = 0;
  992. self.lasty = py;
  993. };
  994. this.update = function(py) {
  995. self.lasttime = self.time();
  996. var dy = py - self.lasty;
  997. var sy = nc.getScrollTop();
  998. var newy = sy + dy;
  999. self.snapy = (newy<0)||(newy>self.nc.page.maxh);
  1000. self.speedy = dy;
  1001. self.lasty = py;
  1002. };
  1003. this.stop = function() {
  1004. if (self.timer) {
  1005. clearTimeout(self.timer);
  1006. self.timer = 0;
  1007. }
  1008. };
  1009. this.doSnapy = function(ny) {
  1010. if (ny<0) {
  1011. self.nc.doScrollTo(0,true);
  1012. }
  1013. else if (ny>self.nc.page.maxh) {
  1014. self.nc.doScrollTo(self.nc.page.maxh,true);
  1015. }
  1016. };
  1017. this.doMomentum = function() {
  1018. var l = self.lasttime;
  1019. var t = self.time();
  1020. self.speedy = Math.min(200,self.speedy);
  1021. var chk = l && (t - l) <= 50;
  1022. var sy = (self.speedy && chk) ? self.speedy : false;
  1023. if (sy) {
  1024. var tm = t-l;
  1025. self.demuly = 0;
  1026. var onscroll = function(){
  1027. var ny = Math.floor(self.nc.getScrollTop() - (self.speedy*(1-self.demuly)));
  1028. self.demuly+=0.02;
  1029. self.nc.setScrollTop(ny);
  1030. self.nc.showCursor(ny);
  1031. if(self.demuly<1) {
  1032. self.timer = setTimeout(onscroll,tm);
  1033. } else {
  1034. self.timer = 0;
  1035. self.nc.hideCursor();
  1036. self.doSnapy(ny);
  1037. }
  1038. };
  1039. onscroll();
  1040. } else {
  1041. if (self.snapy) {
  1042. self.doSnapy(self.nc.getScrollTop());
  1043. }
  1044. }
  1045. }
  1046. };
  1047. // override jQuery scrollTop
  1048. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  1049. $.cssHooks.scrollTop = {
  1050. get: function(elem,computed,extra) {
  1051. var nice = $.data(elem,'__nicescroll')||false;
  1052. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  1053. },
  1054. set: function(elem,value) {
  1055. var nice = $.data(elem,'__nicescroll')||false;
  1056. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
  1057. return this;
  1058. }
  1059. };
  1060. jQuery.fn.scrollTop = function(value) {
  1061. if (typeof value == "undefined") {
  1062. var nice = $.data(this,'__nicescroll')||false;
  1063. return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  1064. } else {
  1065. return this.each(function() {
  1066. var nice = $.data(this,'__nicescroll')||false;
  1067. (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
  1068. });
  1069. }
  1070. }
  1071. var NiceScrollArray = function(doms) {
  1072. var self = this;
  1073. this.length = 0;
  1074. this.name = "nicescrollarray";
  1075. this.each = function(fn) {
  1076. for(var a=0;a<self.length;a++) fn.call(self[a]);
  1077. return self;
  1078. };
  1079. this.show = function() {
  1080. return self.each(function(){
  1081. this.show();
  1082. });
  1083. };
  1084. this.hide = function() {
  1085. return self.each(function(){
  1086. this.hide();
  1087. });
  1088. };
  1089. this.onResize = function() { // OBSOLETE - for compatibilty
  1090. return self.each(function(){
  1091. this.onResize();
  1092. });
  1093. };
  1094. this.resize = function() {
  1095. return self.each(function(){
  1096. this.resize();
  1097. });
  1098. };
  1099. this.remove = function() {
  1100. return self.each(function(){
  1101. this.remove();
  1102. });
  1103. };
  1104. this.stop = function() {
  1105. return self.each(function(){
  1106. this.stop();
  1107. });
  1108. };
  1109. this.push = function(nice) {
  1110. self[self.length]=nice;
  1111. self.length++;
  1112. };
  1113. this.eq = function(idx) {
  1114. return self[idx];
  1115. };
  1116. if (doms) {
  1117. for(a=0;a<doms.length;a++) {
  1118. var nice = $.data(doms[a],'__nicescroll')||false;
  1119. if (nice) {
  1120. this[this.length]=nice;
  1121. this.length++;
  1122. }
  1123. };
  1124. }
  1125. return this;
  1126. };
  1127. jQuery.fn.getNiceScroll = function(index) {
  1128. if (typeof index == "undefined") {
  1129. return (this.length>0) ? new NiceScrollArray(this) : $.data(this,'__nicescroll')||false;
  1130. } else {
  1131. var nice = $.data(this[index],'__nicescroll')||false;
  1132. return nice;
  1133. }
  1134. };
  1135. jQuery.extend(jQuery.expr[':'], {
  1136. nicescroll: function(a) {
  1137. return ($.data(a,'__nicescroll')||false);
  1138. }
  1139. });
  1140. $.fn.niceScroll = function(wrapper,opt) {
  1141. if ((typeof wrapper=="object") && (typeof opt=="undefined")) {
  1142. opt = wrapper;
  1143. wrapper = false;
  1144. }
  1145. var ret = new NiceScrollArray();
  1146. if (typeof opt=="undefined") opt = {};
  1147. if (wrapper||false) {
  1148. opt.doc = $(wrapper);
  1149. opt.win = $(this);
  1150. }
  1151. var docundef = !("doc" in opt);
  1152. this.each(function() {
  1153. var nice = $(this).data('__nicescroll')||false;
  1154. if (!nice) {
  1155. opt.doc = (docundef) ? $(this) : opt.doc;
  1156. nice = new NiceScrollClass(opt,$(this));
  1157. $(this).data('__nicescroll',nice);
  1158. }
  1159. ret.push(nice);
  1160. });
  1161. return (ret.length==1) ? ret[0] : ret;
  1162. };
  1163. })( jQuery );