You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by cm...@apache.org on 2012/07/03 14:22:29 UTC

[17/28] git commit: WICKET-4635 Improve JavaScript files by applying common JSHint rules

WICKET-4635 Improve JavaScript files by applying common JSHint rules

Add all .js files in wicket-core to Grunt's lint checks


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8a4e3e05
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8a4e3e05
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8a4e3e05

Branch: refs/heads/sandbox/resourcefinder
Commit: 8a4e3e05d7a3b148ba9d5e4ee93e3e4b0f06fc3e
Parents: 440003e
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jul 2 16:15:14 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jul 2 19:27:42 2012 +0200

----------------------------------------------------------------------
 grunt.js                                           |   17 ++++--
 .../markup/html/form/AbstractCheckSelector.js      |   48 +++++++++------
 .../wicket/markup/html/form/CheckBoxSelector.js    |   16 +++--
 .../wicket/markup/html/form/CheckGroupSelector.js  |   10 ++-
 .../html/form/CheckboxMultipleChoiceSelector.js    |   13 ++--
 .../html/form/upload/MultiFileUploadField.js       |   25 ++++----
 6 files changed, 78 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/grunt.js
----------------------------------------------------------------------
diff --git a/grunt.js b/grunt.js
index 384939f..c37c87d 100644
--- a/grunt.js
+++ b/grunt.js
@@ -11,14 +11,21 @@
 
 module.exports = function(grunt) {
 
+	var lintCore = [
+		'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js',
+		'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js',
+		'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js',
+		"wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js",
+		"wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js",
+		"wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js",
+		"wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js",
+		"wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js"
+	]
+
 	// Project configuration.
 	grunt.initConfig({
 		lint: {
-			all: [
-				'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js',
-				'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery-debug.js',
-				'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js'
-			]
+			all: lintCore
 		},
 
 		jshint: {

http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js
index 5709cd1..2e2ab9c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractCheckSelector.js
@@ -16,26 +16,29 @@
  */
 
 // introduce a namespace
-if (typeof (Wicket.CheckboxSelector) == "undefined") {
+if (typeof (Wicket.CheckboxSelector) === "undefined") {
 	Wicket.CheckboxSelector = {};
 
 	/**
 	 * Called in the onclick handler of the select-all-checkbox. Updates all
 	 * associated checkboxes by simulating a click on those that need to have
 	 * their state changed.
-	 * 
-	 * @param selectorId
-	 *            the ID of the selector checkbox
+	 *
+	 * @param newCheckedState
+	 *            the state to which all checkboxes should be set
 	 * @param findCheckboxes
 	 *            a function that returns an array containing the IDs of all
 	 *            associated checkboxes
 	 */
 	// adapted from AjaxFormChoiceComponentUpdatingBehavior
 	Wicket.CheckboxSelector.updateAllCheckboxes = function(newCheckedState, findCheckboxes) {
-		var checkboxes = findCheckboxes();
+		"use strict";
+
+		var i,
+			checkboxes = findCheckboxes();
 		for (i in checkboxes) {
 			var checkbox = checkboxes[i];
-			if (checkbox.checked != newCheckedState) {
+			if (checkbox.checked !== newCheckedState) {
 				checkbox.click();
 			}
 		}
@@ -46,7 +49,7 @@ if (typeof (Wicket.CheckboxSelector) == "undefined") {
 	 * update feature is active. Checks the state of all checkboxes - if all are
 	 * checked, the selector is checked too. Otherwise the selector is
 	 * unchecked.
-	 * 
+	 *
 	 * @param selectorId
 	 *            the ID of the selector checkbox
 	 * @param findCheckboxes
@@ -54,8 +57,12 @@ if (typeof (Wicket.CheckboxSelector) == "undefined") {
 	 *            associated checkboxes
 	 */
 	Wicket.CheckboxSelector.updateSelectorState = function(selectorId, findCheckboxes) {
-		var checkboxes = findCheckboxes();
-		var allChecked = true;
+		"use strict";
+
+		var i,
+			checkboxes = findCheckboxes(),
+			allChecked = true;
+
 		for (i in checkboxes) {
 			if (!(checkboxes[i].checked)) {
 				allChecked = false;
@@ -69,7 +76,7 @@ if (typeof (Wicket.CheckboxSelector) == "undefined") {
 	/**
 	 * Called in the onLoad event if the auto update feature is active. Attaches
 	 * an onclick handler to all associated checkboxes.
-	 * 
+	 *
 	 * @param selectorId
 	 *            the ID of the selector checkbox
 	 * @param findCheckboxes
@@ -77,12 +84,16 @@ if (typeof (Wicket.CheckboxSelector) == "undefined") {
 	 *            associated checkboxes
 	 */
 	Wicket.CheckboxSelector.attachUpdateHandlers = function(selectorId, findCheckboxes) {
-		var checkboxes = findCheckboxes();
+		"use strict";
+
+		var i,
+			checkboxes = findCheckboxes(),
+			clickHandler = function() {
+				Wicket.CheckboxSelector.updateSelectorState(selectorId, findCheckboxes);
+			};
+
 		for (i in checkboxes) {
-			Wicket.Event.add(checkboxes[i], 'click', function() {
-				Wicket.CheckboxSelector.updateSelectorState(selectorId,
-						findCheckboxes);
-			});
+			Wicket.Event.add(checkboxes[i], 'click', clickHandler);
 		}
 		// update selector state once to get the right initial state
 		Wicket.CheckboxSelector.updateSelectorState(selectorId, findCheckboxes);
@@ -97,10 +108,11 @@ if (typeof (Wicket.CheckboxSelector) == "undefined") {
 	 *            associated checkboxes
 	 */
 	Wicket.CheckboxSelector.initializeSelector = function(selectorId, findCheckboxes) {
+		"use strict";
+
 		var selector = Wicket.$(selectorId);
 		Wicket.Event.add(selector, 'click', function() {
-			Wicket.CheckboxSelector.updateAllCheckboxes(selector.checked,
-					findCheckboxes);
+			Wicket.CheckboxSelector.updateAllCheckboxes(selector.checked, findCheckboxes);
 		});
-	}
+	};
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js
index e31723a..99cf777 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckBoxSelector.js
@@ -15,23 +15,27 @@
  * limitations under the License.
  */
 // introduce a namespace, just to be nice
-if (typeof (Wicket.CheckboxSelector.Checkboxes) == "undefined") {
+if (typeof (Wicket.CheckboxSelector.Checkboxes) === "undefined") {
 	Wicket.CheckboxSelector.Checkboxes = {};
 	/**
 	 * Returns a closure that finds all checkboxes with the given IDs.
-	 * 
-	 * @param parentChoiceId
+	 *
+	 * @param checkBoxIDs
 	 *            An array containing the markup IDs of all checkboxes this
 	 *            selector should control.
 	 */
 	Wicket.CheckboxSelector.Checkboxes.findCheckboxesFunction = function(checkBoxIDs) {
+		"use strict";
+
 		return function() {
-			var result = new Array();
+			var i,
+				result = [];
+
 			for (i in checkBoxIDs) {
 				var checkBox = Wicket.$(checkBoxIDs[i]);
-				result.push(checkBox)
+				result.push(checkBox);
 			}
 			return result;
-		}
+		};
 	};
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js
index bbbca98..44ae16c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckGroupSelector.js
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 // introduce a namespace, just to be nice
-if (typeof (Wicket.CheckboxSelector.Group) == "undefined") {
+if (typeof (Wicket.CheckboxSelector.Group) === "undefined") {
 	Wicket.CheckboxSelector.Group = {};
 	/**
 	 * Returns a closure that finds all checkboxes associated with the given
 	 * CheckGroup.
-	 * 
+	 *
 	 * @param formId
 	 *            The markup ID of the containing form (needed because the
 	 *            selector might be outside the form)
@@ -28,8 +28,10 @@ if (typeof (Wicket.CheckboxSelector.Group) == "undefined") {
 	 *            The input name of the CheckGroup
 	 */
 	Wicket.CheckboxSelector.Group.findCheckboxesFunction = function(formId, groupName) {
+		"use strict";
+
 		return function() {
-			var result = new Array();
+			var result = [];
 			var parentForm = Wicket.$(formId);
 			var parentGroup = parentForm[groupName];
 			if (parentGroup.length) {
@@ -41,6 +43,6 @@ if (typeof (Wicket.CheckboxSelector.Group) == "undefined") {
 				result.push(parentGroup);
 			}
 			return result;
-		}
+		};
 	};
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js
index 62c3ebe..823edff 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckboxMultipleChoiceSelector.js
@@ -15,21 +15,22 @@
  * limitations under the License.
  */
 // introduce a namespace, just to be nice
-if (typeof (Wicket.CheckboxSelector.Choice) == "undefined") {
+if (typeof (Wicket.CheckboxSelector.Choice) === "undefined") {
 	Wicket.CheckboxSelector.Choice = {};
 
 	/**
 	 * Returns a closure that finds all checkboxes associated with the given
 	 * CheckboxMultipleChoice.
-	 * 
+	 *
 	 * @param parentChoiceId
 	 *            The markup ID of the CheckboxMultipleChoise
 	 */
 	// adapted from AjaxFormChoiceComponentUpdatingBehavior
-	Wicket.CheckboxSelector.Choice.findCheckboxesFunction = function(
-			parentChoiceId) {
+	Wicket.CheckboxSelector.Choice.findCheckboxesFunction = function(parentChoiceId) {
+		"use strict";
+
 		return function() {
-			var result = new Array();
+			var result = [];
 			var inputNodes = Wicket.$(parentChoiceId).getElementsByTagName(
 					'input');
 			for ( var i = 0; i < inputNodes.length; i++) {
@@ -39,6 +40,6 @@ if (typeof (Wicket.CheckboxSelector.Choice) == "undefined") {
 				}
 			}
 			return result;
-		}
+		};
 	};
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8a4e3e05/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js
index 6e2d8d8..a649711 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js
@@ -19,16 +19,16 @@
  *
  *   You might (will) want to play around with the addListRow() method to make the output prettier.
  *
- *   You might also want to change the line 
+ *   You might also want to change the line
  *       element.name = 'file_' + this.count;
  *   ...to a naming convention that makes more sense to you.
- * 
+ *
  * Licence:
  *   Use this however/wherever you like, just don't blame me if it breaks anything.
  *
  * Credit:
  *   If you're nice, you'll leave this bit:
- *  
+ *
  *   Class by Stickman -- http://www.the-stickman.com
  *      with thanks to:
  *      [for Safari fixes]
@@ -39,6 +39,7 @@
  *         'neal'
  */
 function MultiSelector( eprefix, list_target,max, del_label ){
+	"use strict";
 
 	// Where to write the list
 	this.list_target = list_target;
@@ -51,9 +52,9 @@ function MultiSelector( eprefix, list_target,max, del_label ){
 		this.max = max;
 	} else {
 		this.max = -1;
-	};
+	}
 	
-	this.delete_label=del_label
+	this.delete_label=del_label;
 	this.element_name_prefix=eprefix;
 	
 	/**
@@ -62,7 +63,7 @@ function MultiSelector( eprefix, list_target,max, del_label ){
 	this.addElement = function( element ){
 
 		// Make sure it's a file input element
-		if( element.tagName.toLowerCase() == 'input' && element.type.toLowerCase() == 'file' ){
+		if( element.tagName.toLowerCase() === 'input' && element.type.toLowerCase() === 'file' ){
 
 			// Element name -- what number am I?
 			element.name = this.element_name_prefix + "_mf_"+this.id++;
@@ -92,19 +93,19 @@ function MultiSelector( eprefix, list_target,max, del_label ){
 
 			};
 			// If we've reached maximum number, disable input element
-			if( this.max != -1 && this.count >= this.max ){
+			if( this.max !== -1 && this.count >= this.max ){
 				element.disabled = true;
-			};
+			}
 
 			// File element counter
 			this.count++;
 			// Most recent element
 			this.current_element = element;
 			
-		} else {
+		} else if (Wicket && Wicket.Log) {
 			// This can only be applied to file input elements!
-			alert( 'Error: not a file input element' );
-		};
+			Wicket.Log.error( 'Error: not a file input element' );
+		}
 
 	};
 
@@ -156,4 +157,4 @@ function MultiSelector( eprefix, list_target,max, del_label ){
 		
 	};
 
-};
\ No newline at end of file
+}
\ No newline at end of file