Skip to content
Permalink
Browse files

Fix #11767. Modularize build and unit tests for exluding effects.

Closes gh-785. To build a version of jQuery without effects, use `grunt build:*:*:-effects`. The unit tests feature-check for the interfaces and skip the unit tests for effects if they don't detect it.
  • Loading branch information...
gibson042 authored and dmethvin committed May 29, 2012
1 parent 82d4c72 commit 7f2cc46955b35dc3d5a0526d0cb038d4a50b936b
Showing with 434 additions and 320 deletions.
  1. +0 −1 .gitignore
  2. +44 −25 grunt.js
  3. +124 −10 src/css.js
  4. +15 −126 src/effects.js
  5. +1 −1 src/sizzle
  6. +1 −1 test/data/testinit.js
  7. +176 −8 test/unit/css.js
  8. +14 −94 test/unit/effects.js
  9. +59 −54 test/unit/queue.js
@@ -7,6 +7,5 @@ dist
*.patch
/*.html
.DS_Store
dist/.sizecache.json
build/.sizecache.json
node_modules
@@ -50,7 +50,7 @@ module.exports = function( grunt ) {
"src/ajax/jsonp.js",
"src/ajax/script.js",
"src/ajax/xhr.js",
"src/effects.js",
{ flag: "effects", src: "src/effects.js" },
"src/offset.js",
"src/dimensions.js",
"src/exports.js",
@@ -103,7 +103,7 @@ module.exports = function( grunt ) {
});

// Default grunt.
grunt.registerTask( "default", "selector build lint min compare_size" );
grunt.registerTask( "default", "selector build:*:* lint min compare_size" );

grunt.loadNpmTasks("grunt-compare-size");

@@ -159,29 +159,48 @@ module.exports = function( grunt ) {


// Special concat/build task to handle various jQuery build requirements
grunt.registerMultiTask( "build", "Concatenate source, embed date/version", function() {
// Concat specified files.
var compiled = "",
name = this.file.dest;
grunt.registerMultiTask(
"build",
"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;

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 + "'." );
return;
}
log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." );
filepath = filepath.src;
}

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

// Embed Date
// Embed Version
compiled = compiled.replace( "@DATE", new Date() )
.replace( "@VERSION", config("pkg.version") );

// Write concatenated source to file
file.write( name, compiled );

// Fail task if errors were logged.
if ( this.errorCount ) {
return false;
}

this.file.src.forEach(function( filepath ) {
compiled += file.read( filepath ).replace( /.function..jQuery...\{/g, "" ).replace( /\}...jQuery..;/g, "" );
// Otherwise, print a success message.
log.writeln( "File '" + name + "' created." );
});

// Embed Date
// Embed Version
compiled = compiled.replace( "@DATE", new Date() )
.replace( "@VERSION", config("pkg.version") );

// Write concatenated source to file
file.write( name, compiled );

// Fail task if errors were logged.
if ( this.errorCount ) {
return false;
}

// Otherwise, print a success message.
log.writeln( "File '" + name + "' created." );
});
};
@@ -3,22 +3,23 @@
// order is important!
jQuery.cssExpand = [ "Top", "Right", "Bottom", "Left" ];

var ralpha = /alpha\([^)]*\)/i,
var curCSS, iframe, iframeDoc,
ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/,
// fixed for IE9, see #8346
rupper = /([A-Z]|^ms)/g,
rnumsplit = /^([\-+]?(?:\d*\.)?\d+)(.*)$/i,
rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
rrelNum = /^([\-+])=([\-+.\de]+)/,
rmargin = /^margin/,

elemdisplay = {},
cssShow = { position: "absolute", visibility: "hidden", display: "block" },

cssExpand = jQuery.cssExpand,
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
rposition = /^(top|right|bottom|left)$/,

curCSS;
eventsToggle = jQuery.fn.toggle;

// return a css property mapped to a potentially vendor prefixed property
function vendorPropName( style, name ) {
@@ -43,13 +44,83 @@ function vendorPropName( style, name ) {
return origName;
}

jQuery.fn.css = function( name, value ) {
return jQuery.access( this, function( elem, name, value ) {
return value !== undefined ?
jQuery.style( elem, name, value ) :
jQuery.css( elem, name );
}, name, value, arguments.length > 1 );
};
function showHide( elements, show ) {
var elem, display,
values = [],
index = 0,
length = elements.length;

for ( ; index < length; index++ ) {
elem = elements[ index ];
if ( !elem.style ) {
continue;
}
values[ index ] = jQuery._data( elem, "olddisplay" );
if ( show ) {
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !values[ index ] && elem.style.display === "none" ) {
elem.style.display = "";
}

// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( (elem.style.display === "" && curCSS( elem, "display" ) === "none") ||
!jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
values[ index ] = jQuery._data( elem, "olddisplay", jQuery.defaultDisplay(elem.nodeName) );
}
} else {
display = curCSS( elem, "display" );

if ( !values[ index ] && display !== "none" ) {
jQuery._data( elem, "olddisplay", display );
}
}
}

// Set the display of most of the elements in a second loop
// to avoid the constant reflow
for ( index = 0; index < length; index++ ) {
elem = elements[ index ];
if ( !elem.style ) {
continue;
}
if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
elem.style.display = show ? values[ index ] || "" : "none";
}
}

return elements;
}

jQuery.fn.extend({
css: function( name, value ) {
return jQuery.access( this, function( elem, name, value ) {
return value !== undefined ?
jQuery.style( elem, name, value ) :
jQuery.css( elem, name );
}, name, value, arguments.length > 1 );
},
show: function() {
return showHide( this, true );
},
hide: function() {
return showHide( this );
},
toggle: function( fn, fn2 ) {
var bool = typeof fn === "boolean";

if ( jQuery.isFunction( fn ) && jQuery.isFunction( fn2 ) ) {
return eventsToggle.apply( this, arguments );
}

return this.each(function() {
var state = bool ? fn : jQuery( this ).is(":hidden");
showHide([ this ], state );
});
}
});

jQuery.extend({
// Add in style property hooks for overriding the default
@@ -200,6 +271,49 @@ jQuery.extend({
}

return ret;
},

// Try to determine the default display value of an element
defaultDisplay: function( nodeName ) {
if ( elemdisplay[ nodeName ] ) {
return elemdisplay[ nodeName ];
}

var elem = jQuery( "<" + nodeName + ">" ).appendTo( document.body ),
display = elem.css("display");
elem.remove();

// If the simple way fails,
// get element's real default display by attaching it to a temp iframe
if ( display === "none" || display === "" ) {
// Use the already-created iframe if possible
iframe = document.body.appendChild(
iframe || jQuery.extend( document.createElement("iframe"), {
frameBorder: 0,
width: 0,
height: 0
})
);

// Create a cacheable copy of the iframe document on first call.
// IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML
// document to it; WebKit & Firefox won't allow reusing the iframe document.
if ( !iframeDoc || !iframe.createElement ) {
iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
iframeDoc.write("<!doctype html><html><body>");
iframeDoc.close();
}

elem = iframeDoc.body.appendChild( iframeDoc.createElement(nodeName) );

display = curCSS( elem, "display" );
document.body.removeChild( iframe );
}

// Store the correct default display
elemdisplay[ nodeName ] = display;

return display;
}
});

Oops, something went wrong.

0 comments on commit 7f2cc46

Please sign in to comment.
You can’t perform that action at this time.