Skip to content

Commit

Permalink
Increased fallback call frequency to avoid skipping seconds and to pu…
Browse files Browse the repository at this point in the history
…t them at more accurate points

Made a fix that was causing TimeCircles to not work in cross-domain iframes (Related to window.top, which I thought I'd already fixed)
  • Loading branch information
wimbarelds committed Jul 27, 2014
1 parent d1850bc commit 5fa22b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timecircles",
"version": "1.5.2",
"version": "1.5.3",
"homepage": "http://git.wimbarelds.nl/TimeCircles/",
"authors": [
"Wim Barelds <[email protected]>"
Expand Down
42 changes: 24 additions & 18 deletions inc/TimeCircles.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
// Used to disable some features on IE8
var limited_mode = false;
var tick_duration = 200; // in ms

var debug = (location.hash === "#debug");
function debug_log(msg) {
if (debug) {
Expand Down Expand Up @@ -136,8 +136,7 @@
* @param {Mixed} mixed
* @returns {Number}
*/
if (!Array.prototype.indexOf)
{
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
Expand Down Expand Up @@ -234,40 +233,41 @@
}

var TC_Instance_List = {};
function updateInstanceList() {
function updateUsedWindow() {
if(typeof useWindow.TC_Instance_List !== "undefined") {
TC_Instance_List = useWindow.TC_Instance_List;
}
else {
useWindow.TC_Instance_List = TC_Instance_List;
}
initializeAnimationFrameHandler(useWindow);
};

(function() {
function initializeAnimationFrameHandler(w) {
var vendors = ['webkit', 'moz'];
for (var x = 0; x < vendors.length && !window.top.requestAnimationFrame; ++x) {
window.top.requestAnimationFrame = window.top[vendors[x] + 'RequestAnimationFrame'];
window.top.cancelAnimationFrame = window.top[vendors[x] + 'CancelAnimationFrame'];
for (var x = 0; x < vendors.length && !w.requestAnimationFrame; ++x) {
w.requestAnimationFrame = w[vendors[x] + 'RequestAnimationFrame'];
w.cancelAnimationFrame = w[vendors[x] + 'CancelAnimationFrame'];
}

if (!window.top.requestAnimationFrame || !window.top.cancelAnimationFrame) {
window.top.requestAnimationFrame = function(callback, element, instance) {
if (!w.requestAnimationFrame || !w.cancelAnimationFrame) {
w.requestAnimationFrame = function(callback, element, instance) {
if (typeof instance === "undefined")
instance = {data: {last_frame: 0}};
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - instance.data.last_frame));
var id = window.top.setTimeout(function() {
var id = w.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
instance.data.last_frame = currTime + timeToCall;
return id;
};
window.top.cancelAnimationFrame = function(id) {
w.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
})();

};

var TC_Instance = function(element, options) {
this.element = element;
Expand Down Expand Up @@ -420,10 +420,10 @@
}

// Set up interval fallback
var _this = this
var _this = this;
this.data.interval_fallback = useWindow.setInterval(function(){
_this.update.call(_this, true);
}, 1000);
}, 100);
};

TC_Instance.prototype.update = function(nodraw) {
Expand Down Expand Up @@ -668,6 +668,9 @@
};

TC_Instance.prototype.timeLeft = function() {
if (this.data.paused && typeof this.data.timer === "number") {
return this.data.timer;
}
var now = new Date();
return ((this.data.attributes.ref_date - now) / 1000);
};
Expand Down Expand Up @@ -750,8 +753,11 @@
// Use window.top if use_top_frame is true
if(this.config.use_top_frame) {
useWindow = window.top;
updateInstanceList();
}
else {
useWindow = window;
}
updateUsedWindow();

this.data.total_duration = this.config.total_duration;
if (typeof this.data.total_duration === "string") {
Expand Down
2 changes: 1 addition & 1 deletion timecircles.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timecircles",
"version": "1.5.2",
"version": "1.5.3",
"title": "jQuery TimeCircles",
"author": {
"name" : "Wim Barelds",
Expand Down

0 comments on commit 5fa22b0

Please sign in to comment.