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

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

WICKET-4635 Improve JavaScript files by applying common JSHint rules

Enable tree.js for linting


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

Branch: refs/heads/sandbox/resourcefinder
Commit: 5b06f8f30095b1e243a075e4d53e760d331ca26a
Parents: 58f33fc
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jul 2 16:45:21 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jul 2 19:28:26 2012 +0200

----------------------------------------------------------------------
 grunt.js                                           |    4 +-
 .../wicket/extensions/markup/html/tree/res/tree.js |  304 +++++++--------
 2 files changed, 143 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5b06f8f3/grunt.js
----------------------------------------------------------------------
diff --git a/grunt.js b/grunt.js
index dee6915..4c03d7c 100644
--- a/grunt.js
+++ b/grunt.js
@@ -27,10 +27,10 @@ module.exports = function(grunt) {
 		],
 		lintExtensions = [
 			"wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js",
-			"wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js"
+			"wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js",
+			"wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js"
 //			"wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js",
 //			"wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js",
-//			"wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js"
 		],
 		gruntJs = [
 			"grunt.js"

http://git-wip-us.apache.org/repos/asf/wicket/blob/5b06f8f3/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js
index 0273dfe..b560599 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/tree/res/tree.js
@@ -14,166 +14,144 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-if (typeof(Wicket) == "undefined")
-	Wicket = { };
-
-Wicket.Tree = { };
-
-Wicket.Tree.askForReload = function()
-{
-   if (confirm("There was a problem updating the tree. It might be caused be the old page being cached by the browser. \n" +
-   "It is recommended to reload the page. Do you want to reload it?"))
-   {
-      window.location.reload();
-   }
-};
-
-Wicket.Tree.removeNodes = function(prefix, nodeList)
-{
-   var problem = false;
-   for (var i = 0; i < nodeList.length; i++)
-   {
-      var e = document.getElementById(prefix + nodeList[i]);
-      if (e != null)
-      {
-         e.parentNode.removeChild(e);
-      }
-      else
-      {
-         // while developing alert a warning
-         problem = true;
-         Wicket.Log.error("Can't find node with id " + prefix + nodeList[i] +
-         ". This shouldn't happen - possible bug in tree?");
-      }
-   }
-   if (problem == true)
-   {
-      Wicket.Tree.askForReload();
-   }
-};
-
-Wicket.Tree.createElement = function(elementId, afterId)
-{
-   var existing = Wicket.$(elementId);
-   if (typeof(existing) != "undefined" && existing != null)
-   {
-      Wicket.Tree.askForReload();
-   }
-
-   var after = document.getElementById(afterId);
-   var newNode = document.createElement(after.tagName);
-   newNode.setAttribute("id", elementId);
-
-   var p = after.parentNode;
-
-   for (var i = 0; i < p.childNodes.length; ++i)
-   {
-      if (after == p.childNodes[i])
-         break;
-   }
-   if (i == p.childNodes.length - 1)
-   {
-      p.appendChild(newNode);
-   }
-   else
-   {
-      p.insertBefore(newNode, p.childNodes[i + 1]);
-   }
-};
-
-Wicket.TreeTable = { };
-
-/* Javascript that resizes the tree table header so that it matches size of the content.
-   This is needed when the scrollbar next to content is show, so that the columns are 
-   properly aligned */
-Wicket.TreeTable.update = function(elementId)
-{
-
-   var element = document.getElementById(elementId);
-
-   if (element != null && typeof(element) != "undefined")
-   {
-
-      try
-      {
-
-         /// find the div containing the inner header div
-         var headerParent = element.getElementsByTagName("div")[1];
-
-         // find the inner header div
-         var header = headerParent.getElementsByTagName("div")[0];
-
-         // body div should be next div after header parent
-         var body = headerParent.nextSibling;
-
-         // interate until div is found
-         while (body.tagName != "DIV")
-         {
-            body = body.nextSibling;
-         }
-
-         // last check to find out if we are updating the right component
-         if (body.className == "wicket-tree-table-body")
-         {
-
-            // get the right padding from header - we need to substract it from new width
-            var padding;
-            if (document.defaultView && document.defaultView.getComputedStyle)
-            {
-               padding = document.defaultView.getComputedStyle(headerParent, '').getPropertyValue("padding-right");
-            } else if (headerParent.currentStyle)
-            {
-               padding = headerParent.currentStyle.paddingRight;
-            }
-            else
-            {
-               padding = 6;
-            }
-
-            padding = parseInt(padding, 10);
-
-            // set the new width
-            var w = (body.getElementsByTagName("div")[0].clientWidth - padding) + "px";
-
-            if (w == (-padding) + "px")
-            { // this can happen if the first row is hidden (e.g. rootless mode)
-               // try to get the width from second row
-               w = (body.getElementsByTagName("div")[1].clientWidth - padding) + "px";
-
-            }
-
-            if (w != "0px")
-            {
-               header.style.width = w;
-            }
-
-         }
-      }
-      catch (ignore)
-      {
-      }
-   }
-};
-
-Wicket.TreeTable.attached = new Object();
-
-Wicket.TreeTable.attachUpdate = function(treeTableId)
-{
-   // get the object that contains ids of elements on which the update method was already attached
-   var attached = Wicket.TreeTable.attached;
-
-   // force updating the element
-   Wicket.TreeTable.update(treeTableId);
-
-   // if the update has not been attached to this tree table yet...
-   if (typeof(attached[treeTableId]) == "undefined")
-   {
-      // ... attach it
-      attached[treeTableId] = window.setInterval(function()
-      {
-         Wicket.TreeTable.update(treeTableId);
-      }, 100);
-   }
-};
-
+;(function (undefined) {
+	'use strict';
+
+	if (typeof(Wicket) === "undefined") {
+		Wicket = {};
+	}
+
+	Wicket.Tree = {};
+
+	Wicket.Tree.askForReload = function() {
+		if (window.confirm("There was a problem updating the tree. It might be caused be the old page being cached by the browser. \n" +
+			"It is recommended to reload the page. Do you want to reload it?"))
+		{
+			window.location.reload();
+		}
+	};
+
+	Wicket.Tree.removeNodes = function(prefix, nodeList) {
+		var problem = false;
+		for (var i = 0; i < nodeList.length; i++) {
+			var e = document.getElementById(prefix + nodeList[i]);
+			if (e != null) {
+				e.parentNode.removeChild(e);
+			}
+			else {
+				// while developing alert a warning
+				problem = true;
+				if (Wicket.Log) {
+					Wicket.Log.error("Can't find node with id " + prefix + nodeList[i] +
+						". This shouldn't happen - possible bug in tree?");
+				}
+			}
+		}
+
+		if (problem === true) {
+			Wicket.Tree.askForReload();
+		}
+	};
+
+	Wicket.Tree.createElement = function(elementId, afterId) {
+		var existing = Wicket.$(elementId);
+		if (typeof(existing) !== "undefined" && existing !== null) {
+			Wicket.Tree.askForReload();
+		}
+
+		var after = document.getElementById(afterId);
+		var newNode = document.createElement(after.tagName);
+		newNode.setAttribute("id", elementId);
+
+		var p = after.parentNode;
+
+		for (var i = 0; i < p.childNodes.length; ++i) {
+			if (after === p.childNodes[i]) {
+				break;
+			}
+		}
+		if (i === p.childNodes.length - 1) {
+			p.appendChild(newNode);
+		}
+		else {
+			p.insertBefore(newNode, p.childNodes[i + 1]);
+		}
+	};
+
+	Wicket.TreeTable = {};
+
+	/* Javascript that resizes the tree table header so that it matches size of the content.
+	   This is needed when the scrollbar next to content is show, so that the columns are
+	   properly aligned */
+	Wicket.TreeTable.update = function(elementId)
+	{
+		var element = document.getElementById(elementId);
+
+		if (element !== null && typeof(element) !== "undefined")
+		{
+			try {
+				// find the div containing the inner header div
+				var headerParent = element.getElementsByTagName("div")[1];
+
+				// find the inner header div
+				var header = headerParent.getElementsByTagName("div")[0];
+
+				// body div should be next div after header parent
+				var body = headerParent.nextSibling;
+
+				// interate until div is found
+				while (body.tagName !== "DIV") {
+					body = body.nextSibling;
+				}
+
+				// last check to find out if we are updating the right component
+				if (body.className === "wicket-tree-table-body") {
+					// get the right padding from header - we need to substract it from new width
+					var padding;
+					if (document.defaultView && document.defaultView.getComputedStyle) {
+						padding = document.defaultView.getComputedStyle(headerParent, '').getPropertyValue("padding-right");
+					} else if (headerParent.currentStyle) {
+						padding = headerParent.currentStyle.paddingRight;
+					}
+					else {
+						padding = 6;
+					}
+
+					padding = parseInt(padding, 10);
+
+					// set the new width
+					var w = (body.getElementsByTagName("div")[0].clientWidth - padding) + "px";
+
+					if (w === (-padding) + "px") {
+						// this can happen if the first row is hidden (e.g. rootless mode)
+						// try to get the width from second row
+						w = (body.getElementsByTagName("div")[1].clientWidth - padding) + "px";
+					}
+
+					if (w !== "0px") {
+						header.style.width = w;
+					}
+				}
+			}
+			catch (ignore) {}
+		}
+	};
+
+	Wicket.TreeTable.attached = {};
+
+	Wicket.TreeTable.attachUpdate = function(treeTableId) {
+		// get the object that contains ids of elements on which the update method was already attached
+		var attached = Wicket.TreeTable.attached;
+
+		// force updating the element
+		Wicket.TreeTable.update(treeTableId);
+
+		// if the update has not been attached to this tree table yet...
+		if (typeof(attached[treeTableId]) === "undefined") {
+			// ... attach it
+			attached[treeTableId] = window.setInterval(function() {
+				Wicket.TreeTable.update(treeTableId);
+			}, 100);
+		}
+	};
+})();