Skip to content

Commit

Permalink
js modules update:
Browse files Browse the repository at this point in the history
- Hammer.js 2.0.8
- iScroll-lite 5.2.0
- FlexSlider 2.6.1
- PinchZoom: replace setInterval with requestAnimationFrame
  • Loading branch information
Minwe committed May 23, 2016
1 parent 846af96 commit f0452ca
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 106 deletions.
1 change: 0 additions & 1 deletion js/ui.add2home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var UI = require('./core');

/* jshint -W101, -W106 */
/**
* Add to Homescreen v3.2.2
* (c) 2015 Matteo Spinelli
Expand Down
8 changes: 4 additions & 4 deletions js/ui.flexslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var UI = require('./core');
// TODO: start after x ms when pause on actions

/*
* jQuery FlexSlider v2.6.0
* jQuery FlexSlider v2.6.1
* Copyright 2012 WooThemes
* Contributing Author: Tyler Smith
*/
Expand Down Expand Up @@ -241,7 +241,7 @@ $.flexslider = function(el, options) {
if (undefined === slide.attr('data-thumb-alt')) {
slide.attr('data-thumb-alt', '');
}
altText = ( '' !== slide.attr('data-thumb-alt') ) ? altText = ' alt="' + slide.attr('data-thumb-alt') + '"' : '';
var altText = ('' !== slide.attr('data-thumb-alt')) ? altText = ' alt="' + slide.attr('data-thumb-alt') + '"' : '';
item = (slider.vars.controlNav === "thumbnails") ? '<img src="' + slide.attr( 'data-thumb' ) + '"' + altText + '/>' : '<a href="#">' + j + '</a>';
if ('thumbnails' === slider.vars.controlNav && true === slider.vars.thumbCaptions) {
var captn = slide.attr('data-thumbcaption');
Expand Down Expand Up @@ -615,7 +615,7 @@ $.flexslider = function(el, options) {
smoothHeight: function(dur) {
if (!vertical || fade) {
var $obj = (fade) ? slider : slider.viewport;
(dur) ? $obj.animate({"height": slider.slides.eq(slider.animatingTo).height()}, dur) : $obj.height(slider.slides.eq(slider.animatingTo).height());
(dur) ? $obj.animate({"height": slider.slides.eq(slider.animatingTo).innerHeight()}, dur) : $obj.innerHeight(slider.slides.eq(slider.animatingTo).innerHeight());
}
},
sync: function(action) {
Expand Down Expand Up @@ -1228,7 +1228,7 @@ $.fn.flexslider = function(options) {
var selector = (options.selector) ? options.selector : '.am-slides > li';
var $slides = $this.find(selector);

if (($slides.length === 1 && options.allowOneSlide === true) || $slides.length === 0) {
if (( $slides.length === 1 && options.allowOneSlide === false) || $slides.length === 0) {
$slides.fadeIn(400);
if (options.start) {options.start($this);}
} else if ($this.data('flexslider') === undefined) {
Expand Down
162 changes: 112 additions & 50 deletions js/ui.iscroll-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

var UI = require('./core');

/* jshint unused: false */
/* jshint -W101, -W116, -W109 */

/*! iScroll v5.1.3
* (c) 2008-2014 Matteo Spinelli
/*! iScroll v5.2.0
* (c) 2008-2016 Matteo Spinelli
* http://cubiq.org/license
*/

var rAF = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
var rAF = UI.utils.rAF;

var utils = (function() {
var me = {};
Expand All @@ -44,8 +34,8 @@ var utils = (function() {
}

me.getTime = Date.now || function getTime() {
return new Date().getTime();
};
return new Date().getTime();
};

me.extend = function(target, obj) {
for (var i in obj) {
Expand All @@ -63,7 +53,8 @@ var utils = (function() {

me.prefixPointerEvent = function(pointerEvent) {
return window.MSPointerEvent ?
'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10) :
'MSPointer' + pointerEvent.charAt(7)
.toUpperCase() + pointerEvent.substr(8) :
pointerEvent;
};

Expand Down Expand Up @@ -100,12 +91,38 @@ var utils = (function() {
hasTransform: _transform !== false,
hasPerspective: _prefixStyle('perspective') in _elementStyle,
hasTouch: 'ontouchstart' in window,
hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed
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));
/*
This should find all Android browsers lower than build 535.19 (both stock browser and webview)
- galaxy S2 is ok
- 2.3.6 : `AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1`
- 4.0.4 : `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S3 is badAndroid (stock brower, webview)
`AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S4 is badAndroid (stock brower, webview)
`AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S5 is OK
`AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
- galaxy S6 is OK
`AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
*/
me.isBadAndroid = (function() {
var appVersion = window.navigator.appVersion;
// Android browser is not a chrome browser.
if (/Android/.test(appVersion) && !(/Chrome\/\d/.test(appVersion))) {
var safariVersion = appVersion.match(/Safari\/(\d+.\d)/);
if (safariVersion && typeof safariVersion === "object" && safariVersion.length >= 2) {
return parseFloat(safariVersion[1]) < 535.19;
} else {
return true;
}
} else {
return false;
}
})();

me.extend(me.style = {}, {
transform: _transform,
Expand Down Expand Up @@ -249,29 +266,40 @@ var utils = (function() {
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);

// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
// initMouseEvent is deprecated.
ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
ev.initEvent('click', true, true);
ev.view = e.view || window;
ev.detail = 1;
ev.screenX = target.screenX || 0;
ev.screenY = target.screenY || 0;
ev.clientX = target.clientX || 0;
ev.clientY = target.clientY || 0;
ev.ctrlKey = !!e.ctrlKey;
ev.altKey = !!e.altKey;
ev.shiftKey = !!e.shiftKey;
ev.metaKey = !!e.metaKey;
ev.button = 0;
ev.relatedTarget = 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 = {

// INSERT POINT: OPTIONS

// INSERT POINT: OPTIONS
disablePointer: !utils.hasPointer,
disableTouch: utils.hasPointer || !utils.hasTouch,
disableMouse: utils.hasPointer || utils.hasTouch,
startX: 0,
startY: 0,
scrollY: true,
Expand All @@ -287,7 +315,8 @@ function IScroll(el, options) {

HWCompositing: true,
useTransition: true,
useTransform: true
useTransform: true,
bindToWrapper: typeof window.onmousedown === "undefined"
};

for (var i in options) {
Expand Down Expand Up @@ -319,7 +348,14 @@ function IScroll(el, options) {
this.options.tap = 'tap';
}

// INSERT POINT: NORMALIZATION
// https://github.com/cubiq/iscroll/issues/1029
if (!this.options.useTransition && !this.options.useTransform) {
if (!(/relative|absolute/i).test(this.scrollerStyle.position)) {
this.scrollerStyle.position = "relative";
}
}

// INSERT POINT: NORMALIZATION

// Some defaults
this.x = 0;
Expand All @@ -328,7 +364,7 @@ function IScroll(el, options) {
this.directionY = 0;
this._events = {};

// INSERT POINT: DEFAULTS
// INSERT POINT: DEFAULTS

this._init();
this.refresh();
Expand All @@ -338,18 +374,19 @@ function IScroll(el, options) {
}

IScroll.prototype = {
version: '5.1.3',
version: '5.2.0',

_init: function() {
this._initEvents();

// INSERT POINT: _init
// INSERT POINT: _init

},

destroy: function() {
this._initEvents(true);

clearTimeout(this.resizeTimeout);
this.resizeTimeout = null;
this._execEvent('destroy');
},

Expand All @@ -368,7 +405,18 @@ IScroll.prototype = {
_start: function(e) {
// React to left mouse button only
if (utils.eventType[e.type] != 1) {
if (e.button !== 0) {
// for button property
// http://unixpapa.com/js/mouse.html
var button;
if (!e.which) {
/* IE case */
button = (e.button < 2) ? 0 :
((e.button == 4) ? 1 : 2);
} else {
/* All others */
button = e.button;
}
if (button !== 0) {
return;
}
}
Expand All @@ -392,11 +440,10 @@ IScroll.prototype = {
this.directionY = 0;
this.directionLocked = 0;

this._transitionTime();

this.startTime = utils.getTime();

if (this.options.useTransition && this.isInTransition) {
this._transitionTime();
this.isInTransition = false;
pos = this.getComputedPosition();
this._translate(Math.round(pos.x), Math.round(pos.y));
Expand Down Expand Up @@ -579,7 +626,7 @@ IScroll.prototype = {
this.isInTransition = 1;
}

// INSERT POINT: _end
// INSERT POINT: _end

if (newX != this.x || newY != this.y) {
// change easing function when scroller goes out of the boundaries
Expand Down Expand Up @@ -678,7 +725,7 @@ IScroll.prototype = {

this.resetPosition();

// INSERT POINT: _refresh
// INSERT POINT: _refresh

},

Expand Down Expand Up @@ -731,10 +778,12 @@ IScroll.prototype = {
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);
var transitionType = this.options.useTransition && easing.style;
if (!time || transitionType) {
if (transitionType) {
this._transitionTimingFunction(easing.style);
this._transitionTime(time);
}
this._translate(x, y);
} else {
this._animate(x, y, time, easing.fn);
Expand Down Expand Up @@ -773,22 +822,36 @@ IScroll.prototype = {
},

_transitionTime: function(time) {
if (!this.options.useTransition) {
return;
}
time = time || 0;
var durationProp = utils.style.transitionDuration;
if (!durationProp) {
return;
}

this.scrollerStyle[utils.style.transitionDuration] = time + 'ms';
this.scrollerStyle[durationProp] = time + 'ms';

if (!time && utils.isBadAndroid) {
this.scrollerStyle[utils.style.transitionDuration] = '0.001s';
this.scrollerStyle[durationProp] = '0.0001ms';
// remove 0.0001ms
var self = this;
rAF(function() {
if (self.scrollerStyle[durationProp] === '0.0001ms') {
self.scrollerStyle[durationProp] = '0s';
}
});
}

// INSERT POINT: _transitionTime
// INSERT POINT: _transitionTime

},

_transitionTimingFunction: function(easing) {
this.scrollerStyle[utils.style.transitionTimingFunction] = easing;

// INSERT POINT: _transitionTimingFunction
// INSERT POINT: _transitionTimingFunction

},

Expand All @@ -811,7 +874,7 @@ IScroll.prototype = {
this.x = x;
this.y = y;

// INSERT POINT: _translate
// INSERT POINT: _translate

},

Expand Down Expand Up @@ -868,7 +931,6 @@ IScroll.prototype = {

return {x: x, y: y};
},

_animate: function(destX, destY, duration, easingFn) {
var that = this,
startX = this.x,
Expand Down Expand Up @@ -949,7 +1011,7 @@ IScroll.prototype = {
this._key(e);
break;
case 'click':
if (!e._constructed) {
if (this.enabled && !e._constructed) {
e.preventDefault();
e.stopPropagation();
}
Expand Down
Loading

0 comments on commit f0452ca

Please sign in to comment.