Skip to content

Commit

Permalink
Add polyfills for setTimeout and setInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Jul 22, 2013
1 parent 67e9dd8 commit 4fb79b3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cat js/eldarion-ajax-core.js js/eldarion-ajax-handlers.js | uglifyjs -ncm > js/.tmp.min.js
cat js/polyfills.js js/eldarion-ajax-core.js js/eldarion-ajax-handlers.js | uglifyjs -ncm > js/.tmp.min.js
cat js/copyright.js js/.tmp.min.js > js/eldarion-ajax.min.js
rm js/.tmp.min.js
36 changes: 36 additions & 0 deletions js/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*\
|*|
|*| IE-specific polyfill which enables the passage of arbitrary arguments to the
|*| callback functions of javascript timers (HTML5 standard syntax).
|*|
|*| https://developer.mozilla.org/en-US/docs/DOM/window.setInterval
|*|
|*| Syntax:
|*| var timeoutID = window.setTimeout(func, delay, [param1, param2, ...]);
|*| var timeoutID = window.setTimeout(code, delay);
|*| var intervalID = window.setInterval(func, delay[, param1, param2, ...]);
|*| var intervalID = window.setInterval(code, delay);
|*|
\*/

if (document.all && !window.setTimeout.isPolyfill) {
var __nativeST__ = window.setTimeout;
window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
var aArgs = Array.prototype.slice.call(arguments, 2);
return __nativeST__(vCallback instanceof Function ? function () {
vCallback.apply(null, aArgs);
} : vCallback, nDelay);
};
window.setTimeout.isPolyfill = true;
}

if (document.all && !window.setInterval.isPolyfill) {
var __nativeSI__ = window.setInterval;
window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
var aArgs = Array.prototype.slice.call(arguments, 2);
return __nativeSI__(vCallback instanceof Function ? function () {
vCallback.apply(null, aArgs);
} : vCallback, nDelay);
};
window.setInterval.isPolyfill = true;
}
1 change: 1 addition & 0 deletions tests/test-jquery-1.10.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.7.3.js"></script>
<script src="../js/polyfills.js"></script>
<script src="../js/eldarion-ajax-core.js"></script>
<script src="../js/eldarion-ajax-handlers.js"></script>
<script src="tests.js"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/test-jquery-1.8.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.7.3.js"></script>
<script src="../js/polyfills.js"></script>
<script src="../js/eldarion-ajax-core.js"></script>
<script src="../js/eldarion-ajax-handlers.js"></script>
<script src="tests.js"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/test-jquery-1.9.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.7.3.js"></script>
<script src="../js/polyfills.js"></script>
<script src="../js/eldarion-ajax-core.js"></script>
<script src="../js/eldarion-ajax-handlers.js"></script>
<script src="tests.js"></script>
Expand Down
1 change: 1 addition & 0 deletions tests/test-jquery-2.0.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="http://sinonjs.org/releases/sinon-1.7.3.js"></script>
<script src="../js/polyfills.js"></script>
<script src="../js/eldarion-ajax-core.js"></script>
<script src="../js/eldarion-ajax-handlers.js"></script>
<script src="tests.js"></script>
Expand Down

0 comments on commit 4fb79b3

Please sign in to comment.