Browse Source

Removed redundant events.js

css_transitions
josdejong 10 years ago
parent
commit
57732eef35
4 changed files with 2 additions and 120 deletions
  1. +0
    -1
      Jakefile.js
  2. +2
    -2
      examples/graph/07_selections.html
  3. +0
    -116
      src/events.js
  4. +0
    -1
      src/module/exports.js

+ 0
- 1
Jakefile.js View File

@ -54,7 +54,6 @@ task('build', {async: true}, function () {
'./src/shim.js', './src/shim.js',
'./src/util.js', './src/util.js',
'./src/events.js',
'./src/DataSet.js', './src/DataSet.js',
'./src/DataView.js', './src/DataView.js',

+ 2
- 2
examples/graph/07_selections.html View File

@ -51,8 +51,8 @@
graph = new vis.Graph(container, data, options); graph = new vis.Graph(container, data, options);
// add event listener // add event listener
graph.on('select', function(params) {
document.getElementById('info').innerHTML += 'selection: ' + params.nodes + '<br>';
graph.on('select', function(properties) {
document.getElementById('info').innerHTML += 'selection: ' + JSON.stringify(properties) + '<br>';
}); });
// set initial selection (id's of some nodes) // set initial selection (id's of some nodes)

+ 0
- 116
src/events.js View File

@ -1,116 +0,0 @@
/**
* Event listener (singleton)
*/
// TODO: replace usage of the event listener for the EventBus
var events = {
'listeners': [],
/**
* Find a single listener by its object
* @param {Object} object
* @return {Number} index -1 when not found
*/
'indexOf': function (object) {
var listeners = this.listeners;
for (var i = 0, iMax = this.listeners.length; i < iMax; i++) {
var listener = listeners[i];
if (listener && listener.object == object) {
return i;
}
}
return -1;
},
/**
* Add an event listener
* @param {Object} object
* @param {String} event The name of an event, for example 'select'
* @param {function} callback The callback method, called when the
* event takes place
*/
'addListener': function (object, event, callback) {
var index = this.indexOf(object);
var listener = this.listeners[index];
if (!listener) {
listener = {
'object': object,
'events': {}
};
this.listeners.push(listener);
}
var callbacks = listener.events[event];
if (!callbacks) {
callbacks = [];
listener.events[event] = callbacks;
}
// add the callback if it does not yet exist
if (callbacks.indexOf(callback) == -1) {
callbacks.push(callback);
}
},
/**
* Remove an event listener
* @param {Object} object
* @param {String} event The name of an event, for example 'select'
* @param {function} callback The registered callback method
*/
'removeListener': function (object, event, callback) {
var index = this.indexOf(object);
var listener = this.listeners[index];
if (listener) {
var callbacks = listener.events[event];
if (callbacks) {
index = callbacks.indexOf(callback);
if (index != -1) {
callbacks.splice(index, 1);
}
// remove the array when empty
if (callbacks.length == 0) {
delete listener.events[event];
}
}
// count the number of registered events. remove listener when empty
var count = 0;
var events = listener.events;
for (var e in events) {
if (events.hasOwnProperty(e)) {
count++;
}
}
if (count == 0) {
delete this.listeners[index];
}
}
},
/**
* Remove all registered event listeners
*/
'removeAllListeners': function () {
this.listeners = [];
},
/**
* Trigger an event. All registered event handlers will be called
* @param {Object} object
* @param {String} event
* @param {Object} properties (optional)
*/
'trigger': function (object, event, properties) {
var index = this.indexOf(object);
var listener = this.listeners[index];
if (listener) {
var callbacks = listener.events[event];
if (callbacks) {
for (var i = 0, iMax = callbacks.length; i < iMax; i++) {
callbacks[i](properties);
}
}
}
}
};

+ 0
- 1
src/module/exports.js View File

@ -3,7 +3,6 @@
*/ */
var vis = { var vis = {
util: util, util: util,
events: events,
Controller: Controller, Controller: Controller,
DataSet: DataSet, DataSet: DataSet,

Loading…
Cancel
Save