Skip to content

Commit

Permalink
Adds support for IE 7/8.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 5ce3de0bf0b703463dcb8d25ad09c0b9130036e1
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sun May 27 12:29:52 2012 -0700

    Fixes some AMD stuff to make IE happy.

commit 0ec3fb4c117088f3149db2dce5738e4ab6e21741
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sun May 27 12:00:52 2012 -0700

    Adds some annotations for IE abstractions.

commit fc1c588661308af8adde92fe2e8d8e6b6bf111ea
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sun May 27 11:53:20 2012 -0700

    Made DOMActor IE-compatible.

commit 88ff3e8b1941bab45ad85b6b9f7b385cbea37d5f
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat May 26 18:03:12 2012 -0700

    Fixed version number.

commit c64458f3192fcb4745e22f428c71e97e37165555
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat May 26 17:59:40 2012 -0700

    Updates a test to make IE happy, builds 0.8.5.

commit 8f053de3e049982a6d156c63b880ca3eabe7c14b
Author: Jeremy Kahn <jeremyckahn@gmail.com>
Date:   Sat May 26 17:51:20 2012 -0700

    Added some ugly setTimeout hacks for IE.
  • Loading branch information
jeremyckahn committed May 27, 2012
1 parent 59f86c4 commit 9082431
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 85 deletions.
68 changes: 34 additions & 34 deletions dist/rekapi.bundle.min.js

Large diffs are not rendered by default.

