romo 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,8 @@
4
4
  }
5
5
 
6
6
  Romo.prototype.doInit = function() {
7
+ this.parentChildElems = new RomoParentChildElems();
8
+
7
9
  $.each(this._eventCallbacks, function(idx, eventCallback) {
8
10
  $('body').on(eventCallback.eventName, eventCallback.callback);
9
11
  });
@@ -181,3 +183,62 @@ $(function() {
181
183
  Romo.doInit();
182
184
 
183
185
  })
186
+
187
+ var RomoParentChildElems = function() {
188
+ this.attrName = 'romo-parent-elem-id';
189
+ this.elemId = 0;
190
+ this.elems = {};
191
+
192
+ var childRemovedObserver = new MutationObserver($.proxy(function(mutationRecords) {
193
+ mutationRecords.forEach($.proxy(function(mutationRecord) {
194
+ if (mutationRecord.type === 'childList' && mutationRecord.removedNodes.length > 0) {
195
+ $.each($(mutationRecord.removedNodes), $.proxy(function(idx, node) {
196
+ this.remove($(node));
197
+ }, this));
198
+ }
199
+ }, this));
200
+ }, this));
201
+
202
+ childRemovedObserver.observe($('body')[0], {
203
+ childList: true,
204
+ subtree: true
205
+ });
206
+ }
207
+
208
+ RomoParentChildElems.prototype.add = function(parentElem, childElems) {
209
+ parentElem.attr('data-'+this.attrName, this._push(childElems, parentElem.data(this.attrName)));
210
+ }
211
+
212
+ RomoParentChildElems.prototype.remove = function(nodeElem) {
213
+ if(nodeElem.data(this.attrName) !== undefined) {
214
+ this._removeChildElems(nodeElem); // node is a parent elem itself
215
+ }
216
+ $.each(nodeElem.find('[data-'+this.attrName+']'), $.proxy(function(idx, parent) {
217
+ this._removeChildElems($(parent));
218
+ }, this));
219
+ }
220
+
221
+ // private
222
+
223
+ RomoParentChildElems.prototype._removeChildElems = function(parentElem) {
224
+ $.each(this._pop(parentElem.data(this.attrName)), function(idx, elem) {
225
+ $(elem).remove();
226
+ });
227
+ };
228
+
229
+ RomoParentChildElems.prototype._push = function(items, id) {
230
+ if (id === undefined) {
231
+ id = String(this.elemId++);
232
+ }
233
+ if (this.elems[id] === undefined) {
234
+ this.elems[id] = []
235
+ }
236
+ items.forEach($.proxy(function(item){ this.elems[id].push(item) }, this));
237
+ return id;
238
+ };
239
+
240
+ RomoParentChildElems.prototype._pop = function(id) {
241
+ var items = this.elems[id];
242
+ delete this.elems[id];
243
+ return items || [];
244
+ }
@@ -43,6 +43,15 @@ RomoDatepicker.prototype.doBindElem = function() {
43
43
  this.elem.before(elemWrapper);
44
44
  elemWrapper.append(this.elem);
45
45
 
46
+ // the elem wrapper should be treated like a child elem. add it to Romo's
47
+ // parent-child elems so it will be removed when the elem (input) is removed.
48
+ // delay adding it b/c the `append` statement above is not a "move", it is
49
+ // a "remove" and "add" so if added immediately the "remove" part will
50
+ // incorrectly remove the wrapper. Any value will do - I chose 100 arbitrarily.
51
+ setTimeout($.proxy(function() {
52
+ Romo.parentChildElems.add(this.elem, [elemWrapper]);
53
+ }, this), 100);
54
+
46
55
  this.elem.attr('autocomplete', 'off');
47
56
 
48
57
  this.indicatorElem = $();
@@ -6,31 +6,9 @@ $.fn.romoDropdown = function() {
6
6
 
7
7
  var RomoDropdown = function(element) {
8
8
  this.elem = $(element);
9
- this.popupElem = $('<div class="romo-dropdown-popup"><div class="romo-dropdown-body"></div></div>');
10
- this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-dropdown-append-to-closest') || 'body'));
11
- this.doSetPopupZIndex(this.elem);
12
- this.bodyElem = this.popupElem.find('> .romo-dropdown-body');
13
- this.contentElem = $();
9
+ this.doInitPopup();
14
10
  this.romoInvoke = this.elem.romoInvoke()[0];
15
11
 
16
- var positionData = this._parsePositionData(this.elem.data('romo-dropdown-position'));
17
- this.popupPosition = positionData.position || 'bottom';
18
- this.popupAlignment = positionData.alignment || 'left';
19
- this.popupElem.attr('data-romo-dropdown-position', this.popupPosition);
20
- this.popupElem.attr('data-romo-dropdown-alignment', this.popupAlignment);
21
- this.popupElem.attr('data-romo-dropdown-fixed', this.elem.data('romo-dropdown-fixed'));
22
- // don't propagate click events on the popup elem. this prevents the popup
23
- // from closing when clicked (see body click event bind on popup open)
24
- this.popupElem.on('click', function(e) {
25
- if (e !== undefined) {
26
- e.stopPropagation();
27
- }
28
- })
29
-
30
- if (this.elem.data('romo-dropdown-style-class') !== undefined) {
31
- this.bodyElem.addClass(this.elem.data('romo-dropdown-style-class'));
32
- }
33
-
34
12
  this.elem.unbind('click');
35
13
  this.elem.on('click', $.proxy(this.onToggleClick, this));
36
14
  this.elem.on('dropdown:triggerToggle', $.proxy(this.onToggleClick, this));
@@ -58,8 +36,9 @@ RomoDropdown.prototype.doInit = function() {
58
36
  // override as needed
59
37
  }
60
38
 
61
- RomoDropdown.prototype.doInitBody = function() {
62
- this.doResetBody();
39
+ RomoDropdown.prototype.doInitPopup = function() {
40
+ this.popupElem = $('<div class="romo-dropdown-popup"><div class="romo-dropdown-body"></div></div>');
41
+ this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-dropdown-append-to-closest') || 'body'));
63
42
 
64
43
  this.popupElem.on('modal:popupOpen', $.proxy(function(e) {
65
44
  this.doUnBindWindowBodyClick();
@@ -71,11 +50,47 @@ RomoDropdown.prototype.doInitBody = function() {
71
50
  this.doBindWindowBodyKeyUp();
72
51
  this.doBindElemKeyUp();
73
52
  }, this));
53
+
54
+ this.bodyElem = this.popupElem.find('> .romo-dropdown-body');
55
+ if (this.elem.data('romo-dropdown-style-class') !== undefined) {
56
+ this.bodyElem.addClass(this.elem.data('romo-dropdown-style-class'));
57
+ }
58
+
59
+ this.contentElem = $();
60
+
61
+ var positionData = this._parsePositionData(this.elem.data('romo-dropdown-position'));
62
+ this.popupPosition = positionData.position || 'bottom';
63
+ this.popupAlignment = positionData.alignment || 'left';
64
+ this.popupElem.attr('data-romo-dropdown-position', this.popupPosition);
65
+ this.popupElem.attr('data-romo-dropdown-alignment', this.popupAlignment);
66
+ this.popupElem.attr('data-romo-dropdown-fixed', this.elem.data('romo-dropdown-fixed'));
67
+
68
+ this.doSetPopupZIndex(this.elem);
69
+
70
+ // don't propagate click events on the popup elem. this prevents the popup
71
+ // from closing when clicked (see body click event bind on popup open)
72
+ this.popupElem.on('click', function(e) {
73
+ if (e !== undefined) {
74
+ e.stopPropagation();
75
+ }
76
+ })
77
+
78
+ // the popup should be treated like a child elem. add it to Romo's
79
+ // parent-child elems so it will be removed when the elem is removed.
80
+ Romo.parentChildElems.add(this.elem, [this.popupElem]);
81
+ }
82
+
83
+ RomoDropdown.prototype.doInitBody = function() {
84
+ this.doResetBody();
85
+
74
86
  this.contentElem = this.bodyElem.find('.romo-dropdown-content').last();
75
87
  if (this.contentElem.size() === 0) {
76
88
  this.contentElem = this.bodyElem;
77
89
  }
90
+
78
91
  this.closeElem = this.popupElem.find('[data-romo-dropdown-close="true"]');
92
+ this.closeElem.unbind('click');
93
+ this.closeElem.on('click', $.proxy(this.onPopupClose, this));
79
94
 
80
95
  this.contentElem.css({
81
96
  'min-height': this.elem.data('romo-dropdown-min-height'),
@@ -104,9 +119,6 @@ RomoDropdown.prototype.doInitBody = function() {
104
119
  'width': this.elem.data('romo-dropdown-width')
105
120
  });
106
121
  }
107
-
108
- this.closeElem.unbind('click');
109
- this.closeElem.on('click', $.proxy(this.onPopupClose, this));
110
122
  }
111
123
 
112
124
  RomoDropdown.prototype.doResetBody = function() {
@@ -6,18 +6,9 @@ $.fn.romoModal = function() {
6
6
 
7
7
  var RomoModal = function(element) {
8
8
  this.elem = $(element);
9
- this.popupElem = $('<div class="romo-modal-popup"><div class="romo-modal-body"></div></div>');
10
- this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-modal-append-to-closest') || 'body'));
11
- this.bodyElem = this.popupElem.find('> .romo-modal-body');
12
- this.contentElem = $();
13
- this.closeElem = $();
14
- this.dragElem = $();
9
+ this.doInitPopup();
15
10
  this.romoInvoke = this.elem.romoInvoke()[0];
16
11
 
17
- if (this.elem.data('romo-modal-style-class') !== undefined) {
18
- this.bodyElem.addClass(this.elem.data('romo-modal-style-class'));
19
- }
20
-
21
12
  this.elem.unbind('click');
22
13
  this.elem.on('click', $.proxy(this.onToggleClick, this));
23
14
  this.elem.on('modal:triggerToggle', $.proxy(this.onToggleClick, this));
@@ -45,6 +36,24 @@ RomoModal.prototype.doInit = function() {
45
36
  // override as needed
46
37
  }
47
38
 
39
+ RomoModal.prototype.doInitPopup = function() {
40
+ this.popupElem = $('<div class="romo-modal-popup"><div class="romo-modal-body"></div></div>');
41
+ this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-modal-append-to-closest') || 'body'));
42
+
43
+ this.bodyElem = this.popupElem.find('> .romo-modal-body');
44
+ if (this.elem.data('romo-modal-style-class') !== undefined) {
45
+ this.bodyElem.addClass(this.elem.data('romo-modal-style-class'));
46
+ }
47
+
48
+ this.contentElem = $();
49
+ this.closeElem = $();
50
+ this.dragElem = $();
51
+
52
+ // the popup should be treated like a child elem. add it to Romo's
53
+ // parent-child elems so it will be removed when the elem is removed.
54
+ Romo.parentChildElems.add(this.elem, [this.popupElem]);
55
+ }
56
+
48
57
  RomoModal.prototype.doInitBody = function() {
49
58
  this.doResetBody();
50
59
 
@@ -52,8 +61,14 @@ RomoModal.prototype.doInitBody = function() {
52
61
  if (this.contentElem.size() === 0) {
53
62
  this.contentElem = this.bodyElem;
54
63
  }
64
+
55
65
  this.closeElem = this.popupElem.find('[data-romo-modal-close="true"]');
66
+ this.closeElem.unbind('click');
67
+ this.closeElem.on('click', $.proxy(this.onPopupClose, this));
68
+
56
69
  this.dragElem = this.popupElem.find('[data-romo-modal-drag="true"]');
70
+ this.dragElem.addClass('romo-modal-grab');
71
+ this.dragElem.on('mousedown', $.proxy(this.onMouseDown, this));
57
72
 
58
73
  var css = {
59
74
  'min-width': this.elem.data('romo-modal-min-width'),
@@ -73,12 +88,6 @@ RomoModal.prototype.doInitBody = function() {
73
88
  }
74
89
 
75
90
  this.contentElem.css(css);
76
-
77
- this.closeElem.unbind('click');
78
- this.closeElem.on('click', $.proxy(this.onPopupClose, this));
79
-
80
- this.dragElem.addClass('romo-modal-grab');
81
- this.dragElem.on('mousedown', $.proxy(this.onMouseDown, this));
82
91
  }
83
92
 
84
93
  RomoModal.prototype.doResetBody = function() {
@@ -130,6 +130,10 @@ RomoSelect.prototype._buildSelectDropdownElem = function() {
130
130
  romoSelectDropdownElem.before(this.elemWrapper);
131
131
  this.elemWrapper.append(romoSelectDropdownElem);
132
132
 
133
+ // the elem wrapper should be treated like a child elem. add it to Romo's
134
+ // parent-child elems so it will be removed when the elem (select) is removed.
135
+ Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
136
+
133
137
  var caretClass = this.elem.data('romo-select-caret') || this.defaultCaretClass;
134
138
  if (caretClass !== undefined && caretClass !== 'none') {
135
139
  var caret = $('<i class="romo-select-caret '+caretClass+'"></i>');
@@ -6,11 +6,7 @@ $.fn.romoTooltip = function() {
6
6
 
7
7
  var RomoTooltip = function(element) {
8
8
  this.elem = $(element);
9
- this.popupElem = $('<div class="romo-tooltip-popup"><div class="romo-tooltip-arrow"></div><div class="romo-tooltip-body"></div></div>');
10
- this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-tooltip-append-to-closest') || 'body'));
11
- this.doSetPopupZIndex(this.elem);
12
- this.arrowElem = this.popupElem.find('> .romo-tooltip-arrow');
13
- this.bodyElem = this.popupElem.find('> .romo-tooltip-body');
9
+ this.doInitPopup();
14
10
 
15
11
  this.hoverState = 'out';
16
12
  this.delayEnter = 0;
@@ -26,19 +22,6 @@ var RomoTooltip = function(element) {
26
22
  this.delayLeave = this.elem.data('romo-tooltip-delay-leave');
27
23
  }
28
24
 
29
- this.popupPosition = this.elem.data('romo-tooltip-position') || 'top';
30
- this.popupElem.attr('data-romo-tooltip-position', this.popupPosition);
31
- this.popupAlignment = this.elem.data('romo-tooltip-alignment') || 'center';
32
- this.popupElem.attr('data-romo-tooltip-alignment', this.popupAlignment);
33
-
34
- // don't propagate click events on the popup elem. this prevents the popup
35
- // from closing when clicked (see body click event bind on popup open)
36
- this.popupElem.on('click', function(e) {
37
- if (e !== undefined) {
38
- e.stopPropagation();
39
- }
40
- })
41
-
42
25
  if (this.elem.data('romo-tooltip-style-class') !== undefined) {
43
26
  this.bodyElem.addClass(this.elem.data('romo-tooltip-style-class'));
44
27
  }
@@ -63,6 +46,33 @@ RomoTooltip.prototype.doInit = function() {
63
46
  // override as needed
64
47
  }
65
48
 
49
+ RomoTooltip.prototype.doInitPopup = function() {
50
+ this.popupElem = $('<div class="romo-tooltip-popup"><div class="romo-tooltip-arrow"></div><div class="romo-tooltip-body"></div></div>');
51
+ this.popupElem.appendTo(this.elem.closest(this.elem.data('romo-tooltip-append-to-closest') || 'body'));
52
+
53
+ this.bodyElem = this.popupElem.find('> .romo-tooltip-body');
54
+
55
+ this.popupPosition = this.elem.data('romo-tooltip-position') || 'top';
56
+ this.popupElem.attr('data-romo-tooltip-position', this.popupPosition);
57
+
58
+ this.popupAlignment = this.elem.data('romo-tooltip-alignment') || 'center';
59
+ this.popupElem.attr('data-romo-tooltip-alignment', this.popupAlignment);
60
+
61
+ this.doSetPopupZIndex(this.elem);
62
+
63
+ // don't propagate click events on the popup elem. this prevents the popup
64
+ // from closing when clicked (see body click event bind on popup open)
65
+ this.popupElem.on('click', function(e) {
66
+ if (e !== undefined) {
67
+ e.stopPropagation();
68
+ }
69
+ })
70
+
71
+ // the popup should be treated like a child elem. add it to Romo's
72
+ // parent-child elems so it will be removed when the elem is removed.
73
+ Romo.parentChildElems.add(this.elem, [this.popupElem]);
74
+ }
75
+
66
76
  RomoTooltip.prototype.doInitBody = function() {
67
77
  this.doResetBody();
68
78
 
data/lib/romo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Romo
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 13
8
+ - 14
9
9
  - 0
10
- version: 0.13.0
10
+ version: 0.14.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2015-10-28 00:00:00 Z
19
+ date: 2015-11-03 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement