Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define([
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dijit/registry",
- "dojo/_base/declare",
- "dojo/dom-style",
- "dojo/query!css2"
- ], function(
- Menu,
- MenuItem,
- MenuSeparator,
- registry,
- declare,
- domStyle
- ){
- var ContextMenu = declare([Menu], {
- addMenuItem: function(label, callback, insertIndex) {
- // summary:
- // Create a clickable row in the context menu,
- // and pass to the callback the event AND clicked widget.
- // label: string
- // The displayed value of the menu item
- // callback: function
- // When the menu item is clicked, this function
- // will be called with two parameters:
- // * The original click event
- // * The clicked widget
- // insertIndex: Number
- // Optional. Inserts the created menu item at a specific Menu position.
- var menuItem = new MenuItem({
- label: label,
- onClick: function(evt) {
- var node = this.getParent().currentTarget;
- var widget;
- while (!widget && node !== document.body) {
- widget = registry.byNode(node);
- node = node.parentNode;
- }
- if (widget) {
- callback(evt, widget);
- } else {
- console.error("ContextMenu - No widget found from clicked node.");
- }
- }
- });
- this.addChild(menuItem, insertIndex);
- return menuItem;
- },
- addMenuSeparator: function(insertIndex) {
- // summary:
- // Create a horizontal line between menu items
- // insertIndex: Number
- // Optional. Inserts the created menu item at a specific Menu position.
- var menuItem = new MenuSeparator();
- this.addChild(menuItem, insertIndex);
- return menuItem;
- },
- updateMenuItemLabel : function(menuItemId, label){
- var menuItems = this.getChildren();
- for(var i=0; i < menuItems.length; ++i){
- if(menuItemId === menuItems[i].id){
- menuItems[i].set("label", label);
- break;
- }
- }
- },
- hideMenuItem :function(menuItemId){
- this._hideMenuItem(menuItemId);
- },
- showMenuItem : function(menuItemId){
- this._showMenuItem(menuItemId);
- },
- toggleMenuItem: function(menuItemId, show) {
- if (show) {
- this._showMenuItem(menuItemId);
- } else {
- this._hideMenuItem(menuItemId);
- }
- },
- /*
- * Blur event does not happen on the element we created the context menu on, this
- * hides the menu when the creating element is clicked.
- * This forces a blur fire to when desired.
- * There is no public method to do this on Menu.
- */
- hideContextMenu: function(){
- this._onBlur();
- },
- _hideMenuItem :function(menuItemId){
- var menuItems = this.getChildren();
- for(var i=0; i < menuItems.length; ++i){
- if(menuItemId === menuItems[i].id){
- domStyle.set(menuItems[i].domNode, "display", "none");
- break;
- }
- }
- },
- _showMenuItem : function(menuItemId){
- var menuItems = this.getChildren();
- for(var i=0; i < menuItems.length; ++i){
- if(menuItemId === menuItems[i].id){
- domStyle.set(menuItems[i].domNode, "display", "");
- break;
- }
- }
- },
- });
- return ContextMenu;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement