| 1947 | } |
| 1948 | } |
| 1949 | const createEventStorage = function(obj) { |
| 1950 | let handlers = {}; |
| 1951 | let index = 0; |
| 1952 | const eventStorage = function() { |
| 1953 | let combinedResult = true; |
| 1954 | for (const i in handlers) { |
| 1955 | const handlerResult = handlers[i].apply(obj, arguments); |
| 1956 | combinedResult = combinedResult && handlerResult; |
| 1957 | } |
| 1958 | return combinedResult; |
| 1959 | }; |
| 1960 | eventStorage.addEvent = function(handler, settings) { |
| 1961 | if (typeof handler == "function") { |
| 1962 | let handlerId; |
| 1963 | if (settings && settings.id) { |
| 1964 | handlerId = settings.id; |
| 1965 | } else { |
| 1966 | handlerId = index; |
| 1967 | index++; |
| 1968 | } |
| 1969 | if (settings && settings.once) { |
| 1970 | const originalHandler = handler; |
| 1971 | handler = function() { |
| 1972 | originalHandler(); |
| 1973 | eventStorage.removeEvent(handlerId); |
| 1974 | }; |
| 1975 | } |
| 1976 | handlers[handlerId] = handler; |
| 1977 | return handlerId; |
| 1978 | } |
| 1979 | return false; |
| 1980 | }; |
| 1981 | eventStorage.removeEvent = function(id) { |
| 1982 | delete handlers[id]; |
| 1983 | }; |
| 1984 | eventStorage.clear = function() { |
| 1985 | handlers = {}; |
| 1986 | }; |
| 1987 | return eventStorage; |
| 1988 | }; |
| 1989 | function makeEventable(obj) { |
| 1990 | const eventHost = new EventHost(); |
| 1991 | obj.attachEvent = function(eventName, handler, settings) { |