Jump to content

User:Guandalug/vectorDropdownMenus.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Schutz vor Doppeleinbindung
if (jQuery.dropdownMenuTimeout === undefined)
{
jQuery.extend({
  // Configuration constants
  dropdownMenuTimeout: 50,
 
  // And locally used storage variables
  dropdownMenuClosetimer: 0,
  dropdownMenuMenuitem: 0,
  dropdownMenuMainMenu: 0,
  dropdownMenuMenuEntries: new Array(),

  jsddm_open: function()
  {  
    jQuery.jsddm_canceltimer();
    jQuery.jsddm_close();
    jQuery.dropdownMenuMenuitem = jQuery(this).find('ul').css('visibility', 'visible');
  },

  jsddm_close: function()
  {  
    if(jQuery.dropdownMenuMenuitem) 
      jQuery.dropdownMenuMenuitem.css('visibility', 'hidden');
  },

  jsddm_timer: function()
  {   
    jQuery.dropdownMenuClosetimer = window.setTimeout(jQuery.jsddm_close, jQuery.dropdownMenuTimeout);
  },

  jsddm_canceltimer: function()
  {
    if(jQuery.dropdownMenuClosetimer)
    {
      window.clearTimeout(jQuery.dropdownMenuClosetimer);
      jQuery.dropdownMenuClosetimer = null;
    }
  },

  // Main container for personal drop-down menus.
  // Puts itself left of the search bar
  _buildPersonalMenu: function()
  {

    // Now build and attach the menu container
    jQuery('#p-search').before('<div id="p-my-menu" class="vectorTabs"><h5>Persönliches</h5><ul></ul></div>');
    
    jQuery.dropdownMenuMainMenu = jQuery('#p-my-menu');
    mw.util.addCSS('li.personalDropMenu ul li, li.personalDropMenu ul li a { background-image:none; background-color:white; float:none; height:auto; margin:0; padding: 2px; }');
  },

  // Add a new personal drop-down menu. Auto-creates the container if it's not there.
  // Otherwise, adds itself into the container
  _newFavMenu: function(id,title)
  {
    if (!jQuery.dropdownMenuMainMenu)
      jQuery._buildPersonalMenu()
    if (!jQuery.dropdownMenuMainMenu)
      return;

    var node = jQuery.dropdownMenuMainMenu.find('ul:first');
    if (!node)
      return null;

    node.append('<li id="'+id+'" style="float:left;" class="personalDropMenu"><span><a href="#">'+title+'</a></span><ul style="visibility:hidden; position:absolute; border: 1px solid black; height: auto;"></ul></li>');

    return node;
  },

  addDropdownMenu: function(id,title)
  {
    if (!jQuery.dropdownMenuMenuEntries[id])
    {
      jQuery._newFavMenu(id,title);
      jQuery.dropdownMenuMenuEntries[id] = 1;

      jQuery('#'+id).mouseover(jQuery.jsddm_open).mouseout(jQuery.jsddm_timer);
    }
  },

  addEntry: function(id,url,name,desc)
  {
    if (!jQuery.dropdownMenuMenuEntries[id])
      jQuery.addMenu(id,id);

    mw.util.addPortletLink(id,url,name,id+jQuery.dropdownMenuMenuEntries[id], desc);
    ++jQuery.dropdownMenuMenuEntries[id];
  }

});
}