You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/04/13 11:36:32 UTC
svn commit: r393774 - in /incubator/tobago/trunk/theme:
scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/
st...
Author: weber
Date: Thu Apr 13 02:36:28 2006
New Revision: 393774
URL: http://svn.apache.org/viewcvs?rev=393774&view=rev
Log:
fix javascript memory leaks
Modified:
incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
incubator/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-menu.js
incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js
incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Thu Apr 13 02:36:28 2006
@@ -148,6 +148,7 @@
writer.endElement("div");
writer.startElement("div", null);
+ writer.writeIdAttribute(clientId);
renderTabGroupView(facesContext, writer, component, virtualTab, oStyle,
switchType, image1x1);
writer.endElement("div");
@@ -163,8 +164,7 @@
final String[] cmds = {
"new Tobago.TabGroup(",
" '" + clientId + "', ",
- " '" + activeIndex + "', ",
- " '" + pageId + "');"
+ " '" + activeIndex + "');"
};
HtmlRendererUtil.writeScriptLoader(facesContext, scripts, cmds);
}
Modified: incubator/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-menu.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-menu.js?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-menu.js (original)
+++ incubator/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-menu.js Thu Apr 13 02:36:28 2006
@@ -79,6 +79,7 @@
var menu = new MenuItem();
menu.id = id + Tobago.SUB_COMPONENT_SEP + Tobago.Menu.MENU_ROOT_ID;
menu.level = 0;
+ Tobago.addJsObject(menu);
return menu;
}
Modified: incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js (original)
+++ incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tabgroup.js Thu Apr 13 02:36:28 2006
@@ -15,41 +15,72 @@
*/
-Tobago.TabGroupBase = {
- initialize: function(tabGroupId, activeIndex, page) {
- this.tabGroupId = tabGroupId,
- this.activeIndex = activeIndex;
- this.element = Tobago.element(tabGroupId + '.' + activeIndex);
- this.page = Tobago.element(page);
+Tobago.TabGroup = function(tabGroupId, activeIndex, page) {
+ this.tabGroupId = tabGroupId,
+ this.activeIndex = activeIndex;
+ this.activeTabId = tabGroupId + '.' + activeIndex;
+ LOG.debug("activeTabId : " + this.activeTabId);
+
+ Tobago.element(this.tabGroupId).jsObject = this;
+ Tobago.addJsObject(this);
+
+// var htmlId = this.tabGroupId;
+//
+// var onComplete = function() {
+// LOG.debug("htmlId = " + htmlId);
+// var obj = document.getElementById(htmlId).jsObject;
+// LOG.debug("obj = " + typeof obj);
+// obj.onComplete.apply(obj, []);
+// };
- this.options = {
+ // this.options.onComplete = this.onComplete.bind(this);
+
+ this.options = {
method: 'post',
asynchronous: true,
- onComplete: this.onComplete.bind(this),
parameters: '',
- evalScripts: true
- };
-
- this.parent = this.element.parentNode;
- this.setUp();
- },
-
- setUp: function() {
-// LOG.debug("setup tabgroup " + this.element.id);
+ evalScripts: true,
+ onComplete: Tobago.bind(this, "onComplete")
+ };
+
+ LOG.debug("opnclomplete = " + this.options.onComplete);
+
+ this.setUp();
+};
+
+Tobago.TabGroup.prototype.setUp = function() {
+ LOG.debug("tabgroup id " + this.tabGroupId);
+ LOG.debug("setup tabgroup " + this.activeTabId);
+ LOG.debug("activeIndex " + this.activeIndex);
var i = 0;
- var idPrefix = this.element.id + Tobago.SUB_COMPONENT_SEP;
+ var idPrefix = this.activeTabId + Tobago.SUB_COMPONENT_SEP;
+
+// var htmlId = this.tabGroupId;
var anchor = Tobago.element(idPrefix + i++);
while (anchor) {
-// LOG.debug("observe tab " + anchor.id);
+ LOG.debug("observe tab " + anchor.id);
// if (i != this.activeIndex) {
- Event.observe(anchor, "click", this.reload.bindAsEventListener(this));
+// Event.observe(anchor, "click", this.reload.bindAsEventListener(this));
// }
+
+// var onClick = function(event) {
+// LOG.debug("htmlId = " + htmlId);
+// var obj = document.getElementById(htmlId).jsObject;
+// LOG.debug("obj = " + obj);
+// LOG.debug("obj.reload = " + obj.reload);
+// obj.reload.call(obj, event);
+// };
+
+// Tobago.addEventListener(anchor, "click", onClick);
+ Tobago.addBindEventListener(anchor, "click", this, "reload");
anchor = Tobago.element(idPrefix + i++);
}
- },
- reload: function(event) {
+};
+
+Tobago.TabGroup.prototype.reload = function(event) {
+ LOG.debug("Reload ");
if (event) {
var element = Tobago.element(event);
var aId = Tobago.findAnchestorWithTagName(element, 'span').id;
@@ -66,7 +97,8 @@
}
if (Tobago.Updater.hasTransport()) {
this.removeRelatedAcceleratorKeys(aId.substring(0, aId.lastIndexOf(Tobago.SUB_COMPONENT_SEP) + Tobago.SUB_COMPONENT_SEP.length));
- Tobago.Updater.update(this.parent, this.page, this.tabGroupId, this.tabGroupId, this.options);
+ var container = Tobago.element(this.tabGroupId);
+ Tobago.Updater.update(container, Tobago.page, this.tabGroupId, this.tabGroupId, this.options);
} else {
Tobago.submitAction(this.tabGroupId);
}
@@ -74,9 +106,9 @@
LOG.info("No reload Event");
}
- },
+};
- removeRelatedAcceleratorKeys: function(idPrefix) {
+Tobago.TabGroup.prototype.removeRelatedAcceleratorKeys = function(idPrefix) {
var regex = new RegExp("Tobago.clickOnElement\\(\"" + idPrefix);
for (var name in Tobago.acceleratorKeys) {
if (typeof Tobago.acceleratorKeys[name] == 'object'
@@ -85,15 +117,11 @@
Tobago.acceleratorKeys.remove(Tobago.acceleratorKeys[name]);
}
}
- },
+};
- onComplete: function(request) {
+Tobago.TabGroup.prototype.onComplete = function(request) {
LOG.debug("tabgroup loaded : ");
- this.element = this.parent.firstChild;
+ this.activeTabId = Tobago.element(this.tabGroupId).firstChild.id;
+ LOG.debug("activeTabId : " + this.activeTabId);
this.setUp();
- }
-
-}
-
-Tobago.TabGroup = Class.create();
-Tobago.TabGroup.prototype = Object.extend(new Ajax.Base(), Tobago.TabGroupBase);
+};
Modified: incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js (original)
+++ incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js Thu Apr 13 02:36:28 2006
@@ -16,6 +16,29 @@
Tobago.Menu = {
- MENU_ROOT_ID : "menuroot"
-
+ MENU_ROOT_ID : "menuroot",
+
+ destroy: function(node) {
+ if (!node.addMenuItem) {
+ return;
+ }
+
+ this.deleteReferences(node);
+ for (var i = 0; i < node.subItems.length; i++) {
+ this.destroy(node.subItems[i]);
+ }
+ },
+
+ deleteReferences: function(node) {
+ if (node.menubar) {
+ delete node.menubar.menu;
+ delete node.menubar;
+ }
+ if (node.htmlElement) {
+ delete node.htmlElement.menuItem;
+ delete node.htmlElement;
+ delete node.subItemContainer;
+ delete node.subItemIframe;
+ }
+ }
}
Modified: incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Thu Apr 13 02:36:28 2006
@@ -49,11 +49,11 @@
this.oldX = 0;
this.newWidth = 0;
- this.outerDiv = Tobago.element(this.id + "_outer_div");
-
- if (this.ajaxEnabled) {
- this.prototype = new Ajax.Base();
- }
+ this.outerDivId = this.id + "_outer_div";
+ this.headerDivId = this.id + "_header_div";
+ this.contentDivId = this.id + "_data_div";
+ this.selectedId = this.id + Tobago.SUB_COMPONENT_SEP +"selected";
+ this.headerWidthsId = this.id + Tobago.SUB_COMPONENT_SEP + "widths"
this.sortOnclickRegExp
= new RegExp("Tobago.submitAction\\(('|\")(.*?)('|\")\\)");
@@ -72,17 +72,10 @@
this.firstRowRegExp = new RegExp("^" + this.id + "_data_tr_\\d+$");
this.setupElements = function() {
- this.headerDiv = Tobago.element(this.id + "_header_div");
- this.contentDiv = Tobago.element(this.id + "_data_div");
- this.contentTable = this.contentDiv.getElementsByTagName("table")[0];
-
- this.selected
- = Tobago.element(this.id + Tobago.SUB_COMPONENT_SEP +"selected");
- this.headerWidths = Tobago.element(this.id + "::widths");
-
- this.firstRow = this.getFirstRow();
- this.firstRowIndex = (this.firstRow != undefined)
- ? this.firstRow.id.substring(this.firstRow.id.lastIndexOf("_data_tr_") + 9)
+
+ this.firstRowId = this.getFirstRowId();
+ this.firstRowIndex = (this.firstRowId != undefined)
+ ? this.firstRowId.substring(this.firstRowId.lastIndexOf("_data_tr_") + 9)
: -1;
};
@@ -188,7 +181,7 @@
hidden.type = 'hidden';
hidden.value = page;
hidden.name = action + Tobago.SUB_COMPONENT_SEP + "value";
- this.outerDiv.appendChild(hidden);
+ Tobago.element(this.outerDivId).appendChild(hidden);
this.reloadWithAction(action);
};
@@ -210,7 +203,8 @@
this.reloadWithAction = function(action) {
LOG.debug("reload sheet with action \"" + action + "\"");
- Tobago.Updater.update(this.outerDiv, null, action, this.id, this.options);
+ var divElement = Tobago.element(this.outerDivId);
+ Tobago.Updater.update(divElement, null, action, this.id, this.options);
};
@@ -299,9 +293,11 @@
this.setupResizer = function() {
var i = 0;
- Tobago.addBindEventListener(this.headerDiv, "mousemove", this, "doResize");
- Tobago.addBindEventListener(this.headerDiv, "mouseup", this, "endResize");
- Tobago.addBindEventListener(this.contentDiv, "scroll", this, "doScroll");
+ var headerDiv = Tobago.element(this.headerDivId);
+ var contentDiv = Tobago.element(this.contentDivId)
+ Tobago.addBindEventListener(headerDiv, "mousemove", this, "doResize");
+ Tobago.addBindEventListener(headerDiv, "mouseup", this, "endResize");
+ Tobago.addBindEventListener(contentDiv, "scroll", this, "doScroll");
var resizer = Tobago.element(this.id + "_header_resizer_" + i++ );
while (resizer) {
if (resizer.className.match(/tobago-sheet-header-resize-cursor/)) {
@@ -317,8 +313,9 @@
// ToDo: find a better way to fix this problem
// IE needs this in case of ajax loading of style classes
- this.outerDiv.className = this.outerDiv.className;
- this.outerDiv.innerHTML = this.outerDiv.innerHTML;
+ var outerDiv = Tobago.element(this.outerDivId);
+ outerDiv.className = outerDiv.className;
+ outerDiv.innerHTML = outerDiv.innerHTML;
this.setupElements();
@@ -329,7 +326,7 @@
this.setupHeader();
- if (this.firstRow) {
+ if (this.firstRowId) {
this.tobagoLastClickedRowId = this.firstRowIndex;
}
this.addSelectionListener();
@@ -347,12 +344,14 @@
this.adjustScrollBars = function() {
var dataFiller = Tobago.element(this.id + "_data_row_0_column_filler");
if (dataFiller) {
- var tableWidth = this.contentTable.style.width;
- this.contentTable.style.width = "10px";
+ var contentDiv = Tobago.element(this.contentDivId);
+ var contentTable = contentDiv.getElementsByTagName("table")[0];
+ var tableWidth = contentTable.style.width;
+ contentTable.style.width = "10px";
dataFiller.style.width = "0px";
- var clientWidth = this.contentDiv.clientWidth;
+ var clientWidth = contentDiv.clientWidth;
- if (this.contentDiv.scrollWidth <= clientWidth) {
+ if (contentDiv.scrollWidth <= clientWidth) {
var width = 0;
var i = 0;
var cellDiv = Tobago.element(this.id + "_data_row_0_column" + i++);
@@ -363,12 +362,12 @@
}
dataFiller.style.width = Math.max((clientWidth - width), 0) + "px";
}
- this.contentTable.style.width = tableWidth;
+ contentTable.style.width = tableWidth;
}
};
this.addSelectionListener = function() {
- var row = this.firstRow;
+ var row = Tobago.element(this.firstRowId);
if (row) {
var i = this.firstRowIndex;
i++;
@@ -406,7 +405,7 @@
if (! event.ctrlKey && ! selector) {
// clearAllSelections();
- this.selected.value = "";
+ Tobago.element(this.selectedId).value = "";
}
if (event.shiftKey) {
@@ -422,8 +421,8 @@
};
this.updateSelectionView = function(sheetId) {
- var selected = this.selected.value;
- var row = this.firstRow;
+ var selected = Tobago.element(this.selectedId).value;
+ var row = Tobago.element(this.firstRowId);
var i = this.firstRowIndex;
while (row) {
@@ -461,11 +460,12 @@
var selector = Tobago.element(this.id + "_data_row_selector_" + rowIndex);
if (!selector || !selector.src.match(/Disabled/)) {
var re = new RegExp("," + rowIndex + ",");
- if (this.selected.value.search(re) != -1) {
- this.selected.value = this.selected.value.replace(re, "");
+ var selected = Tobago.element(this.selectedId);
+ if (selected.value.search(re) != -1) {
+ selected.value = selected.value.replace(re, "");
}
else {
- this.selected.value = this.selected.value + "," + rowIndex + ",";
+ selected.value = selected.value + "," + rowIndex + ",";
}
}
};
@@ -484,25 +484,26 @@
start = firstIndex;
end = lastIndex;
}
+ var selected = Tobago.element(this.selectedId);
for (var i = start; i <= end; i++) {
var re = new RegExp("," + i + ",");
- if (this.selected.value.search(re) == -1) {
+ if (selected.value.search(re) == -1) {
var selector = Tobago.element(this.id + "_data_row_selector_" + i);
if (!selector || !selector.src.match(/Disabled/)) {
- this.selected.value = this.selected.value + "," + i + ",";
+ selected.value = selected.value + "," + i + ",";
}
}
}
};
- this.getFirstRow = function() {
+ this.getFirstRowId = function() {
var element = Tobago.element(this.id + "_data_row_0_column0");// data div
while (element && element.id.search(this.firstRowRegExp) == -1) {
// LOG.debug("element id = " + element.id);
element = element.parentNode;
}
-// LOG.debug("element id = " + element.id);
- return element;
+// LOG.debug("firstRowId = " + element.id);
+ return element ? element.id : undefined;
};
this.setupHeader = function() {
@@ -537,9 +538,12 @@
};
this.adjustHeaderDiv = function () {
- this.contentTable.style.width = "10px";
- var contentWidth = this.contentDiv.style.width.replace(/px/, "") - 0;
- var clientWidth = this.contentDiv.clientWidth;
+ var headerDiv = Tobago.element(this.headerDivId);
+ var contentDiv = Tobago.element(this.contentDivId);
+ var contentTable = contentDiv.getElementsByTagName("table")[0];
+ contentTable.style.width = "10px";
+ var contentWidth = contentDiv.style.width.replace(/px/, "") - 0;
+ var clientWidth = contentDiv.clientWidth;
var boxSum = 0;
var idx = 0;
var box = Tobago.element(this.id + "_header_box_" + idx++);
@@ -553,18 +557,18 @@
var minWidth = contentWidth - Tobago.Config.get("Sheet", "scrollbarWidth")
- Tobago.Config.get("Sheet", "contentBorderWidth");
minWidth = Math.max(minWidth, 0); // not less than 0
- this.headerDiv.style.width = Math.max(clientWidth, minWidth);
+ headerDiv.style.width = Math.max(clientWidth, minWidth);
var fillBox = Tobago.element(this.id + "_header_box_filler");
- fillBox.style.width = Math.max(this.headerDiv.style.width.replace(/px/, "") - boxSum, 0);
+ fillBox.style.width = Math.max(headerDiv.style.width.replace(/px/, "") - boxSum, 0);
// LOG.debug("adjustHeaderDiv(" + sheetId + ") : clientWidth = " + clientWidth + " :: width => " + headerDiv.style.width);
//headerDiv.style.width = clientWidth;
- var clientWidth2 = this.contentDiv.clientWidth;
+ var clientWidth2 = contentDiv.clientWidth;
if (clientWidth > clientWidth2) {
// IE needs this
- this.headerDiv.style.width = Math.max(clientWidth2, minWidth);
+ headerDiv.style.width = Math.max(clientWidth2, minWidth);
// LOG.debug("second time adjustHeaderDiv(" + sheetId + ") : clientWidth2 = " + clientWidth2 + " :: width => " + headerDiv.style.width);
}
- this.contentTable.style.width = this.contentDiv.clientWidth + "px";
+ contentTable.style.width = contentDiv.clientWidth + "px";
// LOG.debug("div width :" + contentDiv.clientWidth);
// LOG.debug("table width :" + contentTable.clientWidth);
// LOG.debug("boxSum :" + boxSum);
@@ -645,12 +649,13 @@
widths = widths + "," + width;
header = Tobago.element(idPrefix + index++);
}
- this.headerWidths.value = widths;
+ Tobago.element(this.headerWidths).value = widths;
};
this.doScroll = function(event) {
//LOG.debug("header / data " + this.headerDiv.scrollLeft + "/" + this.contentDiv.scrollLeft);
- this.headerDiv.scrollLeft = this.contentDiv.scrollLeft;
+ Tobago.element(this.headerDivId).scrollLeft
+ = Tobago.element(this.contentDivId).scrollLeft;
//LOG.debug("header / data " + this.headerDiv.scrollLeft + "/" + this.contentDiv.scrollLeft);
//LOG.debug("----------------------------------------------");
};
@@ -658,14 +663,15 @@
this.selectAll = function() {
- var row = this.firstRow;
+ var row = Tobago.element(this.firstRowId);
var i = this.firstRowIndex;
+ var selected = Tobago.element(this.selectedId);
while (row) {
var selector = Tobago.element(this.id + "_data_row_selector_" + i);
if (!selector || !selector.src.match(/Disabled/)) {
var re = new RegExp("," + i + ",");
- if (this.selected.value.search(re) == -1) {
- this.selected.value = this.selected.value + "," + i + ",";
+ if (selected.value.search(re) == -1) {
+ selected.value = selected.value + "," + i + ",";
}
}
row = Tobago.element(this.id + "_data_tr_" + ++i );
@@ -674,7 +680,8 @@
};
this.unSelectAll = function() {
- var row = this.firstRow;
+ var selected = Tobago.element(this.selectedId);
+ var row = Tobago.element(this.firstRowId);
var selector = Tobago.element(this.id + "_data_row_selector_" + i);
if (selector) {
var i = this.firstRowIndex;
@@ -682,18 +689,18 @@
selector = Tobago.element(this.id + "_data_row_selector_" + i);
if (!selector || !selector.src.match(/Disabled/)) {
var re = new RegExp("," + i + ",", 'g');
- this.selected.value = this.selected.value.replace(re, "");
+ selected.value = selected.value.replace(re, "");
}
row = Tobago.element(this.id + "_data_tr_" + ++i );
}
} else {
- this.selected.value = "";
+ selected.value = "";
}
this.updateSelectionView();
};
this.toggleAllSelections = function(sheetId) {
- var row = this.firstRow;
+ var row = Tobago.element(this.firstRowId);
var i = this.firstRowIndex;
while (row) {
this.toggleSelection(i);
Modified: incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=393774&r1=393773&r2=393774&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ incubator/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Thu Apr 13 02:36:28 2006
@@ -60,8 +60,20 @@
*/
focusId: null,
+ htmlIdIndex: 0,
+
+ createHtmlId: function() {
+ var id = "__tbg_id_" + this.htmlIdIndex++;
+ LOG.debug("created id = " + id);
+ return id;
+ },
+
images: {},
+ jsObjects: new Array(),
+
+ eventListeners: new Array(),
+
acceleratorKeys: {
set: function(keyAccelerator) {
var key = keyAccelerator.modifier + keyAccelerator.key;
@@ -200,6 +212,60 @@
} else if (!this.isSubmit && this.applicationOnexit) {
this.applicationOnexit();
}
+ this.destroyObjects();
+ },
+
+ addJsObject: function(obj) {
+ this.jsObjects[this.jsObjects.length] = obj;
+ },
+
+ destroyObjects: function() {
+ delete this.page;
+ delete this.form;
+ delete this.action;
+ this.removeEventListeners();
+ for (var i = 0; i < this.jsObjects.length; i++) {
+ this.destroyObject(this.jsObjects[i]);
+ }
+ this.jsObjects.length = 0;
+ delete this.jsObjects;
+ },
+
+ removeEventListeners: function() {
+ var count = 0;
+ for (var i = 0; i < this.eventListeners.length; i++) {
+ var el = this.eventListeners[i];
+ this.removeEventListener(el);
+ delete el.element;
+ delete el.event;
+ delete el.func;
+ this.eventListeners[i] = undefined;
+ count++;
+ }
+ delete this.eventListeners;
+// alert(count + " EverntListener geloescht");
+ },
+
+ destroyObject: function(obj) {
+ if (obj.addMenuItem) {
+ // Menu Object
+ Tobago.Menu.destroy(obj);
+ } else if (obj.htmlElement) {
+ // test
+ delete obj.htmlElement.jsObjects;
+ delete obj.htmlElement;
+ }
+ else {
+ // Unknown Object --> delete all properties
+ if (typeof obj == 'Object') {
+ for (var name in obj) {
+ delete obj[name];
+ }
+ } else if (typeof obj == 'Array') {
+ obj.length = 0;
+ }
+ }
+
},
/**
@@ -757,10 +823,11 @@
* Add a eventListener to a htmlElement
*/
addEventListener: function(element, event, myFunction) {
- if (element.addEventListener) { // this is DOM2
- element.addEventListener(event, myFunction, false);
+ var el = new Tobago.EventListener(element, event, myFunction);
+ if (el.element.addEventListener) { // this is DOM2
+ el.element.addEventListener(el.event, el.func, false);
} else { // IE
- element.attachEvent("on" + event, myFunction);
+ el.element.attachEvent("on" + el.event, el.func);
}
},
@@ -768,6 +835,11 @@
* Remove a eventListener from a htmlElement
*/
removeEventListener: function(element, event, myFunction) {
+ if (!event && !myFunction && element.element && element.event && element.func) {
+ myFunction = element.func;
+ event = element.event;
+ element = element.element;
+ }
if (element.removeEventListener) { // this is DOM2
element.removeEventListener(event, myFunction, true);
}
@@ -975,7 +1047,9 @@
} catch(ex) {
return undefined;
}
+ if (! (typeof arg == 'undefined')) {
LOG.error("arg ist unbekannt : " + typeof arg + " : " + arg);
+ }
return undefined;
}
};
@@ -987,6 +1061,13 @@
this.disabled = disabled;
this.hover = hover;
Tobago.images[id] = this;
+};
+
+Tobago.EventListener = function(element, event, func) {
+ this.element = element;
+ this.event = event;
+ this.func = func;
+ Tobago.eventListeners[Tobago.eventListeners.length] = this;
};
Tobago.AcceleratorKey = function(func, key, modifier) {