Skip to content

Commit

Permalink
Fix #11857. Modularize css.js, add dependency management. Closes gh-816.
Browse files Browse the repository at this point in the history
See the pull request for more info on the dependency management details.
  • Loading branch information
mikesherov authored and dmethvin committed Jun 11, 2012
1 parent 1bb1432 commit 5f35b3d
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 86 deletions.
68 changes: 53 additions & 15 deletions grunt.js
Expand Up @@ -63,14 +63,14 @@ module.exports = function( grunt ) {
"src/selector.js", "src/selector.js",
"src/traversing.js", "src/traversing.js",
"src/manipulation.js", "src/manipulation.js",
"src/css.js", { flag: "css", src: "src/css.js" },
"src/ajax.js", "src/ajax.js",
"src/ajax/jsonp.js", "src/ajax/jsonp.js",
"src/ajax/script.js", "src/ajax/script.js",
"src/ajax/xhr.js", "src/ajax/xhr.js",
{ flag: "effects", src: "src/effects.js" }, { flag: "effects", src: "src/effects.js", needs: ["css"] },
{ flag: "offset", src: "src/offset.js" }, { flag: "offset", src: "src/offset.js", needs: ["css"] },
{ flag: "dimensions", src: "src/dimensions.js" }, { flag: "dimensions", src: "src/dimensions.js", needs: ["css"] },
"src/exports.js", "src/exports.js",
"src/outro.js" "src/outro.js"
] ]
Expand Down Expand Up @@ -187,28 +187,66 @@ module.exports = function( grunt ) {
"Concatenate source (include/exclude modules with +/- flags), embed date/version", "Concatenate source (include/exclude modules with +/- flags), embed date/version",
function() { function() {
// Concat specified files. // Concat specified files.
var compiled = "", var i,
modules = this.flags, compiled = "",
optIn = !modules["*"], modules = this.flags,
name = this.file.dest; optIn = !modules["*"],
name = this.file.dest,
excluded = {},
excluder = function( flag, needsFlag ) {
// explicit > implicit, so set this first and let it be overridden by explicit
if ( optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
excluded[ flag ] = false;
}


if ( excluded[ needsFlag ] || modules[ "-" + flag ] ) {
// explicit exclusion from flag or dependency
excluded[ flag ] = true;
} else if ( modules[ "+" + flag ] && ( excluded[ needsFlag ] === false ) ) {
// explicit inclusion from flag or dependency overriding a weak inclusion
delete excluded[ needsFlag ];
}
};

// figure out which files to exclude based on these rules in this order:
// explicit > implicit (explicit also means a dependency/dependent that was explicit)
// exclude > include
// examples:
// *: none (implicit exclude)
// *:* all (implicit include)
// *:*:-effects all except effects (explicit > implicit)
// *:*:-css all except css and it's deps (explicit)
// *:*:-css:+effects all except css and it's deps (explicit exclude from dep. trumps explicit include)
// *:+effects none except effects and it's deps (explicit include from dep. trumps implicit exclude)
this.file.src.forEach(function( filepath ) { this.file.src.forEach(function( filepath ) {
// Include optional modules per build flags; exclusion trumps inclusion
var flag = filepath.flag; var flag = filepath.flag;

if ( flag ) { if ( flag ) {
if ( modules[ "-" + flag ] ||
optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {


log.writeln( "Excluding " + filepath.flag + ": '" + filepath.src + "'." ); excluder(flag);

// check for dependencies
if ( filepath.needs ) {
filepath.needs.forEach(function( needsFlag ) {
excluder( flag, needsFlag );
});
}
}
});

// conditionally concatenate source
this.file.src.forEach(function( filepath ) {
var flag = filepath.flag;
if ( flag ) {
if ( excluded[ flag ] !== undefined ) {
log.writeln( "Excluding " + flag + ": '" + filepath.src + "'." );
return; return;
} }
log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." ); log.writeln( "Including " + flag + ": '" + filepath.src + "'." );
filepath = filepath.src; filepath = filepath.src;
} }


// Unwrap redundant IIFEs
compiled += file.read( filepath ); compiled += file.read( filepath );
//.replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
}); });


// Embed Date // Embed Date
Expand Down
5 changes: 2 additions & 3 deletions test/data/testinit.js
Expand Up @@ -198,9 +198,8 @@ function url( value ) {


function loadFixture() { function loadFixture() {
var src = url("./data/" + fileName + ".html"), var src = url("./data/" + fileName + ".html"),
iframe = jQuery("<iframe />").css({ iframe = jQuery("<iframe />").appendTo("body")[0];
width: 500, height: 500, position: "absolute", top: -600, left: -600, visibility: "hidden" iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
}).appendTo("body")[0];
iframe.contentWindow.location = src; iframe.contentWindow.location = src;
return iframe; return iframe;
} }
Expand Down
25 changes: 15 additions & 10 deletions test/unit/attributes.js
Expand Up @@ -371,10 +371,8 @@ test("attr(jquery_method)", function(){


var $elem = jQuery("<div />"), var $elem = jQuery("<div />"),
elem = $elem[0], elem = $elem[0],
expected = 5, expected = 2,
attrObj = { attrObj = {};
css: { paddingLeft: 1, paddingRight: 1 }
};


if ( jQuery.fn.width ) { if ( jQuery.fn.width ) {
expected += 2; expected += 2;
Expand All @@ -386,6 +384,11 @@ test("attr(jquery_method)", function(){
attrObj.offset = { top: 1, left: 0 }; attrObj.offset = { top: 1, left: 0 };
} }


if ( jQuery.css ) {
expected += 3;
attrObj.css = { paddingLeft: 1, paddingRight: 1 };
}

expect( expected ); expect( expected );


// one at a time // one at a time
Expand All @@ -395,9 +398,6 @@ test("attr(jquery_method)", function(){
$elem.attr( { text: "bar" }, true ); $elem.attr( { text: "bar" }, true );
equal( elem.innerHTML, "bar", "attr(text)" ); equal( elem.innerHTML, "bar", "attr(text)" );


$elem.attr( { css: { color: "red" } }, true );
ok( /^(#ff0000|red)$/i.test( elem.style.color ), "attr(css)" );

// Multiple attributes // Multiple attributes
$elem.attr( attrObj, true ); $elem.attr( attrObj, true );


Expand All @@ -415,8 +415,13 @@ test("attr(jquery_method)", function(){
equal( elem.style.left, "1px", "attr(offset)" ); equal( elem.style.left, "1px", "attr(offset)" );
} }


equal( elem.style.paddingLeft, "1px", "attr({css:})" ); if ( jQuery.css ) {
equal( elem.style.paddingRight, "1px", "attr({css:})" ); equal( elem.style.paddingLeft, "1px", "attr({css:})" );
equal( elem.style.paddingRight, "1px", "attr({css:})" );

$elem.attr( { css: { color: "red" } }, true );
ok( /^(#ff0000|red)$/i.test( elem.style.color ), "attr(css)" );
}
}); });


test("attr(String, Object) - Loaded via XML document", function() { test("attr(String, Object) - Loaded via XML document", function() {
Expand Down Expand Up @@ -494,7 +499,7 @@ test("removeAttr(String)", function() {
equal( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" ); equal( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
equal( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" ); equal( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
equal( jQuery("<div style='position: absolute'></div>").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" ); equal( jQuery("<div style='position: absolute'></div>").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" );
equal( jQuery("#fx-test-group").attr("height", "3px").removeAttr("height").css("height"), "1px", "Removing height attribute has no effect on height set with style attribute" ); equal( jQuery("#fx-test-group").attr("height", "3px").removeAttr("height").get(0).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );


jQuery("#check1").removeAttr("checked").prop("checked", true).removeAttr("checked"); jQuery("#check1").removeAttr("checked").prop("checked", true).removeAttr("checked");
equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" ); equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" );
Expand Down
15 changes: 11 additions & 4 deletions test/unit/core.js
Expand Up @@ -27,9 +27,8 @@ test("jQuery()", function() {
div = jQuery("<div/><hr/><code/><b/>"), div = jQuery("<div/><hr/><code/><b/>"),
exec = false, exec = false,
long = "", long = "",
expected = 28, expected = 26,
attrObj = { attrObj = {
css: { paddingLeft: 1, paddingRight: 1 },
click: function() { ok( exec, "Click executed." ); }, click: function() { ok( exec, "Click executed." ); },
text: "test", text: "test",
"class": "test2", "class": "test2",
Expand All @@ -46,6 +45,11 @@ test("jQuery()", function() {
attrObj.offset = { top: 1, left: 1 }; attrObj.offset = { top: 1, left: 1 };
} }


if ( jQuery.css ) {
expected += 2;
attrObj.css = { paddingLeft: 1, paddingRight: 1 };
}

expect( expected ); expect( expected );


// Basic constructor's behavior // Basic constructor's behavior
Expand Down Expand Up @@ -103,8 +107,11 @@ test("jQuery()", function() {
equal( elem[0].style.top, "1px", "jQuery() quick setter offset"); equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
} }


equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); if ( jQuery.css ) {
equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
}

equal( elem[0].childNodes.length, 1, "jQuery quick setter text"); equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
equal( elem[0].className, "test2", "jQuery() quick setter class"); equal( elem[0].className, "test2", "jQuery() quick setter class");
Expand Down
4 changes: 4 additions & 0 deletions test/unit/css.js
@@ -1,3 +1,5 @@
if ( jQuery.css ) {

module("css", { teardown: moduleTeardown }); module("css", { teardown: moduleTeardown });


test("css(String|Hash)", function() { test("css(String|Hash)", function() {
Expand Down Expand Up @@ -779,3 +781,5 @@ test( "cssHooks - expand", function() {
}); });


}); });

}
10 changes: 7 additions & 3 deletions test/unit/event.js
Expand Up @@ -1020,9 +1020,11 @@ test("trigger(type, [data], [fn])", function() {
// Triggers 5 // Triggers 5
equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" ); equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );


var pass = true; var pass = true, elem2;
try { try {
jQuery("#form input:first").hide().trigger("focus"); elem2 = jQuery("#form input:first");
elem2.get(0).style.display = "none";
elem2.trigger("focus");
} catch(e) { } catch(e) {
pass = false; pass = false;
} }
Expand Down Expand Up @@ -1133,9 +1135,11 @@ test( "change event bubbles on copied forms (#11796)", function(){
test("trigger(eventObject, [data], [fn])", function() { test("trigger(eventObject, [data], [fn])", function() {
expect(28); expect(28);


var $parent = jQuery("<div id='par' />").hide().appendTo("body"), var $parent = jQuery("<div id='par' />").appendTo("body"),
$child = jQuery("<p id='child'>foo</p>").appendTo( $parent ); $child = jQuery("<p id='child'>foo</p>").appendTo( $parent );


$parent.get( 0 ).style.display = "none";

var event = jQuery.Event("noNew"); var event = jQuery.Event("noNew");
ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" ); ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
equal( event.type, "noNew", "Verify its type" ); equal( event.type, "noNew", "Verify its type" );
Expand Down
22 changes: 12 additions & 10 deletions test/unit/manipulation.js
Expand Up @@ -533,19 +533,21 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
var article = jQuery("article"), var article = jQuery("article"),
aside = jQuery("aside"); aside = jQuery("aside");


equal( article.css("fontSize"), "10px", "HTML5 elements are styleable"); equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable");
equal( aside.length, 1, "HTML5 elements do not collapse their children") equal( aside.length, 1, "HTML5 elements do not collapse their children")
}); });


test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () { if ( jQuery.css ) {
expect(1); test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () {
expect(1);


jQuery("#qunit-fixture").append("<article id='article'></article>"); jQuery("#qunit-fixture").append("<article id='article'></article>");
jQuery("#article").append("<section>This section should have a pink background.</section>"); jQuery("#article").append("<section>This section should have a pink background.</section>");


// In IE, the missing background color will claim its value is "transparent" // In IE, the missing background color will claim its value is "transparent"
notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles"); notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles");
}); });
}


test("html5 clone() cannot use the fragment cache in IE (#6485)", function () { test("html5 clone() cannot use the fragment cache in IE (#6485)", function () {
expect(1); expect(1);
Expand Down Expand Up @@ -1653,8 +1655,8 @@ test("jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function


$wraptarget.wrapAll("<aside style='background-color:green'></aside>"); $wraptarget.wrapAll("<aside style='background-color:green'></aside>");


notEqual( $wraptarget.parent("aside").css("background-color"), "transparent", "HTML5 elements created with wrapAll inherit styles" ); notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
notEqual( $section.css("background-color"), "transparent", "HTML5 elements create with jQuery( string ) inherit styles" ); notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
}); });


test("Cloned, detached HTML5 elems (#10667,10670)", function() { test("Cloned, detached HTML5 elems (#10667,10670)", function() {
Expand Down
42 changes: 22 additions & 20 deletions test/unit/selector.js
Expand Up @@ -34,26 +34,28 @@ test("attributes - jQuery only", function() {
t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] ); t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] );
}); });


test("pseudo - visibility", function() { if ( jQuery.css ) {
expect( 9 ); test("pseudo - visibility", function() {

expect( 9 );
t( "Is Visible", "div:visible:not(#qunit-testrunner-toolbar):lt(2)", ["nothiddendiv", "nothiddendivchild"] );
t( "Is Not Hidden", "#qunit-fixture:hidden", [] ); t( "Is Visible", "div:visible:not(#qunit-testrunner-toolbar):lt(2)", ["nothiddendiv", "nothiddendivchild"] );
t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); t( "Is Not Hidden", "#qunit-fixture:hidden", [] );

t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
var $div = jQuery('<div/>').appendTo("body");
$div.css({ fontSize: 0, lineHeight: 0 });// IE also needs to set font-size and line-height to 0 var $div = jQuery('<div/>').appendTo("body");
$div.css( "width", 1 ).css( "height", 0 ); $div.css({ fontSize: 0, lineHeight: 0 });// IE also needs to set font-size and line-height to 0
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); $div.css( "width", 1 ).css( "height", 0 );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
$div.css( "width", 0 ).css( "height", 1 ); t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); $div.css( "width", 0 ).css( "height", 1 );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
$div.css( "width", 1 ).css( "height", 1 ); t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] ); $div.css( "width", 1 ).css( "height", 1 );
t( "Is Not Visible", '#nothiddendivchild:hidden', [] ); t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
$div.remove(); t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
}); $div.remove();
});
}


test("disconnected nodes", function() { test("disconnected nodes", function() {
expect( 4 ); expect( 4 );
Expand Down
44 changes: 23 additions & 21 deletions test/unit/support.js
Expand Up @@ -6,30 +6,32 @@ test("boxModel", function() {
equal( jQuery.support.boxModel, document.compatMode === "CSS1Compat" , "jQuery.support.boxModel is sort of tied to quirks mode but unstable since 1.8" ); equal( jQuery.support.boxModel, document.compatMode === "CSS1Compat" , "jQuery.support.boxModel is sort of tied to quirks mode but unstable since 1.8" );
}); });


testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9238)", "support/bodyBackground", function( color, support ) { if ( jQuery.css ) {
expect( 2 ); testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9238)", "support/bodyBackground", function( color, support ) {
var i, expect( 2 );
passed = true, var i,
okValue = { passed = true,
"#000000": true, okValue = {
"rgb(0, 0, 0)": true "#000000": true,
}; "rgb(0, 0, 0)": true
ok( okValue[ color ], "color was not reset (" + color + ")" ); };
ok( okValue[ color ], "color was not reset (" + color + ")" );


for ( i in jQuery.support ) { for ( i in jQuery.support ) {
if ( jQuery.support[ i ] !== support[ i ] ) { if ( jQuery.support[ i ] !== support[ i ] ) {
passed = false; passed = false;
strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" ); strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
}
} }
} for ( i in support ) {
for ( i in support ) { if ( !( i in jQuery.support ) ) {
if ( !( i in jQuery.support ) ) { passed = false;
passed = false; strictEqual( jQuery.support[ i ], support[ i ], "Unexpected property: " + i );
strictEqual( jQuery.support[ i ], support[ i ], "Unexpected property: " + i ); }
} }
} ok( passed, "Same support properties" );
ok( passed, "Same support properties" ); });
}); }


testIframeWithCallback( "A background on the testElement does not cause IE8 to crash (#9823)", "support/testElementCrash", function() { testIframeWithCallback( "A background on the testElement does not cause IE8 to crash (#9823)", "support/testElementCrash", function() {
expect(1); expect(1);
Expand Down

0 comments on commit 5f35b3d

Please sign in to comment.