Subversion Repositories SmartDukaan

Rev

Rev 20685 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20685 Rev 20700
Line 1... Line 1...
1
/*! iScroll v5.1.3 ~ (c) 2008-2014 Matteo Spinelli ~ http://cubiq.org/license */
1
/*! iScroll v5.2.0-snapshot ~ (c) 2008-2017 Matteo Spinelli ~ http://cubiq.org/license */
2
(function (window, document, Math) {
2
(function (window, document, Math) {
3
var rAF = window.requestAnimationFrame	||
3
var rAF = window.requestAnimationFrame	||
4
	window.webkitRequestAnimationFrame	||
4
	window.webkitRequestAnimationFrame	||
5
	window.mozRequestAnimationFrame		||
5
	window.mozRequestAnimationFrame		||
6
	window.oRequestAnimationFrame		||
6
	window.oRequestAnimationFrame		||
Line 46... Line 46...
46
	me.removeEvent = function (el, type, fn, capture) {
46
	me.removeEvent = function (el, type, fn, capture) {
47
		el.removeEventListener(type, fn, !!capture);
47
		el.removeEventListener(type, fn, !!capture);
48
	};
48
	};
49
 
49
 
50
	me.prefixPointerEvent = function (pointerEvent) {
50
	me.prefixPointerEvent = function (pointerEvent) {
51
		return window.MSPointerEvent ? 
51
		return window.MSPointerEvent ?
52
			'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10):
52
			'MSPointer' + pointerEvent.charAt(7).toUpperCase() + pointerEvent.substr(8):
53
			pointerEvent;
53
			pointerEvent;
54
	};
54
	};
55
 
55
 
56
	me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) {
56
	me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) {
57
		var distance = current - start,
57
		var distance = current - start,
Line 84... Line 84...
84
 
84
 
85
	me.extend(me, {
85
	me.extend(me, {
86
		hasTransform: _transform !== false,
86
		hasTransform: _transform !== false,
87
		hasPerspective: _prefixStyle('perspective') in _elementStyle,
87
		hasPerspective: _prefixStyle('perspective') in _elementStyle,
88
		hasTouch: 'ontouchstart' in window,
88
		hasTouch: 'ontouchstart' in window,
89
		hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed
89
		hasPointer: !!(window.PointerEvent || window.MSPointerEvent), // IE10 is prefixed
90
		hasTransition: _prefixStyle('transition') in _elementStyle
90
		hasTransition: _prefixStyle('transition') in _elementStyle
91
	});
91
	});
92
 
92
 
-
 
93
	/*
93
	// This should find all Android browsers lower than build 535.19 (both stock browser and webview)
94
	This should find all Android browsers lower than build 535.19 (both stock browser and webview)
-
 
95
	- galaxy S2 is ok
-
 
96
    - 2.3.6 : `AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1`
-
 
97
    - 4.0.4 : `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
-
 
98
   - galaxy S3 is badAndroid (stock brower, webview)
-
 
99
     `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
-
 
100
   - galaxy S4 is badAndroid (stock brower, webview)
-
 
101
     `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
-
 
102
   - galaxy S5 is OK
-
 
103
     `AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
-
 
104
   - galaxy S6 is OK
-
 
105
     `AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
-
 
106
  */
-
 
107
	me.isBadAndroid = (function() {
-
 
108
		var appVersion = window.navigator.appVersion;
-
 
109
		// Android browser is not a chrome browser.
94
	me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion));
110
		if (/Android/.test(appVersion) && !(/Chrome\/\d/.test(appVersion))) {
-
 
111
			var safariVersion = appVersion.match(/Safari\/(\d+.\d)/);
-
 
112
			if(safariVersion && typeof safariVersion === "object" && safariVersion.length >= 2) {
-
 
113
				return parseFloat(safariVersion[1]) < 535.19;
-
 
114
			} else {
-
 
115
				return true;
-
 
116
			}
-
 
117
		} else {
-
 
118
			return false;
-
 
119
		}
-
 
120
	})();
95
 
121
 
96
	me.extend(me.style = {}, {
122
	me.extend(me.style = {}, {
97
		transform: _transform,
123
		transform: _transform,
98
		transitionTimingFunction: _prefixStyle('transitionTimingFunction'),
124
		transitionTimingFunction: _prefixStyle('transitionTimingFunction'),
99
		transitionDuration: _prefixStyle('transitionDuration'),
125
		transitionDuration: _prefixStyle('transitionDuration'),
100
		transitionDelay: _prefixStyle('transitionDelay'),
126
		transitionDelay: _prefixStyle('transitionDelay'),
101
		transformOrigin: _prefixStyle('transformOrigin')
127
		transformOrigin: _prefixStyle('transformOrigin'),
-
 
128
		touchAction: _prefixStyle('touchAction')
102
	});
129
	});
103
 
130
 
104
	me.hasClass = function (e, c) {
131
	me.hasClass = function (e, c) {
105
		var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
132
		var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
106
		return re.test(e.className);
133
		return re.test(e.className);
Line 229... Line 256...
229
	me.click = function (e) {
256
	me.click = function (e) {
230
		var target = e.target,
257
		var target = e.target,
231
			ev;
258
			ev;
232
 
259
 
233
		if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
260
		if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
-
 
261
			// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
-
 
262
			// initMouseEvent is deprecated.
234
			ev = document.createEvent('MouseEvents');
263
			ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
235
			ev.initMouseEvent('click', true, true, e.view, 1,
264
			ev.initEvent('click', true, true);
-
 
265
			ev.view = e.view || window;
-
 
266
			ev.detail = 1;
-
 
267
			ev.screenX = target.screenX || 0;
236
				target.screenX, target.screenY, target.clientX, target.clientY,
268
			ev.screenY = target.screenY || 0;
-
 
269
			ev.clientX = target.clientX || 0;
-
 
270
			ev.clientY = target.clientY || 0;
-
 
271
			ev.ctrlKey = !!e.ctrlKey;
-
 
272
			ev.altKey = !!e.altKey;
-
 
273
			ev.shiftKey = !!e.shiftKey;
237
				e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
274
			ev.metaKey = !!e.metaKey;
238
				0, null);
275
			ev.button = 0;
239
 
-
 
-
 
276
			ev.relatedTarget = null;
240
			ev._constructed = true;
277
			ev._constructed = true;
241
			target.dispatchEvent(ev);
278
			target.dispatchEvent(ev);
242
		}
279
		}
243
	};
280
	};
244
 
281
 
-
 
282
	me.getTouchAction = function(eventPassthrough, addPinch) {
-
 
283
		var touchAction = 'none';
-
 
284
		if ( eventPassthrough === 'vertical' ) {
-
 
285
			touchAction = 'pan-y';
-
 
286
		} else if (eventPassthrough === 'horizontal' ) {
-
 
287
			touchAction = 'pan-x';
-
 
288
		}
-
 
289
		if (addPinch && touchAction != 'none') {
-
 
290
			// add pinch-zoom support if the browser supports it, but if not (eg. Chrome <55) do nothing
-
 
291
			touchAction += ' pinch-zoom';
-
 
292
		}
-
 
293
		return touchAction;
-
 
294
	};
-
 
295
 
-
 
296
	me.getRect = function(el) {
-
 
297
		if (el instanceof SVGElement) {
-
 
298
			var rect = el.getBoundingClientRect();
-
 
299
			return {
-
 
300
				top : rect.top,
-
 
301
				left : rect.left,
-
 
302
				width : rect.width,
-
 
303
				height : rect.height
-
 
304
			};
-
 
305
		} else {
-
 
306
			return {
-
 
307
				top : el.offsetTop,
-
 
308
				left : el.offsetLeft,
-
 
309
				width : el.offsetWidth,
-
 
310
				height : el.offsetHeight
-
 
311
			};
-
 
312
		}
-
 
313
	};
-
 
314
 
245
	return me;
315
	return me;
246
})();
316
})();
247
 
-
 
248
function IScroll (el, options) {
317
function IScroll (el, options) {
249
	this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
318
	this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
250
	this.scroller = this.wrapper.children[0];
319
	this.scroller = this.wrapper.children[0];
251
	this.scrollerStyle = this.scroller.style;		// cache style for better performance
320
	this.scrollerStyle = this.scroller.style;		// cache style for better performance
252
 
321
 
Line 256... Line 325...
256
 
325
 
257
		mouseWheelSpeed: 20,
326
		mouseWheelSpeed: 20,
258
 
327
 
259
		snapThreshold: 0.334,
328
		snapThreshold: 0.334,
260
 
329
 
261
// INSERT POINT: OPTIONS 
330
// INSERT POINT: OPTIONS
262
 
-
 
-
 
331
		disablePointer : !utils.hasPointer,
-
 
332
		disableTouch : utils.hasPointer || !utils.hasTouch,
-
 
333
		disableMouse : utils.hasPointer || utils.hasTouch,
263
		startX: 0,
334
		startX: 0,
264
		startY: 0,
335
		startY: 0,
265
		scrollY: true,
336
		scrollY: true,
266
		directionLockThreshold: 5,
337
		directionLockThreshold: 5,
267
		momentum: true,
338
		momentum: true,
Line 273... Line 344...
273
		preventDefault: true,
344
		preventDefault: true,
274
		preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },
345
		preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },
275
 
346
 
276
		HWCompositing: true,
347
		HWCompositing: true,
277
		useTransition: true,
348
		useTransition: true,
278
		useTransform: true
349
		useTransform: true,
-
 
350
		bindToWrapper: typeof window.onmousedown === "undefined"
279
	};
351
	};
280
 
352
 
