jquery.nicescroll.js 122 KB

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