]> source.dussan.org Git - jquery.git/commitdiff
Fix #11857. Modularize css.js, add dependency management. Closes gh-816.
authorMike Sherov <mike.sherov@gmail.com>
Mon, 11 Jun 2012 01:54:16 +0000 (21:54 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 11 Jun 2012 01:54:16 +0000 (21:54 -0400)
See the pull request for more info on the dependency management details.

grunt.js
test/data/testinit.js
test/unit/attributes.js
test/unit/core.js
test/unit/css.js
test/unit/event.js
test/unit/manipulation.js
test/unit/selector.js
test/unit/support.js

index d3e0c7f6a79a564dce060d3ae0abdcd69b24cceb..062ce837d229ddb8e9bd440d8dd6a1861a94a250 100644 (file)
--- a/grunt.js
+++ b/grunt.js
@@ -63,14 +63,14 @@ module.exports = function( grunt ) {
                                "src/selector.js",
                                "src/traversing.js",
                                "src/manipulation.js",
-                               "src/css.js",
+                               { flag: "css", src: "src/css.js" },
                                "src/ajax.js",
                                "src/ajax/jsonp.js",
                                "src/ajax/script.js",
                                "src/ajax/xhr.js",
-                               { flag: "effects", src: "src/effects.js" },
-                               { flag: "offset", src: "src/offset.js" },
-                               { flag: "dimensions", src: "src/dimensions.js" },
+                               { flag: "effects", src: "src/effects.js", needs: ["css"] },
+                               { flag: "offset", src: "src/offset.js", needs: ["css"] },
+                               { flag: "dimensions", src: "src/dimensions.js", needs: ["css"] },
                                "src/exports.js",
                                "src/outro.js"
                        ]
@@ -187,28 +187,66 @@ module.exports = function( grunt ) {
                "Concatenate source (include/exclude modules with +/- flags), embed date/version",
                function() {
                        // Concat specified files.
-                       var compiled = "",
-                                       modules = this.flags,
-                                       optIn = !modules["*"],
-                                       name = this.file.dest;
+                       var i,
+                               compiled = "",
+                               modules = this.flags,
+                               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 ) {
-                               // Include optional modules per build flags; exclusion trumps inclusion
                                var flag = filepath.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;
                                        }
-                                       log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." );
+                                       log.writeln( "Including " + flag + ": '" + filepath.src + "'." );
                                        filepath = filepath.src;
                                }
 
-                               // Unwrap redundant IIFEs
                                compiled += file.read( filepath );
-                               //.replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
                        });
 
                        // Embed Date