281
	for ( var i in options ) {
353
	for ( var i in options ) {
282
		this.options[i] = options[i];
354
		this.options[i] = options[i];
283
	}
355
	}
Line 305... Line 377...
305
 
377
 
306
	if ( this.options.tap === true ) {
378
	if ( this.options.tap === true ) {
307
		this.options.tap = 'tap';
379
		this.options.tap = 'tap';
308
	}
380
	}
309
 
381
 
-
 
382
	// https://github.com/cubiq/iscroll/issues/1029
-
 
383
	if (!this.options.useTransition && !this.options.useTransform) {
-
 
384
		if(!(/relative|absolute/i).test(this.scrollerStyle.position)) {
-
 
385
			this.scrollerStyle.position = "relative";
-
 
386
		}
-
 
387
	}
-
 
388
 
310
	if ( this.options.shrinkScrollbars == 'scale' ) {
389
	if ( this.options.shrinkScrollbars == 'scale' ) {
311
		this.options.useTransition = false;
390
		this.options.useTransition = false;
312
	}
391
	}
313
 
392
 
314
	this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1;
393
	this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1;
315
 
394
 
316
// INSERT POINT: NORMALIZATION
395
// INSERT POINT: NORMALIZATION
317
 
396
 
318
	// Some defaults	
397
	// Some defaults
319
	this.x = 0;
398
	this.x = 0;
320
	this.y = 0;
399
	this.y = 0;
321
	this.directionX = 0;
400
	this.directionX = 0;
322
	this.directionY = 0;
401
	this.directionY = 0;
323
	this._events = {};
402
	this._events = {};
Line 330... Line 409...
330
	this.scrollTo(this.options.startX, this.options.startY);
409
	this.scrollTo(this.options.startX, this.options.startY);
331
	this.enable();
410
	this.enable();
332
}
411
}
333
 
412
 
