added missing semicolons. Need to investigate contextMenuExtensions potential leaking
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2388 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -13,54 +13,50 @@ var svgedit = svgedit || {};
|
|||||||
if (!svgedit.contextmenu) {
|
if (!svgedit.contextmenu) {
|
||||||
svgedit.contextmenu = {};
|
svgedit.contextmenu = {};
|
||||||
}
|
}
|
||||||
self.contextMenuExtensions = {}
|
self.contextMenuExtensions = {};
|
||||||
|
var menuItemIsValid = function(menuItem) {
|
||||||
|
return menuItem && menuItem.id && menuItem.label && menuItem.action && typeof menuItem.action == 'function';
|
||||||
|
};
|
||||||
var addContextMenuItem = function(menuItem) {
|
var addContextMenuItem = function(menuItem) {
|
||||||
// menuItem: {id, label, shortcut, action}
|
// menuItem: {id, label, shortcut, action}
|
||||||
if (!menuItemIsValid(menuItem)) {
|
if (!menuItemIsValid(menuItem)) {
|
||||||
console
|
console.error("Menu items must be defined and have at least properties: id, label, action, where action must be a function");
|
||||||
.error("Menu items must be defined and have at least properties: id, label, action, where action must be a function");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (menuItem.id in self.contextMenuExtensions) {
|
if (menuItem.id in self.contextMenuExtensions) {
|
||||||
console.error('Cannot add extension "' + menuItem.id
|
console.error('Cannot add extension "' + menuItem.id + '", an extension by that name already exists"');
|
||||||
+ '", an extension by that name already exists"');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Register menuItem action, see below for deferred menu dom injection
|
// Register menuItem action, see below for deferred menu dom injection
|
||||||
console.log("Registed contextmenu item: {id:"+ menuItem.id+", label:"+menuItem.label+"}");
|
console.log("Registed contextmenu item: {id:"+ menuItem.id+", label:"+menuItem.label+"}");
|
||||||
self.contextMenuExtensions[menuItem.id] = menuItem;
|
self.contextMenuExtensions[menuItem.id] = menuItem;
|
||||||
//TODO: Need to consider how to handle custom enable/disable behavior
|
//TODO: Need to consider how to handle custom enable/disable behavior
|
||||||
}
|
};
|
||||||
var hasCustomHandler = function(handlerKey) {
|
var hasCustomHandler = function(handlerKey) {
|
||||||
return self.contextMenuExtensions[handlerKey] && true;
|
return self.contextMenuExtensions[handlerKey] && true;
|
||||||
}
|
};
|
||||||
var getCustomHandler = function(handlerKey) {
|
var getCustomHandler = function(handlerKey) {
|
||||||
return self.contextMenuExtensions[handlerKey].action;
|
return self.contextMenuExtensions[handlerKey].action;
|
||||||
}
|
};
|
||||||
var injectExtendedContextMenuItemIntoDom = function(menuItem) {
|
var injectExtendedContextMenuItemIntoDom = function(menuItem) {
|
||||||
if (Object.keys(self.contextMenuExtensions).length == 0) {
|
if (Object.keys(self.contextMenuExtensions).length === 0) {
|
||||||
// all menuItems appear at the bottom of the menu in their own container.
|
// all menuItems appear at the bottom of the menu in their own container.
|
||||||
// if this is the first extension menu we need to add the separator.
|
// if this is the first extension menu we need to add the separator.
|
||||||
$("#cmenu_canvas").append("<li class='separator'>");
|
$("#cmenu_canvas").append("<li class='separator'>");
|
||||||
}
|
}
|
||||||
var shortcut = menuItem.shortcut || "";
|
var shortcut = menuItem.shortcut || "";
|
||||||
$("#cmenu_canvas").append("<li class='disabled'><a href='#" + menuItem.id + "'>"
|
$("#cmenu_canvas").append("<li class='disabled'><a href='#" + menuItem.id + "'>"
|
||||||
+ menuItem.label + "<span class='shortcut'>"
|
+ menuItem.label + "<span class='shortcut'>"
|
||||||
+ shortcut + "</span></a></li>");
|
+ shortcut + "</span></a></li>");
|
||||||
}
|
};
|
||||||
|
|
||||||
var menuItemIsValid = function(menuItem) {
|
|
||||||
return menuItem && menuItem.id && menuItem.label && menuItem.action && typeof menuItem.action == 'function';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Defer injection to wait out initial menu processing. This probably goes away once all context
|
// Defer injection to wait out initial menu processing. This probably goes away once all context
|
||||||
// menu behavior is brought here.
|
// menu behavior is brought here.
|
||||||
svgEditor.ready(function() {
|
svgEditor.ready(function() {
|
||||||
for (menuItem in contextMenuExtensions) {
|
for (var menuItem in contextMenuExtensions) {
|
||||||
injectExtendedContextMenuItemIntoDom(contextMenuExtensions[menuItem]);
|
injectExtendedContextMenuItemIntoDom(contextMenuExtensions[menuItem]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
svgedit.contextmenu.resetCustomMenus = function(){self.contextMenuExtensions = {}}
|
svgedit.contextmenu.resetCustomMenus = function(){self.contextMenuExtensions = {};};
|
||||||
svgedit.contextmenu.add = addContextMenuItem;
|
svgedit.contextmenu.add = addContextMenuItem;
|
||||||
svgedit.contextmenu.hasCustomHandler = hasCustomHandler;
|
svgedit.contextmenu.hasCustomHandler = hasCustomHandler;
|
||||||
svgedit.contextmenu.getCustomHandler = getCustomHandler;
|
svgedit.contextmenu.getCustomHandler = getCustomHandler;
|
||||||
|
|||||||
Reference in New Issue
Block a user