~/~/ Make sure the XWiki 'namespace' exists. if(typeof(XWiki) == 'undefined') {   XWiki = new Object(); }

~/~/ Make sure the widgets 'namespace' exists. if(typeof(XWiki.widgets) == 'undefined') {   XWiki.widgets = new Object(); }

XWiki.widgets.RecentCommentsUpdater = Class.create({ visibleComments : new Object(), initialize: function() {     this.attachEvents(); new PeriodicalExecuter(function() {this.update()}.bind(this), 30); }, attachEvents : function() {     $$(".recent-comments-list li").each(function(item) {       if(item.down(".show")) {         item.down(".show").observe("click", function(event) {           event.stop(); this.showComment(item.id); }.bindAsEventListener(this)); }       if(item.down(".close")) {         item.down(".close").observe("click", function(event) {           event.stop(); this.hideComment(item.id); }.bindAsEventListener(this)); }     }.bind(this)); }, toggleCommentVisibility: function(item) {     if (item) {        item.down('.comment-text').toggleClassName('hidden'); item.down('.show').toggleClassName('hidden'); }        }, showComment : function(itemID) {     this.toggleCommentVisibility($(itemID)); this.visibleComments[[itemID]] = 1; }, hideComment : function(itemID) {     this.toggleCommentVisibility($(itemID)); this.visibleComments[[itemID]] = 0; }, update : function() {     new Ajax.Request("{{velocity filter="none"}}{{html clean="false" wiki="true"}}/xwiki/bin/view/Panels/RecentComments{{/html}}{{/velocity}}?data=1&xpage=plain", {       onSuccess: function(response) {        $$(".recent-comments-list").each(function(item) {          item.replace(response.responseText); }); this.attachEvents(); for (var itemID in this.visibleComments) {          if (this.visibleComments[[itemID]] == 1) {            this.showComment(itemID); }        } }.bind(this) }); } });

document.observe('xwiki:dom:loaded', function() {   var updater = new XWiki.widgets.RecentCommentsUpdater(); });
