romo 0.19.7 → 0.19.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 97d1c8900aee3e16f65d499f0837bb74f6225033
4
- data.tar.gz: 17737178b8474f79671d577bd173db8fffdfb817
5
2
  SHA512:
6
- metadata.gz: dc935bbf15d8cc944fff91f2e7c2687ec8b8d033839b881cd66d30a549d1eac82e258aa85d8517f91797fb4239317f496702467a58103545058c0f7b12b51dbd
7
- data.tar.gz: 01dbeac8de96746f831ed7993efb7c65ef34f4c2aac876528ccf784c668f361c3c95c2b0a9fab537fc2a85a3ef9fc0b03a2f671a62b385ff8e49984a17573b04
3
+ data.tar.gz: 5eea8c90486df3910adfb7ec8c509ad7b905b00b75cd254dbe0b2ef5717e9af0f4d75274cd674af2c4788c335eec7c1bda863e62ec9f5fb07bd2c79ed98613b7
4
+ metadata.gz: 7677d14e707541385b4bae0f61963fafd0d05ac14ac49cdcf3b0796cac5d473e68a7ea1e71a62238399587d6b43bc1a3676aa3d2babf3fbdbcd5f5ef4506b8d4
5
+ SHA1:
6
+ data.tar.gz: 796333f88f138aaba75067ce59915e6aa5f5bf4c
7
+ metadata.gz: 9a0f573b36b64a154382beb9a02ee6d51351a0db
@@ -1,274 +1,612 @@
1
- (function() {
2
- var Romo = function() {
3
- this._eventCallbacks = [];
4
- }
1
+ var Romo = function() {
2
+ this._eventCallbacks = [];
3
+ }
5
4
 
6
- Romo.prototype.doInit = function() {
7
- this.parentChildElems = new RomoParentChildElems();
5
+ // TODO: rework w/o jQuery
6
+ Romo.prototype.doInit = function() {
7
+ this.parentChildElems = new RomoParentChildElems();
8
8
 
9
- $.each(this._eventCallbacks, function(idx, eventCallback) {
10
- $('body').on(eventCallback.eventName, eventCallback.callback);
11
- });
9
+ $.each(this._eventCallbacks, function(idx, eventCallback) {
10
+ $('body').on(eventCallback.eventName, eventCallback.callback);
11
+ });
12
12
 
13
- this.triggerInitUI($('body'));
14
- }
13
+ this.triggerInitUI($('body'));
14
+ }
15
15
 
16
- // init UI
16
+ // element finders
17
17
 
18
- Romo.prototype.onInitUI = function(callback) {
19
- this._addEventCallback('romo:initUI', callback);
20
- }
18
+ Romo.prototype.f = function(selector) {
19
+ return this.array(document.querySelectorAll(selector));
20
+ }
21
21
 
22
- Romo.prototype.triggerInitUI = function(elems) {
23
- elems.trigger('romo:initUI');
24
- }
22
+ Romo.prototype.find = function(parentElem, selector) {
23
+ return this.array(parentElem.querySelectorAll(selector));
24
+ }
25
+
26
+ Romo.prototype.children = function(parentElem) {
27
+ return this.array(parentElem.children);
28
+ }
25
29
 
26
- Romo.prototype.initUIElems = function(e, selector) {
27
- var elems = $(e.target).find(selector).get();
28
- if ($(e.target).is(selector)) {
29
- elems.push(e.target)
30
+ Romo.prototype.parent = function(childElem) {
31
+ return childElem.parentNode;
32
+ }
33
+
34
+ Romo.prototype.siblings = function(elem) {
35
+ return Array.prototype.filter.call(elem.parentNode.children, function(childElem) {
36
+ return childElem !== elem;
37
+ });
38
+ }
39
+
40
+ Romo.prototype.prev = function(fromElem) {
41
+ return fromElem.previousElementSibling;
42
+ }
43
+
44
+ Romo.prototype.next = function(fromElem) {
45
+ return fromElem.nextElementSibling;
46
+ }
47
+
48
+ Romo.prototype.closest = function(fromElem, selector) {
49
+ if (fromElem.closest) {
50
+ return fromElem.closest(selector);
51
+ } else {
52
+ var matchesSelector = fromElem.matches ||
53
+ fromElem.webkitMatchesSelector ||
54
+ fromElem.mozMatchesSelector ||
55
+ fromElem.msMatchesSelector;
56
+ while (fromElem) {
57
+ if (matchesSelector.call(fromElem, selector)) {
58
+ return fromElem;
59
+ } else {
60
+ fromElem = fromElem.parentElement;
61
+ }
30
62
  }
31
- return $(elems);
63
+ return undefined;
32
64
  }
65
+ }
33
66
 
34
- Romo.prototype.initHtml = function(elems, data) {
35
- elems.each($.proxy(function(index, elem) {
36
- var htmlElems = $(data)
37
- $(elem).html(htmlElems);
38
- this.triggerInitUI(htmlElems);
39
- }, this));
67
+ // TODO: rework w/o jQuery
68
+ Romo.prototype.selectNext = function(elem, selector) {
69
+ // like `$().next()`, but takes a selector; returns first next elem that
70
+ // matches the given selector or an empty collection if non matches
71
+ var el = elem.next();
72
+ while(el.length) {
73
+ if (selector === undefined || el.is(selector)) {
74
+ return el;
75
+ }
76
+ el = el.next();
40
77
  }
78
+ return el;
79
+ }
41
80
 
42
- Romo.prototype.initReplace = function(elems, data) {
43
- elems.each($.proxy(function(index, elem) {
44
- var replacementElem = $(data);
45
- $(elem).replaceWith(replacementElem);
46
- this.triggerInitUI(replacementElem);
47
- }, this));
81
+ // TODO: rework w/o jQuery
82
+ Romo.prototype.selectPrev = function(elem, selector) {
83
+ // like `$().prev()`, but takes a selector; returns first prev elem that
84
+ // matches the given selector or an empty collection if non matches
85
+ var el = elem.prev();
86
+ while(el.length) {
87
+ if (selector === undefined || el.is(selector)) {
88
+ return el;
89
+ }
90
+ el = el.prev();
48
91
  }
92
+ return el;
93
+ }
49
94
 
50
- Romo.prototype.initPrepend = function(elems, data) {
51
- elems.each($.proxy(function(index, elem) {
52
- var prependedElem = $(data);
53
- $(elem).prepend(prependedElem);
54
- this.triggerInitUI(prependedElem);
55
- }, this));
56
- }
95
+ // attributes, styles, classes
57
96
 
58
- Romo.prototype.initAppend = function(elems, data) {
59
- elems.each($.proxy(function(index, elem) {
60
- var appendedElem = $(data);
61
- $(elem).append(appendedElem);
62
- this.triggerInitUI(appendedElem);
63
- }, this));
97
+ Romo.prototype.attr = function(elem, attrName) {
98
+ return elem.getAttribute ? elem.getAttribute(attrName) : undefined;
99
+ }
100
+
101
+ Romo.prototype.setAttr = function(elem, attrName, attrValue) {
102
+ if (elem.setAttribute) {
103
+ elem.setAttribute(attrName, attrValue);
64
104
  }
105
+ return attrValue;
106
+ }
65
107
 
66
- Romo.prototype.initBefore = function(elems, data) {
67
- elems.each($.proxy(function(index, elem) {
68
- var insertedElem = $(data);
69
- $(elem).before(insertedElem);
70
- this.triggerInitUI(insertedElem);
71
- }, this));
108
+ Romo.prototype.style = function(elem, styleName) {
109
+ return elem.style[styleName];
110
+ }
111
+
112
+ Romo.prototype.setStyle = function(elem, styleName, styleValue) {
113
+ elem.style[styleName] = styleValue;
114
+ return styleValue;
115
+ }
116
+
117
+ Romo.prototype.css = function(elem, styleName) {
118
+ return window.getComputedStyle(elem, null).getPropertyValue(styleName);
119
+ }
120
+
121
+ Romo.prototype.addClass = function(elem, className) {
122
+ elem.classList.add(className);
123
+ return className;
124
+ }
125
+
126
+ Romo.prototype.removeClass = function(elem, className) {
127
+ elem.classList.remove(className);
128
+ return className;
129
+ }
130
+
131
+ Romo.prototype.toggleClass = function(elem, className) {
132
+ elem.classList.toggle(className);
133
+ return className;
134
+ }
135
+
136
+ Romo.prototype.hasClass = function(elem, className) {
137
+ return elem.classList.contains(className);
138
+ }
139
+
140
+ Romo.prototype.show = function(elem) {
141
+ elem.style.display = '';
142
+ }
143
+
144
+ Romo.prototype.hide = function(elem) {
145
+ elem.style.display = 'none';
146
+ }
147
+
148
+ Romo.prototype.offset = function(elem) {
149
+ var rect = elem.getBoundingClientRect();
150
+ return {
151
+ top: rect.top + document.body.scrollTop,
152
+ left: rect.left + document.body.scrollLeft
153
+ };
154
+ }
155
+
156
+ Romo.prototype.scrollTop = function(elem) {
157
+ return ('scrollTop' in elem) ? elem.scrollTop : elem.pageYOffset;
158
+ }
159
+
160
+ Romo.prototype.scrollLeft = function(elem) {
161
+ return ('scrollLeft' in elem) ? elem.scrollLeft : elem.pageXOffset;
162
+ }
163
+
164
+ Romo.prototype.setScrollTop = function(elem, value) {
165
+ if ('scrollTop' in elem) {
166
+ elem.scrollTop = value;
167
+ } else {
168
+ elem.scrollTo(elem.scrollX, value);
72
169
  }
170
+ }
73
171
 
74
- Romo.prototype.initAfter = function(elems, data) {
75
- elems.each($.proxy(function(index, elem) {
76
- var insertedElem = $(data);
77
- $(elem).after(insertedElem);
78
- this.triggerInitUI(insertedElem);
79
- }, this));
172
+ Romo.prototype.setScrollLeft = function(elem, value) {
173
+ if ('scrollLeft' in elem) {
174
+ elem.scrollLeft = value;
175
+ } else {
176
+ elem.scrollTo(value, elem.scrollY);
80
177
  }
178
+ }
81
179
 
82
- // page handling
180
+ // TODO: rework w/o jQuery
181
+ Romo.prototype.getComputedStyle = function(node, styleName) {
182
+ return window.getComputedStyle(node, null).getPropertyValue(styleName);
183
+ }
83
184
 
84
- Romo.prototype.reloadPage = function() {
85
- window.location = window.location;
185
+ // TODO: rework w/o jQuery
186
+ Romo.prototype.parseZIndex = function(elem) {
187
+ // for the case where z-index is set directly on the elem
188
+ var val = this.parseElemZIndex(elem);
189
+ if (val !== 0) {
190
+ return val;
86
191
  }
87
192
 
88
- Romo.prototype.redirectPage = function(redirectUrl) {
89
- window.location = redirectUrl;
193
+ // for the case where z-index is inherited from a parent elem
194
+ var parentIndexes = this.toArray(elem.parents()).reduce($.proxy(function(prev, curr) {
195
+ var pval = this.parseElemZIndex($(curr));
196
+ if (pval !== 0) {
197
+ prev.push(pval);
198
+ }
199
+ return prev;
200
+ }, this), []);
201
+ parentIndexes.push(0); // in case z-index is 'auto' all the way up
202
+ return parentIndexes[0];
203
+ }
204
+
205
+ // TODO: rework w/o jQuery
206
+ Romo.prototype.parseElemZIndex = function(elem) {
207
+ var val = parseInt(this.getComputedStyle(elem[0], "z-index"));
208
+ if (!isNaN(val)) {
209
+ return val;
90
210
  }
211
+ return 0;
212
+ }
91
213
 
92
- // param serialization
214
+ // DOM manipulation
93
215
 
94
- Romo.prototype.param = function(data, opts) {
95
- var paramData = $.extend({}, data);
216
+ Romo.prototype.elems = function(htmlString) {
217
+ var context = document.implementation.createHTMLDocument();
96
218
 
97
- if (opts && opts.removeEmpty) {
98
- $.each(paramData, function(key, value) {
99
- if (value === '') {
100
- delete paramData[key];
101
- }
102
- })
103
- }
219
+ // Set the base href for the created document so any parsed
220
+ // elements with URLs are based on the document's URL
221
+ var base = context.createElement('base');
222
+ base.href = document.location.href;
223
+ context.head.appendChild(base);
104
224
 
105
- var paramString = $.param(paramData);
225
+ context.body.innerHTML = htmlString;
226
+ return this.array(context.body.children);
227
+ }
106
228
 
107
- if (opts && opts.decodeValues) {
108
- paramString = this.decodeParam(paramString);
109
- }
229
+ Romo.prototype.remove = function(elem) {
230
+ return elem.parentNode.removeChild(elem);
231
+ }
110
232
 
111
- return paramString;
112
- }
233
+ Romo.prototype.replace = function(elem, replacementElem) {
234
+ elem.parentNode.replaceChild(replacementElem, elem);
235
+ return replacementElem;
236
+ }
113
237
 
114
- Romo.prototype.decodeParam = function(string) {
115
- return this.decodeParamMap.reduce(function(prev, curr) {
116
- return prev.replace(curr[0], curr[1]);
117
- }, string);
118
- }
238
+ Romo.prototype.replaceHtml = function(elem, htmlString) {
239
+ return this.replace(elem, this.elems(htmlString)[0]);
240
+ }
119
241
 
120
- Romo.prototype.decodeParamMap = [
121
- [/%20/g, '+'],
122
- [/%21/g, '!'],
123
- [/%24/g, '$'],
124
- [/%28/g, '('],
125
- [/%29/g, ')'],
126
- [/%2A/g, '*'],
127
- [/%2B/g, '+'],
128
- [/%2C/g, ','],
129
- [/%2D/g, '-'],
130
- [/%2E/g, '.'],
131
- [/%2F/g, '/'],
132
- [/%5B/g, '['],
133
- [/%5C/g, '\\'],
134
- [/%5D/g, ']'],
135
- [/%3A/g, ':'],
136
- [/%3C/g, '<'],
137
- [/%3E/g, '>'],
138
- [/%3F/g, '?'],
139
- [/%40/g, '@'],
140
- [/%5E/g, '^'],
141
- [/%5F/g, '_'],
142
- [/%60/g, '`'],
143
- [/%7B/g, '{'],
144
- [/%7C/g, '|'],
145
- [/%7D/g, '}'],
146
- [/%7E/g, '~']
147
- ];
242
+ Romo.prototype.update = function(elem, childElems) {
243
+ elem.innerHTML = '';
244
+ return childElems.map(function(childElem) {
245
+ return elem.appendChild(childElem);
246
+ });
247
+ }
248
+
249
+ Romo.prototype.updateHtml = function(elem, htmlString) {
250
+ return this.update(elem, this.elems(htmlString));
251
+ }
252
+
253
+ Romo.prototype.prepend = function(elem, childElems) {
254
+ var refElem = elem.firstChild;
255
+ return childElems.reverse().map(function(childElem) {
256
+ refElem = elem.insertBefore(childElem, refElem);
257
+ return refElem;
258
+ }).reverse();
259
+ }
260
+
261
+ Romo.prototype.prependHtml = function(elem, htmlString) {
262
+ return this.prepend(elem, this.elems(htmlString));
263
+ }
264
+
265
+ Romo.prototype.append = function(elem, childElems) {
266
+ return childElems.map(function(childElem) {
267
+ return elem.appendChild(childElem);
268
+ });
269
+ }
270
+
271
+ Romo.prototype.appendHtml = function(elem, htmlString) {
272
+ return this.append(elem, this.elems(htmlString));
273
+ }
274
+
275
+ Romo.prototype.before = function(elem, siblingElems) {
276
+ var refElem = elem;
277
+ var parentElem = elem.parentNode;
278
+ return siblingElems.reverse().map(function(siblingElem) {
279
+ refElem = parentElem.insertBefore(siblingElem, refElem);
280
+ return refElem;
281
+ }).reverse();
282
+ }
283
+
284
+ Romo.prototype.beforeHtml = function(elem, htmlString) {
285
+ return this.before(elem, this.elems(htmlString));
286
+ }
287
+
288
+ Romo.prototype.after = function(elem, siblingElems) {
289
+ var refElem = this.next(elem);
290
+ var parentElem = elem.parentNode;
291
+ return siblingElems.map(function(siblingElem) {
292
+ return parentElem.insertBefore(siblingElem, refElem);
293
+ });
294
+ }
295
+
296
+ Romo.prototype.afterHtml = function(elem, htmlString) {
297
+ return this.after(elem, this.elems(htmlString));
298
+ }
299
+
300
+ // init UI (TODO: rework w/o jQuery)
301
+
302
+ Romo.prototype.onInitUI = function(callback) {
303
+ this._addEventCallback('romo:initUI', callback);
304
+ }
148
305
 
149
- // style handling
306
+ Romo.prototype.triggerInitUI = function(elems) {
307
+ elems.trigger('romo:initUI');
308
+ }
150
309
 
151
- Romo.prototype.getComputedStyle = function(node, styleName) {
152
- return window.getComputedStyle(node, null).getPropertyValue(styleName);
310
+ Romo.prototype.initUIElems = function(e, selector) {
311
+ var elems = $(e.target).find(selector).get();
312
+ if ($(e.target).is(selector)) {
313
+ elems.push(e.target)
153
314
  }
315
+ return $(elems);
316
+ }
154
317
 
155
- Romo.prototype.parseZIndex = function(elem) {
156
- // for the case where z-index is set directly on the elem
157
- var val = this.parseElemZIndex(elem);
158
- if (val !== 0) {
159
- return val;
160
- }
318
+ Romo.prototype.initHtml = function(elems, data) {
319
+ elems.each($.proxy(function(index, elem) {
320
+ var htmlElems = $(data)
321
+ $(elem).html(htmlElems);
322
+ this.triggerInitUI(htmlElems);
323
+ }, this));
324
+ }
325
+
326
+ Romo.prototype.initReplace = function(elems, data) {
327
+ elems.each($.proxy(function(index, elem) {
328
+ var replacementElem = $(data);
329
+ $(elem).replaceWith(replacementElem);
330
+ this.triggerInitUI(replacementElem);
331
+ }, this));
332
+ }
333
+
334
+ Romo.prototype.initPrepend = function(elems, data) {
335
+ elems.each($.proxy(function(index, elem) {
336
+ var prependedElem = $(data);
337
+ $(elem).prepend(prependedElem);
338
+ this.triggerInitUI(prependedElem);
339
+ }, this));
340
+ }
341
+
342
+ Romo.prototype.initAppend = function(elems, data) {
343
+ elems.each($.proxy(function(index, elem) {
344
+ var appendedElem = $(data);
345
+ $(elem).append(appendedElem);
346
+ this.triggerInitUI(appendedElem);
347
+ }, this));
348
+ }
349
+
350
+ Romo.prototype.initBefore = function(elems, data) {
351
+ elems.each($.proxy(function(index, elem) {
352
+ var insertedElem = $(data);
353
+ $(elem).before(insertedElem);
354
+ this.triggerInitUI(insertedElem);
355
+ }, this));
356
+ }
357
+
358
+ Romo.prototype.initAfter = function(elems, data) {
359
+ elems.each($.proxy(function(index, elem) {
360
+ var insertedElem = $(data);
361
+ $(elem).after(insertedElem);
362
+ this.triggerInitUI(insertedElem);
363
+ }, this));
364
+ }
365
+
366
+ // page handling
161
367
 
162
- // for the case where z-index is inherited from a parent elem
163
- var parentIndexes = this.toArray(elem.parents()).reduce($.proxy(function(prev, curr) {
164
- var pval = this.parseElemZIndex($(curr));
165
- if (pval !== 0) {
166
- prev.push(pval);
368
+ Romo.prototype.reloadPage = function() {
369
+ window.location = window.location;
370
+ }
371
+
372
+ Romo.prototype.redirectPage = function(redirectUrl) {
373
+ window.location = redirectUrl;
374
+ }
375
+
376
+ // param serialization (TODO: rework w/o jQuery)
377
+
378
+ Romo.prototype.param = function(data, opts) {
379
+ var paramData = $.extend({}, data);
380
+
381
+ if (opts && opts.removeEmpty) {
382
+ $.each(paramData, function(key, value) {
383
+ if (value === '') {
384
+ delete paramData[key];
167
385
  }
168
- return prev;
169
- }, this), []);
170
- parentIndexes.push(0); // in case z-index is 'auto' all the way up
171
- return parentIndexes[0];
386
+ })
172
387
  }
173
388
 
174
- Romo.prototype.parseElemZIndex = function(elem) {
175
- var val = parseInt(this.getComputedStyle(elem[0], "z-index"));
176
- if (!isNaN(val)) {
177
- return val;
178
- }
179
- return 0;
389
+ var paramString = $.param(paramData);
390
+
391
+ if (opts && opts.decodeValues) {
392
+ paramString = this.decodeParam(paramString);
180
393
  }
181
394
 
182
- // elem handling
395
+ return paramString;
396
+ }
183
397
 
184
- Romo.prototype.toArray = function(elems) {
185
- // converts a collection of elements `$()` to an array of nodes
186
- return $.map(elems, function(node){ return node; })
187
- }
398
+ Romo.prototype.decodeParam = function(string) {
399
+ return this.decodeParamMap.reduce(function(prev, curr) {
400
+ return prev.replace(curr[0], curr[1]);
401
+ }, string);
402
+ }
188
403
 
189
- Romo.prototype.selectNext = function(elem, selector) {
190
- // like `$().next()`, but takes a selector; returns first next elem that
191
- // matches the given selector or an empty collection if non matches
192
- var el = elem.next();
193
- while(el.length) {
194
- if (selector === undefined || el.is(selector)) {
195
- return el;
196
- }
197
- el = el.next();
198
- }
199
- return el;
404
+ Romo.prototype.decodeParamMap = [
405
+ [/%20/g, '+'],
406
+ [/%21/g, '!'],
407
+ [/%24/g, '$'],
408
+ [/%28/g, '('],
409
+ [/%29/g, ')'],
410
+ [/%2A/g, '*'],
411
+ [/%2B/g, '+'],
412
+ [/%2C/g, ','],
413
+ [/%2D/g, '-'],
414
+ [/%2E/g, '.'],
415
+ [/%2F/g, '/'],
416
+ [/%5B/g, '['],
417
+ [/%5C/g, '\\'],
418
+ [/%5D/g, ']'],
419
+ [/%3A/g, ':'],
420
+ [/%3C/g, '<'],
421
+ [/%3E/g, '>'],
422
+ [/%3F/g, '?'],
423
+ [/%40/g, '@'],
424
+ [/%5E/g, '^'],
425
+ [/%5F/g, '_'],
426
+ [/%60/g, '`'],
427
+ [/%7B/g, '{'],
428
+ [/%7C/g, '|'],
429
+ [/%7D/g, '}'],
430
+ [/%7E/g, '~']
431
+ ];
432
+
433
+ // AJAX
434
+
435
+ Romo.prototype.ajax = function(settings) {
436
+ var xhr = new XMLHttpRequest();
437
+ xhr.open(settings.type || 'GET', settings.url, true, settings.username, settings.password);
438
+ if (settings.responseType === 'arraybuffer' || settings.responseType === 'blob') {
439
+ xhr.responseType = settings.responseType;
200
440
  }
201
-
202
- Romo.prototype.selectPrev = function(elem, selector) {
203
- // like `$().prev()`, but takes a selector; returns first prev elem that
204
- // matches the given selector or an empty collection if non matches
205
- var el = elem.prev();
206
- while(el.length) {
207
- if (selector === undefined || el.is(selector)) {
208
- return el;
441
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
442
+ for (name in settings.headers) {
443
+ xhr.setRequestHeader(name, settings.headers[name]);
444
+ }
445
+ if (settings.contentType) {
446
+ xhr.setRequestHeader('Content-Type', settings.contentType);
447
+ }
448
+ xhr.onreadystatechange = function() {
449
+ if (xhr.readyState === 4) {
450
+ if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
451
+ if (xhr.responseType === 'arraybuffer' || xhr.responseType === 'blob') {
452
+ settings.success.call(window, xhr.response, xhr.status, xhr, settings);
453
+ } else {
454
+ settings.success.call(window, xhr.responseText, xhr.status, xhr, settings);
455
+ }
456
+ } else {
457
+ settings.error.call(window, xhr.statusText || null, xhr.status, xhr, settings);
209
458
  }
210
- el = el.prev();
211
459
  }
212
- return el;
213
- }
460
+ };
461
+ xhr.send(settings.data ? settings.data : null);
462
+ },
463
+
464
+ // events
465
+
466
+ Romo.prototype.on = function(elem, eventName, fn) {
467
+ // var proxyFn = function(e) {
468
+ // var result = fn.apply(elem, e.detail === undefined ? [e] : [e].concat(e.detail));
469
+ // if (result === false) {
470
+ // e.preventDefault();
471
+ // e.stopPropagation();
472
+ // }
473
+ // return result;
474
+ // }
475
+ // proxyFn._romofid = this._fn(fn)._romofid;
476
+
477
+ // var key = this._handlerKey(elem, eventName, proxyFn);
478
+ // if (!this._handlers[key]) {
479
+ // elem.addEventListener(eventName, proxyFn);
480
+ // this._handlers[key] = proxyFn;
481
+ // }
482
+
483
+ // Giant Hack to temporarily support jQuery and non-jQuery triggers
484
+ // see: https://bugs.jquery.com/ticket/11047
485
+ $(elem).on(eventName, fn);
486
+ }
214
487
 
215
- // input handling
216
-
217
- Romo.prototype.nonInputTextKeyCodes = function() {
218
- // https://css-tricks.com/snippets/javascript/javascript-keycodes/
219
- return [
220
- 9, /* tab */
221
- 13, /* enter */
222
- 16, /* shift */
223
- 17, /* ctrl */
224
- 18, /* alt */
225
- 19, /* pausebreak */
226
- 20, /* capslock */
227
- 27, /* escape */
228
- 33, /* pageup */
229
- 34, /* pagedown */
230
- 35, /* end */
231
- 36, /* home */
232
- 37, /* leftarrow */
233
- 38, /* uparrow */
234
- 39, /* rightarrow */
235
- 40, /* downarrow */
236
- 45, /* insert */
237
- 46, /* delete */
238
- 91, /* leftwindowkey */
239
- 92, /* rightwindowkey */
240
- 93, /* selectkey */
241
- 112, /* f1 */
242
- 113, /* f2 */
243
- 114, /* f3 */
244
- 115, /* f4 */
245
- 116, /* f5 */
246
- 117, /* f6 */
247
- 118, /* f7 */
248
- 119, /* f8 */
249
- 120, /* f9 */
250
- 121, /* f10 */
251
- 122, /* f11 */
252
- 123, /* f12 */
253
- 144, /* numlock */
254
- 145, /* scrolllock */
255
- ];
256
- }
488
+ Romo.prototype.off = function(elem, eventName, fn) {
489
+ // var key = this._handlerKey(elem, eventName, fn);
490
+ // var proxyFn = this._handlers[key];
491
+ // if (proxyFn) {
492
+ // elem.removeEventListener(eventName, proxyFn);
493
+ // this._handlers[key] = undefined;
494
+ // }
495
+
496
+ // Giant Hack to temporarily support jQuery and non-jQuery triggers
497
+ // see: https://bugs.jquery.com/ticket/11047
498
+ $(elem).off(eventName, fn);
499
+ }
257
500
 
258
- // private
501
+ Romo.prototype.trigger = function(elem, customEventName, args) {
502
+ // var event = undefined;
503
+ // if (typeof window.CustomEvent === "function") {
504
+ // event = new CustomEvent(customEventName, { detail: args });
505
+ // } else {
506
+ // event = document.createEvent('CustomEvent');
507
+ // event.initCustomEvent(customEventName, false, false, args);
508
+ // }
509
+ // elem.dispatchEvent(event);
510
+ $(elem).trigger(customEventName, args);
511
+ }
259
512
 
260
- Romo.prototype._addEventCallback = function(name, callback) {
261
- this._eventCallbacks.push({ eventName: name, callback: callback });
513
+ Romo.prototype.ready = function(eventHandlerFn) {
514
+ if (document.readyState === 'complete' || document.readyState !== 'loading') {
515
+ eventHandlerFn();
516
+ } else {
517
+ this.on(document, 'DOMContentLoaded', eventHandlerFn);
262
518
  }
519
+ }
263
520
 
264
- window.Romo = new Romo();
265
- })();
521
+ // utils
266
522
 
267
- $(function() {
523
+ Romo.prototype.array = function(collection) {
524
+ return Array.prototype.slice.call(collection);
525
+ }
268
526
 
269
- Romo.doInit();
527
+ Romo.prototype.proxy = function(fn, context) {
528
+ var proxyFn = fn.bind(context);
529
+ proxyFn._romofid = this._fn(fn)._romofid;
270
530
 
271
- })
531
+ return proxyFn;
532
+ }
533
+
534
+ // TODO: rework w/o jQuery
535
+ Romo.prototype.toArray = function(elems) {
536
+ // converts a collection of elements `$()` to an array of nodes
537
+ return $.map(elems, function(node){ return node; })
538
+ }
539
+
540
+ Romo.prototype.nonInputTextKeyCodes = function() {
541
+ // https://css-tricks.com/snippets/javascript/javascript-keycodes/
542
+ return [
543
+ 9, /* tab */
544
+ 13, /* enter */
545
+ 16, /* shift */
546
+ 17, /* ctrl */
547
+ 18, /* alt */
548
+ 19, /* pausebreak */
549
+ 20, /* capslock */
550
+ 27, /* escape */
551
+ 33, /* pageup */
552
+ 34, /* pagedown */
553
+ 35, /* end */
554
+ 36, /* home */
555
+ 37, /* leftarrow */
556
+ 38, /* uparrow */
557
+ 39, /* rightarrow */
558
+ 40, /* downarrow */
559
+ 45, /* insert */
560
+ 46, /* delete */
561
+ 91, /* leftwindowkey */
562
+ 92, /* rightwindowkey */
563
+ 93, /* selectkey */
564
+ 112, /* f1 */
565
+ 113, /* f2 */
566
+ 114, /* f3 */
567
+ 115, /* f4 */
568
+ 116, /* f5 */
569
+ 117, /* f6 */
570
+ 118, /* f7 */
571
+ 119, /* f8 */
572
+ 120, /* f9 */
573
+ 121, /* f10 */
574
+ 122, /* f11 */
575
+ 123, /* f12 */
576
+ 144, /* numlock */
577
+ 145, /* scrolllock */
578
+ ];
579
+ }
580
+
581
+ // private helpers
582
+
583
+ Romo.prototype._eid = 1;
584
+ Romo.prototype._fid = 1;
585
+
586
+ Romo.prototype._el = function(elem) {
587
+ elem._romoeid || (
588
+ elem._romoeid = (this.attr(elem, 'data-romo-eid') || this.setAttr(elem, 'data-romo-eid', this._eid++))
589
+ );
590
+ return elem;
591
+ }
592
+
593
+ Romo.prototype._fn = function(fn) {
594
+ fn._romofid || (fn._romofid = this._fid++);
595
+ return fn;
596
+ }
597
+
598
+ Romo.prototype._handlers = {};
599
+
600
+ Romo.prototype._handlerKey = function(elem, eventName, fn) {
601
+ return 'eid--'+this._el(elem)._romoeid+'--'+eventName+'--fid--'+this._fn(fn)._romofid;
602
+ }
603
+
604
+ // TODO: rework w/o jQuery
605
+ Romo.prototype._addEventCallback = function(name, callback) {
606
+ this._eventCallbacks.push({ eventName: name, callback: callback });
607
+ }
608
+
609
+ // RomoParentChildElems (TODO: rework w/o jQuery)
272
610
 
273
611
  var RomoParentChildElems = function() {
274
612
  this.attrName = 'romo-parent-elem-id';
@@ -306,7 +644,7 @@ RomoParentChildElems.prototype.remove = function(nodeElem) {
306
644
  }
307
645
  }
308
646
 
309
- // private
647
+ // private RomoParentChildElems
310
648
 
311
649
  RomoParentChildElems.prototype._removeChildElems = function(parentElem) {
312
650
  $.each(this._pop(parentElem.data(this.attrName)), function(idx, elem) {
@@ -330,3 +668,12 @@ RomoParentChildElems.prototype._pop = function(id) {
330
668
  delete this.elems[id];
331
669
  return items || [];
332
670
  }
671
+
672
+ // Init
673
+
674
+ window.Romo = new Romo();
675
+
676
+ // TODO: rework w/o jQuery
677
+ $(function() {
678
+ Romo.doInit();
679
+ })
@@ -481,10 +481,12 @@ RomoOptionListDropdown.prototype._onElemKeyDown = function(e) {
481
481
  return false;
482
482
  } else if (this.optionFilterElem !== undefined &&
483
483
  Romo.nonInputTextKeyCodes().indexOf(e.keyCode) === -1 /* Input Text */) {
484
+ // don't prevent default on Cmd-* keys (preserve Cmd-R refresh, etc)
484
485
  if (e.metaKey === false) {
485
- // don't prevent default on Cmd-* keys (preserve Cmd-R refresh, etc)
486
486
  e.preventDefault();
487
- this.optionFilterElem.val(e.key);
487
+ if (e.keyCode !== 8) { /* Backspace */
488
+ this.optionFilterElem.val(e.key);
489
+ }
488
490
  this.romoDropdown.doPopupOpen();
489
491
  }
490
492
  e.stopPropagation();
@@ -70,11 +70,14 @@ RomoPicker.prototype.doSetValueDatas = function(valueDatas) {
70
70
  this._setValuesAndDisplayText(values, '');
71
71
  this.romoSelectedOptionsList.doSetItems(datas);
72
72
  } else {
73
- this._setValuesAndDisplayText(
74
- values,
75
- (displayTexts[0] || this.elem.data('romo-picker-empty-option-display-text') || '')
73
+ var displayText = displayTexts[0] ||
74
+ this.elem.data('romo-picker-empty-option-display-text') ||
75
+ '';
76
+ this._setValuesAndDisplayText(values, displayText);
77
+ this.romoOptionListDropdown.doSetSelectedValueAndText(
78
+ values[0],
79
+ displayText
76
80
  );
77
- this.romoOptionListDropdown.doSetSelectedItem(values[0]);
78
81
  }
79
82
  this._refreshUI();
80
83
  }
data/lib/romo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Romo
2
- VERSION = "0.19.7"
2
+ VERSION = "0.19.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.7
4
+ version: 0.19.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2017-09-06 00:00:00 Z
13
+ date: 2017-09-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert