mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
fixed Common.now
This commit is contained in:
parent
26c1200387
commit
2b76c4c10b
1 changed files with 13 additions and 17 deletions
|
@ -12,6 +12,7 @@ module.exports = Common;
|
||||||
|
|
||||||
Common._nextId = 0;
|
Common._nextId = 0;
|
||||||
Common._seed = 0;
|
Common._seed = 0;
|
||||||
|
Common._nowStartTime = +(new Date());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the object in the first argument using the object in the second argument.
|
* Extends the object in the first argument using the object in the second argument.
|
||||||
|
@ -197,7 +198,7 @@ module.exports = Common;
|
||||||
Common.isElement = function(obj) {
|
Common.isElement = function(obj) {
|
||||||
// http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
|
// http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
|
||||||
try {
|
try {
|
||||||
return obj instanceof HTMLElement;
|
return obj instanceof HTMLElement;
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
return (typeof obj==="object") &&
|
return (typeof obj==="object") &&
|
||||||
|
@ -273,26 +274,21 @@ module.exports = Common;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current timestamp (high-res if available).
|
* Returns the current timestamp since the time origin (e.g. from page load).
|
||||||
|
* The result will be high-resolution including decimal places if available.
|
||||||
* @method now
|
* @method now
|
||||||
* @return {number} the current timestamp (high-res if available)
|
* @return {number} the current timestamp
|
||||||
*/
|
*/
|
||||||
Common.now = function() {
|
Common.now = function() {
|
||||||
// http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
|
if (window.performance) {
|
||||||
// https://gist.github.com/davidwaterston/2982531
|
if (window.performance.now) {
|
||||||
|
return window.performance.now();
|
||||||
|
} else if (window.performance.webkitNow) {
|
||||||
|
return window.performance.webkitNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var performance = window.performance || {};
|
return (new Date()) - Common._nowStartTime;
|
||||||
|
|
||||||
performance.now = (function() {
|
|
||||||
return performance.now ||
|
|
||||||
performance.webkitNow ||
|
|
||||||
performance.msNow ||
|
|
||||||
performance.oNow ||
|
|
||||||
performance.mozNow ||
|
|
||||||
function() { return +(new Date()); };
|
|
||||||
})();
|
|
||||||
|
|
||||||
return performance.now();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue