Author: maksimkaszynski
Date: 2007-06-11 13:20:51 -0400 (Mon, 11 Jun 2007)
New Revision: 1125
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
Log:
trying to fix IE incompatibility
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java 2007-06-11
17:17:50 UTC (rev 1124)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/selection/SimpleSelection.java 2007-06-11
17:20:51 UTC (rev 1125)
@@ -3,7 +3,6 @@
*/
package org.richfaces.model.selection;
-import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-11
17:17:50 UTC (rev 1124)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-11
17:20:51 UTC (rev 1125)
@@ -5,12 +5,15 @@
importNode: function(node, bKids) {
var nodeName = node.nodeName.toUpperCase();
+
+ //LOG.debug("Importing node " + Utils.DOM._formatNode(node));
switch(nodeName) {
case "TBODY":
case "TR":
case "TD":
{
+ //LOG.debug("Creating new node ");
var imported = document.createElement(nodeName);
this.copyAttributes(imported, node);
@@ -22,28 +25,37 @@
var importedKid = this.importNode(kid, true);
- imported.appendChild(importedKid);
+ imported.insertBefore(importedKid, null);
}
}
return imported;
}
- default:
- return (document.importNode(node, bKids));
+ default: {
+ var imported = document.createElement(nodeName);
+ imported.outerHTML = node.xml;
+ return imported;
+ }
}
},
- copyAttributes : function(target, source) {
-
+ copyAttributes : function(target, source, opts) {
+ //LOG.debug("Copying attributes from " + Utils.DOM._formatNode(source) +
" to " + Utils.DOM._formatNode(target) );
var attrs = source.attributes;
+ var exclusions = (opts && opts.exclude) ? opts.exclude : [];
+
for(var i = 0 ; i < attrs.length; i++) {
var attributeNode = attrs[i];
+ var nodeName = attributeNode.nodeName;
+ var nodeValue = attributeNode.nodeValue;
- if(attributeNode.specified) {
+ if(attributeNode.specified && nodeValue && nodeValue.length > 0
&& exclusions.indexOf(nodeName) < 0) {
+ //LOG.debug("Copying attribute " + attributeNode.nodeName + "="
+ attributeNode.nodeValue);
+
var newAttributeNode =
- document.createAttribute(attributeNode.nodeName);
+ document.createAttribute(nodeName);
newAttributeNode.nodeValue = attributeNode.nodeValue;
target.setAttributeNode(newAttributeNode);
@@ -56,17 +68,138 @@
replaceNode : function(id, request) {
var target = document.getElementById(id);
var src = request.getElementById(id);
+
+ Utils.DOM.Event.removeListeners(target);
+
- var importProvider = ClientUILib.isIE ? this : document;
+ if (ClientUILib.isIE) {
+ var theDoc = document;
+ var createEl = theDoc.createElement;
+ var row = target.cloneNode(false);
+
+ this.copyAttributes(row, src);
+
+ for (var td = src.firstChild; td; td = td.nextSibling) {
+
+ var outer = td.xml;
+ var openTag = outer.indexOf('>');
+ var closeTag = outer.lastIndexOf('<');
+
+ var inner = outer.substring(openTag + 1, closeTag);
+
+ var cell = createEl(td.tagName.toUpperCase());
+
+ cell.innerHTML = inner;
+
+
+
+ this.copyAttributes(cell, td);
+ row.insertBefore(cell, null);
+ }
+
+ src = row;
+
+ } else {
+
+ src = document.importNode(src, true);
+
+ }
- src = importProvider.importNode(src, true);
+ //var importProvider = ClientUILib.isIE ? this : document;
+
+ //src = importProvider.importNode(src, true);
+
target.parentNode.replaceChild(src, target);
+
+
return src;
+ },
+
+ _formatNode : function(node) {
+
+ var sb = new StringBuilder();
+
+ sb.append("<").append(node.nodeName);
+ for (var i = 0; i < node.attributes.length; i++) {
+ var attr = node.attributes[i];
+ if (attr.specified) {
+ sb
+ .append(" ")
+ .append(attr.nodeName)
+ .append("=\"")
+ .append(attr.nodeValue)
+ .append("\" ");
+ }
+ }
+
+ sb.append("/>");
+
+ return sb.toString();
+
+ },
+
+ Event: {
+
+ /**
+ * cache listeners in element to kill them all on element ajax replace
+ * @param {Object} element
+ * @param {Object} event
+ * @param {Object} handler
+ * @param {Object} useCapture
+ */
+ observe : function (element, event, handler, useCapture) {
+ if (true) {
+ if (!element._listeners) {
+ element._listeners = [];
+ }
+
+ element._listeners[element._listeners.length] =
+ {
+ event: event,
+ handler: handler,
+ useCapture: useCapture
+ };
+ }
+ Event.observe(element, event, handler, useCapture);
+ },
+
+ stopObserving : function(element, event, handler, useCapture) {
+
+ if(element._listeners) {
+ element._listeners =
+ element._listeners.reject(
+ function(obj) {
+ return obj.event == event
+ && obj.handler == handler
+ && obj.useCapture == useCapture;
+ }
+ );
+ }
+
+ Event.stopObserving(element, event, handler, useCapture);
+
+ },
+
+ removeListeners : function(element) {
+ if (element._listeners) {
+ var l = element._listeners.length;
+ for(var i = 0; i < l; i++) {
+ var listener = element._listeners[i];
+ Event.stopObserving(
+ element,
+ listener.event,
+ listener.handler,
+ listener.useCapture);
+ }
+
+ element._listeners = null;
+ }
+ }
}
},
-
+
AJAX : {
updateRows: function(options,request,grid,clientid, callbacks){
var theDoc = document;
@@ -84,19 +217,20 @@
if(rowindex >= rowCount){
rowindex -= rowCount;
}
- var id = baseid + ":f:" + rowindex;
- var row = Utils.DOM.replaceNode(id, request);
- id = baseid + ":n:" + rowindex;
- row = Utils.DOM.replaceNode(id, request);
-
-
- [":f:", ":n:"].each(
+ //var id = baseid + ":f:" + rowindex;
+ //var row = Utils.DOM.replaceNode(id, request);
+ //id = baseid + ":n:" + rowindex;
+ //row = Utils.DOM.replaceNode(id, request);
+
+ //var suffixes =
+
+ [":f:", ":n:"].unbreakableEach(
function(suffix) {
var id = baseid + suffix + rowindex;
var row = Utils.DOM.replaceNode(id, request);
if (callbacks) {
- callbacks.each(
+ callbacks.unbreakableEach(
function(callback) {
callback.call(grid, {index : rowindex, row : row});
}
@@ -114,4 +248,10 @@
}
-}
\ No newline at end of file
+};
+
+Array.prototype.unbreakableEach = function(f) {
+ for (var i = 0; i < this.length; i++) {
+ f(this[i], i);
+ }
+};
\ No newline at end of file
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-06-11
17:17:50 UTC (rev 1124)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-06-11
17:20:51 UTC (rev 1125)
@@ -254,7 +254,7 @@
},
addListener: function(element, rowIndex) {
- Event.observe(element, "click", this.processClick.bindAsEventListener(this,
rowIndex));
+ Utils.DOM.Event.observe(element, "click",
this.processClick.bindAsEventListener(this, rowIndex));
},
/* getGridSelection: function() {
Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-11 17:17:50
UTC (rev 1124)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-11 17:20:51
UTC (rev 1125)
@@ -10,7 +10,7 @@
packages: [],
load: function(showLog) {
// Check for Prototype JavaScript framework
- /*
+
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
@@ -28,11 +28,11 @@
}).each( function(s) {
LibraryPath = s.src.replace(/ClientUILib\.js(\?.*)?$/,'');
});
- */
- /*if(showLog) {
+
+ if(showLog) {
ClientUILogger.create("ClientUILogger");
this.startTime = (new Date()).getTime();
- }*/
+ }
this.initBrowser();
},
@@ -82,21 +82,8 @@
ClientUILib.log(ClientUILogger.INFO, "ClientUILib::declarePackage '" +
libName + "'");
},
log: function(level, infoText) {
- //if(ClientUILogger.isCreated)
- //ClientUILogger.log(level, infoText);
- switch(level) {
- case ClientUILogger.INFO:
- LOG.info(infoText);
- break;
- case ClientUILogger.WARNING:
- LOG.warn(infoText);
- break;
- case ClientUILogger.ERROR:
- LOG.error(infoText);
- break;
- default:
- LOG.debug(infoText);
- }
+ if(ClientUILogger.isCreated)
+ ClientUILogger.log(level, infoText);
},
initBrowser: function() {
var ua = navigator.userAgent.toLowerCase();