I am trying to update an AJAX script I have to work with prototype
v1.6.  It was originally designed to work with 1.4.  Does anyone see
anything that would break in 1.6?  Please help


Ajax.Menu = Class.create();
Object.extend(Object.extend(Ajax.Menu.prototype,
Ajax.Request.prototype), {
        initialize: function(id, url, options) {
                this.id = id;
                this.url = url;

                this.setOptions(Object.extend( {
                                nodeIdentType: "path"
                        }, options));

                this.options.nodeIdentType = this.options.nodeIdentType || "id";

                this.transport = Ajax.getTransport();

                var onComplete = this.options.onComplete || 
Prototype.emptyFunction;
                this.options.onComplete = (function(transport, object) {
                        this.li.className = 
this.li.className.replace(/collapsed/,
"expanded");
                        new Insertion.Bottom( this.li, transport.responseText );
                        onComplete(transport, object);
                }).bind(this);

                this.addObservers();
        },
        addObservers: function() {
                var menu = $(this.id);
                if (menu) {
                        var lis = document.getElementsByTagName("li");
                        for (var i=0; li=lis[i]; i++) {
                                Event.observe(lis[i], "click",
this.onClick.bindAsEventListener(this));
                        }
                }
        },
        setIdentData: function() {
                this.options.nodeIdentKey = this.options.nodeIdentKey ||
this.options.nodeIdentType;
                var params = this.options.parameters || '';
                if (params.length > 0)
                        params += "&";
                switch (this.options.nodeIdentType) {
                        case "path":
                                var re = new RegExp(this.options.nodeIdentKey + 
"=.*?(&|$)", "g");
                                params = params.replace(re, "");
                                var a = (as = 
this.li.getElementsByTagName("a")).length > 0 ?
as[0] : null;
                                if (a) {
                                        /*
                                        Thanks to:
                                        
http://www.quirksmode.org/bugreports/archives/2005/02/getAttributeHREF_is_always_absolute.html
                                        */
                                        var path = a.getAttribute("href", 
2).replace(/^[hf]t?tps?:\/\/[^
\/]+/, '');
                                        params += this.options.nodeIdentKey + 
"=" + path;
                                }
                                break;
                        case "id":
                                params += this.options.nodeIdentKey + "=" + 
li.id;
                                break;
                }
                this.options.parameters = params;
        },
        onClick: function( event ) {
                var li = Event.findElement(event, 'LI');
                Event.stop(event);
                switch (li.className) {
                        case "collapsed":
                                var ul = null;
                                for (var i=0; node=li.childNodes[i]; i++) {
                                        if (node.nodeName.toLowerCase() == 
"ul") {
                                                ul = node;
                                        }
                                }
                                if (ul) {
                                        ul.style.display = "block";
                                        li.className = 
li.className.replace(/collapsed/, "expanded");
                                } else {
                                        this.li = li;
                                        this.setIdentData();
                                        this.request(this.url);
                                }
                                break;
                        case "expanded":
                                var uls = li.getElementsByTagName("ul");
                                for (var i=0; ul=uls[i]; i++) {
                                        ul.style.display = "none";
                                        ul.parentNode.className = 
ul.parentNode.className.replace(/
expanded/, "collapsed");
                                }
                                li.className = li.className.replace(/expanded/, 
"collapsed");
                                break;
                }
        }
});

I call it with the following:

      new Ajax.Menu( 'menu', '/projects/ajaxmenu/data.asp', {
        onComplete: function(xhr, o) {
          alert(o.nodeName);
          //                    Insertion.Bottom( o);
        }
      });
--~--~---------~--~----~------------~-------~--~----~
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