jquery.nicescroll.js 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734
  1. /* jquery.nicescroll
  2. -- version 3.6.7
  3. -- copyright 2016-02-08 InuYaksa*2016
  4. -- licensed under the MIT
  5. --
  6. -- http://nicescroll.areaaperta.com/
  7. -- https://github.com/inuyaksa/jquery.nicescroll
  8. --
  9. */
  10. (function(factory) {
  11. if (typeof define === 'function' && define.amd) {
  12. // AMD. Register as anonymous module.
  13. define(['jquery'], factory);
  14. } else if (typeof exports === 'object') {
  15. // Node/CommonJS.
  16. module.exports = factory(require('jquery'));
  17. } else {
  18. // Browser globals.
  19. factory(jQuery);
  20. }
  21. }(function(jQuery) {
  22. "use strict";
  23. // globals
  24. var domfocus = false;
  25. var mousefocus = false;
  26. var tabindexcounter = 0;
  27. var ascrailcounter = 2000;
  28. var globalmaxzindex = 0;
  29. var $ = jQuery; // sandbox
  30. // http://stackoverflow.com/questions/2161159/get-script-path
  31. function getScriptPath() {
  32. var scripts = document.getElementsByTagName('script');
  33. var path = scripts.length ? scripts[scripts.length - 1].src.split('?')[0] : '';
  34. return (path.split('/').length > 0) ? path.split('/').slice(0, -1).join('/') + '/' : '';
  35. }
  36. var vendors = ['webkit','ms','moz','o'];
  37. var setAnimationFrame = window.requestAnimationFrame || false;
  38. var clearAnimationFrame = window.cancelAnimationFrame || false;
  39. if (!setAnimationFrame) { // legacy detection
  40. for (var vx in vendors) {
  41. var v = vendors[vx];
  42. setAnimationFrame = window[v + 'RequestAnimationFrame'];
  43. if (setAnimationFrame) {
  44. clearAnimationFrame = window[v + 'CancelAnimationFrame'] || window[v + 'CancelRequestAnimationFrame'];
  45. break;
  46. }
  47. }
  48. }
  49. var ClsMutationObserver = window.MutationObserver || window.WebKitMutationObserver || false;
  50. var _globaloptions = {
  51. zindex: "auto",
  52. cursoropacitymin: 0,
  53. cursoropacitymax: 1,
  54. cursorcolor: "#424242",
  55. cursorwidth: "6px",
  56. cursorborder: "1px solid #fff",
  57. cursorborderradius: "5px",
  58. scrollspeed: 60,
  59. mousescrollstep: 8 * 3,
  60. touchbehavior: false,
  61. hwacceleration: true,
  62. usetransition: true,
  63. boxzoom: false,
  64. dblclickzoom: true,
  65. gesturezoom: true,
  66. grabcursorenabled: true,
  67. autohidemode: true,
  68. background: "",
  69. iframeautoresize: true,
  70. cursorminheight: 32,
  71. preservenativescrolling: true,
  72. railoffset: false,
  73. railhoffset: false,
  74. bouncescroll: true,
  75. spacebarenabled: true,
  76. railpadding: {
  77. top: 0,
  78. right: 0,
  79. left: 0,
  80. bottom: 0
  81. },
  82. disableoutline: true,
  83. horizrailenabled: true,
  84. railalign: "right",
  85. railvalign: "bottom",
  86. enabletranslate3d: true,
  87. enablemousewheel: true,
  88. enablekeyboard: true,
  89. smoothscroll: true,
  90. sensitiverail: true,
  91. enablemouselockapi: true,
  92. // cursormaxheight:false,
  93. cursorfixedheight: false,
  94. directionlockdeadzone: 6,
  95. hidecursordelay: 400,
  96. nativeparentscrolling: true,
  97. enablescrollonselection: true,
  98. overflowx: true,
  99. overflowy: true,
  100. cursordragspeed: 0.3,
  101. rtlmode: "auto",
  102. cursordragontouch: false,
  103. oneaxismousemode: "auto",
  104. scriptpath: getScriptPath(),
  105. preventmultitouchscrolling: true
  106. };
  107. var browserdetected = false;
  108. var getBrowserDetection = function() {
  109. if (browserdetected) return browserdetected;
  110. var _el = document.createElement('DIV'),
  111. _style = _el.style,
  112. _agent = navigator.userAgent,
  113. _platform = navigator.platform,
  114. d = {};
  115. d.haspointerlock = "pointerLockElement" in document || "webkitPointerLockElement" in document || "mozPointerLockElement" in document;
  116. d.isopera = ("opera" in window); // 12-
  117. d.isopera12 = (d.isopera && ("getUserMedia" in navigator));
  118. d.isoperamini = (Object.prototype.toString.call(window.operamini) === "[object OperaMini]");
  119. d.isie = (("all" in document) && ("attachEvent" in _el) && !d.isopera); //IE10-
  120. d.isieold = (d.isie && !("msInterpolationMode" in _style)); // IE6 and older
  121. d.isie7 = d.isie && !d.isieold && (!("documentMode" in document) || (document.documentMode == 7));
  122. d.isie8 = d.isie && ("documentMode" in document) && (document.documentMode == 8);
  123. d.isie9 = d.isie && ("performance" in window) && (document.documentMode == 9);
  124. d.isie10 = d.isie && ("performance" in window) && (document.documentMode == 10);
  125. d.isie11 = ("msRequestFullscreen" in _el) && (document.documentMode >= 11); // IE11+
  126. d.isieedge = (navigator.userAgent.match(/Edge\/12\./)); // IE Edge 12
  127. d.isie9mobile = /iemobile.9/i.test(_agent); //wp 7.1 mango
  128. if (d.isie9mobile) d.isie9 = false;
  129. d.isie7mobile = (!d.isie9mobile && d.isie7) && /iemobile/i.test(_agent); //wp 7.0
  130. d.ismozilla = ("MozAppearance" in _style);
  131. d.iswebkit = ("WebkitAppearance" in _style);
  132. d.ischrome = ("chrome" in window);
  133. d.ischrome38 = (d.ischrome && ("touchAction" in _style)); // behavior changed in touch emulation
  134. d.ischrome22 = (!d.ischrome38)&&(d.ischrome && d.haspointerlock);
  135. d.ischrome26 = (!d.ischrome38)&&(d.ischrome && ("transition" in _style)); // issue with transform detection (maintain prefix)
  136. d.cantouch = ("ontouchstart" in document.documentElement) || ("ontouchstart" in window); // with detection for Chrome Touch Emulation
  137. d.hasw3ctouch = (window.PointerEvent || false) && ((navigator.MaxTouchPoints > 0)||(navigator.msMaxTouchPoints > 0)); //IE11 pointer events, following W3C Pointer Events spec
  138. d.hasmstouch = (!d.hasw3ctouch)&&(window.MSPointerEvent || false); // IE10 pointer events
  139. d.ismac = /^mac$/i.test(_platform);
  140. d.isios = (d.cantouch && /iphone|ipad|ipod/i.test(_platform));
  141. d.isios4 = ((d.isios) && !("seal" in Object));
  142. d.isios7 = ((d.isios)&&("webkitHidden" in document)); //iOS 7+
  143. d.isios8 = ((d.isios)&&("hidden" in document)); //iOS 8+
  144. d.isandroid = (/android/i.test(_agent));
  145. d.haseventlistener = ("addEventListener" in _el);
  146. d.trstyle = false;
  147. d.hastransform = false;
  148. d.hastranslate3d = false;
  149. d.transitionstyle = false;
  150. d.hastransition = false;
  151. d.transitionend = false;
  152. var a;
  153. var check = ['transform', 'msTransform', 'webkitTransform', 'MozTransform', 'OTransform'];
  154. for (a = 0; a < check.length; a++) {
  155. if (typeof _style[check[a]] != "undefined") {
  156. d.trstyle = check[a];
  157. break;
  158. }
  159. }
  160. d.hastransform = (!!d.trstyle);
  161. if (d.hastransform) {
  162. _style[d.trstyle] = "translate3d(1px,2px,3px)";
  163. d.hastranslate3d = /translate3d/.test(_style[d.trstyle]);
  164. }
  165. d.transitionstyle = false;
  166. d.prefixstyle = '';
  167. d.transitionend = false;
  168. check = ['transition', 'webkitTransition', 'msTransition', 'MozTransition', 'OTransition', 'OTransition', 'KhtmlTransition'];
  169. var prefix = ['', '-webkit-', '-ms-', '-moz-', '-o-', '-o', '-khtml-'];
  170. var evs = ['transitionend', 'webkitTransitionEnd', 'msTransitionEnd', 'transitionend', 'otransitionend', 'oTransitionEnd', 'KhtmlTransitionEnd'];
  171. for (a = 0; a < check.length; a++) {
  172. if (check[a] in _style) {
  173. d.transitionstyle = check[a];
  174. d.prefixstyle = prefix[a];
  175. d.transitionend = evs[a];
  176. break;
  177. }
  178. }
  179. if (d.ischrome26) { // always use prefix
  180. d.prefixstyle = prefix[1];
  181. }
  182. d.hastransition = (d.transitionstyle);
  183. function detectCursorGrab() {
  184. var lst = ['grab','-webkit-grab', '-moz-grab'];
  185. if ((d.ischrome && !d.ischrome38) || d.isie) lst = []; // force setting for IE returns false positive and chrome cursor bug
  186. for (var a = 0; a < lst.length; a++) {
  187. var p = lst[a];
  188. _style.cursor = p;
  189. if (_style.cursor == p) return p;
  190. }
  191. return 'url(//patriciaportfolio.googlecode.com/files/openhand.cur),n-resize'; // thank you google for custom cursor!
  192. }
  193. d.cursorgrabvalue = detectCursorGrab();
  194. d.hasmousecapture = ("setCapture" in _el);
  195. d.hasMutationObserver = (ClsMutationObserver !== false);
  196. _el = null; //memory released
  197. browserdetected = d;
  198. return d;
  199. };
  200. var NiceScrollClass = function(myopt, me) {
  201. var self = this;
  202. this.version = '3.6.7';
  203. this.name = 'nicescroll';
  204. this.me = me;
  205. this.opt = {
  206. doc: $("body"),
  207. win: false
  208. };
  209. $.extend(this.opt, _globaloptions); // clone opts
  210. // Options for internal use
  211. this.opt.snapbackspeed = 80;
  212. if (myopt || false) {
  213. for (var a in self.opt) {
  214. if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
  215. }
  216. }
  217. this.doc = self.opt.doc;
  218. this.iddoc = (this.doc && this.doc[0]) ? this.doc[0].id || '' : '';
  219. this.ispage = /^BODY|HTML/.test((self.opt.win) ? self.opt.win[0].nodeName : this.doc[0].nodeName);
  220. this.haswrapper = (self.opt.win !== false);
  221. this.win = self.opt.win || (this.ispage ? $(window) : this.doc);
  222. this.docscroll = (this.ispage && !this.haswrapper) ? $(window) : this.win;
  223. this.body = $("body");
  224. this.viewport = false;
  225. this.isfixed = false;
  226. this.iframe = false;
  227. this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
  228. this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
  229. this.forcescreen = false; //force to use screen position on events
  230. this.canshowonmouseevent = (self.opt.autohidemode != "scroll");
  231. // Events jump table
  232. this.onmousedown = false;
  233. this.onmouseup = false;
  234. this.onmousemove = false;
  235. this.onmousewheel = false;
  236. this.onkeypress = false;
  237. this.ongesturezoom = false;
  238. this.onclick = false;
  239. // Nicescroll custom events
  240. this.onscrollstart = false;
  241. this.onscrollend = false;
  242. this.onscrollcancel = false;
  243. this.onzoomin = false;
  244. this.onzoomout = false;
  245. // Let's start!
  246. this.view = false;
  247. this.page = false;
  248. this.scroll = {
  249. x: 0,
  250. y: 0
  251. };
  252. this.scrollratio = {
  253. x: 0,
  254. y: 0
  255. };
  256. this.cursorheight = 20;
  257. this.scrollvaluemax = 0;
  258. // http://dev.w3.org/csswg/css-writing-modes-3/#logical-to-physical
  259. // http://dev.w3.org/csswg/css-writing-modes-3/#svg-writing-mode
  260. if (this.opt.rtlmode == "auto") {
  261. var target = this.win[0] == window ? this.body : this.win;
  262. var writingMode = target.css("writing-mode") || target.css("-webkit-writing-mode") || target.css("-ms-writing-mode") || target.css("-moz-writing-mode");
  263. if (writingMode == "horizontal-tb" || writingMode == "lr-tb" || writingMode == "") {
  264. this.isrtlmode = (target.css("direction") == "rtl");
  265. this.isvertical = false;
  266. } else {
  267. this.isrtlmode = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl" || writingMode == "rl-tb");
  268. this.isvertical = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl");
  269. }
  270. } else {
  271. this.isrtlmode = (this.opt.rtlmode === true);
  272. this.isvertical = false;
  273. }
  274. // this.checkrtlmode = false;
  275. this.scrollrunning = false;
  276. this.scrollmom = false;
  277. this.observer = false; // observer div changes
  278. this.observerremover = false; // observer on parent for remove detection
  279. this.observerbody = false; // observer on body for position change
  280. do {
  281. this.id = "ascrail" + (ascrailcounter++);
  282. } while (document.getElementById(this.id));
  283. this.rail = false;
  284. this.cursor = false;
  285. this.cursorfreezed = false;
  286. this.selectiondrag = false;
  287. this.zoom = false;
  288. this.zoomactive = false;
  289. this.hasfocus = false;
  290. this.hasmousefocus = false;
  291. this.visibility = true;
  292. this.railslocked = false; // locked by resize
  293. this.locked = false; // prevent lost of locked status sets by user
  294. this.hidden = false; // rails always hidden
  295. this.cursoractive = true; // user can interact with cursors
  296. this.wheelprevented = false; //prevent mousewheel event
  297. this.overflowx = self.opt.overflowx;
  298. this.overflowy = self.opt.overflowy;
  299. this.nativescrollingarea = false;
  300. this.checkarea = 0;
  301. this.events = []; // event list for unbind
  302. this.saved = {}; // style saved
  303. this.delaylist = {};
  304. this.synclist = {};
  305. this.lastdeltax = 0;
  306. this.lastdeltay = 0;
  307. this.detected = getBrowserDetection();
  308. var cap = $.extend({}, this.detected);
  309. this.canhwscroll = (cap.hastransform && self.opt.hwacceleration);
  310. this.ishwscroll = (this.canhwscroll && self.haswrapper);
  311. if (this.isrtlmode) {
  312. //RTL mode with reverse horizontal axis
  313. if (this.isvertical) {
  314. this.hasreversehr = !(cap.iswebkit || cap.isie || cap.isie11);
  315. } else {
  316. this.hasreversehr = !(cap.iswebkit || (cap.isie && !cap.isie10 && !cap.isie11));
  317. }
  318. } else {
  319. this.hasreversehr = false;
  320. }
  321. this.istouchcapable = false; // desktop devices with touch screen support
  322. //## Check WebKit-based desktop with touch support
  323. //## + Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
  324. if (!cap.cantouch && (cap.hasw3ctouch||cap.hasmstouch)) { // desktop device with multiple input
  325. this.istouchcapable = true;
  326. } else if (cap.cantouch && !cap.isios && !cap.isandroid && (cap.iswebkit || cap.ismozilla)) {
  327. this.istouchcapable = true;
  328. // cap.cantouch = false; // parse normal desktop events
  329. }
  330. //## disable MouseLock API on user request
  331. if (!self.opt.enablemouselockapi) {
  332. cap.hasmousecapture = false;
  333. cap.haspointerlock = false;
  334. }
  335. /* deprecated
  336. this.delayed = function(name, fn, tm, lazy) {
  337. };
  338. */
  339. /*
  340. this.debounced = function(name, fn, tm) {
  341. if (!self) return;
  342. var dd = self.delaylist[name];
  343. self.delaylist[name] = fn;
  344. if (!dd) {
  345. self.debouncedelayed = setTimeout(function() {
  346. if (!self) return;
  347. var fn = self.delaylist[name];
  348. self.delaylist[name] = false;
  349. fn.call(self);
  350. }, tm);
  351. }
  352. };
  353. */
  354. this.debounced = function(name, fn, tm) {
  355. if (!self) return;
  356. var dd = self.delaylist[name]||false;
  357. if (!dd) {
  358. fn.call(self);
  359. self.delaylist[name] = {
  360. h:setAnimationFrame(function(){
  361. self.delaylist[name].fn.call(self);
  362. self.delaylist[name] = false;
  363. },tm)
  364. };
  365. }
  366. self.delaylist[name].fn = fn;
  367. };
  368. var _onsync = false;
  369. this.synched = function(name, fn) {
  370. function requestSync() {
  371. if (_onsync) return;
  372. setAnimationFrame(function() {
  373. if (!self) return;
  374. _onsync = false;
  375. for (var nn in self.synclist) {
  376. var fn = self.synclist[nn];
  377. if (fn) fn.call(self);
  378. self.synclist[nn] = false;
  379. }
  380. });
  381. _onsync = true;
  382. }
  383. self.synclist[name] = fn;
  384. requestSync();
  385. return name;
  386. };
  387. this.unsynched = function(name) {
  388. if (self.synclist[name]) self.synclist[name] = false;
  389. };
  390. this.css = function(el, pars) { // save & set
  391. for (var n in pars) {
  392. self.saved.css.push([el, n, el.css(n)]);
  393. el.css(n, pars[n]);
  394. }
  395. };
  396. this.scrollTop = function(val) {
  397. return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
  398. };
  399. this.scrollLeft = function(val) {
  400. return (typeof val == "undefined") ? self.getScrollLeft() : self.setScrollLeft(val);
  401. };
  402. // derived by by Dan Pupius www.pupius.net
  403. var BezierClass = function(st, ed, spd, p1, p2, p3, p4) {
  404. this.st = st;
  405. this.ed = ed;
  406. this.spd = spd;
  407. this.p1 = p1 || 0;
  408. this.p2 = p2 || 1;
  409. this.p3 = p3 || 0;
  410. this.p4 = p4 || 1;
  411. this.ts = (new Date()).getTime();
  412. this.df = this.ed - this.st;
  413. };
  414. BezierClass.prototype = {
  415. B2: function(t) {
  416. return 3 * t * t * (1 - t);
  417. },
  418. B3: function(t) {
  419. return 3 * t * (1 - t) * (1 - t);
  420. },
  421. B4: function(t) {
  422. return (1 - t) * (1 - t) * (1 - t);
  423. },
  424. getNow: function() {
  425. var nw = (new Date()).getTime();
  426. var pc = 1 - ((nw - this.ts) / this.spd);
  427. var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
  428. return (pc < 0) ? this.ed : this.st + Math.round(this.df * bz);
  429. },
  430. update: function(ed, spd) {
  431. this.st = this.getNow();
  432. this.ed = ed;
  433. this.spd = spd;
  434. this.ts = (new Date()).getTime();
  435. this.df = this.ed - this.st;
  436. return this;
  437. }
  438. };
  439. //derived from http://stackoverflow.com/questions/11236090/
  440. function getMatrixValues() {
  441. var tr = self.doc.css(cap.trstyle);
  442. if (tr && (tr.substr(0, 6) == "matrix")) {
  443. return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g, '').split(/, +/);
  444. }
  445. return false;
  446. }
  447. if (this.ishwscroll) {
  448. // hw accelerated scroll
  449. this.doc.translate = {
  450. x: 0,
  451. y: 0,
  452. tx: "0px",
  453. ty: "0px"
  454. };
  455. //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
  456. if (cap.hastranslate3d && cap.isios) this.doc.css("-webkit-backface-visibility", "hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/
  457. this.getScrollTop = function(last) {
  458. if (!last) {
  459. var mtx = getMatrixValues();
  460. if (mtx) return (mtx.length == 16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
  461. if (self.timerscroll && self.timerscroll.bz) return self.timerscroll.bz.getNow();
  462. }
  463. return self.doc.translate.y;
  464. };
  465. this.getScrollLeft = function(last) {
  466. if (!last) {
  467. var mtx = getMatrixValues();
  468. if (mtx) return (mtx.length == 16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
  469. if (self.timerscroll && self.timerscroll.bh) return self.timerscroll.bh.getNow();
  470. }
  471. return self.doc.translate.x;
  472. };
  473. this.notifyScrollEvent = function(el) {
  474. var e = document.createEvent("UIEvents");
  475. e.initUIEvent("scroll", false, true, window, 1);
  476. e.niceevent = true;
  477. el.dispatchEvent(e);
  478. };
  479. var cxscrollleft = (this.isrtlmode) ? 1 : -1;
  480. if (cap.hastranslate3d && self.opt.enabletranslate3d) {
  481. this.setScrollTop = function(val, silent) {
  482. self.doc.translate.y = val;
  483. self.doc.translate.ty = (val * -1) + "px";
  484. self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0px)");
  485. if (!silent) self.notifyScrollEvent(self.win[0]);
  486. };
  487. this.setScrollLeft = function(val, silent) {
  488. self.doc.translate.x = val;
  489. self.doc.translate.tx = (val * cxscrollleft) + "px";
  490. self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0px)");
  491. if (!silent) self.notifyScrollEvent(self.win[0]);
  492. };
  493. } else {
  494. this.setScrollTop = function(val, silent) {
  495. self.doc.translate.y = val;
  496. self.doc.translate.ty = (val * -1) + "px";
  497. self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
  498. if (!silent) self.notifyScrollEvent(self.win[0]);
  499. };
  500. this.setScrollLeft = function(val, silent) {
  501. self.doc.translate.x = val;
  502. self.doc.translate.tx = (val * cxscrollleft) + "px";
  503. self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
  504. if (!silent) self.notifyScrollEvent(self.win[0]);
  505. };
  506. }
  507. } else {
  508. // native scroll
  509. this.getScrollTop = function() {
  510. return self.docscroll.scrollTop();
  511. };
  512. this.setScrollTop = function(val) {
  513. return setTimeout(function() {(self)&&self.docscroll.scrollTop(val)}, 1);
  514. };
  515. this.getScrollLeft = function() {
  516. var val;
  517. if (self.hasreversehr) {
  518. if (self.detected.ismozilla) {
  519. val = self.page.maxw - Math.abs(self.docscroll.scrollLeft());
  520. } else {
  521. val = self.page.maxw - self.docscroll.scrollLeft();
  522. }
  523. } else {
  524. val = self.docscroll.scrollLeft();
  525. }
  526. return val;
  527. };
  528. this.setScrollLeft = function(val) {
  529. return setTimeout(function() {
  530. if (!self) return;
  531. if (self.hasreversehr) {
  532. if (self.detected.ismozilla) {
  533. val = -(self.page.maxw - val);
  534. } else {
  535. val = self.page.maxw - val;
  536. }
  537. }
  538. return self.docscroll.scrollLeft(val);
  539. }, 1);
  540. };
  541. }
  542. this.getTarget = function(e) {
  543. if (!e) return false;
  544. if (e.target) return e.target;
  545. if (e.srcElement) return e.srcElement;
  546. return false;
  547. };
  548. this.hasParent = function(e, id) {
  549. if (!e) return false;
  550. var el = e.target || e.srcElement || e || false;
  551. while (el && el.id != id) {
  552. el = el.parentNode || false;
  553. }
  554. return (el !== false);
  555. };
  556. function getZIndex() {
  557. var dom = self.win;
  558. if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
  559. while (dom.length > 0) {
  560. if (dom[0].nodeType == 9) return false;
  561. var zi = dom.css('zIndex');
  562. if (!isNaN(zi) && zi != 0) return parseInt(zi);
  563. dom = dom.parent();
  564. }
  565. return false;
  566. }
  567. //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
  568. var _convertBorderWidth = {
  569. "thin": 1,
  570. "medium": 3,
  571. "thick": 5
  572. };
  573. function getWidthToPixel(dom, prop, chkheight) {
  574. var wd = dom.css(prop);
  575. var px = parseFloat(wd);
  576. if (isNaN(px)) {
  577. px = _convertBorderWidth[wd] || 0;
  578. var brd = (px == 3) ? ((chkheight) ? (self.win.outerHeight() - self.win.innerHeight()) : (self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
  579. if (self.isie8 && px) px += 1;
  580. return (brd) ? px : 0;
  581. }
  582. return px;
  583. }
  584. this.getDocumentScrollOffset = function() {
  585. return {top:window.pageYOffset||document.documentElement.scrollTop,
  586. left:window.pageXOffset||document.documentElement.scrollLeft};
  587. }
  588. this.getOffset = function() {
  589. if (self.isfixed) {
  590. var ofs = self.win.offset(); // fix Chrome auto issue (when right/bottom props only)
  591. var scrl = self.getDocumentScrollOffset();
  592. ofs.top-=scrl.top;
  593. ofs.left-=scrl.left;
  594. return ofs;
  595. }
  596. var ww = self.win.offset();
  597. if (!self.viewport) return ww;
  598. var vp = self.viewport.offset();
  599. return {
  600. top: ww.top - vp.top,// + self.viewport.scrollTop(),
  601. left: ww.left - vp.left // + self.viewport.scrollLeft()
  602. };
  603. };
  604. this.updateScrollBar = function(len) {
  605. if (self.ishwscroll) {
  606. self.rail.css({ //**
  607. height: self.win.innerHeight() - (self.opt.railpadding.top + self.opt.railpadding.bottom)
  608. });
  609. if (self.railh) self.railh.css({ //**
  610. width: self.win.innerWidth() - (self.opt.railpadding.left + self.opt.railpadding.right)
  611. });
  612. } else {
  613. var wpos = self.getOffset();
  614. var pos = {
  615. top: wpos.top,
  616. left: wpos.left - (self.opt.railpadding.left + self.opt.railpadding.right)
  617. };
  618. pos.top += getWidthToPixel(self.win, 'border-top-width', true);
  619. pos.left += (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win, 'border-right-width') - self.rail.width : getWidthToPixel(self.win, 'border-left-width');
  620. var off = self.opt.railoffset;
  621. if (off) {
  622. if (off.top) pos.top += off.top;
  623. if (off.left) pos.left += off.left;
  624. }
  625. if (!self.railslocked) self.rail.css({
  626. top: pos.top,
  627. left: pos.left,
  628. height: ((len) ? len.h : self.win.innerHeight()) - (self.opt.railpadding.top + self.opt.railpadding.bottom)
  629. });
  630. if (self.zoom) {
  631. self.zoom.css({
  632. top: pos.top + 1,
  633. left: (self.rail.align == 1) ? pos.left - 20 : pos.left + self.rail.width + 4
  634. });
  635. }
  636. if (self.railh && !self.railslocked) {
  637. var pos = {
  638. top: wpos.top,
  639. left: wpos.left
  640. };
  641. var off = self.opt.railhoffset;
  642. if (!!off) {
  643. if (!!off.top) pos.top += off.top;
  644. if (!!off.left) pos.left += off.left;
  645. }
  646. 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);
  647. var x = pos.left + getWidthToPixel(self.win, 'border-left-width');
  648. self.railh.css({
  649. top: y - (self.opt.railpadding.top + self.opt.railpadding.bottom),
  650. left: x,
  651. width: self.railh.width
  652. });
  653. }
  654. }
  655. };
  656. this.doRailClick = function(e, dbl, hr) {
  657. var fn, pg, cur, pos;
  658. if (self.railslocked) return;
  659. self.cancelEvent(e);
  660. if (dbl) {
  661. fn = (hr) ? self.doScrollLeft : self.doScrollTop;
  662. 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);
  663. fn(cur);
  664. } else {
  665. fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
  666. cur = (hr) ? self.scroll.x : self.scroll.y;
  667. pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
  668. pg = (hr) ? self.view.w : self.view.h;
  669. fn((cur >= pos) ? pg: -pg);// (cur >= pos) ? fn(pg): fn(-pg);
  670. }
  671. };
  672. self.hasanimationframe = (setAnimationFrame);
  673. self.hascancelanimationframe = (clearAnimationFrame);
  674. if (!self.hasanimationframe) {
  675. setAnimationFrame = function(fn) {
  676. return setTimeout(fn, 15 - Math.floor((+new Date()) / 1000) % 16);
  677. }; // 1000/60)};
  678. clearAnimationFrame = clearTimeout;
  679. } else if (!self.hascancelanimationframe) clearAnimationFrame = function() {
  680. self.cancelAnimationFrame = true;
  681. };
  682. this.init = function() {
  683. self.saved.css = [];
  684. if (cap.isie7mobile) return true; // SORRY, DO NOT WORK!
  685. if (cap.isoperamini) return true; // SORRY, DO NOT WORK!
  686. if (cap.hasmstouch) self.css((self.ispage) ? $("html") : self.win, {
  687. '-ms-touch-action': 'none'
  688. });
  689. self.zindex = "auto";
  690. if (!self.ispage && self.opt.zindex == "auto") {
  691. self.zindex = getZIndex() || "auto";
  692. } else {
  693. self.zindex = self.opt.zindex;
  694. }
  695. if (!self.ispage && self.zindex != "auto") {
  696. if (self.zindex > globalmaxzindex) globalmaxzindex = self.zindex;
  697. }
  698. if (self.isie && self.zindex == 0 && self.opt.zindex == "auto") { // fix IE auto == 0
  699. self.zindex = "auto";
  700. }
  701. if (!self.ispage || (!cap.cantouch && !cap.isieold && !cap.isie9mobile)) {
  702. var cont = self.docscroll;
  703. if (self.ispage) cont = (self.haswrapper) ? self.win : self.doc;
  704. if (!cap.isie9mobile) self.css(cont, {
  705. 'overflow-y': 'hidden'
  706. });
  707. if (self.ispage && cap.isie7) {
  708. if (self.doc[0].nodeName == 'BODY') self.css($("html"), {
  709. 'overflow-y': 'hidden'
  710. }); //IE7 double scrollbar issue
  711. else if (self.doc[0].nodeName == 'HTML') self.css($("body"), {
  712. 'overflow-y': 'hidden'
  713. }); //IE7 double scrollbar issue
  714. }
  715. if (cap.isios && !self.ispage && !self.haswrapper) self.css($("body"), {
  716. "-webkit-overflow-scrolling": "touch"
  717. }); //force hw acceleration
  718. var cursor = $(document.createElement('div'));
  719. cursor.css({
  720. position: "relative",
  721. top: 0,
  722. "float": "right",
  723. width: self.opt.cursorwidth,
  724. height: "0px",
  725. 'background-color': self.opt.cursorcolor,
  726. border: self.opt.cursorborder,
  727. 'background-clip': 'padding-box',
  728. '-webkit-border-radius': self.opt.cursorborderradius,
  729. '-moz-border-radius': self.opt.cursorborderradius,
  730. 'border-radius': self.opt.cursorborderradius
  731. });
  732. cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
  733. cursor.addClass('nicescroll-cursors');
  734. self.cursor = cursor;
  735. var rail = $(document.createElement('div'));
  736. rail.attr('id', self.id);
  737. rail.addClass('nicescroll-rails nicescroll-rails-vr');
  738. var v, a, kp = ["left","right","top","bottom"]; //**
  739. for (var n in kp) {
  740. a = kp[n];
  741. v = self.opt.railpadding[a];
  742. (v) ? rail.css("padding-"+a,v+"px") : self.opt.railpadding[a] = 0;
  743. }
  744. rail.append(cursor);
  745. rail.width = Math.max(parseFloat(self.opt.cursorwidth), cursor.outerWidth());
  746. rail.css({
  747. width: rail.width + "px",
  748. 'zIndex': self.zindex,
  749. "background": self.opt.background,
  750. cursor: "default"
  751. });
  752. rail.visibility = true;
  753. rail.scrollable = true;
  754. rail.align = (self.opt.railalign == "left") ? 0 : 1;
  755. self.rail = rail;
  756. self.rail.drag = false;
  757. var zoom = false;
  758. if (self.opt.boxzoom && !self.ispage && !cap.isieold) {
  759. zoom = document.createElement('div');
  760. self.bind(zoom, "click", self.doZoom);
  761. self.bind(zoom, "mouseenter", function() {
  762. self.zoom.css('opacity', self.opt.cursoropacitymax);
  763. });
  764. self.bind(zoom, "mouseleave", function() {
  765. self.zoom.css('opacity', self.opt.cursoropacitymin);
  766. });
  767. self.zoom = $(zoom);
  768. self.zoom.css({
  769. "cursor": "pointer",
  770. 'z-index': self.zindex,
  771. 'backgroundImage': 'url(' + self.opt.scriptpath + 'zoomico.png)',
  772. 'height': 18,
  773. 'width': 18,
  774. 'backgroundPosition': '0px 0px'
  775. });
  776. if (self.opt.dblclickzoom) self.bind(self.win, "dblclick", self.doZoom);
  777. if (cap.cantouch && self.opt.gesturezoom) {
  778. self.ongesturezoom = function(e) {
  779. if (e.scale > 1.5) self.doZoomIn(e);
  780. if (e.scale < 0.8) self.doZoomOut(e);
  781. return self.cancelEvent(e);
  782. };
  783. self.bind(self.win, "gestureend", self.ongesturezoom);
  784. }
  785. }
  786. // init HORIZ
  787. self.railh = false;
  788. var railh;
  789. if (self.opt.horizrailenabled) {
  790. self.css(cont, {
  791. 'overflow-x': 'hidden'
  792. });
  793. var cursor = $(document.createElement('div'));
  794. cursor.css({
  795. position: "absolute",
  796. top: 0,
  797. height: self.opt.cursorwidth,
  798. width: "0px",
  799. 'background-color': self.opt.cursorcolor,
  800. border: self.opt.cursorborder,
  801. 'background-clip': 'padding-box',
  802. '-webkit-border-radius': self.opt.cursorborderradius,
  803. '-moz-border-radius': self.opt.cursorborderradius,
  804. 'border-radius': self.opt.cursorborderradius
  805. });
  806. if (cap.isieold) cursor.css({'overflow':'hidden'}); //IE6 horiz scrollbar issue
  807. cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth());
  808. cursor.addClass('nicescroll-cursors');
  809. self.cursorh = cursor;
  810. railh = $(document.createElement('div'));
  811. railh.attr('id', self.id + '-hr');
  812. railh.addClass('nicescroll-rails nicescroll-rails-hr');
  813. railh.height = Math.max(parseFloat(self.opt.cursorwidth), cursor.outerHeight());
  814. railh.css({
  815. height: railh.height + "px",
  816. 'zIndex': self.zindex,
  817. "background": self.opt.background
  818. });
  819. railh.append(cursor);
  820. railh.visibility = true;
  821. railh.scrollable = true;
  822. railh.align = (self.opt.railvalign == "top") ? 0 : 1;
  823. self.railh = railh;
  824. self.railh.drag = false;
  825. }
  826. //
  827. if (self.ispage) {
  828. rail.css({
  829. position: "fixed",
  830. top: "0px",
  831. height: "100%"
  832. });
  833. (rail.align) ? rail.css({
  834. right: "0px"
  835. }): rail.css({
  836. left: "0px"
  837. });
  838. self.body.append(rail);
  839. if (self.railh) {
  840. railh.css({
  841. position: "fixed",
  842. left: "0px",
  843. width: "100%"
  844. });
  845. (railh.align) ? railh.css({
  846. bottom: "0px"
  847. }): railh.css({
  848. top: "0px"
  849. });
  850. self.body.append(railh);
  851. }
  852. } else {
  853. if (self.ishwscroll) {
  854. if (self.win.css('position') == 'static') self.css(self.win, {
  855. 'position': 'relative'
  856. });
  857. var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
  858. $(bd).scrollTop(0).scrollLeft(0); // fix rail position if content already scrolled
  859. if (self.zoom) {
  860. self.zoom.css({
  861. position: "absolute",
  862. top: 1,
  863. right: 0,
  864. "margin-right": rail.width + 4
  865. });
  866. bd.append(self.zoom);
  867. }
  868. rail.css({
  869. position: "absolute",
  870. top: 0
  871. });
  872. (rail.align) ? rail.css({
  873. right: 0
  874. }): rail.css({
  875. left: 0
  876. });
  877. bd.append(rail);
  878. if (railh) {
  879. railh.css({
  880. position: "absolute",
  881. left: 0,
  882. bottom: 0
  883. });
  884. (railh.align) ? railh.css({
  885. bottom: 0
  886. }): railh.css({
  887. top: 0
  888. });
  889. bd.append(railh);
  890. }
  891. } else {
  892. self.isfixed = (self.win.css("position") == "fixed");
  893. var rlpos = (self.isfixed) ? "fixed" : "absolute";
  894. if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
  895. if (self.viewport) {
  896. self.body = self.viewport;
  897. if ((/fixed|absolute/.test(self.viewport.css("position"))) == false) self.css(self.viewport, {
  898. "position": "relative"
  899. });
  900. }
  901. rail.css({
  902. position: rlpos
  903. });
  904. if (self.zoom) self.zoom.css({
  905. position: rlpos
  906. });
  907. self.updateScrollBar();
  908. self.body.append(rail);
  909. if (self.zoom) self.body.append(self.zoom);
  910. if (self.railh) {
  911. railh.css({
  912. position: rlpos
  913. });
  914. self.body.append(railh);
  915. }
  916. }
  917. if (cap.isios) self.css(self.win, {
  918. '-webkit-tap-highlight-color': 'rgba(0,0,0,0)',
  919. '-webkit-touch-callout': 'none'
  920. }); // prevent grey layer on click
  921. if (cap.isie && self.opt.disableoutline) self.win.attr("hideFocus", "true"); // IE, prevent dotted rectangle on focused div
  922. if (cap.iswebkit && self.opt.disableoutline) self.win.css({"outline": "none"}); // Webkit outline
  923. //if (cap.isopera&&self.opt.disableoutline) self.win.css({"outline":"0"}); // Opera 12- to test [TODO]
  924. }
  925. if (self.opt.autohidemode === false) {
  926. self.autohidedom = false;
  927. self.rail.css({
  928. opacity: self.opt.cursoropacitymax
  929. });
  930. if (self.railh) self.railh.css({
  931. opacity: self.opt.cursoropacitymax
  932. });
  933. } else if ((self.opt.autohidemode === true) || (self.opt.autohidemode === "leave")) {
  934. self.autohidedom = $().add(self.rail);
  935. if (cap.isie8) self.autohidedom = self.autohidedom.add(self.cursor);
  936. if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
  937. if (self.railh && cap.isie8) self.autohidedom = self.autohidedom.add(self.cursorh);
  938. } else if (self.opt.autohidemode == "scroll") {
  939. self.autohidedom = $().add(self.rail);
  940. if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
  941. } else if (self.opt.autohidemode == "cursor") {
  942. self.autohidedom = $().add(self.cursor);
  943. if (self.railh) self.autohidedom = self.autohidedom.add(self.cursorh);
  944. } else if (self.opt.autohidemode == "hidden") {
  945. self.autohidedom = false;
  946. self.hide();
  947. self.railslocked = false;
  948. }
  949. if (cap.isie9mobile) {
  950. self.scrollmom = new ScrollMomentumClass2D(self);
  951. self.onmangotouch = function() {
  952. var py = self.getScrollTop();
  953. var px = self.getScrollLeft();
  954. if ((py == self.scrollmom.lastscrolly) && (px == self.scrollmom.lastscrollx)) return true;
  955. var dfy = py - self.mangotouch.sy;
  956. var dfx = px - self.mangotouch.sx;
  957. var df = Math.round(Math.sqrt(Math.pow(dfx, 2) + Math.pow(dfy, 2)));
  958. if (df == 0) return;
  959. var dry = (dfy < 0) ? -1 : 1;
  960. var drx = (dfx < 0) ? -1 : 1;
  961. var tm = +new Date();
  962. if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
  963. if (((tm - self.mangotouch.tm) > 80) || (self.mangotouch.dry != dry) || (self.mangotouch.drx != drx)) {
  964. self.scrollmom.stop();
  965. self.scrollmom.reset(px, py);
  966. self.mangotouch.sy = py;
  967. self.mangotouch.ly = py;
  968. self.mangotouch.sx = px;
  969. self.mangotouch.lx = px;
  970. self.mangotouch.dry = dry;
  971. self.mangotouch.drx = drx;
  972. self.mangotouch.tm = tm;
  973. } else {
  974. self.scrollmom.stop();
  975. self.scrollmom.update(self.mangotouch.sx - dfx, self.mangotouch.sy - dfy);
  976. self.mangotouch.tm = tm;
  977. var ds = Math.max(Math.abs(self.mangotouch.ly - py), Math.abs(self.mangotouch.lx - px));
  978. self.mangotouch.ly = py;
  979. self.mangotouch.lx = px;
  980. if (ds > 2) {
  981. self.mangotouch.lazy = setTimeout(function() {
  982. self.mangotouch.lazy = false;
  983. self.mangotouch.dry = 0;
  984. self.mangotouch.drx = 0;
  985. self.mangotouch.tm = 0;
  986. self.scrollmom.doMomentum(30);
  987. }, 100);
  988. }
  989. }
  990. };
  991. var top = self.getScrollTop();
  992. var lef = self.getScrollLeft();
  993. self.mangotouch = {
  994. sy: top,
  995. ly: top,
  996. dry: 0,
  997. sx: lef,
  998. lx: lef,
  999. drx: 0,
  1000. lazy: false,
  1001. tm: 0
  1002. };
  1003. self.bind(self.docscroll, "scroll", self.onmangotouch);
  1004. } else {
  1005. if (cap.cantouch || self.istouchcapable || self.opt.touchbehavior || cap.hasmstouch) {
  1006. self.scrollmom = new ScrollMomentumClass2D(self);
  1007. self.ontouchstart = function(e) {
  1008. console.log(e.type,e.pointerType);
  1009. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  1010. self.hasmoving = false;
  1011. if (!self.railslocked) {
  1012. console.log('touchstart ',e.type);
  1013. var tg;
  1014. if (cap.hasmstouch) {
  1015. tg = (e.target) ? e.target : false;
  1016. while (tg) {
  1017. var nc = $(tg).getNiceScroll();
  1018. if ((nc.length > 0) && (nc[0].me == self.me)) break;
  1019. if (nc.length > 0) return false;
  1020. if ((tg.nodeName == 'DIV') && (tg.id == self.id)) break;
  1021. tg = (tg.parentNode) ? tg.parentNode : false;
  1022. }
  1023. }
  1024. self.cancelScroll();
  1025. tg = self.getTarget(e);
  1026. if (tg) {
  1027. var skp = (/INPUT/i.test(tg.nodeName)) && (/range/i.test(tg.type));
  1028. if (skp) return self.stopPropagation(e);
  1029. }
  1030. if (!("clientX" in e) && ("changedTouches" in e)) {
  1031. e.clientX = e.changedTouches[0].clientX;
  1032. e.clientY = e.changedTouches[0].clientY;
  1033. }
  1034. if (self.forcescreen) {
  1035. var le = e;
  1036. e = {
  1037. "original": (e.original) ? e.original : e
  1038. };
  1039. e.clientX = le.screenX;
  1040. e.clientY = le.screenY;
  1041. }
  1042. self.rail.drag = {
  1043. x: e.clientX,
  1044. y: e.clientY,
  1045. sx: self.scroll.x,
  1046. sy: self.scroll.y,
  1047. st: self.getScrollTop(),
  1048. sl: self.getScrollLeft(),
  1049. pt: 2,
  1050. dl: false
  1051. };
  1052. if (self.ispage || !self.opt.directionlockdeadzone) {
  1053. self.rail.drag.dl = "f";
  1054. } else {
  1055. var view = {
  1056. w: $(window).width(),
  1057. h: $(window).height()
  1058. };
  1059. var page = {
  1060. w: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
  1061. h: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
  1062. };
  1063. var maxh = Math.max(0, page.h - view.h);
  1064. var maxw = Math.max(0, page.w - view.w);
  1065. if (!self.rail.scrollable && self.railh.scrollable) self.rail.drag.ck = (maxh > 0) ? "v" : false;
  1066. else if (self.rail.scrollable && !self.railh.scrollable) self.rail.drag.ck = (maxw > 0) ? "h" : false;
  1067. else self.rail.drag.ck = false;
  1068. if (!self.rail.drag.ck) self.rail.drag.dl = "f";
  1069. }
  1070. if (self.opt.touchbehavior && self.isiframe && cap.isie) {
  1071. var wp = self.win.position();
  1072. self.rail.drag.x += wp.left;
  1073. self.rail.drag.y += wp.top;
  1074. }
  1075. self.hasmoving = false;
  1076. self.lastmouseup = false;
  1077. self.scrollmom.reset(e.clientX, e.clientY);
  1078. if (!cap.cantouch && !this.istouchcapable && !e.pointerType) {
  1079. var ip = (tg) ? /INPUT|SELECT|TEXTAREA/i.test(tg.nodeName) : false;
  1080. if (!ip) {
  1081. if (!self.ispage && cap.hasmousecapture) tg.setCapture();
  1082. if (self.opt.touchbehavior) {
  1083. if (tg.onclick && !(tg._onclick || false)) { // intercept DOM0 onclick event
  1084. tg._onclick = tg.onclick;
  1085. tg.onclick = function(e) {
  1086. if (self.hasmoving) return false;
  1087. tg._onclick.call(this, e);
  1088. };
  1089. }
  1090. return self.cancelEvent(e);
  1091. }
  1092. return self.stopPropagation(e);
  1093. }
  1094. if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
  1095. pc = {
  1096. "tg": tg,
  1097. "click": false
  1098. };
  1099. self.preventclick = pc;
  1100. }
  1101. }
  1102. }
  1103. };
  1104. self.ontouchend = function(e) {
  1105. if (!self.rail.drag) return true;
  1106. if (self.rail.drag.pt == 2) {
  1107. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  1108. console.log('touchend:',e.target.nodeName);
  1109. self.scrollmom.doMomentum();
  1110. self.rail.drag = false;
  1111. if (self.hasmoving) {
  1112. self.lastmouseup = true;
  1113. self.hideCursor();
  1114. if (cap.hasmousecapture) document.releaseCapture();
  1115. if (!cap.cantouch) return self.cancelEvent(e);
  1116. }
  1117. }
  1118. else if (self.rail.drag.pt == 1) {
  1119. return self.onmouseup(e);
  1120. }
  1121. };
  1122. var moveneedoffset = (self.opt.touchbehavior && self.isiframe && !cap.hasmousecapture);
  1123. self.ontouchmove = function(e, byiframe) {
  1124. if (!self.rail.drag) return false;
  1125. if (e.targetTouches && self.opt.preventmultitouchscrolling) {
  1126. if (e.targetTouches.length > 1) return false; // multitouch
  1127. }
  1128. if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
  1129. if (self.rail.drag.pt == 2) {
  1130. if (cap.cantouch && (cap.isios) && (typeof e.original == "undefined")) return true; // prevent ios "ghost" events by clickable elements
  1131. self.hasmoving = true;
  1132. if (self.preventclick && !self.preventclick.click) {
  1133. self.preventclick.click = self.preventclick.tg.onclick || false;
  1134. self.preventclick.tg.onclick = self.onpreventclick;
  1135. }
  1136. var ev = $.extend({
  1137. "original": e
  1138. }, e);
  1139. e = ev;
  1140. if (("changedTouches" in e)) {
  1141. e.clientX = e.changedTouches[0].clientX;
  1142. e.clientY = e.changedTouches[0].clientY;
  1143. }
  1144. if (self.forcescreen) {
  1145. var le = e;
  1146. e = {
  1147. "original": (e.original) ? e.original : e
  1148. };
  1149. e.clientX = le.screenX;
  1150. e.clientY = le.screenY;
  1151. }
  1152. var ofy,ofx;
  1153. ofx = ofy = 0;
  1154. if (moveneedoffset && !byiframe) {
  1155. var wp = self.win.position();
  1156. ofx = -wp.left;
  1157. ofy = -wp.top;
  1158. }
  1159. var fy = e.clientY + ofy;
  1160. var my = (fy - self.rail.drag.y);
  1161. var fx = e.clientX + ofx;
  1162. var mx = (fx - self.rail.drag.x);
  1163. var ny = self.rail.drag.st - my;
  1164. if (self.ishwscroll && self.opt.bouncescroll) {
  1165. if (ny < 0) {
  1166. ny = Math.round(ny / 2);
  1167. // fy = 0;
  1168. } else if (ny > self.page.maxh) {
  1169. ny = self.page.maxh + Math.round((ny - self.page.maxh) / 2);
  1170. // fy = 0;
  1171. }
  1172. } else {
  1173. if (ny < 0) {
  1174. ny = 0;
  1175. fy = 0;
  1176. }
  1177. if (ny > self.page.maxh) {
  1178. ny = self.page.maxh;
  1179. fy = 0;
  1180. }
  1181. }
  1182. var nx;
  1183. if (self.railh && self.railh.scrollable) {
  1184. nx = (self.isrtlmode) ? mx - self.rail.drag.sl : self.rail.drag.sl - mx;
  1185. if (self.ishwscroll && self.opt.bouncescroll) {
  1186. if (nx < 0) {
  1187. nx = Math.round(nx / 2);
  1188. // fx = 0;
  1189. } else if (nx > self.page.maxw) {
  1190. nx = self.page.maxw + Math.round((nx - self.page.maxw) / 2);
  1191. // fx = 0;
  1192. }
  1193. } else {
  1194. if (nx < 0) {
  1195. nx = 0;
  1196. fx = 0;
  1197. }
  1198. if (nx > self.page.maxw) {
  1199. nx = self.page.maxw;
  1200. fx = 0;
  1201. }
  1202. }
  1203. }
  1204. var grabbed = false;
  1205. if (self.rail.drag.dl) {
  1206. grabbed = true;
  1207. if (self.rail.drag.dl == "v") nx = self.rail.drag.sl;
  1208. else if (self.rail.drag.dl == "h") ny = self.rail.drag.st;
  1209. } else {
  1210. var ay = Math.abs(my);
  1211. var ax = Math.abs(mx);
  1212. var dz = self.opt.directionlockdeadzone;
  1213. if (self.rail.drag.ck == "v") {
  1214. if (ay > dz && (ax <= (ay * 0.3))) {
  1215. self.rail.drag = false;
  1216. return true;
  1217. } else if (ax > dz) {
  1218. self.rail.drag.dl = "f";
  1219. $("body").scrollTop($("body").scrollTop()); // stop iOS native scrolling (when active javascript has blocked)
  1220. }
  1221. } else if (self.rail.drag.ck == "h") {
  1222. if (ax > dz && (ay <= (ax * 0.3))) {
  1223. self.rail.drag = false;
  1224. return true;
  1225. } else if (ay > dz) {
  1226. self.rail.drag.dl = "f";
  1227. $("body").scrollLeft($("body").scrollLeft()); // stop iOS native scrolling (when active javascript has blocked)
  1228. }
  1229. }
  1230. }
  1231. self.synched("touchmove", function() {
  1232. if (self.rail.drag && (self.rail.drag.pt == 2)) {
  1233. if (self.prepareTransition) self.prepareTransition(0);
  1234. if (self.rail.scrollable) self.setScrollTop(ny);
  1235. self.scrollmom.update(fx, fy);
  1236. if (self.railh && self.railh.scrollable) {
  1237. self.setScrollLeft(nx);
  1238. self.showCursor(ny, nx);
  1239. } else {
  1240. self.showCursor(ny);
  1241. }
  1242. if (cap.isie10) document.selection.clear();
  1243. }
  1244. });
  1245. if (cap.ischrome && self.istouchcapable) grabbed = false; //chrome touch emulation doesn't like!
  1246. if (grabbed) return self.cancelEvent(e);
  1247. }
  1248. else if (self.rail.drag.pt == 1) { // drag on cursor
  1249. return self.onmousemove(e);
  1250. }
  1251. };
  1252. }
  1253. self.onmousedown = function(e, hronly) {
  1254. if (self.rail.drag && self.rail.drag.pt != 1) return;
  1255. if (self.railslocked) return self.cancelEvent(e);
  1256. self.cancelScroll();
  1257. self.rail.drag = {
  1258. x: e.clientX,
  1259. y: e.clientY,
  1260. sx: self.scroll.x,
  1261. sy: self.scroll.y,
  1262. pt: 1,
  1263. hr: (!!hronly)
  1264. };
  1265. var tg = self.getTarget(e);
  1266. if (!self.ispage && cap.hasmousecapture) tg.setCapture();
  1267. if (self.isiframe && !cap.hasmousecapture) {
  1268. self.saved.csspointerevents = self.doc.css("pointer-events");
  1269. self.css(self.doc, {
  1270. "pointer-events": "none"
  1271. });
  1272. }
  1273. self.hasmoving = false;
  1274. return self.cancelEvent(e);
  1275. };
  1276. self.onmouseup = function(e) {
  1277. if (self.rail.drag) {
  1278. if (self.rail.drag.pt != 1) return true;
  1279. // console.log('mouseup');
  1280. if (cap.hasmousecapture) document.releaseCapture();
  1281. if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents);
  1282. self.rail.drag = false;
  1283. //if (!self.rail.active) self.hideCursor();
  1284. if (self.hasmoving) self.triggerScrollEnd(); // TODO - check &&!self.scrollrunning
  1285. return self.cancelEvent(e);
  1286. }
  1287. };
  1288. self.onmousemove = function(e) {
  1289. if (self.rail.drag) {
  1290. if (self.rail.drag.pt != 1) return;
  1291. if (cap.ischrome && e.which == 0) return self.onmouseup(e);
  1292. self.cursorfreezed = true;
  1293. self.hasmoving = true;
  1294. if (self.rail.drag.hr) {
  1295. self.scroll.x = self.rail.drag.sx + (e.clientX - self.rail.drag.x);
  1296. if (self.scroll.x < 0) self.scroll.x = 0;
  1297. var mw = self.scrollvaluemaxw;
  1298. if (self.scroll.x > mw) self.scroll.x = mw;
  1299. } else {
  1300. self.scroll.y = self.rail.drag.sy + (e.clientY - self.rail.drag.y);
  1301. if (self.scroll.y < 0) self.scroll.y = 0;
  1302. var my = self.scrollvaluemax;
  1303. if (self.scroll.y > my) self.scroll.y = my;
  1304. }
  1305. self.synched('mousemove', function() {
  1306. if (self.rail.drag && (self.rail.drag.pt == 1)) {
  1307. self.showCursor();
  1308. if (self.rail.drag.hr) {
  1309. if (self.hasreversehr) {
  1310. self.doScrollLeft(self.scrollvaluemaxw-Math.round(self.scroll.x * self.scrollratio.x), self.opt.cursordragspeed);
  1311. } else {
  1312. self.doScrollLeft(Math.round(self.scroll.x * self.scrollratio.x), self.opt.cursordragspeed);
  1313. }
  1314. }
  1315. else self.doScrollTop(Math.round(self.scroll.y * self.scrollratio.y), self.opt.cursordragspeed);
  1316. }
  1317. });
  1318. return self.cancelEvent(e);
  1319. }
  1320. else {
  1321. self.checkarea = 0;
  1322. }
  1323. };
  1324. if (cap.cantouch || self.opt.touchbehavior) {
  1325. self.onpreventclick = function(e) {
  1326. if (self.preventclick) {
  1327. self.preventclick.tg.onclick = self.preventclick.click;
  1328. self.preventclick = false;
  1329. return self.cancelEvent(e);
  1330. }
  1331. }
  1332. self.bind(self.win, "mousedown", self.ontouchstart); // control content dragging
  1333. self.onclick = (cap.isios) ? false : function(e) { // it needs to check IE11 ???
  1334. if (self.lastmouseup) {
  1335. self.lastmouseup = false;
  1336. return self.cancelEvent(e);
  1337. } else {
  1338. return true;
  1339. }
  1340. };
  1341. if (self.opt.grabcursorenabled && cap.cursorgrabvalue) {
  1342. self.css((self.ispage) ? self.doc : self.win, {
  1343. 'cursor': cap.cursorgrabvalue
  1344. });
  1345. self.css(self.rail, {
  1346. 'cursor': cap.cursorgrabvalue
  1347. });
  1348. }
  1349. } else {
  1350. var checkSelectionScroll = function(e) {
  1351. if (!self.selectiondrag) return;
  1352. if (e) {
  1353. var ww = self.win.outerHeight();
  1354. var df = (e.pageY - self.selectiondrag.top);
  1355. if (df > 0 && df < ww) df = 0;
  1356. if (df >= ww) df -= ww;
  1357. self.selectiondrag.df = df;
  1358. }
  1359. if (self.selectiondrag.df == 0) return;
  1360. var rt = -Math.floor(self.selectiondrag.df / 6) * 2;
  1361. self.doScrollBy(rt);
  1362. self.debounced("doselectionscroll", function() {
  1363. checkSelectionScroll()
  1364. }, 50);
  1365. };
  1366. if ("getSelection" in document) { // A grade - Major browsers
  1367. self.hasTextSelected = function() {
  1368. return (document.getSelection().rangeCount > 0);
  1369. };
  1370. } else if ("selection" in document) { //IE9-
  1371. self.hasTextSelected = function() {
  1372. return (document.selection.type != "None");
  1373. };
  1374. } else {
  1375. self.hasTextSelected = function() { // no support
  1376. return false;
  1377. };
  1378. }
  1379. self.onselectionstart = function(e) {
  1380. /* More testing - severe chrome issues
  1381. if (!self.haswrapper&&(e.which&&e.which==2)) { // fool browser to manage middle button scrolling
  1382. self.win.css({'overflow':'auto'});
  1383. setTimeout(function(){
  1384. self.win.css({'overflow':''});
  1385. },10);
  1386. return true;
  1387. }
  1388. */
  1389. if (self.ispage) return;
  1390. self.selectiondrag = self.win.offset();
  1391. };
  1392. self.onselectionend = function(e) {
  1393. self.selectiondrag = false;
  1394. };
  1395. self.onselectiondrag = function(e) {
  1396. if (!self.selectiondrag) return;
  1397. if (self.hasTextSelected()) self.debounced("selectionscroll", function() {
  1398. checkSelectionScroll(e)
  1399. }, 250);
  1400. };
  1401. }
  1402. if (cap.hasw3ctouch) { //IE11+
  1403. self.css(self.rail, {
  1404. 'touch-action': 'none'
  1405. });
  1406. self.css(self.cursor, {
  1407. 'touch-action': 'none'
  1408. });
  1409. self.bind(self.win, "pointerdown", self.ontouchstart);
  1410. self.bind(document, "pointerup", self.ontouchend);
  1411. self.bind(document, "pointermove", self.ontouchmove);
  1412. } else if (cap.hasmstouch) { //IE10
  1413. self.css(self.rail, {
  1414. '-ms-touch-action': 'none'
  1415. });
  1416. self.css(self.cursor, {
  1417. '-ms-touch-action': 'none'
  1418. });
  1419. self.bind(self.win, "MSPointerDown", self.ontouchstart);
  1420. self.bind(document, "MSPointerUp", self.ontouchend);
  1421. self.bind(document, "MSPointerMove", self.ontouchmove);
  1422. self.bind(self.cursor, "MSGestureHold", function(e) {
  1423. e.preventDefault()
  1424. });
  1425. self.bind(self.cursor, "contextmenu", function(e) {
  1426. e.preventDefault()
  1427. });
  1428. } else if (this.istouchcapable) { //desktop with screen touch enabled
  1429. self.bind(self.win, "touchstart", self.ontouchstart);
  1430. self.bind(document, "touchend", self.ontouchend);
  1431. self.bind(document, "touchcancel", self.ontouchend);
  1432. self.bind(document, "touchmove", self.ontouchmove);
  1433. }
  1434. if (self.opt.cursordragontouch || (!cap.cantouch && !self.opt.touchbehavior)) {
  1435. self.rail.css({
  1436. "cursor": "default"
  1437. });
  1438. self.railh && self.railh.css({
  1439. "cursor": "default"
  1440. });
  1441. self.jqbind(self.rail, "mouseenter", function() {
  1442. if (!self.ispage && !self.win.is(":visible")) return false;
  1443. if (self.canshowonmouseevent) self.showCursor();
  1444. self.rail.active = true;
  1445. });
  1446. self.jqbind(self.rail, "mouseleave", function() {
  1447. self.rail.active = false;
  1448. if (!self.rail.drag) self.hideCursor();
  1449. });
  1450. if (self.opt.sensitiverail) {
  1451. self.bind(self.rail, "click", function(e) {
  1452. self.doRailClick(e, false, false)
  1453. });
  1454. self.bind(self.rail, "dblclick", function(e) {
  1455. self.doRailClick(e, true, false)
  1456. });
  1457. self.bind(self.cursor, "click", function(e) {
  1458. self.cancelEvent(e)
  1459. });
  1460. self.bind(self.cursor, "dblclick", function(e) {
  1461. self.cancelEvent(e)
  1462. });
  1463. }
  1464. if (self.railh) {
  1465. self.jqbind(self.railh, "mouseenter", function() {
  1466. if (!self.ispage && !self.win.is(":visible")) return false;
  1467. if (self.canshowonmouseevent) self.showCursor();
  1468. self.rail.active = true;
  1469. });
  1470. self.jqbind(self.railh, "mouseleave", function() {
  1471. self.rail.active = false;
  1472. if (!self.rail.drag) self.hideCursor();
  1473. });
  1474. if (self.opt.sensitiverail) {
  1475. self.bind(self.railh, "click", function(e) {
  1476. self.doRailClick(e, false, true)
  1477. });
  1478. self.bind(self.railh, "dblclick", function(e) {
  1479. self.doRailClick(e, true, true)
  1480. });
  1481. self.bind(self.cursorh, "click", function(e) {
  1482. self.cancelEvent(e)
  1483. });
  1484. self.bind(self.cursorh, "dblclick", function(e) {
  1485. self.cancelEvent(e)
  1486. });
  1487. }
  1488. }
  1489. }
  1490. if (!cap.cantouch && !self.opt.touchbehavior) {
  1491. self.bind((cap.hasmousecapture) ? self.win : document, "mouseup", self.onmouseup);
  1492. self.bind(document, "mousemove", self.onmousemove);
  1493. if (self.onclick) self.bind(document, "click", self.onclick);
  1494. self.bind(self.cursor, "mousedown", self.onmousedown);
  1495. self.bind(self.cursor, "mouseup", self.onmouseup);
  1496. if (self.railh) {
  1497. self.bind(self.cursorh, "mousedown", function(e) {
  1498. self.onmousedown(e, true)
  1499. });
  1500. self.bind(self.cursorh, "mouseup", self.onmouseup);
  1501. }
  1502. if (!self.ispage && self.opt.enablescrollonselection) {
  1503. self.bind(self.win[0], "mousedown", self.onselectionstart);
  1504. self.bind(document, "mouseup", self.onselectionend);
  1505. self.bind(self.cursor, "mouseup", self.onselectionend);
  1506. if (self.cursorh) self.bind(self.cursorh, "mouseup", self.onselectionend);
  1507. self.bind(document, "mousemove", self.onselectiondrag);
  1508. }
  1509. if (self.zoom) {
  1510. self.jqbind(self.zoom, "mouseenter", function() {
  1511. if (self.canshowonmouseevent) self.showCursor();
  1512. self.rail.active = true;
  1513. });
  1514. self.jqbind(self.zoom, "mouseleave", function() {
  1515. self.rail.active = false;
  1516. if (!self.rail.drag) self.hideCursor();
  1517. });
  1518. }
  1519. } else {
  1520. self.bind((cap.hasmousecapture) ? self.win : document, "mouseup", self.ontouchend);
  1521. self.bind(document, "mousemove", self.ontouchmove);
  1522. if (self.onclick) self.bind(document, "click", self.onclick);
  1523. if (self.opt.cursordragontouch) {
  1524. self.bind(self.cursor, "mousedown", self.onmousedown);
  1525. self.bind(self.cursor, "mouseup", self.onmouseup);
  1526. //self.bind(self.cursor, "mousemove", self.onmousemove);
  1527. self.cursorh && self.bind(self.cursorh, "mousedown", function(e) {
  1528. self.onmousedown(e, true)
  1529. });
  1530. //self.cursorh && self.bind(self.cursorh, "mousemove", self.onmousemove);
  1531. self.cursorh && self.bind(self.cursorh, "mouseup", self.onmouseup);
  1532. } else {
  1533. self.bind(self.rail, "mousedown", function(e){e.preventDefault();}); // prevent text selection
  1534. self.railh&&self.bind(self.railh, "mousedown", function(e){e.preventDefault();});
  1535. }
  1536. }
  1537. if (self.opt.enablemousewheel) {
  1538. if (!self.isiframe) self.mousewheel((cap.isie && self.ispage) ? document : self.win , self.onmousewheel);
  1539. self.mousewheel(self.rail, self.onmousewheel);
  1540. if (self.railh) self.mousewheel(self.railh, self.onmousewheelhr);
  1541. }
  1542. if (!self.ispage && !cap.cantouch && !(/HTML|^BODY/.test(self.win[0].nodeName))) {
  1543. if (!self.win.attr("tabindex")) self.win.attr({
  1544. "tabindex": tabindexcounter++
  1545. });
  1546. self.jqbind(self.win, "focus", function(e) {
  1547. domfocus = (self.getTarget(e)).id || true;
  1548. self.hasfocus = true;
  1549. if (self.canshowonmouseevent) self.noticeCursor();
  1550. });
  1551. self.jqbind(self.win, "blur", function(e) {
  1552. domfocus = false;
  1553. self.hasfocus = false;
  1554. });
  1555. self.jqbind(self.win, "mouseenter", function(e) {
  1556. mousefocus = (self.getTarget(e)).id || true;
  1557. self.hasmousefocus = true;
  1558. if (self.canshowonmouseevent) self.noticeCursor();
  1559. });
  1560. self.jqbind(self.win, "mouseleave", function() {
  1561. mousefocus = false;
  1562. self.hasmousefocus = false;
  1563. if (!self.rail.drag) self.hideCursor();
  1564. });
  1565. }
  1566. } // !ie9mobile
  1567. //Thanks to http://www.quirksmode.org !!
  1568. self.onkeypress = function(e) {
  1569. if (self.railslocked && self.page.maxh == 0) return true;
  1570. e = (e) ? e : window.e;
  1571. var tg = self.getTarget(e);
  1572. if (tg && /INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
  1573. var tp = tg.getAttribute('type') || tg.type || false;
  1574. if ((!tp) || !(/submit|button|cancel/i.tp)) return true;
  1575. }
  1576. if ($(tg).attr('contenteditable')) return true;
  1577. if (self.hasfocus || (self.hasmousefocus && !domfocus) || (self.ispage && !domfocus && !mousefocus)) {
  1578. var key = e.keyCode;
  1579. if (self.railslocked && key != 27) return self.cancelEvent(e);
  1580. var ctrl = e.ctrlKey || false;
  1581. var shift = e.shiftKey || false;
  1582. var ret = false;
  1583. switch (key) {
  1584. case 38:
  1585. case 63233: //safari
  1586. self.doScrollBy(24 * 3);
  1587. ret = true;
  1588. break;
  1589. case 40:
  1590. case 63235: //safari
  1591. self.doScrollBy(-24 * 3);
  1592. ret = true;
  1593. break;
  1594. case 37:
  1595. case 63232: //safari
  1596. if (self.railh) {
  1597. (ctrl) ? self.doScrollLeft(0): self.doScrollLeftBy(24 * 3);
  1598. ret = true;
  1599. }
  1600. break;
  1601. case 39:
  1602. case 63234: //safari
  1603. if (self.railh) {
  1604. (ctrl) ? self.doScrollLeft(self.page.maxw): self.doScrollLeftBy(-24 * 3);
  1605. ret = true;
  1606. }
  1607. break;
  1608. case 33:
  1609. case 63276: // safari
  1610. self.doScrollBy(self.view.h);
  1611. ret = true;
  1612. break;
  1613. case 34:
  1614. case 63277: // safari
  1615. self.doScrollBy(-self.view.h);
  1616. ret = true;
  1617. break;
  1618. case 36:
  1619. case 63273: // safari
  1620. (self.railh && ctrl) ? self.doScrollPos(0, 0): self.doScrollTo(0);
  1621. ret = true;
  1622. break;
  1623. case 35:
  1624. case 63275: // safari
  1625. (self.railh && ctrl) ? self.doScrollPos(self.page.maxw, self.page.maxh): self.doScrollTo(self.page.maxh);
  1626. ret = true;
  1627. break;
  1628. case 32:
  1629. if (self.opt.spacebarenabled) {
  1630. (shift) ? self.doScrollBy(self.view.h): self.doScrollBy(-self.view.h);
  1631. ret = true;
  1632. }
  1633. break;
  1634. case 27: // ESC
  1635. if (self.zoomactive) {
  1636. self.doZoom();
  1637. ret = true;
  1638. }
  1639. break;
  1640. }
  1641. if (ret) return self.cancelEvent(e);
  1642. }
  1643. };
  1644. if (self.opt.enablekeyboard) self.bind(document, (cap.isopera && !cap.isopera12) ? "keypress" : "keydown", self.onkeypress);
  1645. self.bind(document, "keydown", function(e) {
  1646. var ctrl = e.ctrlKey || false;
  1647. if (ctrl) self.wheelprevented = true;
  1648. });
  1649. self.bind(document, "keyup", function(e) {
  1650. var ctrl = e.ctrlKey || false;
  1651. if (!ctrl) self.wheelprevented = false;
  1652. });
  1653. self.bind(window,"blur",function(e){
  1654. self.wheelprevented = false;
  1655. });
  1656. self.bind(window, 'resize', self.lazyResize);
  1657. self.bind(window, 'orientationchange', self.lazyResize);
  1658. self.bind(window, "load", self.lazyResize);
  1659. if (cap.ischrome && !self.ispage && !self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
  1660. var tmp = self.win.attr("style");
  1661. var ww = parseFloat(self.win.css("width")) + 1;
  1662. self.win.css('width', ww);
  1663. self.synched("chromefix", function() {
  1664. self.win.attr("style", tmp)
  1665. });
  1666. }
  1667. // Trying a cross-browser implementation - good luck!
  1668. self.onAttributeChange = function(e) {
  1669. self.lazyResize(self.isieold ? 250 : 30);
  1670. };
  1671. if (ClsMutationObserver !== false) {
  1672. self.observerbody = new ClsMutationObserver(function(mutations) {
  1673. mutations.forEach(function(mut){
  1674. if (mut.type=="attributes") {
  1675. return ($("body").hasClass("modal-open") && $("body").hasClass("modal-dialog") && !$.contains($('.modal-dialog')[0],self.doc[0])) ? self.hide() : self.show(); // Support for Bootstrap modal; Added check if the nice scroll element is inside a modal
  1676. }
  1677. });
  1678. if (document.body.scrollHeight!=self.page.maxh) return self.lazyResize(30);
  1679. });
  1680. self.observerbody.observe(document.body, {
  1681. childList: true,
  1682. subtree: true,
  1683. characterData: false,
  1684. attributes: true,
  1685. attributeFilter: ['class']
  1686. });
  1687. }
  1688. if (!self.ispage && !self.haswrapper) {
  1689. // redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
  1690. if (ClsMutationObserver !== false) {
  1691. self.observer = new ClsMutationObserver(function(mutations) {
  1692. mutations.forEach(self.onAttributeChange);
  1693. });
  1694. self.observer.observe(self.win[0], {
  1695. childList: true,
  1696. characterData: false,
  1697. attributes: true,
  1698. subtree: false
  1699. });
  1700. self.observerremover = new ClsMutationObserver(function(mutations) {
  1701. mutations.forEach(function(mo) {
  1702. if (mo.removedNodes.length > 0) {
  1703. for (var dd in mo.removedNodes) {
  1704. if (!!self && (mo.removedNodes[dd] == self.win[0])) return self.remove();
  1705. }
  1706. }
  1707. });
  1708. });
  1709. self.observerremover.observe(self.win[0].parentNode, {
  1710. childList: true,
  1711. characterData: false,
  1712. attributes: false,
  1713. subtree: false
  1714. });
  1715. } else {
  1716. self.bind(self.win, (cap.isie && !cap.isie9) ? "propertychange" : "DOMAttrModified", self.onAttributeChange);
  1717. if (cap.isie9) self.win[0].attachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
  1718. self.bind(self.win, "DOMNodeRemoved", function(e) {
  1719. if (e.target == self.win[0]) self.remove();
  1720. });
  1721. }
  1722. }
  1723. //
  1724. if (!self.ispage && self.opt.boxzoom) self.bind(window, "resize", self.resizeZoom);
  1725. if (self.istextarea) {
  1726. self.bind(self.win, "keydown", self.lazyResize);
  1727. self.bind(self.win, "mouseup", self.lazyResize);
  1728. }
  1729. // self.checkrtlmode = true;
  1730. self.lazyResize(30);
  1731. }
  1732. if (this.doc[0].nodeName == 'IFRAME') {
  1733. var oniframeload = function() {
  1734. self.iframexd = false;
  1735. var doc;
  1736. try {
  1737. doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
  1738. var a = doc.domain;
  1739. } catch (e) {
  1740. self.iframexd = true;
  1741. doc = false
  1742. }
  1743. if (self.iframexd) {
  1744. if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
  1745. return true; //cross-domain - I can't manage this
  1746. }
  1747. self.forcescreen = true;
  1748. if (self.isiframe) {
  1749. self.iframe = {
  1750. "doc": $(doc),
  1751. "html": self.doc.contents().find('html')[0],
  1752. "body": self.doc.contents().find('body')[0]
  1753. };
  1754. self.getContentSize = function() {
  1755. return {
  1756. w: Math.max(self.iframe.html.scrollWidth, self.iframe.body.scrollWidth),
  1757. h: Math.max(self.iframe.html.scrollHeight, self.iframe.body.scrollHeight)
  1758. };
  1759. };
  1760. self.docscroll = $(self.iframe.body); //$(this.contentWindow);
  1761. }
  1762. if (!cap.isios && self.opt.iframeautoresize && !self.isiframe) {
  1763. self.win.scrollTop(0); // reset position
  1764. self.doc.height(""); //reset height to fix browser bug
  1765. var hh = Math.max(doc.getElementsByTagName('html')[0].scrollHeight, doc.body.scrollHeight);
  1766. self.doc.height(hh);
  1767. }
  1768. self.lazyResize(30);
  1769. if (cap.isie7) self.css($(self.iframe.html), {
  1770. 'overflow-y': 'hidden'
  1771. });
  1772. self.css($(self.iframe.body), {
  1773. 'overflow-y': 'hidden'
  1774. });
  1775. if (cap.isios && self.haswrapper) {
  1776. self.css($(doc.body), {
  1777. '-webkit-transform': 'translate3d(0,0,0)'
  1778. }); // avoid iFrame content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/
  1779. }
  1780. if ('contentWindow' in this) {
  1781. self.bind(this.contentWindow, "scroll", self.onscroll); //IE8 & minor
  1782. } else {
  1783. self.bind(doc, "scroll", self.onscroll);
  1784. }
  1785. if (self.opt.enablemousewheel) {
  1786. self.mousewheel(doc, self.onmousewheel);
  1787. }
  1788. if (self.opt.enablekeyboard) self.bind(doc, (cap.isopera) ? "keypress" : "keydown", self.onkeypress);
  1789. if (cap.cantouch || self.opt.touchbehavior) {
  1790. self.bind(doc, "mousedown", self.ontouchstart);
  1791. self.bind(doc, "mousemove", function(e) {
  1792. return self.ontouchmove(e, true)
  1793. });
  1794. if (self.opt.grabcursorenabled && cap.cursorgrabvalue) self.css($(doc.body), {
  1795. 'cursor': cap.cursorgrabvalue
  1796. });
  1797. }
  1798. self.bind(doc, "mouseup", self.ontouchend);
  1799. if (self.zoom) {
  1800. if (self.opt.dblclickzoom) self.bind(doc, 'dblclick', self.doZoom);
  1801. if (self.ongesturezoom) self.bind(doc, "gestureend", self.ongesturezoom);
  1802. }
  1803. };
  1804. if (this.doc[0].readyState && this.doc[0].readyState == "complete") {
  1805. setTimeout(function() {
  1806. oniframeload.call(self.doc[0], false)
  1807. }, 500);
  1808. }
  1809. self.bind(this.doc, "load", oniframeload);
  1810. }
  1811. };
  1812. this.showCursor = function(py, px) {
  1813. if (self.cursortimeout) {
  1814. clearTimeout(self.cursortimeout);
  1815. self.cursortimeout = 0;
  1816. }
  1817. if (!self.rail) return;
  1818. if (self.autohidedom) {
  1819. self.autohidedom.stop().css({
  1820. opacity: self.opt.cursoropacitymax
  1821. });
  1822. self.cursoractive = true;
  1823. }
  1824. if (!self.rail.drag || self.rail.drag.pt != 1) {
  1825. if ((typeof py != "undefined") && (py !== false)) {
  1826. self.scroll.y = Math.round(py * 1 / self.scrollratio.y);
  1827. }
  1828. if (typeof px != "undefined") {
  1829. self.scroll.x = Math.round(px * 1 / self.scrollratio.x);
  1830. }
  1831. }
  1832. self.cursor.css({
  1833. height: self.cursorheight,
  1834. top: self.scroll.y
  1835. });
  1836. if (self.cursorh) {
  1837. var lx = (self.hasreversehr) ? self.scrollvaluemaxw-self.scroll.x : self.scroll.x;
  1838. (!self.rail.align && self.rail.visibility) ? self.cursorh.css({
  1839. width: self.cursorwidth,
  1840. left: lx + self.rail.width
  1841. }): self.cursorh.css({
  1842. width: self.cursorwidth,
  1843. left: lx
  1844. });
  1845. self.cursoractive = true;
  1846. }
  1847. if (self.zoom) self.zoom.stop().css({
  1848. opacity: self.opt.cursoropacitymax
  1849. });
  1850. };
  1851. this.hideCursor = function(tm) {
  1852. if (self.cursortimeout) return;
  1853. if (!self.rail) return;
  1854. if (!self.autohidedom) return;
  1855. if (self.hasmousefocus && self.opt.autohidemode == "leave") return;
  1856. self.cursortimeout = setTimeout(function() {
  1857. if (!self.rail.active || !self.showonmouseevent) {
  1858. self.autohidedom.stop().animate({
  1859. opacity: self.opt.cursoropacitymin
  1860. });
  1861. if (self.zoom) self.zoom.stop().animate({
  1862. opacity: self.opt.cursoropacitymin
  1863. });
  1864. self.cursoractive = false;
  1865. }
  1866. self.cursortimeout = 0;
  1867. }, tm || self.opt.hidecursordelay);
  1868. };
  1869. this.noticeCursor = function(tm, py, px) {
  1870. self.showCursor(py, px);
  1871. if (!self.rail.active) self.hideCursor(tm);
  1872. };
  1873. this.getContentSize =
  1874. (self.ispage) ?
  1875. function() {
  1876. return {
  1877. w: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
  1878. h: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
  1879. }
  1880. } : (self.haswrapper) ?
  1881. function() {
  1882. return {
  1883. w: self.doc.outerWidth() + parseInt(self.win.css('paddingLeft')) + parseInt(self.win.css('paddingRight')),
  1884. h: self.doc.outerHeight() + parseInt(self.win.css('paddingTop')) + parseInt(self.win.css('paddingBottom'))
  1885. }
  1886. } : function() {
  1887. return {
  1888. w: self.docscroll[0].scrollWidth,
  1889. h: self.docscroll[0].scrollHeight
  1890. }
  1891. };
  1892. this.onResize = function(e, page) {
  1893. if (!self || !self.win) return false;
  1894. if (!self.haswrapper && !self.ispage) {
  1895. if (self.win.css('display') == 'none') {
  1896. if (self.visibility) self.hideRail().hideRailHr();
  1897. return false;
  1898. } else {
  1899. if (!self.hidden && !self.visibility) self.showRail().showRailHr();
  1900. }
  1901. }
  1902. var premaxh = self.page.maxh;
  1903. var premaxw = self.page.maxw;
  1904. var preview = {
  1905. h: self.view.h,
  1906. w: self.view.w
  1907. };
  1908. self.view = {
  1909. w: (self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
  1910. h: (self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
  1911. };
  1912. self.page = (page) ? page : self.getContentSize();
  1913. self.page.maxh = Math.max(0, self.page.h - self.view.h);
  1914. self.page.maxw = Math.max(0, self.page.w - self.view.w);
  1915. if ((self.page.maxh == premaxh) && (self.page.maxw == premaxw) && (self.view.w == preview.w) && (self.view.h == preview.h)) {
  1916. // test position
  1917. if (!self.ispage) {
  1918. var pos = self.win.offset();
  1919. if (self.lastposition) {
  1920. var lst = self.lastposition;
  1921. if ((lst.top == pos.top) && (lst.left == pos.left)) return self; //nothing to do
  1922. }
  1923. self.lastposition = pos;
  1924. } else {
  1925. return self; //nothing to do
  1926. }
  1927. }
  1928. if (self.page.maxh == 0) {
  1929. self.hideRail();
  1930. self.scrollvaluemax = 0;
  1931. self.scroll.y = 0;
  1932. self.scrollratio.y = 0;
  1933. self.cursorheight = 0;
  1934. self.setScrollTop(0);
  1935. if (self.rail) self.rail.scrollable = false;
  1936. } else {
  1937. self.page.maxh -= (self.opt.railpadding.top + self.opt.railpadding.bottom); //**
  1938. self.rail.scrollable = true;
  1939. }
  1940. if (self.page.maxw == 0) {
  1941. self.hideRailHr();
  1942. self.scrollvaluemaxw = 0;
  1943. self.scroll.x = 0;
  1944. self.scrollratio.x = 0;
  1945. self.cursorwidth = 0;
  1946. self.setScrollLeft(0);
  1947. if (self.railh) {
  1948. self.railh.scrollable = false;
  1949. }
  1950. } else {
  1951. self.page.maxw -= (self.opt.railpadding.left + self.opt.railpadding.right); //**
  1952. if (self.railh) self.railh.scrollable = (self.opt.horizrailenabled);
  1953. }
  1954. self.railslocked = (self.locked) || ((self.page.maxh == 0) && (self.page.maxw == 0));
  1955. if (self.railslocked) {
  1956. if (!self.ispage) self.updateScrollBar(self.view);
  1957. return false;
  1958. }
  1959. if (!self.hidden && !self.visibility) {
  1960. self.showRail().showRailHr();
  1961. }
  1962. else if (self.railh && (!self.hidden && !self.railh.visibility)) self.showRailHr();
  1963. if (self.istextarea && self.win.css('resize') && self.win.css('resize') != 'none') self.view.h -= 20;
  1964. self.cursorheight = Math.min(self.view.h, Math.round(self.view.h * (self.view.h / self.page.h)));
  1965. self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight, self.cursorheight);
  1966. self.cursorwidth = Math.min(self.view.w, Math.round(self.view.w * (self.view.w / self.page.w)));
  1967. self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight, self.cursorwidth);
  1968. self.scrollvaluemax = self.view.h - self.cursorheight - self.cursor.hborder - (self.opt.railpadding.top + self.opt.railpadding.bottom); //**
  1969. if (self.railh) {
  1970. self.railh.width = (self.page.maxh > 0) ? (self.view.w - self.rail.width) : self.view.w;
  1971. self.scrollvaluemaxw = self.railh.width - self.cursorwidth - self.cursorh.wborder - (self.opt.railpadding.left + self.opt.railpadding.right); //**
  1972. }
  1973. /*
  1974. if (self.checkrtlmode&&self.railh) {
  1975. self.checkrtlmode = false;
  1976. if (self.opt.rtlmode&&self.scroll.x==0) self.setScrollLeft(self.page.maxw);
  1977. }
  1978. */
  1979. if (!self.ispage) self.updateScrollBar(self.view);
  1980. self.scrollratio = {
  1981. x: (self.page.maxw / self.scrollvaluemaxw),
  1982. y: (self.page.maxh / self.scrollvaluemax)
  1983. };
  1984. var sy = self.getScrollTop();
  1985. if (sy > self.page.maxh) {
  1986. self.doScrollTop(self.page.maxh);
  1987. } else {
  1988. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  1989. self.scroll.x = Math.round(self.getScrollLeft() * (1 / self.scrollratio.x));
  1990. if (self.cursoractive) self.noticeCursor();
  1991. }
  1992. if (self.scroll.y && (self.getScrollTop() == 0)) self.doScrollTo(Math.floor(self.scroll.y * self.scrollratio.y));
  1993. return self;
  1994. };
  1995. this.resize = self.onResize;
  1996. this.hlazyresize = 0;
  1997. this.lazyResize = function(tm) { // event debounce
  1998. /*
  1999. tm = (isNaN(tm)) ? 30 : tm;
  2000. self.debounced('resize', self.resize, tm);
  2001. */
  2002. // if (!self.haswrapper&&self.opt.autohidemode!==false) self.hide();
  2003. if (!self.haswrapper) self.hide();
  2004. if (self.hlazyresize) clearTimeout(self.hlazyresize);
  2005. self.hlazyresize = setTimeout(function(){
  2006. self.show().resize();
  2007. },240);
  2008. return self;
  2009. };
  2010. // modified by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
  2011. function _modernWheelEvent(dom, name, fn, bubble) {
  2012. self._bind(dom, name, function(e) {
  2013. var e = (e) ? e : window.event;
  2014. var event = {
  2015. original: e,
  2016. target: e.target || e.srcElement,
  2017. type: "wheel",
  2018. deltaMode: e.type == "MozMousePixelScroll" ? 0 : 1,
  2019. deltaX: 0,
  2020. deltaZ: 0,
  2021. preventDefault: function() {
  2022. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  2023. return false;
  2024. },
  2025. stopImmediatePropagation: function() {
  2026. (e.stopImmediatePropagation) ? e.stopImmediatePropagation(): e.cancelBubble = true;
  2027. }
  2028. };
  2029. if (name == "mousewheel") {
  2030. e.wheelDeltaX && (event.deltaX = -1 / 40 * e.wheelDeltaX);
  2031. e.wheelDeltaY && (event.deltaY = -1 / 40 * e.wheelDeltaY);
  2032. !event.deltaY && !event.deltaX && (event.deltaY = -1 / 40 * e.wheelDelta);
  2033. } else {
  2034. event.deltaY = e.detail;
  2035. }
  2036. return fn.call(dom, event);
  2037. }, bubble);
  2038. };
  2039. this.jqbind = function(dom, name, fn) { // use jquery bind for non-native events (mouseenter/mouseleave)
  2040. self.events.push({
  2041. e: dom,
  2042. n: name,
  2043. f: fn,
  2044. q: true
  2045. });
  2046. $(dom).bind(name, fn);
  2047. };
  2048. this.mousewheel = function(dom, fn, bubble) { // bind mousewheel
  2049. var el = ("jquery" in dom) ? dom[0] : dom;
  2050. if ("onwheel" in document.createElement("div")) { // Modern browsers support "wheel"
  2051. self._bind(el, "wheel", fn, bubble || false);
  2052. } else {
  2053. var wname = (typeof document.onmousewheel != "undefined") ? "mousewheel" : "DOMMouseScroll"; // older Webkit+IE support or older Firefox
  2054. _modernWheelEvent(el, wname, fn, bubble || false);
  2055. if (wname == "DOMMouseScroll") _modernWheelEvent(el, "MozMousePixelScroll", fn, bubble || false); // Firefox legacy
  2056. }
  2057. };
  2058. if (cap.haseventlistener) { // W3C standard event model
  2059. this.bind = function(dom, name, fn, bubble) { // W3C
  2060. var el = ("jquery" in dom) ? dom[0] : dom;
  2061. self._bind(el, name, fn, bubble || false);
  2062. }
  2063. this._bind = function(el, name, fn, bubble) { // primitive bind
  2064. self.events.push({
  2065. e: el,
  2066. n: name,
  2067. f: fn,
  2068. b: bubble,
  2069. q: false
  2070. });
  2071. el.addEventListener(name, fn, bubble || false);
  2072. };
  2073. this.cancelEvent = function(e) {
  2074. if (!e) return false;
  2075. var e = (e.original) ? e.original : e;
  2076. if (e.cancelable) e.preventDefault();
  2077. e.stopPropagation();
  2078. if (e.preventManipulation) e.preventManipulation(); //IE10
  2079. return false;
  2080. };
  2081. this.stopPropagation = function(e) {
  2082. if (!e) return false;
  2083. var e = (e.original) ? e.original : e;
  2084. e.stopPropagation();
  2085. return false;
  2086. };
  2087. this._unbind = function(el, name, fn, bub) { // primitive unbind
  2088. el.removeEventListener(name, fn, bub);
  2089. };
  2090. } else { // old IE model
  2091. this.bind = function(dom, name, fn, bubble) { // legacy IE
  2092. var el = ("jquery" in dom) ? dom[0] : dom;
  2093. self._bind(el, name, function(e) {
  2094. e = e || window.event || false;
  2095. if (e) {
  2096. if (e.srcElement) e.target = e.srcElement;
  2097. }
  2098. if (!("pageY" in e)) {
  2099. e.pageX = e.clientX + document.documentElement.scrollLeft;
  2100. e.pageY = e.clientY + document.documentElement.scrollTop;
  2101. }
  2102. return ((fn.call(el, e) === false) || bubble === false) ? self.cancelEvent(e) : true;
  2103. });
  2104. }
  2105. this._bind = function(el, name, fn, bubble) { // primitive bind
  2106. self.events.push({
  2107. e: el,
  2108. n: name,
  2109. f: fn,
  2110. b: bubble,
  2111. q: false
  2112. });
  2113. if (el.attachEvent) {
  2114. el.attachEvent("on" + name, fn);
  2115. } else {
  2116. el["on" + name] = fn;
  2117. }
  2118. };
  2119. // Thanks to http://www.switchonthecode.com !!
  2120. this.cancelEvent = function(e) {
  2121. var e = window.event || false;
  2122. if (!e) return false;
  2123. e.cancelBubble = true;
  2124. e.cancel = true;
  2125. e.returnValue = false;
  2126. return false;
  2127. };
  2128. this.stopPropagation = function(e) {
  2129. var e = window.event || false;
  2130. if (!e) return false;
  2131. e.cancelBubble = true;
  2132. return false;
  2133. };
  2134. this._unbind = function(el, name, fn, bub) { // primitive unbind IE old
  2135. if (el.detachEvent) {
  2136. el.detachEvent('on' + name, fn);
  2137. } else {
  2138. el['on' + name] = false;
  2139. }
  2140. };
  2141. }
  2142. this.unbindAll = function() {
  2143. for (var a = 0; a < self.events.length; a++) {
  2144. var r = self.events[a];
  2145. (r.q) ? r.e.unbind(r.n, r.f): self._unbind(r.e, r.n, r.f, r.b);
  2146. }
  2147. };
  2148. this.showRail = function() {
  2149. if ((self.page.maxh != 0) && (self.ispage || self.win.css('display') != 'none')) {
  2150. self.visibility = true;
  2151. self.rail.visibility = true;
  2152. self.rail.css('display', 'block');
  2153. }
  2154. return self;
  2155. };
  2156. this.showRailHr = function() {
  2157. if (!self.railh) return self;
  2158. if ((self.page.maxw != 0) && (self.ispage || self.win.css('display') != 'none')) {
  2159. self.railh.visibility = true;
  2160. self.railh.css('display', 'block');
  2161. }
  2162. return self;
  2163. };
  2164. this.hideRail = function() {
  2165. self.visibility = false;
  2166. self.rail.visibility = false;
  2167. self.rail.css('display', 'none');
  2168. return self;
  2169. };
  2170. this.hideRailHr = function() {
  2171. if (!self.railh) return self;
  2172. self.railh.visibility = false;
  2173. self.railh.css('display', 'none');
  2174. return self;
  2175. };
  2176. this.show = function() {
  2177. self.hidden = false;
  2178. self.railslocked = false;
  2179. return self.showRail().showRailHr();
  2180. };
  2181. this.hide = function() {
  2182. self.hidden = true;
  2183. self.railslocked = true;
  2184. return self.hideRail().hideRailHr();
  2185. };
  2186. this.toggle = function() {
  2187. return (self.hidden) ? self.show() : self.hide();
  2188. };
  2189. this.remove = function() {
  2190. self.stop();
  2191. if (self.cursortimeout) clearTimeout(self.cursortimeout);
  2192. // if (self.debouncedelayed) clearTimeout(self.debouncedelayed);
  2193. for(var n in self.delaylist) if (self.delaylist[n]) clearAnimationFrame(self.delaylist[n].h);
  2194. self.doZoomOut();
  2195. self.unbindAll();
  2196. if (cap.isie9) self.win[0].detachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
  2197. if (self.observer !== false) self.observer.disconnect();
  2198. if (self.observerremover !== false) self.observerremover.disconnect();
  2199. if (self.observerbody !== false) self.observerbody.disconnect();
  2200. self.events = null;
  2201. if (self.cursor) {
  2202. self.cursor.remove();
  2203. }
  2204. if (self.cursorh) {
  2205. self.cursorh.remove();
  2206. }
  2207. if (self.rail) {
  2208. self.rail.remove();
  2209. }
  2210. if (self.railh) {
  2211. self.railh.remove();
  2212. }
  2213. if (self.zoom) {
  2214. self.zoom.remove();
  2215. }
  2216. for (var a = 0; a < self.saved.css.length; a++) {
  2217. var d = self.saved.css[a];
  2218. d[0].css(d[1], (typeof d[2] == "undefined") ? '' : d[2]);
  2219. }
  2220. self.saved = false;
  2221. self.me.data('__nicescroll', ''); //erase all traces
  2222. // memory leak fixed by GianlucaGuarini - thanks a lot!
  2223. // remove the current nicescroll from the $.nicescroll array & normalize array
  2224. var lst = $.nicescroll;
  2225. lst.each(function(i) {
  2226. if (!this) return;
  2227. if (this.id === self.id) {
  2228. delete lst[i];
  2229. for (var b = ++i; b < lst.length; b++, i++) lst[i] = lst[b];
  2230. lst.length--;
  2231. if (lst.length) delete lst[lst.length];
  2232. }
  2233. });
  2234. for (var i in self) {
  2235. self[i] = null;
  2236. delete self[i];
  2237. }
  2238. self = null;
  2239. };
  2240. this.scrollstart = function(fn) {
  2241. this.onscrollstart = fn;
  2242. return self;
  2243. };
  2244. this.scrollend = function(fn) {
  2245. this.onscrollend = fn;
  2246. return self;
  2247. };
  2248. this.scrollcancel = function(fn) {
  2249. this.onscrollcancel = fn;
  2250. return self;
  2251. };
  2252. this.zoomin = function(fn) {
  2253. this.onzoomin = fn;
  2254. return self;
  2255. };
  2256. this.zoomout = function(fn) {
  2257. this.onzoomout = fn;
  2258. return self;
  2259. };
  2260. this.isScrollable = function(e) {
  2261. var dom = (e.target) ? e.target : e;
  2262. if (dom.nodeName == 'OPTION') return true;
  2263. while (dom && (dom.nodeType == 1) && !(/^BODY|HTML/.test(dom.nodeName))) {
  2264. var dd = $(dom);
  2265. var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
  2266. if (/scroll|auto/.test(ov)) return (dom.clientHeight != dom.scrollHeight);
  2267. dom = (dom.parentNode) ? dom.parentNode : false;
  2268. }
  2269. return false;
  2270. };
  2271. this.getViewport = function(me) {
  2272. var dom = (me && me.parentNode) ? me.parentNode : false;
  2273. while (dom && (dom.nodeType == 1) && !(/^BODY|HTML/.test(dom.nodeName))) {
  2274. var dd = $(dom);
  2275. if (/fixed|absolute/.test(dd.css("position"))) return dd;
  2276. var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
  2277. if ((/scroll|auto/.test(ov)) && (dom.clientHeight != dom.scrollHeight)) return dd;
  2278. if (dd.getNiceScroll().length > 0) return dd;
  2279. dom = (dom.parentNode) ? dom.parentNode : false;
  2280. }
  2281. return false; //(dom) ? $(dom) : false;
  2282. };
  2283. this.triggerScrollEnd = function() {
  2284. if (!self.onscrollend) return;
  2285. var px = self.getScrollLeft();
  2286. var py = self.getScrollTop();
  2287. var info = {
  2288. "type": "scrollend",
  2289. "current": {
  2290. "x": px,
  2291. "y": py
  2292. },
  2293. "end": {
  2294. "x": px,
  2295. "y": py
  2296. }
  2297. };
  2298. self.onscrollend.call(self, info);
  2299. }
  2300. function execScrollWheel(e, hr, chkscroll) {
  2301. var px, py;
  2302. if (e.deltaMode == 0) { // PIXEL
  2303. px = -Math.floor(e.deltaX * (self.opt.mousescrollstep / (18 * 3)));
  2304. py = -Math.floor(e.deltaY * (self.opt.mousescrollstep / (18 * 3)));
  2305. } else if (e.deltaMode == 1) { // LINE
  2306. px = -Math.floor(e.deltaX * self.opt.mousescrollstep);
  2307. py = -Math.floor(e.deltaY * self.opt.mousescrollstep);
  2308. }
  2309. if (hr && self.opt.oneaxismousemode && (px == 0) && py) { // classic vertical-only mousewheel + browser with x/y support
  2310. px = py;
  2311. py = 0;
  2312. if (chkscroll) {
  2313. var hrend = (px < 0) ? (self.getScrollLeft() >= self.page.maxw) : (self.getScrollLeft() <= 0);
  2314. if (hrend) { // preserve vertical scrolling
  2315. py = px;
  2316. px = 0;
  2317. }
  2318. }
  2319. }
  2320. // invert horizontal direction for rtl mode
  2321. if (self.isrtlmode) px = -px;
  2322. if (px) {
  2323. if (self.scrollmom) {
  2324. self.scrollmom.stop()
  2325. }
  2326. self.lastdeltax += px;
  2327. self.debounced("mousewheelx", function() {
  2328. var dt = self.lastdeltax;
  2329. self.lastdeltax = 0;
  2330. if (!self.rail.drag) {
  2331. self.doScrollLeftBy(dt)
  2332. }
  2333. }, 15);
  2334. }
  2335. if (py) {
  2336. if (self.opt.nativeparentscrolling && chkscroll && !self.ispage && !self.zoomactive) {
  2337. if (py < 0) {
  2338. if (self.getScrollTop() >= self.page.maxh) return true;
  2339. } else {
  2340. if (self.getScrollTop() <= 0) return true;
  2341. }
  2342. }
  2343. if (self.scrollmom) {
  2344. self.scrollmom.stop()
  2345. }
  2346. self.lastdeltay += py;
  2347. // self.debounced("mousewheely", function() {
  2348. self.synched("mousewheely", function() {
  2349. var dt = self.lastdeltay;
  2350. self.lastdeltay = 0;
  2351. if (!self.rail.drag) {
  2352. self.doScrollBy(dt)
  2353. }
  2354. }, 15);
  2355. }
  2356. e.stopImmediatePropagation();
  2357. return e.preventDefault();
  2358. };
  2359. this.onmousewheel = function(e) {
  2360. if (self.wheelprevented) return;
  2361. if (self.railslocked) {
  2362. self.debounced("checkunlock", self.resize, 250);
  2363. return true;
  2364. }
  2365. if (self.rail.drag) return self.cancelEvent(e);
  2366. if (self.opt.oneaxismousemode == "auto" && e.deltaX != 0) self.opt.oneaxismousemode = false; // check two-axis mouse support (not very elegant)
  2367. if (self.opt.oneaxismousemode && e.deltaX == 0) {
  2368. if (!self.rail.scrollable) {
  2369. if (self.railh && self.railh.scrollable) {
  2370. return self.onmousewheelhr(e);
  2371. } else {
  2372. return true;
  2373. }
  2374. }
  2375. }
  2376. var nw = +(new Date());
  2377. var chk = false;
  2378. if (self.opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
  2379. self.nativescrollingarea = self.isScrollable(e);
  2380. chk = true;
  2381. }
  2382. self.checkarea = nw;
  2383. if (self.nativescrollingarea) return true; // this isn't my business
  2384. var ret = execScrollWheel(e, false, chk);
  2385. if (ret) self.checkarea = 0;
  2386. return ret;
  2387. };
  2388. this.onmousewheelhr = function(e) {
  2389. if (self.wheelprevented) return;
  2390. if (self.railslocked || !self.railh.scrollable) return true;
  2391. if (self.rail.drag) return self.cancelEvent(e);
  2392. var nw = +(new Date());
  2393. var chk = false;
  2394. if (self.opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
  2395. self.nativescrollingarea = self.isScrollable(e);
  2396. chk = true;
  2397. }
  2398. self.checkarea = nw;
  2399. if (self.nativescrollingarea) return true; // this isn't my business
  2400. if (self.railslocked) return self.cancelEvent(e);
  2401. return execScrollWheel(e, true, chk);
  2402. };
  2403. this.stop = function() {
  2404. self.cancelScroll();
  2405. if (self.scrollmon) self.scrollmon.stop();
  2406. self.cursorfreezed = false;
  2407. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  2408. self.noticeCursor();
  2409. return self;
  2410. };
  2411. this.getTransitionSpeed = function(dif) {
  2412. var sp = Math.round(self.opt.scrollspeed * 10);
  2413. var ex = Math.min(sp, Math.round((dif / 20) * self.opt.scrollspeed));
  2414. return (ex > 20) ? ex : 0;
  2415. };
  2416. if (!self.opt.smoothscroll) {
  2417. this.doScrollLeft = function(x, spd) { //direct
  2418. var y = self.getScrollTop();
  2419. self.doScrollPos(x, y, spd);
  2420. };
  2421. this.doScrollTop = function(y, spd) { //direct
  2422. var x = self.getScrollLeft();
  2423. self.doScrollPos(x, y, spd);
  2424. };
  2425. this.doScrollPos = function(x, y, spd) { //direct
  2426. var nx = (x > self.page.maxw) ? self.page.maxw : x;
  2427. if (nx < 0) nx = 0;
  2428. var ny = (y > self.page.maxh) ? self.page.maxh : y;
  2429. if (ny < 0) ny = 0;
  2430. self.synched('scroll', function() {
  2431. self.setScrollTop(ny);
  2432. self.setScrollLeft(nx);
  2433. });
  2434. };
  2435. this.cancelScroll = function() {}; // direct
  2436. } else if (self.ishwscroll && cap.hastransition && self.opt.usetransition && !!self.opt.smoothscroll) {
  2437. this.prepareTransition = function(dif, istime) {
  2438. var ex = (istime) ? ((dif > 20) ? dif : 0) : self.getTransitionSpeed(dif);
  2439. var trans = (ex) ? cap.prefixstyle + 'transform ' + ex + 'ms ease-out' : '';
  2440. if (!self.lasttransitionstyle || self.lasttransitionstyle != trans) {
  2441. // console.log(trans);
  2442. self.lasttransitionstyle = trans;
  2443. self.doc.css(cap.transitionstyle, trans);
  2444. }
  2445. return ex;
  2446. };
  2447. this.doScrollLeft = function(x, spd) { //trans
  2448. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  2449. self.doScrollPos(x, y, spd);
  2450. };
  2451. this.doScrollTop = function(y, spd) { //trans
  2452. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  2453. self.doScrollPos(x, y, spd);
  2454. };
  2455. this.doScrollPos = function(x, y, spd) { //trans
  2456. var py = self.getScrollTop();
  2457. var px = self.getScrollLeft();
  2458. if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection
  2459. if (self.opt.bouncescroll == false) {
  2460. if (y < 0) y = 0;
  2461. else if (y > self.page.maxh) y = self.page.maxh;
  2462. if (x < 0) x = 0;
  2463. else if (x > self.page.maxw) x = self.page.maxw;
  2464. }
  2465. if (self.scrollrunning && x == self.newscrollx && y == self.newscrolly) return false;
  2466. self.newscrolly = y;
  2467. self.newscrollx = x;
  2468. self.newscrollspeed = spd || false;
  2469. if (self.timer) return false;
  2470. self.timer = setTimeout(function() {
  2471. var top = self.getScrollTop();
  2472. var lft = self.getScrollLeft();
  2473. var dst = {};
  2474. dst.x = x - lft;
  2475. dst.y = y - top;
  2476. dst.px = lft;
  2477. dst.py = top;
  2478. var dd = Math.round(Math.sqrt(Math.pow(dst.x, 2) + Math.pow(dst.y, 2)));
  2479. var ms = (self.newscrollspeed && self.newscrollspeed > 1) ? self.newscrollspeed : self.getTransitionSpeed(dd);
  2480. if (self.newscrollspeed && self.newscrollspeed <= 1) ms *= self.newscrollspeed;
  2481. self.prepareTransition(ms, true);
  2482. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2483. if (ms > 0) {
  2484. if (!self.scrollrunning && self.onscrollstart) {
  2485. var info = {
  2486. "type": "scrollstart",
  2487. "current": {
  2488. "x": lft,
  2489. "y": top
  2490. },
  2491. "request": {
  2492. "x": x,
  2493. "y": y
  2494. },
  2495. "end": {
  2496. "x": self.newscrollx,
  2497. "y": self.newscrolly
  2498. },
  2499. "speed": ms
  2500. };
  2501. self.onscrollstart.call(self, info);
  2502. }
  2503. if (cap.transitionend) {
  2504. if (!self.scrollendtrapped) {
  2505. self.scrollendtrapped = true;
  2506. self.bind(self.doc, cap.transitionend, self.onScrollTransitionEnd, false); //I have got to do something usefull!!
  2507. }
  2508. } else {
  2509. if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
  2510. self.scrollendtrapped = setTimeout(self.onScrollTransitionEnd, ms); // simulate transitionend event
  2511. }
  2512. var py = top;
  2513. var px = lft;
  2514. self.timerscroll = {
  2515. bz: new BezierClass(py, self.newscrolly, ms, 0, 0, 0.58, 1),
  2516. bh: new BezierClass(px, self.newscrollx, ms, 0, 0, 0.58, 1)
  2517. };
  2518. if (!self.cursorfreezed) self.timerscroll.tm = setInterval(function() {
  2519. self.showCursor(self.getScrollTop(), self.getScrollLeft())
  2520. }, 60);
  2521. }
  2522. self.synched("doScroll-set", function() {
  2523. self.timer = 0;
  2524. if (self.scrollendtrapped) self.scrollrunning = true;
  2525. self.setScrollTop(self.newscrolly);
  2526. self.setScrollLeft(self.newscrollx);
  2527. if (!self.scrollendtrapped) self.onScrollTransitionEnd();
  2528. });
  2529. }, 50);
  2530. };
  2531. this.cancelScroll = function() {
  2532. if (!self.scrollendtrapped) return true;
  2533. var py = self.getScrollTop();
  2534. var px = self.getScrollLeft();
  2535. self.scrollrunning = false;
  2536. if (!cap.transitionend) clearTimeout(cap.transitionend);
  2537. self.scrollendtrapped = false;
  2538. self._unbind(self.doc[0], cap.transitionend, self.onScrollTransitionEnd);
  2539. self.prepareTransition(0);
  2540. self.setScrollTop(py); // fire event onscroll
  2541. if (self.railh) self.setScrollLeft(px);
  2542. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2543. self.timerscroll = false;
  2544. self.cursorfreezed = false;
  2545. self.showCursor(py, px);
  2546. return self;
  2547. };
  2548. this.onScrollTransitionEnd = function() {
  2549. if (self.scrollendtrapped) self._unbind(self.doc[0], cap.transitionend, self.onScrollTransitionEnd);
  2550. self.scrollendtrapped = false;
  2551. self.prepareTransition(0);
  2552. if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
  2553. self.timerscroll = false;
  2554. var py = self.getScrollTop();
  2555. var px = self.getScrollLeft();
  2556. self.setScrollTop(py); // fire event onscroll
  2557. if (self.railh) self.setScrollLeft(px); // fire event onscroll left
  2558. self.noticeCursor(false, py, px);
  2559. self.cursorfreezed = false;
  2560. if (py < 0) py = 0
  2561. else if (py > self.page.maxh) py = self.page.maxh;
  2562. if (px < 0) px = 0
  2563. else if (px > self.page.maxw) px = self.page.maxw;
  2564. if ((py != self.newscrolly) || (px != self.newscrollx)) return self.doScrollPos(px, py, self.opt.snapbackspeed);
  2565. if (self.onscrollend && self.scrollrunning) {
  2566. self.triggerScrollEnd();
  2567. }
  2568. self.scrollrunning = false;
  2569. };
  2570. } else {
  2571. this.doScrollLeft = function(x, spd) { //no-trans
  2572. var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
  2573. self.doScrollPos(x, y, spd);
  2574. };
  2575. this.doScrollTop = function(y, spd) { //no-trans
  2576. var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
  2577. self.doScrollPos(x, y, spd);
  2578. };
  2579. this.doScrollPos = function(x, y, spd) { //no-trans
  2580. var y = ((typeof y == "undefined") || (y === false)) ? self.getScrollTop(true) : y;
  2581. if ((self.timer) && (self.newscrolly == y) && (self.newscrollx == x)) return true;
  2582. if (self.timer) clearAnimationFrame(self.timer);
  2583. self.timer = 0;
  2584. var py = self.getScrollTop();
  2585. var px = self.getScrollLeft();
  2586. if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection
  2587. self.newscrolly = y;
  2588. self.newscrollx = x;
  2589. if (!self.bouncescroll || !self.rail.visibility) {
  2590. if (self.newscrolly < 0) {
  2591. self.newscrolly = 0;
  2592. } else if (self.newscrolly > self.page.maxh) {
  2593. self.newscrolly = self.page.maxh;
  2594. }
  2595. }
  2596. if (!self.bouncescroll || !self.railh.visibility) {
  2597. if (self.newscrollx < 0) {
  2598. self.newscrollx = 0;
  2599. } else if (self.newscrollx > self.page.maxw) {
  2600. self.newscrollx = self.page.maxw;
  2601. }
  2602. }
  2603. self.dst = {};
  2604. self.dst.x = x - px;
  2605. self.dst.y = y - py;
  2606. self.dst.px = px;
  2607. self.dst.py = py;
  2608. var dst = Math.round(Math.sqrt(Math.pow(self.dst.x, 2) + Math.pow(self.dst.y, 2)));
  2609. self.dst.ax = self.dst.x / dst;
  2610. self.dst.ay = self.dst.y / dst;
  2611. var pa = 0;
  2612. var pe = dst;
  2613. if (self.dst.x == 0) {
  2614. pa = py;
  2615. pe = y;
  2616. self.dst.ay = 1;
  2617. self.dst.py = 0;
  2618. } else if (self.dst.y == 0) {
  2619. pa = px;
  2620. pe = x;
  2621. self.dst.ax = 1;
  2622. self.dst.px = 0;
  2623. }
  2624. var ms = self.getTransitionSpeed(dst);
  2625. if (spd && spd <= 1) ms *= spd;
  2626. if (ms > 0) {
  2627. self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe, ms) : new BezierClass(pa, pe, ms, 0, 1, 0, 1);
  2628. } else {
  2629. self.bzscroll = false;
  2630. }
  2631. if (self.timer) return;
  2632. if ((py == self.page.maxh && y >= self.page.maxh) || (px == self.page.maxw && x >= self.page.maxw)) self.checkContentSize();
  2633. var sync = 1;
  2634. function scrolling() {
  2635. if (self.cancelAnimationFrame) return true;
  2636. self.scrollrunning = true;
  2637. sync = 1 - sync;
  2638. if (sync) return (self.timer = setAnimationFrame(scrolling) || 1);
  2639. var done = 0;
  2640. var sx, sy;
  2641. var sc = sy = self.getScrollTop();
  2642. if (self.dst.ay) {
  2643. sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow() * self.dst.ay) : self.newscrolly;
  2644. var dr = sc - sy;
  2645. if ((dr < 0 && sc < self.newscrolly) || (dr > 0 && sc > self.newscrolly)) sc = self.newscrolly;
  2646. self.setScrollTop(sc);
  2647. if (sc == self.newscrolly) done = 1;
  2648. } else {
  2649. done = 1;
  2650. }
  2651. var scx = sx = self.getScrollLeft();
  2652. if (self.dst.ax) {
  2653. scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow() * self.dst.ax) : self.newscrollx;
  2654. var dr = scx - sx;
  2655. if ((dr < 0 && scx < self.newscrollx) || (dr > 0 && scx > self.newscrollx)) scx = self.newscrollx;
  2656. self.setScrollLeft(scx);
  2657. if (scx == self.newscrollx) done += 1;
  2658. } else {
  2659. done += 1;
  2660. }
  2661. if (done == 2) {
  2662. self.timer = 0;
  2663. self.cursorfreezed = false;
  2664. self.bzscroll = false;
  2665. self.scrollrunning = false;
  2666. if (sc < 0) sc = 0;
  2667. else if (sc > self.page.maxh) sc = self.page.maxh;
  2668. if (scx < 0) scx = 0;
  2669. else if (scx > self.page.maxw) scx = self.page.maxw;
  2670. if ((scx != self.newscrollx) || (sc != self.newscrolly)) self.doScrollPos(scx, sc);
  2671. else {
  2672. if (self.onscrollend) {
  2673. self.triggerScrollEnd();
  2674. }
  2675. }
  2676. } else {
  2677. self.timer = setAnimationFrame(scrolling) || 1;
  2678. }
  2679. };
  2680. self.cancelAnimationFrame = false;
  2681. self.timer = 1;
  2682. if (self.onscrollstart && !self.scrollrunning) {
  2683. var info = {
  2684. "type": "scrollstart",
  2685. "current": {
  2686. "x": px,
  2687. "y": py
  2688. },
  2689. "request": {
  2690. "x": x,
  2691. "y": y
  2692. },
  2693. "end": {
  2694. "x": self.newscrollx,
  2695. "y": self.newscrolly
  2696. },
  2697. "speed": ms
  2698. };
  2699. self.onscrollstart.call(self, info);
  2700. }
  2701. scrolling();
  2702. if ((py == self.page.maxh && y >= py) || (px == self.page.maxw && x >= px)) self.checkContentSize();
  2703. self.noticeCursor();
  2704. };
  2705. this.cancelScroll = function() {
  2706. if (self.timer) clearAnimationFrame(self.timer);
  2707. self.timer = 0;
  2708. self.bzscroll = false;
  2709. self.scrollrunning = false;
  2710. return self;
  2711. };
  2712. }
  2713. this.doScrollBy = function(stp, relative) {
  2714. var ny = 0;
  2715. if (relative) {
  2716. ny = Math.floor((self.scroll.y - stp) * self.scrollratio.y)
  2717. } else {
  2718. var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
  2719. ny = sy - stp;
  2720. }
  2721. if (self.bouncescroll) {
  2722. var haf = Math.round(self.view.h / 2);
  2723. if (ny < -haf) ny = -haf
  2724. else if (ny > (self.page.maxh + haf)) ny = (self.page.maxh + haf);
  2725. }
  2726. self.cursorfreezed = false;
  2727. var py = self.getScrollTop(true);
  2728. if (ny < 0 && py <= 0) return self.noticeCursor();
  2729. else if (ny > self.page.maxh && py >= self.page.maxh) {
  2730. self.checkContentSize();
  2731. return self.noticeCursor();
  2732. }
  2733. self.doScrollTop(ny);
  2734. };
  2735. this.doScrollLeftBy = function(stp, relative) {
  2736. var nx = 0;
  2737. if (relative) {
  2738. nx = Math.floor((self.scroll.x - stp) * self.scrollratio.x)
  2739. } else {
  2740. var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
  2741. nx = sx - stp;
  2742. }
  2743. if (self.bouncescroll) {
  2744. var haf = Math.round(self.view.w / 2);
  2745. if (nx < -haf) nx = -haf;
  2746. else if (nx > (self.page.maxw + haf)) nx = (self.page.maxw + haf);
  2747. }
  2748. self.cursorfreezed = false;
  2749. var px = self.getScrollLeft(true);
  2750. if (nx < 0 && px <= 0) return self.noticeCursor();
  2751. else if (nx > self.page.maxw && px >= self.page.maxw) return self.noticeCursor();
  2752. self.doScrollLeft(nx);
  2753. };
  2754. this.doScrollTo = function(pos, relative) {
  2755. var ny = (relative) ? Math.round(pos * self.scrollratio.y) : pos;
  2756. if (ny < 0) ny = 0;
  2757. else if (ny > self.page.maxh) ny = self.page.maxh;
  2758. self.cursorfreezed = false;
  2759. self.doScrollTop(pos);
  2760. };
  2761. this.checkContentSize = function() {
  2762. var pg = self.getContentSize();
  2763. if ((pg.h != self.page.h) || (pg.w != self.page.w)) self.resize(false, pg);
  2764. };
  2765. self.onscroll = function(e) {
  2766. if (self.rail.drag) return;
  2767. if (!self.cursorfreezed) {
  2768. self.synched('scroll', function() {
  2769. self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
  2770. if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1 / self.scrollratio.x));
  2771. self.noticeCursor();
  2772. });
  2773. }
  2774. };
  2775. self.bind(self.docscroll, "scroll", self.onscroll);
  2776. this.doZoomIn = function(e) {
  2777. if (self.zoomactive) return;
  2778. self.zoomactive = true;
  2779. self.zoomrestore = {
  2780. style: {}
  2781. };
  2782. var lst = ['position', 'top', 'left', 'zIndex', 'backgroundColor', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight'];
  2783. var win = self.win[0].style;
  2784. for (var a in lst) {
  2785. var pp = lst[a];
  2786. self.zoomrestore.style[pp] = (typeof win[pp] != "undefined") ? win[pp] : '';
  2787. }
  2788. self.zoomrestore.style.width = self.win.css('width');
  2789. self.zoomrestore.style.height = self.win.css('height');
  2790. self.zoomrestore.padding = {
  2791. w: self.win.outerWidth() - self.win.width(),
  2792. h: self.win.outerHeight() - self.win.height()
  2793. };
  2794. if (cap.isios4) {
  2795. self.zoomrestore.scrollTop = $(window).scrollTop();
  2796. $(window).scrollTop(0);
  2797. }
  2798. self.win.css({
  2799. "position": (cap.isios4) ? "absolute" : "fixed",
  2800. "top": 0,
  2801. "left": 0,
  2802. "z-index": globalmaxzindex + 100,
  2803. "margin": "0px"
  2804. });
  2805. var bkg = self.win.css("backgroundColor");
  2806. if (bkg == "" || /transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor", "#fff");
  2807. self.rail.css({
  2808. "z-index": globalmaxzindex + 101
  2809. });
  2810. self.zoom.css({
  2811. "z-index": globalmaxzindex + 102
  2812. });
  2813. self.zoom.css('backgroundPosition', '0px -18px');
  2814. self.resizeZoom();
  2815. if (self.onzoomin) self.onzoomin.call(self);
  2816. return self.cancelEvent(e);
  2817. };
  2818. this.doZoomOut = function(e) {
  2819. if (!self.zoomactive) return;
  2820. self.zoomactive = false;
  2821. self.win.css("margin", "");
  2822. self.win.css(self.zoomrestore.style);
  2823. if (cap.isios4) {
  2824. $(window).scrollTop(self.zoomrestore.scrollTop);
  2825. }
  2826. self.rail.css({
  2827. "z-index": self.zindex
  2828. });
  2829. self.zoom.css({
  2830. "z-index": self.zindex
  2831. });
  2832. self.zoomrestore = false;
  2833. self.zoom.css('backgroundPosition', '0px 0px');
  2834. self.onResize();
  2835. if (self.onzoomout) self.onzoomout.call(self);
  2836. return self.cancelEvent(e);
  2837. };
  2838. this.doZoom = function(e) {
  2839. return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
  2840. };
  2841. this.resizeZoom = function() {
  2842. if (!self.zoomactive) return;
  2843. var py = self.getScrollTop(); //preserve scrolling position
  2844. self.win.css({
  2845. width: $(window).width() - self.zoomrestore.padding.w + "px",
  2846. height: $(window).height() - self.zoomrestore.padding.h + "px"
  2847. });
  2848. self.onResize();
  2849. self.setScrollTop(Math.min(self.page.maxh, py));
  2850. };
  2851. this.init();
  2852. $.nicescroll.push(this);
  2853. };
  2854. // Inspired by the work of Kin Blas
  2855. // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
  2856. var ScrollMomentumClass2D = function(nc) {
  2857. var self = this;
  2858. this.nc = nc;
  2859. this.lastx = 0;
  2860. this.lasty = 0;
  2861. this.speedx = 0;
  2862. this.speedy = 0;
  2863. this.lasttime = 0;
  2864. this.steptime = 0;
  2865. this.snapx = false;
  2866. this.snapy = false;
  2867. this.demulx = 0;
  2868. this.demuly = 0;
  2869. this.lastscrollx = -1;
  2870. this.lastscrolly = -1;
  2871. this.chkx = 0;
  2872. this.chky = 0;
  2873. this.timer = 0;
  2874. this.time = function() {
  2875. return +new Date(); //beautifull hack
  2876. };
  2877. this.reset = function(px, py) {
  2878. self.stop();
  2879. var now = self.time();
  2880. self.steptime = 0;
  2881. self.lasttime = now;
  2882. self.speedx = 0;
  2883. self.speedy = 0;
  2884. self.lastx = px;
  2885. self.lasty = py;
  2886. self.lastscrollx = -1;
  2887. self.lastscrolly = -1;
  2888. };
  2889. this.update = function(px, py) {
  2890. var now = self.time();
  2891. self.steptime = now - self.lasttime;
  2892. self.lasttime = now;
  2893. var dy = py - self.lasty;
  2894. var dx = px - self.lastx;
  2895. var sy = self.nc.getScrollTop();
  2896. var sx = self.nc.getScrollLeft();
  2897. var newy = sy + dy;
  2898. var newx = sx + dx;
  2899. self.snapx = (newx < 0) || (newx > self.nc.page.maxw);
  2900. self.snapy = (newy < 0) || (newy > self.nc.page.maxh);
  2901. self.speedx = dx;
  2902. self.speedy = dy;
  2903. self.lastx = px;
  2904. self.lasty = py;
  2905. };
  2906. this.stop = function() {
  2907. self.nc.unsynched("domomentum2d");
  2908. if (self.timer) clearTimeout(self.timer);
  2909. self.timer = 0;
  2910. self.lastscrollx = -1;
  2911. self.lastscrolly = -1;
  2912. };
  2913. this.doSnapy = function(nx, ny) {
  2914. var snap = false;
  2915. if (ny < 0) {
  2916. ny = 0;
  2917. snap = true;
  2918. } else if (ny > self.nc.page.maxh) {
  2919. ny = self.nc.page.maxh;
  2920. snap = true;
  2921. }
  2922. if (nx < 0) {
  2923. nx = 0;
  2924. snap = true;
  2925. } else if (nx > self.nc.page.maxw) {
  2926. nx = self.nc.page.maxw;
  2927. snap = true;
  2928. }
  2929. (snap) ? self.nc.doScrollPos(nx, ny, self.nc.opt.snapbackspeed): self.nc.triggerScrollEnd();
  2930. };
  2931. this.doMomentum = function(gp) {
  2932. var t = self.time();
  2933. var l = (gp) ? t + gp : self.lasttime;
  2934. var sl = self.nc.getScrollLeft();
  2935. var st = self.nc.getScrollTop();
  2936. var pageh = self.nc.page.maxh;
  2937. var pagew = self.nc.page.maxw;
  2938. self.speedx = (pagew > 0) ? Math.min(60, self.speedx) : 0;
  2939. self.speedy = (pageh > 0) ? Math.min(60, self.speedy) : 0;
  2940. var chk = l && (t - l) <= 60;
  2941. if ((st < 0) || (st > pageh) || (sl < 0) || (sl > pagew)) chk = false;
  2942. var sy = (self.speedy && chk) ? self.speedy : false;
  2943. var sx = (self.speedx && chk) ? self.speedx : false;
  2944. if (sy || sx) {
  2945. var tm = Math.max(16, self.steptime); //timeout granularity
  2946. if (tm > 50) { // do smooth
  2947. var xm = tm / 50;
  2948. self.speedx *= xm;
  2949. self.speedy *= xm;
  2950. tm = 50;
  2951. }
  2952. self.demulxy = 0;
  2953. self.lastscrollx = self.nc.getScrollLeft();
  2954. self.chkx = self.lastscrollx;
  2955. self.lastscrolly = self.nc.getScrollTop();
  2956. self.chky = self.lastscrolly;
  2957. var nx = self.lastscrollx;
  2958. var ny = self.lastscrolly;
  2959. var onscroll = function() {
  2960. var df = ((self.time() - t) > 600) ? 0.04 : 0.02;
  2961. if (self.speedx) {
  2962. nx = Math.floor(self.lastscrollx - (self.speedx * (1 - self.demulxy)));
  2963. self.lastscrollx = nx;
  2964. if ((nx < 0) || (nx > pagew)) df = 0.10;
  2965. }
  2966. if (self.speedy) {
  2967. ny = Math.floor(self.lastscrolly - (self.speedy * (1 - self.demulxy)));
  2968. self.lastscrolly = ny;
  2969. if ((ny < 0) || (ny > pageh)) df = 0.10;
  2970. }
  2971. self.demulxy = Math.min(1, self.demulxy + df);
  2972. self.nc.synched("domomentum2d", function() {
  2973. if (self.speedx) {
  2974. var scx = self.nc.getScrollLeft();
  2975. // if (scx != self.chkx) self.stop();
  2976. self.chkx = nx;
  2977. self.nc.setScrollLeft(nx);
  2978. }
  2979. if (self.speedy) {
  2980. var scy = self.nc.getScrollTop();
  2981. // if (scy != self.chky) self.stop();
  2982. self.chky = ny;
  2983. self.nc.setScrollTop(ny);
  2984. }
  2985. if (!self.timer) {
  2986. self.nc.hideCursor();
  2987. self.doSnapy(nx, ny);
  2988. }
  2989. });
  2990. if (self.demulxy < 1) {
  2991. self.timer = setTimeout(onscroll, tm);
  2992. } else {
  2993. self.stop();
  2994. self.nc.hideCursor();
  2995. self.doSnapy(nx, ny);
  2996. }
  2997. };
  2998. onscroll();
  2999. } else {
  3000. self.doSnapy(self.nc.getScrollLeft(), self.nc.getScrollTop());
  3001. }
  3002. }
  3003. };
  3004. // override jQuery scrollTop
  3005. var _scrollTop = jQuery.fn.scrollTop; // preserve original function
  3006. jQuery.cssHooks["pageYOffset"] = {
  3007. get: function(elem, computed, extra) {
  3008. var nice = $.data(elem, '__nicescroll') || false;
  3009. return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
  3010. },
  3011. set: function(elem, value) {
  3012. var nice = $.data(elem, '__nicescroll') || false;
  3013. (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)): _scrollTop.call(elem, value);
  3014. return this;
  3015. }
  3016. };
  3017. /*
  3018. $.fx.step["scrollTop"] = function(fx){
  3019. $.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
  3020. };
  3021. */
  3022. jQuery.fn.scrollTop = function(value) {
  3023. if (typeof value == "undefined") {
  3024. var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
  3025. return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
  3026. } else {
  3027. return this.each(function() {
  3028. var nice = $.data(this, '__nicescroll') || false;
  3029. (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)): _scrollTop.call($(this), value);
  3030. });
  3031. }
  3032. };
  3033. // override jQuery scrollLeft
  3034. var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
  3035. $.cssHooks.pageXOffset = {
  3036. get: function(elem, computed, extra) {
  3037. var nice = $.data(elem, '__nicescroll') || false;
  3038. return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
  3039. },
  3040. set: function(elem, value) {
  3041. var nice = $.data(elem, '__nicescroll') || false;
  3042. (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)): _scrollLeft.call(elem, value);
  3043. return this;
  3044. }
  3045. };
  3046. /*
  3047. $.fx.step["scrollLeft"] = function(fx){
  3048. $.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
  3049. };
  3050. */
  3051. jQuery.fn.scrollLeft = function(value) {
  3052. if (typeof value == "undefined") {
  3053. var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
  3054. return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
  3055. } else {
  3056. return this.each(function() {
  3057. var nice = $.data(this, '__nicescroll') || false;
  3058. (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)): _scrollLeft.call($(this), value);
  3059. });
  3060. }
  3061. };
  3062. var NiceScrollArray = function(doms) {
  3063. var self = this;
  3064. this.length = 0;
  3065. this.name = "nicescrollarray";
  3066. this.each = function(fn) {
  3067. for (var a = 0, i = 0; a < self.length; a++) fn.call(self[a], i++);
  3068. return self;
  3069. };
  3070. this.push = function(nice) {
  3071. self[self.length] = nice;
  3072. self.length++;
  3073. };
  3074. this.eq = function(idx) {
  3075. return self[idx];
  3076. };
  3077. if (doms) {
  3078. for (var a = 0; a < doms.length; a++) {
  3079. var nice = $.data(doms[a], '__nicescroll') || false;
  3080. if (nice) {
  3081. this[this.length] = nice;
  3082. this.length++;
  3083. }
  3084. };
  3085. }
  3086. return this;
  3087. };
  3088. function mplex(el, lst, fn) {
  3089. for (var a = 0; a < lst.length; a++) fn(el, lst[a]);
  3090. };
  3091. mplex(
  3092. NiceScrollArray.prototype, ['show', 'hide', 'toggle', 'onResize', 'resize', 'remove', 'stop', 'doScrollPos'],
  3093. function(e, n) {
  3094. e[n] = function() {
  3095. var args = arguments;
  3096. return this.each(function() {
  3097. this[n].apply(this, args);
  3098. });
  3099. };
  3100. }
  3101. );
  3102. jQuery.fn.getNiceScroll = function(index) {
  3103. if (typeof index == "undefined") {
  3104. return new NiceScrollArray(this);
  3105. } else {
  3106. var nice = this[index] && $.data(this[index], '__nicescroll') || false;
  3107. return nice;
  3108. }
  3109. };
  3110. jQuery.extend(jQuery.expr[':'], {
  3111. nicescroll: function(a) {
  3112. return ($.data(a, '__nicescroll')) ? true : false;
  3113. }
  3114. });
  3115. $.fn.niceScroll = function(wrapper, opt) {
  3116. if (typeof opt == "undefined") {
  3117. if ((typeof wrapper == "object") && !("jquery" in wrapper)) {
  3118. opt = wrapper;
  3119. wrapper = false;
  3120. }
  3121. }
  3122. opt = $.extend({},opt); // cloning
  3123. var ret = new NiceScrollArray();
  3124. if (typeof opt == "undefined") opt = {};
  3125. if (wrapper || false) {
  3126. opt.doc = $(wrapper);
  3127. opt.win = $(this);
  3128. }
  3129. var docundef = !("doc" in opt);
  3130. if (!docundef && !("win" in opt)) opt.win = $(this);
  3131. this.each(function() {
  3132. var nice = $(this).data('__nicescroll') || false;
  3133. if (!nice) {
  3134. opt.doc = (docundef) ? $(this) : opt.doc;
  3135. nice = new NiceScrollClass(opt, $(this));
  3136. $(this).data('__nicescroll', nice);
  3137. }
  3138. ret.push(nice);
  3139. });
  3140. return (ret.length == 1) ? ret[0] : ret;
  3141. };
  3142. window.NiceScroll = {
  3143. getjQuery: function() {
  3144. return jQuery
  3145. }
  3146. };
  3147. if (!$.nicescroll) {
  3148. $.nicescroll = new NiceScrollArray();
  3149. $.nicescroll.options = _globaloptions;
  3150. }
  3151. }));