$(window).addEvent("domready", function() { var _commentHandler = new CommentsHandler("http://www.justise.com/wp-content/plugins/inline-comments/inline-comments-get.php"); }) //--- Attach to comments var CommentsHandler = new Class({ postbackUrl : "", initialize: function(postbackUrl) { this.postbackUrl = postbackUrl; this._attachEvents(); }, _attachEvents : function() { var that = this; $$(".show_comments").addEvent("click", function(ev) { //--- User clicked the toggle comments button. that.toggleComments($(this)); new Event(ev).stop(); }); }, toggleComments: function(btn) { //--- comments are already being shown. if(btn.getNext('.comments')) return; var comments = btn.getNext(".inline-comments"); if(!comments) { //--- Add and Show comments this.addComments(btn.getProperty("rel"), btn); } else { if(comments.getStyle("visibility") == "hidden"){ this.showComments(comments); } else { this.hideComments(comments); } } }, addComments : function(postID, btn) { var div = new Element("DIV", {'class': "inline-comments ajax-loading"}); div.inject(btn, "after"); var that = this; var req = new Request.HTML({ url : this.postbackUrl, method : "get", update: div, onSuccess : function() { that.showComments(div) } }); req.send("postid=" + postID) return div; }, showComments: function(el) { if(el.getStyle("visibility") == "hidden") { el.setStyle("visibility", "visible"); } var comments = el.getElement(".comments"); //--- Get height of inline-comments var size = comments.getSize(); el.setStyle("height", el.getSize().y + "px"); el.removeClass("ajax-loading"); comments.setStyle("visibility", "visible"); el.tween('height', size.y); }, hideComments: function(el) { new Fx.Tween(el, {onComplete: function() { el.setStyle("visibility", "hidden"); }}).start('height', 0); } });