From 0477a6e99e95ae93da983e7fc2a30bf16ea8ca77 Mon Sep 17 00:00:00 2001 From: John Resig Date: Sat, 25 Aug 2007 03:55:12 +0000 Subject: [PATCH] Added a test case for "purple include", fixed a bug. --- build/test/data/test3.html | 3 +++ src/ajax/ajax.js | 6 ++++-- src/ajax/ajaxTest.js | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 build/test/data/test3.html diff --git a/build/test/data/test3.html b/build/test/data/test3.html new file mode 100644 index 0000000..909d417 --- /dev/null +++ b/build/test/data/test3.html @@ -0,0 +1,3 @@ +
This is a user
+
This is a user
+
This is a teacher
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index 795cd8a..ccf4f14 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -49,8 +49,10 @@ jQuery.fn.extend({ return this.bind("load", url); var off = url.indexOf(" "); - var selector = url.slice(off, url.length); - url = url.slice(0, off); + if ( off >= 0 ) { + var selector = url.slice(off, url.length); + url = url.slice(0, off); + } callback = callback || function(){}; diff --git a/src/ajax/ajaxTest.js b/src/ajax/ajaxTest.js index 4d4bc07..0fd4888 100644 --- a/src/ajax/ajaxTest.js +++ b/src/ajax/ajaxTest.js @@ -94,6 +94,15 @@ test("load(String)", function() { $('#first').load("data/name.html", start); }); +test("load('url selector')", function() { + expect(1); + stop(true); // check if load can be called with only url + $('#first').load("data/test3.html div.user", function(){ + equals( $(this).children("div").length, 2, "Verify that specific elements were injected" ); + start(); + }); +}); + test("load(String, Function) - simple: inject text into DOM", function() { expect(2); stop(); -- 1.7.10.4