dev@jsf-extensions.java.net

diff: JavaScript-oriented fix for "DynaFaces already defined" collision, etc.

From: Matthew Bohm <Matthew.Bohm_at_Sun.COM>
Date: Mon, 09 Apr 2007 21:37:35 -0700

JavaScript-oriented fix for "DynaFaces already defined" collision; trim
src in DynaFaces.replace; add
DynaFacesZones.inspectElementByNameAndAttribute convenience function

The following was just committed by mbohm, following a discussion
between mbohm and edburns:

Index: code/run-time/avatar/src/main/resources/com_sun_faces_ajax.js
===================================================================
--- code/run-time/avatar/src/main/resources/com_sun_faces_ajax.js
(revision 423)
+++ code/run-time/avatar/src/main/resources/com_sun_faces_ajax.js
(working copy)
@@ -27,8 +27,9 @@
  * Copyright 2005 Sun Microsystems Inc. All Rights Reserved
  */
 
+var __existingDynaFaces__ = null;
 if (typeof DynaFaces != 'undefined') {
- alert("DynaFaces already defined!");
+ __existingDynaFaces__ = DynaFaces;
 }
 
 var DynaFaces = new Object();
@@ -291,7 +292,7 @@
     var temp = document.createElement('div');
     var result = null;
     temp.id = d.id;
- temp.innerHTML = src;
+ temp.innerHTML = DynaFaces.trim(src);
 
     result = temp.firstChild;
     parent.replaceChild(temp.firstChild,d);
@@ -341,6 +342,11 @@
     return document.forms[0];
 };
 
+var __existingFaces__ = null;
+if (typeof Faces != 'undefined') {
+ __existingFaces__ = Faces;
+}
+
 /* Facelet Utility Class
  ***********************************************************/
 var Faces = {
@@ -1015,3 +1021,12 @@
 DynaFaces.queueFacesEvent = function (facesEvent) {
     DynaFaces._eventQueue.push(facesEvent);
 }
+
+if (__existingDynaFaces__ != null) {
+ DynaFaces = __existingDynaFaces__;
+ __existingDynaFaces__ = null;
+}
+if (__existingFaces__ != null) {
+ Faces = __existingFaces__;
+ __existingFaces__ = null;
+}
Index: code/run-time/avatar/src/main/resources/com_sun_faces_ajax_zone.js
===================================================================
---
code/run-time/avatar/src/main/resources/com_sun_faces_ajax_zone.js
(revision 423)
+++
code/run-time/avatar/src/main/resources/com_sun_faces_ajax_zone.js
(working copy)
@@ -385,3 +385,59 @@
 
     return result;
 }
+
+/**
+ * Convenience function for customizing inspectElement.
+ * @param element The element being inspected.
+ * @param tagNames A string or array of strings specifying the tag
names of elements to arm.
+ * @param attributeNames A string or array of strings (parallel to
tagNames)
+ * that restrict the elements to arm by attribute name. Can be
undefined or
+ * null if we do not want to restrict the elements to arm by attribute
name and value.
+ * @param attributeValues A string or array of strings (parallel to
tagNames)
+ * that restrict the elements to arm by attribute value. Can be
undefined or
+ * null if we do not want to restrict the elements to arm by attribute
value.
+ */
+DynaFacesZones.inspectElementByNameAndAttribute = function(element,
tagNames, attributeNames, attributeValues) {
+ var defaultResult = DynaFacesZones.inspectElement(element);
+ if (defaultResult != true) {
+ return false;
+ }
+ if (! (tagNames instanceof Array)) {
+ tagNames = [tagNames];
+ }
+ if (typeof attributeNames != 'undefined' && attributeNames != null
&& !(attributeNames instanceof Array)) {
+ attributeNames = [attributeNames];
+ }
+ if (typeof attributeValues != 'undefined' && attributeValues !=
null && !(attributeValues instanceof Array)) {
+ attributeValues = [attributeValues];
+ }
+ for (var i = 0; i < tagNames.length; i++) {
+ tagNames[i] = tagNames[i].toLowerCase();
+ if (element.nodeName.toLowerCase().indexOf(tagNames[i]) != 0) {
+ continue;
+ }
+ //if an attribute name corresponding to tagNames[i] was supplied
+ if (typeof attributeNames != 'undefined' && attributeNames !=
null && attributeNames[i] != null) {
+ //if an attribute value corresponding to tagNames[i] was
supplied
+ if (typeof attributeValues != 'undefined' &&
attributeValues != null && attributeValues[i] != null) {
+ //if the attribute's value is the same as the one
supplied, return true
+ if (element.getAttribute(attributeNames[i]) ==
attributeValues[i]) {
+ return true;
+ }
+ }
+ else {
+ //an attribute name corresponding to tagNames[i] was
supplied
+ //an attribute value corresponding to tagNames[i] was
NOT supplied
+ //if the attribute has a defined, non-null value,
return true
+ var value = element.getAttribute(attributeNames[i]);
+ if (typeof value != 'undefined' && value != null) {
+ return true;
+ }
+ }
+ }
+ else {
+ return true;
+ }
+ }
+ return false;
+}