/*!======================================================================*\ || #################################################################### || || # vBulletin 3.8.3 || # ---------------------------------------------------------------- # || || # Copyright ©2000-2009 Jelsoft Enterprises Ltd. All Rights Reserved. || || # This file may not be redistributed in whole or significant part. # || || # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # || || # http://www.vbulletin.com | http://www.vbulletin.com/license.html # || || #################################################################### || \*======================================================================*/ vBulletin.add_event("vBmenuShow"); vBulletin.add_event("vBmenuHide"); /** * vBulletin popup menu example usage: * * To create a new popup menu: * Click me * The menu class expects an element with the id of x_menu that contains the menu. *
...
*/ // ############################################################################# // vB_Popup_Handler // ############################################################################# /** * vBulletin popup menu registry * * @package vBulletin * @version $Revision: 29558 $ * @date $Date: 2009-02-16 06:54:03 -0600 (Mon, 16 Feb 2009) $ * @author Kier Darby, vBulletin Development Team */ function vB_Popup_Handler() { /** * Options: * * @var integer Number of steps to use in sliding menus open * @var boolean Use opacity face in menu open? */ this.open_steps = 10; this.open_fade = false; this.active = false; this.menus = new Array(); this.activemenu = null; }; // ============================================================================= // vB_Popup_Handler methods /** * Activate / Deactivate the menu system * * @param boolean Active state for menus */ vB_Popup_Handler.prototype.activate = function(active) { this.active = active; console.log("vBmenu :: System Activated"); }; /** * Register a control object as a menu control * * @param string ID of the control object * @param boolean Disable menu pop image addition * @param boolean Disable menu slide open * * @return vB_Popup_Menu */ vB_Popup_Handler.prototype.register = function(controlkey, noimage, noslide) { //console.log("vBmenu :: registering '%s'", controlkey); this.menus[controlkey] = new vB_Popup_Menu(controlkey, noimage, noslide); // deal with usercss var usercss = YAHOO.util.Dom.get("usercss"); if (usercss && YAHOO.util.Dom.isAncestor(usercss, controlkey)) { this.menus[controlkey].imgsrc = IMGDIR_MISC + "/menu_open_usercss.gif"; } this.menus[controlkey].startup(); return this.menus[controlkey]; }; /** * Hide active menu */ vB_Popup_Handler.prototype.hide = function() { if (this.activemenu != null) { this.menus[this.activemenu].hide(); } }; // ############################################################################# // initialize menu registry var vBmenu = new vB_Popup_Handler(); /** * Function to allow anything to hide all menus * * @param event Event object * * @return mixed */ function vbmenu_hide(e) { if (e && e.button && e.button != 1 && e.type == 'click') { return true; } else { vBmenu.hide(); } }; // ############################################################################# // vB_Popup_Menu // ############################################################################# /** * vBulletin popup menu class constructor * * Manages a single menu and control object * Initializes control object * * @package vBulletin * @version $Revision: 29558 $ * @date $Date: 2009-02-16 06:54:03 -0600 (Mon, 16 Feb 2009) $ * @author Kier Darby, vBulletin Development Team * * @param string ID of the control object * @param boolean Disable menu pop image addition * @param boolean Disable menu slide open */ function vB_Popup_Menu(controlkey, noimage, noslide) { this.controlkey = controlkey; this.noimage = noimage; this.noslide = noslide; this.menuname = this.controlkey.split('.')[0] + '_menu'; this.imgsrc = IMGDIR_MISC + '/menu_open.gif'; }; // ============================================================================= // vB_Popup_Menu methods /** * Startup routine for a popup menu */ vB_Popup_Menu.prototype.startup = function() { this.init_control(this.noimage); if (fetch_object(this.menuname)) { this.init_menu(); } this.slide_open = (this.noslide ? false : true); this.open_steps = vBmenu.open_steps; vBulletin.add_event("vBmenuShow_" + this.controlkey); vBulletin.add_event("vBmenuHide_" + this.controlkey); } /** * Initialize the control object */ vB_Popup_Menu.prototype.init_control = function(noimage) { this.controlobj = fetch_object(this.controlkey); this.controlobj.state = false; if (this.controlobj.firstChild && (this.controlobj.firstChild.tagName == 'TEXTAREA' || this.controlobj.firstChild.tagName == 'INPUT')) { // do nothing } else { if (!noimage && !(is_mac && is_ie)) { var space = document.createTextNode(' '); this.controlobj.appendChild(space); var img = document.createElement('img'); img.src = this.imgsrc; img.border = 0; img.title = ''; img.alt = ''; this.img = this.controlobj.appendChild(img); } this.controlobj.unselectable = true; if (!noimage) { this.controlobj.style.cursor = pointer_cursor; } this.controlobj.onclick = vB_Popup_Events.prototype.controlobj_onclick; this.controlobj.onmouseover = vB_Popup_Events.prototype.controlobj_onmouseover; } }; /** * Init the popup menu object */ vB_Popup_Menu.prototype.init_menu = function() { this.menuobj = fetch_object(this.menuname); this.select_handler = new vB_Select_Overlay_Handler(this.menuobj); if (this.menuobj && !this.menuobj.initialized) { this.menuobj.initialized = true; this.menuobj.onclick = e_by_gum; this.menuobj.style.position = 'absolute'; this.menuobj.style.zIndex = 50; // workaround border disappearing issues in IE if (is_ie && !is_mac) { if (YAHOO.env.ua.ie < 7) { // this seems to fix it in < IE7, but IE7 disables ClearType with filters... this.menuobj.style.filter += "alpha(enabled=1,opacity=100)"; } else { // ...so use this trick for IE7. It seems to work, but I don't know why. :) this.menuobj.style.minHeight = '1%'; } } this.init_menu_contents(); } }; /** * Init the popup menu contents */ vB_Popup_Menu.prototype.init_menu_contents = function() { var tags = new Array("td", "li"); for (var j = 0; j < tags.length; j++) { var blocks = fetch_tags(this.menuobj, tags[j]); for (var i = 0; i < blocks.length; i++) { if (blocks[i].className == 'vbmenu_option') { if (blocks[i].title && blocks[i].title == 'nohilite') { // not an active cell blocks[i].title = ''; } else { // create a reference back to the menu class blocks[i].controlkey = this.controlkey; // handle mouseover / mouseout highlighting events blocks[i].onmouseover = vB_Popup_Events.prototype.menuoption_onmouseover; blocks[i].onmouseout = vB_Popup_Events.prototype.menuoption_onmouseout; var links = fetch_tags(blocks[i], 'a'); if (links.length == 1) { /* Ok we have a link, we should use this if 1. There is no onclick event in the link 2. There is no onclick event on the cell 3. The onclick event for the cell should equal the link if the above are true If we find a browser thats gets confused we may need to set remove_link to true for it. */ blocks[i].className = blocks[i].className + ' vbmenu_option_alink'; blocks[i].islink = true; var linkobj = links[0]; var remove_link = false; blocks[i].target = linkobj.getAttribute('target'); if (typeof linkobj.onclick == 'function') { blocks[i].ofunc = linkobj.onclick; blocks[i].onclick = vB_Popup_Events.prototype.menuoption_onclick_function; remove_link = true; } else if (typeof blocks[i].onclick == 'function') { blocks[i].ofunc = blocks[i].onclick; blocks[i].onclick = vB_Popup_Events.prototype.menuoption_onclick_function; remove_link = true; } else { blocks[i].href = linkobj.href; blocks[i].onclick = vB_Popup_Events.prototype.menuoption_onclick_link; } if (remove_link) { var newlink = document.createElement('a'); newlink.innerHTML = linkobj.innerHTML; newlink.href = '#'; newlink.onclick = function(e) { e = e ? e : window.event; e.returnValue = false; return false; }; blocks[i].insertBefore(newlink, linkobj); blocks[i].removeChild(linkobj); } } else if (typeof blocks[i].onclick == 'function') { blocks[i].ofunc = blocks[i].onclick; blocks[i].onclick = vB_Popup_Events.prototype.menuoption_onclick_function; } } } } } }; /** * Show the menu * * @param object The control object calling the menu * @param boolean Use slide (false) or open instantly? (true) */ vB_Popup_Menu.prototype.show = function(obj, instant) { if (!vBmenu.active) { return false; } else if (!this.menuobj) { this.init_menu(); } if (!this.menuobj || vBmenu.activemenu == this.controlkey) { return false; } console.log("vBmenu :: Show '%s'", this.controlkey); if (vBmenu.activemenu != null && vBmenu.activemenu != this.controlkey) { vBmenu.menus[vBmenu.activemenu].hide(); } vBmenu.activemenu = this.controlkey; this.menuobj.style.display = ''; if (this.slide_open) { this.menuobj.style.clip = 'rect(auto, 0px, 0px, auto)'; } this.set_menu_position(obj); if (!instant && this.slide_open) { this.intervalX = Math.ceil(this.menuobj.offsetWidth / this.open_steps); this.intervalY = Math.ceil(this.menuobj.offsetHeight / this.open_steps); this.slide((this.direction == 'left' ? 0 : this.menuobj.offsetWidth), 0, 0); } else if (this.menuobj.style.clip && this.slide_open) { this.menuobj.style.clip = 'rect(auto, auto, auto, auto)'; } // deal with IE putting