cogAdds new entries to the top menus, from a JavaScript extension
TypeSnippet
Category
Developed by

Jerome

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Code

Paste and adapt the following code in a JavaScript eXtension object to dynamically inject a new menu in the XWiki top menu bar.

(function(){

document.observe("dom:loaded", function(){
 var topMenu = $('actionmenu').down('.leftmenu');
 if(typeof topMenu != "undefined") {
   var aMenu = topMenu.appendChild(
     new Element("div", {
       'class':'topmenuentry',
       'onmouseout' : "hidesubmenu(this);",
        'onmouseover' :"showsubmenu(this);"
      }).update(
        new Element("a", {
          'class':'tme',
          'style' : 'cursor:default;'
         }).update("Extra !")
     )
   );
   var colon = new Element("span", {'class' : 'hidden menucolon'}).update(":");
    $(aMenu).insert( {'bottom': colon });
   var menuEntries =
          new Element("span", {'class' : 'submenu hidden'}).update(
             new Element("span", {'class':'submenuitem'}).update(
                new Element("a").update("Say Hello").observe("click", sayHello)
             )
          );
    $(aMenu).insert( {'bottom': menuEntries });
   menuEntries.insert( {'bottom': new Element("span", {'class' : 'submenuseparator'}) });
   var menuEntry2 =
       new Element("span", {'class':'submenuitem'}).update(
          new Element("a").update("Do Something else").observe("click", doSomethingElse)
       );
   menuEntries.insert( {'bottom': menuEntry2 });
  }
});

function sayHello() {
 alert("Hello");
}

function doSomethingElse() {
 alert("Something Else !");
}

})();

Result

topmenu.png

Tags: presentation
     

Get Connected