diff --git a/jquery/jquery-1.8.d.ts b/jquery/jquery-1.8.d.ts index fd2044984..1300fcec6 100644 --- a/jquery/jquery-1.8.d.ts +++ b/jquery/jquery-1.8.d.ts @@ -575,6 +575,10 @@ interface JQuery { context: Element; jquery: string; + + error(handler: (eventObject: JQueryEventObject) => any): JQuery; + error(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; + pushStack(elements: any[]): JQuery; pushStack(elements: any[], name: any, arguments: any): JQuery; diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index e5286cfd6..ff019b048 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1090,6 +1090,31 @@ function test_die() { */ function test_each() { + $.each([52, 97], function (index, value) { + alert(index + ': ' + value); + }); + var map = { + 'flammable': 'inflammable', + 'duh': 'no duh' + }; + $.each(map, function (key, value) { + alert(key + ': ' + value); + }); + var arr = ["one", "two", "three", "four", "five"]; + var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 }; + jQuery.each(arr, function () { + $("#" + this).text("Mine is " + this + "."); + return (this != "three"); + }); + jQuery.each(obj, function (i, val) { + $("#" + i).append(document.createTextNode(" - " + val)); + }); + $.each(['a', 'b', 'c'], function (i, l) { + alert("Index #" + i + ": " + l); + }); + $.each({ name: "John", lang: "JS" }, function (k, v) { + alert("Key: " + k + ", Value: " + v); + }); $('li').each(function (index) { alert(index + ': ' + $(this).text()); }); @@ -1119,6 +1144,41 @@ function test_each() { }); } +function test_empty() { + $('.hello').empty(); +} + +function test_end() { + $('ul.first').find('.foo').css('background-color', 'red') + .end().find('.bar').css('background-color', 'green'); + $('ul.first').find('.foo') + .css('background-color', 'red') + .end().find('.bar') + .css('background-color', 'green') + .end(); +} + +function test_eq() { + $('li').eq(2).css('background-color', 'red'); + $('li').eq(-2).css('background-color', 'red'); + $('li').eq(5).css('background-color', 'red'); + $("body").find("div").eq(2).addClass("blue"); +} + +function test_error() { + $('#book') + .error(function () { + alert('Handler for .error() called.') + }) + .attr("src", "missing.png"); + $("img") + .error(function () { + $(this).hide(); + }) + .attr("src", "missing.png"); + jQuery.error = console.error; +} + function test_mouseEvents() { var i = 0; $("div.overout").mouseover(function () {