jquery.nicescroll.js 122 KB

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