From 5287b0e10de4e54c18cf41b4d95625042065f94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Sat, 20 Jun 2015 23:06:55 +0200 Subject: [PATCH] Removed some unnecessary files --- static/js/lib/blur.min.js | 17 - static/js/lib/color-thief.js | 609 ----------- static/js/lib/iscroll-min.js | 1 - static/js/lib/iscroll.js | 2006 ---------------------------------- 4 files changed, 2633 deletions(-) delete mode 100755 static/js/lib/blur.min.js delete mode 100755 static/js/lib/color-thief.js delete mode 100755 static/js/lib/iscroll-min.js delete mode 100755 static/js/lib/iscroll.js diff --git a/static/js/lib/blur.min.js b/static/js/lib/blur.min.js deleted file mode 100755 index 2d0da8e3..00000000 --- a/static/js/lib/blur.min.js +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Blur.js - * Copyright Jacob Kelley - * MIT License - */ -// Stackblur, courtesy of Mario Klingemann: http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html -(function(l){l.fn.blurjs=function(e){function O(){this.a=this.b=this.g=this.r=0;this.next=null}var y=document.createElement("canvas"),P=!1,H=l(this).selector.replace(/[^a-zA-Z0-9]/g,"");if(y.getContext){var e=l.extend({source:"body",radius:5,overlay:"",offset:{x:0,y:0},optClass:"",cache:!1,cacheKeyPrefix:"blurjs-",draggable:!1,debug:!1},e),R=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345, -328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309, -305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],S=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20, -20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24, -24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];return this.each(function(){var A=l(this),I=l(e.source),B=I.css("backgroundImage").replace(/"/g,"").replace(/url\(|\)$/ig,"");ctx=y.getContext("2d");tempImg=new Image;tempImg.onload=function(){if(P)j=tempImg.src;else{y.style.display="none";y.width=tempImg.width;y.height=tempImg.height;ctx.drawImage(tempImg,0,0);var j=y.width,q=y.height,k=e.radius;if(!(isNaN(k)||1>k)){var k= -k|0,M=y.getContext("2d"),l;try{try{l=M.getImageData(0,0,j,q)}catch(L){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"),l=M.getImageData(0,0,j,q)}catch(T){throw alert("Cannot access local image"),Error("unable to access local image data: "+T);}}}catch(U){throw alert("Cannot access image"),Error("unable to access image data: "+U);}var c=l.data,u,z,a,d,f,J,g,h,i,v,w,x,m,n,o,r,s,t,C;u=k+k+1;var K=j-1,N=q-1,p=k+1,D=p*(p+1)/2,E=new O,b=E;for(a=1;a>G,c[f+1]=h*F>>G,c[f+2]=i*F>>G,g-=v,h-=w,i-=x,v-=a.r,w-=a.g,x-=a.b,d=J+((d=u+k+1)>G,c[d+1]=h*F>>G,c[d+2]=i*F>>G,g-=v,h-=w,i-=x,v-=a.r,w-=a.g,x-=a.b,d=u+((d=z+p)= 125) { - if (!(r > 250 && g > 250 && b > 250)) { - pixelArray.push([r, g, b]); - } - } - } - - // Send array to quantize function which clusters values - // using median cut algorithm - var cmap = MMCQ.quantize(pixelArray, colorCount); - var palette = cmap.palette(); - - // Clean up - image.removeCanvas(); - - return palette; -}; - - - - -/*! - * quantize.js Copyright 2008 Nick Rabinowitz. - * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php - */ - -// fill out a couple protovis dependencies -/*! - * Block below copied from Protovis: http://mbostock.github.com/protovis/ - * Copyright 2010 Stanford Visualization Group - * Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php - */ -if (!pv) { - var pv = { - map: function(array, f) { - var o = {}; - return f ? array.map(function(d, i) { o.index = i; return f.call(o, d); }) : array.slice(); - }, - naturalOrder: function(a, b) { - return (a < b) ? -1 : ((a > b) ? 1 : 0); - }, - sum: function(array, f) { - var o = {}; - return array.reduce(f ? function(p, d, i) { o.index = i; return p + f.call(o, d); } : function(p, d) { return p + d; }, 0); - }, - max: function(array, f) { - return Math.max.apply(null, f ? pv.map(array, f) : array); - } - }; -} - - - -/** - * Basic Javascript port of the MMCQ (modified median cut quantization) - * algorithm from the Leptonica library (http://www.leptonica.com/). - * Returns a color map you can use to map original pixels to the reduced - * palette. Still a work in progress. - * - * @author Nick Rabinowitz - * @example - -// array of pixels as [R,G,B] arrays -var myPixels = [[190,197,190], [202,204,200], [207,214,210], [211,214,211], [205,207,207] - // etc - ]; -var maxColors = 4; - -var cmap = MMCQ.quantize(myPixels, maxColors); -var newPalette = cmap.palette(); -var newPixels = myPixels.map(function(p) { - return cmap.map(p); -}); - - */ -var MMCQ = (function() { - // private constants - var sigbits = 5, - rshift = 8 - sigbits, - maxIterations = 1000, - fractByPopulations = 0.75; - - // get reduced-space color index for a pixel - function getColorIndex(r, g, b) { - return (r << (2 * sigbits)) + (g << sigbits) + b; - } - - // Simple priority queue - function PQueue(comparator) { - var contents = [], - sorted = false; - - function sort() { - contents.sort(comparator); - sorted = true; - } - - return { - push: function(o) { - contents.push(o); - sorted = false; - }, - peek: function(index) { - if (!sorted) sort(); - if (index===undefined) index = contents.length - 1; - return contents[index]; - }, - pop: function() { - if (!sorted) sort(); - return contents.pop(); - }, - size: function() { - return contents.length; - }, - map: function(f) { - return contents.map(f); - }, - debug: function() { - if (!sorted) sort(); - return contents; - } - }; - } - - // 3d color space box - function VBox(r1, r2, g1, g2, b1, b2, histo) { - var vbox = this; - vbox.r1 = r1; - vbox.r2 = r2; - vbox.g1 = g1; - vbox.g2 = g2; - vbox.b1 = b1; - vbox.b2 = b2; - vbox.histo = histo; - } - VBox.prototype = { - volume: function(force) { - var vbox = this; - if (!vbox._volume || force) { - vbox._volume = ((vbox.r2 - vbox.r1 + 1) * (vbox.g2 - vbox.g1 + 1) * (vbox.b2 - vbox.b1 + 1)); - } - return vbox._volume; - }, - count: function(force) { - var vbox = this, - histo = vbox.histo; - if (!vbox._count_set || force) { - var npix = 0, - i, j, k; - for (i = vbox.r1; i <= vbox.r2; i++) { - for (j = vbox.g1; j <= vbox.g2; j++) { - for (k = vbox.b1; k <= vbox.b2; k++) { - index = getColorIndex(i,j,k); - npix += (histo[index] || 0); - } - } - } - vbox._count = npix; - vbox._count_set = true; - } - return vbox._count; - }, - copy: function() { - var vbox = this; - return new VBox(vbox.r1, vbox.r2, vbox.g1, vbox.g2, vbox.b1, vbox.b2, vbox.histo); - }, - avg: function(force) { - var vbox = this, - histo = vbox.histo; - if (!vbox._avg || force) { - var ntot = 0, - mult = 1 << (8 - sigbits), - rsum = 0, - gsum = 0, - bsum = 0, - hval, - i, j, k, histoindex; - for (i = vbox.r1; i <= vbox.r2; i++) { - for (j = vbox.g1; j <= vbox.g2; j++) { - for (k = vbox.b1; k <= vbox.b2; k++) { - histoindex = getColorIndex(i,j,k); - hval = histo[histoindex] || 0; - ntot += hval; - rsum += (hval * (i + 0.5) * mult); - gsum += (hval * (j + 0.5) * mult); - bsum += (hval * (k + 0.5) * mult); - } - } - } - if (ntot) { - vbox._avg = [~~(rsum/ntot), ~~(gsum/ntot), ~~(bsum/ntot)]; - } else { -// console.log('empty box'); - vbox._avg = [ - ~~(mult * (vbox.r1 + vbox.r2 + 1) / 2), - ~~(mult * (vbox.g1 + vbox.g2 + 1) / 2), - ~~(mult * (vbox.b1 + vbox.b2 + 1) / 2) - ]; - } - } - return vbox._avg; - }, - contains: function(pixel) { - var vbox = this, - rval = pixel[0] >> rshift; - gval = pixel[1] >> rshift; - bval = pixel[2] >> rshift; - return (rval >= vbox.r1 && rval <= vbox.r2 && - gval >= vbox.g1 && gval <= vbox.g2 && - bval >= vbox.b1 && bval <= vbox.b2); - } - }; - - // Color map - function CMap() { - this.vboxes = new PQueue(function(a,b) { - return pv.naturalOrder( - a.vbox.count()*a.vbox.volume(), - b.vbox.count()*b.vbox.volume() - ); - }); - } - CMap.prototype = { - push: function(vbox) { - this.vboxes.push({ - vbox: vbox, - color: vbox.avg() - }); - }, - palette: function() { - return this.vboxes.map(function(vb) { return vb.color; }); - }, - size: function() { - return this.vboxes.size(); - }, - map: function(color) { - var vboxes = this.vboxes; - for (var i=0; i 251 - var idx = vboxes.length-1, - highest = vboxes[idx].color; - if (highest[0] > 251 && highest[1] > 251 && highest[2] > 251) - vboxes[idx].color = [255,255,255]; - } - }; - - // histo (1-d array, giving the number of pixels in - // each quantized region of color space), or null on error - function getHisto(pixels) { - var histosize = 1 << (3 * sigbits), - histo = new Array(histosize), - index, rval, gval, bval; - pixels.forEach(function(pixel) { - rval = pixel[0] >> rshift; - gval = pixel[1] >> rshift; - bval = pixel[2] >> rshift; - index = getColorIndex(rval, gval, bval); - histo[index] = (histo[index] || 0) + 1; - }); - return histo; - } - - function vboxFromPixels(pixels, histo) { - var rmin=1000000, rmax=0, - gmin=1000000, gmax=0, - bmin=1000000, bmax=0, - rval, gval, bval; - // find min/max - pixels.forEach(function(pixel) { - rval = pixel[0] >> rshift; - gval = pixel[1] >> rshift; - bval = pixel[2] >> rshift; - if (rval < rmin) rmin = rval; - else if (rval > rmax) rmax = rval; - if (gval < gmin) gmin = gval; - else if (gval > gmax) gmax = gval; - if (bval < bmin) bmin = bval; - else if (bval > bmax) bmax = bval; - }); - return new VBox(rmin, rmax, gmin, gmax, bmin, bmax, histo); - } - - function medianCutApply(histo, vbox) { - if (!vbox.count()) return; - - var rw = vbox.r2 - vbox.r1 + 1, - gw = vbox.g2 - vbox.g1 + 1, - bw = vbox.b2 - vbox.b1 + 1, - maxw = pv.max([rw, gw, bw]); - // only one pixel, no split - if (vbox.count() == 1) { - return [vbox.copy()]; - } - /* Find the partial sum arrays along the selected axis. */ - var total = 0, - partialsum = [], - lookaheadsum = [], - i, j, k, sum, index; - if (maxw == rw) { - for (i = vbox.r1; i <= vbox.r2; i++) { - sum = 0; - for (j = vbox.g1; j <= vbox.g2; j++) { - for (k = vbox.b1; k <= vbox.b2; k++) { - index = getColorIndex(i,j,k); - sum += (histo[index] || 0); - } - } - total += sum; - partialsum[i] = total; - } - } - else if (maxw == gw) { - for (i = vbox.g1; i <= vbox.g2; i++) { - sum = 0; - for (j = vbox.r1; j <= vbox.r2; j++) { - for (k = vbox.b1; k <= vbox.b2; k++) { - index = getColorIndex(j,i,k); - sum += (histo[index] || 0); - } - } - total += sum; - partialsum[i] = total; - } - } - else { /* maxw == bw */ - for (i = vbox.b1; i <= vbox.b2; i++) { - sum = 0; - for (j = vbox.r1; j <= vbox.r2; j++) { - for (k = vbox.g1; k <= vbox.g2; k++) { - index = getColorIndex(j,k,i); - sum += (histo[index] || 0); - } - } - total += sum; - partialsum[i] = total; - } - } - partialsum.forEach(function(d,i) { - lookaheadsum[i] = total-d; - }); - function doCut(color) { - var dim1 = color + '1', - dim2 = color + '2', - left, right, vbox1, vbox2, d2, count2=0; - for (i = vbox[dim1]; i <= vbox[dim2]; i++) { - if (partialsum[i] > total / 2) { - vbox1 = vbox.copy(); - vbox2 = vbox.copy(); - left = i - vbox[dim1]; - right = vbox[dim2] - i; - if (left <= right) - d2 = Math.min(vbox[dim2] - 1, ~~(i + right / 2)); - else d2 = Math.max(vbox[dim1], ~~(i - 1 - left / 2)); - // avoid 0-count boxes - while (!partialsum[d2]) d2++; - count2 = lookaheadsum[d2]; - while (!count2 && partialsum[d2-1]) count2 = lookaheadsum[--d2]; - // set dimensions - vbox1[dim2] = d2; - vbox2[dim1] = vbox1[dim2] + 1; -// console.log('vbox counts:', vbox.count(), vbox1.count(), vbox2.count()); - return [vbox1, vbox2]; - } - } - - } - // determine the cut planes - return maxw == rw ? doCut('r') : - maxw == gw ? doCut('g') : - doCut('b'); - } - - function quantize(pixels, maxcolors) { - // short-circuit - if (!pixels.length || maxcolors < 2 || maxcolors > 256) { -// console.log('wrong number of maxcolors'); - return false; - } - - // XXX: check color content and convert to grayscale if insufficient - - var histo = getHisto(pixels), - histosize = 1 << (3 * sigbits); - - // check that we aren't below maxcolors already - var nColors = 0; - histo.forEach(function() { nColors++; }); - if (nColors <= maxcolors) { - // XXX: generate the new colors from the histo and return - } - - // get the beginning vbox from the colors - var vbox = vboxFromPixels(pixels, histo), - pq = new PQueue(function(a,b) { return pv.naturalOrder(a.count(), b.count()); }); - pq.push(vbox); - - // inner function to do the iteration - function iter(lh, target) { - var ncolors = 1, - niters = 0, - vbox; - while (niters < maxIterations) { - vbox = lh.pop(); - if (!vbox.count()) { /* just put it back */ - lh.push(vbox); - niters++; - continue; - } - // do the cut - var vboxes = medianCutApply(histo, vbox), - vbox1 = vboxes[0], - vbox2 = vboxes[1]; - - if (!vbox1) { -// console.log("vbox1 not defined; shouldn't happen!"); - return; - } - lh.push(vbox1); - if (vbox2) { /* vbox2 can be null */ - lh.push(vbox2); - ncolors++; - } - if (ncolors >= target) return; - if (niters++ > maxIterations) { -// console.log("infinite loop; perhaps too few pixels!"); - return; - } - } - } - - // first set of colors, sorted by population - iter(pq, fractByPopulations * maxcolors); - - // Re-sort by the product of pixel occupancy times the size in color space. - var pq2 = new PQueue(function(a,b) { - return pv.naturalOrder(a.count()*a.volume(), b.count()*b.volume()); - }); - while (pq.size()) { - pq2.push(pq.pop()); - } - - // next set - generate the median cuts using the (npix * vol) sorting. - iter(pq2, maxcolors - pq2.size()); - - // calculate the actual colors - var cmap = new CMap(); - while (pq2.size()) { - cmap.push(pq2.pop()); - } - - return cmap; - } - - return { - quantize: quantize - }; -})(); diff --git a/static/js/lib/iscroll-min.js b/static/js/lib/iscroll-min.js deleted file mode 100755 index 38965713..00000000 --- a/static/js/lib/iscroll-min.js +++ /dev/null @@ -1 +0,0 @@ -(function(e,t,n){function s(e,n){this.wrapper=typeof e=="string"?t.querySelector(e):e;this.scroller=this.wrapper.children[0];this.scrollerStyle=this.scroller.style;this.options={resizeScrollbars:true,mouseWheelSpeed:20,snapThreshold:.334,startX:0,startY:0,scrollY:true,directionLockThreshold:5,momentum:true,bounce:true,bounceTime:600,bounceEasing:"",preventDefault:true,preventDefaultException:{tagName:/^(INPUT|TEXTAREA|BUTTON|SELECT)$/},HWCompositing:true,useTransition:true,useTransform:true};for(var r in n){this.options[r]=n[r]}this.translateZ=this.options.HWCompositing&&i.hasPerspective?" translateZ(0)":"";this.options.useTransition=i.hasTransition&&this.options.useTransition;this.options.useTransform=i.hasTransform&&this.options.useTransform;this.options.eventPassthrough=this.options.eventPassthrough===true?"vertical":this.options.eventPassthrough;this.options.preventDefault=!this.options.eventPassthrough&&this.options.preventDefault;this.options.scrollY=this.options.eventPassthrough=="vertical"?false:this.options.scrollY;this.options.scrollX=this.options.eventPassthrough=="horizontal"?false:this.options.scrollX;this.options.freeScroll=this.options.freeScroll&&!this.options.eventPassthrough;this.options.directionLockThreshold=this.options.eventPassthrough?0:this.options.directionLockThreshold;this.options.bounceEasing=typeof this.options.bounceEasing=="string"?i.ease[this.options.bounceEasing]||i.ease.circular:this.options.bounceEasing;this.options.resizePolling=this.options.resizePolling===undefined?60:this.options.resizePolling;if(this.options.tap===true){this.options.tap="tap"}if(this.options.shrinkScrollbars=="scale"){this.options.useTransition=false}this.options.invertWheelDirection=this.options.invertWheelDirection?-1:1;this.x=0;this.y=0;this.directionX=0;this.directionY=0;this._events={};this._init();this.refresh();this.scrollTo(this.options.startX,this.options.startY);this.enable()}function o(e,n,r){var i=t.createElement("div"),s=t.createElement("div");if(r===true){i.style.cssText="position:absolute;z-index:9999";s.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px"}s.className="iScrollIndicator";if(e=="h"){if(r===true){i.style.cssText+=";height:7px;left:2px;right:2px;bottom:0";s.style.height="100%"}i.className="iScrollHorizontalScrollbar"}else{if(r===true){i.style.cssText+=";width:7px;bottom:2px;top:2px;right:1px";s.style.width="100%"}i.className="iScrollVerticalScrollbar"}i.style.cssText+=";overflow:hidden";if(!n){i.style.pointerEvents="none"}i.appendChild(s);return i}function u(n,r){this.wrapper=typeof r.el=="string"?t.querySelector(r.el):r.el;this.wrapperStyle=this.wrapper.style;this.indicator=this.wrapper.children[0];this.indicatorStyle=this.indicator.style;this.scroller=n;this.options={listenX:true,listenY:true,interactive:false,resize:true,defaultScrollbars:false,shrink:false,fade:false,speedRatioX:0,speedRatioY:0};for(var s in r){this.options[s]=r[s]}this.sizeRatioX=1;this.sizeRatioY=1;this.maxPosX=0;this.maxPosY=0;if(this.options.interactive){if(!this.options.disableTouch){i.addEvent(this.indicator,"touchstart",this);i.addEvent(e,"touchend",this)}if(!this.options.disablePointer){i.addEvent(this.indicator,i.prefixPointerEvent("pointerdown"),this);i.addEvent(e,i.prefixPointerEvent("pointerup"),this)}if(!this.options.disableMouse){i.addEvent(this.indicator,"mousedown",this);i.addEvent(e,"mouseup",this)}}if(this.options.fade){this.wrapperStyle[i.style.transform]=this.scroller.translateZ;this.wrapperStyle[i.style.transitionDuration]=i.isBadAndroid?"0.001s":"0ms";this.wrapperStyle.opacity="0"}}var r=e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(t){e.setTimeout(t,1e3/60)};var i=function(){function o(e){if(s===false)return false;if(s==="")return e;return s+e.charAt(0).toUpperCase()+e.substr(1)}var r={};var i=t.createElement("div").style;var s=function(){var e=["t","webkitT","MozT","msT","OT"],t,n=0,r=e.length;for(;n0){f=s?s/2.5*(a/8):0;u=n.abs(e)+f;l=u/a}return{destination:n.round(f),duration:l}};var u=o("transform");r.extend(r,{hasTransform:u!==false,hasPerspective:o("perspective")in i,hasTouch:"ontouchstart"in e,hasPointer:e.PointerEvent||e.MSPointerEvent,hasTransition:o("transition")in i});r.isBadAndroid=/Android /.test(e.navigator.appVersion)&&!/Chrome\/\d/.test(e.navigator.appVersion);r.extend(r.style={},{transform:u,transitionTimingFunction:o("transitionTimingFunction"),transitionDuration:o("transitionDuration"),transitionDelay:o("transitionDelay"),transformOrigin:o("transformOrigin")});r.hasClass=function(e,t){var n=new RegExp("(^|\\s)"+t+"(\\s|$)");return n.test(e.className)};r.addClass=function(e,t){if(r.hasClass(e,t)){return}var n=e.className.split(" ");n.push(t);e.className=n.join(" ")};r.removeClass=function(e,t){if(!r.hasClass(e,t)){return}var n=new RegExp("(^|\\s)"+t+"(\\s|$)","g");e.className=e.className.replace(n," ")};r.offset=function(e){var t=-e.offsetLeft,n=-e.offsetTop;while(e=e.offsetParent){t-=e.offsetLeft;n-=e.offsetTop}return{left:t,top:n}};r.preventDefaultException=function(e,t){for(var n in t){if(t[n].test(e[n])){return true}}return false};r.extend(r.eventType={},{touchstart:1,touchmove:1,touchend:1,mousedown:2,mousemove:2,mouseup:2,pointerdown:3,pointermove:3,pointerup:3,MSPointerDown:3,MSPointerMove:3,MSPointerUp:3});r.extend(r.ease={},{quadratic:{style:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",fn:function(e){return e*(2-e)}},circular:{style:"cubic-bezier(0.1, 0.57, 0.1, 1)",fn:function(e){return n.sqrt(1- --e*e)}},back:{style:"cubic-bezier(0.175, 0.885, 0.32, 1.275)",fn:function(e){var t=4;return(e=e-1)*e*((t+1)*e+t)+1}},bounce:{style:"",fn:function(e){if((e/=1)<1/2.75){return 7.5625*e*e}else if(e<2/2.75){return 7.5625*(e-=1.5/2.75)*e+.75}else if(e<2.5/2.75){return 7.5625*(e-=2.25/2.75)*e+.9375}else{return 7.5625*(e-=2.625/2.75)*e+.984375}}},elastic:{style:"",fn:function(e){var t=.22,r=.4;if(e===0){return 0}if(e==1){return 1}return r*n.pow(2,-10*e)*n.sin((e-t/4)*2*n.PI/t)+1}}});r.tap=function(e,n){var r=t.createEvent("Event");r.initEvent(n,true,true);r.pageX=e.pageX;r.pageY=e.pageY;e.target.dispatchEvent(r)};r.click=function(e){var n=e.target,r;if(!/(SELECT|INPUT|TEXTAREA)/i.test(n.tagName)){r=t.createEvent("MouseEvents");r.initMouseEvent("click",true,true,e.view,1,n.screenX,n.screenY,n.clientX,n.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,null);r._constructed=true;n.dispatchEvent(r)}};return r}();s.prototype={version:"5.1.2",_init:function(){this._initEvents();if(this.options.scrollbars||this.options.indicators){this._initIndicators()}if(this.options.mouseWheel){this._initWheel()}if(this.options.snap){this._initSnap()}if(this.options.keyBindings){this._initKeys()}},destroy:function(){this._initEvents(true);this._execEvent("destroy")},_transitionEnd:function(e){if(e.target!=this.scroller||!this.isInTransition){return}this._transitionTime();if(!this.resetPosition(this.options.bounceTime)){this.isInTransition=false;this._execEvent("scrollEnd")}},_start:function(e){if(i.eventType[e.type]!=1){if(e.button!==0){return}}if(!this.enabled||this.initiated&&i.eventType[e.type]!==this.initiated){return}if(this.options.preventDefault&&!i.isBadAndroid&&!i.preventDefaultException(e.target,this.options.preventDefaultException)){e.preventDefault()}var t=e.touches?e.touches[0]:e,r;this.initiated=i.eventType[e.type];this.moved=false;this.distX=0;this.distY=0;this.directionX=0;this.directionY=0;this.directionLocked=0;this._transitionTime();this.startTime=i.getTime();if(this.options.useTransition&&this.isInTransition){this.isInTransition=false;r=this.getComputedPosition();this._translate(n.round(r.x),n.round(r.y));this._execEvent("scrollEnd")}else if(!this.options.useTransition&&this.isAnimating){this.isAnimating=false;this._execEvent("scrollEnd")}this.startX=this.x;this.startY=this.y;this.absStartX=this.x;this.absStartY=this.y;this.pointX=t.pageX;this.pointY=t.pageY;this._execEvent("beforeScrollStart")},_move:function(e){if(!this.enabled||i.eventType[e.type]!==this.initiated){return}if(this.options.preventDefault){e.preventDefault()}var t=e.touches?e.touches[0]:e,r=t.pageX-this.pointX,s=t.pageY-this.pointY,o=i.getTime(),u,a,f,l;this.pointX=t.pageX;this.pointY=t.pageY;this.distX+=r;this.distY+=s;f=n.abs(this.distX);l=n.abs(this.distY);if(o-this.endTime>300&&f<10&&l<10){return}if(!this.directionLocked&&!this.options.freeScroll){if(f>l+this.options.directionLockThreshold){this.directionLocked="h"}else if(l>=f+this.options.directionLockThreshold){this.directionLocked="v"}else{this.directionLocked="n"}}if(this.directionLocked=="h"){if(this.options.eventPassthrough=="vertical"){e.preventDefault()}else if(this.options.eventPassthrough=="horizontal"){this.initiated=false;return}s=0}else if(this.directionLocked=="v"){if(this.options.eventPassthrough=="horizontal"){e.preventDefault()}else if(this.options.eventPassthrough=="vertical"){this.initiated=false;return}r=0}r=this.hasHorizontalScroll?r:0;s=this.hasVerticalScroll?s:0;u=this.x+r;a=this.y+s;if(u>0||u0?0:this.maxScrollX}if(a>0||a0?0:this.maxScrollY}this.directionX=r>0?-1:r<0?1:0;this.directionY=s>0?-1:s<0?1:0;if(!this.moved){this._execEvent("scrollStart")}this.moved=true;this._translate(u,a);if(o-this.startTime>300){this.startTime=o;this.startX=this.x;this.startY=this.y}},_end:function(e){if(!this.enabled||i.eventType[e.type]!==this.initiated){return}if(this.options.preventDefault&&!i.preventDefaultException(e.target,this.options.preventDefaultException)){e.preventDefault()}var t=e.changedTouches?e.changedTouches[0]:e,r,s,o=i.getTime()-this.startTime,u=n.round(this.x),a=n.round(this.y),f=n.abs(u-this.startX),l=n.abs(a-this.startY),c=0,h="";this.isInTransition=0;this.initiated=0;this.endTime=i.getTime();if(this.resetPosition(this.options.bounceTime)){return}this.scrollTo(u,a);if(!this.moved){if(this.options.tap){i.tap(e,this.options.tap)}if(this.options.click){i.click(e)}this._execEvent("scrollCancel");return}if(this._events.flick&&o<200&&f<100&&l<100){this._execEvent("flick");return}if(this.options.momentum&&o<300){r=this.hasHorizontalScroll?i.momentum(this.x,this.startX,o,this.maxScrollX,this.options.bounce?this.wrapperWidth:0,this.options.deceleration):{destination:u,duration:0};s=this.hasVerticalScroll?i.momentum(this.y,this.startY,o,this.maxScrollY,this.options.bounce?this.wrapperHeight:0,this.options.deceleration):{destination:a,duration:0};u=r.destination;a=s.destination;c=n.max(r.duration,s.duration);this.isInTransition=1}if(this.options.snap){var p=this._nearestSnap(u,a);this.currentPage=p;c=this.options.snapSpeed||n.max(n.max(n.min(n.abs(u-p.x),1e3),n.min(n.abs(a-p.y),1e3)),300);u=p.x;a=p.y;this.directionX=0;this.directionY=0;h=this.options.bounceEasing}if(u!=this.x||a!=this.y){if(u>0||u0||a0){t=0}else if(this.x0){n=0}else if(this.y-1){this._events[e].splice(n,1)}},_execEvent:function(e){if(!this._events[e]){return}var t=0,n=this._events[e].length;if(!n){return}for(;t0;if(!n||this.options.useTransition&&r.style){this._transitionTimingFunction(r.style);this._transitionTime(n);this._translate(e,t)}else{this._animate(e,t,n,r.fn)}},scrollToElement:function(e,t,r,s,o){e=e.nodeType?e:this.scroller.querySelector(e);if(!e){return}var u=i.offset(e);u.left-=this.wrapperOffset.left;u.top-=this.wrapperOffset.top;if(r===true){r=n.round(e.offsetWidth/2-this.wrapper.offsetWidth/2)}if(s===true){s=n.round(e.offsetHeight/2-this.wrapper.offsetHeight/2)}u.left-=r||0;u.top-=s||0;u.left=u.left>0?0:u.left0?0:u.top0){i--}else if(t<0){i++}if(r>0){s--}else if(r<0){s++}this.goToPage(i,s);return}i=this.x+n.round(this.hasHorizontalScroll?t:0);s=this.y+n.round(this.hasVerticalScroll?r:0);if(i>0){i=0}else if(i0){s=0}else if(s-this.scrollerWidth){this.pages[e]=[];t=0;a=0;while(a>-this.scrollerHeight){this.pages[e][t]={x:n.max(u,this.maxScrollX),y:n.max(a,this.maxScrollY),width:f,height:l,cx:u-s,cy:a-o};a-=l;t++}u-=f;e++}}else{c=this.options.snap;t=c.length;i=-1;for(;ethis.maxScrollX){r++}}}this.goToPage(this.currentPage.pageX||0,this.currentPage.pageY||0,0);if(this.options.snapThreshold%1===0){this.snapThresholdX=this.options.snapThreshold;this.snapThresholdY=this.options.snapThreshold}else{this.snapThresholdX=n.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width*this.options.snapThreshold);this.snapThresholdY=n.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height*this.options.snapThreshold)}});this.on("flick",function(){var e=this.options.snapSpeed||n.max(n.max(n.min(n.abs(this.x-this.startX),1e3),n.min(n.abs(this.y-this.startY),1e3)),300);this.goToPage(this.currentPage.pageX+this.directionX,this.currentPage.pageY+this.directionY,e)})},_nearestSnap:function(e,t){if(!this.pages.length){return{x:0,y:0,pageX:0,pageY:0}}var r=0,i=this.pages.length,s=0;if(n.abs(e-this.absStartX)0){e=0}else if(e0){t=0}else if(t=this.pages[r][0].cx){e=this.pages[r][0].x;break}}i=this.pages[r].length;for(;s=this.pages[0][s].cy){t=this.pages[0][s].y;break}}if(r==this.currentPage.pageX){r+=this.directionX;if(r<0){r=0}else if(r>=this.pages.length){r=this.pages.length-1}e=this.pages[r][0].x}if(s==this.currentPage.pageY){s+=this.directionY;if(s<0){s=0}else if(s>=this.pages[0].length){s=this.pages[0].length-1}t=this.pages[0][s].y}return{x:e,y:t,pageX:r,pageY:s}},goToPage:function(e,t,r,i){i=i||this.options.bounceEasing;if(e>=this.pages.length){e=this.pages.length-1}else if(e<0){e=0}if(t>=this.pages[e].length){t=this.pages[e].length-1}else if(t<0){t=0}var s=this.pages[e][t].x,o=this.pages[e][t].y;r=r===undefined?this.options.snapSpeed||n.max(n.max(n.min(n.abs(s-this.x),1e3),n.min(n.abs(o-this.y),1e3)),300):r;this.currentPage={x:s,y:o,pageX:e,pageY:t};this.scrollTo(s,o,r,i)},next:function(e,t){var n=this.currentPage.pageX,r=this.currentPage.pageY;n++;if(n>=this.pages.length&&this.hasVerticalScroll){n=0;r++}this.goToPage(n,r,e,t)},prev:function(e,t){var n=this.currentPage.pageX,r=this.currentPage.pageY;n--;if(n<0&&this.hasVerticalScroll){n=0;r--}this.goToPage(n,r,e,t)},_initKeys:function(t){var n={pageUp:33,pageDown:34,end:35,home:36,left:37,up:38,right:39,down:40};var r;if(typeof this.options.keyBindings=="object"){for(r in this.options.keyBindings){if(typeof this.options.keyBindings[r]=="string"){this.options.keyBindings[r]=this.options.keyBindings[r].toUpperCase().charCodeAt(0)}}}else{this.options.keyBindings={}}for(r in n){this.options.keyBindings[r]=this.options.keyBindings[r]||n[r]}i.addEvent(e,"keydown",this);this.on("destroy",function(){i.removeEvent(e,"keydown",this)})},_key:function(e){if(!this.enabled){return}var t=this.options.snap,r=t?this.currentPage.pageX:this.x,s=t?this.currentPage.pageY:this.y,o=i.getTime(),u=this.keyTime||0,a=.25,f;if(this.options.useTransition&&this.isInTransition){f=this.getComputedPosition();this._translate(n.round(f.x),n.round(f.y));this.isInTransition=false}this.keyAcceleration=o-u<200?n.min(this.keyAcceleration+a,50):0;switch(e.keyCode){case this.options.keyBindings.pageUp:if(this.hasHorizontalScroll&&!this.hasVerticalScroll){r+=t?1:this.wrapperWidth}else{s+=t?1:this.wrapperHeight}break;case this.options.keyBindings.pageDown:if(this.hasHorizontalScroll&&!this.hasVerticalScroll){r-=t?1:this.wrapperWidth}else{s-=t?1:this.wrapperHeight}break;case this.options.keyBindings.end:r=t?this.pages.length-1:this.maxScrollX;s=t?this.pages[0].length-1:this.maxScrollY;break;case this.options.keyBindings.home:r=0;s=0;break;case this.options.keyBindings.left:r+=t?-1:5+this.keyAcceleration>>0;break;case this.options.keyBindings.up:s+=t?1:5+this.keyAcceleration>>0;break;case this.options.keyBindings.right:r-=t?-1:5+this.keyAcceleration>>0;break;case this.options.keyBindings.down:s-=t?1:5+this.keyAcceleration>>0;break;default:return}if(t){this.goToPage(r,s);return}if(r>0){r=0;this.keyAcceleration=0}else if(r0){s=0;this.keyAcceleration=0}else if(s=l){o.isAnimating=false;o._translate(e,t);if(!o.resetPosition(o.options.bounceTime)){o._execEvent("scrollEnd")}return}h=(h-f)/n;v=s(h);p=(e-u)*v+u;d=(t-a)*v+a;o._translate(p,d);if(o.isAnimating){r(c)}}var o=this,u=this.x,a=this.y,f=i.getTime(),l=f+n;this.isAnimating=true;c()},handleEvent:function(e){switch(e.type){case"touchstart":case"pointerdown":case"MSPointerDown":case"mousedown":this._start(e);break;case"touchmove":case"pointermove":case"MSPointerMove":case"mousemove":this._move(e);break;case"touchend":case"pointerup":case"MSPointerUp":case"mouseup":case"touchcancel":case"pointercancel":case"MSPointerCancel":case"mousecancel":this._end(e);break;case"orientationchange":case"resize":this._resize();break;case"transitionend":case"webkitTransitionEnd":case"oTransitionEnd":case"MSTransitionEnd":this._transitionEnd(e);break;case"wheel":case"DOMMouseScroll":case"mousewheel":this._wheel(e);break;case"keydown":this._key(e);break;case"click":if(!e._constructed){e.preventDefault();e.stopPropagation()}break}}};u.prototype={handleEvent:function(e){switch(e.type){case"touchstart":case"pointerdown":case"MSPointerDown":case"mousedown":this._start(e);break;case"touchmove":case"pointermove":case"MSPointerMove":case"mousemove":this._move(e);break;case"touchend":case"pointerup":case"MSPointerUp":case"mouseup":case"touchcancel":case"pointercancel":case"MSPointerCancel":case"mousecancel":this._end(e);break}},destroy:function(){if(this.options.interactive){i.removeEvent(this.indicator,"touchstart",this);i.removeEvent(this.indicator,i.prefixPointerEvent("pointerdown"),this);i.removeEvent(this.indicator,"mousedown",this);i.removeEvent(e,"touchmove",this);i.removeEvent(e,i.prefixPointerEvent("pointermove"),this);i.removeEvent(e,"mousemove",this);i.removeEvent(e,"touchend",this);i.removeEvent(e,i.prefixPointerEvent("pointerup"),this);i.removeEvent(e,"mouseup",this)}if(this.options.defaultScrollbars){this.wrapper.parentNode.removeChild(this.wrapper)}},_start:function(t){var n=t.touches?t.touches[0]:t;t.preventDefault();t.stopPropagation();this.transitionTime();this.initiated=true;this.moved=false;this.lastPointX=n.pageX;this.lastPointY=n.pageY;this.startTime=i.getTime();if(!this.options.disableTouch){i.addEvent(e,"touchmove",this)}if(!this.options.disablePointer){i.addEvent(e,i.prefixPointerEvent("pointermove"),this)}if(!this.options.disableMouse){i.addEvent(e,"mousemove",this)}this.scroller._execEvent("beforeScrollStart")},_move:function(e){var t=e.touches?e.touches[0]:e,n,r,s,o,u=i.getTime();if(!this.moved){this.scroller._execEvent("scrollStart")}this.moved=true;n=t.pageX-this.lastPointX;this.lastPointX=t.pageX;r=t.pageY-this.lastPointY;this.lastPointY=t.pageY;s=this.x+n;o=this.y+r;this._pos(s,o);e.preventDefault();e.stopPropagation()},_end:function(t){if(!this.initiated){return}this.initiated=false;t.preventDefault();t.stopPropagation();i.removeEvent(e,"touchmove",this);i.removeEvent(e,i.prefixPointerEvent("pointermove"),this);i.removeEvent(e,"mousemove",this);if(this.scroller.options.snap){var r=this.scroller._nearestSnap(this.scroller.x,this.scroller.y);var s=this.options.snapSpeed||n.max(n.max(n.min(n.abs(this.scroller.x-r.x),1e3),n.min(n.abs(this.scroller.y-r.y),1e3)),300);if(this.scroller.x!=r.x||this.scroller.y!=r.y){this.scroller.directionX=0;this.scroller.directionY=0;this.scroller.currentPage=r;this.scroller.scrollTo(r.x,r.y,s,this.scroller.options.bounceEasing)}}if(this.moved){this.scroller._execEvent("scrollEnd")}},transitionTime:function(e){e=e||0;this.indicatorStyle[i.style.transitionDuration]=e+"ms";if(!e&&i.isBadAndroid){this.indicatorStyle[i.style.transitionDuration]="0.001s"}},transitionTimingFunction:function(e){this.indicatorStyle[i.style.transitionTimingFunction]=e},refresh:function(){this.transitionTime();if(this.options.listenX&&!this.options.listenY){this.indicatorStyle.display=this.scroller.hasHorizontalScroll?"block":"none"}else if(this.options.listenY&&!this.options.listenX){this.indicatorStyle.display=this.scroller.hasVerticalScroll?"block":"none"}else{this.indicatorStyle.display=this.scroller.hasHorizontalScroll||this.scroller.hasVerticalScroll?"block":"none"}if(this.scroller.hasHorizontalScroll&&this.scroller.hasVerticalScroll){i.addClass(this.wrapper,"iScrollBothScrollbars");i.removeClass(this.wrapper,"iScrollLoneScrollbar");if(this.options.defaultScrollbars&&this.options.customStyle){if(this.options.listenX){this.wrapper.style.right="8px"}else{this.wrapper.style.bottom="8px"}}}else{i.removeClass(this.wrapper,"iScrollBothScrollbars");i.addClass(this.wrapper,"iScrollLoneScrollbar");if(this.options.defaultScrollbars&&this.options.customStyle){if(this.options.listenX){this.wrapper.style.right="2px"}else{this.wrapper.style.bottom="2px"}}}var e=this.wrapper.offsetHeight;if(this.options.listenX){this.wrapperWidth=this.wrapper.clientWidth;if(this.options.resize){this.indicatorWidth=n.max(n.round(this.wrapperWidth*this.wrapperWidth/(this.scroller.scrollerWidth||this.wrapperWidth||1)),8);this.indicatorStyle.width=this.indicatorWidth+"px"}else{this.indicatorWidth=this.indicator.clientWidth}this.maxPosX=this.wrapperWidth-this.indicatorWidth;if(this.options.shrink=="clip"){this.minBoundaryX=-this.indicatorWidth+8;this.maxBoundaryX=this.wrapperWidth-8}else{this.minBoundaryX=0;this.maxBoundaryX=this.maxPosX}this.sizeRatioX=this.options.speedRatioX||this.scroller.maxScrollX&&this.maxPosX/this.scroller.maxScrollX}if(this.options.listenY){this.wrapperHeight=this.wrapper.clientHeight;if(this.options.resize){this.indicatorHeight=n.max(n.round(this.wrapperHeight*this.wrapperHeight/(this.scroller.scrollerHeight||this.wrapperHeight||1)),8);this.indicatorStyle.height=this.indicatorHeight+"px"}else{this.indicatorHeight=this.indicator.clientHeight}this.maxPosY=this.wrapperHeight-this.indicatorHeight;if(this.options.shrink=="clip"){this.minBoundaryY=-this.indicatorHeight+8;this.maxBoundaryY=this.wrapperHeight-8}else{this.minBoundaryY=0;this.maxBoundaryY=this.maxPosY}this.maxPosY=this.wrapperHeight-this.indicatorHeight;this.sizeRatioY=this.options.speedRatioY||this.scroller.maxScrollY&&this.maxPosY/this.scroller.maxScrollY}this.updatePosition()},updatePosition:function(){var e=this.options.listenX&&n.round(this.sizeRatioX*this.scroller.x)||0,t=this.options.listenY&&n.round(this.sizeRatioY*this.scroller.y)||0;if(!this.options.ignoreBoundaries){if(ethis.maxBoundaryX){if(this.options.shrink=="scale"){this.width=n.max(this.indicatorWidth-(e-this.maxPosX),8);this.indicatorStyle.width=this.width+"px";e=this.maxPosX+this.indicatorWidth-this.width}else{e=this.maxBoundaryX}}else if(this.options.shrink=="scale"&&this.width!=this.indicatorWidth){this.width=this.indicatorWidth;this.indicatorStyle.width=this.width+"px"}if(tthis.maxBoundaryY){if(this.options.shrink=="scale"){this.height=n.max(this.indicatorHeight-(t-this.maxPosY)*3,8);this.indicatorStyle.height=this.height+"px";t=this.maxPosY+this.indicatorHeight-this.height}else{t=this.maxBoundaryY}}else if(this.options.shrink=="scale"&&this.height!=this.indicatorHeight){this.height=this.indicatorHeight;this.indicatorStyle.height=this.height+"px"}}this.x=e;this.y=t;if(this.scroller.options.useTransform){this.indicatorStyle[i.style.transform]="translate("+e+"px,"+t+"px)"+this.scroller.translateZ}else{this.indicatorStyle.left=e+"px";this.indicatorStyle.top=t+"px"}},_pos:function(e,t){if(e<0){e=0}else if(e>this.maxPosX){e=this.maxPosX}if(t<0){t=0}else if(t>this.maxPosY){t=this.maxPosY}e=this.options.listenX?n.round(e/this.sizeRatioX):this.scroller.x;t=this.options.listenY?n.round(t/this.sizeRatioY):this.scroller.y;this.scroller.scrollTo(e,t)},fade:function(e,t){if(t&&!this.visible){return}clearTimeout(this.fadeTimeout);this.fadeTimeout=null;var n=e?250:500,r=e?0:300;e=e?"1":"0";this.wrapperStyle[i.style.transitionDuration]=n+"ms";this.fadeTimeout=setTimeout(function(e){this.wrapperStyle.opacity=e;this.visible=+e}.bind(this,e),r)}};s.utils=i;if(typeof module!="undefined"&&module.exports){module.exports=s}else{e.IScroll=s}})(window,document,Math) \ No newline at end of file diff --git a/static/js/lib/iscroll.js b/static/js/lib/iscroll.js deleted file mode 100755 index 32b1ad5b..00000000 --- a/static/js/lib/iscroll.js +++ /dev/null @@ -1,2006 +0,0 @@ -/*! iScroll v5.1.2 ~ (c) 2008-2014 Matteo Spinelli ~ http://cubiq.org/license */ -(function (window, document, Math) { -var rAF = window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function (callback) { window.setTimeout(callback, 1000 / 60); }; - -var utils = (function () { - var me = {}; - - var _elementStyle = document.createElement('div').style; - var _vendor = (function () { - var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'], - transform, - i = 0, - l = vendors.length; - - for ( ; i < l; i++ ) { - transform = vendors[i] + 'ransform'; - if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1); - } - - return false; - })(); - - function _prefixStyle (style) { - if ( _vendor === false ) return false; - if ( _vendor === '' ) return style; - return _vendor + style.charAt(0).toUpperCase() + style.substr(1); - } - - me.getTime = Date.now || function getTime () { return new Date().getTime(); }; - - me.extend = function (target, obj) { - for ( var i in obj ) { - target[i] = obj[i]; - } - }; - - me.addEvent = function (el, type, fn, capture) { - el.addEventListener(type, fn, !!capture); - }; - - me.removeEvent = function (el, type, fn, capture) { - el.removeEventListener(type, fn, !!capture); - }; - - me.prefixPointerEvent = function (pointerEvent) { - return window.MSPointerEvent ? - 'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10): - pointerEvent; - }; - - me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) { - var distance = current - start, - speed = Math.abs(distance) / time, - destination, - duration; - - deceleration = deceleration === undefined ? 0.0006 : deceleration; - - destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 ); - duration = speed / deceleration; - - if ( destination < lowerMargin ) { - destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin; - distance = Math.abs(destination - current); - duration = distance / speed; - } else if ( destination > 0 ) { - destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0; - distance = Math.abs(current) + destination; - duration = distance / speed; - } - - return { - destination: Math.round(destination), - duration: duration - }; - }; - - var _transform = _prefixStyle('transform'); - - me.extend(me, { - hasTransform: _transform !== false, - hasPerspective: _prefixStyle('perspective') in _elementStyle, - hasTouch: 'ontouchstart' in window, - hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed - hasTransition: _prefixStyle('transition') in _elementStyle - }); - - // This should find all Android browsers lower than build 535.19 (both stock browser and webview) - me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion)); - - me.extend(me.style = {}, { - transform: _transform, - transitionTimingFunction: _prefixStyle('transitionTimingFunction'), - transitionDuration: _prefixStyle('transitionDuration'), - transitionDelay: _prefixStyle('transitionDelay'), - transformOrigin: _prefixStyle('transformOrigin') - }); - - me.hasClass = function (e, c) { - var re = new RegExp("(^|\\s)" + c + "(\\s|$)"); - return re.test(e.className); - }; - - me.addClass = function (e, c) { - if ( me.hasClass(e, c) ) { - return; - } - - var newclass = e.className.split(' '); - newclass.push(c); - e.className = newclass.join(' '); - }; - - me.removeClass = function (e, c) { - if ( !me.hasClass(e, c) ) { - return; - } - - var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g'); - e.className = e.className.replace(re, ' '); - }; - - me.offset = function (el) { - var left = -el.offsetLeft, - top = -el.offsetTop; - - // jshint -W084 - while (el = el.offsetParent) { - left -= el.offsetLeft; - top -= el.offsetTop; - } - // jshint +W084 - - return { - left: left, - top: top - }; - }; - - me.preventDefaultException = function (el, exceptions) { - for ( var i in exceptions ) { - if ( exceptions[i].test(el[i]) ) { - return true; - } - } - - return false; - }; - - me.extend(me.eventType = {}, { - touchstart: 1, - touchmove: 1, - touchend: 1, - - mousedown: 2, - mousemove: 2, - mouseup: 2, - - pointerdown: 3, - pointermove: 3, - pointerup: 3, - - MSPointerDown: 3, - MSPointerMove: 3, - MSPointerUp: 3 - }); - - me.extend(me.ease = {}, { - quadratic: { - style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', - fn: function (k) { - return k * ( 2 - k ); - } - }, - circular: { - style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1) - fn: function (k) { - return Math.sqrt( 1 - ( --k * k ) ); - } - }, - back: { - style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)', - fn: function (k) { - var b = 4; - return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1; - } - }, - bounce: { - style: '', - fn: function (k) { - if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { - return 7.5625 * k * k; - } else if ( k < ( 2 / 2.75 ) ) { - return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; - } else if ( k < ( 2.5 / 2.75 ) ) { - return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; - } else { - return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; - } - } - }, - elastic: { - style: '', - fn: function (k) { - var f = 0.22, - e = 0.4; - - if ( k === 0 ) { return 0; } - if ( k == 1 ) { return 1; } - - return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 ); - } - } - }); - - me.tap = function (e, eventName) { - var ev = document.createEvent('Event'); - ev.initEvent(eventName, true, true); - ev.pageX = e.pageX; - ev.pageY = e.pageY; - e.target.dispatchEvent(ev); - }; - - me.click = function (e) { - var target = e.target, - ev; - - if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) { - ev = document.createEvent('MouseEvents'); - ev.initMouseEvent('click', true, true, e.view, 1, - target.screenX, target.screenY, target.clientX, target.clientY, - e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, - 0, null); - - ev._constructed = true; - target.dispatchEvent(ev); - } - }; - - return me; -})(); - -function IScroll (el, options) { - this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; - this.scroller = this.wrapper.children[0]; - this.scrollerStyle = this.scroller.style; // cache style for better performance - - this.options = { - - resizeScrollbars: true, - - mouseWheelSpeed: 20, - - snapThreshold: 0.334, - -// INSERT POINT: OPTIONS - - startX: 0, - startY: 0, - scrollY: true, - directionLockThreshold: 5, - momentum: true, - - bounce: true, - bounceTime: 600, - bounceEasing: '', - - preventDefault: true, - preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ }, - - HWCompositing: true, - useTransition: true, - useTransform: true - }; - - for ( var i in options ) { - this.options[i] = options[i]; - } - - // Normalize options - this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : ''; - - this.options.useTransition = utils.hasTransition && this.options.useTransition; - this.options.useTransform = utils.hasTransform && this.options.useTransform; - - this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough; - this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault; - - // If you want eventPassthrough I have to lock one of the axes - this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY; - this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX; - - // With eventPassthrough we also need lockDirection mechanism - this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough; - this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold; - - this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing; - - this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling; - - if ( this.options.tap === true ) { - this.options.tap = 'tap'; - } - - if ( this.options.shrinkScrollbars == 'scale' ) { - this.options.useTransition = false; - } - - this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1; - -// INSERT POINT: NORMALIZATION - - // Some defaults - this.x = 0; - this.y = 0; - this.directionX = 0; - this.directionY = 0; - this._events = {}; - -// INSERT POINT: DEFAULTS - - this._init(); - this.refresh(); - - this.scrollTo(this.options.startX, this.options.startY); - this.enable(); -} - -IScroll.prototype = { - version: '5.1.2', - - _init: function () { - this._initEvents(); - - if ( this.options.scrollbars || this.options.indicators ) { - this._initIndicators(); - } - - if ( this.options.mouseWheel ) { - this._initWheel(); - } - - if ( this.options.snap ) { - this._initSnap(); - } - - if ( this.options.keyBindings ) { - this._initKeys(); - } - -// INSERT POINT: _init - - }, - - destroy: function () { - this._initEvents(true); - - this._execEvent('destroy'); - }, - - _transitionEnd: function (e) { - if ( e.target != this.scroller || !this.isInTransition ) { - return; - } - - this._transitionTime(); - if ( !this.resetPosition(this.options.bounceTime) ) { - this.isInTransition = false; - this._execEvent('scrollEnd'); - } - }, - - _start: function (e) { - // React to left mouse button only - if ( utils.eventType[e.type] != 1 ) { - if ( e.button !== 0 ) { - return; - } - } - - if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) { - return; - } - - if ( this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { - e.preventDefault(); - } - - var point = e.touches ? e.touches[0] : e, - pos; - - this.initiated = utils.eventType[e.type]; - this.moved = false; - this.distX = 0; - this.distY = 0; - this.directionX = 0; - this.directionY = 0; - this.directionLocked = 0; - - this._transitionTime(); - - this.startTime = utils.getTime(); - - if ( this.options.useTransition && this.isInTransition ) { - this.isInTransition = false; - pos = this.getComputedPosition(); - this._translate(Math.round(pos.x), Math.round(pos.y)); - this._execEvent('scrollEnd'); - } else if ( !this.options.useTransition && this.isAnimating ) { - this.isAnimating = false; - this._execEvent('scrollEnd'); - } - - this.startX = this.x; - this.startY = this.y; - this.absStartX = this.x; - this.absStartY = this.y; - this.pointX = point.pageX; - this.pointY = point.pageY; - - this._execEvent('beforeScrollStart'); - }, - - _move: function (e) { - if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { - return; - } - - if ( this.options.preventDefault ) { // increases performance on Android? TODO: check! - e.preventDefault(); - } - - var point = e.touches ? e.touches[0] : e, - deltaX = point.pageX - this.pointX, - deltaY = point.pageY - this.pointY, - timestamp = utils.getTime(), - newX, newY, - absDistX, absDistY; - - this.pointX = point.pageX; - this.pointY = point.pageY; - - this.distX += deltaX; - this.distY += deltaY; - absDistX = Math.abs(this.distX); - absDistY = Math.abs(this.distY); - - // We need to move at least 10 pixels for the scrolling to initiate - if ( timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10) ) { - return; - } - - // If you are scrolling in one direction lock the other - if ( !this.directionLocked && !this.options.freeScroll ) { - if ( absDistX > absDistY + this.options.directionLockThreshold ) { - this.directionLocked = 'h'; // lock horizontally - } else if ( absDistY >= absDistX + this.options.directionLockThreshold ) { - this.directionLocked = 'v'; // lock vertically - } else { - this.directionLocked = 'n'; // no lock - } - } - - if ( this.directionLocked == 'h' ) { - if ( this.options.eventPassthrough == 'vertical' ) { - e.preventDefault(); - } else if ( this.options.eventPassthrough == 'horizontal' ) { - this.initiated = false; - return; - } - - deltaY = 0; - } else if ( this.directionLocked == 'v' ) { - if ( this.options.eventPassthrough == 'horizontal' ) { - e.preventDefault(); - } else if ( this.options.eventPassthrough == 'vertical' ) { - this.initiated = false; - return; - } - - deltaX = 0; - } - - deltaX = this.hasHorizontalScroll ? deltaX : 0; - deltaY = this.hasVerticalScroll ? deltaY : 0; - - newX = this.x + deltaX; - newY = this.y + deltaY; - - // Slow down if outside of the boundaries - if ( newX > 0 || newX < this.maxScrollX ) { - newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX; - } - if ( newY > 0 || newY < this.maxScrollY ) { - newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY; - } - - this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; - this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; - - if ( !this.moved ) { - this._execEvent('scrollStart'); - } - - this.moved = true; - - this._translate(newX, newY); - -/* REPLACE START: _move */ - - if ( timestamp - this.startTime > 300 ) { - this.startTime = timestamp; - this.startX = this.x; - this.startY = this.y; - } - -/* REPLACE END: _move */ - - }, - - _end: function (e) { - if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { - return; - } - - if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { - e.preventDefault(); - } - - var point = e.changedTouches ? e.changedTouches[0] : e, - momentumX, - momentumY, - duration = utils.getTime() - this.startTime, - newX = Math.round(this.x), - newY = Math.round(this.y), - distanceX = Math.abs(newX - this.startX), - distanceY = Math.abs(newY - this.startY), - time = 0, - easing = ''; - - this.isInTransition = 0; - this.initiated = 0; - this.endTime = utils.getTime(); - - // reset if we are outside of the boundaries - if ( this.resetPosition(this.options.bounceTime) ) { - return; - } - - this.scrollTo(newX, newY); // ensures that the last position is rounded - - // we scrolled less than 10 pixels - if ( !this.moved ) { - if ( this.options.tap ) { - utils.tap(e, this.options.tap); - } - - if ( this.options.click ) { - utils.click(e); - } - - this._execEvent('scrollCancel'); - return; - } - - if ( this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) { - this._execEvent('flick'); - return; - } - - // start momentum animation if needed - if ( this.options.momentum && duration < 300 ) { - momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : { destination: newX, duration: 0 }; - momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : { destination: newY, duration: 0 }; - newX = momentumX.destination; - newY = momentumY.destination; - time = Math.max(momentumX.duration, momentumY.duration); - this.isInTransition = 1; - } - - - if ( this.options.snap ) { - var snap = this._nearestSnap(newX, newY); - this.currentPage = snap; - time = this.options.snapSpeed || Math.max( - Math.max( - Math.min(Math.abs(newX - snap.x), 1000), - Math.min(Math.abs(newY - snap.y), 1000) - ), 300); - newX = snap.x; - newY = snap.y; - - this.directionX = 0; - this.directionY = 0; - easing = this.options.bounceEasing; - } - -// INSERT POINT: _end - - if ( newX != this.x || newY != this.y ) { - // change easing function when scroller goes out of the boundaries - if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) { - easing = utils.ease.quadratic; - } - - this.scrollTo(newX, newY, time, easing); - return; - } - - this._execEvent('scrollEnd'); - }, - - _resize: function () { - var that = this; - - clearTimeout(this.resizeTimeout); - - this.resizeTimeout = setTimeout(function () { - that.refresh(); - }, this.options.resizePolling); - }, - - resetPosition: function (time) { - var x = this.x, - y = this.y; - - time = time || 0; - - if ( !this.hasHorizontalScroll || this.x > 0 ) { - x = 0; - } else if ( this.x < this.maxScrollX ) { - x = this.maxScrollX; - } - - if ( !this.hasVerticalScroll || this.y > 0 ) { - y = 0; - } else if ( this.y < this.maxScrollY ) { - y = this.maxScrollY; - } - - if ( x == this.x && y == this.y ) { - return false; - } - - this.scrollTo(x, y, time, this.options.bounceEasing); - - return true; - }, - - disable: function () { - this.enabled = false; - }, - - enable: function () { - this.enabled = true; - }, - - refresh: function () { - var rf = this.wrapper.offsetHeight; // Force reflow - - this.wrapperWidth = this.wrapper.clientWidth; - this.wrapperHeight = this.wrapper.clientHeight; - -/* REPLACE START: refresh */ - - this.scrollerWidth = this.scroller.offsetWidth; - this.scrollerHeight = this.scroller.offsetHeight; - - this.maxScrollX = this.wrapperWidth - this.scrollerWidth; - this.maxScrollY = this.wrapperHeight - this.scrollerHeight; - -/* REPLACE END: refresh */ - - this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0; - this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0; - - if ( !this.hasHorizontalScroll ) { - this.maxScrollX = 0; - this.scrollerWidth = this.wrapperWidth; - } - - if ( !this.hasVerticalScroll ) { - this.maxScrollY = 0; - this.scrollerHeight = this.wrapperHeight; - } - - this.endTime = 0; - this.directionX = 0; - this.directionY = 0; - - this.wrapperOffset = utils.offset(this.wrapper); - - this._execEvent('refresh'); - - this.resetPosition(); - -// INSERT POINT: _refresh - - }, - - on: function (type, fn) { - if ( !this._events[type] ) { - this._events[type] = []; - } - - this._events[type].push(fn); - }, - - off: function (type, fn) { - if ( !this._events[type] ) { - return; - } - - var index = this._events[type].indexOf(fn); - - if ( index > -1 ) { - this._events[type].splice(index, 1); - } - }, - - _execEvent: function (type) { - if ( !this._events[type] ) { - return; - } - - var i = 0, - l = this._events[type].length; - - if ( !l ) { - return; - } - - for ( ; i < l; i++ ) { - this._events[type][i].apply(this, [].slice.call(arguments, 1)); - } - }, - - scrollBy: function (x, y, time, easing) { - x = this.x + x; - y = this.y + y; - time = time || 0; - - this.scrollTo(x, y, time, easing); - }, - - scrollTo: function (x, y, time, easing) { - easing = easing || utils.ease.circular; - - this.isInTransition = this.options.useTransition && time > 0; - - if ( !time || (this.options.useTransition && easing.style) ) { - this._transitionTimingFunction(easing.style); - this._transitionTime(time); - this._translate(x, y); - } else { - this._animate(x, y, time, easing.fn); - } - }, - - scrollToElement: function (el, time, offsetX, offsetY, easing) { - el = el.nodeType ? el : this.scroller.querySelector(el); - - if ( !el ) { - return; - } - - var pos = utils.offset(el); - - pos.left -= this.wrapperOffset.left; - pos.top -= this.wrapperOffset.top; - - // if offsetX/Y are true we center the element to the screen - if ( offsetX === true ) { - offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2); - } - if ( offsetY === true ) { - offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2); - } - - pos.left -= offsetX || 0; - pos.top -= offsetY || 0; - - pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left; - pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top; - - time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time; - - this.scrollTo(pos.left, pos.top, time, easing); - }, - - _transitionTime: function (time) { - time = time || 0; - - this.scrollerStyle[utils.style.transitionDuration] = time + 'ms'; - - if ( !time && utils.isBadAndroid ) { - this.scrollerStyle[utils.style.transitionDuration] = '0.001s'; - } - - - if ( this.indicators ) { - for ( var i = this.indicators.length; i--; ) { - this.indicators[i].transitionTime(time); - } - } - - -// INSERT POINT: _transitionTime - - }, - - _transitionTimingFunction: function (easing) { - this.scrollerStyle[utils.style.transitionTimingFunction] = easing; - - - if ( this.indicators ) { - for ( var i = this.indicators.length; i--; ) { - this.indicators[i].transitionTimingFunction(easing); - } - } - - -// INSERT POINT: _transitionTimingFunction - - }, - - _translate: function (x, y) { - if ( this.options.useTransform ) { - -/* REPLACE START: _translate */ - - this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ; - -/* REPLACE END: _translate */ - - } else { - x = Math.round(x); - y = Math.round(y); - this.scrollerStyle.left = x + 'px'; - this.scrollerStyle.top = y + 'px'; - } - - this.x = x; - this.y = y; - - - if ( this.indicators ) { - for ( var i = this.indicators.length; i--; ) { - this.indicators[i].updatePosition(); - } - } - - -// INSERT POINT: _translate - - }, - - _initEvents: function (remove) { - var eventType = remove ? utils.removeEvent : utils.addEvent, - target = this.options.bindToWrapper ? this.wrapper : window; - - eventType(window, 'orientationchange', this); - eventType(window, 'resize', this); - - if ( this.options.click ) { - eventType(this.wrapper, 'click', this, true); - } - - if ( !this.options.disableMouse ) { - eventType(this.wrapper, 'mousedown', this); - eventType(target, 'mousemove', this); - eventType(target, 'mousecancel', this); - eventType(target, 'mouseup', this); - } - - if ( utils.hasPointer && !this.options.disablePointer ) { - eventType(this.wrapper, utils.prefixPointerEvent('pointerdown'), this); - eventType(target, utils.prefixPointerEvent('pointermove'), this); - eventType(target, utils.prefixPointerEvent('pointercancel'), this); - eventType(target, utils.prefixPointerEvent('pointerup'), this); - } - - if ( utils.hasTouch && !this.options.disableTouch ) { - eventType(this.wrapper, 'touchstart', this); - eventType(target, 'touchmove', this); - eventType(target, 'touchcancel', this); - eventType(target, 'touchend', this); - } - - eventType(this.scroller, 'transitionend', this); - eventType(this.scroller, 'webkitTransitionEnd', this); - eventType(this.scroller, 'oTransitionEnd', this); - eventType(this.scroller, 'MSTransitionEnd', this); - }, - - getComputedPosition: function () { - var matrix = window.getComputedStyle(this.scroller, null), - x, y; - - if ( this.options.useTransform ) { - matrix = matrix[utils.style.transform].split(')')[0].split(', '); - x = +(matrix[12] || matrix[4]); - y = +(matrix[13] || matrix[5]); - } else { - x = +matrix.left.replace(/[^-\d.]/g, ''); - y = +matrix.top.replace(/[^-\d.]/g, ''); - } - - return { x: x, y: y }; - }, - - _initIndicators: function () { - var interactive = this.options.interactiveScrollbars, - customStyle = typeof this.options.scrollbars != 'string', - indicators = [], - indicator; - - var that = this; - - this.indicators = []; - - if ( this.options.scrollbars ) { - // Vertical scrollbar - if ( this.options.scrollY ) { - indicator = { - el: createDefaultScrollbar('v', interactive, this.options.scrollbars), - interactive: interactive, - defaultScrollbars: true, - customStyle: customStyle, - resize: this.options.resizeScrollbars, - shrink: this.options.shrinkScrollbars, - fade: this.options.fadeScrollbars, - listenX: false - }; - - this.wrapper.appendChild(indicator.el); - indicators.push(indicator); - } - - // Horizontal scrollbar - if ( this.options.scrollX ) { - indicator = { - el: createDefaultScrollbar('h', interactive, this.options.scrollbars), - interactive: interactive, - defaultScrollbars: true, - customStyle: customStyle, - resize: this.options.resizeScrollbars, - shrink: this.options.shrinkScrollbars, - fade: this.options.fadeScrollbars, - listenY: false - }; - - this.wrapper.appendChild(indicator.el); - indicators.push(indicator); - } - } - - if ( this.options.indicators ) { - // TODO: check concat compatibility - indicators = indicators.concat(this.options.indicators); - } - - for ( var i = indicators.length; i--; ) { - this.indicators.push( new Indicator(this, indicators[i]) ); - } - - // TODO: check if we can use array.map (wide compatibility and performance issues) - function _indicatorsMap (fn) { - for ( var i = that.indicators.length; i--; ) { - fn.call(that.indicators[i]); - } - } - - if ( this.options.fadeScrollbars ) { - this.on('scrollEnd', function () { - _indicatorsMap(function () { - this.fade(); - }); - }); - - this.on('scrollCancel', function () { - _indicatorsMap(function () { - this.fade(); - }); - }); - - this.on('scrollStart', function () { - _indicatorsMap(function () { - this.fade(1); - }); - }); - - this.on('beforeScrollStart', function () { - _indicatorsMap(function () { - this.fade(1, true); - }); - }); - } - - - this.on('refresh', function () { - _indicatorsMap(function () { - this.refresh(); - }); - }); - - this.on('destroy', function () { - _indicatorsMap(function () { - this.destroy(); - }); - - delete this.indicators; - }); - }, - - _initWheel: function () { - utils.addEvent(this.wrapper, 'wheel', this); - utils.addEvent(this.wrapper, 'mousewheel', this); - utils.addEvent(this.wrapper, 'DOMMouseScroll', this); - - this.on('destroy', function () { - utils.removeEvent(this.wrapper, 'wheel', this); - utils.removeEvent(this.wrapper, 'mousewheel', this); - utils.removeEvent(this.wrapper, 'DOMMouseScroll', this); - }); - }, - - _wheel: function (e) { - if ( !this.enabled ) { - return; - } - - e.preventDefault(); - e.stopPropagation(); - - var wheelDeltaX, wheelDeltaY, - newX, newY, - that = this; - - if ( this.wheelTimeout === undefined ) { - that._execEvent('scrollStart'); - } - - // Execute the scrollEnd event after 400ms the wheel stopped scrolling - clearTimeout(this.wheelTimeout); - this.wheelTimeout = setTimeout(function () { - that._execEvent('scrollEnd'); - that.wheelTimeout = undefined; - }, 400); - - if ( 'deltaX' in e ) { - wheelDeltaX = -e.deltaX; - wheelDeltaY = -e.deltaY; - } else if ( 'wheelDeltaX' in e ) { - wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed; - wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed; - } else if ( 'wheelDelta' in e ) { - wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed; - } else if ( 'detail' in e ) { - wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed; - } else { - return; - } - - wheelDeltaX *= this.options.invertWheelDirection; - wheelDeltaY *= this.options.invertWheelDirection; - - if ( !this.hasVerticalScroll ) { - wheelDeltaX = wheelDeltaY; - wheelDeltaY = 0; - } - - if ( this.options.snap ) { - newX = this.currentPage.pageX; - newY = this.currentPage.pageY; - - if ( wheelDeltaX > 0 ) { - newX--; - } else if ( wheelDeltaX < 0 ) { - newX++; - } - - if ( wheelDeltaY > 0 ) { - newY--; - } else if ( wheelDeltaY < 0 ) { - newY++; - } - - this.goToPage(newX, newY); - - return; - } - - newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0); - newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0); - - if ( newX > 0 ) { - newX = 0; - } else if ( newX < this.maxScrollX ) { - newX = this.maxScrollX; - } - - if ( newY > 0 ) { - newY = 0; - } else if ( newY < this.maxScrollY ) { - newY = this.maxScrollY; - } - - this.scrollTo(newX, newY, 0); - -// INSERT POINT: _wheel - }, - - _initSnap: function () { - this.currentPage = {}; - - if ( typeof this.options.snap == 'string' ) { - this.options.snap = this.scroller.querySelectorAll(this.options.snap); - } - - this.on('refresh', function () { - var i = 0, l, - m = 0, n, - cx, cy, - x = 0, y, - stepX = this.options.snapStepX || this.wrapperWidth, - stepY = this.options.snapStepY || this.wrapperHeight, - el; - - this.pages = []; - - if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) { - return; - } - - if ( this.options.snap === true ) { - cx = Math.round( stepX / 2 ); - cy = Math.round( stepY / 2 ); - - while ( x > -this.scrollerWidth ) { - this.pages[i] = []; - l = 0; - y = 0; - - while ( y > -this.scrollerHeight ) { - this.pages[i][l] = { - x: Math.max(x, this.maxScrollX), - y: Math.max(y, this.maxScrollY), - width: stepX, - height: stepY, - cx: x - cx, - cy: y - cy - }; - - y -= stepY; - l++; - } - - x -= stepX; - i++; - } - } else { - el = this.options.snap; - l = el.length; - n = -1; - - for ( ; i < l; i++ ) { - if ( i === 0 || el[i].offsetLeft <= el[i-1].offsetLeft ) { - m = 0; - n++; - } - - if ( !this.pages[m] ) { - this.pages[m] = []; - } - - x = Math.max(-el[i].offsetLeft, this.maxScrollX); - y = Math.max(-el[i].offsetTop, this.maxScrollY); - cx = x - Math.round(el[i].offsetWidth / 2); - cy = y - Math.round(el[i].offsetHeight / 2); - - this.pages[m][n] = { - x: x, - y: y, - width: el[i].offsetWidth, - height: el[i].offsetHeight, - cx: cx, - cy: cy - }; - - if ( x > this.maxScrollX ) { - m++; - } - } - } - - this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0); - - // Update snap threshold if needed - if ( this.options.snapThreshold % 1 === 0 ) { - this.snapThresholdX = this.options.snapThreshold; - this.snapThresholdY = this.options.snapThreshold; - } else { - this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold); - this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold); - } - }); - - this.on('flick', function () { - var time = this.options.snapSpeed || Math.max( - Math.max( - Math.min(Math.abs(this.x - this.startX), 1000), - Math.min(Math.abs(this.y - this.startY), 1000) - ), 300); - - this.goToPage( - this.currentPage.pageX + this.directionX, - this.currentPage.pageY + this.directionY, - time - ); - }); - }, - - _nearestSnap: function (x, y) { - if ( !this.pages.length ) { - return { x: 0, y: 0, pageX: 0, pageY: 0 }; - } - - var i = 0, - l = this.pages.length, - m = 0; - - // Check if we exceeded the snap threshold - if ( Math.abs(x - this.absStartX) < this.snapThresholdX && - Math.abs(y - this.absStartY) < this.snapThresholdY ) { - return this.currentPage; - } - - if ( x > 0 ) { - x = 0; - } else if ( x < this.maxScrollX ) { - x = this.maxScrollX; - } - - if ( y > 0 ) { - y = 0; - } else if ( y < this.maxScrollY ) { - y = this.maxScrollY; - } - - for ( ; i < l; i++ ) { - if ( x >= this.pages[i][0].cx ) { - x = this.pages[i][0].x; - break; - } - } - - l = this.pages[i].length; - - for ( ; m < l; m++ ) { - if ( y >= this.pages[0][m].cy ) { - y = this.pages[0][m].y; - break; - } - } - - if ( i == this.currentPage.pageX ) { - i += this.directionX; - - if ( i < 0 ) { - i = 0; - } else if ( i >= this.pages.length ) { - i = this.pages.length - 1; - } - - x = this.pages[i][0].x; - } - - if ( m == this.currentPage.pageY ) { - m += this.directionY; - - if ( m < 0 ) { - m = 0; - } else if ( m >= this.pages[0].length ) { - m = this.pages[0].length - 1; - } - - y = this.pages[0][m].y; - } - - return { - x: x, - y: y, - pageX: i, - pageY: m - }; - }, - - goToPage: function (x, y, time, easing) { - easing = easing || this.options.bounceEasing; - - if ( x >= this.pages.length ) { - x = this.pages.length - 1; - } else if ( x < 0 ) { - x = 0; - } - - if ( y >= this.pages[x].length ) { - y = this.pages[x].length - 1; - } else if ( y < 0 ) { - y = 0; - } - - var posX = this.pages[x][y].x, - posY = this.pages[x][y].y; - - time = time === undefined ? this.options.snapSpeed || Math.max( - Math.max( - Math.min(Math.abs(posX - this.x), 1000), - Math.min(Math.abs(posY - this.y), 1000) - ), 300) : time; - - this.currentPage = { - x: posX, - y: posY, - pageX: x, - pageY: y - }; - - this.scrollTo(posX, posY, time, easing); - }, - - next: function (time, easing) { - var x = this.currentPage.pageX, - y = this.currentPage.pageY; - - x++; - - if ( x >= this.pages.length && this.hasVerticalScroll ) { - x = 0; - y++; - } - - this.goToPage(x, y, time, easing); - }, - - prev: function (time, easing) { - var x = this.currentPage.pageX, - y = this.currentPage.pageY; - - x--; - - if ( x < 0 && this.hasVerticalScroll ) { - x = 0; - y--; - } - - this.goToPage(x, y, time, easing); - }, - - _initKeys: function (e) { - // default key bindings - var keys = { - pageUp: 33, - pageDown: 34, - end: 35, - home: 36, - left: 37, - up: 38, - right: 39, - down: 40 - }; - var i; - - // if you give me characters I give you keycode - if ( typeof this.options.keyBindings == 'object' ) { - for ( i in this.options.keyBindings ) { - if ( typeof this.options.keyBindings[i] == 'string' ) { - this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0); - } - } - } else { - this.options.keyBindings = {}; - } - - for ( i in keys ) { - this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i]; - } - - utils.addEvent(window, 'keydown', this); - - this.on('destroy', function () { - utils.removeEvent(window, 'keydown', this); - }); - }, - - _key: function (e) { - if ( !this.enabled ) { - return; - } - - var snap = this.options.snap, // we are using this alot, better to cache it - newX = snap ? this.currentPage.pageX : this.x, - newY = snap ? this.currentPage.pageY : this.y, - now = utils.getTime(), - prevTime = this.keyTime || 0, - acceleration = 0.250, - pos; - - if ( this.options.useTransition && this.isInTransition ) { - pos = this.getComputedPosition(); - - this._translate(Math.round(pos.x), Math.round(pos.y)); - this.isInTransition = false; - } - - this.keyAcceleration = now - prevTime < 200 ? Math.min(this.keyAcceleration + acceleration, 50) : 0; - - switch ( e.keyCode ) { - case this.options.keyBindings.pageUp: - if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { - newX += snap ? 1 : this.wrapperWidth; - } else { - newY += snap ? 1 : this.wrapperHeight; - } - break; - case this.options.keyBindings.pageDown: - if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { - newX -= snap ? 1 : this.wrapperWidth; - } else { - newY -= snap ? 1 : this.wrapperHeight; - } - break; - case this.options.keyBindings.end: - newX = snap ? this.pages.length-1 : this.maxScrollX; - newY = snap ? this.pages[0].length-1 : this.maxScrollY; - break; - case this.options.keyBindings.home: - newX = 0; - newY = 0; - break; - case this.options.keyBindings.left: - newX += snap ? -1 : 5 + this.keyAcceleration>>0; - break; - case this.options.keyBindings.up: - newY += snap ? 1 : 5 + this.keyAcceleration>>0; - break; - case this.options.keyBindings.right: - newX -= snap ? -1 : 5 + this.keyAcceleration>>0; - break; - case this.options.keyBindings.down: - newY -= snap ? 1 : 5 + this.keyAcceleration>>0; - break; - default: - return; - } - - if ( snap ) { - this.goToPage(newX, newY); - return; - } - - if ( newX > 0 ) { - newX = 0; - this.keyAcceleration = 0; - } else if ( newX < this.maxScrollX ) { - newX = this.maxScrollX; - this.keyAcceleration = 0; - } - - if ( newY > 0 ) { - newY = 0; - this.keyAcceleration = 0; - } else if ( newY < this.maxScrollY ) { - newY = this.maxScrollY; - this.keyAcceleration = 0; - } - - this.scrollTo(newX, newY, 0); - - this.keyTime = now; - }, - - _animate: function (destX, destY, duration, easingFn) { - var that = this, - startX = this.x, - startY = this.y, - startTime = utils.getTime(), - destTime = startTime + duration; - - function step () { - var now = utils.getTime(), - newX, newY, - easing; - - if ( now >= destTime ) { - that.isAnimating = false; - that._translate(destX, destY); - - if ( !that.resetPosition(that.options.bounceTime) ) { - that._execEvent('scrollEnd'); - } - - return; - } - - now = ( now - startTime ) / duration; - easing = easingFn(now); - newX = ( destX - startX ) * easing + startX; - newY = ( destY - startY ) * easing + startY; - that._translate(newX, newY); - - if ( that.isAnimating ) { - rAF(step); - } - } - - this.isAnimating = true; - step(); - }, - handleEvent: function (e) { - switch ( e.type ) { - case 'touchstart': - case 'pointerdown': - case 'MSPointerDown': - case 'mousedown': - this._start(e); - break; - case 'touchmove': - case 'pointermove': - case 'MSPointerMove': - case 'mousemove': - this._move(e); - break; - case 'touchend': - case 'pointerup': - case 'MSPointerUp': - case 'mouseup': - case 'touchcancel': - case 'pointercancel': - case 'MSPointerCancel': - case 'mousecancel': - this._end(e); - break; - case 'orientationchange': - case 'resize': - this._resize(); - break; - case 'transitionend': - case 'webkitTransitionEnd': - case 'oTransitionEnd': - case 'MSTransitionEnd': - this._transitionEnd(e); - break; - case 'wheel': - case 'DOMMouseScroll': - case 'mousewheel': - this._wheel(e); - break; - case 'keydown': - this._key(e); - break; - case 'click': - if ( !e._constructed ) { - e.preventDefault(); - e.stopPropagation(); - } - break; - } - } -}; -function createDefaultScrollbar (direction, interactive, type) { - var scrollbar = document.createElement('div'), - indicator = document.createElement('div'); - - if ( type === true ) { - scrollbar.style.cssText = 'position:absolute;z-index:9999'; - indicator.style.cssText = '-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px'; - } - - indicator.className = 'iScrollIndicator'; - - if ( direction == 'h' ) { - if ( type === true ) { - scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0'; - indicator.style.height = '100%'; - } - scrollbar.className = 'iScrollHorizontalScrollbar'; - } else { - if ( type === true ) { - scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px'; - indicator.style.width = '100%'; - } - scrollbar.className = 'iScrollVerticalScrollbar'; - } - - scrollbar.style.cssText += ';overflow:hidden'; - - if ( !interactive ) { - scrollbar.style.pointerEvents = 'none'; - } - - scrollbar.appendChild(indicator); - - return scrollbar; -} - -function Indicator (scroller, options) { - this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el; - this.wrapperStyle = this.wrapper.style; - this.indicator = this.wrapper.children[0]; - this.indicatorStyle = this.indicator.style; - this.scroller = scroller; - - this.options = { - listenX: true, - listenY: true, - interactive: false, - resize: true, - defaultScrollbars: false, - shrink: false, - fade: false, - speedRatioX: 0, - speedRatioY: 0 - }; - - for ( var i in options ) { - this.options[i] = options[i]; - } - - this.sizeRatioX = 1; - this.sizeRatioY = 1; - this.maxPosX = 0; - this.maxPosY = 0; - - if ( this.options.interactive ) { - if ( !this.options.disableTouch ) { - utils.addEvent(this.indicator, 'touchstart', this); - utils.addEvent(window, 'touchend', this); - } - if ( !this.options.disablePointer ) { - utils.addEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this); - utils.addEvent(window, utils.prefixPointerEvent('pointerup'), this); - } - if ( !this.options.disableMouse ) { - utils.addEvent(this.indicator, 'mousedown', this); - utils.addEvent(window, 'mouseup', this); - } - } - - if ( this.options.fade ) { - this.wrapperStyle[utils.style.transform] = this.scroller.translateZ; - this.wrapperStyle[utils.style.transitionDuration] = utils.isBadAndroid ? '0.001s' : '0ms'; - this.wrapperStyle.opacity = '0'; - } -} - -Indicator.prototype = { - handleEvent: function (e) { - switch ( e.type ) { - case 'touchstart': - case 'pointerdown': - case 'MSPointerDown': - case 'mousedown': - this._start(e); - break; - case 'touchmove': - case 'pointermove': - case 'MSPointerMove': - case 'mousemove': - this._move(e); - break; - case 'touchend': - case 'pointerup': - case 'MSPointerUp': - case 'mouseup': - case 'touchcancel': - case 'pointercancel': - case 'MSPointerCancel': - case 'mousecancel': - this._end(e); - break; - } - }, - - destroy: function () { - if ( this.options.interactive ) { - utils.removeEvent(this.indicator, 'touchstart', this); - utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this); - utils.removeEvent(this.indicator, 'mousedown', this); - - utils.removeEvent(window, 'touchmove', this); - utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this); - utils.removeEvent(window, 'mousemove', this); - - utils.removeEvent(window, 'touchend', this); - utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this); - utils.removeEvent(window, 'mouseup', this); - } - - if ( this.options.defaultScrollbars ) { - this.wrapper.parentNode.removeChild(this.wrapper); - } - }, - - _start: function (e) { - var point = e.touches ? e.touches[0] : e; - - e.preventDefault(); - e.stopPropagation(); - - this.transitionTime(); - - this.initiated = true; - this.moved = false; - this.lastPointX = point.pageX; - this.lastPointY = point.pageY; - - this.startTime = utils.getTime(); - - if ( !this.options.disableTouch ) { - utils.addEvent(window, 'touchmove', this); - } - if ( !this.options.disablePointer ) { - utils.addEvent(window, utils.prefixPointerEvent('pointermove'), this); - } - if ( !this.options.disableMouse ) { - utils.addEvent(window, 'mousemove', this); - } - - this.scroller._execEvent('beforeScrollStart'); - }, - - _move: function (e) { - var point = e.touches ? e.touches[0] : e, - deltaX, deltaY, - newX, newY, - timestamp = utils.getTime(); - - if ( !this.moved ) { - this.scroller._execEvent('scrollStart'); - } - - this.moved = true; - - deltaX = point.pageX - this.lastPointX; - this.lastPointX = point.pageX; - - deltaY = point.pageY - this.lastPointY; - this.lastPointY = point.pageY; - - newX = this.x + deltaX; - newY = this.y + deltaY; - - this._pos(newX, newY); - -// INSERT POINT: indicator._move - - e.preventDefault(); - e.stopPropagation(); - }, - - _end: function (e) { - if ( !this.initiated ) { - return; - } - - this.initiated = false; - - e.preventDefault(); - e.stopPropagation(); - - utils.removeEvent(window, 'touchmove', this); - utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this); - utils.removeEvent(window, 'mousemove', this); - - if ( this.scroller.options.snap ) { - var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y); - - var time = this.options.snapSpeed || Math.max( - Math.max( - Math.min(Math.abs(this.scroller.x - snap.x), 1000), - Math.min(Math.abs(this.scroller.y - snap.y), 1000) - ), 300); - - if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) { - this.scroller.directionX = 0; - this.scroller.directionY = 0; - this.scroller.currentPage = snap; - this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing); - } - } - - if ( this.moved ) { - this.scroller._execEvent('scrollEnd'); - } - }, - - transitionTime: function (time) { - time = time || 0; - this.indicatorStyle[utils.style.transitionDuration] = time + 'ms'; - - if ( !time && utils.isBadAndroid ) { - this.indicatorStyle[utils.style.transitionDuration] = '0.001s'; - } - }, - - transitionTimingFunction: function (easing) { - this.indicatorStyle[utils.style.transitionTimingFunction] = easing; - }, - - refresh: function () { - this.transitionTime(); - - if ( this.options.listenX && !this.options.listenY ) { - this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none'; - } else if ( this.options.listenY && !this.options.listenX ) { - this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none'; - } else { - this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none'; - } - - if ( this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ) { - utils.addClass(this.wrapper, 'iScrollBothScrollbars'); - utils.removeClass(this.wrapper, 'iScrollLoneScrollbar'); - - if ( this.options.defaultScrollbars && this.options.customStyle ) { - if ( this.options.listenX ) { - this.wrapper.style.right = '8px'; - } else { - this.wrapper.style.bottom = '8px'; - } - } - } else { - utils.removeClass(this.wrapper, 'iScrollBothScrollbars'); - utils.addClass(this.wrapper, 'iScrollLoneScrollbar'); - - if ( this.options.defaultScrollbars && this.options.customStyle ) { - if ( this.options.listenX ) { - this.wrapper.style.right = '2px'; - } else { - this.wrapper.style.bottom = '2px'; - } - } - } - - var r = this.wrapper.offsetHeight; // force refresh - - if ( this.options.listenX ) { - this.wrapperWidth = this.wrapper.clientWidth; - if ( this.options.resize ) { - this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8); - this.indicatorStyle.width = this.indicatorWidth + 'px'; - } else { - this.indicatorWidth = this.indicator.clientWidth; - } - - this.maxPosX = this.wrapperWidth - this.indicatorWidth; - - if ( this.options.shrink == 'clip' ) { - this.minBoundaryX = -this.indicatorWidth + 8; - this.maxBoundaryX = this.wrapperWidth - 8; - } else { - this.minBoundaryX = 0; - this.maxBoundaryX = this.maxPosX; - } - - this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX)); - } - - if ( this.options.listenY ) { - this.wrapperHeight = this.wrapper.clientHeight; - if ( this.options.resize ) { - this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8); - this.indicatorStyle.height = this.indicatorHeight + 'px'; - } else { - this.indicatorHeight = this.indicator.clientHeight; - } - - this.maxPosY = this.wrapperHeight - this.indicatorHeight; - - if ( this.options.shrink == 'clip' ) { - this.minBoundaryY = -this.indicatorHeight + 8; - this.maxBoundaryY = this.wrapperHeight - 8; - } else { - this.minBoundaryY = 0; - this.maxBoundaryY = this.maxPosY; - } - - this.maxPosY = this.wrapperHeight - this.indicatorHeight; - this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY)); - } - - this.updatePosition(); - }, - - updatePosition: function () { - var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0, - y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0; - - if ( !this.options.ignoreBoundaries ) { - if ( x < this.minBoundaryX ) { - if ( this.options.shrink == 'scale' ) { - this.width = Math.max(this.indicatorWidth + x, 8); - this.indicatorStyle.width = this.width + 'px'; - } - x = this.minBoundaryX; - } else if ( x > this.maxBoundaryX ) { - if ( this.options.shrink == 'scale' ) { - this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8); - this.indicatorStyle.width = this.width + 'px'; - x = this.maxPosX + this.indicatorWidth - this.width; - } else { - x = this.maxBoundaryX; - } - } else if ( this.options.shrink == 'scale' && this.width != this.indicatorWidth ) { - this.width = this.indicatorWidth; - this.indicatorStyle.width = this.width + 'px'; - } - - if ( y < this.minBoundaryY ) { - if ( this.options.shrink == 'scale' ) { - this.height = Math.max(this.indicatorHeight + y * 3, 8); - this.indicatorStyle.height = this.height + 'px'; - } - y = this.minBoundaryY; - } else if ( y > this.maxBoundaryY ) { - if ( this.options.shrink == 'scale' ) { - this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8); - this.indicatorStyle.height = this.height + 'px'; - y = this.maxPosY + this.indicatorHeight - this.height; - } else { - y = this.maxBoundaryY; - } - } else if ( this.options.shrink == 'scale' && this.height != this.indicatorHeight ) { - this.height = this.indicatorHeight; - this.indicatorStyle.height = this.height + 'px'; - } - } - - this.x = x; - this.y = y; - - if ( this.scroller.options.useTransform ) { - this.indicatorStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.scroller.translateZ; - } else { - this.indicatorStyle.left = x + 'px'; - this.indicatorStyle.top = y + 'px'; - } - }, - - _pos: function (x, y) { - if ( x < 0 ) { - x = 0; - } else if ( x > this.maxPosX ) { - x = this.maxPosX; - } - - if ( y < 0 ) { - y = 0; - } else if ( y > this.maxPosY ) { - y = this.maxPosY; - } - - x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x; - y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y; - - this.scroller.scrollTo(x, y); - }, - - fade: function (val, hold) { - if ( hold && !this.visible ) { - return; - } - - clearTimeout(this.fadeTimeout); - this.fadeTimeout = null; - - var time = val ? 250 : 500, - delay = val ? 0 : 300; - - val = val ? '1' : '0'; - - this.wrapperStyle[utils.style.transitionDuration] = time + 'ms'; - - this.fadeTimeout = setTimeout((function (val) { - this.wrapperStyle.opacity = val; - this.visible = +val; - }).bind(this, val), delay); - } -}; - -IScroll.utils = utils; - -if ( typeof module != 'undefined' && module.exports ) { - module.exports = IScroll; -} else { - window.IScroll = IScroll; -} - -})(window, document, Math); \ No newline at end of file