From 07041a3088e7284058df81a35961b61d5faff106 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Thu, 16 Jan 2014 13:38:16 +0000 Subject: [PATCH] jQuery: queue, dequeue, hasdata added queue test suite --- jquery/jquery-tests.ts | 62 ++++++++++++++++++++++++++++++++++++++++++ jquery/jquery.d.ts | 45 ++++++++++++++++++++++++++---- 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 0ad13a4bf..e024f1dc6 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1095,6 +1095,68 @@ function test_dequeue() { }); } +function test_queue() { + + $("#show").click(function () { + var n = jQuery.queue($("div")[0], "fx"); + $("span").text("Queue length is: " + n.length); + }); + + function runIt() { + $("div") + .show("slow") + .animate({ + left: "+=200" + }, 2000) + .slideToggle(1000) + .slideToggle("fast") + .animate({ + left: "-=200" + }, 1500) + .hide("slow") + .show(1200) + .slideUp("normal", runIt); + } + + runIt(); + + $(document.body).click(function () { + var divs = $("div") + .show("slow") + .animate({ left: "+=200" }, 2000); + jQuery.queue(divs[0], "fx", function () { + $(this).addClass("newcolor"); + jQuery.dequeue(this); + }); + divs.animate({ left: "-=200" }, 500); + jQuery.queue(divs[0], "fx", function () { + $(this).removeClass("newcolor"); + jQuery.dequeue(this); + }); + divs.slideUp(); + }); + + $("#start").click(function () { + var divs = $("div") + .show("slow") + .animate({ left: "+=200" }, 5000); + jQuery.queue(divs[0], "fx", function () { + $(this).addClass("newcolor"); + jQuery.dequeue(this); + }); + divs.animate({ left: "-=200" }, 1500); + jQuery.queue(divs[0], "fx", function () { + $(this).removeClass("newcolor"); + jQuery.dequeue(this); + }); + divs.slideUp(); + }); + $("#stop").click(function () { + jQuery.queue($("div")[0], "fx", []); + $("div").stop(); + }); +} + function test_detach() { $("p").click(function () { $(this).toggleClass("off"); diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index d690a649e..df6256293 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -423,9 +423,9 @@ interface JQueryEasing { swing(p: number): number; } -/* - Static members of jQuery (those on $ and jQuery themselves) -*/ +/** + * Static members of jQuery (those on $ and jQuery themselves) + */ interface JQueryStatic { /** @@ -659,6 +659,9 @@ interface JQueryStatic { */ when(...deferreds: any[]): JQueryPromise; + /** + * Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties. + */ cssHooks: { [key: string]: any; }; cssNumber: any; @@ -684,12 +687,44 @@ interface JQueryStatic { */ data(element: Element): any; - dequeue(element: Element, queueName?: string): any; + /** + * Execute the next function on the queue for the matched element. + * + * @param element A DOM element from which to remove and execute a queued function. + * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. + */ + dequeue(element: Element, queueName?: string): void; + /** + * Determine whether an element has any jQuery data associated with it. + * + * @param element A DOM element to be checked for data. + */ hasData(element: Element): boolean; + /** + * Show the queue of functions to be executed on the matched element. + * + * @param element A DOM element to inspect for an attached queue. + * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. + */ queue(element: Element, queueName?: string): any[]; - queue(element: Element, queueName: string, newQueueOrCallback: any): JQuery; + /** + * Manipulate the queue of functions to be executed on the matched element. + * + * @param element A DOM element where the array of queued functions is attached. + * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. + * @param newQueue An array of functions to replace the current queue contents. + */ + queue(element: Element, queueName: string, newQueue: Function[]): JQuery; + /** + * Manipulate the queue of functions to be executed on the matched element. + * + * @param element A DOM element on which to add a queued function. + * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. + * @param callback The new function to add to the queue. + */ + queue(element: Element, queueName: string, callback: Function): JQuery; removeData(element: Element, name?: string): JQuery;