| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584 | /*! iScroll v5.1.3 ~ (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 = {		mouseWheelSpeed: 20,		snapThreshold: 0.334,		infiniteUseTransform: true,		deceleration: 0.004,// 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';	}	this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1;	if ( this.options.infiniteElements ) {		this.options.probeType = 3;	}	this.options.infiniteUseTransform = this.options.infiniteUseTransform && this.options.useTransform;	if ( this.options.probeType == 3 ) {		this.options.useTransition = false;	}// 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.3',	_init: function () {		this._initEvents();		if ( this.options.mouseWheel ) {			this._initWheel();		}		if ( this.options.snap ) {			this._initSnap();		}		if ( this.options.keyBindings ) {			this._initKeys();		}		if ( this.options.infiniteElements ) {			this._initInfinite();		}// 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;			if ( this.options.probeType == 1 ) {				this._execEvent('scroll');			}		}		if ( this.options.probeType > 1 ) {			this._execEvent('scroll');		}/* 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;				var limit;		if ( this.options.infiniteElements ) {			this.options.infiniteLimit = this.options.infiniteLimit || Math.floor(2147483645 / this.infiniteElementHeight);			limit = -this.options.infiniteLimit * this.infiniteElementHeight + this.wrapperHeight;		}		this.maxScrollY		= limit !== undefined ? limit : 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';		}// INSERT POINT: _transitionTime	},	_transitionTimingFunction: function (easing) {		this.scrollerStyle[utils.style.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;// 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 };	},	_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 ) {			if (e.deltaMode === 1) {				wheelDeltaX = -e.deltaX * this.options.mouseWheelSpeed;				wheelDeltaY = -e.deltaY * this.options.mouseWheelSpeed;			} else {				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);		if ( this.options.probeType > 1 ) {			this._execEvent('scroll');		}// 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);			}			if ( that.options.probeType == 3 ) {				that._execEvent('scroll');			}		}		this.isAnimating = true;		step();	},	_initInfinite: function () {		var el = this.options.infiniteElements;		this.infiniteElements = typeof el == 'string' ? document.querySelectorAll(el) : el;		this.infiniteLength = this.infiniteElements.length;		this.infiniteMaster = this.infiniteElements[0];		this.infiniteElementHeight = this.infiniteMaster.offsetHeight;		this.infiniteHeight = this.infiniteLength * this.infiniteElementHeight;		this.options.cacheSize = this.options.cacheSize || 1000;		this.infiniteCacheBuffer = Math.round(this.options.cacheSize / 4);		//this.infiniteCache = {};		this.options.dataset.call(this, 0, this.options.cacheSize);		this.on('refresh', function () {			var elementsPerPage = Math.ceil(this.wrapperHeight / this.infiniteElementHeight);			this.infiniteUpperBufferSize = Math.floor((this.infiniteLength - elementsPerPage) / 2);			this.reorderInfinite();		});		this.on('scroll', this.reorderInfinite);	},	// TO-DO: clean up the mess	reorderInfinite: function () {		var center = -this.y + this.wrapperHeight / 2;		var minorPhase = Math.max(Math.floor(-this.y / this.infiniteElementHeight) - this.infiniteUpperBufferSize, 0),			majorPhase = Math.floor(minorPhase / this.infiniteLength),			phase = minorPhase - majorPhase * this.infiniteLength;		var top = 0;		var i = 0;		var update = [];		//var cachePhase = Math.floor((minorPhase + this.infiniteLength / 2) / this.infiniteCacheBuffer);		var cachePhase = Math.floor(minorPhase / this.infiniteCacheBuffer);		while ( i < this.infiniteLength ) {			top = i * this.infiniteElementHeight + majorPhase * this.infiniteHeight;			if ( phase > i ) {				top += this.infiniteElementHeight * this.infiniteLength;			}			if ( this.infiniteElements[i]._top !== top ) {				this.infiniteElements[i]._phase = top / this.infiniteElementHeight;				if ( this.infiniteElements[i]._phase < this.options.infiniteLimit ) {					this.infiniteElements[i]._top = top;					if ( this.options.infiniteUseTransform ) {						this.infiniteElements[i].style[utils.style.transform] = 'translate(0, ' + top + 'px)' + this.translateZ;					} else {						this.infiniteElements[i].style.top = top + 'px';					}					update.push(this.infiniteElements[i]);				}			}			i++;		}		if ( this.cachePhase != cachePhase && (cachePhase === 0 || minorPhase - this.infiniteCacheBuffer > 0) ) {			this.options.dataset.call(this, Math.max(cachePhase * this.infiniteCacheBuffer - this.infiniteCacheBuffer, 0), this.options.cacheSize);		}		this.cachePhase = cachePhase;		this.updateContent(update);	},	updateContent: function (els) {		if ( this.infiniteCache === undefined ) {			return;		}		for ( var i = 0, l = els.length; i < l; i++ ) {			this.options.dataFiller.call(this, els[i], this.infiniteCache[els[i]._phase]);		}	},	updateCache: function (start, data) {		var firstRun = this.infiniteCache === undefined;		this.infiniteCache = {};		for ( var i = 0, l = data.length; i < l; i++ ) {			this.infiniteCache[start++] = data[i];		}		if ( firstRun ) {			this.updateContent(this.infiniteElements);		}	},	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;		}	}};IScroll.utils = utils;if ( typeof module != 'undefined' && module.exports ) {	module.exports = IScroll;} else {	window.IScroll = IScroll;}})(window, document, Math);
 |