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