1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update event binding

This commit is contained in:
Luke Pulverenti 2015-12-17 10:54:47 -05:00
parent bcfbb01b4b
commit a08715f2f2
10 changed files with 164 additions and 126 deletions

View file

@ -16,12 +16,12 @@
},
"devDependencies": {},
"ignore": [],
"version": "1.0.13",
"_release": "1.0.13",
"version": "1.0.15",
"_release": "1.0.15",
"_resolution": {
"type": "version",
"tag": "1.0.13",
"commit": "50abac508289fd4db77f6d52ba1ee351b57baec2"
"tag": "1.0.15",
"commit": "2b89c4815135e6acef56ec14d56ad0a1d7551e00"
},
"_source": "git://github.com/MediaBrowser/Emby.ApiClient.Javascript.git",
"_target": "~1.0.3",

View file

@ -2,22 +2,20 @@
function getCallbacks(obj, name) {
ensureCallbacks(obj, name);
return obj._callbacks[name];
}
function ensureCallbacks(obj, name) {
if (!obj) {
throw new Error("obj cannot be null!");
}
obj._callbacks = obj._callbacks || {};
if (!obj._callbacks[name]) {
var list = obj._callbacks[name];
if (!list) {
obj._callbacks[name] = [];
list = obj._callbacks[name];
}
return list;
}
return {
@ -26,17 +24,17 @@
var list = getCallbacks(obj, eventName);
if (list.indexOf(fn) == -1) {
list.push(fn);
}
list.push(fn);
},
off: function (obj, eventName, fn) {
var list = getCallbacks(obj, eventName);
obj._callbacks[name] = list.filter(function (i) {
return i != fn;
});
var i = list.indexOf(fn);
if (i != -1) {
list.splice(i, 1);
}
},
trigger: function (obj, eventName) {
@ -53,7 +51,9 @@
eventArgs.push(additionalArgs[i]);
}
getCallbacks(obj, eventName).forEach(function (c) {
var callbacks = getCallbacks(obj, eventName).slice(0);
callbacks.forEach(function (c) {
c.apply(obj, eventArgs);
});
}