/* jquery.nicescroll -- version 3.7.6 -- copyright 2017-07-19 inuyaksa*2017 -- licensed under the mit -- -- https://nicescroll.areaaperta.com/ -- https://github.com/inuyaksa/jquery.nicescroll -- */ /* jshint expr: true */ (function (factory) { if (typeof define === 'function' && define.amd) { // amd. register as anonymous module. define(['jquery'], factory); } else if (typeof exports === 'object') { // node/commonjs. module.exports = factory(require('jquery')); } else { // browser globals. factory(jquery); } }(function (jquery) { "use strict"; // globals var domfocus = false, mousefocus = false, tabindexcounter = 0, ascrailcounter = 2000, globalmaxzindex = 0; var $ = jquery, // sandbox _doc = document, _win = window, $window = $(_win); var delegatevents = []; // http://stackoverflow.com/questions/2161159/get-script-path function getscriptpath() { var scripts = _doc.currentscript || (function () { var s = _doc.getelementsbytagname('script'); return (s.length) ? s[s.length - 1] : false; })(); var path = scripts ? scripts.src.split('?')[0] : ''; return (path.split('/').length > 0) ? path.split('/').slice(0, -1).join('/') + '/' : ''; } // based on code by paul irish https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ var setanimationframe = _win.requestanimationframe || _win.webkitrequestanimationframe || _win.mozrequestanimationframe || false; var clearanimationframe = _win.cancelanimationframe || _win.webkitcancelanimationframe || _win.mozcancelanimationframe || false; if (!setanimationframe) { var anilasttime = 0; setanimationframe = function (callback, element) { var currtime = new date().gettime(); var timetocall = math.max(0, 16 - (currtime - anilasttime)); var id = _win.settimeout(function () { callback(currtime + timetocall); }, timetocall); anilasttime = currtime + timetocall; return id; }; clearanimationframe = function (id) { _win.cleartimeout(id); }; } else { if (!_win.cancelanimationframe) clearanimationframe = function (id) { }; } var clsmutationobserver = _win.mutationobserver || _win.webkitmutationobserver || false; var now = date.now || function () { return new date().gettime(); }; var _globaloptions = { zindex: "auto", cursoropacitymin: 0, cursoropacitymax: 1, cursorcolor: "#424242", cursorwidth: "6px", cursorborder: "1px solid #fff", cursorborderradius: "5px", scrollspeed: 40, mousescrollstep: 9 * 3, touchbehavior: false, // deprecated emulatetouch: false, // replacing touchbehavior hwacceleration: true, usetransition: true, boxzoom: false, dblclickzoom: true, gesturezoom: true, grabcursorenabled: true, autohidemode: true, background: "", iframeautoresize: true, cursorminheight: 32, preservenativescrolling: true, railoffset: false, railhoffset: false, bouncescroll: true, spacebarenabled: true, railpadding: { top: 0, right: 0, left: 0, bottom: 0 }, disableoutline: true, horizrailenabled: true, railalign: "right", railvalign: "bottom", enabletranslate3d: true, enablemousewheel: true, enablekeyboard: true, smoothscroll: true, sensitiverail: true, enablemouselockapi: true, // cursormaxheight:false, cursorfixedheight: false, directionlockdeadzone: 6, hidecursordelay: 400, nativeparentscrolling: true, enablescrollonselection: true, overflowx: true, overflowy: true, cursordragspeed: 0.3, rtlmode: "auto", cursordragontouch: false, oneaxismousemode: "auto", scriptpath: getscriptpath(), preventmultitouchscrolling: true, disablemutationobserver: false, enableobserver: true, scrollbarid: false }; var browserdetected = false; var getbrowserdetection = function () { if (browserdetected) return browserdetected; var _el = _doc.createelement('div'), _style = _el.style, _agent = navigator.useragent, _platform = navigator.platform, d = {}; d.haspointerlock = "pointerlockelement" in _doc || "webkitpointerlockelement" in _doc || "mozpointerlockelement" in _doc; d.isopera = ("opera" in _win); // 12- d.isopera12 = (d.isopera && ("getusermedia" in navigator)); d.isoperamini = (object.prototype.tostring.call(_win.operamini) === "[object operamini]"); d.isie = (("all" in _doc) && ("attachevent" in _el) && !d.isopera); //ie10- d.isieold = (d.isie && !("msinterpolationmode" in _style)); // ie6 and older d.isie7 = d.isie && !d.isieold && (!("documentmode" in _doc) || (_doc.documentmode === 7)); d.isie8 = d.isie && ("documentmode" in _doc) && (_doc.documentmode === 8); d.isie9 = d.isie && ("performance" in _win) && (_doc.documentmode === 9); d.isie10 = d.isie && ("performance" in _win) && (_doc.documentmode === 10); d.isie11 = ("msrequestfullscreen" in _el) && (_doc.documentmode >= 11); // ie11+ d.ismsedge = ("mscredentials" in _win); // ms edge 14+ d.ismozilla = ("mozappearance" in _style); d.iswebkit = !d.ismsedge && ("webkitappearance" in _style); d.ischrome = d.iswebkit && ("chrome" in _win); d.ischrome38 = (d.ischrome && ("touchaction" in _style)); // behavior changed in touch emulation d.ischrome22 = (!d.ischrome38) && (d.ischrome && d.haspointerlock); d.ischrome26 = (!d.ischrome38) && (d.ischrome && ("transition" in _style)); // issue with transform detection (maintain prefix) d.cantouch = ("ontouchstart" in _doc.documentelement) || ("ontouchstart" in _win); // with detection for chrome touch emulation d.hasw3ctouch = (_win.pointerevent || false) && ((navigator.maxtouchpoints > 0) || (navigator.msmaxtouchpoints > 0)); //ie11 pointer events, following w3c pointer events spec d.hasmstouch = (!d.hasw3ctouch) && (_win.mspointerevent || false); // ie10 pointer events d.ismac = /^mac$/i.test(_platform); d.isios = d.cantouch && /iphone|ipad|ipod/i.test(_platform); d.isios4 = d.isios && !("seal" in object); d.isios7 = d.isios && ("webkithidden" in _doc); //ios 7+ d.isios8 = d.isios && ("hidden" in _doc); //ios 8+ d.isios10 = d.isios && _win.proxy; //ios 10+ d.isandroid = (/android/i.test(_agent)); d.haseventlistener = ("addeventlistener" in _el); d.trstyle = false; d.hastransform = false; d.hastranslate3d = false; d.transitionstyle = false; d.hastransition = false; d.transitionend = false; d.trstyle = "transform"; d.hastransform = ("transform" in _style) || (function () { var check = ['mstransform', 'webkittransform', 'moztransform', 'otransform']; for (var a = 0, c = check.length; a < c; a++) { if (_style[check[a]] !== undefined) { d.trstyle = check[a]; break; } } d.hastransform = (!!d.trstyle); })(); if (d.hastransform) { _style[d.trstyle] = "translate3d(1px,2px,3px)"; d.hastranslate3d = /translate3d/.test(_style[d.trstyle]); } d.transitionstyle = "transition"; d.prefixstyle = ''; d.transitionend = "transitionend"; d.hastransition = ("transition" in _style) || (function () { d.transitionend = false; var check = ['webkittransition', 'mstransition', 'moztransition', 'otransition', 'otransition', 'khtmltransition']; var prefix = ['-webkit-', '-ms-', '-moz-', '-o-', '-o', '-khtml-']; var evs = ['webkittransitionend', 'mstransitionend', 'transitionend', 'otransitionend', 'otransitionend', 'khtmltransitionend']; for (var a = 0, c = check.length; a < c; a++) { if (check[a] in _style) { d.transitionstyle = check[a]; d.prefixstyle = prefix[a]; d.transitionend = evs[a]; break; } } if (d.ischrome26) d.prefixstyle = prefix[1]; // always use prefix d.hastransition = (d.transitionstyle); })(); function detectcursorgrab() { var lst = ['grab', '-webkit-grab', '-moz-grab']; if ((d.ischrome && !d.ischrome38) || d.isie) lst = []; // force setting for ie returns false positive and chrome cursor bug for (var a = 0, l = lst.length; a < l; a++) { var p = lst[a]; _style.cursor = p; if (_style.cursor == p) return p; } return 'url(https://cdnjs.cloudflare.com/ajax/libs/slider-pro/1.3.0/css/images/openhand.cur),n-resize'; // thanks to https://cdnjs.com/ for the openhand cursor! } d.cursorgrabvalue = detectcursorgrab(); d.hasmousecapture = ("setcapture" in _el); d.hasmutationobserver = (clsmutationobserver !== false); _el = null; //memory released browserdetected = d; return d; }; var nicescrollclass = function (myopt, me) { var self = this; this.version = '3.7.6'; this.name = 'nicescroll'; this.me = me; var $body = $("body"); var opt = this.opt = { doc: $body, win: false }; $.extend(opt, _globaloptions); // clone opts // options for internal use opt.snapbackspeed = 80; if (myopt || false) { for (var a in opt) { if (myopt[a] !== undefined) opt[a] = myopt[a]; } } if (opt.disablemutationobserver) clsmutationobserver = false; this.doc = opt.doc; this.iddoc = (this.doc && this.doc[0]) ? this.doc[0].id || '' : ''; this.ispage = /^body|html/.test((opt.win) ? opt.win[0].nodename : this.doc[0].nodename); this.haswrapper = (opt.win !== false); this.win = opt.win || (this.ispage ? $window : this.doc); this.docscroll = (this.ispage && !this.haswrapper) ? $window : this.win; this.body = $body; this.viewport = false; this.isfixed = false; this.iframe = false; this.isiframe = ((this.doc[0].nodename == 'iframe') && (this.win[0].nodename == 'iframe')); this.istextarea = (this.win[0].nodename == 'textarea'); this.forcescreen = false; //force to use screen position on events this.canshowonmouseevent = (opt.autohidemode != "scroll"); // events jump table this.onmousedown = false; this.onmouseup = false; this.onmousemove = false; this.onmousewheel = false; this.onkeypress = false; this.ongesturezoom = false; this.onclick = false; // nicescroll custom events this.onscrollstart = false; this.onscrollend = false; this.onscrollcancel = false; this.onzoomin = false; this.onzoomout = false; // let's start! this.view = false; this.page = false; this.scroll = { x: 0, y: 0 }; this.scrollratio = { x: 0, y: 0 }; this.cursorheight = 20; this.scrollvaluemax = 0; // http://dev.w3.org/csswg/css-writing-modes-3/#logical-to-physical // http://dev.w3.org/csswg/css-writing-modes-3/#svg-writing-mode if (opt.rtlmode == "auto") { var target = this.win[0] == _win ? this.body : this.win; var writingmode = target.css("writing-mode") || target.css("-webkit-writing-mode") || target.css("-ms-writing-mode") || target.css("-moz-writing-mode"); if (writingmode == "horizontal-tb" || writingmode == "lr-tb" || writingmode === "") { this.isrtlmode = (target.css("direction") == "rtl"); this.isvertical = false; } else { this.isrtlmode = (writingmode == "vertical-rl" || writingmode == "tb" || writingmode == "tb-rl" || writingmode == "rl-tb"); this.isvertical = (writingmode == "vertical-rl" || writingmode == "tb" || writingmode == "tb-rl"); } } else { this.isrtlmode = (opt.rtlmode === true); this.isvertical = false; } // this.checkrtlmode = false; this.scrollrunning = false; this.scrollmom = false; this.observer = false; // observer div changes this.observerremover = false; // observer on parent for remove detection this.observerbody = false; // observer on body for position change if (opt.scrollbarid !== false) { this.id = opt.scrollbarid; } else { do { this.id = "ascrail" + (ascrailcounter++); } while (_doc.getelementbyid(this.id)); } this.rail = false; this.cursor = false; this.cursorfreezed = false; this.selectiondrag = false; this.zoom = false; this.zoomactive = false; this.hasfocus = false; this.hasmousefocus = false; //this.visibility = true; this.railslocked = false; // locked by resize this.locked = false; // prevent lost of locked status sets by user this.hidden = false; // rails always hidden this.cursoractive = true; // user can interact with cursors this.wheelprevented = false; //prevent mousewheel event this.overflowx = opt.overflowx; this.overflowy = opt.overflowy; this.nativescrollingarea = false; this.checkarea = 0; this.events = []; // event list for unbind this.saved = {}; // style saved this.delaylist = {}; this.synclist = {}; this.lastdeltax = 0; this.lastdeltay = 0; this.detected = getbrowserdetection(); var cap = $.extend({}, this.detected); this.canhwscroll = (cap.hastransform && opt.hwacceleration); this.ishwscroll = (this.canhwscroll && self.haswrapper); if (!this.isrtlmode) { this.hasreversehr = false; } else if (this.isvertical) { // rtl mode with reverse horizontal axis this.hasreversehr = !(cap.iswebkit || cap.isie || cap.isie11); } else { this.hasreversehr = !(cap.iswebkit || (cap.isie && !cap.isie10 && !cap.isie11)); } this.istouchcapable = false; // desktop devices with touch screen support //## check webkit-based desktop with touch support //## + firefox 18 nightly build (desktop) false positive (or desktop with touch support) if (!cap.cantouch && (cap.hasw3ctouch || cap.hasmstouch)) { // desktop device with multiple input this.istouchcapable = true; } else if (cap.cantouch && !cap.isios && !cap.isandroid && (cap.iswebkit || cap.ismozilla)) { this.istouchcapable = true; } //## disable mouselock api on user request if (!opt.enablemouselockapi) { cap.hasmousecapture = false; cap.haspointerlock = false; } this.debounced = function (name, fn, tm) { if (!self) return; var dd = self.delaylist[name] || false; if (!dd) { self.delaylist[name] = { h: setanimationframe(function () { self.delaylist[name].fn.call(self); self.delaylist[name] = false; }, tm) }; fn.call(self); } self.delaylist[name].fn = fn; }; this.synched = function (name, fn) { if (self.synclist[name]) self.synclist[name] = fn; else { self.synclist[name] = fn; setanimationframe(function () { if (!self) return; self.synclist[name] && self.synclist[name].call(self); self.synclist[name] = null; }); } }; this.unsynched = function (name) { if (self.synclist[name]) self.synclist[name] = false; }; this.css = function (el, pars) { // save & set for (var n in pars) { self.saved.css.push([el, n, el.css(n)]); el.css(n, pars[n]); } }; this.scrolltop = function (val) { return (val === undefined) ? self.getscrolltop() : self.setscrolltop(val); }; this.scrollleft = function (val) { return (val === undefined) ? self.getscrollleft() : self.setscrollleft(val); }; // derived by by dan pupius www.pupius.net var bezierclass = function (st, ed, spd, p1, p2, p3, p4) { this.st = st; this.ed = ed; this.spd = spd; this.p1 = p1 || 0; this.p2 = p2 || 1; this.p3 = p3 || 0; this.p4 = p4 || 1; this.ts = now(); this.df = ed - st; }; bezierclass.prototype = { b2: function (t) { return 3 * (1 - t) * (1 - t) * t; }, b3: function (t) { return 3 * (1 - t) * t * t; }, b4: function (t) { return t * t * t; }, getpos: function () { return (now() - this.ts) / this.spd; }, getnow: function () { var pc = (now() - this.ts) / this.spd; var bz = this.b2(pc) + this.b3(pc) + this.b4(pc); return (pc >= 1) ? this.ed : this.st + (this.df * bz) | 0; }, update: function (ed, spd) { this.st = this.getnow(); this.ed = ed; this.spd = spd; this.ts = now(); this.df = this.ed - this.st; return this; } }; //derived from http://stackoverflow.com/questions/11236090/ function getmatrixvalues() { var tr = self.doc.css(cap.trstyle); if (tr && (tr.substr(0, 6) == "matrix")) { return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g, '').split(/, +/); } return false; } if (this.ishwscroll) { // hw accelerated scroll this.doc.translate = { x: 0, y: 0, tx: "0px", ty: "0px" }; //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/ if (cap.hastranslate3d && cap.isios) this.doc.css("-webkit-backface-visibility", "hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/ this.getscrolltop = function (last) { if (!last) { var mtx = getmatrixvalues(); if (mtx) return (mtx.length == 16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on ie10 if (self.timerscroll && self.timerscroll.bz) return self.timerscroll.bz.getnow(); } return self.doc.translate.y; }; this.getscrollleft = function (last) { if (!last) { var mtx = getmatrixvalues(); if (mtx) return (mtx.length == 16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on ie10 if (self.timerscroll && self.timerscroll.bh) return self.timerscroll.bh.getnow(); } return self.doc.translate.x; }; this.notifyscrollevent = function (el) { var e = _doc.createevent("uievents"); e.inituievent("scroll", false, false, _win, 1); e.niceevent = true; el.dispatchevent(e); }; var cxscrollleft = (this.isrtlmode) ? 1 : -1; if (cap.hastranslate3d && opt.enabletranslate3d) { this.setscrolltop = function (val, silent) { self.doc.translate.y = val; self.doc.translate.ty = (val * -1) + "px"; self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)"); if (!silent) self.notifyscrollevent(self.win[0]); }; this.setscrollleft = function (val, silent) { self.doc.translate.x = val; self.doc.translate.tx = (val * cxscrollleft) + "px"; self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)"); if (!silent) self.notifyscrollevent(self.win[0]); }; } else { this.setscrolltop = function (val, silent) { self.doc.translate.y = val; self.doc.translate.ty = (val * -1) + "px"; self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")"); if (!silent) self.notifyscrollevent(self.win[0]); }; this.setscrollleft = function (val, silent) { self.doc.translate.x = val; self.doc.translate.tx = (val * cxscrollleft) + "px"; self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")"); if (!silent) self.notifyscrollevent(self.win[0]); }; } } else { // native scroll this.getscrolltop = function () { return self.docscroll.scrolltop(); }; this.setscrolltop = function (val) { self.docscroll.scrolltop(val); }; this.getscrollleft = function () { var val; if (!self.hasreversehr) { val = self.docscroll.scrollleft(); } else if (self.detected.ismozilla) { val = self.page.maxw - math.abs(self.docscroll.scrollleft()); } else { val = self.page.maxw - self.docscroll.scrollleft(); } return val; }; this.setscrollleft = function (val) { return settimeout(function () { if (!self) return; if (self.hasreversehr) { if (self.detected.ismozilla) { val = -(self.page.maxw - val); } else { val = self.page.maxw - val; } } return self.docscroll.scrollleft(val); }, 1); }; } this.gettarget = function (e) { if (!e) return false; if (e.target) return e.target; if (e.srcelement) return e.srcelement; return false; }; this.hasparent = function (e, id) { if (!e) return false; var el = e.target || e.srcelement || e || false; while (el && el.id != id) { el = el.parentnode || false; } return (el !== false); }; function getzindex() { var dom = self.win; if ("zindex" in dom) return dom.zindex(); // use jquery ui method when available while (dom.length > 0) { if (dom[0].nodetype == 9) return false; var zi = dom.css('zindex'); if (!isnan(zi) && zi !== 0) return parseint(zi); dom = dom.parent(); } return false; } //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie var _convertborderwidth = { "thin": 1, "medium": 3, "thick": 5 }; function getwidthtopixel(dom, prop, chkheight) { var wd = dom.css(prop); var px = parsefloat(wd); if (isnan(px)) { px = _convertborderwidth[wd] || 0; var brd = (px == 3) ? ((chkheight) ? (self.win.outerheight() - self.win.innerheight()) : (self.win.outerwidth() - self.win.innerwidth())) : 1; //don't trust css if (self.isie8 && px) px += 1; return (brd) ? px : 0; } return px; } this.getdocumentscrolloffset = function () { return { top: _win.pageyoffset || _doc.documentelement.scrolltop, left: _win.pagexoffset || _doc.documentelement.scrollleft }; }; this.getoffset = function () { if (self.isfixed) { var ofs = self.win.offset(); // fix chrome auto issue (when right/bottom props only) var scrl = self.getdocumentscrolloffset(); ofs.top -= scrl.top; ofs.left -= scrl.left; return ofs; } var ww = self.win.offset(); if (!self.viewport) return ww; var vp = self.viewport.offset(); return { top: ww.top - vp.top, left: ww.left - vp.left }; }; this.updatescrollbar = function (len) { var pos, off; if (self.ishwscroll) { self.rail.css({ height: self.win.innerheight() - (opt.railpadding.top + opt.railpadding.bottom) }); if (self.railh) self.railh.css({ width: self.win.innerwidth() - (opt.railpadding.left + opt.railpadding.right) }); } else { var wpos = self.getoffset(); pos = { top: wpos.top, left: wpos.left - (opt.railpadding.left + opt.railpadding.right) }; pos.top += getwidthtopixel(self.win, 'border-top-width', true); pos.left += (self.rail.align) ? self.win.outerwidth() - getwidthtopixel(self.win, 'border-right-width') - self.rail.width : getwidthtopixel(self.win, 'border-left-width'); off = opt.railoffset; if (off) { if (off.top) pos.top += off.top; if (off.left) pos.left += off.left; } if (!self.railslocked) self.rail.css({ top: pos.top, left: pos.left, height: ((len) ? len.h : self.win.innerheight()) - (opt.railpadding.top + opt.railpadding.bottom) }); if (self.zoom) { self.zoom.css({ top: pos.top + 1, left: (self.rail.align == 1) ? pos.left - 20 : pos.left + self.rail.width + 4 }); } if (self.railh && !self.railslocked) { pos = { top: wpos.top, left: wpos.left }; off = opt.railhoffset; if (off) { if (off.top) pos.top += off.top; if (off.left) pos.left += off.left; } 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); var x = pos.left + getwidthtopixel(self.win, 'border-left-width'); self.railh.css({ top: y - (opt.railpadding.top + opt.railpadding.bottom), left: x, width: self.railh.width }); } } }; this.dorailclick = function (e, dbl, hr) { var fn, pg, cur, pos; if (self.railslocked) return; self.cancelevent(e); if (!("pagey" in e)) { e.pagex = e.clientx + _doc.documentelement.scrollleft; e.pagey = e.clienty + _doc.documentelement.scrolltop; } if (dbl) { fn = (hr) ? self.doscrollleft : self.doscrolltop; 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); self.unsynched("relativexy"); fn(cur|0); } else { fn = (hr) ? self.doscrollleftby : self.doscrollby; cur = (hr) ? self.scroll.x : self.scroll.y; pos = (hr) ? e.pagex - self.railh.offset().left : e.pagey - self.rail.offset().top; pg = (hr) ? self.view.w : self.view.h; fn((cur >= pos) ? pg : -pg); } }; self.newscrolly = self.newscrollx = 0; self.hasanimationframe = ("requestanimationframe" in _win); self.hascancelanimationframe = ("cancelanimationframe" in _win); self.hasborderbox = false; this.init = function () { self.saved.css = []; if (cap.isoperamini) return true; // sorry, do not work! if (cap.isandroid && !("hidden" in _doc)) return true; // android 3- sorry, do not work! opt.emulatetouch = opt.emulatetouch || opt.touchbehavior; // mantain compatibility with "touchbehavior" self.hasborderbox = _win.getcomputedstyle && (_win.getcomputedstyle(_doc.body)['box-sizing'] === "border-box"); var _scrollyhidden = { 'overflow-y': 'hidden' }; if (cap.isie11 || cap.isie10) _scrollyhidden['-ms-overflow-style'] = 'none'; // ie 10 & 11 is always a world apart! if (self.ishwscroll) { this.doc.css(cap.transitionstyle, cap.prefixstyle + 'transform 0ms ease-out'); if (cap.transitionend) self.bind(self.doc, cap.transitionend, self.onscrolltransitionend, false); //i have got to do something usefull!! } self.zindex = "auto"; if (!self.ispage && opt.zindex == "auto") { self.zindex = getzindex() || "auto"; } else { self.zindex = opt.zindex; } if (!self.ispage && self.zindex != "auto" && self.zindex > globalmaxzindex) { globalmaxzindex = self.zindex; } if (self.isie && self.zindex === 0 && opt.zindex == "auto") { // fix ie auto == 0 self.zindex = "auto"; } if (!self.ispage || !cap.isieold) { var cont = self.docscroll; if (self.ispage) cont = (self.haswrapper) ? self.win : self.doc; self.css(cont, _scrollyhidden); if (self.ispage && (cap.isie11 || cap.isie)) { // ie 7-11 self.css($("html"), _scrollyhidden); } if (cap.isios && !self.ispage && !self.haswrapper) self.css($body, { "-webkit-overflow-scrolling": "touch" }); //force hw acceleration var cursor = $(_doc.createelement('div')); cursor.css({ position: "relative", top: 0, "float": "right", width: opt.cursorwidth, height: 0, 'background-color': opt.cursorcolor, border: opt.cursorborder, 'background-clip': 'padding-box', '-webkit-border-radius': opt.cursorborderradius, '-moz-border-radius': opt.cursorborderradius, 'border-radius': opt.cursorborderradius }); cursor.addclass('nicescroll-cursors'); self.cursor = cursor; var rail = $(_doc.createelement('div')); rail.attr('id', self.id); rail.addclass('nicescroll-rails nicescroll-rails-vr'); var v, a, kp = ["left", "right", "top", "bottom"]; //** for (var n in kp) { a = kp[n]; v = opt.railpadding[a] || 0; v && rail.css("padding-" + a, v + "px"); } rail.append(cursor); rail.width = math.max(parsefloat(opt.cursorwidth), cursor.outerwidth()); rail.css({ width: rail.width + "px", zindex: self.zindex, background: opt.background, cursor: "default" }); rail.visibility = true; rail.scrollable = true; rail.align = (opt.railalign == "left") ? 0 : 1; self.rail = rail; self.rail.drag = false; var zoom = false; if (opt.boxzoom && !self.ispage && !cap.isieold) { zoom = _doc.createelement('div'); self.bind(zoom, "click", self.dozoom); self.bind(zoom, "mouseenter", function () { self.zoom.css('opacity', opt.cursoropacitymax); }); self.bind(zoom, "mouseleave", function () { self.zoom.css('opacity', opt.cursoropacitymin); }); self.zoom = $(zoom); self.zoom.css({ cursor: "pointer", zindex: self.zindex, backgroundimage: 'url(' + opt.scriptpath + 'zoomico.png)', height: 18, width: 18, backgroundposition: '0 0' }); if (opt.dblclickzoom) self.bind(self.win, "dblclick", self.dozoom); if (cap.cantouch && opt.gesturezoom) { self.ongesturezoom = function (e) { if (e.scale > 1.5) self.dozoomin(e); if (e.scale < 0.8) self.dozoomout(e); return self.cancelevent(e); }; self.bind(self.win, "gestureend", self.ongesturezoom); } } // init horiz self.railh = false; var railh; if (opt.horizrailenabled) { self.css(cont, { overflowx: 'hidden' }); cursor = $(_doc.createelement('div')); cursor.css({ position: "absolute", top: 0, height: opt.cursorwidth, width: 0, backgroundcolor: opt.cursorcolor, border: opt.cursorborder, backgroundclip: 'padding-box', '-webkit-border-radius': opt.cursorborderradius, '-moz-border-radius': opt.cursorborderradius, 'border-radius': opt.cursorborderradius }); if (cap.isieold) cursor.css('overflow', 'hidden'); //ie6 horiz scrollbar issue cursor.addclass('nicescroll-cursors'); self.cursorh = cursor; railh = $(_doc.createelement('div')); railh.attr('id', self.id + '-hr'); railh.addclass('nicescroll-rails nicescroll-rails-hr'); railh.height = math.max(parsefloat(opt.cursorwidth), cursor.outerheight()); railh.css({ height: railh.height + "px", 'zindex': self.zindex, "background": opt.background }); railh.append(cursor); railh.visibility = true; railh.scrollable = true; railh.align = (opt.railvalign == "top") ? 0 : 1; self.railh = railh; self.railh.drag = false; } if (self.ispage) { rail.css({ position: "fixed", top: 0, height: "100%" }); rail.css((rail.align) ? { right: 0 } : { left: 0 }); self.body.append(rail); if (self.railh) { railh.css({ position: "fixed", left: 0, width: "100%" }); railh.css((railh.align) ? { bottom: 0 } : { top: 0 }); self.body.append(railh); } } else { if (self.ishwscroll) { if (self.win.css('position') == 'static') self.css(self.win, { 'position': 'relative' }); var bd = (self.win[0].nodename == 'html') ? self.body : self.win; $(bd).scrolltop(0).scrollleft(0); // fix rail position if content already scrolled if (self.zoom) { self.zoom.css({ position: "absolute", top: 1, right: 0, "margin-right": rail.width + 4 }); bd.append(self.zoom); } rail.css({ position: "absolute", top: 0 }); rail.css((rail.align) ? { right: 0 } : { left: 0 }); bd.append(rail); if (railh) { railh.css({ position: "absolute", left: 0, bottom: 0 }); railh.css((railh.align) ? { bottom: 0 } : { top: 0 }); bd.append(railh); } } else { self.isfixed = (self.win.css("position") == "fixed"); var rlpos = (self.isfixed) ? "fixed" : "absolute"; if (!self.isfixed) self.viewport = self.getviewport(self.win[0]); if (self.viewport) { self.body = self.viewport; if (!(/fixed|absolute/.test(self.viewport.css("position")))) self.css(self.viewport, { "position": "relative" }); } rail.css({ position: rlpos }); if (self.zoom) self.zoom.css({ position: rlpos }); self.updatescrollbar(); self.body.append(rail); if (self.zoom) self.body.append(self.zoom); if (self.railh) { railh.css({ position: rlpos }); self.body.append(railh); } } if (cap.isios) self.css(self.win, { '-webkit-tap-highlight-color': 'rgba(0,0,0,0)', '-webkit-touch-callout': 'none' }); // prevent grey layer on click if (opt.disableoutline) { if (cap.isie) self.win.attr("hidefocus", "true"); // ie, prevent dotted rectangle on focused div if (cap.iswebkit) self.win.css('outline', 'none'); // webkit outline } } if (opt.autohidemode === false) { self.autohidedom = false; self.rail.css({ opacity: opt.cursoropacitymax }); if (self.railh) self.railh.css({ opacity: opt.cursoropacitymax }); } else if ((opt.autohidemode === true) || (opt.autohidemode === "leave")) { self.autohidedom = $().add(self.rail); if (cap.isie8) self.autohidedom = self.autohidedom.add(self.cursor); if (self.railh) self.autohidedom = self.autohidedom.add(self.railh); if (self.railh && cap.isie8) self.autohidedom = self.autohidedom.add(self.cursorh); } else if (opt.autohidemode == "scroll") { self.autohidedom = $().add(self.rail); if (self.railh) self.autohidedom = self.autohidedom.add(self.railh); } else if (opt.autohidemode == "cursor") { self.autohidedom = $().add(self.cursor); if (self.railh) self.autohidedom = self.autohidedom.add(self.cursorh); } else if (opt.autohidemode == "hidden") { self.autohidedom = false; self.hide(); self.railslocked = false; } if (cap.cantouch || self.istouchcapable || opt.emulatetouch || cap.hasmstouch) { self.scrollmom = new scrollmomentumclass2d(self); var delayedclick = null; self.ontouchstart = function (e) { if (self.locked) return false; //if (e.pointertype && e.pointertype != 2 && e.pointertype != "touch") return false; if (e.pointertype && (e.pointertype === 'mouse' || e.pointertype === e.mspointer_type_mouse)) return false; // need test on surface!! self.hasmoving = false; if (self.scrollmom.timer) { self.triggerscrollend(); self.scrollmom.stop(); } if (!self.railslocked) { var tg = self.gettarget(e); if (tg) { var skp = (/input/i.test(tg.nodename)) && (/range/i.test(tg.type)); if (skp) return self.stoppropagation(e); } var ismouse = (e.type === "mousedown"); if (!("clientx" in e) && ("changedtouches" in e)) { e.clientx = e.changedtouches[0].clientx; e.clienty = e.changedtouches[0].clienty; } if (self.forcescreen) { var le = e; e = { "original": (e.original) ? e.original : e }; e.clientx = le.screenx; e.clienty = le.screeny; } self.rail.drag = { x: e.clientx, y: e.clienty, sx: self.scroll.x, sy: self.scroll.y, st: self.getscrolltop(), sl: self.getscrollleft(), pt: 2, dl: false, tg: tg }; if (self.ispage || !opt.directionlockdeadzone) { self.rail.drag.dl = "f"; } else { var view = { w: $window.width(), h: $window.height() }; var page = self.getcontentsize(); var maxh = page.h - view.h; var maxw = page.w - view.w; if (self.rail.scrollable && !self.railh.scrollable) self.rail.drag.ck = (maxh > 0) ? "v" : false; else if (!self.rail.scrollable && self.railh.scrollable) self.rail.drag.ck = (maxw > 0) ? "h" : false; else self.rail.drag.ck = false; } if (opt.emulatetouch && self.isiframe && cap.isie) { var wp = self.win.position(); self.rail.drag.x += wp.left; self.rail.drag.y += wp.top; } self.hasmoving = false; self.lastmouseup = false; self.scrollmom.reset(e.clientx, e.clienty); if (tg&&ismouse) { var ip = /input|select|button|textarea/i.test(tg.nodename); if (!ip) { if (cap.hasmousecapture) tg.setcapture(); if (opt.emulatetouch) { if (tg.onclick && !(tg._onclick || false)) { // intercept dom0 onclick event tg._onclick = tg.onclick; tg.onclick = function (e) { if (self.hasmoving) return false; tg._onclick.call(this, e); }; } return self.cancelevent(e); } return self.stoppropagation(e); } if (/submit|cancel|button/i.test($(tg).attr('type'))) { self.preventclick = { "tg": tg, "click": false }; } } } }; self.ontouchend = function (e) { if (!self.rail.drag) return true; if (self.rail.drag.pt == 2) { //if (e.pointertype && e.pointertype != 2 && e.pointertype != "touch") return false; if (e.pointertype && (e.pointertype === 'mouse' || e.pointertype === e.mspointer_type_mouse)) return false; self.rail.drag = false; var ismouse = (e.type === "mouseup"); if (self.hasmoving) { self.scrollmom.domomentum(); self.lastmouseup = true; self.hidecursor(); if (cap.hasmousecapture) _doc.releasecapture(); if (ismouse) return self.cancelevent(e); } } else if (self.rail.drag.pt == 1) { return self.onmouseup(e); } }; var moveneedoffset = (opt.emulatetouch && self.isiframe && !cap.hasmousecapture); var locktollerance = opt.directionlockdeadzone * 0.3 | 0; self.ontouchmove = function (e, byiframe) { if (!self.rail.drag) return true; if (e.targettouches && opt.preventmultitouchscrolling) { if (e.targettouches.length > 1) return true; // multitouch } //if (e.pointertype && e.pointertype != 2 && e.pointertype != "touch") return false; if (e.pointertype && (e.pointertype === 'mouse' || e.pointertype === e.mspointer_type_mouse)) return true; if (self.rail.drag.pt == 2) { if (("changedtouches" in e)) { e.clientx = e.changedtouches[0].clientx; e.clienty = e.changedtouches[0].clienty; } var ofy, ofx; ofx = ofy = 0; if (moveneedoffset && !byiframe) { var wp = self.win.position(); ofx = -wp.left; ofy = -wp.top; } var fy = e.clienty + ofy; var my = (fy - self.rail.drag.y); var fx = e.clientx + ofx; var mx = (fx - self.rail.drag.x); var ny = self.rail.drag.st - my; if (self.ishwscroll && opt.bouncescroll) { if (ny < 0) { ny = math.round(ny / 2); } else if (ny > self.page.maxh) { ny = self.page.maxh + math.round((ny - self.page.maxh) / 2); } } else { if (ny < 0) { ny = 0; fy = 0; } else if (ny > self.page.maxh) { ny = self.page.maxh; fy = 0; } if (fy === 0 && !self.hasmoving) { if (!self.ispage) self.rail.drag = false; return true; } } var nx = self.getscrollleft(); if (self.railh && self.railh.scrollable) { nx = (self.isrtlmode) ? mx - self.rail.drag.sl : self.rail.drag.sl - mx; if (self.ishwscroll && opt.bouncescroll) { if (nx < 0) { nx = math.round(nx / 2); } else if (nx > self.page.maxw) { nx = self.page.maxw + math.round((nx - self.page.maxw) / 2); } } else { if (nx < 0) { nx = 0; fx = 0; } if (nx > self.page.maxw) { nx = self.page.maxw; fx = 0; } } } if (!self.hasmoving) { if (self.rail.drag.y === e.clienty && self.rail.drag.x === e.clientx) return self.cancelevent(e); // prevent first useless move event var ay = math.abs(my); var ax = math.abs(mx); var dz = opt.directionlockdeadzone; if (!self.rail.drag.ck) { if (ay > dz && ax > dz) self.rail.drag.dl = "f"; else if (ay > dz) self.rail.drag.dl = (ax > locktollerance) ? "f" : "v"; else if (ax > dz) self.rail.drag.dl = (ay > locktollerance) ? "f" : "h"; } else if (self.rail.drag.ck == "v") { if (ax > dz && ay <= locktollerance) { self.rail.drag = false; } else if (ay > dz) self.rail.drag.dl = "v"; } else if (self.rail.drag.ck == "h") { if (ay > dz && ax <= locktollerance) { self.rail.drag = false; } else if (ax > dz) self.rail.drag.dl = "h"; } if (!self.rail.drag.dl) return self.cancelevent(e); self.triggerscrollstart(e.clientx, e.clienty, 0, 0, 0); self.hasmoving = true; } if (self.preventclick && !self.preventclick.click) { self.preventclick.click = self.preventclick.tg.onclick || false; self.preventclick.tg.onclick = self.onpreventclick; } if (self.rail.drag.dl) { if (self.rail.drag.dl == "v") nx = self.rail.drag.sl; else if (self.rail.drag.dl == "h") ny = self.rail.drag.st; } self.synched("touchmove", function () { if (self.rail.drag && (self.rail.drag.pt == 2)) { if (self.preparetransition) self.resettransition(); if (self.rail.scrollable) self.setscrolltop(ny); self.scrollmom.update(fx, fy); if (self.railh && self.railh.scrollable) { self.setscrollleft(nx); self.showcursor(ny, nx); } else { self.showcursor(ny); } if (cap.isie10) _doc.selection.clear(); } }); return self.cancelevent(e); } else if (self.rail.drag.pt == 1) { // drag on cursor return self.onmousemove(e); } }; self.ontouchstartcursor = function (e, hronly) { if (self.rail.drag && self.rail.drag.pt != 3) return; if (self.locked) return self.cancelevent(e); self.cancelscroll(); self.rail.drag = { x: e.touches[0].clientx, y: e.touches[0].clienty, sx: self.scroll.x, sy: self.scroll.y, pt: 3, hr: (!!hronly) }; var tg = self.gettarget(e); if (!self.ispage && cap.hasmousecapture) tg.setcapture(); if (self.isiframe && !cap.hasmousecapture) { self.saved.csspointerevents = self.doc.css("pointer-events"); self.css(self.doc, { "pointer-events": "none" }); } return self.cancelevent(e); }; self.ontouchendcursor = function (e) { if (self.rail.drag) { if (cap.hasmousecapture) _doc.releasecapture(); if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents); if (self.rail.drag.pt != 3) return; self.rail.drag = false; return self.cancelevent(e); } }; self.ontouchmovecursor = function (e) { if (self.rail.drag) { if (self.rail.drag.pt != 3) return; self.cursorfreezed = true; if (self.rail.drag.hr) { self.scroll.x = self.rail.drag.sx + (e.touches[0].clientx - self.rail.drag.x); if (self.scroll.x < 0) self.scroll.x = 0; var mw = self.scrollvaluemaxw; if (self.scroll.x > mw) self.scroll.x = mw; } else { self.scroll.y = self.rail.drag.sy + (e.touches[0].clienty - self.rail.drag.y); if (self.scroll.y < 0) self.scroll.y = 0; var my = self.scrollvaluemax; if (self.scroll.y > my) self.scroll.y = my; } self.synched('touchmove', function () { if (self.rail.drag && (self.rail.drag.pt == 3)) { self.showcursor(); if (self.rail.drag.hr) self.doscrollleft(math.round(self.scroll.x * self.scrollratio.x), opt.cursordragspeed); else self.doscrolltop(math.round(self.scroll.y * self.scrollratio.y), opt.cursordragspeed); } }); return self.cancelevent(e); } }; } self.onmousedown = function (e, hronly) { if (self.rail.drag && self.rail.drag.pt != 1) return; if (self.railslocked) return self.cancelevent(e); self.cancelscroll(); self.rail.drag = { x: e.clientx, y: e.clienty, sx: self.scroll.x, sy: self.scroll.y, pt: 1, hr: hronly || false }; var tg = self.gettarget(e); if (cap.hasmousecapture) tg.setcapture(); if (self.isiframe && !cap.hasmousecapture) { self.saved.csspointerevents = self.doc.css("pointer-events"); self.css(self.doc, { "pointer-events": "none" }); } self.hasmoving = false; return self.cancelevent(e); }; self.onmouseup = function (e) { if (self.rail.drag) { if (self.rail.drag.pt != 1) return true; if (cap.hasmousecapture) _doc.releasecapture(); if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents); self.rail.drag = false; self.cursorfreezed = false; if (self.hasmoving) self.triggerscrollend(); return self.cancelevent(e); } }; self.onmousemove = function (e) { if (self.rail.drag) { if (self.rail.drag.pt !== 1) return; if (cap.ischrome && e.which === 0) return self.onmouseup(e); self.cursorfreezed = true; if (!self.hasmoving) self.triggerscrollstart(e.clientx, e.clienty, 0, 0, 0); self.hasmoving = true; if (self.rail.drag.hr) { self.scroll.x = self.rail.drag.sx + (e.clientx - self.rail.drag.x); if (self.scroll.x < 0) self.scroll.x = 0; var mw = self.scrollvaluemaxw; if (self.scroll.x > mw) self.scroll.x = mw; } else { self.scroll.y = self.rail.drag.sy + (e.clienty - self.rail.drag.y); if (self.scroll.y < 0) self.scroll.y = 0; var my = self.scrollvaluemax; if (self.scroll.y > my) self.scroll.y = my; } self.synched('mousemove', function () { if (self.cursorfreezed) { self.showcursor(); if (self.rail.drag.hr) { self.scrollleft(math.round(self.scroll.x * self.scrollratio.x)); } else { self.scrolltop(math.round(self.scroll.y * self.scrollratio.y)); } } }); return self.cancelevent(e); } else { self.checkarea = 0; } }; if (cap.cantouch || opt.emulatetouch) { self.onpreventclick = function (e) { if (self.preventclick) { self.preventclick.tg.onclick = self.preventclick.click; self.preventclick = false; return self.cancelevent(e); } }; self.onclick = (cap.isios) ? false : function (e) { // it needs to check ie11 ??? if (self.lastmouseup) { self.lastmouseup = false; return self.cancelevent(e); } else { return true; } }; if (opt.grabcursorenabled && cap.cursorgrabvalue) { self.css((self.ispage) ? self.doc : self.win, { 'cursor': cap.cursorgrabvalue }); self.css(self.rail, { 'cursor': cap.cursorgrabvalue }); } } else { var checkselectionscroll = function (e) { if (!self.selectiondrag) return; if (e) { var ww = self.win.outerheight(); var df = (e.pagey - self.selectiondrag.top); if (df > 0 && df < ww) df = 0; if (df >= ww) df -= ww; self.selectiondrag.df = df; } if (self.selectiondrag.df === 0) return; var rt = -(self.selectiondrag.df*2/6)|0; self.doscrollby(rt); self.debounced("doselectionscroll", function () { checkselectionscroll(); }, 50); }; if ("getselection" in _doc) { // a grade - major browsers self.hastextselected = function () { return (_doc.getselection().rangecount > 0); }; } else if ("selection" in _doc) { //ie9- self.hastextselected = function () { return (_doc.selection.type != "none"); }; } else { self.hastextselected = function () { // no support return false; }; } self.onselectionstart = function (e) { // more testing - severe chrome issues /* if (!self.haswrapper&&(e.which&&e.which==2)) { // fool browser to manage middle button scrolling self.win.css({'overflow':'auto'}); settimeout(function(){ self.win.css({'overflow':'hidden'}); },10); return true; } */ if (self.ispage) return; self.selectiondrag = self.win.offset(); }; self.onselectionend = function (e) { self.selectiondrag = false; }; self.onselectiondrag = function (e) { if (!self.selectiondrag) return; if (self.hastextselected()) self.debounced("selectionscroll", function () { checkselectionscroll(e); }, 250); }; } if (cap.hasw3ctouch) { //ie11+ self.css((self.ispage) ? $("html") : self.win, { 'touch-action': 'none' }); self.css(self.rail, { 'touch-action': 'none' }); self.css(self.cursor, { 'touch-action': 'none' }); self.bind(self.win, "pointerdown", self.ontouchstart); self.bind(_doc, "pointerup", self.ontouchend); self.delegate(_doc, "pointermove", self.ontouchmove); } else if (cap.hasmstouch) { //ie10 self.css((self.ispage) ? $("html") : self.win, { '-ms-touch-action': 'none' }); self.css(self.rail, { '-ms-touch-action': 'none' }); self.css(self.cursor, { '-ms-touch-action': 'none' }); self.bind(self.win, "mspointerdown", self.ontouchstart); self.bind(_doc, "mspointerup", self.ontouchend); self.delegate(_doc, "mspointermove", self.ontouchmove); self.bind(self.cursor, "msgesturehold", function (e) { e.preventdefault(); }); self.bind(self.cursor, "contextmenu", function (e) { e.preventdefault(); }); } else if (cap.cantouch) { // smartphones/touch devices self.bind(self.win, "touchstart", self.ontouchstart, false, true); self.bind(_doc, "touchend", self.ontouchend, false, true); self.bind(_doc, "touchcancel", self.ontouchend, false, true); self.delegate(_doc, "touchmove", self.ontouchmove, false, true); } if (opt.emulatetouch) { self.bind(self.win, "mousedown", self.ontouchstart, false, true); self.bind(_doc, "mouseup", self.ontouchend, false, true); self.bind(_doc, "mousemove", self.ontouchmove, false, true); } if (opt.cursordragontouch || (!cap.cantouch && !opt.emulatetouch)) { self.rail.css({ cursor: "default" }); self.railh && self.railh.css({ cursor: "default" }); self.jqbind(self.rail, "mouseenter", function () { if (!self.ispage && !self.win.is(":visible")) return false; if (self.canshowonmouseevent) self.showcursor(); self.rail.active = true; }); self.jqbind(self.rail, "mouseleave", function () { self.rail.active = false; if (!self.rail.drag) self.hidecursor(); }); if (opt.sensitiverail) { self.bind(self.rail, "click", function (e) { self.dorailclick(e, false, false); }); self.bind(self.rail, "dblclick", function (e) { self.dorailclick(e, true, false); }); self.bind(self.cursor, "click", function (e) { self.cancelevent(e); }); self.bind(self.cursor, "dblclick", function (e) { self.cancelevent(e); }); } if (self.railh) { self.jqbind(self.railh, "mouseenter", function () { if (!self.ispage && !self.win.is(":visible")) return false; if (self.canshowonmouseevent) self.showcursor(); self.rail.active = true; }); self.jqbind(self.railh, "mouseleave", function () { self.rail.active = false; if (!self.rail.drag) self.hidecursor(); }); if (opt.sensitiverail) { self.bind(self.railh, "click", function (e) { self.dorailclick(e, false, true); }); self.bind(self.railh, "dblclick", function (e) { self.dorailclick(e, true, true); }); self.bind(self.cursorh, "click", function (e) { self.cancelevent(e); }); self.bind(self.cursorh, "dblclick", function (e) { self.cancelevent(e); }); } } } if (opt.cursordragontouch && (this.istouchcapable || cap.cantouch)) { self.bind(self.cursor, "touchstart", self.ontouchstartcursor); self.bind(self.cursor, "touchmove", self.ontouchmovecursor); self.bind(self.cursor, "touchend", self.ontouchendcursor); self.cursorh && self.bind(self.cursorh, "touchstart", function (e) { self.ontouchstartcursor(e, true); }); self.cursorh && self.bind(self.cursorh, "touchmove", self.ontouchmovecursor); self.cursorh && self.bind(self.cursorh, "touchend", self.ontouchendcursor); } // if (!cap.cantouch && !opt.emulatetouch) { if (!opt.emulatetouch && !cap.isandroid && !cap.isios) { self.bind((cap.hasmousecapture) ? self.win : _doc, "mouseup", self.onmouseup); self.bind(_doc, "mousemove", self.onmousemove); if (self.onclick) self.bind(_doc, "click", self.onclick); self.bind(self.cursor, "mousedown", self.onmousedown); self.bind(self.cursor, "mouseup", self.onmouseup); if (self.railh) { self.bind(self.cursorh, "mousedown", function (e) { self.onmousedown(e, true); }); self.bind(self.cursorh, "mouseup", self.onmouseup); } if (!self.ispage && opt.enablescrollonselection) { self.bind(self.win[0], "mousedown", self.onselectionstart); self.bind(_doc, "mouseup", self.onselectionend); self.bind(self.cursor, "mouseup", self.onselectionend); if (self.cursorh) self.bind(self.cursorh, "mouseup", self.onselectionend); self.bind(_doc, "mousemove", self.onselectiondrag); } if (self.zoom) { self.jqbind(self.zoom, "mouseenter", function () { if (self.canshowonmouseevent) self.showcursor(); self.rail.active = true; }); self.jqbind(self.zoom, "mouseleave", function () { self.rail.active = false; if (!self.rail.drag) self.hidecursor(); }); } } else { self.bind((cap.hasmousecapture) ? self.win : _doc, "mouseup", self.ontouchend); if (self.onclick) self.bind(_doc, "click", self.onclick); if (opt.cursordragontouch) { self.bind(self.cursor, "mousedown", self.onmousedown); self.bind(self.cursor, "mouseup", self.onmouseup); self.cursorh && self.bind(self.cursorh, "mousedown", function (e) { self.onmousedown(e, true); }); self.cursorh && self.bind(self.cursorh, "mouseup", self.onmouseup); } else { self.bind(self.rail, "mousedown", function (e) { e.preventdefault(); }); // prevent text selection self.railh && self.bind(self.railh, "mousedown", function (e) { e.preventdefault(); }); } } if (opt.enablemousewheel) { if (!self.isiframe) self.mousewheel((cap.isie && self.ispage) ? _doc : self.win, self.onmousewheel); self.mousewheel(self.rail, self.onmousewheel); if (self.railh) self.mousewheel(self.railh, self.onmousewheelhr); } if (!self.ispage && !cap.cantouch && !(/html|^body/.test(self.win[0].nodename))) { if (!self.win.attr("tabindex")) self.win.attr({ "tabindex": ++tabindexcounter }); self.bind(self.win, "focus", function (e) { // better using native events domfocus = (self.gettarget(e)).id || self.gettarget(e) || false; self.hasfocus = true; if (self.canshowonmouseevent) self.noticecursor(); }); self.bind(self.win, "blur", function (e) { // * domfocus = false; self.hasfocus = false; }); self.bind(self.win, "mouseenter", function (e) { // * mousefocus = (self.gettarget(e)).id || self.gettarget(e) || false; self.hasmousefocus = true; if (self.canshowonmouseevent) self.noticecursor(); }); self.bind(self.win, "mouseleave", function (e) { // * mousefocus = false; self.hasmousefocus = false; if (!self.rail.drag) self.hidecursor(); }); } //thanks to http://www.quirksmode.org !! self.onkeypress = function (e) { if (self.railslocked && self.page.maxh === 0) return true; e = e || _win.event; var tg = self.gettarget(e); if (tg && /input|textarea|select|option/.test(tg.nodename)) { var tp = tg.getattribute('type') || tg.type || false; if ((!tp) || !(/submit|button|cancel/i.tp)) return true; } if ($(tg).attr('contenteditable')) return true; if (self.hasfocus || (self.hasmousefocus && !domfocus) || (self.ispage && !domfocus && !mousefocus)) { var key = e.keycode; if (self.railslocked && key != 27) return self.cancelevent(e); var ctrl = e.ctrlkey || false; var shift = e.shiftkey || false; var ret = false; switch (key) { case 38: case 63233: //safari self.doscrollby(24 * 3); ret = true; break; case 40: case 63235: //safari self.doscrollby(-24 * 3); ret = true; break; case 37: case 63232: //safari if (self.railh) { (ctrl) ? self.doscrollleft(0) : self.doscrollleftby(24 * 3); ret = true; } break; case 39: case 63234: //safari if (self.railh) { (ctrl) ? self.doscrollleft(self.page.maxw) : self.doscrollleftby(-24 * 3); ret = true; } break; case 33: case 63276: // safari self.doscrollby(self.view.h); ret = true; break; case 34: case 63277: // safari self.doscrollby(-self.view.h); ret = true; break; case 36: case 63273: // safari (self.railh && ctrl) ? self.doscrollpos(0, 0) : self.doscrollto(0); ret = true; break; case 35: case 63275: // safari (self.railh && ctrl) ? self.doscrollpos(self.page.maxw, self.page.maxh) : self.doscrollto(self.page.maxh); ret = true; break; case 32: if (opt.spacebarenabled) { (shift) ? self.doscrollby(self.view.h) : self.doscrollby(-self.view.h); ret = true; } break; case 27: // esc if (self.zoomactive) { self.dozoom(); ret = true; } break; } if (ret) return self.cancelevent(e); } }; if (opt.enablekeyboard) self.bind(_doc, (cap.isopera && !cap.isopera12) ? "keypress" : "keydown", self.onkeypress); self.bind(_doc, "keydown", function (e) { var ctrl = e.ctrlkey || false; if (ctrl) self.wheelprevented = true; }); self.bind(_doc, "keyup", function (e) { var ctrl = e.ctrlkey || false; if (!ctrl) self.wheelprevented = false; }); self.bind(_win, "blur", function (e) { self.wheelprevented = false; }); self.bind(_win, 'resize', self.onscreenresize); self.bind(_win, 'orientationchange', self.onscreenresize); self.bind(_win, "load", self.lazyresize); if (cap.ischrome && !self.ispage && !self.haswrapper) { //chrome void scrollbar bug - it persists in version 26 var tmp = self.win.attr("style"); var ww = parsefloat(self.win.css("width")) + 1; self.win.css('width', ww); self.synched("chromefix", function () { self.win.attr("style", tmp); }); } // trying a cross-browser implementation - good luck! self.onattributechange = function (e) { self.lazyresize(self.isieold ? 250 : 30); }; if (opt.enableobserver) { if ((!self.isie11) && (clsmutationobserver !== false)) { // ie11 crashes #568 self.observerbody = new clsmutationobserver(function (mutations) { mutations.foreach(function (mut) { if (mut.type == "attributes") { 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 } }); if (self.me.clientwidth != self.page.width || self.me.clientheight != self.page.height) return self.lazyresize(30); }); self.observerbody.observe(_doc.body, { childlist: true, subtree: true, characterdata: false, attributes: true, attributefilter: ['class'] }); } if (!self.ispage && !self.haswrapper) { var _dom = self.win[0]; // redesigned mutationobserver for chrome18+/firefox14+/ios6+ with support for: remove div, add/remove content if (clsmutationobserver !== false) { self.observer = new clsmutationobserver(function (mutations) { mutations.foreach(self.onattributechange); }); self.observer.observe(_dom, { childlist: true, characterdata: false, attributes: true, subtree: false }); self.observerremover = new clsmutationobserver(function (mutations) { mutations.foreach(function (mo) { if (mo.removednodes.length > 0) { for (var dd in mo.removednodes) { if (!!self && (mo.removednodes[dd] === _dom)) return self.remove(); } } }); }); self.observerremover.observe(_dom.parentnode, { childlist: true, characterdata: false, attributes: false, subtree: false }); } else { self.bind(_dom, (cap.isie && !cap.isie9) ? "propertychange" : "domattrmodified", self.onattributechange); if (cap.isie9) _dom.attachevent("onpropertychange", self.onattributechange); //ie9 domattrmodified bug self.bind(_dom, "domnoderemoved", function (e) { if (e.target === _dom) self.remove(); }); } } } // if (!self.ispage && opt.boxzoom) self.bind(_win, "resize", self.resizezoom); if (self.istextarea) { self.bind(self.win, "keydown", self.lazyresize); self.bind(self.win, "mouseup", self.lazyresize); } self.lazyresize(30); } if (this.doc[0].nodename == 'iframe') { var oniframeload = function () { self.iframexd = false; var doc; try { doc = 'contentdocument' in this ? this.contentdocument : this.contentwindow._doc; var a = doc.domain; } catch (e) { self.iframexd = true; doc = false; } if (self.iframexd) { if ("console" in _win) console.log('nicescroll error: policy restriced iframe'); return true; //cross-domain - i can't manage this } self.forcescreen = true; if (self.isiframe) { self.iframe = { "doc": $(doc), "html": self.doc.contents().find('html')[0], "body": self.doc.contents().find('body')[0] }; self.getcontentsize = function () { return { w: math.max(self.iframe.html.scrollwidth, self.iframe.body.scrollwidth), h: math.max(self.iframe.html.scrollheight, self.iframe.body.scrollheight) }; }; self.docscroll = $(self.iframe.body); } if (!cap.isios && opt.iframeautoresize && !self.isiframe) { self.win.scrolltop(0); // reset position self.doc.height(""); //reset height to fix browser bug var hh = math.max(doc.getelementsbytagname('html')[0].scrollheight, doc.body.scrollheight); self.doc.height(hh); } self.lazyresize(30); self.css($(self.iframe.body), _scrollyhidden); if (cap.isios && self.haswrapper) { self.css($(doc.body), { '-webkit-transform': 'translate3d(0,0,0)' }); // avoid iframe content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/ } if ('contentwindow' in this) { self.bind(this.contentwindow, "scroll", self.onscroll); //ie8 & minor } else { self.bind(doc, "scroll", self.onscroll); } if (opt.enablemousewheel) { self.mousewheel(doc, self.onmousewheel); } if (opt.enablekeyboard) self.bind(doc, (cap.isopera) ? "keypress" : "keydown", self.onkeypress); if (cap.cantouch) { self.bind(doc, "touchstart", self.ontouchstart); self.bind(doc, "touchmove", self.ontouchmove); } else if (opt.emulatetouch) { self.bind(doc, "mousedown", self.ontouchstart); self.bind(doc, "mousemove", function (e) { return self.ontouchmove(e, true); }); if (opt.grabcursorenabled && cap.cursorgrabvalue) self.css($(doc.body), { 'cursor': cap.cursorgrabvalue }); } self.bind(doc, "mouseup", self.ontouchend); if (self.zoom) { if (opt.dblclickzoom) self.bind(doc, 'dblclick', self.dozoom); if (self.ongesturezoom) self.bind(doc, "gestureend", self.ongesturezoom); } }; if (this.doc[0].readystate && this.doc[0].readystate === "complete") { settimeout(function () { oniframeload.call(self.doc[0], false); }, 500); } self.bind(this.doc, "load", oniframeload); } }; this.showcursor = function (py, px) { if (self.cursortimeout) { cleartimeout(self.cursortimeout); self.cursortimeout = 0; } if (!self.rail) return; if (self.autohidedom) { self.autohidedom.stop().css({ opacity: opt.cursoropacitymax }); self.cursoractive = true; } if (!self.rail.drag || self.rail.drag.pt != 1) { if (py !== undefined && py !== false) { self.scroll.y = (py / self.scrollratio.y) | 0; } if (px !== undefined) { self.scroll.x = (px / self.scrollratio.x) | 0; } } self.cursor.css({ height: self.cursorheight, top: self.scroll.y }); if (self.cursorh) { var lx = (self.hasreversehr) ? self.scrollvaluemaxw - self.scroll.x : self.scroll.x; self.cursorh.css({ width: self.cursorwidth, left: (!self.rail.align && self.rail.visibility) ? lx + self.rail.width : lx }); self.cursoractive = true; } if (self.zoom) self.zoom.stop().css({ opacity: opt.cursoropacitymax }); }; this.hidecursor = function (tm) { if (self.cursortimeout) return; if (!self.rail) return; if (!self.autohidedom) return; if (self.hasmousefocus && opt.autohidemode === "leave") return; self.cursortimeout = settimeout(function () { if (!self.rail.active || !self.showonmouseevent) { self.autohidedom.stop().animate({ opacity: opt.cursoropacitymin }); if (self.zoom) self.zoom.stop().animate({ opacity: opt.cursoropacitymin }); self.cursoractive = false; } self.cursortimeout = 0; }, tm || opt.hidecursordelay); }; this.noticecursor = function (tm, py, px) { self.showcursor(py, px); if (!self.rail.active) self.hidecursor(tm); }; this.getcontentsize = (self.ispage) ? function () { return { w: math.max(_doc.body.scrollwidth, _doc.documentelement.scrollwidth), h: math.max(_doc.body.scrollheight, _doc.documentelement.scrollheight) }; } : (self.haswrapper) ? function () { return { w: self.doc[0].offsetwidth, h: self.doc[0].offsetheight }; } : function () { return { w: self.docscroll[0].scrollwidth, h: self.docscroll[0].scrollheight }; }; this.onresize = function (e, page) { if (!self || !self.win) return false; var premaxh = self.page.maxh, premaxw = self.page.maxw, previewh = self.view.h, previeww = self.view.w; self.view = { w: (self.ispage) ? self.win.width() : self.win[0].clientwidth, h: (self.ispage) ? self.win.height() : self.win[0].clientheight }; self.page = (page) ? page : self.getcontentsize(); self.page.maxh = math.max(0, self.page.h - self.view.h); self.page.maxw = math.max(0, self.page.w - self.view.w); if ((self.page.maxh == premaxh) && (self.page.maxw == premaxw) && (self.view.w == previeww) && (self.view.h == previewh)) { // test position if (!self.ispage) { var pos = self.win.offset(); if (self.lastposition) { var lst = self.lastposition; if ((lst.top == pos.top) && (lst.left == pos.left)) return self; //nothing to do } self.lastposition = pos; } else { return self; //nothing to do } } if (self.page.maxh === 0) { self.hiderail(); self.scrollvaluemax = 0; self.scroll.y = 0; self.scrollratio.y = 0; self.cursorheight = 0; self.setscrolltop(0); if (self.rail) self.rail.scrollable = false; } else { self.page.maxh -= (opt.railpadding.top + opt.railpadding.bottom); self.rail.scrollable = true; } if (self.page.maxw === 0) { self.hiderailhr(); self.scrollvaluemaxw = 0; self.scroll.x = 0; self.scrollratio.x = 0; self.cursorwidth = 0; self.setscrollleft(0); if (self.railh) { self.railh.scrollable = false; } } else { self.page.maxw -= (opt.railpadding.left + opt.railpadding.right); if (self.railh) self.railh.scrollable = (opt.horizrailenabled); } self.railslocked = (self.locked) || ((self.page.maxh === 0) && (self.page.maxw === 0)); if (self.railslocked) { if (!self.ispage) self.updatescrollbar(self.view); return false; } if (!self.hidden) { if (!self.rail.visibility) self.showrail(); if (self.railh && !self.railh.visibility) self.showrailhr(); } if (self.istextarea && self.win.css('resize') && self.win.css('resize') != 'none') self.view.h -= 20; self.cursorheight = math.min(self.view.h, math.round(self.view.h * (self.view.h / self.page.h))); self.cursorheight = (opt.cursorfixedheight) ? opt.cursorfixedheight : math.max(opt.cursorminheight, self.cursorheight); self.cursorwidth = math.min(self.view.w, math.round(self.view.w * (self.view.w / self.page.w))); self.cursorwidth = (opt.cursorfixedheight) ? opt.cursorfixedheight : math.max(opt.cursorminheight, self.cursorwidth); self.scrollvaluemax = self.view.h - self.cursorheight - (opt.railpadding.top + opt.railpadding.bottom); if (!self.hasborderbox) self.scrollvaluemax -= self.cursor[0].offsetheight - self.cursor[0].clientheight; if (self.railh) { self.railh.width = (self.page.maxh > 0) ? (self.view.w - self.rail.width) : self.view.w; self.scrollvaluemaxw = self.railh.width - self.cursorwidth - (opt.railpadding.left + opt.railpadding.right); } if (!self.ispage) self.updatescrollbar(self.view); self.scrollratio = { x: (self.page.maxw / self.scrollvaluemaxw), y: (self.page.maxh / self.scrollvaluemax) }; var sy = self.getscrolltop(); if (sy > self.page.maxh) { self.doscrolltop(self.page.maxh); } else { self.scroll.y = (self.getscrolltop() / self.scrollratio.y) | 0; self.scroll.x = (self.getscrollleft() / self.scrollratio.x) | 0; if (self.cursoractive) self.noticecursor(); } if (self.scroll.y && (self.getscrolltop() === 0)) self.doscrollto((self.scroll.y * self.scrollratio.y)|0); return self; }; this.resize = self.onresize; var hlazyresize = 0; this.onscreenresize = function(e) { cleartimeout(hlazyresize); var hiderails = (!self.ispage && !self.haswrapper); if (hiderails) self.hiderails(); hlazyresize = settimeout(function () { if (self) { if (hiderails) self.showrails(); self.resize(); } hlazyresize=0; }, 120); }; this.lazyresize = function (tm) { // event debounce cleartimeout(hlazyresize); tm = isnan(tm) ? 240 : tm; hlazyresize = settimeout(function () { self && self.resize(); hlazyresize=0; }, tm); return self; }; // derived by mdn https://developer.mozilla.org/en-us/docs/dom/mozilla_event_reference/wheel function _modernwheelevent(dom, name, fn, bubble) { self._bind(dom, name, function (e) { e = e || _win.event; var event = { original: e, target: e.target || e.srcelement, type: "wheel", deltamode: e.type == "mozmousepixelscroll" ? 0 : 1, deltax: 0, deltaz: 0, preventdefault: function () { e.preventdefault ? e.preventdefault() : e.returnvalue = false; return false; }, stopimmediatepropagation: function () { (e.stopimmediatepropagation) ? e.stopimmediatepropagation() : e.cancelbubble = true; } }; if (name == "mousewheel") { e.wheeldeltax && (event.deltax = -1 / 40 * e.wheeldeltax); e.wheeldeltay && (event.deltay = -1 / 40 * e.wheeldeltay); !event.deltay && !event.deltax && (event.deltay = -1 / 40 * e.wheeldelta); } else { event.deltay = e.detail; } return fn.call(dom, event); }, bubble); } this.jqbind = function (dom, name, fn) { // use jquery bind for non-native events (mouseenter/mouseleave) self.events.push({ e: dom, n: name, f: fn, q: true }); $(dom).on(name, fn); }; this.mousewheel = function (dom, fn, bubble) { // bind mousewheel var el = ("jquery" in dom) ? dom[0] : dom; if ("onwheel" in _doc.createelement("div")) { // modern browsers support "wheel" self._bind(el, "wheel", fn, bubble || false); } else { var wname = (_doc.onmousewheel !== undefined) ? "mousewheel" : "dommousescroll"; // older webkit+ie support or older firefox _modernwheelevent(el, wname, fn, bubble || false); if (wname == "dommousescroll") _modernwheelevent(el, "mozmousepixelscroll", fn, bubble || false); // firefox legacy } }; var passivesupported = false; if (cap.haseventlistener) { // w3c standard event model // thanks to https://developer.mozilla.org/en-us/docs/web/api/eventtarget/addeventlistener try { var options = object.defineproperty({}, "passive", { get: function () { passivesupported = !0; } }); _win.addeventlistener("test", null, options); } catch (err) { } this.stoppropagation = function (e) { if (!e) return false; e = (e.original) ? e.original : e; e.stoppropagation(); return false; }; this.cancelevent = function(e) { if (e.cancelable) e.preventdefault(); e.stopimmediatepropagation(); if (e.preventmanipulation) e.preventmanipulation(); // ie10+ return false; }; } else { // inspired from https://gist.github.com/jonathantneal/2415137 event.prototype.preventdefault = function () { this.returnvalue = false; }; event.prototype.stoppropagation = function () { this.cancelbubble = true; }; _win.constructor.prototype.addeventlistener = _doc.constructor.prototype.addeventlistener = element.prototype.addeventlistener = function (type, listener, usecapture) { this.attachevent("on" + type, listener); }; _win.constructor.prototype.removeeventlistener = _doc.constructor.prototype.removeeventlistener = element.prototype.removeeventlistener = function (type, listener, usecapture) { this.detachevent("on" + type, listener); }; // thanks to http://www.switchonthecode.com !! this.cancelevent = function (e) { e = e || _win.event; if (e) { e.cancelbubble = true; e.cancel = true; e.returnvalue = false; } return false; }; this.stoppropagation = function (e) { e = e || _win.event; if (e) e.cancelbubble = true; return false; }; } this.delegate = function (dom, name, fn, bubble, active) { var de = delegatevents[name] || false; if (!de) { de = { a: [], l: [], f: function (e) { var lst = de.l, l = lst.length - 1; var r = false; for (var a = l; a >= 0; a--) { r = lst[a].call(e.target, e); if (r === false) return false; } return r; } }; self.bind(dom, name, de.f, bubble, active); delegatevents[name] = de; } if (self.ispage) { de.a = [self.id].concat(de.a); de.l = [fn].concat(de.l); } else { de.a.push(self.id); de.l.push(fn); } }; this.undelegate = function (dom, name, fn, bubble, active) { var de = delegatevents[name]||false; if (de&&de.l) { // quick fix #683 for (var a=0,l=de.l.length;a 0) return dd; dom = (dom.parentnode) ? dom.parentnode : false; } return false; }; this.triggerscrollstart = function (cx, cy, rx, ry, ms) { if (self.onscrollstart) { var info = { type: "scrollstart", current: { x: cx, y: cy }, request: { x: rx, y: ry }, end: { x: self.newscrollx, y: self.newscrolly }, speed: ms }; self.onscrollstart.call(self, info); } }; this.triggerscrollend = function () { if (self.onscrollend) { var px = self.getscrollleft(); var py = self.getscrolltop(); var info = { type: "scrollend", current: { x: px, y: py }, end: { x: px, y: py } }; self.onscrollend.call(self, info); } }; var scrolldiry = 0, scrolldirx = 0, scrolltmr = 0, scrollspd = 1; function doscrollrelative(px, py, chkscroll, iswheel) { if (!self.scrollrunning) { self.newscrolly = self.getscrolltop(); self.newscrollx = self.getscrollleft(); scrolltmr = now(); } var gap = (now() - scrolltmr); scrolltmr = now(); if (gap > 350) { scrollspd = 1; } else { scrollspd += (2 - scrollspd) / 10; } px = px * scrollspd | 0; py = py * scrollspd | 0; if (px) { if (iswheel) { // mouse-only if (px < 0) { // fix apple magic mouse swipe back/forward if (self.getscrollleft() >= self.page.maxw) return true; } else { if (self.getscrollleft() <= 0) return true; } } var dx = px > 0 ? 1 : -1; if (scrolldirx !== dx) { if (self.scrollmom) self.scrollmom.stop(); self.newscrollx = self.getscrollleft(); scrolldirx = dx; } self.lastdeltax -= px; } if (py) { var chk = (function () { var top = self.getscrolltop(); if (py < 0) { if (top >= self.page.maxh) return true; } else { if (top <= 0) return true; } })(); if (chk) { if (opt.nativeparentscrolling && chkscroll && !self.ispage && !self.zoomactive) return true; var ny = self.view.h >> 1; if (self.newscrolly < -ny) { self.newscrolly = -ny; py = -1; } else if (self.newscrolly > self.page.maxh + ny) { self.newscrolly = self.page.maxh + ny; py = 1; } else py = 0; } var dy = py > 0 ? 1 : -1; if (scrolldiry !== dy) { if (self.scrollmom) self.scrollmom.stop(); self.newscrolly = self.getscrolltop(); scrolldiry = dy; } self.lastdeltay -= py; } if (py || px) { self.synched("relativexy", function () { var dty = self.lastdeltay + self.newscrolly; self.lastdeltay = 0; var dtx = self.lastdeltax + self.newscrollx; self.lastdeltax = 0; if (!self.rail.drag) self.doscrollpos(dtx, dty); }); } } var hasparentscrollingphase = false; function execscrollwheel(e, hr, chkscroll) { var px, py; if (!chkscroll && hasparentscrollingphase) return true; if (e.deltamode === 0) { // pixel px = -(e.deltax * (opt.mousescrollstep / (18 * 3))) | 0; py = -(e.deltay * (opt.mousescrollstep / (18 * 3))) | 0; } else if (e.deltamode === 1) { // line px = -(e.deltax * opt.mousescrollstep * 50 / 80) | 0; py = -(e.deltay * opt.mousescrollstep * 50 / 80) | 0; } if (hr && opt.oneaxismousemode && (px === 0) && py) { // classic vertical-only mousewheel + browser with x/y support px = py; py = 0; if (chkscroll) { var hrend = (px < 0) ? (self.getscrollleft() >= self.page.maxw) : (self.getscrollleft() <= 0); if (hrend) { // preserve vertical scrolling py = px; px = 0; } } } // invert horizontal direction for rtl mode if (self.isrtlmode) px = -px; var chk = doscrollrelative(px, py, chkscroll, true); if (chk) { if (chkscroll) hasparentscrollingphase = true; } else { hasparentscrollingphase = false; e.stopimmediatepropagation(); // return e.preventdefault(); } } this.onmousewheel = function (e) { if (self.wheelprevented||self.locked) return false; if (self.railslocked) { self.debounced("checkunlock", self.resize, 250); return false; } if (self.rail.drag) return self.cancelevent(e); if (opt.oneaxismousemode === "auto" && e.deltax !== 0) opt.oneaxismousemode = false; // check two-axis mouse support (not very elegant) if (opt.oneaxismousemode && e.deltax === 0) { if (!self.rail.scrollable) { if (self.railh && self.railh.scrollable) { return self.onmousewheelhr(e); } else { return true; } } } var nw = now(); var chk = false; if (opt.preservenativescrolling && ((self.checkarea + 600) < nw)) { self.nativescrollingarea = self.isscrollable(e); chk = true; } self.checkarea = nw; if (self.nativescrollingarea) return true; // this isn't my business var ret = execscrollwheel(e, false, chk); if (ret) self.checkarea = 0; return ret; }; this.onmousewheelhr = function (e) { if (self.wheelprevented) return; if (self.railslocked || !self.railh.scrollable) return true; if (self.rail.drag) return self.cancelevent(e); var nw = now(); var chk = false; if (opt.preservenativescrolling && ((self.checkarea + 600) < nw)) { self.nativescrollingarea = self.isscrollable(e); chk = true; } self.checkarea = nw; if (self.nativescrollingarea) return true; // this is not my business if (self.railslocked) return self.cancelevent(e); return execscrollwheel(e, true, chk); }; this.stop = function () { self.cancelscroll(); if (self.scrollmon) self.scrollmon.stop(); self.cursorfreezed = false; self.scroll.y = math.round(self.getscrolltop() * (1 / self.scrollratio.y)); self.noticecursor(); return self; }; this.gettransitionspeed = function (dif) { return 80 + (dif / 72) * opt.scrollspeed |0; }; if (!opt.smoothscroll) { this.doscrollleft = function (x, spd) { //direct var y = self.getscrolltop(); self.doscrollpos(x, y, spd); }; this.doscrolltop = function (y, spd) { //direct var x = self.getscrollleft(); self.doscrollpos(x, y, spd); }; this.doscrollpos = function (x, y, spd) { //direct var nx = (x > self.page.maxw) ? self.page.maxw : x; if (nx < 0) nx = 0; var ny = (y > self.page.maxh) ? self.page.maxh : y; if (ny < 0) ny = 0; self.synched('scroll', function () { self.setscrolltop(ny); self.setscrollleft(nx); }); }; this.cancelscroll = function () { }; // direct } else if (self.ishwscroll && cap.hastransition && opt.usetransition && !!opt.smoothscroll) { var lasttransitionstyle = ''; this.resettransition = function () { lasttransitionstyle = ''; self.doc.css(cap.prefixstyle + 'transition-duration', '0ms'); }; this.preparetransition = function (dif, istime) { var ex = (istime) ? dif : self.gettransitionspeed(dif); var trans = ex + 'ms'; if (lasttransitionstyle !== trans) { lasttransitionstyle = trans; self.doc.css(cap.prefixstyle + 'transition-duration', trans); } return ex; }; this.doscrollleft = function (x, spd) { //trans var y = (self.scrollrunning) ? self.newscrolly : self.getscrolltop(); self.doscrollpos(x, y, spd); }; this.doscrolltop = function (y, spd) { //trans var x = (self.scrollrunning) ? self.newscrollx : self.getscrollleft(); self.doscrollpos(x, y, spd); }; this.cursorupdate = { running: false, start: function () { var m = this; if (m.running) return; m.running = true; var loop = function () { if (m.running) setanimationframe(loop); self.showcursor(self.getscrolltop(), self.getscrollleft()); self.notifyscrollevent(self.win[0]); }; setanimationframe(loop); }, stop: function () { this.running = false; } }; this.doscrollpos = function (x, y, spd) { //trans var py = self.getscrolltop(); var px = self.getscrollleft(); if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelscroll(); //inverted movement detection if (!opt.bouncescroll) { if (y < 0) y = 0; else if (y > self.page.maxh) y = self.page.maxh; if (x < 0) x = 0; else if (x > self.page.maxw) x = self.page.maxw; } else { if (y < 0) y = y / 2 | 0; else if (y > self.page.maxh) y = self.page.maxh + (y - self.page.maxh) / 2 | 0; if (x < 0) x = x / 2 | 0; else if (x > self.page.maxw) x = self.page.maxw + (x - self.page.maxw) / 2 | 0; } if (self.scrollrunning && x == self.newscrollx && y == self.newscrolly) return false; self.newscrolly = y; self.newscrollx = x; var top = self.getscrolltop(); var lft = self.getscrollleft(); var dst = {}; dst.x = x - lft; dst.y = y - top; var dd = math.sqrt((dst.x * dst.x) + (dst.y * dst.y)) | 0; var ms = self.preparetransition(dd); if (!self.scrollrunning) { self.scrollrunning = true; self.triggerscrollstart(lft, top, x, y, ms); self.cursorupdate.start(); } self.scrollendtrapped = true; if (!cap.transitionend) { if (self.scrollendtrapped) cleartimeout(self.scrollendtrapped); self.scrollendtrapped = settimeout(self.onscrolltransitionend, ms); // simulate transitionend event } self.setscrolltop(self.newscrolly); self.setscrollleft(self.newscrollx); }; this.cancelscroll = function () { if (!self.scrollendtrapped) return true; var py = self.getscrolltop(); var px = self.getscrollleft(); self.scrollrunning = false; if (!cap.transitionend) cleartimeout(cap.transitionend); self.scrollendtrapped = false; self.resettransition(); self.setscrolltop(py); // fire event onscroll if (self.railh) self.setscrollleft(px); if (self.timerscroll && self.timerscroll.tm) clearinterval(self.timerscroll.tm); self.timerscroll = false; self.cursorfreezed = false; self.cursorupdate.stop(); self.showcursor(py, px); return self; }; this.onscrolltransitionend = function () { if (!self.scrollendtrapped) return; var py = self.getscrolltop(); var px = self.getscrollleft(); if (py < 0) py = 0; else if (py > self.page.maxh) py = self.page.maxh; if (px < 0) px = 0; else if (px > self.page.maxw) px = self.page.maxw; if ((py != self.newscrolly) || (px != self.newscrollx)) return self.doscrollpos(px, py, opt.snapbackspeed); if (self.scrollrunning) self.triggerscrollend(); self.scrollrunning = false; self.scrollendtrapped = false; self.resettransition(); self.timerscroll = false; self.setscrolltop(py); // fire event onscroll if (self.railh) self.setscrollleft(px); // fire event onscroll left self.cursorupdate.stop(); self.noticecursor(false, py, px); self.cursorfreezed = false; }; } else { this.doscrollleft = function (x, spd) { //no-trans var y = (self.scrollrunning) ? self.newscrolly : self.getscrolltop(); self.doscrollpos(x, y, spd); }; this.doscrolltop = function (y, spd) { //no-trans var x = (self.scrollrunning) ? self.newscrollx : self.getscrollleft(); self.doscrollpos(x, y, spd); }; this.doscrollpos = function (x, y, spd) { //no-trans var py = self.getscrolltop(); var px = self.getscrollleft(); if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelscroll(); //inverted movement detection var clipped = false; if (!self.bouncescroll || !self.rail.visibility) { if (y < 0) { y = 0; clipped = true; } else if (y > self.page.maxh) { y = self.page.maxh; clipped = true; } } if (!self.bouncescroll || !self.railh.visibility) { if (x < 0) { x = 0; clipped = true; } else if (x > self.page.maxw) { x = self.page.maxw; clipped = true; } } if (self.scrollrunning && (self.newscrolly === y) && (self.newscrollx === x)) return true; self.newscrolly = y; self.newscrollx = x; self.dst = {}; self.dst.x = x - px; self.dst.y = y - py; self.dst.px = px; self.dst.py = py; var dd = math.sqrt((self.dst.x * self.dst.x) + (self.dst.y * self.dst.y)) | 0; var ms = self.gettransitionspeed(dd); self.bzscroll = {}; var p3 = (clipped) ? 1 : 0.58; self.bzscroll.x = new bezierclass(px, self.newscrollx, ms, 0, 0, p3, 1); self.bzscroll.y = new bezierclass(py, self.newscrolly, ms, 0, 0, p3, 1); var loopid = now(); var loop = function () { if (!self.scrollrunning) return; var x = self.bzscroll.y.getpos(); self.setscrollleft(self.bzscroll.x.getnow()); self.setscrolltop(self.bzscroll.y.getnow()); if (x <= 1) { self.timer = setanimationframe(loop); } else { self.scrollrunning = false; self.timer = 0; self.triggerscrollend(); } }; if (!self.scrollrunning) { self.triggerscrollstart(px, py, x, y, ms); self.scrollrunning = true; self.timer = setanimationframe(loop); } }; this.cancelscroll = function () { if (self.timer) clearanimationframe(self.timer); self.timer = 0; self.bzscroll = false; self.scrollrunning = false; return self; }; } this.doscrollby = function (stp, relative) { doscrollrelative(0, stp); }; this.doscrollleftby = function (stp, relative) { doscrollrelative(stp, 0); }; this.doscrollto = function (pos, relative) { var ny = (relative) ? math.round(pos * self.scrollratio.y) : pos; if (ny < 0) ny = 0; else if (ny > self.page.maxh) ny = self.page.maxh; self.cursorfreezed = false; self.doscrolltop(pos); }; this.checkcontentsize = function () { var pg = self.getcontentsize(); if ((pg.h != self.page.h) || (pg.w != self.page.w)) self.resize(false, pg); }; self.onscroll = function (e) { if (self.rail.drag) return; if (!self.cursorfreezed) { self.synched('scroll', function () { self.scroll.y = math.round(self.getscrolltop() / self.scrollratio.y); if (self.railh) self.scroll.x = math.round(self.getscrollleft() / self.scrollratio.x); self.noticecursor(); }); } }; self.bind(self.docscroll, "scroll", self.onscroll); this.dozoomin = function (e) { if (self.zoomactive) return; self.zoomactive = true; self.zoomrestore = { style: {} }; var lst = ['position', 'top', 'left', 'zindex', 'backgroundcolor', 'margintop', 'marginbottom', 'marginleft', 'marginright']; var win = self.win[0].style; for (var a in lst) { var pp = lst[a]; self.zoomrestore.style[pp] = (win[pp] !== undefined) ? win[pp] : ''; } self.zoomrestore.style.width = self.win.css('width'); self.zoomrestore.style.height = self.win.css('height'); self.zoomrestore.padding = { w: self.win.outerwidth() - self.win.width(), h: self.win.outerheight() - self.win.height() }; if (cap.isios4) { self.zoomrestore.scrolltop = $window.scrolltop(); $window.scrolltop(0); } self.win.css({ position: (cap.isios4) ? "absolute" : "fixed", top: 0, left: 0, zindex: globalmaxzindex + 100, margin: 0 }); var bkg = self.win.css("backgroundcolor"); if ("" === bkg || /transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundcolor", "#fff"); self.rail.css({ zindex: globalmaxzindex + 101 }); self.zoom.css({ zindex: globalmaxzindex + 102 }); self.zoom.css('backgroundposition', '0 -18px'); self.resizezoom(); if (self.onzoomin) self.onzoomin.call(self); return self.cancelevent(e); }; this.dozoomout = function (e) { if (!self.zoomactive) return; self.zoomactive = false; self.win.css("margin", ""); self.win.css(self.zoomrestore.style); if (cap.isios4) { $window.scrolltop(self.zoomrestore.scrolltop); } self.rail.css({ "z-index": self.zindex }); self.zoom.css({ "z-index": self.zindex }); self.zoomrestore = false; self.zoom.css('backgroundposition', '0 0'); self.onresize(); if (self.onzoomout) self.onzoomout.call(self); return self.cancelevent(e); }; this.dozoom = function (e) { return (self.zoomactive) ? self.dozoomout(e) : self.dozoomin(e); }; this.resizezoom = function () { if (!self.zoomactive) return; var py = self.getscrolltop(); //preserve scrolling position self.win.css({ width: $window.width() - self.zoomrestore.padding.w + "px", height: $window.height() - self.zoomrestore.padding.h + "px" }); self.onresize(); self.setscrolltop(math.min(self.page.maxh, py)); }; this.init(); $.nicescroll.push(this); }; // inspired by the work of kin blas // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js var scrollmomentumclass2d = function (nc) { var self = this; this.nc = nc; this.lastx = 0; this.lasty = 0; this.speedx = 0; this.speedy = 0; this.lasttime = 0; this.steptime = 0; this.snapx = false; this.snapy = false; this.demulx = 0; this.demuly = 0; this.lastscrollx = -1; this.lastscrolly = -1; this.chkx = 0; this.chky = 0; this.timer = 0; this.reset = function (px, py) { self.stop(); self.steptime = 0; self.lasttime = now(); self.speedx = 0; self.speedy = 0; self.lastx = px; self.lasty = py; self.lastscrollx = -1; self.lastscrolly = -1; }; this.update = function (px, py) { var tm = now(); self.steptime = tm - self.lasttime; self.lasttime = tm; var dy = py - self.lasty; var dx = px - self.lastx; var sy = self.nc.getscrolltop(); var sx = self.nc.getscrollleft(); var newy = sy + dy; var newx = sx + dx; self.snapx = (newx < 0) || (newx > self.nc.page.maxw); self.snapy = (newy < 0) || (newy > self.nc.page.maxh); self.speedx = dx; self.speedy = dy; self.lastx = px; self.lasty = py; }; this.stop = function () { self.nc.unsynched("domomentum2d"); if (self.timer) cleartimeout(self.timer); self.timer = 0; self.lastscrollx = -1; self.lastscrolly = -1; }; this.dosnapy = function (nx, ny) { var snap = false; if (ny < 0) { ny = 0; snap = true; } else if (ny > self.nc.page.maxh) { ny = self.nc.page.maxh; snap = true; } if (nx < 0) { nx = 0; snap = true; } else if (nx > self.nc.page.maxw) { nx = self.nc.page.maxw; snap = true; } (snap) ? self.nc.doscrollpos(nx, ny, self.nc.opt.snapbackspeed) : self.nc.triggerscrollend(); }; this.domomentum = function (gp) { var t = now(); var l = (gp) ? t + gp : self.lasttime; var sl = self.nc.getscrollleft(); var st = self.nc.getscrolltop(); var pageh = self.nc.page.maxh; var pagew = self.nc.page.maxw; self.speedx = (pagew > 0) ? math.min(60, self.speedx) : 0; self.speedy = (pageh > 0) ? math.min(60, self.speedy) : 0; var chk = l && (t - l) <= 60; if ((st < 0) || (st > pageh) || (sl < 0) || (sl > pagew)) chk = false; var sy = (self.speedy && chk) ? self.speedy : false; var sx = (self.speedx && chk) ? self.speedx : false; if (sy || sx) { var tm = math.max(16, self.steptime); //timeout granularity if (tm > 50) { // do smooth var xm = tm / 50; self.speedx *= xm; self.speedy *= xm; tm = 50; } self.demulxy = 0; self.lastscrollx = self.nc.getscrollleft(); self.chkx = self.lastscrollx; self.lastscrolly = self.nc.getscrolltop(); self.chky = self.lastscrolly; var nx = self.lastscrollx; var ny = self.lastscrolly; var onscroll = function () { var df = ((now() - t) > 600) ? 0.04 : 0.02; if (self.speedx) { nx = math.floor(self.lastscrollx - (self.speedx * (1 - self.demulxy))); self.lastscrollx = nx; if ((nx < 0) || (nx > pagew)) df = 0.10; } if (self.speedy) { ny = math.floor(self.lastscrolly - (self.speedy * (1 - self.demulxy))); self.lastscrolly = ny; if ((ny < 0) || (ny > pageh)) df = 0.10; } self.demulxy = math.min(1, self.demulxy + df); self.nc.synched("domomentum2d", function () { if (self.speedx) { var scx = self.nc.getscrollleft(); // if (scx != self.chkx) self.stop(); self.chkx = nx; self.nc.setscrollleft(nx); } if (self.speedy) { var scy = self.nc.getscrolltop(); // if (scy != self.chky) self.stop(); self.chky = ny; self.nc.setscrolltop(ny); } if (!self.timer) { self.nc.hidecursor(); self.dosnapy(nx, ny); } }); if (self.demulxy < 1) { self.timer = settimeout(onscroll, tm); } else { self.stop(); self.nc.hidecursor(); self.dosnapy(nx, ny); } }; onscroll(); } else { self.dosnapy(self.nc.getscrollleft(), self.nc.getscrolltop()); } }; }; // override jquery scrolltop var _scrolltop = jquery.fn.scrolltop; // preserve original function jquery.csshooks.pageyoffset = { get: function (elem, computed, extra) { var nice = $.data(elem, '__nicescroll') || false; return (nice && nice.ishwscroll) ? nice.getscrolltop() : _scrolltop.call(elem); }, set: function (elem, value) { var nice = $.data(elem, '__nicescroll') || false; (nice && nice.ishwscroll) ? nice.setscrolltop(parseint(value)) : _scrolltop.call(elem, value); return this; } }; jquery.fn.scrolltop = function (value) { if (value === undefined) { var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false; return (nice && nice.ishwscroll) ? nice.getscrolltop() : _scrolltop.call(this); } else { return this.each(function () { var nice = $.data(this, '__nicescroll') || false; (nice && nice.ishwscroll) ? nice.setscrolltop(parseint(value)) : _scrolltop.call($(this), value); }); } }; // override jquery scrollleft var _scrollleft = jquery.fn.scrollleft; // preserve original function $.csshooks.pagexoffset = { get: function (elem, computed, extra) { var nice = $.data(elem, '__nicescroll') || false; return (nice && nice.ishwscroll) ? nice.getscrollleft() : _scrollleft.call(elem); }, set: function (elem, value) { var nice = $.data(elem, '__nicescroll') || false; (nice && nice.ishwscroll) ? nice.setscrollleft(parseint(value)) : _scrollleft.call(elem, value); return this; } }; jquery.fn.scrollleft = function (value) { if (value === undefined) { var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false; return (nice && nice.ishwscroll) ? nice.getscrollleft() : _scrollleft.call(this); } else { return this.each(function () { var nice = $.data(this, '__nicescroll') || false; (nice && nice.ishwscroll) ? nice.setscrollleft(parseint(value)) : _scrollleft.call($(this), value); }); } }; var nicescrollarray = function (doms) { var self = this; this.length = 0; this.name = "nicescrollarray"; this.each = function (fn) { $.each(self, fn); return self; }; this.push = function (nice) { self[self.length] = nice; self.length++; }; this.eq = function (idx) { return self[idx]; }; if (doms) { for (var a = 0; a < doms.length; a++) { var nice = $.data(doms[a], '__nicescroll') || false; if (nice) { this[this.length] = nice; this.length++; } } } return this; }; function mplex(el, lst, fn) { for (var a = 0, l = lst.length; a < l; a++) fn(el, lst[a]); } mplex( nicescrollarray.prototype, ['show', 'hide', 'toggle', 'onresize', 'resize', 'remove', 'stop', 'doscrollpos'], function (e, n) { e[n] = function () { var args = arguments; return this.each(function () { this[n].apply(this, args); }); }; } ); jquery.fn.getnicescroll = function (index) { if (index === undefined) { return new nicescrollarray(this); } else { return this[index] && $.data(this[index], '__nicescroll') || false; } }; var pseudos = jquery.expr.pseudos || jquery.expr[':']; // jquery 3 migration pseudos.nicescroll = function (a) { return $.data(a, '__nicescroll') !== undefined; }; $.fn.nicescroll = function (wrapper, _opt) { if (_opt === undefined && typeof wrapper == "object" && !("jquery" in wrapper)) { _opt = wrapper; wrapper = false; } var ret = new nicescrollarray(); this.each(function () { var $this = $(this); var opt = $.extend({}, _opt); // cloning if (wrapper || false) { var wrp = $(wrapper); opt.doc = (wrp.length > 1) ? $(wrapper, $this) : wrp; opt.win = $this; } var docundef = !("doc" in opt); if (!docundef && !("win" in opt)) opt.win = $this; var nice = $this.data('__nicescroll') || false; if (!nice) { opt.doc = opt.doc || $this; nice = new nicescrollclass(opt, $this); $this.data('__nicescroll', nice); } ret.push(nice); }); return (ret.length === 1) ? ret[0] : ret; }; _win.nicescroll = { getjquery: function () { return jquery; } }; if (!$.nicescroll) { $.nicescroll = new nicescrollarray(); $.nicescroll.options = _globaloptions; } }));