webgui/www/extras/yui/docs/menu/overview-summary-contextmenu.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

545 lines
15 KiB
HTML

<html>
<head>
<title>JavaScript Documentation - contextmenu.js</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>JavaScript Documentation</h1>
<h3><a href="./index.html">Yahoo! Menuing Library</a></h3>
<div class="breadcrumbs">
<a href="./index.html">Yahoo! Menuing Library</a>
&gt;
<strong>contextmenu.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.widget.ContextMenu.html">
YAHOO.widget.ContextMenu</a>
</li>
<li>
<a href="YAHOO.widget.ContextMenuItem.html">
YAHOO.widget.ContextMenuItem</a>
</li>
<li>
<a href="YAHOO.widget.Menu.html">
YAHOO.widget.Menu</a>
</li>
<li>
<a href="YAHOO.widget.MenuBar.html">
YAHOO.widget.MenuBar</a>
</li>
<li>
<a href="YAHOO.widget.MenuBarItem.html">
YAHOO.widget.MenuBarItem</a>
</li>
<li>
<a href="YAHOO.widget.MenuItem.html">
YAHOO.widget.MenuItem</a>
</li>
<li>
<a href="YAHOO.widget.MenuModule.html">
YAHOO.widget.MenuModule</a>
</li>
<li>
<a href="YAHOO.widget.MenuModuleItem.html">
YAHOO.widget.MenuModuleItem</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-contextmenu.js.html">
contextmenu.js</a>
</li>
<li>
<a href="overview-summary-contextmenuitem.js.html">
contextmenuitem.js</a>
</li>
<li>
<a href="overview-summary-menu.js.html">
menu.js</a>
</li>
<li>
<a href="overview-summary-menubar.js.html">
menubar.js</a>
</li>
<li>
<a href="overview-summary-menubaritem.js.html">
menubaritem.js</a>
</li>
<li>
<a href="overview-summary-menuitem.js.html">
menuitem.js</a>
</li>
<li>
<a href="overview-summary-menumodule.js.html">
menumodule.js</a>
</li>
<li>
<a href="overview-summary-menumoduleitem.js.html">
menumoduleitem.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>contextmenu.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#classSummary">Class Summary</a> |
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<h3><a name="classSummary">Class Summary</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<div class="content">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="name">
<a href="YAHOO.widget.ContextMenu.html">YAHOO.widget.ContextMenu</a>
</td>
<td class="overview">Creates a list of options which vary depending on the context in which the menu is invoked.</td>
</tr>
</table>
</div>
</div>
<div class="section source">
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview">
<span class="comment">/**
* <span class="attrib">@class</span> Creates a list of options which vary depending on the context in
* which the menu is invoked.
* <span class="attrib">@constructor</span>
* <span class="attrib">@extends</span> YAHOO.widget.Menu
* <span class="attrib">@base</span> YAHOO.widget.Menu
* <span class="attrib">@param</span> {String or HTMLElement} p_oElement String id or HTMLElement
* (either HTMLSelectElement or HTMLDivElement) of the source HTMLElement node.
* <span class="attrib">@param</span> {Object} p_oConfig Optional. The configuration object literal
* containing the configuration for a ContextMenu instance. See
* configuration class documentation for more details.
*/</span>
YAHOO.widget.ContextMenu = <span class="reserved">function</span>(p_oElement, p_oConfig) {
YAHOO.widget.ContextMenu.superclass.constructor.call(
<span class="reserved">this</span>,
p_oElement,
p_oConfig
);
};
YAHOO.extend(YAHOO.widget.ContextMenu, YAHOO.widget.Menu);
<span class="comment">
// Private properties</span>
<span class="comment">/**
* Array of ContextMenu instances
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {Array}
*/</span>
YAHOO.widget.ContextMenu._aMenus = [];
<span class="comment">/**
* The id(s) or element(s) that trigger the display of the ContextMenu instance
* <span class="attrib">@private</span>
* <span class="attrib">@type</span> {String/Array/HTMLElement}
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>._oTrigger = null;
<span class="comment">
// Public properties</span>
<span class="comment">/**
* Returns the HTMLElement node that was the target of the "contextmenu"
* DOM event.
* <span class="attrib">@type</span> HTMLElement
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>.contextEventTarget = null;
<span class="comment">/**
* The ContextMenu class's initialization method. This method is automatically
* called by the constructor, and sets up all DOM references for pre-existing
* markup, and creates required markup if it is not already present.
* <span class="attrib">@param</span> {String or HTMLElement} p_oElement String id or HTMLElement
* (either HTMLSelectElement or HTMLDivElement) of the source HTMLElement node.
* <span class="attrib">@param</span> {Object} p_oConfig Optional. The configuration object literal
* containing the configuration for a ContextMenu instance. See
* configuration class documentation for more details.
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(p_oElement, p_oConfig) {
<span class="reserved">if</span>(!<span class="reserved">this</span>.ITEM_TYPE) {
<span class="reserved">this</span>.ITEM_TYPE = YAHOO.widget.ContextMenuItem;
}
<span class="comment">
// Call the init of the superclass (YAHOO.widget.Menu)</span>
YAHOO.widget.ContextMenu.superclass.init.call(<span class="reserved">this</span>, p_oElement);
<span class="reserved">this</span>.beforeInitEvent.fire(YAHOO.widget.ContextMenu);
<span class="reserved">if</span>(p_oConfig) {
<span class="reserved">this</span>.cfg.applyConfig(p_oConfig, true);
}
<span class="reserved">this</span>.initEvent.fire(YAHOO.widget.ContextMenu);
var aMenus = YAHOO.widget.ContextMenu._aMenus;
aMenus[aMenus.length] = <span class="reserved">this</span>;
};
<span class="comment">
// Private event handlers</span>
<span class="comment">/**
* "click" event handler for the document object.
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {Event} p_oEvent Event object passed back by the
* event utility (YAHOO.util.Event).
* <span class="attrib">@param</span> {YAHOO.widget.ContextMenu} p_oMenu The ContextMenu instance
* handling the event.
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>._onDocumentClick =
<span class="reserved">function</span>(p_oEvent, p_oMenu) {
<span class="reserved">this</span>.hide();
};
<span class="comment">/**
* "click" event handler for the HTMLElement node that triggered the event.
* Used to cancel default behaviors in Opera.
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {Event} p_oEvent Event object passed back by the
* event utility (YAHOO.util.Event).
* <span class="attrib">@param</span> {YAHOO.widget.ContextMenu} p_oMenu The ContextMenu instance
* handling the event.
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>._onTriggerClick =
<span class="reserved">function</span>(p_oEvent, p_oMenu) {
<span class="reserved">if</span>(p_oEvent.ctrlKey) {
YAHOO.util.Event.stopEvent(p_oEvent);
}
};
<span class="comment">/**
* "contextmenu" event handler ("mousedown" for Opera) for the HTMLElement
* node that triggered the event.
* <span class="attrib">@private</span>
* <span class="attrib">@param</span> {Event} p_oEvent Event object passed back by the
* event utility (YAHOO.util.Event).
* <span class="attrib">@param</span> {YAHOO.widget.ContextMenu} p_oMenu The ContextMenu instance
* handling the event.
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>._onTriggerContextMenu =
<span class="reserved">function</span>(p_oEvent, p_oMenu) {
var Event = YAHOO.util.Event;
var oConfig = <span class="reserved">this</span>.cfg;
<span class="comment">
// Hide any other ContextMenu instances that might be visible</span>
var aMenus = YAHOO.widget.ContextMenu._aMenus;
var i = aMenus.length - 1;
do {
aMenus[i].hide();
}
<span class="reserved">while</span>(i--);
<span class="reserved">if</span>(p_oEvent.type == <span class="literal">"mousedown"</span> &amp;&amp; !p_oEvent.ctrlKey) {
<span class="reserved">return</span>;
}
<span class="reserved">this</span>.contextEventTarget = Event.getTarget(p_oEvent);
<span class="comment">
// Position and display the context menu</span>
var nX = Event.getPageX(p_oEvent);
var nY = Event.getPageY(p_oEvent);
oConfig.applyConfig( { xy:[nX, nY], visible:true } );
oConfig.fireQueue();
<span class="comment">/*
Prevent the browser's default context menu from appearing and
stop the propagation of the "contextmenu" event so that
other ContextMenu instances are no displayed.
*/</span>
Event.stopEvent(p_oEvent);
};
<span class="comment">
// Public methods</span>
<span class="comment">/**
* Initializes the class's configurable properties which can be changed using
* a ContextMenu instance's Config object (cfg).
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>.initDefaultConfig = <span class="reserved">function</span>() {
YAHOO.widget.ContextMenu.superclass.initDefaultConfig.call(<span class="reserved">this</span>);
<span class="comment">
// Add a configuration property</span>
<span class="reserved">this</span>.cfg.addProperty(<span class="literal">"trigger"</span>, { handler: <span class="reserved">this</span>.configTrigger });
};
<span class="comment">
// Event handlers for configuration properties</span>
<span class="comment">/**
* Event handler for when the "trigger" configuration property of
* a MenuItem instance.
* <span class="attrib">@param</span> {String} p_sType The name of the event that was fired.
* <span class="attrib">@param</span> {Array} p_aArgs Collection of arguments sent when the
* event was fired.
* <span class="attrib">@param</span> {YAHOO.widget.ContextMenu} p_oMenu The ContextMenu that instance fired
* the event.
*/</span>
YAHOO.widget.ContextMenu.<span class="reserved">prototype</span>.configTrigger =
<span class="reserved">function</span>(p_sType, p_aArgs, p_oMenu) {
var Event = YAHOO.util.Event;
var oTrigger = p_aArgs[0];
<span class="reserved">if</span>(oTrigger) {
<span class="comment">/*
If there is a current "trigger" - remove the event handlers
from that element(s) before assigning new ones
*/</span>
<span class="reserved">if</span>(<span class="reserved">this</span>._oTrigger) {
Event.purgeElement(<span class="reserved">this</span>._oTrigger);
}
<span class="reserved">this</span>._oTrigger = oTrigger;
<span class="comment">/*
Listen for the "mousedown" event in Opera b/c it does not
support the "contextmenu" event
*/</span>
var bOpera = (<span class="reserved">this</span>.browser == <span class="literal">"opera"</span>);
Event.addListener(
oTrigger,
(bOpera ? <span class="literal">"mousedown"</span> : <span class="literal">"contextmenu"</span>),
<span class="reserved">this</span>._onTriggerContextMenu,
<span class="reserved">this</span>,
true
);
<span class="comment">/*
Assign a "click" event handler to the trigger element(s) for
Opera to prevent default browser behaviors.
*/</span>
<span class="reserved">if</span>(bOpera) {
Event.addListener(
oTrigger,
<span class="literal">"click"</span>,
<span class="reserved">this</span>._onTriggerClick,
<span class="reserved">this</span>,
true
);
}
<span class="comment">
// Assign a "mousedown" event handler to the document</span>
Event.addListener(
document,
<span class="literal">"click"</span>,
<span class="reserved">this</span>._onDocumentClick,
<span class="reserved">this</span>,
true
);
}
};</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2006 Yahoo! Inc. All rights reserved.
<br /><br />
Documentation generated by <a href="http://jsdoc.sourceforge.net/">
JSDoc</a>
</div>
</body>
</html>