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