On Jan 28, 2008 10:46 AM, Justin Perkins <[EMAIL PROTECTED]> wrote:

> The script you are including is probably doing document.write, which
> is fine if the script is running in an IFRAME (I'm guessing you're
> doing advertisements?). Try using DOM-manipulation techniques instead.


the script is just a simple thing to allow 'buttons' to be animated.  they
are typcially
styled span tags.  i make them appear as buttons, using css and javascript.
there is no dynamic writing of dom elements.  the dom elements are sent from
the server and im using onDOMReady() to apply the prototype based class to
them.

var CssButtons = Class.create({
        initialize : function(buttonDomIds, buttonHoverClassnames,
buttonPressedClassnames, clickEventHandlers, buttonNormalStyles,
buttonHoverStyles, buttonPressedStyles) {
                this.buttonDomIds = $H(buttonDomIds);
                this.buttonHoverClasses = buttonHoverClassnames;
                this.buttonHoverStyles = buttonHoverStyles;
                this.buttonNormalStyles = buttonNormalStyles;
                this.buttonPressedStyles = buttonPressedStyles;
                this.buttonPressedClasses = buttonPressedClassnames;
                this.clickEventHandlers = $(clickEventHandlers);
                this._registerListeners();
// register event handlers for the buttons
        }
        ,
        _registerListeners : function() {
                this.buttonDomIds.each(function(pair) {
                        element = pair.value;
                        if($(element) == null) {                // dont
attempt to register listeners for an element that doesnt exist
                                return;
                        }
                        var hoverClass = this.hoverClass;
                        var pressedClass = this.pressedClass;
                        this.buttonDomIds[pair.key] =
$(element);               // extend these dom ids, prototype sytle
                        Event.observe(element, 'mouseover', function() {

$(this.buttonDomIds[pair.key]).select('span').each(function(elt)
{
                                        elt.setStyle(this.buttonHoverStyles[
pair.key]);
                                }.bind(this));
                                $(this.buttonDomIds[pair.key
]).removeClassName(this.buttonHoverClasses[pair.key]);
                                $(this.buttonDomIds[pair.key]).addClassName(
this.buttonHoverClasses[pair.key]);
                        }.bindAsEventListener(this));
                        Event.observe(element, 'mouseout', function() {

$(this.buttonDomIds[pair.key]).select('span').each(function(elt)
{
                                        elt.setStyle(this.buttonNormalStyles
[pair.key]);
                                }.bind(this));
                                $(this.buttonDomIds[pair.key
]).removeClassName(this.buttonHoverClasses[pair.key]);
                                $(this.buttonDomIds[pair.key
]).removeClassName(this.buttonPressedClasses[pair.key]);
                        }.bindAsEventListener(this));
                        Event.observe(element, 'mousedown',  function() {

$(this.buttonDomIds[pair.key]).select('span').each(function(elt)
{
                                        elt.setStyle(
this.buttonPressedStyles[pair.key]);
                                }.bind(this));
                                $(this.buttonDomIds[pair.key
]).removeClassName(this.buttonHoverClasses[pair.key]);
                                $(this.buttonDomIds[pair.key]).addClassName(
this.buttonPressedClasses[pair.key]);
                        }.bindAsEventListener(this));
                        /// add an event handler for the click event of the
button, if one has been supplied
                        if(this.clickEventHandlers[pair.key] !== undefined
&&
                                this.clickEventHandlers[pair.key] !== null)
{
                                Event.observe(element, 'click',
this.clickEventHandlers[pair.key]);
                        }
                }.bind(this));
        }
});

-nathan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to