From 950da8ae7f408032a91089a5d5c7befa4cd168aa Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 26 May 2011 18:38:34 +0100 Subject: [PATCH] Added queue flag to $.Callbacks. Unit tests added (more to come). --- src/callbacks.js | 6 ++++++ test/unit/callbacks.js | 1 + 2 files changed, 7 insertions(+) diff --git a/src/callbacks.js b/src/callbacks.js index 8be35094..a1caf91f 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -34,6 +34,9 @@ function createFlags( flags ) { * after the list has been fired right away with the latest "memorized" * values (like a Deferred) * + * queue: only first callback in the list is called each time the list is fired + * (cannot be used in conjunction with memory) + * * unique: will ensure a callback can only be added once (no duplicate in the list) * * relocate: like "unique" but will relocate the callback at the end of the list @@ -112,6 +115,9 @@ jQuery.Callbacks = function( flags, filter ) { if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) { memory = true; // Mark as halted break; + } else if ( flags.queue ) { + list.splice( firingIndex, 1 ); + break; } } firing = false; diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 54817de4..fcc3ee46 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -19,6 +19,7 @@ var output, "relocate": "XABC X XAABC X XBB X XBA X", "stopOnFalse": "XABC X XABCABCC X XBB X XA X", "addAfterFire": "XAB X XABCAB X XBB X XABA X", + "queue": "XA X XB X XB X XA X", "once memory": "XABC XABC X XA X XA XABA XC", "once unique": "XABC X X X X X XAB X", "once relocate": "XABC X X X X X XBA X",