jquery.nicescroll.js 102 KB

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