[seam-commits] Seam SVN: r11190 - in sandbox/trunk/modules/xwidgets: src/main/javascript and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 23 07:27:12 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-06-23 07:27:11 -0400 (Tue, 23 Jun 2009)
New Revision: 11190

Modified:
   sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
Log:
fixes for IE

Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js
===================================================================
--- sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js	2009-06-23 09:06:16 UTC (rev 11189)
+++ sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js	2009-06-23 11:27:11 UTC (rev 11190)
@@ -16,7 +16,8 @@
     if (this.control == null)
     {
       this.control = document.createTextNode(this.value);
-      this.control.widget = this;
+      // IE doesn't support setting random properties on text nodes
+      // this.control.widget = this;
       this.parent.control.appendChild(this.control);
     }       
   }

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js	2009-06-23 09:06:16 UTC (rev 11189)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js	2009-06-23 11:27:11 UTC (rev 11190)
@@ -16,7 +16,8 @@
     if (this.control == null)
     {
       this.control = document.createTextNode(this.value);
-      this.control.widget = this;
+      // IE doesn't support setting random properties on text nodes
+      // this.control.widget = this;
       this.parent.control.appendChild(this.control);
     }       
   }

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-06-23 09:06:16 UTC (rev 11189)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-06-23 11:27:11 UTC (rev 11190)
@@ -99,7 +99,21 @@
 
 xw.Sys.chainEvent = function(ctl, eventName, eventFunc)
 {
-  return ctl.addEventListener(eventName, eventFunc, false);
+  if (ctl.addEventListener)
+  {
+    // normal browsers like firefox, chrome and safari support this
+    ctl.addEventListener(eventName, eventFunc, false);
+  }
+  else if (ctl.attachEvent)
+  {
+    // irregular browsers such as IE don't support standard functions
+    ctl.attachEvent("on" + eventName, eventFunc);
+  }
+  else
+  {
+    // really old browsers
+    // alert("your browser doesn't support adding event listeners");
+  }
 }
 
 /**
@@ -188,19 +202,15 @@
     for (var i = 0; i < elements.length; i++)
     {
       var element = elements.item(i);    
-      if (element instanceof Element)
+      if (element.nodeType != 1) continue; // not an element
+      if (element.tagName == "event") continue; // ignore events
+      var controlName = xw.Sys.capitalize(element.tagName);                                
+      if (!xw.Sys.arrayContains(this.controls, controlName))
       {
-        if (element.tagName != "event")
-        {
-          var controlName = xw.Sys.capitalize(element.tagName);                                
-          if (!xw.Sys.arrayContains(this.controls, controlName))
-          {
-            this.controls.push(controlName);
-          }        
-          
-          this.parseChildNodes(element.childNodes);    
-        }
-      }
+        this.controls.push(controlName);
+      }        
+      
+      this.parseChildNodes(element.childNodes);    
     }
   }    
   
@@ -216,10 +226,9 @@
   {
     for (var i = 0; i < children.length; i++)
     {      
-      if (children.item(i) instanceof Element)
-      {
-        this.parseControl(children.item(i), parentControl);
-      }
+      var element = children.item(i);
+      if (element.nodeType != 1) continue; // not an element
+      this.parseControl(element, parentControl);
     }       
   }
   
@@ -248,15 +257,12 @@
       }
       parentControl.children.push(control);
       
-      if (element.hasAttributes())
+      // Set control properties
+      for (var i = 0; i < element.attributes.length; i++)
       {
-        // Set control properties
-        for (var i = 0; i < element.attributes.length; i++)
-        {
-          var name = element.attributes[i].name;
-          var value = element.getAttribute(name);
-          control[name] = value;
-        }
+        var name = element.attributes[i].name;
+        var value = element.getAttribute(name);
+        control[name] = value;
       }
     
       this.parseChildren(element.childNodes, control);      
@@ -271,23 +277,24 @@
   for (var i = 0; i < element.childNodes.length; i++)
   {
     var child = element.childNodes.item(i);
-    if (child instanceof Element && child.tagName == "action")
+    if (child.nodeType != 1) continue; // not an element
+    if (child.tagName != "action") continue; // not an action
+    if (child.getAttribute("type") != "script") continue; // not a script
+
+    // get all the text content of the action node, textContent would be
+    // easier but IE doesn't support that
+    var actionScript = "";
+    for (var j = 0; j < child.childNodes.length; j++)
     {
-      if (child.getAttribute("type") == "script")
-      {
-        for (var j = 0; j < child.childNodes.length; j++)
-        {
-          if (child.childNodes[j].nodeType == 4) // CDATA_SECTION_NODE
-          {
-            var actionScript = child.childNodes[j].nodeValue;
-            var action = new xw.Action();
-            action.script = actionScript;
-            events[eventType] = action;
-          }
-        }                                
-      }
-      break; 
+      var grandChild = child.childNodes[j];
+      var nodeType = grandChild.nodeType;
+      if (nodeType != 3 && nodeType != 4) continue; // not TEXT or CDATA
+      actionScript = actionScript + grandChild.nodeValue;
     }
+    var action = new xw.Action();
+    action.script = actionScript;
+    events[eventType] = action;
+    break; 
   }
 }
 




More information about the seam-commits mailing list