Add editor events component and migrate to it

This commit is contained in:
Nick O'Leary
2015-07-10 19:49:31 +01:00
parent 60539d890b
commit 999cf66b27
11 changed files with 66 additions and 102 deletions

View File

@@ -94,8 +94,7 @@ RED.workspaces = (function() {
}
activeWorkspace = tab.id;
event.workspace = activeWorkspace;
eventHandler.emit("change",event);
RED.events.emit("workspace:change",event);
},
ondblclick: function(tab) {
if (tab.type != "subflow") {
@@ -200,33 +199,13 @@ RED.workspaces = (function() {
function init() {
createWorkspaceTabs();
$('#btn-workspace-add-tab').on("click",function(e) {addWorkspace(); e.preventDefault()});
RED.sidebar.on("resize",workspace_tabs.resize);
RED.events.on("sidebar:resize",workspace_tabs.resize);
RED.menu.setAction('menu-item-workspace-delete',function() {
deleteWorkspace(RED.nodes.workspace(activeWorkspace));
});
}
// TODO: DRY
var eventHandler = (function() {
var handlers = {};
return {
on: function(evt,func) {
handlers[evt] = handlers[evt]||[];
handlers[evt].push(func);
},
emit: function(evt,arg) {
if (handlers[evt]) {
for (var i=0;i<handlers[evt].length;i++) {
handlers[evt][i](arg);
}
}
}
}
})();
function removeWorkspace(ws) {
if (!ws) {
deleteWorkspace(RED.nodes.workspace(activeWorkspace));
@@ -238,7 +217,6 @@ RED.workspaces = (function() {
}
return {
init: init,
on: eventHandler.on,
add: addWorkspace,
remove: removeWorkspace,