[wip] NS instance topology view
[osm/LW-UI.git] / static / TopologyComposer / js / event.js
1 /*
2 Copyright 2017 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
3 Copyright 2018 EveryUP srl
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17
18 if (typeof TCD3 === 'undefined') {
19 var TCD3 = {};
20 }
21
22 TCD3.Event = (function () {
23 'use strict';
24
25 function Event () {
26 this._listeners = {};
27 }
28
29 Event.prototype.addL = function (type, listener) {
30 if (typeof this._listeners[type] === "undefined"){
31 this._listeners[type] = [];
32 }
33 this._listeners[type].push(listener);
34 };
35
36 Event.prototype.fire = function (event, args) {
37 if (typeof event === "string"){
38 event = { type: event };
39 }
40 if (!event.target){
41 event.target = this;
42 }
43
44 if (!event.type){
45 throw new Error("Event object missing 'type' property.");
46 }
47
48 if (this._listeners[event.type] instanceof Array){
49 var listeners = this._listeners[event.type];
50 for (var i=0, len=listeners.length; i < len; i++){
51 listeners[i].call(this, event, args);
52 }
53 }
54 };
55
56 /*Event.prototype.addListener = function (type, listener) {
57 if (this._listeners[type] instanceof Array){
58 var listeners = this._listeners[type];
59 for (var i=0, len=listeners.length; i < len; i++){
60 if (listeners[i] === listener){
61 listeners.splice(i, 1);
62 break;
63 }
64 }
65 }
66
67 };*/
68
69 return Event;
70 }());
71
72 if (typeof module === 'object') {
73 module.exports = TCD3.Event;
74 }