Author: dbiatenia
Date: 2007-05-25 11:59:38 -0400 (Fri, 25 May 2007)
New Revision: 887
Modified:
trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
Log:
Modified:
trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
===================================================================
---
trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2007-05-25
15:08:52 UTC (rev 886)
+++
trunk/richfaces/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2007-05-25
15:59:38 UTC (rev 887)
@@ -1,338 +1,350 @@
-if (!window.DW) {
- window.DW = {};
-}
-
-if (!window.Richfaces) {
- window.Richfaces = {};
-}
-
-var PanelMenuStorage = new Object();
-PanelMenu = Class.create();
-PanelMenu.prototype = {
- initialize: function(myId,so){
- this.childObj = new Array();
- this.expandSingle = so;
- this.lastExpanded = null;
- this.is = 'panelMenu';
- PanelMenuStorage[myId] = this;}};
-PanelMenuItem = Class.create();
-PanelMenuItem.prototype = {
- initialize: function(ids, options, hoveredStyles, hoveredClasses, level,
haveDynamicIcon, action, opened, ajaxFunction, iconAlign, iconExpanded, iconCollapsed,
iconSpacer){
- if (!ids.parentId){return};
- this.type = options.type;
- this.onopen = options.onopen;
- this.onclose = options.onclose;
- this.event = options.event;
-
- this.mode = options.mode;
- if (!this.mode)
- this.mode = ("node" == this.type) ? "none" : "server";
-
- this.ajaxSubmit = ajaxFunction;
- this.target = options.target;
-
- this.hoveredStyles = hoveredStyles;
- this.hoveredClasses = hoveredClasses;
- this.tdhider = $("tdhide"+ids.myId);
- this.tablehider = $("tablehide"+ids.myId);
- this.haveDynamicIcon = haveDynamicIcon;
- if (this.haveDynamicIcon==true)
- this.iconswitcher = $("icon"+ids.myId);
- this.childObj = new Array();
- this.parentObj = PanelMenuStorage[ids.parentId];
- this.parentObj.childObj.push(this);
- var parent = this.parentObj;
- while (parent) {
- if (parent.is && "panelMenu" == parent.is) {
- this.expandSingle = parent.expandSingle;
- break;
- }
- parent = parent.parentObj;
- }
- this.obj = $(ids.myId);
- this.content = this._getDirectChildrenByTag(this.obj,"TD")[level+1];
- this.iconAlign = iconAlign;
- if (level == 0){
- this.tdhider.style.display = "";
- this.tablehider.style.display = "";
- } else if
(this._getDirectChildrenByTag(this.content,"INPUT")[0].value!="closed"){
- this.tdhider.style.display = "";
- this.tablehider.style.display = "";
- }
- this.iconCollapsed = iconCollapsed;
- this.iconExpanded = iconExpanded;
- this.iconSpacer = iconSpacer;
- if(action){
- this.action = action;
- }
- PanelMenuStorage[ids.myId] = this;
- this._attachBehaviors();
- this.inputs = this._getDirectChildrenByTag(this.content,"INPUT");
- for (var i=0;i<this.inputs.length;i++){
- if (this.inputs[i].name.indexOf("panelMenuState")!=-1){
- this.inputState = this.inputs[i];
- } else if (this.inputs[i].name.indexOf("panelMenuAction")!=-1){
- this.inputAction = this.inputs[i];
- }
- }
- if (opened){
- this.parentObj.lastExpanded = this;
- this.expand();
- } else {
- this.expanded = false;
- }
- if (this.parentObj.type=="node"&&this.parentObj.expanded){
- if (this.type=="node")
- this.tdhider.style.display="";
- }
- },
-
- collapse: function(){
- if (this.expanded){
- if (this._getDirectChildrenByTag(this.content,"INPUT")[0]!=null){
- this._getDirectChildrenByTag(this.content,"INPUT")[0].value="closed";}
- for (var i = 0; i < this.childObj.length; i++){
- if
(this.childObj[i]._getDirectChildrenByTag(this.childObj[i].content,"INPUT")[0]!=null){
- this.childObj[i]._getDirectChildrenByTag(this.childObj[i].content,"INPUT")[0].value="";}
- if (this.haveDynamicIcon){
- var img = null
- if (this.iconAlign=="right"){
- img =
this._getDirectChildrenByTag(this.iconswitcher.nextSibling,"IMG")[0];
- } else {
- img =
this._getDirectChildrenByTag(this.iconswitcher.previousSibling,"IMG")[0];
- }
- if (img!=null){
- if (this.iconCollapsed!="none"){
- if (this.iconCollapsed!=null) {
- img.src = this.iconCollapsed;
- } else {
- img.src = this.iconSpacer;
- }
- }
- }
- }
- this.childObj[i].collapse();
- this.childObj[i].hide();
- this.childObj[i].tdhider.style.display="none";
- this.childObj[i].tablehider.style.display="none";
- }
- }
- this.expanded = false;
- },
- hide: function(){
- this.obj.style.display = 'none';
- this.inputState.value="closed";
- },
- expand: function(){
- if (!this.expanded){
- if (this._getDirectChildrenByTag(this.content,"INPUT")[0]!=null){
- this.inputState.value="opened";
- }
- if (this.haveDynamicIcon){
- var img = null
- if (this.iconAlign=="right"){
- img =
this._getDirectChildrenByTag(this.iconswitcher.nextSibling,"IMG")[0];
- } else {
- img =
this._getDirectChildrenByTag(this.iconswitcher.previousSibling,"IMG")[0];
- }
- if (img!=null){
- if (this.iconExpanded!="none"){
- if (this.iconExpanded!=null) {
- img.src = this.iconExpanded;
- } else {
- img.src = this.iconSpacer;}}}}
- for (var i = 0; i < this.childObj.length; i++){
- this.childObj[i].show();
- }
- }
- this.expanded = true;
- },
-
- show: function(){
- if (this.type!="node")
- this.inputState.value="opened";
- this.tdhider.style.display="";
- this.tablehider.style.display="";
- this.obj.style.display = "";
- },
-
- preTrigger:function(e){
- this.inputAction.setAttribute('value', this.obj.id);
- },
-
- trigger:function(e){
- if ("none" == this.mode)
- return;
- if (this.action !="panelMenuItemAction"){
- this.preTrigger(e);
- var form = Event.findElement(e, "form");
- if(!form || typeof(form) == 'undefined' || !form.tagName ||
form.tagName.toLowerCase() != 'form'){
- form = document.createElement('form');
- form.setAttribute('method', 'post');
- form.setAttribute('enctype', 'application/x-www-form-urlencoded');
- form.action = action;
- document.body.appendChild(form);
- }
- if ("server" == this.mode) {
- if (this.target)
- form.target = this.target;
- form.submit();
- }
- else if ("ajax" == this.mode) {
- var event = e;
- eval(this.ajaxSubmit);
- }
- }
- },
-
- itemClicked: function(e){
- if(this.action){
- if (this.action=='panelMenuNodeAction'){
- if (this.expanded){
- if ("node" == this.type){
- if (new Function(this.onclose+";return true;")()){
- this.collapse();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- } else {
- if (this.parentObj.expandSingle){
- if (this.parentObj.lastExpanded!=null){
- this.parentObj.lastExpanded.collapse();
- }
- if ("node" == this.type){
- if (new Function(this.onopen+";return true;")()){
- this.expand();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- this.parentObj.lastExpanded = this;
- } else {
- if ("node" == this.type){
- if (new Function(this.onopen+";return true;")()){
- this.expand();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- }
- }
- }
- } else {
- if (this.expanded){
- if ("node" == this.type){
- if (new Function(this.onclose + ";return true;")()){
- this.collapse();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- } else {
- if (this.parentObj.expandSingle){
- if (this.parentObj.lastExpanded!=null){
- this.parentObj.lastExpanded.collapse();
- }
- if ("node" == this.type){
- if (new Function(this.onopen+";return true;")()){
- this.expand();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- this.parentObj.lastExpanded = this;
- } else {
- if ("node" == this.type){
- if (new Function(this.onopen+";return true;")()){
- this.expand();
- }
- }
- if (this.action){
- this.trigger(e);
- }
- }
- }
- }
- },
-
- addHoverStyles: function(e) {
- if (this.hoveredStyles) {
- Element.setStyle(this.obj, this.hoveredStyles);
- }
- if (this.hoveredClasses)
- for (i = 0; i < this.hoveredClasses.length; i++)
- this.obj.addClassName(this.hoveredClasses[i]);
- },
-
- removeHoverStyles: function(e) {
- if (this.hoveredClasses)
- for (var i = 0; i < this.hoveredClasses.length; i++)
- this.obj.removeClassName(this.hoveredClasses[i]);
- },
-
- _getDirectChildrenByTag: function(e, tagName) {
- var allKids = e.childNodes;
- var kids = new Array();
- var ddk;
- tagName = tagName.toLowerCase();
- for( var i = 0 ; i < allKids.length ; i++ )
- if ( allKids[i] && allKids[i].tagName &&
allKids[i].tagName.toLowerCase() == tagName )
- kids.push(allKids[i]);
- return kids;
- },
-
- _fireEditEvent: function(e){
- if( document.createEvent ) {
- var evObj = document.createEvent('HTMLEvents');
- evObj.initEvent( e, true, false );
- this.edit.dispatchEvent(evObj);
- } else if( document.createEventObject ) {
- this.edit.fireEvent('on' + e);
- }
- },
-
- _attachBehaviors: function() {
- if (this.event)
- Event.observe(this.obj, this.event, this.itemClicked.bindAsEventListener(this),
false);
- else
- Event.observe(this.obj, "click", this.itemClicked.bindAsEventListener(this),
false);
- Event.observe(this.obj, "mouseover",
this.addHoverStyles.bindAsEventListener(this), false);
- Event.observe(this.obj, "mouseout",
this.removeHoverStyles.bindAsEventListener(this), false);
- }
-};
-
-PanelMenu.doExpand = function (id) {
- var group = PanelMenuStorage[id];
- if (group && group.type && "node" == group.type) {
- var parent = group.parentObj;
- if (parent.expandSingle){
- if (group.parentObj.lastExpanded!=null){
- group.parentObj.lastExpanded.collapse();
- }
- }
- while (parent) {
- if (parent.type && "node" == parent.type) {
- parent.expand();
- }
- parent = parent.parentObj;
- }
- if (!group.expanded && new Function(group.onopen+";return
true;")()){
- group.expand();
- }
- }
-}
-
-PanelMenu.doCollapse = function (id) {
- var group = PanelMenuStorage[id];
- if (group && group.type && "node" == group.type) {
- if (group.expanded && new Function(group.onclose+";return
true;")()){
- group.collapse();
- }
- }
-}
\ No newline at end of file
+if (!window.DW) {
+ window.DW = {};
+}
+
+if (!window.Richfaces) {
+ window.Richfaces = {};
+}
+
+var PanelMenuStorage = new Object();
+PanelMenu = Class.create();
+PanelMenu.prototype = {
+ initialize: function(myId,so){
+ this.childObj = new Array();
+ this.expandSingle = so;
+ this.lastExpanded = null;
+ this.is = 'panelMenu';
+ PanelMenuStorage[myId] = this;}};
+PanelMenuItem = Class.create();
+PanelMenuItem.prototype = {
+ initialize: function(ids, options, hoveredStyles, hoveredClasses, level,
haveDynamicIcon, action, opened, ajaxFunction, iconAlign, iconExpanded, iconCollapsed,
iconSpacer){
+ if (!ids.parentId){return};
+ this.type = options.type;
+ this.onopen = options.onopen;
+ this.onclose = options.onclose;
+ this.event = options.event;
+
+ this.mode = options.mode;
+ if (!this.mode)
+ this.mode = ("node" == this.type) ? "none" : "server";
+
+ this.ajaxSubmit = ajaxFunction;
+ this.target = options.target;
+
+ this.hoveredStyles = hoveredStyles;
+ this.hoveredClasses = hoveredClasses;
+ this.tdhider = $("tdhide"+ids.myId);
+ this.tablehider = $("tablehide"+ids.myId);
+ this.haveDynamicIcon = haveDynamicIcon;
+ if (this.haveDynamicIcon==true)
+ this.iconswitcher = $("icon"+ids.myId);
+ this.childObj = new Array();
+ this.parentObj = PanelMenuStorage[ids.parentId];
+ this.parentObj.childObj.push(this);
+ var parent = this.parentObj;
+ while (parent) {
+ if (parent.is && "panelMenu" == parent.is) {
+ this.expandSingle = parent.expandSingle;
+ break;
+ }
+ parent = parent.parentObj;
+ }
+ this.obj = $(ids.myId);
+ this.content = this._getDirectChildrenByTag(this.obj,"TD")[level+1];
+ this.iconAlign = iconAlign;
+ if (level == 0){
+ this.tdhider.style.display = "";
+ this.tablehider.style.display = "";
+ } else if
(this._getDirectChildrenByTag(this.content,"INPUT")[0].value!="closed"){
+ this.tdhider.style.display = "";
+ this.tablehider.style.display = "";
+ }
+ this.iconCollapsed = iconCollapsed;
+ this.iconExpanded = iconExpanded;
+ this.iconSpacer = iconSpacer;
+ if(action){
+ this.action = action;
+ }
+ PanelMenuStorage[ids.myId] = this;
+
+ this.initialStyles=null;
+ this.hasInitialSylesChecked=false;
+
+ this._attachBehaviors();
+ this.inputs = this._getDirectChildrenByTag(this.content,"INPUT");
+ for (var i=0;i<this.inputs.length;i++){
+ if (this.inputs[i].name.indexOf("panelMenuState")!=-1){
+ this.inputState = this.inputs[i];
+ } else if (this.inputs[i].name.indexOf("panelMenuAction")!=-1){
+ this.inputAction = this.inputs[i];
+ }
+ }
+ if (opened){
+ this.parentObj.lastExpanded = this;
+ this.expand();
+ } else {
+ this.expanded = false;
+ }
+ if (this.parentObj.type=="node"&&this.parentObj.expanded){
+ if (this.type=="node")
+ this.tdhider.style.display="";
+ }
+ },
+
+ collapse: function(){
+ if (this.expanded){
+ if (this._getDirectChildrenByTag(this.content,"INPUT")[0]!=null){
+ this._getDirectChildrenByTag(this.content,"INPUT")[0].value="closed";}
+ for (var i = 0; i < this.childObj.length; i++){
+ if
(this.childObj[i]._getDirectChildrenByTag(this.childObj[i].content,"INPUT")[0]!=null){
+ this.childObj[i]._getDirectChildrenByTag(this.childObj[i].content,"INPUT")[0].value="";}
+ if (this.haveDynamicIcon){
+ var img = null
+ if (this.iconAlign=="right"){
+ img =
this._getDirectChildrenByTag(this.iconswitcher.nextSibling,"IMG")[0];
+ } else {
+ img =
this._getDirectChildrenByTag(this.iconswitcher.previousSibling,"IMG")[0];
+ }
+ if (img!=null){
+ if (this.iconCollapsed!="none"){
+ if (this.iconCollapsed!=null) {
+ img.src = this.iconCollapsed;
+ } else {
+ img.src = this.iconSpacer;
+ }
+ }
+ }
+ }
+ this.childObj[i].collapse();
+ this.childObj[i].hide();
+ this.childObj[i].tdhider.style.display="none";
+ this.childObj[i].tablehider.style.display="none";
+ }
+ }
+ this.expanded = false;
+ },
+ hide: function(){
+ this.obj.style.display = 'none';
+ this.inputState.value="closed";
+ },
+ expand: function(){
+ if (!this.expanded){
+ if (this._getDirectChildrenByTag(this.content,"INPUT")[0]!=null){
+ this.inputState.value="opened";
+ }
+ if (this.haveDynamicIcon){
+ var img = null
+ if (this.iconAlign=="right"){
+ img =
this._getDirectChildrenByTag(this.iconswitcher.nextSibling,"IMG")[0];
+ } else {
+ img =
this._getDirectChildrenByTag(this.iconswitcher.previousSibling,"IMG")[0];
+ }
+ if (img!=null){
+ if (this.iconExpanded!="none"){
+ if (this.iconExpanded!=null) {
+ img.src = this.iconExpanded;
+ } else {
+ img.src = this.iconSpacer;}}}}
+ for (var i = 0; i < this.childObj.length; i++){
+ this.childObj[i].show();
+ }
+ }
+ this.expanded = true;
+ },
+
+ show: function(){
+ if (this.type!="node")
+ this.inputState.value="opened";
+ this.tdhider.style.display="";
+ this.tablehider.style.display="";
+ this.obj.style.display = "";
+ },
+
+ preTrigger:function(e){
+ this.inputAction.setAttribute('value', this.obj.id);
+ },
+
+ trigger:function(e){
+ if ("none" == this.mode)
+ return;
+ if (this.action !="panelMenuItemAction"){
+ this.preTrigger(e);
+ var form = Event.findElement(e, "form");
+ if(!form || typeof(form) == 'undefined' || !form.tagName ||
form.tagName.toLowerCase() != 'form'){
+ form = document.createElement('form');
+ form.setAttribute('method', 'post');
+ form.setAttribute('enctype', 'application/x-www-form-urlencoded');
+ form.action = action;
+ document.body.appendChild(form);
+ }
+ if ("server" == this.mode) {
+ if (this.target)
+ form.target = this.target;
+ form.submit();
+ }
+ else if ("ajax" == this.mode) {
+ var event = e;
+ eval(this.ajaxSubmit);
+ }
+ }
+ },
+
+ itemClicked: function(e){
+ if(this.action){
+ if (this.action=='panelMenuNodeAction'){
+ if (this.expanded){
+ if ("node" == this.type){
+ if (new Function(this.onclose+";return true;")()){
+ this.collapse();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ } else {
+ if (this.parentObj.expandSingle){
+ if (this.parentObj.lastExpanded!=null){
+ this.parentObj.lastExpanded.collapse();
+ }
+ if ("node" == this.type){
+ if (new Function(this.onopen+";return true;")()){
+ this.expand();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ this.parentObj.lastExpanded = this;
+ } else {
+ if ("node" == this.type){
+ if (new Function(this.onopen+";return true;")()){
+ this.expand();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ }
+ }
+ }
+ } else {
+ if (this.expanded){
+ if ("node" == this.type){
+ if (new Function(this.onclose + ";return true;")()){
+ this.collapse();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ } else {
+ if (this.parentObj.expandSingle){
+ if (this.parentObj.lastExpanded!=null){
+ this.parentObj.lastExpanded.collapse();
+ }
+ if ("node" == this.type){
+ if (new Function(this.onopen+";return true;")()){
+ this.expand();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ this.parentObj.lastExpanded = this;
+ } else {
+ if ("node" == this.type){
+ if (new Function(this.onopen+";return true;")()){
+ this.expand();
+ }
+ }
+ if (this.action){
+ this.trigger(e);
+ }
+ }
+ }
+ }
+ },
+
+ addHoverStyles: function(e) {
+ if(!this.hasInitialSylesChecked){
+ this.initialStyles = this.obj.style.cssText;
+ this.hasInitialSylesChecked = true;
+ }
+ if (this.hoveredStyles) {
+ Element.setStyle(this.obj, this.hoveredStyles);
+ }
+ if (this.hoveredClasses)
+ for (i = 0; i < this.hoveredClasses.length; i++)
+ this.obj.addClassName(this.hoveredClasses[i]);
+ },
+
+ removeHoverStyles: function(e) {
+ if (this.hoveredStyles && this.hasInitialSylesChecked) {
+ this.obj.style.cssText = this.initialStyles;
+ }
+
+ if (this.hoveredClasses)
+ for (var i = 0; i < this.hoveredClasses.length; i++)
+ this.obj.removeClassName(this.hoveredClasses[i]);
+ },
+
+ _getDirectChildrenByTag: function(e, tagName) {
+ var allKids = e.childNodes;
+ var kids = new Array();
+ var ddk;
+ tagName = tagName.toLowerCase();
+ for( var i = 0 ; i < allKids.length ; i++ )
+ if ( allKids[i] && allKids[i].tagName &&
allKids[i].tagName.toLowerCase() == tagName )
+ kids.push(allKids[i]);
+ return kids;
+ },
+
+ _fireEditEvent: function(e){
+ if( document.createEvent ) {
+ var evObj = document.createEvent('HTMLEvents');
+ evObj.initEvent( e, true, false );
+ this.edit.dispatchEvent(evObj);
+ } else if( document.createEventObject ) {
+ this.edit.fireEvent('on' + e);
+ }
+ },
+
+ _attachBehaviors: function() {
+ if (this.event)
+ Event.observe(this.obj, this.event, this.itemClicked.bindAsEventListener(this),
false);
+ else
+ Event.observe(this.obj, "click", this.itemClicked.bindAsEventListener(this),
false);
+ Event.observe(this.obj, "mouseover",
this.addHoverStyles.bindAsEventListener(this), false);
+ Event.observe(this.obj, "mouseout",
this.removeHoverStyles.bindAsEventListener(this), false);
+ }
+};
+
+PanelMenu.doExpand = function (id) {
+ var group = PanelMenuStorage[id];
+ if (group && group.type && "node" == group.type) {
+ var parent = group.parentObj;
+ if (parent.expandSingle){
+ if (group.parentObj.lastExpanded!=null){
+ group.parentObj.lastExpanded.collapse();
+ }
+ }
+ while (parent) {
+ if (parent.type && "node" == parent.type) {
+ parent.expand();
+ }
+ parent = parent.parentObj;
+ }
+ if (!group.expanded && new Function(group.onopen+";return
true;")()){
+ group.expand();
+ }
+ }
+}
+
+PanelMenu.doCollapse = function (id) {
+ var group = PanelMenuStorage[id];
+ if (group && group.type && "node" == group.type) {
+ if (group.expanded && new Function(group.onclose+";return
true;")()){
+ group.collapse();
+ }
+ }
+}