]> source.dussan.org Git - jquery.git/commitdiff
Split the queue code out from data.js into a dedicated queue.js file (also split...
authorJohn Resig <jeresig@gmail.com>
Sun, 6 Dec 2009 22:19:33 +0000 (17:19 -0500)
committerJohn Resig <jeresig@gmail.com>
Sun, 6 Dec 2009 22:19:33 +0000 (17:19 -0500)
Makefile
Rakefile
build.xml
src/data.js
src/queue.js [new file with mode: 0644]
test/index.html
test/unit/data.js
test/unit/queue.js [new file with mode: 0644]

index ac14d7ac69474e2ed4d9d5733160269e9ef79a97..a57b3c0ddb231c9febbf8b7d9a2db6a2b2d1ceec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ DIST_DIR = ${PREFIX}/dist
 
 BASE_FILES = ${SRC_DIR}/core.js\
        ${SRC_DIR}/data.js\
+       ${SRC_DIR}/queue.js\
        ${SRC_DIR}/event.js\
        ${SRC_DIR}/support.js\
        ${SRC_DIR}/selector.js\
index af31714265af2a7e66444ce99b57404541065e48..54fa3e8aa18a95dfe41ee3d046021bd77dcc4471 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -1,5 +1,5 @@
 # Basic Rakefile for building jQuery
-files = [ "intro", "core", "data", "event", "support", "selector", "traversing", "attributes", "manipulation", "css", "ajax", "fx", "offset", "dimensions", "outro" ]
+files = [ "intro", "core", "data", "queue", "event", "support", "selector", "traversing", "attributes", "manipulation", "css", "ajax", "fx", "offset", "dimensions", "outro" ]
 
 date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.gsub(/\n/, "")
 version = `cat version.txt`.gsub(/\n/, "")
index 5235347b411b453a1cc8d2708b135b8e32068ca7..8efd387c3f0450b176bae0f4d586c50382da7765 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -38,6 +38,7 @@
             <fileset dir="${SRC_DIR}" includes="intro.js" />
             <fileset dir="${SRC_DIR}" includes="core.js" />
             <fileset dir="${SRC_DIR}" includes="data.js" />
+            <fileset dir="${SRC_DIR}" includes="queue.js" />
             <fileset dir="${SRC_DIR}" includes="event.js" />
             <fileset dir="${SRC_DIR}" includes="support.js" />
             <fileset dir="${SRC_DIR}" includes="selector.js" />
index 3e6eb19f6d99e9bacb5048ee0f636a21b46e65f9..1d993fe5827cac1c79a004815b7925bc1426c342 100644 (file)
@@ -77,40 +77,6 @@ jQuery.extend({
                        // Completely remove the data cache
                        delete cache[ id ];
                }
-       },
-       
-       queue: function( elem, type, data ) {
-               if ( !elem ) { return; }
-
-               type = (type || "fx") + "queue";
-               var q = jQuery.data( elem, type );
-
-               // Speed up dequeue by getting out quickly if this is just a lookup
-               if ( !data ) { return q || []; }
-
-               if ( !q || jQuery.isArray(data) ) {
-                       q = jQuery.data( elem, type, jQuery.makeArray(data) );
-               } else {
-                       q.push( data );
-               }
-               return q;
-       },
-
-       dequeue: function( elem, type ){
-               type = type || "fx";
-
-               var queue = jQuery.queue( elem, type ), fn = queue.shift();
-
-               // If the fx queue is dequeued, always remove the progress sentinel
-               if ( fn === "inprogress" ) { fn = queue.shift(); }
-
-               if ( fn ) {
-                       // Add a progress sentinel to prevent the fx queue from being
-                       // automatically dequeued
-                       if ( type == "fx" ) { queue.unshift("inprogress"); }
-
-                       fn.call(elem, function() { jQuery.dequeue(elem, type); });
-               }
        }
 });
 