334
IScroll.prototype = {
413
IScroll.prototype = {
335
	version: '5.1.3',
414
	version: '5.2.0-snapshot',
336
 
415
 
337
	_init: function () {
416
	_init: function () {
338
		this._initEvents();
417
		this._initEvents();
339
 
418
 
340
		if ( this.options.scrollbars || this.options.indicators ) {
419
		if ( this.options.scrollbars || this.options.indicators ) {
Line 357... Line 436...
357
 
436
 
358
	},
437
	},
359
 
438
 
360
	destroy: function () {
439
	destroy: function () {
361
		this._initEvents(true);
440
		this._initEvents(true);
362
 
-
 
-
 
441
		clearTimeout(this.resizeTimeout);
-
 
442
 		this.resizeTimeout = null;
363
		this._execEvent('destroy');
443
		this._execEvent('destroy');
364
	},
444
	},
365
 
445
 
366
	_transitionEnd: function (e) {
446
	_transitionEnd: function (e) {
367
		if ( e.target != this.scroller || !this.isInTransition ) {
447
		if ( e.target != this.scroller || !this.isInTransition ) {
Line 376... Line 456...
376
	},
456
	},
377
 
457
 
378
	_start: function (e) {
458
	_start: function (e) {
379
		// React to left mouse button only
459
		// React to left mouse button only
380
		if ( utils.eventType[e.type] != 1 ) {
460
		if ( utils.eventType[e.type] != 1 ) {
-
 
461
		  // for button property
-
 
462
		  // http://unixpapa.com/js/mouse.html
-
 
463
		  var button;
-
 
464
	    if (!e.which) {
-
 
465
	      /* IE case */
-
 
466
	      button = (e.button < 2) ? 0 :
-
 
467
	               ((e.button == 4) ? 1 : 2);
-
 
468
	    } else {
-
 
469
	      /* All others */
-
 
470
	      button = e.button;
-
 
471
	    }
381
			if ( e.button !== 0 ) {
472
			if ( button !== 0 ) {
382
				return;
473
				return;
383
			}
474
			}
384
		}
475
		}
385
 
476
 
386
		if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) {
477
		if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) {
Line 400... Line 491...
400
		this.distY		= 0;
491
		this.distY		= 0;
401
		this.directionX = 0;
492
		this.directionX = 0;
402
		this.directionY = 0;
493
		this.directionY = 0;
403
		this.directionLocked = 0;
494
		this.directionLocked = 0;
404
 
495
 
405
		this._transitionTime();
-
 
406
 
-
 
407
		this.startTime = utils.getTime();
496
		this.startTime = utils.getTime();
408
 
497
 
409
		if ( this.options.useTransition && this.isInTransition ) {
498
		if ( this.options.useTransition && this.isInTransition ) {
-
 
499
			this._transitionTime();
410
			this.isInTransition = false;
500
			this.isInTransition = false;
411
			pos = this.getComputedPosition();
501
			pos = this.getComputedPosition();
412
			this._translate(Math.round(pos.x), Math.round(pos.y));
502
			this._translate(Math.round(pos.x), Math.round(pos.y));
413
			this._execEvent('scrollEnd');
503
			this._execEvent('scrollEnd');
414
		} else if ( !this.options.useTransition && this.isAnimating ) {
504
		} else if ( !this.options.useTransition && this.isAnimating ) {
Line 659... Line 749...
659
	enable: function () {
749
	enable: function () {
660
		this.enabled = true;
750
		this.enabled = true;
661
	},
751
	},
662
 
752
 
663
	refresh: function () {
753
	refresh: function () {
664
		var rf = this.wrapper.offsetHeight;		// Force reflow
754
		utils.getRect(this.wrapper);		// Force reflow
665
 
755
 
666
		this.wrapperWidth	= this.wrapper.clientWidth;
756
		this.wrapperWidth	= this.wrapper.clientWidth;
667
		this.wrapperHeight	= this.wrapper.clientHeight;
757
		this.wrapperHeight	= this.wrapper.clientHeight;
668
 
758
 
-
 
759
		var rect = utils.getRect(this.scroller);
669
/* REPLACE START: refresh */
760
/* REPLACE START: refresh */
670
 
761
 
671
		this.scrollerWidth	= this.scroller.offsetWidth;
762
		this.scrollerWidth	= rect.width;
672
		this.scrollerHeight	= this.scroller.offsetHeight;
763
		this.scrollerHeight	= rect.height;
673
 
764
 
674
		this.maxScrollX		= this.wrapperWidth - this.scrollerWidth;
765
		this.maxScrollX		= this.wrapperWidth - this.scrollerWidth;
675
		this.maxScrollY		= this.wrapperHeight - this.scrollerHeight;
766
		this.maxScrollY		= this.wrapperHeight - this.scrollerHeight;
676
 
767
 
677
/* REPLACE END: refresh */
768
/* REPLACE END: refresh */
678
 
769
 
679
		this.hasHorizontalScroll	= this.options.scrollX && this.maxScrollX < 0;
770
		this.hasHorizontalScroll	= this.options.scrollX && this.maxScrollX < 0;
680
		this.hasVerticalScroll		= this.options.scrollY && this.maxScrollY < 0;
771
		this.hasVerticalScroll		= this.options.scrollY && this.maxScrollY < 0;
681
 
772
		
682
		if ( !this.hasHorizontalScroll ) {
773
		if ( !this.hasHorizontalScroll ) {
683
			this.maxScrollX = 0;
774
			this.maxScrollX = 0;
684
			this.scrollerWidth = this.wrapperWidth;
775
			this.scrollerWidth = this.wrapperWidth;
685
		}
776
		}
686
 
777
 
Line 690... Line 781...
690
		}
781
		}
691
 
782
 
692
		this.endTime = 0;
783
		this.endTime = 0;
693
		this.directionX = 0;
784
		this.directionX = 0;
694
		this.directionY = 0;
785
		this.directionY = 0;
-
 
786
		
-
 
787
		if(utils.hasPointer && !this.options.disablePointer) {
-
 
788
			// The wrapper should have `touchAction` property for using pointerEvent.
-
 
789
			this.wrapper.style[utils.style.touchAction] = utils.getTouchAction(this.options.eventPassthrough, true);
695
 
790
 
-
 
791
			// case. not support 'pinch-zoom'
-
 
792
			// https://github.com/cubiq/iscroll/issues/1118#issuecomment-270057583
-
 
793
			if (!this.wrapper.style[utils.style.touchAction]) {
-
 
794
				this.wrapper.style[utils.style.touchAction] = utils.getTouchAction(this.options.eventPassthrough, false);
-
 
795
			}
-
 
796
		}
696
		this.wrapperOffset = utils.offset(this.wrapper);
797
		this.wrapperOffset = utils.offset(this.wrapper);
697
 
798
 
698
		this._execEvent('refresh');
799
		this._execEvent('refresh');
699
 
800
 
700
		this.resetPosition();
801
		this.resetPosition();
701
 
802
 
702
// INSERT POINT: _refresh
803
// INSERT POINT: _refresh
703
 
804
 
704
	},
805
	},	
705
 
806
 
706
	on: function (type, fn) {
807
	on: function (type, fn) {
707
		if ( !this._events[type] ) {
808
		if ( !this._events[type] ) {
708
			this._events[type] = [];
809
			this._events[type] = [];
709
		}
810
		}
Line 750... Line 851...
750
 
851
 
751
	scrollTo: function (x, y, time, easing) {
852
	scrollTo: function (x, y, time, easing) {
752
		easing = easing || utils.ease.circular;
853
		easing = easing || utils.ease.circular;
753
 
854
 
754
		this.isInTransition = this.options.useTransition && time > 0;
855
		this.isInTransition = this.options.useTransition && time > 0;
755
 
-
 
756
		if ( !time || (this.options.useTransition && easing.style) ) {
856
		var transitionType = this.options.useTransition && easing.style;
-
 
857
		if ( !time || transitionType ) {
-
 
858
				if(transitionType) {
757
			this._transitionTimingFunction(easing.style);
859
					this._transitionTimingFunction(easing.style);
758
			this._transitionTime(time);
860
					this._transitionTime(time);
-
 
861
				}
759
			this._translate(x, y);
862
			this._translate(x, y);
760
		} else {
863
		} else {
761
			this._animate(x, y, time, easing.fn);
864
			this._animate(x, y, time, easing.fn);
762
		}
865
		}
763
	},
866
	},
Line 773... Line 876...
773
 
876
 
774
		pos.left -= this.wrapperOffset.left;
877
		pos.left -= this.wrapperOffset.left;
775
		pos.top  -= this.wrapperOffset.top;
878
		pos.top  -= this.wrapperOffset.top;
776
 
879
 
777
		// if offsetX/Y are true we center the element to the screen
880
		// if offsetX/Y are true we center the element to the screen
-
 
881
		var elRect = utils.getRect(el);
-
 
882
		var wrapperRect = utils.getRect(this.wrapper);
778
		if ( offsetX === true ) {
883
		if ( offsetX === true ) {
779
			offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2);
884
			offsetX = Math.round(elRect.width / 2 - wrapperRect.width / 2);
780
		}
885
		}
781
		if ( offsetY === true ) {
886
		if ( offsetY === true ) {
782
			offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2);
887
			offsetY = Math.round(elRect.height / 2 - wrapperRect.height / 2);
783
		}
888
		}
784
 
889
 
785
		pos.left -= offsetX || 0;
890
		pos.left -= offsetX || 0;
786
		pos.top  -= offsetY || 0;
891
		pos.top  -= offsetY || 0;
787
 
892
 
Line 792... Line 897...
792
 
897
 
793
		this.scrollTo(pos.left, pos.top, time, easing);
898
		this.scrollTo(pos.left, pos.top, time, easing);
794
	},
899
	},
795
 
900
 
796
	_transitionTime: function (time) {
901
	_transitionTime: function (time) {
-
 
902
		if (!this.options.useTransition) {
-
 
903
			return;
-
 
904
		}
797
		time = time || 0;
905
		time = time || 0;
-
 
906
		var durationProp = utils.style.transitionDuration;
-
 
907
		if(!durationProp) {
-
 
908
			return;
-
 
909
		}
798
 
910
 
799
		this.scrollerStyle[utils.style.transitionDuration] = time + 'ms';
911
		this.scrollerStyle[durationProp] = time + 'ms';
800
 
912
 
801
		if ( !time && utils.isBadAndroid ) {
913
		if ( !time && utils.isBadAndroid ) {
802
			this.scrollerStyle[utils.style.transitionDuration] = '0.001s';
914
			this.scrollerStyle[durationProp] = '0.0001ms';
-
 
915
			// remove 0.0001ms
-
 
916
			var self = this;
-
 
917
			rAF(function() {
-
 
918
				if(self.scrollerStyle[durationProp] === '0.0001ms') {
-
 
919
					self.scrollerStyle[durationProp] = '0s';
-
 
920
				}
-
 
921
			});
803
		}
922
		}
804
 
923
 
805
 
924
 
806
		if ( this.indicators ) {
925
		if ( this.indicators ) {
807
			for ( var i = this.indicators.length; i--; ) {
926
			for ( var i = this.indicators.length; i--; ) {
Line 911... Line 1030...
911
			y = +matrix.top.replace(/[^-\d.]/g, '');
1030
			y = +matrix.top.replace(/[^-\d.]/g, '');
912
		}
1031
		}
913
 
1032
 
914
		return { x: x, y: y };
1033
		return { x: x, y: y };
915
	},
1034
	},
916
 
-
 
917
	_initIndicators: function () {
1035
	_initIndicators: function () {
918
		var interactive = this.options.interactiveScrollbars,
1036
		var interactive = this.options.interactiveScrollbars,
919
			customStyle = typeof this.options.scrollbars != 'string',
1037
			customStyle = typeof this.options.scrollbars != 'string',
920
			indicators = [],
1038
			indicators = [],
921
			indicator;
1039
			indicator;
Line 969... Line 1087...
969
			this.indicators.push( new Indicator(this, indicators[i]) );
1087
			this.indicators.push( new Indicator(this, indicators[i]) );
970
		}
1088
		}
971
 
1089
 
972
		// TODO: check if we can use array.map (wide compatibility and performance issues)
1090
		// TODO: check if we can use array.map (wide compatibility and performance issues)
973
		function _indicatorsMap (fn) {
1091
		function _indicatorsMap (fn) {
-
 
1092
			if (that.indicators) {
974
			for ( var i = that.indicators.length; i--; ) {
1093
				for ( var i = that.indicators.length; i--; ) {
975
				fn.call(that.indicators[i]);
1094
					fn.call(that.indicators[i]);
-
 
1095
				}
976
			}
1096
			}
977
		}
1097
		}
978
 
1098
 
979
		if ( this.options.fadeScrollbars ) {
1099
		if ( this.options.fadeScrollbars ) {
980
			this.on('scrollEnd', function () {
1100
			this.on('scrollEnd', function () {
Line 1022... Line 1142...
1022
		utils.addEvent(this.wrapper, 'wheel', this);
1142
		utils.addEvent(this.wrapper, 'wheel', this);
1023
		utils.addEvent(this.wrapper, 'mousewheel', this);
1143
		utils.addEvent(this.wrapper, 'mousewheel', this);
1024
		utils.addEvent(this.wrapper, 'DOMMouseScroll', this);
1144
		utils.addEvent(this.wrapper, 'DOMMouseScroll', this);
1025
 
1145
 
1026
		this.on('destroy', function () {
1146
		this.on('destroy', function () {
-
 
1147
			clearTimeout(this.wheelTimeout);
-
 
1148
			this.wheelTimeout = null;
1027
			utils.removeEvent(this.wrapper, 'wheel', this);
1149
			utils.removeEvent(this.wrapper, 'wheel', this);
1028
			utils.removeEvent(this.wrapper, 'mousewheel', this);
1150
			utils.removeEvent(this.wrapper, 'mousewheel', this);
1029
			utils.removeEvent(this.wrapper, 'DOMMouseScroll', this);
1151
			utils.removeEvent(this.wrapper, 'DOMMouseScroll', this);
1030
		});
1152
		});
1031
	},
1153
	},
Line 1034... Line 1156...
1034
		if ( !this.enabled ) {
1156
		if ( !this.enabled ) {
1035
			return;
1157
			return;
1036
		}
1158
		}
1037
 
1159
 
1038
		e.preventDefault();
1160
		e.preventDefault();
1039
		e.stopPropagation();
-
 
1040
 
1161
 
1041
		var wheelDeltaX, wheelDeltaY,
1162
		var wheelDeltaX, wheelDeltaY,
1042
			newX, newY,
1163
			newX, newY,
1043
			that = this;
1164
			that = this;
1044
 
1165
 
Line 1047... Line 1168...
1047
		}
1168
		}
1048
 
1169
 
1049
		// Execute the scrollEnd event after 400ms the wheel stopped scrolling
1170
		// Execute the scrollEnd event after 400ms the wheel stopped scrolling
1050
		clearTimeout(this.wheelTimeout);
1171
		clearTimeout(this.wheelTimeout);
1051
		this.wheelTimeout = setTimeout(function () {
1172
		this.wheelTimeout = setTimeout(function () {
-
 
1173
			if(!that.options.snap) {
1052
			that._execEvent('scrollEnd');
1174
				that._execEvent('scrollEnd');
-
 
1175
			}
1053
			that.wheelTimeout = undefined;
1176
			that.wheelTimeout = undefined;
1054
		}, 400);
1177
		}, 400);
1055
 
1178
 
1056
		if ( 'deltaX' in e ) {
1179
		if ( 'deltaX' in e ) {
1057
			if (e.deltaMode === 1) {
1180
			if (e.deltaMode === 1) {
Line 1102... Line 1225...
1102
		}
1225
		}
1103
 
1226
 
1104
		newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0);
1227
		newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0);
1105
		newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0);
1228
		newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0);
1106
 
1229
 
-
 
1230
		this.directionX = wheelDeltaX > 0 ? -1 : wheelDeltaX < 0 ? 1 : 0;
-
 
1231
		this.directionY = wheelDeltaY > 0 ? -1 : wheelDeltaY < 0 ? 1 : 0;
-
 
1232
 
1107
		if ( newX > 0 ) {
1233
		if ( newX > 0 ) {
1108
			newX = 0;
1234
			newX = 0;
1109
		} else if ( newX < this.maxScrollX ) {
1235
		} else if ( newX < this.maxScrollX ) {
1110
			newX = this.maxScrollX;
1236
			newX = this.maxScrollX;
1111
		}
1237
		}
Line 1133... Line 1259...
1133
				m = 0, n,
1259
				m = 0, n,
1134
				cx, cy,
1260
				cx, cy,
1135
				x = 0, y,
1261
				x = 0, y,
1136
				stepX = this.options.snapStepX || this.wrapperWidth,
1262
				stepX = this.options.snapStepX || this.wrapperWidth,
1137
				stepY = this.options.snapStepY || this.wrapperHeight,
1263
				stepY = this.options.snapStepY || this.wrapperHeight,
1138
				el;
1264
				el,
-
 
1265
				rect;
1139
 
1266
 
1140
			this.pages = [];
1267
			this.pages = [];
1141
 
1268
 
1142
			if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) {
1269
			if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) {
1143
				return;
1270
				return;
Line 1173... Line 1300...
1173
				el = this.options.snap;
1300
				el = this.options.snap;
1174
				l = el.length;
1301
				l = el.length;
1175
				n = -1;
1302
				n = -1;
1176
 
1303
 
1177
				for ( ; i < l; i++ ) {
1304
				for ( ; i < l; i++ ) {
-
 
1305
					rect = utils.getRect(el[i]);
1178
					if ( i === 0 || el[i].offsetLeft <= el[i-1].offsetLeft ) {
1306
					if ( i === 0 || rect.left <= utils.getRect(el[i-1]).left ) {
1179
						m = 0;
1307
						m = 0;
1180
						n++;
1308
						n++;
1181
					}
1309
					}
1182
 
1310
 
1183
					if ( !this.pages[m] ) {
1311
					if ( !this.pages[m] ) {
1184
						this.pages[m] = [];
1312
						this.pages[m] = [];
1185
					}
1313
					}
1186
 
1314
 
1187
					x = Math.max(-el[i].offsetLeft, this.maxScrollX);
1315
					x = Math.max(-rect.left, this.maxScrollX);
1188
					y = Math.max(-el[i].offsetTop, this.maxScrollY);
1316
					y = Math.max(-rect.top, this.maxScrollY);
1189
					cx = x - Math.round(el[i].offsetWidth / 2);
1317
					cx = x - Math.round(rect.width / 2);
1190
					cy = y - Math.round(el[i].offsetHeight / 2);
1318
					cy = y - Math.round(rect.height / 2);
1191
 
1319
 
1192
					this.pages[m][n] = {
1320
					this.pages[m][n] = {
1193
						x: x,
1321
						x: x,
1194
						y: y,
1322
						y: y,
1195
						width: el[i].offsetWidth,
1323
						width: rect.width,
1196
						height: el[i].offsetHeight,
1324
						height: rect.height,
1197
						cx: cx,
1325
						cx: cx,
1198
						cy: cy
1326
						cy: cy
1199
					};
1327
					};
1200
 
1328
 
1201
					if ( x > this.maxScrollX ) {
1329
					if ( x > this.maxScrollX ) {
Line 1569... Line 1697...
1569
				break;
1697
				break;
1570
			case 'keydown':
1698
			case 'keydown':
1571
				this._key(e);
1699
				this._key(e);
1572
				break;
1700
				break;
1573
			case 'click':
1701
			case 'click':
1574
				if ( !e._constructed ) {
1702
				if ( this.enabled && !e._constructed ) {
1575
					e.preventDefault();
1703
					e.preventDefault();
1576
					e.stopPropagation();
1704
					e.stopPropagation();
1577
				}
1705
				}
1578
				break;
1706
				break;
1579
		}
1707
		}
Line 1658... Line 1786...
1658
		}
1786
		}
1659
	}
1787
	}
1660
 
1788
 
1661
	if ( this.options.fade ) {
1789
	if ( this.options.fade ) {
1662
		this.wrapperStyle[utils.style.transform] = this.scroller.translateZ;
1790
		this.wrapperStyle[utils.style.transform] = this.scroller.translateZ;
-
 
1791
		var durationProp = utils.style.transitionDuration;
-
 
1792
		if(!durationProp) {
-
 
1793
			return;
-
 
1794
		}
1663
		this.wrapperStyle[utils.style.transitionDuration] = utils.isBadAndroid ? '0.001s' : '0ms';
1795
		this.wrapperStyle[durationProp] = utils.isBadAndroid ? '0.0001ms' : '0ms';
-
 
1796
		// remove 0.0001ms
-
 
1797
		var self = this;
-
 
1798
		if(utils.isBadAndroid) {
-
 
1799
			rAF(function() {
-
 
1800
				if(self.wrapperStyle[durationProp] === '0.0001ms') {
-
 
1801
					self.wrapperStyle[durationProp] = '0s';
-
 
1802
				}
-
 
1803
			});
-
 
1804
		}
1664
		this.wrapperStyle.opacity = '0';
1805
		this.wrapperStyle.opacity = '0';
1665
	}
1806
	}
1666
}
1807
}
1667
 
1808
 
1668
Indicator.prototype = {
1809
Indicator.prototype = {
Line 1692... Line 1833...
1692
				break;
1833
				break;
1693
		}
1834
		}
1694
	},
1835
	},
1695
 
1836
 
1696
	destroy: function () {
1837
	destroy: function () {
-
 
1838
		if ( this.options.fadeScrollbars ) {
-
 
1839
			clearTimeout(this.fadeTimeout);
-
 
1840
			this.fadeTimeout = null;
-
 
1841
		}
1697
		if ( this.options.interactive ) {
1842
		if ( this.options.interactive ) {
1698
			utils.removeEvent(this.indicator, 'touchstart', this);
1843
			utils.removeEvent(this.indicator, 'touchstart', this);
1699
			utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
1844
			utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
1700
			utils.removeEvent(this.indicator, 'mousedown', this);
1845
			utils.removeEvent(this.indicator, 'mousedown', this);
1701
 
1846
 
Line 1706... Line 1851...
1706
			utils.removeEvent(window, 'touchend', this);
1851
			utils.removeEvent(window, 'touchend', this);
1707
			utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this);
1852
			utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this);
1708
			utils.removeEvent(window, 'mouseup', this);
1853
			utils.removeEvent(window, 'mouseup', this);
1709
		}
1854
		}
1710
 
1855
 
1711
		if ( this.options.defaultScrollbars ) {
1856
		if ( this.options.defaultScrollbars && this.wrapper.parentNode ) {
1712
			this.wrapper.parentNode.removeChild(this.wrapper);
1857
			this.wrapper.parentNode.removeChild(this.wrapper);
1713
		}
1858
		}
1714
	},
1859
	},
