var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
jsonp, status, data, type = s.type.toUpperCase(), noContent = rnoContent.test(type);
- s.url = s.url.replace( rhash, "" );
+ // toString fixes people passing a window.location or
+ // document.location to $.ajax, which worked in 1.4.2 and
+ // earlier (bug #7531). It should be removed in 1.5.
+ s.url = ("" + s.url).replace( rhash, "" );
// Use original (not extended) context object if it was provided
s.context = origSettings && origSettings.context != null ? origSettings.context : s;
};
}
- if ( s.dataType === "script" && s.cache === null ) {
+ if ( s.dataType === "script" && s.cache === undefined ) {
s.cache = false;
}
(function( jQuery ) {
-var rclass = /[\n\t]/g,
+var rclass = /[\n\t\r]/g,
rspaces = /\s+/,
rreturn = /\r/g,
rspecialurl = /^(?:href|src|style)$/,
if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) {
return elem.getAttribute("value") === null ? "on" : elem.value;
}
-
// Everything else, we just grab the value
return (elem.value || "").replace(rreturn, "");
height: true,
offset: true
},
-
+
attr: function( elem, name, value, pass ) {
// don't set attributes on text and comment nodes
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
// Try to normalize/fix the name
name = notxml && jQuery.props[ name ] || name;
- // These attributes require special treatment
- var special = rspecialurl.test( name );
+ // Only do all the following if this is a node (faster for style)
+ if ( elem.nodeType === 1 ) {
+ // These attributes require special treatment
+ var special = rspecialurl.test( name );
+
+ // Safari mis-reports the default selected property of an option
+ // Accessing the parent's selectedIndex property fixes it
+ if ( name === "selected" && !jQuery.support.optSelected ) {
+ var parent = elem.parentNode;
+ if ( parent ) {
+ parent.selectedIndex;
+
+ // Make sure that it also works with optgroups, see #5701
+ if ( parent.parentNode ) {
+ parent.parentNode.selectedIndex;
+ }
+ }
+ }
- // Safari mis-reports the default selected property of an option
- // Accessing the parent's selectedIndex property fixes it
- if ( name === "selected" && !jQuery.support.optSelected ) {
- var parent = elem.parentNode;
- if ( parent ) {
- parent.selectedIndex;
+ // If applicable, access the attribute via the DOM 0 way
+ // 'in' checks fail in Blackberry 4.7 #6931
+ if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
+ if ( set ) {
+ // We can't allow the type property to be changed (since it causes problems in IE)
+ if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
+ jQuery.error( "type property can't be changed" );
+ }
+
+ if ( value === null ) {
+ if ( elem.nodeType === 1 ) {
+ elem.removeAttribute( name );
+ }
- // Make sure that it also works with optgroups, see #5701
- if ( parent.parentNode ) {
- parent.parentNode.selectedIndex;
+ } else {
+ elem[ name ] = value;
+ }
}
- }
- }
- // If applicable, access the attribute via the DOM 0 way
- // 'in' checks fail in Blackberry 4.7 #6931
- if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
- if ( set ) {
- // We can't allow the type property to be changed (since it causes problems in IE)
- if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
- jQuery.error( "type property can't be changed" );
+ // browsers index elements by id/name on forms, give priority to attributes.
+ if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
+ return elem.getAttributeNode( name ).nodeValue;
}
- if ( value === null ) {
- if ( elem.nodeType === 1 ) {
- elem.removeAttribute( name );
- }
+ // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
+ // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
+ if ( name === "tabIndex" ) {
+ var attributeNode = elem.getAttributeNode( "tabIndex" );
- } else {
- elem[ name ] = value;
+ return attributeNode && attributeNode.specified ?
+ attributeNode.value :
+ rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
+ 0 :
+ undefined;
}
- }
- // browsers index elements by id/name on forms, give priority to attributes.
- if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
- return elem.getAttributeNode( name ).nodeValue;
+ return elem[ name ];
}
- // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
- // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
- if ( name === "tabIndex" ) {
- var attributeNode = elem.getAttributeNode( "tabIndex" );
+ if ( !jQuery.support.style && notxml && name === "style" ) {
+ if ( set ) {
+ elem.style.cssText = "" + value;
+ }
- return attributeNode && attributeNode.specified ?
- attributeNode.value :
- rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
- 0 :
- undefined;
+ return elem.style.cssText;
}
- return elem[ name ];
- }
-
- if ( !jQuery.support.style && notxml && name === "style" ) {
if ( set ) {
- elem.style.cssText = "" + value;
+ // convert the value to a string (all browsers do this but IE) see #1070
+ elem.setAttribute( name, "" + value );
}
- return elem.style.cssText;
- }
+ // Ensure that missing attributes return undefined
+ // Blackberry 4.7 returns "" from getAttribute #6938
+ if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
+ return undefined;
+ }
- if ( set ) {
- // convert the value to a string (all browsers do this but IE) see #1070
- elem.setAttribute( name, "" + value );
- }
+ var attr = !jQuery.support.hrefNormalized && notxml && special ?
+ // Some attributes require a special call on IE
+ elem.getAttribute( name, 2 ) :
+ elem.getAttribute( name );
- // Ensure that missing attributes return undefined
- // Blackberry 4.7 returns "" from getAttribute #6938
- if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
- return undefined;
+ // Non-existent attributes return null, we normalize to undefined
+ return attr === null ? undefined : attr;
}
-
- var attr = !jQuery.support.hrefNormalized && notxml && special ?
- // Some attributes require a special call on IE
- elem.getAttribute( name, 2 ) :
- elem.getAttribute( name );
-
- // Non-existent attributes return null, we normalize to undefined
- return attr === null ? undefined : attr;
+ // Handle everything which isn't a DOM element node
+ if ( set ) {
+ elem[ name ] = value;
+ }
+ return elem[ name ];
}
});
this.toArray() :
// Return just the object
- ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] );
+ ( num < 0 ? this[ this.length + num ] : this[ num ] );
},
// Take an array of elements and push it onto the stack
jQuery.event.special.submit = {
setup: function( data, namespaces ) {
- if ( this.nodeName.toLowerCase() !== "form" ) {
+ if ( this.nodeName && this.nodeName.toLowerCase() !== "form" ) {
jQuery.event.add(this, "click.specialSubmit", function( e ) {
var elem = e.target,
type = elem.type;
events = events.events;
}
- // Make sure we avoid non-left-click bubbling in Firefox (#3861)
- if ( event.liveFired === this || !events || !events.live || event.button && event.type === "click" ) {
+ // Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911)
+ if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) {
return;
}
// checked="checked" or checked (html5)
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
raction = /\=([^="'>\s]+\/)>/g,
+ rbodystart = /^\s*<body/i,
+ rbodyend = /<\/body>\s*$/i,
wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ],
// the name attribute on an input).
var html = this.outerHTML,
ownerDocument = this.ownerDocument;
-
if ( !html ) {
var div = ownerDocument.createElement("div");
div.appendChild( this.cloneNode(true) );
html = div.innerHTML;
+ } else if ( rbodystart.test(html) && rbodyend.test(html) ) {
+ html = html.replace( rbodystart, "<div>" ).replace( rbodyend, "</div>" );
}
return jQuery.clean([html.replace(rinlinejQuery, "")
});
test("jQuery.ajax() - JSONP, Local", function() {
- expect(8);
+ expect(9);
var count = 0;
- function plus(){ if ( ++count == 8 ) start(); }
+ function plus(){ if ( ++count == 9 ) start(); }
stop();
plus();
}
});
+
+ //#7578
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ beforeSend: function(){
+ strictEqual( this.cache, false, "cache must be false on JSON request" );
+ plus();
+ return false;
+ }
+ });
});
test("JSONP - Custom JSONP Callback", function() {
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
});
+test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
+ var success = false;
+ try {
+ var xhr = jQuery.ajax({ url: document.location });
+ success = true;
+ xhr.abort();
+ } catch (e) {}
+
+ ok( success, "document.location did not generate exception" );
+});
}
var functionReturningObj = function(value) { return (function() { return value; }); };
test("attr(String)", function() {
- expect(31);
+ expect(37);
// This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
equals( jQuery(document).attr("nodeName"), "#document", "attr works correctly on document nodes (bug #7451)." );
+
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) {
+ strictEqual( jQuery(ele).attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
+ });
});
if ( !isLocal ) {
});
test("attr(String, Object)", function() {
- expect(24);
+ expect(30);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
jQuery("#name").attr('maxLength', '10');
equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ jQuery.each( [document, attributeNode, obj, "#firstp"], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" );
+ equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." );
+ });
+ jQuery.each( [commentNode, textNode], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" );
+ strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
+ });
+ //cleanup
+ jQuery.each( [document, "#firstp"], function( i, ele ) {
+ jQuery( ele ).removeAttr("nonexisting");
+ });
+
var table = jQuery('#table').append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
td = table.find('td:first');
td.attr("rowspan", "2");
});
test("removeAttr(String)", function() {
- expect(1);
+ expect(7);
equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
+
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ //removeAttr only really removes on DOM element nodes handle all other seperatyl
+ strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" );
+
+ jQuery.each( [document, attributeNode, obj], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
+ strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." );
+ });
+ jQuery.each( [commentNode, textNode], function( i, ele ) {
+ $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
+ strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." );
+ });
});
test("val()", function() {
});
test("addClass, removeClass, hasClass", function() {
- expect(14);
+ expect(17);
var jq = jQuery("<p>Hi</p>"), x = jq[0];
ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" );
- var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n'></p>");
- ok( jq.hasClass("class1"), "Check hasClass with carriage return" );
- ok( jq.is(".class1"), "Check is with carriage return" );
+ var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
+ ok( jq.hasClass("class1"), "Check hasClass with line feed" );
+ ok( jq.is(".class1"), "Check is with line feed" );
ok( jq.hasClass("class2"), "Check hasClass with tab" );
ok( jq.is(".class2"), "Check is with tab" );
ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
+ ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
+ ok( jq.is(".class4"), "Check is with carriage return" );
jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3");
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
+ jq.removeClass("class4");
+ ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
});
})
test("get(Number)", function() {
- expect(1);
+ expect(2);
equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
+ strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
});
test("get(-Number)",function() {
- expect(1);
- equals( jQuery("p").get(-1),
- document.getElementById("first"),
- "Get a single element with negative index" )
+ expect(2);
+ equals( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
+ strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
})
test("each(Function)", function() {
});
test("bind()/trigger()/unbind() on plain object", function() {
- expect( 7 );
+ expect( 8 );
var obj = {};
// Make sure it doesn't complain when no events are found
jQuery(obj).unbind("test");
- jQuery(obj).bind("test", function(){
- ok( true, "Custom event run." );
+ jQuery(obj).bind({
+ test: function() {
+ ok( true, "Custom event run." );
+ },
+ submit: function() {
+ ok( true, "Custom submit event run." );
+ }
});
var events = jQuery(obj).data("__events__");
// Should trigger 1
jQuery(obj).trigger("test");
+ jQuery(obj).trigger("submit");
jQuery(obj).unbind("test");
+ jQuery(obj).unbind("submit");
// Should trigger 0
jQuery(obj).trigger("test");
});
test("clone()", function() {
- expect(31);
+ expect(32);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
var clone = jQuery('#yahoo').clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
form.appendChild( div );
equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
+
+ equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
});
if (!isLocal) {