1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-apiclient/events.js

1 line
747 B
JavaScript
Raw Normal View History

2018-09-12 19:26:21 +02:00
define([],function(){"use strict";function getCallbacks(obj,name){if(!obj)throw new Error("obj cannot be null!");obj._callbacks=obj._callbacks||{};var list=obj._callbacks[name];return list||(obj._callbacks[name]=[],list=obj._callbacks[name]),list}return{on:function(obj,eventName,fn){getCallbacks(obj,eventName).push(fn)},off:function(obj,eventName,fn){var list=getCallbacks(obj,eventName),i=list.indexOf(fn);-1!==i&&list.splice(i,1)},trigger:function(obj,eventName){var eventObject={type:eventName},eventArgs=[];eventArgs.push(eventObject);for(var additionalArgs=arguments[2]||[],i=0,length=additionalArgs.length;i<length;i++)eventArgs.push(additionalArgs[i]);getCallbacks(obj,eventName).slice(0).forEach(function(c){c.apply(obj,eventArgs)})}}});