From ef16c3fcbdd35cc4231e5b55111c00e4d6810919 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Mon, 5 Nov 2012 11:52:18 +0200 Subject: [PATCH] Add jQuery.text definitions and more tests --- Definitions/jquery-1.8.d.ts | 5 +-- Tests/jquery-tests.ts | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Definitions/jquery-1.8.d.ts b/Definitions/jquery-1.8.d.ts index 455f7cb54..467f498e7 100644 --- a/Definitions/jquery-1.8.d.ts +++ b/Definitions/jquery-1.8.d.ts @@ -597,9 +597,10 @@ interface JQuery { replaceWith(func: any): JQuery; - text(textString: string): JQuery; text(): string; - + text(textString: string): JQuery; + text(textString: (index: number, text: string) => string): JQuery; + toArray(): any[]; unwrap(): JQuery; diff --git a/Tests/jquery-tests.ts b/Tests/jquery-tests.ts index b7e9e6685..6fc2c7398 100644 --- a/Tests/jquery-tests.ts +++ b/Tests/jquery-tests.ts @@ -645,6 +645,58 @@ function test_callbacks() { dfd.resolve("its been published!"); } +function test_callbacksFunctions() { + var foo = function (value) { + console.log('foo:' + value); + } + var bar = function (value) { + console.log('bar:' + value); + } + var callbacks = $.Callbacks(); + callbacks.add(foo); + callbacks.fire('hello'); + callbacks.add(bar); + callbacks.fire('world'); + callbacks.disable(); + callbacks.empty(); + callbacks.fire('hello'); + console.log(callbacks.fired()); + callbacks.fireWith(window, ['foo', 'bar']); + var foo2 = function (value1, value2) { + console.log('Received:' + value1 + ',' + value2); + }; + console.log(callbacks.has(foo2)); + callbacks.lock(); + console.log(callbacks.locked()); + callbacks.remove(foo); +} + +function test_change() { + $('.target').change(function () { + alert('Handler for .change() called.'); + }); + $('#other').click(function () { + $('.target').change(); + }); + $("input[type='text']").change(function () { }); +} + +function test_children() { + $('ul.level-2').children().css('background-color', 'red'); + $("#container").click(function (e) { + $("*").removeClass("hilite"); + var $kids = $(e.target).children(); + var len = $kids.addClass("hilite").length; + + $("#results span:first").text(len.toString()); + $("#results span:last").text(e.target.tagName); + + e.preventDefault(); + return false; + }); + $("div").children(".selected").css("color", "blue"); +} + function test_each() { $('li').each(function (index) { alert(index + ': ' + $(this).text()); @@ -673,4 +725,13 @@ function test_each() { } }); }); +} + +function test_text() { + var str = $("p:first").text(); + $("p:last").html(str); + $('ul li').text(function (index) { + return 'item number ' + (index + 1); + }); + $("p").text("Some new text."); } \ No newline at end of file