index f2898e0ba2fac43263cd3da0dd72aecd0bb3b908..23bdb9163366452d97d744712d64f4efe2a805d9 100644 (file)
@@ -198,9 +198,8 @@ function url( value ) {
 
                function loadFixture() {
                        var src = url("./data/" + fileName + ".html"),
-                               iframe = jQuery("<iframe />").css({
-                                       width: 500, height: 500, position: "absolute", top: -600, left: -600, visibility: "hidden"
-                               }).appendTo("body")[0];
+                               iframe = jQuery("<iframe />").appendTo("body")[0];
+                               iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;";
                        iframe.contentWindow.location = src;
                        return iframe;
                }
index 33551ba9437965104dc9eab41528edf7ca877b45..6062bc7c9975fbbe272b3ec16edf92118e303545 100644 (file)
@@ -371,10 +371,8 @@ test("attr(jquery_method)", function(){
 
        var $elem = jQuery("<div />"),
                elem = $elem[0],
-               expected = 5,
-               attrObj = {
-                       css: { paddingLeft: 1, paddingRight: 1 }
-               };
+               expected = 2,
+               attrObj = {};
 
        if ( jQuery.fn.width ) {
                expected += 2;
@@ -386,6 +384,11 @@ test("attr(jquery_method)", function(){
                attrObj.offset = { top: 1, left: 0 };
        }
 
+       if ( jQuery.css ) {
+               expected += 3;
+               attrObj.css = { paddingLeft: 1, paddingRight: 1 };
+       }
+
        expect( expected );
 
        // one at a time
@@ -395,9 +398,6 @@ test("attr(jquery_method)", function(){
        $elem.attr( { text: "bar" }, true );
        equal( elem.innerHTML, "bar", "attr(text)" );
 
-       $elem.attr( { css: { color: "red" } }, true );
-       ok( /^(#ff0000|red)$/i.test( elem.style.color ), "attr(css)" );
-
        // Multiple attributes
        $elem.attr( attrObj, true );
 
@@ -415,8 +415,13 @@ test("attr(jquery_method)", function(){
                equal( elem.style.left, "1px", "attr(offset)" );
        }
 
-       equal( elem.style.paddingLeft, "1px", "attr({css:})" );
-       equal( elem.style.paddingRight, "1px", "attr({css:})" );
+       if ( jQuery.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() {
@@ -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("#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("#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");
        equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" );
index 2daf5d24dc5a99308cb3ec5e7f4b66fab07c34ae..88c4701043d72e04474126026ae883b97c158db2 100644 (file)
@@ -27,9 +27,8 @@ test("jQuery()", function() {
                div = jQuery("<div/><hr/><code/><b/>"),
                exec = false,
                long = "",
-               expected = 28,
+               expected = 26,
                attrObj = {
-                       css: { paddingLeft: 1, paddingRight: 1 },
                        click: function() { ok( exec, "Click executed." ); },
                        text: "test",
                        "class": "test2",
@@ -46,6 +45,11 @@ test("jQuery()", function() {
                attrObj.offset = { top: 1, left: 1 };
        }
 
+       if ( jQuery.css ) {
+               expected += 2;
+               attrObj.css = { paddingLeft: 1, paddingRight: 1 };
+       }
+
        expect( expected );
 
        // Basic constructor's behavior
@@ -103,8 +107,11 @@ test("jQuery()", function() {
                equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
        }
 
-       equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
-       equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
+       if ( jQuery.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].firstChild.nodeValue, "test", "jQuery quick setter text");
        equal( elem[0].className, "test2", "jQuery() quick setter class");
index b030569fb94253b4aaa4f645730f342cf1095cdf..ea57c9abee588d8d819031dd70eb06560f5f9ef8 100644 (file)
@@ -1,3 +1,5 @@
+if ( jQuery.css ) {
+
 module("css", { teardown: moduleTeardown });
 
 test("css(String|Hash)", function() {
@@ -779,3 +781,5 @@ test( "cssHooks - expand", function() {
        });
 
 });
+
+}
index db7065fd16f366eca4aa38e1c80b683f6d42bb2a..36cb53aec9e353da91caefff7517bf1b3efe7926 100644 (file)
@@ -1020,9 +1020,11 @@ test("trigger(type, [data], [fn])", function() {
        // Triggers 5
        equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
 
-       var pass = true;
+       var pass = true, elem2;
        try {
-               jQuery("#form input:first").hide().trigger("focus");
+               elem2 = jQuery("#form input:first");
+               elem2.get(0).style.display = "none";
+               elem2.trigger("focus");
        } catch(e) {
                pass = false;
        }
@@ -1133,9 +1135,11 @@ test( "change event bubbles on copied forms (#11796)", function(){
 test("trigger(eventObject, [data], [fn])", function() {
        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 );
 
+       $parent.get( 0 ).style.display = "none";
+
        var event = jQuery.Event("noNew");
        ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
        equal( event.type, "noNew", "Verify its type" );
index 0e419a8bb0cfa4906fd2de881ce36febc825638e..e8c183f3c836f6a014356cd9ba34c610c5994dff 100644 (file)
@@ -533,19 +533,21 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
        var article = jQuery("article"),
        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")
 });
 
-test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () {
-       expect(1);
+if ( jQuery.css ) {
+       test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () {
+               expect(1);
 
-       jQuery("#qunit-fixture").append("<article id='article'></article>");
-       jQuery("#article").append("<section>This section should have a pink background.</section>");
+               jQuery("#qunit-fixture").append("<article id='article'></article>");
+               jQuery("#article").append("<section>This section should have a pink background.</section>");
 
-       // In IE, the missing background color will claim its value is "transparent"
-       notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles");
-});
+               // In IE, the missing background color will claim its value is "transparent"
+               notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles");
+       });
+}
 
 test("html5 clone() cannot use the fragment cache in IE (#6485)", function () {
        expect(1);
@@ -1653,8 +1655,8 @@ test("jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function
 
        $wraptarget.wrapAll("<aside style='background-color:green'></aside>");
 
-       notEqual( $wraptarget.parent("aside").css("background-color"), "transparent", "HTML5 elements created with wrapAll inherit styles" );
-       notEqual( $section.css("background-color"), "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
+       notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll 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() {
index f4a5f4954d9e5813b1095a6b08378c7e5b5c4821..5bea3215eaa4699fb7dd1c1b24e70255adf64032 100644 (file)
@@ -34,26 +34,28 @@ test("attributes - jQuery only", function() {
        t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] );
 });
 
-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 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
-       $div.css( "width", 1 ).css( "height", 0 );
-       t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
-       t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
-       $div.css( "width", 0 ).css( "height", 1 );
-       t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
-       t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
-       $div.css( "width", 1 ).css( "height", 1 );
-       t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
-       t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
-       $div.remove();
-});
+if ( jQuery.css ) {
+       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 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
+               $div.css( "width", 1 ).css( "height", 0 );
+               t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
+               t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
+               $div.css( "width", 0 ).css( "height", 1 );
+               t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
+               t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
+               $div.css( "width", 1 ).css( "height", 1 );
+               t( "Is Visible", '#nothiddendivchild:visible', ['nothiddendivchild'] );
+               t( "Is Not Visible", '#nothiddendivchild:hidden', [] );
+               $div.remove();
+       });
+}
 
 test("disconnected nodes", function() {
        expect( 4 );
index bb488792182139be34fc6904e5c7279316111a79..e733d520d1923b6dbe7b955f26d2efb9573e4277 100644 (file)
@@ -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" );
 });
 
-testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9238)", "support/bodyBackground", function( color, support ) {
-       expect( 2 );
-       var i,
-               passed = true,
-               okValue = {
-                       "#000000": true,
-                       "rgb(0, 0, 0)": true
-               };
-       ok( okValue[ color ], "color was not reset (" + color + ")" );
+if ( jQuery.css ) {
+       testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9238)", "support/bodyBackground", function( color, support ) {
+               expect( 2 );
+               var i,
+                       passed = true,
+                       okValue = {
+                               "#000000": true,
+                               "rgb(0, 0, 0)": true
+                       };
+               ok( okValue[ color ], "color was not reset (" + color + ")" );
 
-       for ( i in jQuery.support ) {
-               if ( jQuery.support[ i ] !== support[ i ] ) {
-                       passed = false;
-                       strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
+               for ( i in jQuery.support ) {
+                       if ( jQuery.support[ i ] !== support[ i ] ) {
+                               passed = false;
+                               strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
+                       }
                }
-       }
-       for ( i in support ) {
-               if ( !( i in jQuery.support ) ) {
-                       passed = false;
-                       strictEqual( jQuery.support[ i ], support[ i ], "Unexpected property: " + i );
+               for ( i in support ) {
+                       if ( !( i in jQuery.support ) ) {
+                               passed = false;
+                               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() {
        expect(1);