]> source.dussan.org Git - jquery.git/commitdiff
Some adjustments and style edits on lrbabe's pull for requestAnimationFrame
authortimmywil <tim.willison@thisismedium.com>
Mon, 4 Apr 2011 23:25:12 +0000 (19:25 -0400)
committertimmywil <tim.willison@thisismedium.com>
Mon, 4 Apr 2011 23:25:12 +0000 (19:25 -0400)
- Moved support.js check to effects.js.  This is just an assignment to the function if it exists.  Removed string concatenations.

  + Still need to do the checks on window, but after that, window is no longer needed.

- Switched ternary to an if statmenet

- assigned timerId to a number rather than the function. I did perf tests to check which is faster.

src/effects.js
src/support.js

index e5a10295ca91cea4237fd06ba482c117404157ae..9835e959828232515033bf29c2bb1eab5c8dd336 100644 (file)
@@ -11,7 +11,8 @@ var elemdisplay = {},
                [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
                // opacity animations
                [ "opacity" ]
-       ];
+       ],
+       requestAnimationFrame = window.webkitRequestAnimationFrame || window.mozRequestionAnimationFrame;
 
 jQuery.fn.extend({
        show: function( speed, easing, callback ) {
@@ -364,15 +365,18 @@ jQuery.fx.prototype = {
 
                if ( t() && jQuery.timers.push(t) && !timerId ) {
                        // Use requestAnimationFrame instead of setInterval if available
-                       ( timerId = jQuery.support.requestAnimationFrame ) ?
-                               window[timerId](function raf() {
-                                       // timerId will be true as long as the animation hasn't been stopped
-                                       if (timerId) {
-                                               window[timerId](raf);
+                       if ( requestAnimationFrame ) {
+                               timerId = 1;
+                               requestAnimationFrame(function raf() {
+                                       // When timerId gets set to null at any point, this stops
+                                       if ( timerId ) {
+                                               requestAnimationFrame( raf );
                                                fx.tick();
                                        }
-                               }):
-                               timerId = setInterval(fx.tick, fx.interval);
+                               });
+                       } else {
+                               timerId = setInterval( fx.tick, fx.interval );
+                       }
                }
        },
 
index 64a54b83218ba96cb9a8a3d8e8d4d85b41375d79..4c309562f7c17c6a7d17ebfd1c2a5a24af514c5b 100644 (file)
@@ -13,8 +13,7 @@
                a = div.getElementsByTagName("a")[0],
                select = document.createElement("select"),
                opt = select.appendChild( document.createElement("option") ),
-               input = div.getElementsByTagName("input")[0],
-               raf = "RequestAnimationFrame";
+               input = div.getElementsByTagName("input")[0];
 
        // Can't get basic test support
        if ( !all || !all.length || !a ) {
                // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
                optSelected: opt.selected,
 
-               // Verify requestAnimationFrame mechanism existence
-               // use the prefixed name as the value
-               requestAnimationFrame:
-                       window['moz' + raf] ? 'moz' + raf :
-                       window['webkit' + raf] ? 'webkit' + raf :
-                       false,
-
                // Will be defined later
                deleteExpando: true,
                optDisabled: false,