Skip to content

Commit

Permalink
Release 2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
darsain committed Aug 7, 2014
1 parent 4e1cb08 commit e3eb1b8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 83 deletions.
63 changes: 31 additions & 32 deletions dist/jquery.motio.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Motio 2.2.1 - 18th Apr 2013
* https://github.com/Darsain/motio
* motio 2.2.2 - 7th Aug 2014
* https://github.com/darsain/motio
*
* Licensed under the MIT license.
* http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -38,6 +38,15 @@
}
}());

// Returns time in as precise manner as possible
var getTime = (function () {
var perf = w.performance;
if (perf && perf.now) return perf.now.bind(perf);
return function () {
return +new Date();
};
}());

/**
* Motio.
*
Expand All @@ -58,7 +67,7 @@
var callbacks = {};
var animation = {};
var active = 0;
var pos, bgPos, lastPos, frameID, renderID, i, l;
var pos, bgPos, lastPos, frameID, i, l;

// Exposed properties
self.element = element;
Expand All @@ -73,10 +82,9 @@
* @return {Object} Motio instance.
*/
self.pause = function () {
// frameID can be timeout, or animationFrame ID
cAF(frameID);
clearTimeout(frameID);
frameID = 0;
animation.lastFrame = 0;
if (!self.isPaused) {
self.isPaused = true;
trigger('pause');
Expand Down Expand Up @@ -111,7 +119,7 @@
if (!frameID) {
self.isPaused = false;
trigger('play');
requestRender();
frameID = rAF(render);
}
}

Expand Down Expand Up @@ -240,8 +248,14 @@
* @return {Void}
*/
function render() {
// Reset renderID
renderID = 0;
frameID = rAF(render);
var time = getTime();

// Don't render when it's not time for next frame yet
if (o.fps < 60 && animation.lastFrame && animation.lastFrame + (1000 / o.fps) + 1 > time) return;

animation.lastFrame = time;
positionTick();

// Prepare new background position
bgPos = isPan ? Math.round(pos.x) + 'px ' + Math.round(pos.y) + 'px' : frames[active];
Expand All @@ -264,29 +278,6 @@
}
}

/**
* Render rAF wrapper.
*
* @return {Int} Animation frame index.
*/
function requestRender() {
if (!(animation.finite && animation.to === active)) {
if (animation.immediate) {
frameID = 0;
} else {
if (o.fps >= 60) {
frameID = rAF(requestRender);
} else {
frameID = setTimeout(requestRender, 1000 / o.fps);
}
}
positionTick();
if (!renderID) {
renderID = rAF(render);
}
}
}

/**
* Update one of the dynamic option properties.
*
Expand Down Expand Up @@ -465,7 +456,15 @@
* @return {String}
*/
function type(value) {
return Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase();
if (value == null) {
return String(value);
}
if (typeof value === 'object' || typeof value === 'function') {
return (value instanceof w.NodeList && 'nodelist') ||
(value instanceof w.HTMLCollection && 'htmlcollection') ||
Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase();
}
return typeof value;
}

/**
Expand Down
17 changes: 9 additions & 8 deletions dist/jquery.motio.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 31 additions & 32 deletions dist/motio.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Motio 2.2.1 - 18th Apr 2013
* https://github.com/Darsain/motio
* motio 2.2.2 - 7th Aug 2014
* https://github.com/darsain/motio
*
* Licensed under the MIT license.
* http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -38,6 +38,15 @@
}
}());

// Returns time in as precise manner as possible
var getTime = (function () {
var perf = w.performance;
if (perf && perf.now) return perf.now.bind(perf);
return function () {
return +new Date();
};
}());

/**
* Motio.
*
Expand All @@ -58,7 +67,7 @@
var callbacks = {};
var animation = {};
var active = 0;
var pos, bgPos, lastPos, frameID, renderID, i, l;
var pos, bgPos, lastPos, frameID, i, l;

// Exposed properties
self.element = element;
Expand All @@ -73,10 +82,9 @@
* @return {Object} Motio instance.
*/
self.pause = function () {
// frameID can be timeout, or animationFrame ID
cAF(frameID);
clearTimeout(frameID);
frameID = 0;
animation.lastFrame = 0;
if (!self.isPaused) {
self.isPaused = true;
trigger('pause');
Expand Down Expand Up @@ -111,7 +119,7 @@
if (!frameID) {
self.isPaused = false;
trigger('play');
requestRender();
frameID = rAF(render);
}
}

Expand Down Expand Up @@ -240,8 +248,14 @@
* @return {Void}
*/
function render() {
// Reset renderID
renderID = 0;
frameID = rAF(render);
var time = getTime();

// Don't render when it's not time for next frame yet
if (o.fps < 60 && animation.lastFrame && animation.lastFrame + (1000 / o.fps) + 1 > time) return;

animation.lastFrame = time;
positionTick();

// Prepare new background position
bgPos = isPan ? Math.round(pos.x) + 'px ' + Math.round(pos.y) + 'px' : frames[active];
Expand All @@ -264,29 +278,6 @@
}
}

/**
* Render rAF wrapper.
*
* @return {Int} Animation frame index.
*/
function requestRender() {
if (!(animation.finite && animation.to === active)) {
if (animation.immediate) {
frameID = 0;
} else {
if (o.fps >= 60) {
frameID = rAF(requestRender);
} else {
frameID = setTimeout(requestRender, 1000 / o.fps);
}
}
positionTick();
if (!renderID) {
renderID = rAF(render);
}
}
}

/**
* Update one of the dynamic option properties.
*
Expand Down Expand Up @@ -465,7 +456,15 @@
* @return {String}
*/
function type(value) {
return Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase();
if (value == null) {
return String(value);
}
if (typeof value === 'object' || typeof value === 'function') {
return (value instanceof w.NodeList && 'nodelist') ||
(value instanceof w.HTMLCollection && 'htmlcollection') ||
Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase();
}
return typeof value;
}

/**
Expand Down
Loading

0 comments on commit e3eb1b8

Please sign in to comment.