1715
 
1860
 
1716
	_start: function (e) {
1861
	_start: function (e) {
Line 1806... Line 1951...
1806
		}
1951
		}
1807
	},
1952
	},
1808
 
1953
 
1809
	transitionTime: function (time) {
1954
	transitionTime: function (time) {
1810
		time = time || 0;
1955
		time = time || 0;
-
 
1956
		var durationProp = utils.style.transitionDuration;
-
 
1957
		if(!durationProp) {
-
 
1958
			return;
-
 
1959
		}
-
 
1960
 
1811
		this.indicatorStyle[utils.style.transitionDuration] = time + 'ms';
1961
		this.indicatorStyle[durationProp] = time + 'ms';
1812
 
1962
 
1813
		if ( !time && utils.isBadAndroid ) {
1963
		if ( !time && utils.isBadAndroid ) {
1814
			this.indicatorStyle[utils.style.transitionDuration] = '0.001s';
1964
			this.indicatorStyle[durationProp] = '0.0001ms';
-
 
1965
			// remove 0.0001ms
-
 
1966
			var self = this;
-
 
1967
			rAF(function() {
-
 
1968
				if(self.indicatorStyle[durationProp] === '0.0001ms') {
-
 
1969
					self.indicatorStyle[durationProp] = '0s';
-
 
1970
				}
-
 
1971
			});
1815
		}
1972
		}
1816
	},
1973
	},
