| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 |
4×
4×
4×
4×
4×
4×
4×
12×
4×
4×
4×
1×
18×
18×
18×
18×
4×
12×
12×
6×
6×
6×
6×
6×
18×
18×
12×
18×
4×
4×
1×
4×
6×
12×
4×
4×
| "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _assign = require("babel-runtime/core-js/object/assign");
var _assign2 = _interopRequireDefault(_assign);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* global CustomEvent */
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 David Heidrich, BowlingX <me@bowlingx.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
// polyfill for custom events to make thinks work in IE
// The needed polyfill is so small that I embedded it here
(function poly() {
Iif (global.document && (!global.CustomEvent || typeof global.CustomEvent !== 'function')) {
var _CustomEvent = function CustomEvent(event, params) {
var thisParams = params || {
bubbles: false,
cancelable: false,
detail: undefined
};
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent(event, thisParams.bubbles, thisParams.cancelable, thisParams.detail);
evt.superPreventDefault = evt.preventDefault;
evt.preventDefault = function () {
// Due a bug in IE11, we need to set defaultPrevented manually
Object.defineProperty(evt, "defaultPrevented", {
get: function get() {
return true;
}
});
evt.superPreventDefault();
};
return evt;
};
_CustomEvent.prototype = global.Event.prototype;
global.CustomEvent = _CustomEvent;
}
})();
/**
* Simpler Event dispatching
*/
var EventHandler = function () {
/**
* @param {HTMLElement} target
* @param {String} name
*/
function EventHandler(target, name) {
(0, _classCallCheck3.default)(this, EventHandler);
this.target = target;
this.defaultOptions = {
bubbles: true,
cancelable: true
};
this.name = name;
}
/**
* Set more options
* @param {Object} options
* @returns {EventHandler}
*/
(0, _createClass3.default)(EventHandler, [{
key: "withOptions",
value: function withOptions(options) {
(0, _assign2.default)(this.defaultOptions, options || {});
return this;
}
/**
* Call with the originalEvent
* @param {Event} e
* @returns {EventHandler}
*/
}, {
key: "withOriginal",
value: function withOriginal(e) {
return this.withDetail({
originalEvent: e
});
}
/**
* Extends the detail part of the event
* @param {Object} o
* @returns {EventHandler}
*/
}, {
key: "withDetail",
value: function withDetail(o) {
Eif (!this.defaultOptions.detail) {
this.defaultOptions.detail = {};
}
(0, _assign2.default)(this.defaultOptions.detail, o);
return this;
}
/**
* @returns {CustomEvent}
*/
}, {
key: "fire",
value: function fire() {
var e = new CustomEvent(this.name, this.defaultOptions);
if (this.target) {
this.target.dispatchEvent(e);
}
return e;
}
}]);
return EventHandler;
}();
var Event = function () {
function Event() {
(0, _classCallCheck3.default)(this, Event);
}
(0, _createClass3.default)(Event, null, [{
key: "dispatch",
/**
* Prepares to dispatch a custom event (without firing)
* @param {HTMLElement} target
* @param {String} name
* @returns {EventHandler}
*/
value: function dispatch(target, name) {
return new EventHandler(target, name);
}
/**
* Dispatches a custom event and fires it directly
* @param {HTMLElement} target
* @param {String} name
* @param {Object} [options]
* @returns {CustomEvent}
*/
}, {
key: "dispatchAndFire",
value: function dispatchAndFire(target, name, options) {
return new EventHandler(target, name).withOptions(options).fire();
}
}]);
return Event;
}();
exports.default = Event;
|