From bfbb04cf56c897a5eb997021fc420082ad8d03fc Mon Sep 17 00:00:00 2001 From: Doug Neiner Date: Sun, 7 Mar 2010 15:15:55 -0500 Subject: [PATCH 1/9] Added support for slideToggle to take an optional state parameter By adding the state parameter, slideToggle can now be called in the following ways: slideToggle(); slideToggle(speed); slideToggle(state); slideToggle(callback); slideToggle(speed,callback); slideToggle(state,callback); slideToggle(speed,state,callback); If `state` is `true` then `slideDown` is called. If `state` is `false` then `slideUp` is called. If `state` is not a boolean, then the original `slideToggle` is called. (It was moved to `_slideToggle`) --- src/effects.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/effects.js b/src/effects.js index 97456ccc4b..a7058d492c 100644 --- a/src/effects.js +++ b/src/effects.js @@ -235,7 +235,7 @@ function genFx( type, num ) { jQuery.each({ slideDown: genFx("show", 1), slideUp: genFx("hide", 1), - slideToggle: genFx("toggle", 1), + '_slideToggle': genFx("toggle", 1), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" } }, function( name, props ) { @@ -244,6 +244,23 @@ jQuery.each({ }; }); +jQuery.fn.slideToggle = function( speed, state, callback ) { + if( typeof speed === "boolean" ){ + callback = state; + state = speed; + speed = undefined; + } + if( jQuery.isFunction(state) ){ + callback = state; + state = undefined; + } + if( typeof state === "boolean" ){ + return this[ state ? "slideDown" : "slideUp"](speed, callback); + } else { + return this._slideToggle( speed, callback ); + } +}; + jQuery.extend({ speed: function( speed, easing, fn ) { var opt = speed && typeof speed === "object" ? speed : { From 60658f79ab015380e52cc68159ac641e3abd4693 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Sat, 12 Jun 2010 23:55:49 -0400 Subject: [PATCH 2/9] Updated Rakefile to mirror the functionality of the Makefile The Rakefile now supports all the functionality of the Makefile including only rebuilding files when dependent files change. To see availible tasks, run: rake -T --- Rakefile | 119 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 17 deletions(-) diff --git a/Rakefile b/Rakefile index 71a7067192..5ee4a5ece6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,26 +1,111 @@ -# Basic Rakefile for building jQuery -files = [ "intro", "core", "support", "data", "queue", "event", "selector", "traversing", "attributes", "manipulation", "css", "ajax", "effects", "offset", "dimensions", "outro" ] +prefix = File.dirname( __FILE__ ) -date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.gsub(/\n/, "") -version = `cat version.txt`.gsub(/\n/, "") +# Directory variables +src_dir = File.join( prefix, 'src' ) +build_dir = File.join( prefix, 'build' ) +test_dir = File.join( prefix, 'test' ) -task :default => :jquery +# A different destination directory can be set by +# setting DIST_DIR before calling rake +dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' ) -task :init do - sh "if test ! -d test/qunit; then git clone git://github.com/jquery/qunit.git test/qunit; fi" - sh "if test ! -d src/sizzle; then git clone git://github.com/jeresig/sizzle.git src/sizzle; fi" - sh "cd src/sizzle && git pull origin master &> /dev/null" - sh "cd test/qunit && git pull origin master &> /dev/null" +base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) } + +# Sizzle, QUnit and jQuery files/dirs +sizzle_dir = File.join( src_dir, "sizzle" ) +sizzle = File.join( sizzle_dir, "sizzle.js" ) +selector = File.join( src_dir, "selector.js" ) + +qunit_dir = File.join( test_dir, "qunit" ) +qunit = File.join( qunit_dir, "qunit", "qunit.js" ) + +jq = File.join( dist_dir, "jquery.js" ) +jq_min = File.join( dist_dir, "jquery.min.js" ) + +# General Variables +date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.strip +version = File.read( File.join( prefix, 'version.txt' ) ).strip + +# Build tools +rhino = "java -jar #{build_dir}/js.jar" +minfier = "java -jar #{build_dir}/google-compiler-20091218.jar" + +# Turn off output other than needed from `sh` and file commands +verbose(false) + + +# Tasks +task :default => "jquery" + +desc "Builds jQuery; Tests with JSLint; Minifies jQuery" +task :all => [:jquery, :lint, :min] do + puts "jQuery build complete." +end + +desc "Builds jQuery: jquery.js (Default task)" +task :jquery => [:selector, jq] + +desc "Builds a minified version of jQuery: jquery.min.js" +task :min => jq_min + + +task :init => [sizzle, qunit] do + puts "Updating SizzleJS with latest..." + sh "cd #{sizzle_dir} && git pull origin master &> /dev/null" + + puts "Updating QUnit with latest..." + sh "cd #{qunit_dir} && git pull origin master &> /dev/null" end -task :jquery => [:init, :selector] do - sh "mkdir -p dist" +desc "Removes dist folder, selector.js, and Sizzle/QUnit" +task :clean do + puts "Removing Distribution directory: #{dist_dir}..." + rm_r dist_dir + + puts "Removing built copy of Sizzle..." + rm_r selector + + puts "Removing cloned directories..." + rm_r qunit_dir + rm_r sizzle_dir +end + +desc "Rebuilds selector.js from SizzleJS" +task :selector => [:init, selector] + +desc "Tests built jquery.js against JSLint" +task :lint => jq do + puts "Checking jQuery against JSLint..." + sh "#{rhino} #{build_dir}/jslint-check.js" +end + + +# File and Directory Dependencies +directory dist_dir + +file jq => [dist_dir, base_files].flatten do + puts "Building jquery.js..." + sh "cat #{base_files.join(' ')} | sed 's/Date:./&#{date}/' | sed s/@VERSION/#{version}/ > #{jq}" +end + +file jq_min => jq do + puts "Building jquery.min.js..." + + sh "head -15 #{jq} > #{jq_min}" + sh "#{minfier} --js #{jq} --warning_level QUIET >> #{jq_min}" +end + +file selector => [sizzle] do + puts "Building selector code from Sizzle..." + sh "sed '/EXPOSE/r #{src_dir}/sizzle-jquery.js' #{sizzle} > #{selector}" +end - sh "cat " + files.map {|file| "src/" + file + ".js"}.join(" ") + - " | sed 's/Date:./&" + date + "/' | " + - " sed s/@VERSION/" + version + "/ > dist/jquery.js" +file sizzle do + puts "Retrieving SizzleJS from Github..." + sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}" end -task :selector do - sh "sed '/EXPOSE/r src/sizzle-jquery.js' src/sizzle/sizzle.js > src/selector.js" +file qunit do + puts "Retrieving SizzleJS from Github..." + sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}" end From 7957131f719e488264c461a4679db3deff52c51e Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 02:05:06 -0400 Subject: [PATCH 3/9] Updated Rakefile to remove use of *nix specific commands Only `sh` statements left are either 'java' or 'git' commands, which should work on Windows, though I still need to test --- Rakefile | 57 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/Rakefile b/Rakefile index 5ee4a5ece6..74acf42329 100644 --- a/Rakefile +++ b/Rakefile @@ -23,7 +23,7 @@ jq = File.join( dist_dir, "jquery.js" ) jq_min = File.join( dist_dir, "jquery.min.js" ) # General Variables -date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.strip +date = `git log -1`[/^Date:\s+(.+)$/, 1] version = File.read( File.join( prefix, 'version.txt' ) ).strip # Build tools @@ -33,7 +33,6 @@ minfier = "java -jar #{build_dir}/google-compiler-20091218.jar" # Turn off output other than needed from `sh` and file commands verbose(false) - # Tasks task :default => "jquery" @@ -50,24 +49,27 @@ task :min => jq_min task :init => [sizzle, qunit] do + sizzle_git = File.join(sizzle_dir, '.git') + qunit_git = File.join(qunit_dir, '.git') + puts "Updating SizzleJS with latest..." - sh "cd #{sizzle_dir} && git pull origin master &> /dev/null" + sh "git --git-dir=#{sizzle_git} pull -q origin master" puts "Updating QUnit with latest..." - sh "cd #{qunit_dir} && git pull origin master &> /dev/null" + sh "git --git-dir=#{qunit_git} pull -q origin master" end desc "Removes dist folder, selector.js, and Sizzle/QUnit" task :clean do puts "Removing Distribution directory: #{dist_dir}..." - rm_r dist_dir + rm_r dist_dir, :force => true puts "Removing built copy of Sizzle..." - rm_r selector + rm_r selector, :force => true puts "Removing cloned directories..." - rm_r qunit_dir - rm_r sizzle_dir + rm_r qunit_dir, :force => true + rm_r sizzle_dir, :force => true end desc "Rebuilds selector.js from SizzleJS" @@ -76,7 +78,7 @@ task :selector => [:init, selector] desc "Tests built jquery.js against JSLint" task :lint => jq do puts "Checking jQuery against JSLint..." - sh "#{rhino} #{build_dir}/jslint-check.js" + sh "#{rhino} " + File.join(build_dir, 'jslint-check.js') end @@ -85,19 +87,37 @@ directory dist_dir file jq => [dist_dir, base_files].flatten do puts "Building jquery.js..." - sh "cat #{base_files.join(' ')} | sed 's/Date:./&#{date}/' | sed s/@VERSION/#{version}/ > #{jq}" + + File.open(jq, 'w') do |f| + f.write cat(base_files).gsub(/(Date:.)/, "\\1#{date}" ).gsub(/@VERSION/, version) + end end file jq_min => jq do puts "Building jquery.min.js..." - sh "head -15 #{jq} > #{jq_min}" - sh "#{minfier} --js #{jq} --warning_level QUIET >> #{jq_min}" + sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}" + + min = File.read( jq_min ) + + # Equivilent of "head" + File.open(jq_min, 'w') do |f| + f.write File.readlines(jq)[0..14].join() + f.write min + end end -file selector => [sizzle] do +file selector => [sizzle, :init] do puts "Building selector code from Sizzle..." - sh "sed '/EXPOSE/r #{src_dir}/sizzle-jquery.js' #{sizzle} > #{selector}" + + File.open(selector, 'w') do |f| + f.write File.read(sizzle).gsub( + /^.+EXPOSE$\n/, + '\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' )) + ).gsub( + /^window.Sizzle.+$\n/, '' + ) + end end file sizzle do @@ -106,6 +126,13 @@ file sizzle do end file qunit do - puts "Retrieving SizzleJS from Github..." + puts "Retrieving QUnity from Github..." sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}" end + + +def cat( files ) + files.map do |file| + File.read(file) + end.join('') +end \ No newline at end of file From cc661f094e9f0590c58b5052ca74a833673784a1 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 02:07:21 -0400 Subject: [PATCH 4/9] Fixed spelling on QUnit pull message --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 74acf42329..790b5f3f00 100644 --- a/Rakefile +++ b/Rakefile @@ -126,7 +126,7 @@ file sizzle do end file qunit do - puts "Retrieving QUnity from Github..." + puts "Retrieving QUnit from Github..." sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}" end From 5cda32b57a47fc158491e3c2a0ab69fb53acbec8 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 11:17:13 -0400 Subject: [PATCH 5/9] Updated README file with updated information for the Rake addtions Also changed the default Rake task to "all" instead of "jquery" to parallel the Makefile. --- README.md | 61 +++++++++++++++++++++++++++++++++++++++---------------- Rakefile | 2 +- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7b794af6ad..3f4f258b65 100644 --- a/README.md +++ b/README.md @@ -7,52 +7,79 @@ What you need to build your own jQuery If not, go to this page and download "Java Runtime Environment (JRE) 5.0" [http://java.sun.com/javase/downloads/index.jsp](http://java.sun.com/javase/downloads/index.jsp) -* You now have two options for building jQuery, if you have access to common UNIX commands (like `make`, `mkdir`, `rm`, `cat`, and `echo`) then simply type `make` to build all the components. +Build Options +-------------- -* The other option is if you have Ant installed (or are on Windows and don't have access to make). You can download Ant from here: [http://ant.apache.org/bindownload.cgi](http://ant.apache.org/bindownload.cgi) -If you do have Ant, everytime (in this README) that I say 'make', do 'ant' instead - it works identically (for all intents and purposes). +You now have **three** options for building jQuery: + +* **`make`**: If you have access to common UNIX commands (like `make`, `mkdir`, `rm`, `cat`, and `echo`) then simply type `make` to build all the components. + +* **`rake`**: If you have Ruby Rake installed, you can simply type `rake` to build all the components. This method works on both Windows and UNIX/Linux systems. + +* **`ant`**: If you have Ant installed (or are on Windows and don't have access to make). You can download Ant from here: [http://ant.apache.org/bindownload.cgi](http://ant.apache.org/bindownload.cgi). How to build your own jQuery ----------------------------- +*Note: If you are using either `rake` or `ant`, substitute your chosen method in place of `make` in the examples below. They work identically for all intents and purposes. Quick reference is also available for `rake` by typing `rake -T` in the `jquery` directory.* + In the main directory of the distribution (the one that this file is in), type the following to make all versions of jQuery: -`make` + make -Here are each of the individual items that are buildable from the Makefile. +*Here are each of the individual items that are buildable from the Makefile:* -`make init` + make init Pull in all the external dependencies (QUnit, Sizzle) for the project. -`make jquery` + make jquery The standard, uncompressed, jQuery code. -Makes: ./dist/jquery.js +Makes: `./dist/jquery.js` -`make min` + make min A compressed version of jQuery (made the Closure Compiler). -Makes: ./dist/jquery.min.js +Makes: `./dist/jquery.min.js` -`make lint` + make lint Tests a build of jQuery against JSLint, looking for potential errors or bits of confusing code. -`make selector` + make selector Builds the selector library for jQuery from Sizzle. -Makes: ./src/selector.js +Makes: `./src/selector.js` Finally, you can remove all the built files using the command: -`make clean` + make clean + +Building to a different directory +---------------------------------- + +If you want to install jQuery to a location that is not this directory, you can... -Additionally, if you want to install jQuery to a location that is not this -directory, you can specify the PREFIX directory, for example: +**Make only:** Specify the PREFIX directory, for example: -`make PREFIX=/home/john/test/` + make PREFIX=/home/john/test/ [command] + +With this example, the output files would be contained in `/home/john/test/dist/` + +**Rake only:** Define the DIST_DIR directory, for example: + + rake DIST_DIR=/home/john/test/ [command] + +With this example, the output files would be contained in `/home/john/test/` + +*In both examples, `[command]` is optional.* + +**Ant only:** You cannot currently build to another directory when using Ant. + +Questions? +---------- If you have any questions, please feel free to ask them on the jQuery mailing list, which can be found here: diff --git a/Rakefile b/Rakefile index 790b5f3f00..100bd1f0f5 100644 --- a/Rakefile +++ b/Rakefile @@ -34,7 +34,7 @@ minfier = "java -jar #{build_dir}/google-compiler-20091218.jar" verbose(false) # Tasks -task :default => "jquery" +task :default => "all" desc "Builds jQuery; Tests with JSLint; Minifies jQuery" task :all => [:jquery, :lint, :min] do From 3d7c07e440f08bc980461ad3a9ae616e055f225c Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 11:25:22 -0400 Subject: [PATCH 6/9] Minor changes to README --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f4f258b65..c48167fa73 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,8 @@ What you need to build your own jQuery --------------------------------------- -* Make sure that you have Java installed (if you want to build a minified version of jQuery). -If not, go to this page and download "Java Runtime Environment (JRE) 5.0" -[http://java.sun.com/javase/downloads/index.jsp](http://java.sun.com/javase/downloads/index.jsp) +* Make sure that you have Java installed (if you want to build a minified version of jQuery). +If not, [go to this page](http://java.sun.com/javase/downloads/index.jsp) and download "Java Runtime Environment (JRE) 5.0" Build Options -------------- @@ -14,9 +13,9 @@ You now have **three** options for building jQuery: * **`make`**: If you have access to common UNIX commands (like `make`, `mkdir`, `rm`, `cat`, and `echo`) then simply type `make` to build all the components. -* **`rake`**: If you have Ruby Rake installed, you can simply type `rake` to build all the components. This method works on both Windows and UNIX/Linux systems. +* **`rake`**: If you have Ruby Rake installed, you can simply type `rake` to build all the components. This method works on both Windows and UNIX/Linux systems (with Rake installed). -* **`ant`**: If you have Ant installed (or are on Windows and don't have access to make). You can download Ant from here: [http://ant.apache.org/bindownload.cgi](http://ant.apache.org/bindownload.cgi). +* **`ant`**: If you have Ant installed (or are on Windows and don't have access to make). You can download Ant from here: [http://ant.apache.org/bindownload.cgi]. How to build your own jQuery ----------------------------- From 240e4874d994cc94064ac742bbd04e86a09e5da2 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 11:49:30 -0400 Subject: [PATCH 7/9] Edits to README after Karl's review --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c48167fa73..59c5bce78c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ You now have **three** options for building jQuery: * **`make`**: If you have access to common UNIX commands (like `make`, `mkdir`, `rm`, `cat`, and `echo`) then simply type `make` to build all the components. -* **`rake`**: If you have Ruby Rake installed, you can simply type `rake` to build all the components. This method works on both Windows and UNIX/Linux systems (with Rake installed). +* **`rake`**: If you have Ruby Rake installed (on either Windows or UNIX/Linux), you can simply type `rake` to build all the components. * **`ant`**: If you have Ant installed (or are on Windows and don't have access to make). You can download Ant from here: [http://ant.apache.org/bindownload.cgi]. @@ -27,7 +27,7 @@ the following to make all versions of jQuery: make -*Here are each of the individual items that are buildable from the Makefile:* +*Here are the individual items that are buildable from the Makefile:* make init @@ -59,7 +59,7 @@ Finally, you can remove all the built files using the command: Building to a different directory ---------------------------------- -If you want to install jQuery to a location that is not this directory, you can... +If you want to build jQuery to a directory that is different from the default location, you can... **Make only:** Specify the PREFIX directory, for example: From ce80e1dcd04d2e47956fe9f154f3d98c578c73b1 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Mon, 14 Jun 2010 15:03:13 -0400 Subject: [PATCH 8/9] Slight optmization on the Rakefile --- Rakefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 100bd1f0f5..38406bdbb1 100644 --- a/Rakefile +++ b/Rakefile @@ -62,14 +62,14 @@ end desc "Removes dist folder, selector.js, and Sizzle/QUnit" task :clean do puts "Removing Distribution directory: #{dist_dir}..." - rm_r dist_dir, :force => true + rm_rf dist_dir puts "Removing built copy of Sizzle..." - rm_r selector, :force => true + rm_rf selector puts "Removing cloned directories..." - rm_r qunit_dir, :force => true - rm_r sizzle_dir, :force => true + rm_rf qunit_dir + rm_rf sizzle_dir end desc "Rebuilds selector.js from SizzleJS" From 31d2d3e33cee9932c27720362bd0a487b6353822 Mon Sep 17 00:00:00 2001 From: Douglas Neiner Date: Tue, 17 Aug 2010 14:26:41 -0400 Subject: [PATCH 9/9] Added the ability for hasClass to accept an array of class names instead of just a single string. It returns true if *any* of the classes match --- src/attributes.js | 19 ++++++++++++++----- test/unit/attributes.js | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index aca9e055db..094e0cf643 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -123,13 +123,22 @@ jQuery.fn.extend({ }, hasClass: function( selector ) { - var className = " " + selector + " "; - for ( var i = 0, l = this.length; i < l; i++ ) { - if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) { - return true; + var classNames; + if (typeof selector === "string") { + classNames = " " + selector + " "; + for ( var i = 0, l = this.length; i < l; i++ ) { + if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( classNames ) > -1 ) { + return true; + } + } + } else if (jQuery.isArray(selector)) { + classNames = new RegExp('\\b' + selector.join('\\b|\\b').replace(/\./, '\\.') + '\\b'); + for ( var i = 0, l = this.length; i < l; i++ ) { + if (this[i].className.replace(rclass, " ").match(classNames)) { + return true; + } } } - return false; }, diff --git a/test/unit/attributes.js b/test/unit/attributes.js index c125ec7b5f..20725694f9 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -680,7 +680,7 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() { }); test("addClass, removeClass, hasClass", function() { - expect(14); + expect(18); var jq = jQuery("

Hi

"), x = jq[0]; @@ -699,13 +699,17 @@ test("addClass, removeClass, hasClass", function() { ok( jq.hasClass("hi"), "Check has1" ); ok( jq.hasClass("bar"), "Check has2" ); + ok( jq.hasClass(["hi", "bar", "foo"]), "Check has with an array"); - var jq = jQuery("

"); + var jq = jQuery("

"); ok( jq.hasClass("class1"), "Check hasClass with carriage return" ); ok( jq.is(".class1"), "Check is with carriage return" ); ok( jq.hasClass("class2"), "Check hasClass with tab" ); ok( jq.is(".class2"), "Check is with tab" ); ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" ); + ok( jq.hasClass(["class1", "class2"]), "Check has with an array and tab/carriage return"); + ok( jq.hasClass(["cla.ss3"]), "Check has with an array and dot"); + ok( jq.hasClass(["cla.ss4"]) == false, "Check that has with an array and dot does not match any character"); jq.removeClass("class2"); ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );