diff --git a/.gitignore b/.gitignore index a77d67a9..6cd54797 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,5 @@ dist *~ *.diff *.patch -test/qunit -src/sizzle /*.html .DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..19c60418 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "src/sizzle"] + path = src/sizzle + url = git://github.com/jquery/sizzle.git +[submodule "test/qunit"] + path = test/qunit + url = git://github.com/jquery/qunit.git diff --git a/Makefile b/Makefile index a6aae425..cfd2a975 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -V ?= 0 - SRC_DIR = src TEST_DIR = test BUILD_DIR = build @@ -38,48 +36,21 @@ JQ = ${DIST_DIR}/jquery.js JQ_MIN = ${DIST_DIR}/jquery.min.js SIZZLE_DIR = ${SRC_DIR}/sizzle -QUNIT_DIR = ${TEST_DIR}/qunit JQ_VER = $(shell cat version.txt) VER = sed "s/@VERSION/${JQ_VER}/" DATE=$(shell git log -1 --pretty=format:%ad) -all: jquery min lint +all: update_submodules core + +core: jquery min lint @@echo "jQuery build complete." ${DIST_DIR}: @@mkdir -p ${DIST_DIR} -ifeq ($(strip $(V)),0) -verbose = --quiet -else ifeq ($(strip $(V)),1) -verbose = -else -verbose = --verbose -endif - -define clone_or_pull --@@if test ! -d $(strip ${1})/.git; then \ - echo "Cloning $(strip ${1})..."; \ - git clone $(strip ${verbose}) --depth=1 $(strip ${2}) $(strip ${1}); \ - else \ - echo "Pulling $(strip ${1})..."; \ - git --git-dir=$(strip ${1})/.git pull $(strip ${verbose}) origin master; \ - fi - -endef - -${QUNIT_DIR}: - $(call clone_or_pull, ${QUNIT_DIR}, git://github.com/jquery/qunit.git) - -${SIZZLE_DIR}: - $(call clone_or_pull, ${SIZZLE_DIR}, git://github.com/jeresig/sizzle.git) - -init: ${QUNIT_DIR} ${SIZZLE_DIR} - -jquery: init ${JQ} -jq: init ${JQ} +jquery: ${JQ} ${JQ}: ${MODULES} | ${DIST_DIR} @@echo "Building" ${JQ} @@ -102,9 +73,9 @@ lint: jquery echo "You must have NodeJS installed in order to test jQuery against JSLint."; \ fi -min: ${JQ_MIN} +min: jquery ${JQ_MIN} -${JQ_MIN}: jquery +${JQ_MIN}: ${JQ} @@if test ! -z ${JS_ENGINE}; then \ echo "Minifying jQuery" ${JQ_MIN}; \ ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \ @@ -122,7 +93,28 @@ clean: @@echo "Removing built copy of Sizzle" @@rm -f src/selector.js - @@echo "Removing cloned directories" +distclean: clean + @@echo "Removing submodules" @@rm -rf test/qunit src/sizzle -.PHONY: all jquery lint min init jq clean +# change pointers for submodules and update them to what is specified in jQuery +# --merge doesn't work when doing an initial clone, thus test if we have non-existing +# submodules, then do an real update +update_submodules: + @@if [ -d .git ]; then \ + if git submodule status | grep -q -E '^-'; then \ + git submodule update --init --recursive; \ + else \ + git submodule update --init --recursive --merge; \ + fi; \ + fi; + +# update the submodules to the latest at the most logical branch +pull_submodules: + @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" + @@git submodule summary + +pull: pull_submodules + @@git pull ${REMOTE} ${BRANCH} + +.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core diff --git a/src/ajax.js b/src/ajax.js index 4714afda..d94abd6f 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -7,7 +7,7 @@ var r20 = /%20/g, rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, // #7653, #8125, #8152: local protocol detection - rlocalProtocol = /(?:^file|^widget|\-extension):$/, + rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/, rnoContent = /^(?:GET|HEAD)$/, rprotocol = /^\/\//, rquery = /\?/, @@ -19,7 +19,7 @@ var r20 = /%20/g, rucHeadersFunc = function( _, $1, $2 ) { return $1 + $2.toUpperCase(); }, - rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/, + rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/, // Keep a copy of the old load method _load = jQuery.fn.load, @@ -61,7 +61,7 @@ try { } // Segment location into parts -ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ); +ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport function addToPrefiltersOrTransports( structure ) { @@ -319,7 +319,6 @@ jQuery.extend({ cache: null, traditional: false, headers: {}, - crossDomain: null, */ accepts: { @@ -604,7 +603,7 @@ jQuery.extend({ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax ); // Determine if a cross-domain request is in order - if ( !s.crossDomain ) { + if ( s.crossDomain == null ) { parts = rurl.exec( s.url.toLowerCase() ); s.crossDomain = !!( parts && ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] || diff --git a/src/attributes.js b/src/attributes.js index e5425a05..f7c2e981 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -6,7 +6,8 @@ var rclass = /[\n\t\r]/g, rtype = /^(?:button|input)$/i, rfocusable = /^(?:button|input|object|select|textarea)$/i, rclickable = /^a(?:rea)?$/i, - rradiocheck = /^(?:radio|checkbox)$/i; + rradiocheck = /^(?:radio|checkbox)$/i, + formHook; jQuery.fn.extend({ attr: function( name, value ) { @@ -15,9 +16,21 @@ jQuery.fn.extend({ removeAttr: function( name ) { return this.each(function() { - if ( this.nodeType === 1 ) { - this.removeAttribute( name ); - } + jQuery.removeAttr( this, name ); + }); + }, + + prop: function( name, value ) { + return jQuery.access( this, name, value, true, jQuery.prop ); + }, + + removeProp: function( name ) { + return this.each(function() { + // try/catch handles cases where IE balks (such as removing a property on window) + try { + this[ name ] = undefined; + delete this[ name ]; + } catch( e ) {} }); }, @@ -36,10 +49,10 @@ jQuery.fn.extend({ }, addClass: function( value ) { - if ( jQuery.isFunction(value) ) { + if ( jQuery.isFunction( value ) ) { return this.each(function(i) { var self = jQuery(this); - self.addClass( value.call(this, i, self.attr("class")) ); + self.addClass( value.call(this, i, self.attr("class") || "") ); }); } @@ -275,80 +288,79 @@ jQuery.extend({ offset: true }, - // TODO: Check to see if any of these are needed anymore? - // If not, it may be good to standardize on all-lowercase names instead attrFix: { - "for": "htmlFor", - "class": "className", - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing", - rowspan: "rowSpan", - colspan: "colSpan", + // Always normalize to ensure hook usage tabindex: "tabIndex", - usemap: "useMap", - frameborder: "frameBorder" + readonly: "readOnly" }, - + attr: function( elem, name, value, pass ) { + var nType = elem.nodeType; + // don't get/set attributes on text, comment and attribute nodes - if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || elem.nodeType === 2 ) { + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { return undefined; } if ( pass && name in jQuery.attrFn ) { - return jQuery(elem)[name](value); + return jQuery( elem )[ name ]( value ); } - - var ret, - notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ), - hooks; - - // Try to normalize/fix the name + + var ret, hooks, + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + // Normalize the name if needed name = notxml && jQuery.attrFix[ name ] || name; - - hooks = jQuery.attrHooks[ name ]; - + + // Get the appropriate hook, or the formHook + // if getSetAttribute is not supported and we have form objects in IE6/7 + hooks = jQuery.attrHooks[ name ] || ( elem.nodeName === "FORM" && formHook ); + if ( value !== undefined ) { - - if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value )) !== undefined ) { + + if ( value === null ) { + jQuery.removeAttr( elem, name ); + return undefined; + + } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) { return ret; - + } else { - // convert the value to a string (all browsers do this but IE) see #1070 - value = "" + value; - - elem.setAttribute( name, value ); - + elem.setAttribute( name, "" + value ); return value; } - - } else { - - if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem )) !== undefined ) { - return ret; - - } else { - - if ( !jQuery.hasAttr( elem, name ) ) { - return undefined; - } - var attr = elem.getAttribute( name ); + } else { + + if ( hooks && "get" in hooks && notxml ) { + return hooks.get( elem, name ); + + } else { + + ret = elem.getAttribute( name ); // Non-existent attributes return null, we normalize to undefined - return attr === null ? + return ret === null ? undefined : - attr; + ret; } } }, - hasAttr: function( elem, name ) { - // Blackberry 4.7 returns "" from getAttribute #6938 - return elem.attributes[ name ] || (elem.hasAttribute && elem.hasAttribute( name )); + removeAttr: function( elem, name ) { + if ( elem.nodeType === 1 ) { + name = jQuery.attrFix[ name ] || name; + + if ( jQuery.support.getSetAttribute ) { + // Use removeAttribute in browsers that support it + elem.removeAttribute( name ); + } else { + jQuery.attr( elem, name, "" ); + elem.removeAttributeNode( elem.getAttributeNode( name ) ); + } + } }, - + attrHooks: { type: { set: function( elem, value ) { @@ -358,15 +370,14 @@ jQuery.extend({ } } }, - - // 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/ tabIndex: { get: function( elem ) { - var attributeNode = elem.getAttributeNode( "tabIndex" ); + // 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/ + var attributeNode = elem.getAttributeNode("tabIndex"); return attributeNode && attributeNode.specified ? - attributeNode.value : + parseInt( attributeNode.value, 10 ) : rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? 0 : undefined; @@ -374,11 +385,18 @@ jQuery.extend({ } }, - // TODO: Check to see if we really need any here. propFix: {}, prop: function( elem, name, value ) { - var ret, hooks; + var nType = elem.nodeType; + + // don't get/set properties on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return undefined; + } + + var ret, hooks, + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); // Try to normalize/fix the name name = notxml && jQuery.propFix[ name ] || name; @@ -386,7 +404,7 @@ jQuery.extend({ hooks = jQuery.propHooks[ name ]; if ( value !== undefined ) { - if ( hooks && "set" in hooks && (ret = hooks.set( elem, value )) !== undefined ) { + if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { return ret; } else { @@ -394,7 +412,7 @@ jQuery.extend({ } } else { - if ( hooks && "get" in hooks && (ret = hooks.get( elem )) !== undefined ) { + if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== undefined ) { return ret; } else { @@ -406,12 +424,73 @@ jQuery.extend({ propHooks: {} }); +// IE6/7 do not support getting/setting some attributes with get/setAttribute +if ( !jQuery.support.getSetAttribute ) { + jQuery.attrFix = jQuery.extend( jQuery.attrFix, { + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder" + }); + + // Use this for any attribute on a form in IE6/7 + // And the name attribute + formHook = jQuery.attrHooks.name = { + get: function( elem, name ) { + var ret = elem.getAttributeNode( name ); + // Return undefined if not specified instead of empty string + return ret && ret.specified ? + ret.nodeValue : + undefined; + }, + set: function( elem, value, name ) { + // Check form objects in IE (multiple bugs related) + // Only use nodeValue if the attribute node exists on the form + var ret = elem.getAttributeNode( name ); + if ( ret ) { + ret.nodeValue = value; + return value; + } + } + }; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }); + }); +} + +// Remove certain attrs if set to false +jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === false ) { + jQuery.removeAttr( elem, name ); + return value; + } + } + }); +}); + // Some attributes require a special call on IE if ( !jQuery.support.hrefNormalized ) { - jQuery.each([ "href", "src", "style" ], function( i, name ) { + jQuery.each([ "href", "src", "width", "height", "list" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { get: function( elem ) { - return elem.getAttribute( name, 2 ); + var ret = elem.getAttribute( name, 2 ); + return ret === null ? undefined : ret; } }); }); @@ -420,9 +499,10 @@ if ( !jQuery.support.hrefNormalized ) { if ( !jQuery.support.style ) { jQuery.attrHooks.style = { get: function( elem ) { - return elem.style.cssText; + // Return undefined in the case of empty string + // Normalize to lowercase since IE uppercases css property names + return elem.style.cssText.toLowerCase() || undefined; }, - set: function( elem, value ) { return (elem.style.cssText = "" + value); } @@ -432,10 +512,10 @@ if ( !jQuery.support.style ) { // Safari mis-reports the default selected property of an option // Accessing the parent's selectedIndex property fixes it if ( !jQuery.support.optSelected ) { - jQuery.attrHooks.selected = { + jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, { get: function( elem ) { var parent = elem.parentNode; - + if ( parent ) { parent.selectedIndex; @@ -445,7 +525,7 @@ if ( !jQuery.support.optSelected ) { } } } - }; + }); } })( jQuery ); diff --git a/src/core.js b/src/core.js index 9312ee28..6b00a015 100644 --- a/src/core.js +++ b/src/core.js @@ -894,4 +894,4 @@ function doScrollCheck() { // Expose jQuery to the global object return jQuery; -})(); +})(); \ No newline at end of file diff --git a/src/css.js b/src/css.js index 8a982312..17ac136b 100644 --- a/src/css.js +++ b/src/css.js @@ -3,7 +3,8 @@ var ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, rdashAlpha = /-([a-z])/ig, - rupper = /([A-Z])/g, + // fixed for IE9, see #8346 + rupper = /([A-Z]|^ms)/g, rnumpx = /^-?\d+(?:px)?$/i, rnum = /^-?\d/, @@ -240,6 +241,28 @@ if ( !jQuery.support.opacity ) { }; } +jQuery(function() { + // This hook cannot be added until DOM ready because the support test + // for it is not run until after DOM ready + if ( !jQuery.support.reliableMarginRight ) { + jQuery.cssHooks.marginRight = { + get: function( elem, computed ) { + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + // Work around by temporarily setting element display to inline-block + var ret; + jQuery.swap( elem, { "display": "inline-block" }, function() { + if ( computed ) { + ret = curCSS( elem, "margin-right", "marginRight" ); + } else { + ret = elem.style.marginRight; + } + }); + return ret; + } + }; + } +}); + if ( document.defaultView && document.defaultView.getComputedStyle ) { getComputedStyle = function( elem, newName, name ) { var ret, defaultView, computedStyle; diff --git a/src/deferred.js b/src/deferred.js index f0d7c08c..90f9c808 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -144,7 +144,10 @@ jQuery.extend({ return function( value ) { args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; if ( !( --count ) ) { - deferred.resolveWith( deferred, args ); + // Strange bug in FF4: + // Values changed onto the arguments object sometimes end up as undefined values + // outside the $.when method. Cloning the object into a fresh array solves the issue + deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) ); } }; } diff --git a/src/event.js b/src/event.js index f7e0a08c..bc2cf76e 100644 --- a/src/event.js +++ b/src/event.js @@ -70,10 +70,10 @@ jQuery.event = { } if ( !eventHandle ) { - elemData.handle = eventHandle = function() { + elemData.handle = eventHandle = function( e ) { // Handle the second event of a trigger and when // an event is called after a page has unloaded - return typeof jQuery !== "undefined" && !jQuery.event.triggered ? + return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? jQuery.event.handle.apply( eventHandle.elem, arguments ) : undefined; }; @@ -380,7 +380,7 @@ jQuery.event = { target[ "on" + targetType ] = null; } - jQuery.event.triggered = true; + jQuery.event.triggered = event.type; target[ targetType ](); } @@ -391,7 +391,7 @@ jQuery.event = { target[ "on" + targetType ] = old; } - jQuery.event.triggered = false; + jQuery.event.triggered = undefined; } } }, @@ -661,7 +661,7 @@ var withinElement = function( event ) { // Chrome does something similar, the parentNode property // can be accessed but is null. - if ( parent !== document && !parent.parentNode ) { + if ( parent && parent !== document && !parent.parentNode ) { return; } // Traverse up the tree @@ -868,19 +868,33 @@ function trigger( type, elem, args ) { // Create "bubbling" focus and blur events if ( document.addEventListener ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0; + jQuery.event.special[ fix ] = { setup: function() { - this.addEventListener( orig, handler, true ); + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } }, teardown: function() { - this.removeEventListener( orig, handler, true ); + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); + } } }; - function handler( e ) { - e = jQuery.event.fix( e ); + function handler( donor ) { + // Donor event is always a native one; fix it and switch its type. + // Let focusin/out handler cancel the donor focus/blur event. + var e = jQuery.event.fix( donor ); e.type = fix; - return jQuery.event.handle.call( this, e ); + e.originalEvent = {}; + jQuery.event.trigger( e, null, e.target ); + if ( e.isDefaultPrevented() ) { + donor.preventDefault(); + } } }); } diff --git a/src/manipulation.js b/src/manipulation.js index ba316971..758cdbae 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -261,7 +261,9 @@ jQuery.fn.extend({ } }); } else { - return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); + return this.length ? + this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) : + this; } }, @@ -375,7 +377,7 @@ function cloneCopyEvent( src, dest ) { } } -function cloneFixAttributes(src, dest) { +function cloneFixAttributes( src, dest ) { // We do not need to do anything for non-Elements if ( dest.nodeType !== 1 ) { return; @@ -547,7 +549,8 @@ jQuery.extend({ // Return the cloned set return clone; -}, + }, + clean: function( elems, context, fragment, scripts ) { context = context || document; diff --git a/src/offset.js b/src/offset.js index 1003c400..a0cd7a15 100644 --- a/src/offset.js +++ b/src/offset.js @@ -37,8 +37,8 @@ if ( "getBoundingClientRect" in document.documentElement ) { win = getWindow(doc), clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, - scrollTop = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ), - scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft), + scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop, + scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft, top = box.top + scrollTop - clientTop, left = box.left + scrollLeft - clientLeft; @@ -151,7 +151,6 @@ jQuery.offset = { this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop); body.removeChild( container ); - body = container = innerDiv = checkDiv = table = td = null; jQuery.offset.initialize = jQuery.noop; }, @@ -181,10 +180,10 @@ jQuery.offset = { curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), curCSSLeft = jQuery.css( elem, "left" ), - calculatePosition = (position === "absolute" && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1), + calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1, props = {}, curPosition = {}, curTop, curLeft; - // need to be able to calculate position if either top or left is auto and position is absolute + // need to be able to calculate position if either top or left is auto and position is either absolute or fixed if ( calculatePosition ) { curPosition = curElem.position(); } diff --git a/src/sizzle b/src/sizzle new file mode 160000 index 00000000..f12b9309 --- /dev/null +++ b/src/sizzle @@ -0,0 +1 @@ +Subproject commit f12b9309269ba7e705a99efe099f86ed1fe98d58 diff --git a/src/support.js b/src/support.js index 7470b33e..89d2bfea 100644 --- a/src/support.js +++ b/src/support.js @@ -7,8 +7,9 @@ var div = document.createElement("div"); div.style.display = "none"; - div.innerHTML = "
a"; - + div.setAttribute("className", "t"); + div.innerHTML = "
a"; + var all = div.getElementsByTagName("*"), a = div.getElementsByTagName("a")[0], select = document.createElement("select"), @@ -33,8 +34,8 @@ htmlSerialize: !!div.getElementsByTagName("link").length, // Get the style information from getAttribute - // (IE uses .cssText insted) - style: /red/.test( a.getAttribute("style") ), + // (IE uses .cssText instead, and capitalizes all property names) + style: /top/.test( a.getAttribute("style") ), // Make sure that URLs aren't manipulated // (IE normalizes it by default) @@ -57,6 +58,9 @@ // Make sure that a selected-by-default option has a working selected property. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, + + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) + getSetAttribute: div.className !== "t", // Will be defined later deleteExpando: true, @@ -67,7 +71,8 @@ boxModel: null, inlineBlockNeedsLayout: false, shrinkWrapBlocks: false, - reliableHiddenOffsets: true + reliableHiddenOffsets: true, + reliableMarginRight: true }; input.checked = true; @@ -85,15 +90,15 @@ script = document.createElement("script"), id = "script" + jQuery.now(); + // Make sure that the execution of code works by injecting a script + // tag with appendChild/createTextNode + // (IE doesn't support this, fails, and uses .text instead) try { script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); } catch(e) {} root.insertBefore( script, root.firstChild ); - // Make sure that the execution of code works by injecting a script - // tag with appendChild/createTextNode - // (IE doesn't support this, fails, and uses .text instead) if ( window[ id ] ) { _scriptEval = true; delete window[ id ]; @@ -102,8 +107,6 @@ } root.removeChild( script ); - // release memory in IE - root = script = id = null; } return _scriptEval; @@ -188,6 +191,17 @@ jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0; div.innerHTML = ""; + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. For more + // info see bug #3333 + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + if ( document.defaultView && document.defaultView.getComputedStyle ) { + div.style.width = "1px"; + div.style.marginRight = "0"; + jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div, null).marginRight, 10) || 0 ) === 0; + } + body.removeChild( div ).style.display = "none"; div = tds = null; }); @@ -211,8 +225,6 @@ el.setAttribute(eventName, "return;"); isSupported = typeof el[eventName] === "function"; } - el = null; - return isSupported; }; diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index 3181718d..81ba4ca7 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -35,6 +35,7 @@
+

Click the white box to move the marker to it.

diff --git a/test/index.html b/test/index.html index c7c2ae55..a1065508 100644 --- a/test/index.html +++ b/test/index.html @@ -203,6 +203,10 @@ Z + + + +
diff --git a/test/qunit b/test/qunit new file mode 160000 index 00000000..d404faf8 --- /dev/null +++ b/test/qunit @@ -0,0 +1 @@ +Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2a2ac46a..7c572a32 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -492,7 +492,7 @@ test(".ajax() - hash", function() { test("jQuery ajax - cross-domain detection", function() { - expect( 5 ); + expect( 6 ); var loc = document.location, otherPort = loc.port === 666 ? 667 : 666, @@ -508,6 +508,7 @@ test("jQuery ajax - cross-domain detection", function() { }); jQuery.ajax({ + dataType: "jsonp", url: 'app:/path', beforeSend: function( _ , s ) { ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); @@ -533,6 +534,15 @@ test("jQuery ajax - cross-domain detection", function() { } }); + jQuery.ajax({ + dataType: "jsonp", + url: "about:blank", + beforeSend: function( _ , s ) { + ok( s.crossDomain , "Test about:blank is detected as cross-domain" ); + return false; + } + }); + jQuery.ajax({ dataType: "jsonp", url: loc.protocol + "//" + loc.host, diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 8cf47bed..fa30ff04 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -3,38 +3,81 @@ module("attributes", { teardown: moduleTeardown }); var bareObj = function(value) { return value; }; var functionReturningObj = function(value) { return (function() { return value; }); }; -test("jQuery.props: itegrity test", function() { - expect(1); +test("jQuery.attrFix integrity test", function() { + expect(1); + + // This must be maintained and equal jQuery.attrFix when appropriate + // Ensure that accidental or erroneous property + // overwrites don't occur + // This is simply for better code coverage and future proofing. + var propsShouldBe; + if ( !jQuery.support.getSetAttribute ) { + propsShouldBe = { + tabindex: "tabIndex", + readonly: "readOnly", + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder" + }; + } else { + propsShouldBe = { + tabindex: "tabIndex", + readonly: "readOnly" + }; + } - // This must be maintained and equal jQuery.props - // Ensure that accidental or erroneous property - // overwrites don't occur - // This is simply for better code coverage and future proofing. - var propsShouldBe = { - "for": "htmlFor", - "class": "className", - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing", - rowspan: "rowSpan", - colspan: "colSpan", - tabindex: "tabIndex", - usemap: "useMap", - frameborder: "frameBorder" - }; - - same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check"); + same(propsShouldBe, jQuery.attrFix, "jQuery.attrFix passes integrity check"); +}); +test("prop(String, Object)", function() { + expect(19); + equals( jQuery('#text1').prop('value'), "Test", 'Check for value attribute' ); + equals( jQuery('#text1').prop('value', "Test2").prop('defaultValue'), "Test", 'Check for defaultValue attribute' ); + equals( jQuery('#select2').prop('selectedIndex'), 3, 'Check for selectedIndex attribute' ); + equals( jQuery('#foo').prop('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' ); + equals( jQuery('#foo').prop('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' ); + equals( jQuery("