@@ -143,45 +109,5 @@ jQuery.fn.extend({
                return this.each(function(){
                        jQuery.removeData( this, key );
                });
-       },
-       queue: function(type, data){
-               if ( typeof type !== "string" ) {
-                       data = type;
-                       type = "fx";
-               }
-
-               if ( data === undefined ) {
-                       return jQuery.queue( this[0], type );
-               }
-               return this.each(function(i, elem){
-                       var queue = jQuery.queue( this, type, data );
-
-                       if ( type == "fx" && queue[0] !== "inprogress" ) {
-                               jQuery.dequeue( this, type );
-                       }
-               });
-       },
-       dequeue: function(type){
-               return this.each(function(){
-                       jQuery.dequeue( this, type );
-               });
-       },
-
-       // Based off of the plugin by Clint Helfers, with permission.
-       // http://blindsignals.com/index.php/2009/07/jquery-delay/
-       delay: function( time, type ) {
-               time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
-               type = type || "fx";
-
-               return this.queue( type, function() {
-                       var elem = this;
-                       setTimeout(function() {
-                               jQuery.dequeue( elem, type );
-                       }, time );
-               });
-       },
-
-       clearQueue: function(type){
-               return this.queue( type || "fx", [] );
        }
 });
diff --git a/src/queue.js b/src/queue.js
new file mode 100644 (file)
index 0000000..e636ffb
--- /dev/null
@@ -0,0 +1,78 @@
+jQuery.extend({
+       queue: function( elem, type, data ) {
+               if ( !elem ) { return; }
+
+               type = (type || "fx") + "queue";
+               var q = jQuery.data( elem, type );
+
+               // Speed up dequeue by getting out quickly if this is just a lookup
+               if ( !data ) { return q || []; }
+
+               if ( !q || jQuery.isArray(data) ) {
+                       q = jQuery.data( elem, type, jQuery.makeArray(data) );
+               } else {
+                       q.push( data );
+               }
+               return q;
+       },
+
+       dequeue: function( elem, type ){
+               type = type || "fx";
+
+               var queue = jQuery.queue( elem, type ), fn = queue.shift();
+
+               // If the fx queue is dequeued, always remove the progress sentinel
+               if ( fn === "inprogress" ) { fn = queue.shift(); }
+
+               if ( fn ) {
+                       // Add a progress sentinel to prevent the fx queue from being
+                       // automatically dequeued
+                       if ( type == "fx" ) { queue.unshift("inprogress"); }
+
+                       fn.call(elem, function() { jQuery.dequeue(elem, type); });
+               }
+       }
+});
+
+jQuery.fn.extend({
+       queue: function(type, data){
+               if ( typeof type !== "string" ) {
+                       data = type;
+                       type = "fx";
+               }
+
+               if ( data === undefined ) {
+                       return jQuery.queue( this[0], type );
+               }
+               return this.each(function(i, elem){
+                       var queue = jQuery.queue( this, type, data );
+
+                       if ( type == "fx" && queue[0] !== "inprogress" ) {
+                               jQuery.dequeue( this, type );
+                       }
+               });
+       },
+       dequeue: function(type){
+               return this.each(function(){
+                       jQuery.dequeue( this, type );
+               });
+       },
+
+       // Based off of the plugin by Clint Helfers, with permission.
+       // http://blindsignals.com/index.php/2009/07/jquery-delay/
+       delay: function( time, type ) {
+               time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
+               type = type || "fx";
+
+               return this.queue( type, function() {
+                       var elem = this;
+                       setTimeout(function() {
+                               jQuery.dequeue( elem, type );
+                       }, time );
+               });
+       },
+
+       clearQueue: function(type){
+               return this.queue( type || "fx", [] );
+       }
+});
index 5c18f4f6a0019233ba89ec571201e7fd7540dd59..6d34672d37caa2ce71d5f31fe8ac470b1c76cc54 100644 (file)
@@ -12,6 +12,7 @@
        <script type="text/javascript" src="data/testrunner.js"></script>
        <script type="text/javascript" src="unit/core.js"></script>
        <script type="text/javascript" src="unit/data.js"></script>
+       <script type="text/javascript" src="unit/queue.js"></script>
        <script type="text/javascript" src="unit/attributes.js"></script>
        <script type="text/javascript" src="unit/css.js"></script>
        <script type="text/javascript" src="unit/traversing.js"></script>
index d18377d5933fafaf0ef4d3efdc5a943a395feff6..3916534c19a237e6b2f7b2f64d40a9b64b19824f 100644 (file)
@@ -142,170 +142,3 @@ test(".removeData()", function() {
        div.removeData("test.foo");
        equals( div.data("test.foo"), undefined, "Make sure data is intact" );
 });
