WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Problem with attribute of an Object, Guilherme Blanco, October 17, 2003

Subject: Problem with attribute of an Object From: Guilherme Blanco Date: October 17, 2003

Hello Oracle and cia =)
I got some problems with my dButtons, soI'm asking a little help for you.
I created an Object called dButton that adds some properties to it. One of them is iMethod (called Obj.method = iMethod). This is responsible for group of buttons (only one button in a group can be selected) and if it's undefined, the buttons isn't inside any group, and can be selected as you want.
But, I got some problems with this: I set the property in the object okay and also tested it.
When I send the obj as an argument of a function onclick="button.click(this);", the property of the object returns me undefined (when it should display a number). Here is the code... any help is appreciate (including a disable addon or extra tools to add).

var button = new Object();
var btnCounter = 0;
var btn = new Array();
var currentSelectedButton = new Array();

function dButton( sText, sIcon, sAction, sHint, iMethod ) {
         this.id = "dotcom-btn-object-"+ btnCounter++;
         this.text = sText;
         this.icon = sIcon;
         this.action = sAction;
         this.hint = sHint;
         this.method = iMethod;

         this._selected = false;

         str = "<div id=\""+ this.id +"\" class=\"button-off\" onmouseover=\"button.overButton(this); document.getElementById('description').innerHTML='"+ this.hint +"';\" "
         + "onmouseout=\"button.outButton(this); document.getElementById('description').innerHTML='[ Descrição dos Itens ]';\" onclick=\"button.clickButton(this); "+ this.action +"\">";
         if ( this.text == "" )
                  str += "<img src=\""+ this.icon +"\" class=\"icon\" border=\"0\" width=\"16\" height=\"16\"></div>";
         else
                  str += "<img src=\""+ this.icon +"\" class=\"icon\" border=\"0\" width=\"16\" height=\"16\">&nbsp;"+ this.text +"</div>";
         document.write(str);

         return this;
}

button.doClick = function ( el ) {
         button.clickButton ( document.getElementById( el.id ) );
         document.getElementById( el.id ).className = "button-sel-off";

         if ( el.method != undefined )
                  currentSelectedButton[ el.method ] = el;
}

button.overButton = function ( el ) {
         if ( el._selected == false )
                  el.className = "button-sel-on";
         else
                  el.className = "button-on";
}

button.outButton = function ( el ) {
         if ( el._selected == false )
                  el.className = "button-sel-off";
         else
                  el.className = "button-off";
}

button.clickButton = function ( el ) {
         if ( el.method != undefined && el != currentSelectedButton[ el.method ] && currentSelectedButton[ el.method ] != null ) {
                  currentSelectedButton[ el.method ].className = "button-off";
                  currentSelectedButton[ el.method ]._selected = true;
                  if( document.getElementById( currentSelectedButton[ el.method ].id ).className != "button-off" ) {
                           document.getElementById( currentSelectedButton[ el.method ].id ).className = "button-off";
                           document.getElementById( currentSelectedButton[ el.method ].id )._selected = true;
                  }
                  currentSelectedButton[ el.method ] = el;
         }

         if ( el._selected == false ) {
                  el.className = "button-on";
                  el._selected = true;
         } else {
                  el.className = "button-sel-on";
                  el._selected = false;
         }
}


To create a button, just use this piece of code:
<script>btn[0] = new dButton("", "email.gif", "", "Teste 0", 2);</script>

The last argument is the method that is an optional.



Cheers,
Guilherme Blanco




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX