jquery.nicescroll.js 122 KB

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