diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 0df1c6e4..d2cf8e8a 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -124,6 +124,7 @@ ${basedir}/target/compress header.js + Events.js ${basedir}/../web2d/target/classes/web2d.svg-min.js Messages.js TopicEventDispatcher.js diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index 22c6bab0..b2210b3f 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -17,7 +17,7 @@ */ mindplot.Designer = new Class({ - Extends:Events, + Extends: mindplot.Events, initialize:function (options, divElement) { $assert(options, "options must be defined"); $assert(options.zoom, "zoom must be defined"); diff --git a/mindplot/src/main/javascript/Events.js b/mindplot/src/main/javascript/Events.js new file mode 100644 index 00000000..7bbea205 --- /dev/null +++ b/mindplot/src/main/javascript/Events.js @@ -0,0 +1,63 @@ +mindplot.Events = new Class({ + + $events: {}, + + _removeOn: function(string){ + return string.replace(/^on([A-Z])/, function(full, first){ + return first.toLowerCase(); + }); + }, + + addEvent: function(type, fn, internal){ + type = this._removeOn(type); + + this.$events[type] = (this.$events[type] || []).include(fn); + if (internal) fn.internal = true; + return this; + }, + + addEvents: function(events){ + for (var type in events) this.addEvent(type, events[type]); + return this; + }, + + fireEvent: function(type, args, delay){ + type = this._removeOn(type); + var events = this.$events[type]; + if (!events) return this; + args = Array.from(args); + events.each(function(fn){ + if (delay) fn.delay(delay, this, args); + else fn.apply(this, args); + }, this); + return this; + }, + + removeEvent: function(type, fn){ + type = this._removeOn(type); + var events = this.$events[type]; + if (events && !fn.internal){ + var index = events.indexOf(fn); + if (index != -1) delete events[index]; + } + return this; + }, + + removeEvents: function(events){ + var type; + if (typeOf(events) == 'object'){ + for (type in events) this.removeEvent(type, events[type]); + return this; + } + if (events) events = removeOn(events); + for (type in this.$events){ + if (events && events != type) continue; + var fns = this.$events[type]; + for (var i = fns.length; i--;) if (i in fns){ + this.removeEvent(type, fns[i]); + } + } + return this; + } + +}); diff --git a/mindplot/src/main/javascript/MultilineTextEditor.js b/mindplot/src/main/javascript/MultilineTextEditor.js index 06fa546a..87aae092 100644 --- a/mindplot/src/main/javascript/MultilineTextEditor.js +++ b/mindplot/src/main/javascript/MultilineTextEditor.js @@ -17,7 +17,7 @@ */ mindplot.MultilineTextEditor = new Class({ - Extends:Events, + Extends: mindplot.Events, initialize:function () { this._topic = null; this._timeoutId = -1; diff --git a/mindplot/src/main/javascript/TopicEventDispatcher.js b/mindplot/src/main/javascript/TopicEventDispatcher.js index 20476d10..71b4f033 100644 --- a/mindplot/src/main/javascript/TopicEventDispatcher.js +++ b/mindplot/src/main/javascript/TopicEventDispatcher.js @@ -17,7 +17,7 @@ */ mindplot.TopicEventDispatcher = new Class({ - Extends: Events, + Extends: mindplot.Events, Static: { _instance: null, diff --git a/mindplot/src/main/javascript/layout/LayoutManager.js b/mindplot/src/main/javascript/layout/LayoutManager.js index 3b89ad5f..49cbacbb 100644 --- a/mindplot/src/main/javascript/layout/LayoutManager.js +++ b/mindplot/src/main/javascript/layout/LayoutManager.js @@ -16,7 +16,7 @@ * limitations under the License. */ mindplot.layout.LayoutManager = new Class({ - Extends: Events, + Extends: mindplot.Events, initialize: function(rootNodeId, rootSize) { $assert($defined(rootNodeId), "rootNodeId can not be null"); $assert(rootSize, "rootSize can not be null");