1817
 
1974
 
1818
	transitionTimingFunction: function (easing) {
1975
	transitionTimingFunction: function (easing) {
1819
		this.indicatorStyle[utils.style.transitionTimingFunction] = easing;
1976
		this.indicatorStyle[utils.style.transitionTimingFunction] = easing;
Line 1852... Line 2009...
1852
					this.wrapper.style.bottom = '2px';
2009
					this.wrapper.style.bottom = '2px';
1853
				}
2010
				}
1854
			}
2011
			}
1855
		}
2012
		}
1856
 
2013
 
1857
		var r = this.wrapper.offsetHeight;	// force refresh
2014
		utils.getRect(this.wrapper);	// force refresh
1858
 
2015
 
1859
		if ( this.options.listenX ) {
2016
		if ( this.options.listenX ) {
1860
			this.wrapperWidth = this.wrapper.clientWidth;
2017
			this.wrapperWidth = this.wrapper.clientWidth;
1861
			if ( this.options.resize ) {
2018
			if ( this.options.resize ) {
1862
				this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
2019
				this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
Line 1873... Line 2030...
1873
			} else {
2030
			} else {
1874
				this.minBoundaryX = 0;
2031
				this.minBoundaryX = 0;
1875
				this.maxBoundaryX = this.maxPosX;
2032
				this.maxBoundaryX = this.maxPosX;
1876
			}
2033
			}
1877
 
2034
 
1878
			this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));	
2035
			this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));
1879
		}
2036
		}
1880
 
2037
 
1881
		if ( this.options.listenY ) {
2038
		if ( this.options.listenY ) {
1882
			this.wrapperHeight = this.wrapper.clientHeight;
2039
			this.wrapperHeight = this.wrapper.clientHeight;
1883
			if ( this.options.resize ) {
2040
			if ( this.options.resize ) {
Line 2002... Line 2159...
2002
 
2159
 
2003
IScroll.utils = utils;
2160
IScroll.utils = utils;
2004
 
2161
 
2005
if ( typeof module != 'undefined' && module.exports ) {
2162
if ( typeof module != 'undefined' && module.exports ) {
2006
	module.exports = IScroll;
2163
	module.exports = IScroll;
-
 
2164
} else if ( typeof define == 'function' && define.amd ) {
-
 
2165
        define( function () { return IScroll; } );
2007
} else {
2166
} else {
2008
	window.IScroll = IScroll;
2167
	window.IScroll = IScroll;
2009
}
2168
}
2010
 
2169
 
2011
})(window, document, Math);
2170
})(window, document, Math);
2012
2171