[richfaces-svn-commits] JBoss Rich Faces SVN: r1379 - trunk/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jun 28 15:01:12 EDT 2007


Author: sergeyhalipov
Date: 2007-06-28 15:01:12 -0400 (Thu, 28 Jun 2007)
New Revision: 1379

Modified:
   trunk/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
Log:
Some improvements for RF-46.

Modified: trunk/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
===================================================================
--- trunk/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js	2007-06-28 18:28:14 UTC (rev 1378)
+++ trunk/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js	2007-06-28 19:01:12 UTC (rev 1379)
@@ -164,6 +164,9 @@
 
 		this.eventFirstOnfocus = this.firstOnfocus.bindAsEventListener(this);
 		this.eventLastOnfocus = this.lastOnfocus.bindAsEventListener(this);
+
+		this.firstHref = $(this.markerId.id + "FirstHref");
+		this.lastHref = $(this.markerId.id + "LastHref");
 	},
 
 	destroy: function() {
@@ -263,93 +266,77 @@
 	},
 
 	firstOnfocus: function(event) {
-		var firstHref = $(this.markerId.id + "FirstHref");
-		if (firstHref) {
-			firstHref.focus();
+		if (this.firstHref) {
+			this.firstHref.focus();
 		}
 	},
 
 	lastOnfocus: function(event) {
-		var lastHref = $(this.markerId.id + "LastHref");
-		if (lastHref) {
-			lastHref.focus();
+		if (this.lastHref) {
+			this.lastHref.focus();
 		}
 	},
 
-	isInModalPanel: function(input) {
-		var element = $(input);
-		if (!element)
-			return false;
-		while (element && element.tagName && element.tagName.toLowerCase != "body") {
-			if (element == this.cdiv)
-				return true;
-			element = element.parentNode;
+	processAllFocusElements: function(root) {
+		if (root.focus && 
+			// Many not visible elements have focus method, we is had to avoid processing them.
+			/^a|input|select|button|textarea$/i.test(root.tagName) &&
+			!root.disabled && !/^hidden$/.test(root.type) &&
+			!/^none$/.test(root.style.display)) {
+				this.execute(root);
+		} else {
+			if (root == this.cdiv)
+				this.inModalPanel = true;
+			var child = root.firstChild;
+			while (child) {
+				this.processAllFocusElements(child);
+				child = child.nextSibling;
+			}
+			if (root == this.cdiv)
+				this.inModalPanel = false;
 		}
-		return false;
 	},
 
-	processTabindexes:	function(inputs) {
-		if (!inputs || !inputs.length)
-			return ;
-		for (var i = 0; i < inputs.length; i++) {
-			if (!this.isInModalPanel(inputs[i])) {
-				if (!this.firstOutside)
-					this.firstOutside = inputs[i];
-				this.lastOutside = inputs[i];
-				if (inputs[i].tabIndex) {
-					inputs[i].prevTabIndex = inputs[i].tabIndex;
-				}
-				inputs[i].tabIndex = null;
-				if (inputs[i].accesskey) {
-					inputs[i].prevAccesskey = inputs[i].accesskey;
-				}
-				inputs[i].accesskey = undefined;
+	processTabindexes:	function(input) {
+		if (!this.inModalPanel) {
+			if (!this.firstOutside)
+				this.firstOutside = input;
+			this.lastOutside = input;
+			if (input.tabIndex) {
+				input.prevTabIndex = input.tabIndex;
 			}
+			input.tabIndex = undefined;
+			if (input.accesskey) {
+				input.prevAccesskey = input.accesskey;
+			}
+			input.accesskey = undefined;
 		}
 	},
 
-	restoreTabindexes:	function(inputs) {
-		if (!inputs || !inputs.length)
-			return;
-		for (var i = 0; i < inputs.length; i++) {
-			if (!this.isInModalPanel(inputs[i])) {
-				inputs[i].tabIndex = inputs[i].prevTabIndex;
-				inputs[i].accesskey = inputs[i].prevAccesskey;
-			}
+	restoreTabindexes:	function(input) {
+		if (!this.inModalPanel) {
+			if (input.prevTabIndex)
+				input.tabIndex = input.prevTabIndex;
+			if (input.prevAccesskey)
+				input.accesskey = input.prevAccesskey;
 		}
 	},
 
 	preventFocus:	function() {
-		var inputs = document.getElementsByTagName("input");
-		this.processTabindexes(inputs);
-		var selects = document.getElementsByTagName("select");
-		this.processTabindexes(selects);
-		var buttons = document.getElementsByTagName("button");
-		this.processTabindexes(buttons);
-		var hrefs = document.getElementsByTagName("a");
-		this.processTabindexes(hrefs);
-		var texts = document.getElementsByTagName("textarea");
-		this.processTabindexes(texts);
+		this.execute = this.processTabindexes;
+		this.processAllFocusElements(document);
 		
 		if (this.firstOutside) {
 			Event.observe(this.firstOutside, "focus", this.eventFirstOnfocus); 
 		}
-		if (this.lastOutside) {
+		if (this.lastOutside && this.lastOutside != this.firstOutside) {
 			Event.observe(this.lastOutside, "focus", this.eventLastOnfocus); 
 		}
 	},
 
 	restoreFocus: function() {
-		var inputs = document.getElementsByTagName("input");
-		this.restoreTabindexes(inputs);
-		var selects = document.getElementsByTagName("select");
-		this.restoreTabindexes(selects);
-		var buttons = document.getElementsByTagName("button");
-		this.restoreTabindexes(buttons);
-		var hrefs = document.getElementsByTagName("a");
-		this.restoreTabindexes(hrefs);
-		var texts = document.getElementsByTagName("textarea");
-		this.restoreTabindexes(texts);
+		this.execute = this.restoreTabindexes;
+		this.processAllFocusElements(document);
 		
 		if (this.firstOutside) {
 			Event.stopObserving(this.firstOutside, "focus", this.eventFirstOnfocus);




More information about the richfaces-svn-commits mailing list