@converse/skeletor 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -7
- package/dist/skeletor.js +508 -1048
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +4 -93
- package/dist/skeletor.min.js.map +1 -1
- package/package.json +6 -7
- package/src/collection.js +1 -1
- package/src/drivers/indexeddb-getitems.js~ +1116 -0
- package/src/drivers/indexeddb.js~ +1115 -0
- package/src/storage.js +11 -8
- package/src/storage.js~ +13 -9
- package/CHANGES.md +0 -26
- package/dist/skeletor.js~ +0 -2291
- package/src/.events.js.swp +0 -0
- package/src/.helpers.js.swp +0 -0
- package/src/.history.js.swp +0 -0
- package/src/.model.js.swp +0 -0
- package/src/.overview.js.swp +0 -0
- package/src/.router.js.swp +0 -0
- package/src/.view.js.swp +0 -0
- package/src/collection.js~ +0 -737
- package/src/drivers/.sessionStorage.js.swp +0 -0
- package/src/drivers/sessionStorage.js~ +0 -316
- package/src/element-overview.js~ +0 -4
- package/src/element.js~ +0 -190
- package/src/events.js~ +0 -334
- package/src/helpers.js~ +0 -151
- package/src/history.js~ +0 -301
- package/src/htmlview.js~ +0 -14
- package/src/model.js~ +0 -439
- package/src/orderedlist.js~ +0 -88
- package/src/overview.js~ +0 -111
- package/src/router.js~ +0 -119
- package/src/vdomview.js~ +0 -15
- package/src/view.js~ +0 -283
|
Binary file
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
// Copyright 2014 Mozilla
|
|
2
|
-
// Copyright 2015 Thodoris Greasidis
|
|
3
|
-
// Copyright 2018 JC Brand
|
|
4
|
-
//
|
|
5
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
// you may not use this file except in compliance with the License.
|
|
7
|
-
// You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
// See the License for the specific language governing permissions and
|
|
15
|
-
// limitations under the License.
|
|
16
|
-
|
|
17
|
-
import executeCallback from 'localforage/src/utils/executeCallback';
|
|
18
|
-
import getCallback from 'localforage/src/utils/getCallback';
|
|
19
|
-
import normalizeKey from 'localforage/src/utils/normalizeKey';
|
|
20
|
-
import serializer from 'localforage/src/utils/serializer';
|
|
21
|
-
|
|
22
|
-
const serialize = serializer["serialize"];
|
|
23
|
-
const deserialize = serializer["deserialize"];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function isSessionStorageValid () {
|
|
27
|
-
// If the app is running inside a Google Chrome packaged webapp, or some
|
|
28
|
-
// other context where sessionStorage isn't available, we don't use
|
|
29
|
-
// sessionStorage. This feature detection is preferred over the old
|
|
30
|
-
// `if (window.chrome && window.chrome.runtime)` code.
|
|
31
|
-
// See: https://github.com/mozilla/localForage/issues/68
|
|
32
|
-
try {
|
|
33
|
-
// If sessionStorage isn't available, we get outta here!
|
|
34
|
-
// This should be inside a try catch
|
|
35
|
-
if (sessionStorage && ('setItem' in sessionStorage)) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.log(e);
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _getKeyPrefix(options, defaultConfig) {
|
|
45
|
-
let keyPrefix = options.name + '/';
|
|
46
|
-
|
|
47
|
-
if (options.storeName !== defaultConfig.storeName) {
|
|
48
|
-
keyPrefix += options.storeName + '/';
|
|
49
|
-
}
|
|
50
|
-
return keyPrefix;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const dbInfo = {
|
|
54
|
-
'serializer': {
|
|
55
|
-
'serialize': serialize,
|
|
56
|
-
'deserialize': deserialize
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function _initStorage(options) {
|
|
61
|
-
dbInfo.keyPrefix = _getKeyPrefix(options, this._defaultConfig);
|
|
62
|
-
if (options) {
|
|
63
|
-
for (const i in options) { // eslint-disable-line guard-for-in
|
|
64
|
-
dbInfo[i] = options[i];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Remove all keys from the datastore, effectively destroying all data in
|
|
70
|
-
// the app's key/value store!
|
|
71
|
-
function clear(callback) {
|
|
72
|
-
const promise = this.ready().then(function() {
|
|
73
|
-
const keyPrefix = dbInfo.keyPrefix;
|
|
74
|
-
|
|
75
|
-
for (let i = sessionStorage.length - 1; i >= 0; i--) {
|
|
76
|
-
const key = sessionStorage.key(i);
|
|
77
|
-
|
|
78
|
-
if (key.indexOf(keyPrefix) === 0) {
|
|
79
|
-
sessionStorage.removeItem(key);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
executeCallback(promise, callback);
|
|
85
|
-
return promise;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Retrieve an item from the store. Unlike the original async_storage
|
|
89
|
-
// library in Gaia, we don't modify return values at all. If a key's value
|
|
90
|
-
// is `undefined`, we pass that value to the callback function.
|
|
91
|
-
function getItem(key, callback) {
|
|
92
|
-
key = normalizeKey(key);
|
|
93
|
-
|
|
94
|
-
const promise = this.ready().then(function() {
|
|
95
|
-
let result = sessionStorage.getItem(dbInfo.keyPrefix + key);
|
|
96
|
-
// If a result was found, parse it from the serialized
|
|
97
|
-
// string into a JS object. If result isn't truthy, the key
|
|
98
|
-
// is likely undefined and we'll pass it straight to the
|
|
99
|
-
// callback.
|
|
100
|
-
if (result) {
|
|
101
|
-
result = dbInfo.serializer.deserialize(result);
|
|
102
|
-
}
|
|
103
|
-
return result;
|
|
104
|
-
});
|
|
105
|
-
executeCallback(promise, callback);
|
|
106
|
-
return promise;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Iterate over all items in the store.
|
|
110
|
-
function iterate(iterator, callback) {
|
|
111
|
-
const self = this;
|
|
112
|
-
|
|
113
|
-
const promise = self.ready().then(function() {
|
|
114
|
-
const keyPrefix = dbInfo.keyPrefix;
|
|
115
|
-
const keyPrefixLength = keyPrefix.length;
|
|
116
|
-
const length = sessionStorage.length;
|
|
117
|
-
|
|
118
|
-
// We use a dedicated iterator instead of the `i` variable below
|
|
119
|
-
// so other keys we fetch in sessionStorage aren't counted in
|
|
120
|
-
// the `iterationNumber` argument passed to the `iterate()`
|
|
121
|
-
// callback.
|
|
122
|
-
//
|
|
123
|
-
// See: github.com/mozilla/localForage/pull/435#discussion_r38061530
|
|
124
|
-
let iterationNumber = 1;
|
|
125
|
-
|
|
126
|
-
for (let i = 0; i < length; i++) {
|
|
127
|
-
const key = sessionStorage.key(i);
|
|
128
|
-
if (key.indexOf(keyPrefix) !== 0) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
let value = sessionStorage.getItem(key);
|
|
132
|
-
|
|
133
|
-
// If a result was found, parse it from the serialized
|
|
134
|
-
// string into a JS object. If result isn't truthy, the
|
|
135
|
-
// key is likely undefined and we'll pass it straight
|
|
136
|
-
// to the iterator.
|
|
137
|
-
if (value) {
|
|
138
|
-
value = dbInfo.serializer.deserialize(value);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
value = iterator(
|
|
142
|
-
value,
|
|
143
|
-
key.substring(keyPrefixLength),
|
|
144
|
-
iterationNumber++
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
if (value !== void 0) { // eslint-disable-line no-void
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
executeCallback(promise, callback);
|
|
154
|
-
return promise;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Same as sessionStorage's key() method, except takes a callback.
|
|
158
|
-
function key(n, callback) {
|
|
159
|
-
const self = this;
|
|
160
|
-
const promise = self.ready().then(function() {
|
|
161
|
-
let result;
|
|
162
|
-
try {
|
|
163
|
-
result = sessionStorage.key(n);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
result = null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Remove the prefix from the key, if a key is found.
|
|
169
|
-
if (result) {
|
|
170
|
-
result = result.substring(dbInfo.keyPrefix.length);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return result;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
executeCallback(promise, callback);
|
|
177
|
-
return promise;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function keys(callback) {
|
|
181
|
-
const self = this;
|
|
182
|
-
const promise = self.ready().then(function() {
|
|
183
|
-
const length = sessionStorage.length;
|
|
184
|
-
const keys = [];
|
|
185
|
-
|
|
186
|
-
for (let i = 0; i < length; i++) {
|
|
187
|
-
const itemKey = sessionStorage.key(i);
|
|
188
|
-
if (itemKey.indexOf(dbInfo.keyPrefix) === 0) {
|
|
189
|
-
keys.push(itemKey.substring(dbInfo.keyPrefix.length));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return keys;
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
executeCallback(promise, callback);
|
|
196
|
-
return promise;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Supply the number of keys in the datastore to the callback function.
|
|
200
|
-
function length(callback) {
|
|
201
|
-
const self = this;
|
|
202
|
-
const promise = self.keys().then(function(keys) {
|
|
203
|
-
return keys.length;
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
executeCallback(promise, callback);
|
|
207
|
-
return promise;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Remove an item from the store, nice and simple.
|
|
211
|
-
function removeItem(key, callback) {
|
|
212
|
-
key = normalizeKey(key);
|
|
213
|
-
const promise = this.ready().then(function() {
|
|
214
|
-
sessionStorage.removeItem(dbInfo.keyPrefix + key);
|
|
215
|
-
});
|
|
216
|
-
executeCallback(promise, callback);
|
|
217
|
-
return promise;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Set a key's value and run an optional callback once the value is set.
|
|
221
|
-
// Unlike Gaia's implementation, the callback function is passed the value,
|
|
222
|
-
// in case you want to operate on that value only after you're sure it
|
|
223
|
-
// saved, or something like that.
|
|
224
|
-
function setItem(key, value, callback) {
|
|
225
|
-
key = normalizeKey(key);
|
|
226
|
-
|
|
227
|
-
const promise = this.ready().then(function() {
|
|
228
|
-
// Convert undefined values to null.
|
|
229
|
-
// https://github.com/mozilla/localForage/pull/42
|
|
230
|
-
if (value === undefined) {
|
|
231
|
-
value = null;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Save the original value to pass to the callback.
|
|
235
|
-
const originalValue = value;
|
|
236
|
-
|
|
237
|
-
return new Promise(function(resolve, reject) {
|
|
238
|
-
dbInfo.serializer.serialize(value, function(value, error) {
|
|
239
|
-
if (error) {
|
|
240
|
-
reject(error);
|
|
241
|
-
} else {
|
|
242
|
-
try {
|
|
243
|
-
sessionStorage.setItem(dbInfo.keyPrefix + key, value);
|
|
244
|
-
resolve(originalValue);
|
|
245
|
-
} catch (e) {
|
|
246
|
-
// sessionStorage capacity exceeded.
|
|
247
|
-
// TODO: Make this a specific error/event.
|
|
248
|
-
if (
|
|
249
|
-
e.name === 'QuotaExceededError' ||
|
|
250
|
-
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
|
|
251
|
-
) {
|
|
252
|
-
reject(e);
|
|
253
|
-
}
|
|
254
|
-
reject(e);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
executeCallback(promise, callback);
|
|
262
|
-
return promise;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function dropInstance(options, callback) {
|
|
266
|
-
callback = getCallback.apply(this, arguments);
|
|
267
|
-
|
|
268
|
-
options = (typeof options !== 'function' && options) || {};
|
|
269
|
-
if (!options.name) {
|
|
270
|
-
const currentConfig = this.config();
|
|
271
|
-
options.name = options.name || currentConfig.name;
|
|
272
|
-
options.storeName = options.storeName || currentConfig.storeName;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const self = this;
|
|
276
|
-
let promise;
|
|
277
|
-
if (!options.name) {
|
|
278
|
-
promise = Promise.reject(new Error('Invalid arguments'));
|
|
279
|
-
} else {
|
|
280
|
-
promise = new Promise(function(resolve) {
|
|
281
|
-
if (!options.storeName) {
|
|
282
|
-
resolve(`${options.name}/`);
|
|
283
|
-
} else {
|
|
284
|
-
resolve(_getKeyPrefix(options, self._defaultConfig));
|
|
285
|
-
}
|
|
286
|
-
}).then(function(keyPrefix) {
|
|
287
|
-
for (var i = sessionStorage.length - 1; i >= 0; i--) {
|
|
288
|
-
var key = sessionStorage.key(i);
|
|
289
|
-
|
|
290
|
-
if (key.indexOf(keyPrefix) === 0) {
|
|
291
|
-
sessionStorage.removeItem(key);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
executeCallback(promise, callback);
|
|
298
|
-
return promise;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const sessionStorageWrapper = {
|
|
302
|
-
_driver: 'sessionStorageWrapper',
|
|
303
|
-
_initStorage: _initStorage,
|
|
304
|
-
_support: isSessionStorageValid(),
|
|
305
|
-
iterate: iterate,
|
|
306
|
-
getItem: getItem,
|
|
307
|
-
setItem: setItem,
|
|
308
|
-
removeItem: removeItem,
|
|
309
|
-
clear: clear,
|
|
310
|
-
length: length,
|
|
311
|
-
key: key,
|
|
312
|
-
keys: keys,
|
|
313
|
-
dropInstance: dropInstance
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
export default sessionStorageWrapper;
|
package/src/element-overview.js~
DELETED
package/src/element.js~
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import extend from "lodash-es/extend.js";
|
|
2
|
-
import isElement from "lodash-es/isElement.js";
|
|
3
|
-
import isFunction from "lodash-es/isFunction.js";
|
|
4
|
-
import pick from "lodash-es/pick.js";
|
|
5
|
-
import result from "lodash-es/result.js";
|
|
6
|
-
import uniqueId from "lodash-es/uniqueId.js";
|
|
7
|
-
import { Events } from './events.js';
|
|
8
|
-
import { inherits, NotImplementedError } from './helpers.js';
|
|
9
|
-
import { render } from 'lit-html';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const paddedLt = /^\s*</;
|
|
13
|
-
|
|
14
|
-
// Caches a local reference to `Element.prototype` for faster access.
|
|
15
|
-
const ElementProto = (typeof Element !== 'undefined' && Element.prototype) || {};
|
|
16
|
-
|
|
17
|
-
// Cached regex to split keys for `delegate`.
|
|
18
|
-
const delegateEventSplitter = /^(\S+)\s*(.*)$/;
|
|
19
|
-
|
|
20
|
-
// List of view options to be set as properties.
|
|
21
|
-
const viewOptions = ['model', 'collection', 'events'];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export class ElementView extends HTMLElement {
|
|
25
|
-
|
|
26
|
-
constructor(options) {
|
|
27
|
-
super();
|
|
28
|
-
// Creating a View creates its initial element outside of the DOM,
|
|
29
|
-
// if an existing element is not provided...
|
|
30
|
-
this.cid = uniqueId('view');
|
|
31
|
-
this._domEvents = [];
|
|
32
|
-
extend(this, pick(options, viewOptions));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
createRenderRoot () {
|
|
36
|
-
// Render without the shadow DOM
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
connectedCallback () {
|
|
41
|
-
if (!this._initialized) {
|
|
42
|
-
this.preinitialize.apply(this, arguments);
|
|
43
|
-
this.initialize.apply(this, arguments);
|
|
44
|
-
this._initialized = true;
|
|
45
|
-
}
|
|
46
|
-
this.delegateEvents();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
disconnectedCallback () {
|
|
50
|
-
this.undelegateEvents();
|
|
51
|
-
this.stopListening();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get events () { // eslint-disable-line class-methods-use-this
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// preinitialize is an empty function by default. You can override it with a function
|
|
59
|
-
// or object. preinitialize will run before any instantiation logic is run in the View
|
|
60
|
-
preinitialize () { // eslint-disable-line class-methods-use-this
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Initialize is an empty function by default. Override it with your own
|
|
64
|
-
// initialization logic.
|
|
65
|
-
initialize() {} // eslint-disable-line class-methods-use-this
|
|
66
|
-
|
|
67
|
-
// **render** is the core function that your view should override, in order
|
|
68
|
-
// to populate its element (`this.el`), with the appropriate HTML. The
|
|
69
|
-
// convention is for **render** to always return `this`.
|
|
70
|
-
render() {
|
|
71
|
-
isFunction(this.beforeRender) && this.beforeRender();
|
|
72
|
-
isFunction(this.toHTML) && render(this.toHTML(), this);
|
|
73
|
-
isFunction(this.afterRender) && this.afterRender();
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Set callbacks, where `this.events` is a hash of
|
|
78
|
-
//
|
|
79
|
-
// *{"event selector": "callback"}*
|
|
80
|
-
//
|
|
81
|
-
// {
|
|
82
|
-
// 'mousedown .title': 'edit',
|
|
83
|
-
// 'click .button': 'save',
|
|
84
|
-
// 'click .open': function(e) { ... }
|
|
85
|
-
// }
|
|
86
|
-
//
|
|
87
|
-
// pairs. Callbacks will be bound to the view, with `this` set properly.
|
|
88
|
-
// Uses event delegation for efficiency.
|
|
89
|
-
// Omitting the selector binds the event to `this.el`.
|
|
90
|
-
delegateEvents() {
|
|
91
|
-
if (!this.events) {
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
this.undelegateEvents();
|
|
95
|
-
for (const key in this.events) {
|
|
96
|
-
let method = this.events[key];
|
|
97
|
-
if (!isFunction(method)) method = this[method];
|
|
98
|
-
if (!method) continue;
|
|
99
|
-
const match = key.match(delegateEventSplitter);
|
|
100
|
-
this.delegate(match[1], match[2], method.bind(this));
|
|
101
|
-
}
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Make a event delegation handler for the given `eventName` and `selector`
|
|
106
|
-
// and attach it to `this.el`.
|
|
107
|
-
// If selector is empty, the listener will be bound to `this.el`. If not, a
|
|
108
|
-
// new handler that will recursively traverse up the event target's DOM
|
|
109
|
-
// hierarchy looking for a node that matches the selector. If one is found,
|
|
110
|
-
// the event's `delegateTarget` property is set to it and the return the
|
|
111
|
-
// result of calling bound `listener` with the parameters given to the
|
|
112
|
-
// handler.
|
|
113
|
-
delegate(eventName, selector, listener) {
|
|
114
|
-
const root = this;
|
|
115
|
-
if (!root) {
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
if (typeof selector === 'function') {
|
|
119
|
-
listener = selector;
|
|
120
|
-
selector = null;
|
|
121
|
-
}
|
|
122
|
-
// Given that `focus` and `blur` events do not bubble, do not delegate these events
|
|
123
|
-
if (['focus', 'blur'].indexOf(eventName) !== -1) {
|
|
124
|
-
const els = this.querySelectorAll(selector);
|
|
125
|
-
for (let i = 0, len = els.length; i < len; i++) {
|
|
126
|
-
const item = els[i];
|
|
127
|
-
item.addEventListener(eventName, listener, false);
|
|
128
|
-
this._domEvents.push({el: item, eventName: eventName, handler: listener});
|
|
129
|
-
}
|
|
130
|
-
return listener;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const handler = selector ? function (e) {
|
|
134
|
-
let node = e.target || e.srcElement;
|
|
135
|
-
for (; node && node != root; node = node.parentNode) {
|
|
136
|
-
if (node.matches(selector)) {
|
|
137
|
-
e.delegateTarget = node;
|
|
138
|
-
listener(e);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} : listener;
|
|
142
|
-
|
|
143
|
-
this.addEventListener(eventName, handler, false);
|
|
144
|
-
this._domEvents.push({el: this, eventName: eventName, handler: handler, listener: listener, selector: selector});
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Clears all callbacks previously bound to the view by `delegateEvents`.
|
|
149
|
-
// You usually don't need to use this, but may wish to if you have multiple
|
|
150
|
-
// Backbone views attached to the same DOM element.
|
|
151
|
-
undelegateEvents() {
|
|
152
|
-
if (this) {
|
|
153
|
-
for (let i = 0, len = this._domEvents.length; i < len; i++) {
|
|
154
|
-
const item = this._domEvents[i];
|
|
155
|
-
item.el.removeEventListener(item.eventName, item.handler, false);
|
|
156
|
-
}
|
|
157
|
-
this._domEvents.length = 0;
|
|
158
|
-
}
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// A finer-grained `undelegateEvents` for removing a single delegated event.
|
|
163
|
-
// `selector` and `listener` are both optional.
|
|
164
|
-
undelegate(eventName, selector, listener) {
|
|
165
|
-
if (typeof selector === 'function') {
|
|
166
|
-
listener = selector;
|
|
167
|
-
selector = null;
|
|
168
|
-
}
|
|
169
|
-
if (this) {
|
|
170
|
-
const handlers = this._domEvents.slice();
|
|
171
|
-
let i = handlers.length;
|
|
172
|
-
while (i--) {
|
|
173
|
-
const item = handlers[i];
|
|
174
|
-
const match = item.eventName === eventName &&
|
|
175
|
-
(listener ? item.listener === listener : true) &&
|
|
176
|
-
(selector ? item.selector === selector : true);
|
|
177
|
-
|
|
178
|
-
if (!match) {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
item.el.removeEventListener(item.eventName, item.handler, false);
|
|
182
|
-
this._domEvents.splice(i, 1);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return this;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Set up all inheritable **View** properties and methods.
|
|
190
|
-
Object.assign(ElementView.prototype, Events);
|