├── .gitignore ├── example ├── node │ └── app.js └── browser │ └── example.html ├── package.json ├── LICENSE ├── lib └── eventbus.min.js ├── src └── EventBus.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log -------------------------------------------------------------------------------- /example/node/app.js: -------------------------------------------------------------------------------- 1 | var EventBus = require('../../lib/eventbus.min'); 2 | 3 | function myFunction(event) { 4 | console.log('myFunction type=' + event.type); 5 | } 6 | EventBus.addEventListener('my_function_event', myFunction); 7 | EventBus.dispatch('my_function_event'); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eventbusjs", 3 | "version": "0.2.0", 4 | "description": "Managing events with JavaScript", 5 | "main": "lib/eventbus.min.js", 6 | "directories": { 7 | "example": "example" 8 | }, 9 | "scripts": { 10 | "build": "uglifyjs ./src/EventBus.js -o ./lib/eventbus.min.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/krasimir/EventBus.git" 15 | }, 16 | "keywords": [ 17 | "event", 18 | "bus", 19 | "dispatch", 20 | "listen" 21 | ], 22 | "author": "Krasimir Tsonev", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/krasimir/EventBus/issues" 26 | }, 27 | "homepage": "https://github.com/krasimir/EventBus", 28 | "devDependencies": { 29 | "uglify-js": "2.6.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Krasimir Tsonev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /lib/eventbus.min.js: -------------------------------------------------------------------------------- 1 | (function(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define("EventBus",[],factory);else if(typeof exports==="object")exports["EventBus"]=factory();else root["EventBus"]=factory()})(this,function(){var EventBusClass={};EventBusClass=function(){this.listeners={}};EventBusClass.prototype={addEventListener:function(type,callback,scope){var args=[];var numOfArgs=arguments.length;for(var i=0;i3?args.splice(3,args.length-1):[];if(typeof this.listeners[type]!="undefined"){this.listeners[type].push({scope:scope,callback:callback,args:args})}else{this.listeners[type]=[{scope:scope,callback:callback,args:args}]}},removeEventListener:function(type,callback,scope){if(typeof this.listeners[type]!="undefined"){var numOfCallbacks=this.listeners[type].length;var newArray=[];for(var i=0;i0}for(var i=0;i2?args.splice(2,args.length-1):[];args=[event].concat(args);if(typeof this.listeners[type]!="undefined"){var listeners=this.listeners[type].slice();var numOfCallbacks=listeners.length;for(var i=0;i 2 | 3 | 4 | Events 5 | 6 | 7 | 74 | 75 | 76 | 77 |
78 | 79 |
80 | 81 | -------------------------------------------------------------------------------- /src/EventBus.js: -------------------------------------------------------------------------------- 1 | (function (root, factory) { 2 | if(typeof exports === 'object' && typeof module === 'object') 3 | module.exports = factory(); 4 | else if(typeof define === 'function' && define.amd) 5 | define("EventBus", [], factory); 6 | else if(typeof exports === 'object') 7 | exports["EventBus"] = factory(); 8 | else 9 | root["EventBus"] = factory(); 10 | })(this, function() { 11 | 12 | var EventBusClass = {}; 13 | EventBusClass = function() { 14 | this.listeners = {}; 15 | }; 16 | EventBusClass.prototype = { 17 | addEventListener: function(type, callback, scope) { 18 | var args = []; 19 | var numOfArgs = arguments.length; 20 | for(var i=0; i 3 ? args.splice(3, args.length-1) : []; 24 | if(typeof this.listeners[type] != "undefined") { 25 | this.listeners[type].push({scope:scope, callback:callback, args:args}); 26 | } else { 27 | this.listeners[type] = [{scope:scope, callback:callback, args:args}]; 28 | } 29 | }, 30 | removeEventListener: function(type, callback, scope) { 31 | if(typeof this.listeners[type] != "undefined") { 32 | var numOfCallbacks = this.listeners[type].length; 33 | var newArray = []; 34 | for(var i=0; i 0; 50 | } 51 | for(var i=0; i 2 ? args.splice(2, args.length-1) : []; 71 | args = [event].concat(args); 72 | 73 | 74 | if(typeof this.listeners[type] != "undefined") { 75 | var listeners = this.listeners[type].slice(); 76 | var numOfCallbacks = listeners.length; 77 | for(var i=0; i