-
-test("queue() defaults to 'fx' type", function () {
-       expect(1);
-       stop();
-
-       var counter = 0;
-
-       var $foo = jQuery("#foo");
-
-       $foo.queue(function() {
-               var self = this;
-               setTimeout(function() {
-                       jQuery(self).dequeue("fx");
-                       start();
-               }, 200);
-       }).queue(function() {
-               ok( "dequeuing 'fx' calls queues created with no name" )
-       });
-
-});
-
-test("queue() with other types",function() {
-       expect(9);
-       var counter = 0;
-       
-       var $div = jQuery({});
-       
-       $div
-               .queue('foo',function(){
-                       equals( ++counter, 1, "Dequeuing" );
-                       jQuery.dequeue(this,'foo');
-               })
-               .queue('foo',function(){
-                       equals( ++counter, 2, "Dequeuing" );
-                       jQuery(this).dequeue('foo');
-               })
-               .queue('foo',function(){
-                       equals( ++counter, 3, "Dequeuing" );
-               })
-               .queue('foo',function(){
-                       equals( ++counter, 4, "Dequeuing" );
-               });
-               
-       equals( $div.queue('foo').length, 4, "Testing queue length" );
-       
-       $div.dequeue('foo');
-       
-       equals( counter, 3, "Testing previous call to dequeue" );
-       equals( $div.queue('foo').length, 1, "Testing queue length" );
-       
-       $div.dequeue('foo');
-       
-       equals( counter, 4, "Testing previous call to dequeue" );
-       equals( $div.queue('foo').length, 0, "Testing queue length" );
-});
-
-test("queue(name) passes in the next item in the queue as a parameter", function() {
-       expect(2);
-       
-       var div = jQuery({});
-       var counter = 0;
-       
-       div.queue("foo", function(next) {
-               equals(++counter, 1, "Dequeueing");
-               next();
-       }).queue("foo", function(next) {
-               equals(++counter, 2, "Next was called");
-               next();
-       }).queue("bar", function() {
-               equals(++counter, 3, "Other queues are not triggered by next()")
-       });
-       
-       div.dequeue("foo");
-});
-
-test("queue(name) passes in the next item in the queue as a parameter", function() {
-       expect(2);
-       
-       var div = jQuery({});
-       var counter = 0;
-       
-       div.queue("foo", function(next) {
-               equals(++counter, 1, "Dequeueing");
-               next();
-       }).queue("foo", function(next) {
-               equals(++counter, 2, "Next was called");
-               next();
-       }).queue("bar", function() {
-               equals(++counter, 3, "Other queues are not triggered by next()")
-       });
-       
-       div.dequeue("foo");
-});
-
-test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
-       expect(2);
-       stop();
-       
-       var div = jQuery({});
-       var counter = 0;
-       
-       div.queue(function(next) {
-               equals(++counter, 1, "Dequeueing");
-               var self = this;
-               setTimeout(function() { next() }, 500);
-       }).queue(function(next) {
-               equals(++counter, 2, "Next was called");
-               next();
-               start();
-       }).queue("bar", function() {
-               equals(++counter, 3, "Other queues are not triggered by next()")
-       });
-
-});
-
-test("delay()", function() {
-       expect(2);
-       stop();
-
-       var foo = jQuery({}), run = 0;
-
-       foo.delay(100).queue(function(){
-               run = 1;
-               ok( true, "The function was dequeued." );
-               start();
-       });
-
-       equals( run, 0, "The delay delayed the next function from running." );
-});
-
-test("clearQueue(name) clears the queue", function() {
-       expect(1);
-       
-       var div = jQuery({});
-       var counter = 0;
-       
-       div.queue("foo", function(next) {
-               counter++;
-               jQuery(this).clearQueue("foo");
-               next();
-       }).queue("foo", function(next) {
-               counter++;
-       });
-       
-       div.dequeue("foo");
-       
-       equals(counter, 1, "the queue was cleared");
-});
-
-test("clearQueue() clears the fx queue", function() {
-       expect(1);
-       
-       var div = jQuery({});
-       var counter = 0;
-       
-       div.queue(function(next) {
-               counter++;
-               var self = this;
-               setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
-       }).queue(function(next) {
-               counter++;
-       });
-       
-       equals(counter, 1, "the queue was cleared");
-       
-       div.removeData();
-});
diff --git a/test/unit/queue.js b/test/unit/queue.js
new file mode 100644 (file)
index 0000000..79b753c
--- /dev/null
@@ -0,0 +1,148 @@
+module("queue");
+
+test("queue() with other types",function() {
+       expect(9);
+       var counter = 0;
+       
+       var $div = jQuery({});
+       
+       $div
+               .queue('foo',function(){
+                       equals( ++counter, 1, "Dequeuing" );
+                       jQuery.dequeue(this,'foo');
+               })
+               .queue('foo',function(){
+                       equals( ++counter, 2, "Dequeuing" );
+                       jQuery(this).dequeue('foo');
+               })
+               .queue('foo',function(){
+                       equals( ++counter, 3, "Dequeuing" );
+               })
+               .queue('foo',function(){
+                       equals( ++counter, 4, "Dequeuing" );
+               });
+               
+       equals( $div.queue('foo').length, 4, "Testing queue length" );
+       
+       $div.dequeue('foo');
+       
+       equals( counter, 3, "Testing previous call to dequeue" );
+       equals( $div.queue('foo').length, 1, "Testing queue length" );
+       
+       $div.dequeue('foo');
+       
+       equals( counter, 4, "Testing previous call to dequeue" );
+       equals( $div.queue('foo').length, 0, "Testing queue length" );
+});
+
+test("queue(name) passes in the next item in the queue as a parameter", function() {
+       expect(2);
+       
+       var div = jQuery({});
+       var counter = 0;
+       
+       div.queue("foo", function(next) {
+               equals(++counter, 1, "Dequeueing");
+               next();
+       }).queue("foo", function(next) {
+               equals(++counter, 2, "Next was called");
+               next();
+       }).queue("bar", function() {
+               equals(++counter, 3, "Other queues are not triggered by next()")
+       });
+       
+       div.dequeue("foo");
+});
+
+test("queue(name) passes in the next item in the queue as a parameter", function() {
+       expect(2);
+       
+       var div = jQuery({});
+       var counter = 0;
+       
+       div.queue("foo", function(next) {
+               equals(++counter, 1, "Dequeueing");
+               next();
+       }).queue("foo", function(next) {
+               equals(++counter, 2, "Next was called");
+               next();
+       }).queue("bar", function() {
+               equals(++counter, 3, "Other queues are not triggered by next()")
+       });
+       
+       div.dequeue("foo");
+});
+
+test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
+       expect(2);
+       stop();
+       
+       var div = jQuery({});
+       var counter = 0;
+       
+       div.queue(function(next) {
+               equals(++counter, 1, "Dequeueing");
+               var self = this;
+               setTimeout(function() { next() }, 500);
+       }).queue(function(next) {
+               equals(++counter, 2, "Next was called");
+               next();
+               start();
+       }).queue("bar", function() {
+               equals(++counter, 3, "Other queues are not triggered by next()")
+       });
+
+});
+
+test("delay()", function() {
+       expect(2);
+       stop();
+
+       var foo = jQuery({}), run = 0;
+
+       foo.delay(100).queue(function(){
+               run = 1;
+               ok( true, "The function was dequeued." );
+               start();
+       });
+
+       equals( run, 0, "The delay delayed the next function from running." );
+});
+
+test("clearQueue(name) clears the queue", function() {
+       expect(1);
+       
+       var div = jQuery({});
+       var counter = 0;
+       
+       div.queue("foo", function(next) {
+               counter++;
+               jQuery(this).clearQueue("foo");
+               next();
+       }).queue("foo", function(next) {
+               counter++;
+       });
+       
+       div.dequeue("foo");
+       
+       equals(counter, 1, "the queue was cleared");
+});
+
+test("clearQueue() clears the fx queue", function() {
+       expect(1);
+       
+       var div = jQuery({});
+       var counter = 0;
+       
+       div.queue(function(next) {
+               counter++;
+               var self = this;
+               setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
+       }).queue(function(next) {
+               counter++;
+       });
+       
+       equals(counter, 1, "the queue was cleared");
+       
+       div.removeData();
+});