49 changes: 40 additions & 9 deletions dist/rekapi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Rekapi - Rewritten Kapi. v0.8.5
* Rekapi - Rewritten Kapi. v0.8.6
* By Jeremy Kahn - jeremyckahn@gmail.com
* https://github.com/jeremyckahn/rekapi
*
Expand Down Expand Up @@ -127,10 +127,19 @@ var rekapiCore = function (global, deps) {
* @param {Kapi} kapi
*/
function tick (kapi) {
kapi._loopId = kapi._scheduleUpdate.call(window, function () {
var updateFn = function () {
tick(kapi);
renderCurrentMillisecond(kapi);
}, 1000 / kapi.config.fps);
};

// Need to check for .call presence to get around an IE limitation.
// See annotation for cancelLoop for more info.
if (kapi._scheduleUpdate.call) {
kapi._loopId = kapi._scheduleUpdate.call(window,
updateFn, 1000 / kapi.config.fps);
} else {
kapi._loopId = setTimeout(updateFn, 1000 / kapi.config.fps);
}
}


Expand Down Expand Up @@ -218,6 +227,22 @@ var rekapiCore = function (global, deps) {
};


/**
* Cancels an update loop. This abstraction is needed to get around the fact
* that in IE, clearTimeout is not technically a function
* (https://twitter.com/kitcambridge/status/206655060342603777) and thus
* Function.prototype.call cannot be used upon it.
* @param {Kapi} kapi
*/
function cancelLoop (kapi) {
if (kapi._cancelUpdate.call) {
kapi._cancelUpdate.call(window, kapi._loopId);
} else {
clearTimeout(kapi._loopId);
}
}


/**
* Does nothing. Absolutely nothing at all.
*/
Expand Down Expand Up @@ -388,7 +413,7 @@ var rekapiCore = function (global, deps) {
* @return {Kapi}
*/
gk.prototype.play = function (opt_howManyTimes) {
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);

if (this._playState === playState.PAUSED) {
this._loopTimestamp += now() - this._pausedAtTime;
Expand Down Expand Up @@ -445,7 +470,7 @@ var rekapiCore = function (global, deps) {
}

this._playState = playState.PAUSED;
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);
this._pausedAtTime = now();

// also pause any shifty tweens that are running.
Expand All @@ -467,7 +492,7 @@ var rekapiCore = function (global, deps) {
*/
gk.prototype.stop = function () {
this._playState = playState.STOPPED;
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);

// Also kill any shifty tweens that are running.
_.each(this._actors, function (actor) {
Expand Down Expand Up @@ -1491,7 +1516,13 @@ var rekapiDOM = function (global, deps) {
gk.DOMActor = function (element) {
gk.Actor.call(this);
this._context = element;
this._context.classList.add(this.getCSSName());
var className = this.getCSSName();

// Add the class if it's not already there.
// Using className instead of classList to make IE happy.
if (!this._context.className.match(className)) {
this._context.className += className;
}

// Remove the instance's render method to allow the
// ActorMethods.prototype.render method to be accessible.
Expand Down Expand Up @@ -1823,14 +1854,14 @@ if (typeof define === 'function' && define.amd) {
,Kapi = rekapi(global, deps);

if (typeof KAPI_DEBUG !== 'undefined' && KAPI_DEBUG === true) {
Kapi.underscore_version = deps.underscore.VERSION;
Kapi.underscore_version = deps.underscore.VERSION;
}

if (!underscoreAlreadyInUse) {
// Prevent Underscore from polluting the global scope.
// This global can be safely removed since Rekapi keeps its own reference
// to Underscore via the `deps` object passed earlier as an argument.
delete global._;
global._ = undefined;
}

return Kapi;
Expand Down
66 changes: 33 additions & 33 deletions dist/rekapi.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion ext/dom/rekapi.dom.actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ var rekapiDOM = function (global, deps) {
gk.DOMActor = function (element) {
gk.Actor.call(this);
this._context = element;
this._context.classList.add(this.getCSSName());
var className = this.getCSSName();

// Add the class if it's not already there.
// Using className instead of classList to make IE happy.
if (!this._context.className.match(className)) {
this._context.className += className;
}

// Remove the instance's render method to allow the
// ActorMethods.prototype.render method to be accessible.
Expand Down
35 changes: 30 additions & 5 deletions src/rekapi.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,19 @@ var rekapiCore = function (global, deps) {
* @param {Kapi} kapi
*/
function tick (kapi) {
kapi._loopId = kapi._scheduleUpdate.call(window, function () {
var updateFn = function () {
tick(kapi);
renderCurrentMillisecond(kapi);
}, 1000 / kapi.config.fps);
};

// Need to check for .call presence to get around an IE limitation.
// See annotation for cancelLoop for more info.
if (kapi._scheduleUpdate.call) {
kapi._loopId = kapi._scheduleUpdate.call(window,
updateFn, 1000 / kapi.config.fps);
} else {
kapi._loopId = setTimeout(updateFn, 1000 / kapi.config.fps);
}
}


Expand Down Expand Up @@ -207,6 +216,22 @@ var rekapiCore = function (global, deps) {
};


/**
* Cancels an update loop. This abstraction is needed to get around the fact
* that in IE, clearTimeout is not technically a function
* (https://twitter.com/kitcambridge/status/206655060342603777) and thus
* Function.prototype.call cannot be used upon it.
* @param {Kapi} kapi
*/
function cancelLoop (kapi) {
if (kapi._cancelUpdate.call) {
kapi._cancelUpdate.call(window, kapi._loopId);
} else {
clearTimeout(kapi._loopId);
}
}


/**
* Does nothing. Absolutely nothing at all.
*/
Expand Down Expand Up @@ -377,7 +402,7 @@ var rekapiCore = function (global, deps) {
* @return {Kapi}
*/
gk.prototype.play = function (opt_howManyTimes) {
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);

if (this._playState === playState.PAUSED) {
this._loopTimestamp += now() - this._pausedAtTime;
Expand Down Expand Up @@ -434,7 +459,7 @@ var rekapiCore = function (global, deps) {
}

this._playState = playState.PAUSED;
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);
this._pausedAtTime = now();

// also pause any shifty tweens that are running.
Expand All @@ -456,7 +481,7 @@ var rekapiCore = function (global, deps) {
*/
gk.prototype.stop = function () {
this._playState = playState.STOPPED;
this._cancelUpdate.call(window, this._loopId);
cancelLoop(this);

// Also kill any shifty tweens that are running.
_.each(this._actors, function (actor) {
Expand Down
4 changes: 2 additions & 2 deletions src/rekapi.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ if (typeof define === 'function' && define.amd) {
,Kapi = rekapi(global, deps);

if (typeof KAPI_DEBUG !== 'undefined' && KAPI_DEBUG === true) {
Kapi.underscore_version = deps.underscore.VERSION;
Kapi.underscore_version = deps.underscore.VERSION;
}

if (!underscoreAlreadyInUse) {
// Prevent Underscore from polluting the global scope.
// This global can be safely removed since Rekapi keeps its own reference
// to Underscore via the `deps` object passed earlier as an argument.
delete global._;
global._ = undefined;
}

return Kapi;
Expand Down
25 changes: 25 additions & 0 deletions tests/test.dom_doesitlookright.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
,element;

element = document.getElementById('actor');
element.removeAttribute('style');
element.style.position = 'absolute';
element.style.height = '50px';
element.style.width = '50px';
element.style.background = '#f00';
Expand Down Expand Up @@ -93,6 +95,28 @@
});


$('#basic-linear-tween-ie').click(function () {
var actor;

killTest();
kapi = setupTestKapi();
actor = setupTestActor(kapi);

actor
.keyframe(0, {
'left': '0px'
,'top': '0px'
})
.keyframe(1500, {
'left': '200px'
,'top': '200px'
});

kapi.play();
console.log(kapi);
});


$('#basic-eased-tween').click(function () {
var actor;

Expand Down Expand Up @@ -195,6 +219,7 @@
<button id="stop">Stop</button>
</li>
<li><button id="basic-linear-tween">Basic linear tween loop</button></li>
<li><button id="basic-linear-tween-ie">Basic linear tween loop (IE-friendly)</button></li>
<li><button id="delayed-start">Delayed start</button></li>
<li><button id="basic-eased-tween">Basic eased tween loop</button></li>
<li><button id="multi-eased-tween">Tween loop with multiple easings</button></li>
Expand Down
13 changes: 13 additions & 0 deletions tests/test.state.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
return actor;
}

// Silly hack to make IE work properly for the test.
// http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i<this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
}
}

(function () {

module('Actor management');
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.5
0.8.6

0 comments on commit 9082431

Please sign in to comment.