Author: jogep
Date: Wed Mar 9 19:19:33 2011
New Revision: 1079950
URL: http://svn.apache.org/viewvc?rev=1079950&view=rev
Log:
WW-3437: JavaScript should following the JSLint recommendations
Modified:
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
struts/struts2/trunk/core/src/main/resources/template/css_xhtml/validation.js
struts/struts2/trunk/core/src/main/resources/template/xhtml/validation.js
Modified:
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js?rev=1079950&r1=1079949&r2=1079950&view=diff
==
---
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
(original)
+++
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/utils.js
Wed Mar 9 19:19:33 2011
@@ -24,7 +24,7 @@ var StrutsUtils = {};
// gets an object with validation errors from string returned by
// the ajaxValidation interceptor
StrutsUtils.getValidationErrors = function(data) {
- if(data.indexOf("/* {") == 0) {
+ if(data.indexOf("/* {") === 0) {
return eval("( " + data.substring(2, data.length - 2) + " )");
} else {
return null;
@@ -33,7 +33,7 @@ StrutsUtils.getValidationErrors = functi
StrutsUtils.clearValidationErrors = function(form) {
var firstNode = StrutsUtils.firstElement(form);
-var xhtml = firstNode.tagName.toLowerCase() == "table";
+var xhtml = firstNode.tagName.toLowerCase() === "table";
if(xhtml) {
clearErrorMessagesXHTML(form);
@@ -59,11 +59,12 @@ StrutsUtils.showValidationErrors = funct
StrutsUtils.clearValidationErrors(form, errors);
if (errors.errors) {
- var errorList = document.createElement("ul");
+ var l, errorList = document.createElement("ul");
+
errorList.setAttribute("class", "errorMessage");
errorList.setAttribute("className", "errorMessage"); // ie hack
cause ie does not support setAttribute
- for ( var l = 0; l < errors.errors.length; l++) {
+ for ( l = 0; l < errors.errors.length; l++) {
var item = document.createElement("li");
var itemText =
document.createTextNode(errors.errors[l]);
item.appendChild(itemText);
@@ -75,16 +76,18 @@ StrutsUtils.showValidationErrors = funct
StrutsUtils.errorLists[form] = errorList;
}
- var firstNode = StrutsUtils.firstElement(form);
- var xhtml = firstNode.tagName.toLowerCase() == "table";
+ var i, fieldName, firstNode = StrutsUtils.firstElement(form);
+ var xhtml = firstNode.tagName.toLowerCase() === "table";
if(errors.fieldErrors) {
-for(var fieldName in errors.fieldErrors) {
- for(var i = 0; i < errors.fieldErrors[fieldName].length; i++) {
-if(xhtml) {
- addErrorXHTML(form.elements[fieldName],
errors.fieldErrors[fieldName][i]);
-} else {
- addErrorCSS(form.elements[fieldName],
errors.fieldErrors[fieldName][i]);
-}
+for(fieldName in errors.fieldErrors) {
+ if(errors.fieldErrors.hasOwnProperty(fieldName)) {
+for(i = 0; i < errors.fieldErrors[fieldName].length; i++) {
+ if(xhtml) {
+addErrorXHTML(form.elements[fieldName],
errors.fieldErrors[fieldName][i]);
+ } else {
+addErrorCSS(form.elements[fieldName],
errors.fieldErrors[fieldName][i]);
+ }
+}
}
}
}
@@ -92,10 +95,10 @@ StrutsUtils.showValidationErrors = funct
StrutsUtils.firstElement = function(parentNode, tagName) {
var node = parentNode.firstChild;
- while(node && node.nodeType != 1){
+ while(node && node.nodeType !== 1){
node = node.nextSibling;
}
- if(tagName && node && node.tagName && node.tagName.toLowerCase() !=
tagName.toLowerCase()) {
+ if(tagName && node && node.tagName && node.tagName.toLowerCase() !==
tagName.toLowerCase()) {
node = StrutsUtils.nextElement(node, tagName);
}
return node;
@@ -105,9 +108,9 @@ StrutsUtils.nextElement = function(node,
if(!node) { return null; }
do {
node = node.nextSibling;
- } while(node && node.nodeType != 1);
+ } while(node && node.nodeType !== 1);
- if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+ if(node && tagName && tagName.toLowerCase() !== node.tagName.toLowerCase()) {
return StrutsUtils.nextElement(node, tagName);
}
return node;
@@ -118,9 +121,9 @@ StrutsUtils.previousElement = function(n
if(tagName) { tagName = tagName.toLowerCase(); }
do {
node = node.previousSibling;
- } while(node && node.nodeType != 1);
+ } while(node && node.nodeType !== 1);
- if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+ if(node && tagNa