From 999cf66b27a5b58a03e02e3dd85a0495c71d52c9 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 10 Jul 2015 19:49:31 +0100 Subject: [PATCH] Add editor events component and migrate to it --- Gruntfile.js | 5 ++-- editor/js/events.js | 48 ++++++++++++++++++++++++++++++++++++++ editor/js/nodes.js | 24 +------------------ editor/js/ui/clipboard.js | 2 +- editor/js/ui/deploy.js | 3 ++- editor/js/ui/library.js | 2 +- editor/js/ui/sidebar.js | 28 ++++------------------ editor/js/ui/subflow.js | 2 +- editor/js/ui/tab-info.js | 2 +- editor/js/ui/view.js | 26 ++------------------- editor/js/ui/workspaces.js | 26 ++------------------- 11 files changed, 66 insertions(+), 102 deletions(-) create mode 100644 editor/js/events.js diff --git a/Gruntfile.js b/Gruntfile.js index 04273c683..ad46baee9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -93,6 +93,7 @@ module.exports = function(grunt) { // Ensure editor source files are concatenated in // the right order "editor/js/main.js", + "editor/js/events.js", "editor/js/i18n.js", "editor/js/settings.js", "editor/js/user.js", @@ -301,7 +302,7 @@ module.exports = function(grunt) { mode: '755' }, release: { - // Target-specific file/dir lists and/or options go here. + // Target-specific file/dir lists and/or options go here. src: [ path.resolve('<%= paths.dist %>/node-red-<%= pkg.version %>/nodes/core/hardware/nrgpio*') ] @@ -332,7 +333,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-chmod'); grunt.loadNpmTasks('grunt-jsonlint'); - + grunt.registerMultiTask('attachCopyright', function() { var files = this.data.src; var copyright = "/**\n"+ diff --git a/editor/js/events.js b/editor/js/events.js new file mode 100644 index 000000000..804027af9 --- /dev/null +++ b/editor/js/events.js @@ -0,0 +1,48 @@ +/** + * Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + + RED.events = (function() { + var handlers = {}; + + function on(evt,func) { + handlers[evt] = handlers[evt]||[]; + handlers[evt].push(func); + } + function off(evt,func) { + var handler = handlers[evt]; + if (handler) { + for (var i=0;i