*/
function isSet(a, b, msg) {
var ret = true;
- if ( a && b && a.length == b.length ) {
+ if ( a && b && a.length != undefined && a.length == b.length ) {
for ( var i = 0; i < a.length; i++ )
if ( a[i] != b[i] )
ret = false;
_config.Test.push( [ ret, msg ] );
}
+/**
+ * Asserts that two objects are equivalent
+ */
+function isObj(a, b, msg) {
+ var ret = true;
+
+ if ( a && b ) {
+ for ( var i in a )
+ if ( a[i] != b[i] )
+ ret = false;
+
+ for ( i in b )
+ if ( a[i] != b[i] )
+ ret = false;
+ } else
+ ret = false;
+
+ _config.Test.push( [ ret, msg ] );
+}
+
function serialArray( a ) {
var r = [];
- for ( var i = 0; i < a.length; i++ ) {
- var str = a[i].nodeName;
- if ( str ) {
- str = str.toLowerCase();
- if ( a[i].id )
- str += "#" + a[i].id;
- } else
- str = a[i];
- r.push( str );
- }
+
+ if ( a && a.length )
+ for ( var i = 0; i < a.length; i++ ) {
+ var str = a[i].nodeName;
+ if ( str ) {
+ str = str.toLowerCase();
+ if ( a[i].id )
+ str += "#" + a[i].id;
+ } else
+ str = a[i];
+ r.push( str );
+ }
return "[ " + r.join(", ") + " ]"
}
// Handle triggering a single element
else {
- var val, ret, fn = jQuery.isFunction( element[ type ] );
+ var val, ret, fn = jQuery.isFunction( element[ type ] || null );
// Pass along a fake event
data.unshift( this.fix({ type: type, target: element }) );
},
handle: function(event) {
+ // returned undefined or false
+ var val;
+
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
- if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return;
+ if ( typeof jQuery == "undefined" || jQuery.event.triggered )
+ return val;
// Empty object is for triggered events with no data
event = jQuery.event.fix( event || window.event || {} );
- // returned undefined or false
- var returnValue;
-
- var c = this.$events[event.type];
-
- var args = [].slice.call( arguments, 1 );
+ var c = this.$events[event.type], args = [].slice.call( arguments, 1 );
args.unshift( event );
for ( var j in c ) {
if ( c[j].apply( this, args ) === false ) {
event.preventDefault();
event.stopPropagation();
- returnValue = false;
+ val = false;
}
}
// Clean up added properties in IE to prevent memory leak
- if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null;
+ if (jQuery.browser.msie)
+ event.target = event.preventDefault = event.stopPropagation =
+ event.handler = event.data = null;
- return returnValue;
+ return val;
},
fix: function(event) {
return this.click(function(e) {
// Figure out which function to execute
- this.lastToggle = this.lastToggle == 0 ? 1 : 0;
+ this.lastToggle = 0 == this.lastToggle ? 1 : 0;
// Make sure that clicks stop
e.preventDefault();
ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
reset();
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
+ var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
$('#sap').append(document.getElementById('first'));
ok( expected == $('#sap').text(), "Check for appending of element" );
ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
reset();
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
+ var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
$(document.getElementById('first')).appendTo('#sap');
ok( expected == $('#sap').text(), "Check for appending of element" );
ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
reset();
- expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
+ var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
$('#sap').prepend(document.getElementById('first'));
ok( expected == $('#sap').text(), "Check for prepending of element" );
ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
reset();
- expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
+ var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
$(document.getElementById('first')).prependTo('#sap');
ok( expected == $('#sap').text(), "Check for prepending of element" );
optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
jQuery.extend(settings, options);
- isSet( settings, merged, "Check if extended: settings must be extended" );
- isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
+ isObj( settings, merged, "Check if extended: settings must be extended" );
+ isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
});
test("$.extend(Object, Object, Object, Object)", function() {
options2Copy = { xstring2: "xx", xxx: "newstringx" },
merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
var settings = jQuery.extend({}, defaults, options1, options2);
- isSet( settings, merged, "Check if extended: settings must be extended" );
- isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
- isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
- isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
+ isObj( settings, merged, "Check if extended: settings must be extended" );
+ isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
+ isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
+ isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
});
test("val()", function() {
*/
clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){
- var a = a.cloneNode( deep != undefined ? deep : true );
+ a = a.cloneNode( deep != undefined ? deep : true );
a.$events = null; // drop $events expando to avoid firing incorrect events
return a;
}) );
/**
* Extend one object with one or more others, returning the original,
* modified, object. This is a great utility for simple inheritance.
- *
- * There is also an optional collision resolution function. Any time the target and
- * merged object both contain a key this function is called. This may be used to create
- * a recursive merge. (See example) Unless you know what this is, you probably don't care.
*
* @example var settings = { validate: false, limit: 5, name: "foo" };
* var options = { validate: true, name: "bar" };
* @result settings == { validate: true, limit: 5, name: "bar" }
* @desc Merge defaults and options, without modifying the defaults
*
- * @example var defaults = { validate: false, limit: 5, name: "foo", nested: {depth: false} };
- * var options = { validate: true, name: "bar", nested: {depth: true} };
- * var collision_resolver_fn = function(target, mergee) {
- * // combine nested Objects, in this case the object being merged takes priority
- * return jQuery.extend({}, target, mergee);
- * }
- * var settings = jQuery.extend({}, collision_resolver_fn, defaults, options);
- * @result settings == { validate: true, limit: 5, name: "bar" }
- * @desc Recursively merge defaults and options, without modifying the defaults
- *
* @name $.extend
* @param Object target The object to extend
- * @param Function (optional) collision resolution function. Hook to extend the merging behavior of $.extend(). See example.
* @param Object prop1 The object that will be merged into the first.
* @param Object propN (optional) More objects to merge into the first
* @type Object
*/
jQuery.extend = jQuery.fn.extend = function() {
// copy reference to target object
- var resolver, prop, target = arguments[0],
- a = 1;
-
+ var target = arguments[0], a = 1;
+
// extend jQuery itself if only one argument is passed
if ( arguments.length == 1 ) {
target = this;
a = 0;
- } else if (jQuery.isFunction(arguments[a])) {
- resolver = arguments[a++];
}
-
- while (prop = arguments[a++])
+ var prop;
+ while ( (prop = arguments[a++]) != null )
// Extend the base object
- for ( var i in prop ) {
- if (resolver && target[i] && prop[i]) {
- target[i] = resolver(target[i], prop[i]);
- } else {
- target[i] = prop[i];
- }
- }
+ for ( var i in prop ) target[i] = prop[i];
// Return the modified object
return target;
arg = jQuery.makeArray( div.childNodes );
}
- if ( arg.length === 0 && !jQuery(arg).is("form, select") )
+ if ( 0 === arg.length && !jQuery(arg).is("form, select") )
return;
if ( arg[0] == undefined || jQuery(arg).is("form, select") )
var r = [], num = jQuery.mergeNum++;
for ( var i = 0, fl = first.length; i < fl; i++ )
- if ( first[i].mergeNum != num ) {
+ if ( num != first[i].mergeNum ) {
first[i].mergeNum = num;
r.push(first[i]);
}
contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
// Visibility
- visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
- hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
+ visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
+ hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
// Form attributes
enabled: "!a.disabled",
selected: "a.selected||jQuery.attr(a,'selected')",
// Form elements
- text: "a.type=='text'",
- radio: "a.type=='radio'",
- checkbox: "a.type=='checkbox'",
- file: "a.type=='file'",
- password: "a.type=='password'",
- submit: "a.type=='submit'",
- image: "a.type=='image'",
- reset: "a.type=='reset'",
- button: 'a.type=="button"||jQuery.nodeName(a,"button")',
+ text: "'text'==a.type",
+ radio: "'radio'==a.type",
+ checkbox: "'checkbox'==a.type",
+ file: "'file'==a.type",
+ password: "'password'==a.type",
+ submit: "'submit'==a.type",
+ image: "'image'==a.type",
+ reset: "'reset'==a.type",
+ button: '"button"==a.type||jQuery.nodeName(a,"button")',
input: "/input|select|textarea|button/i.test(a.nodeName)"
},
".": "jQuery.className.has(a,m[2])",
_resort: function(m){
return ["", m[1], m[3], m[2], m[5]];
},
- _prefix: "z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);"
+ _prefix: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);"
},
"[": "jQuery.find(m[2],a).length"
},
// Handle multiple expressions
if ( !t.indexOf(",") ) {
// Clean the result set
- if ( ret[0] == context ) ret.shift();
+ if ( context == ret[0] ) ret.shift();
// Merge the result sets
done = jQuery.merge( done, ret );
ret = [];
// Remove the root context
- if ( ret && ret[0] == context )
+ if ( ret && context == ret[0] )
ret.shift();
// And combine the results
for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType == 1 ) num++;
if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
- result == "odd" && num % 2 == 1 && cur == elem ) return cur;
+ result == "odd" && num % 2 == 1 && cur == elem ) break;
}
+ return cur;
},
/**