blob: 6519b7d976d503da73bab8307c69ac0fa9773be5 [file] [log] [blame]
lombardoffb37bca2018-05-03 16:20:04 +02001/*
2 Copyright 2017 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
lombardofre6eb7432018-10-28 19:43:46 +01003 Copyright 2018 EveryUP srl
lombardoffb37bca2018-05-03 16:20:04 +02004
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
lombardofre6eb7432018-10-28 19:43:46 +010018if (typeof TCD3 === 'undefined') {
19 var TCD3 = {};
lombardoffb37bca2018-05-03 16:20:04 +020020}
21
lombardofre6eb7432018-10-28 19:43:46 +010022TCD3.Event = (function () {
lombardoffb37bca2018-05-03 16:20:04 +020023 'use strict';
24
25 function Event () {
lombardofre6eb7432018-10-28 19:43:46 +010026 this._listeners = {};
lombardoffb37bca2018-05-03 16:20:04 +020027 }
28
29 Event.prototype.addL = function (type, listener) {
lombardofre6eb7432018-10-28 19:43:46 +010030 if (typeof this._listeners[type] === "undefined"){
lombardoffb37bca2018-05-03 16:20:04 +020031 this._listeners[type] = [];
32 }
33 this._listeners[type].push(listener);
34 };
35
36 Event.prototype.fire = function (event, args) {
lombardofre6eb7432018-10-28 19:43:46 +010037 if (typeof event === "string"){
lombardoffb37bca2018-05-03 16:20:04 +020038 event = { type: event };
39 }
40 if (!event.target){
41 event.target = this;
42 }
43
lombardofre6eb7432018-10-28 19:43:46 +010044 if (!event.type){
lombardoffb37bca2018-05-03 16:20:04 +020045 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
lombardofre6eb7432018-10-28 19:43:46 +010056 /*Event.prototype.addListener = function (type, listener) {
lombardoffb37bca2018-05-03 16:20:04 +020057 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
lombardofre6eb7432018-10-28 19:43:46 +010067 };*/
lombardoffb37bca2018-05-03 16:20:04 +020068
69 return Event;
70}());
71
72if (typeof module === 'object') {
lombardofre6eb7432018-10-28 19:43:46 +010073 module.exports = TCD3.Event;
lombardoffb37bca2018-05-03 16:20:04 +020074}