romo 0.19.10 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,97 +1,120 @@
1
- $.fn.romoSortable = function() {
2
- return $.map(this, function(element) {
3
- return new RomoSortable(element);
4
- });
5
- }
6
-
7
- var RomoSortable = function(element) {
8
- this.elem = $(element);
1
+ var RomoSortable = RomoComponent(function(elem) {
2
+ this.elem = elem;
9
3
 
10
4
  this.draggableSelector = '[data-romo-sortable-item="true"]';
11
- this.handleSelector = '[data-romo-sortable-handle="true"]';
5
+ this.handleSelector = '[data-romo-sortable-handle="true"]';
12
6
 
13
- this.draggedElem = this.draggedIndex = this.draggableSelected = null;
14
- this.draggedOverElem = this.dragDirection = this.lastY = null;
7
+ this.draggedElem = undefined;
8
+ this.draggedIndex = undefined;
9
+ this.draggableSelected = undefined;
10
+ this.draggedOverElem = undefined;
11
+ this.dragDirection = undefined;
12
+ this.lastY = undefined;
15
13
 
16
14
  this.doInit();
17
- this.doBindDrag();
18
- this.doInitPlaceholder();
19
- this._resetGrabClasses();
15
+ this._bindElem();
16
+
17
+ Romo.trigger(this.elem, 'romoSortable:ready', [this]);
18
+ });
20
19
 
21
- this.elem.trigger('sortable:ready', [this]);
20
+ RomoSortable.prototype.draggingClass = function() {
21
+ return Romo.data(this.elem, 'romo-sortable-dragging-class');
22
22
  }
23
23
 
24
- RomoSortable.prototype.doInit = function() {
25
- // override as needed
24
+ RomoSortable.prototype.dragOverClass = function() {
25
+ return Romo.data(this.elem, 'romo-sortable-dragover-class');
26
26
  }
27
27
 
28
- RomoSortable.prototype.doBindDrag = function() {
29
- this.draggingClass = this.elem.data('romo-sortable-dragging-class') || '';
30
- this.dragOverClass = this.elem.data('romo-sortable-dragover-class') || '';
31
- this.placeholderClass = this.elem.data('romo-sortable-placeholder-class') || '';
28
+ RomoSortable.prototype.placeholderClass = function() {
29
+ return Romo.data(this.elem, 'romo-sortable-placeholder-class');
30
+ }
31
+
32
+ // private
33
+
34
+ RomoSortable.prototype._bindElem = function() {
35
+ this.draggableElems = [];
36
+ this._bindDraggableElems(Romo.find(this.elem, this.draggableSelector));
32
37
 
33
- this.draggableElems = $();
34
- this.doBindDraggableElems(this.elem.find(this.draggableSelector));
38
+ Romo.on(this.elem, 'romoSortable:bindDraggableElems', Romo.proxy(this._onBindDraggableElems, this));
35
39
 
36
- this.elem.on('sortable:bindDraggableElems', $.proxy(this.onBindDraggableElems, this));
40
+ Romo.on(this.elem, 'dragenter', Romo.proxy(this._onDragEnter, this));
41
+ Romo.on(this.elem, 'dragover', Romo.proxy(this._onDragOver, this));
42
+ Romo.on(this.elem, 'dragend', Romo.proxy(this._onDragEnd, this));
43
+ Romo.on(this.elem, 'drop', Romo.proxy(this._onDragDrop, this));
37
44
 
38
- this.elem.on('dragenter', $.proxy(this.onDragEnter, this));
39
- this.elem.on('dragover', $.proxy(this.onDragOver, this));
40
- this.elem.on('dragend', $.proxy(this.onDragEnd, this));
41
- this.elem.on('drop', $.proxy(this.onDragDrop, this));
45
+ Romo.on(Romo.f('body')[0], 'mouseup', Romo.proxy(this._onWindowBodyMouseUp, this));
42
46
 
43
- $('body').on('mouseup', $.proxy(this.onWindowBodyMouseUp, this));
47
+ this._bindPlaceholder();
48
+ this._resetGrabClasses();
44
49
  }
45
50
 
46
- RomoSortable.prototype.onBindDraggableElems = function(e, draggableElems) {
47
- this.doBindDraggableElems(draggableElems);
51
+ RomoSortable.prototype._bindPlaceholder = function() {
52
+ var tag = undefined;
53
+ try {
54
+ tag = this.draggableElems[0].tagName;
55
+ } catch(e) {
56
+ tag = /^ul|ol$/i.test(this.elem.tagName) ? 'li' : 'div';
57
+ }
58
+ this.placeholderElem = Romo.elems('<' + tag + '/>')[0];
59
+ if (this.placeholderClass() !== undefined) {
60
+ Romo.addClass(this.placeholderElem, this.placeholderClass());
61
+ }
62
+
63
+ Romo.on(this.placeholderElem, 'dragover', Romo.proxy(this._onDragOver, this));
64
+ Romo.on(this.placeholderElem, 'drop', Romo.proxy(this._onDragDrop, this));
48
65
  }
49
66
 
50
- RomoSortable.prototype.doBindDraggableElems = function(draggableElems) {
51
- draggableElems.prop('draggable', 'true');
67
+ RomoSortable.prototype._bindDraggableElems = function(draggableElems) {
68
+ draggableElems.forEach(Romo.proxy(function(draggableElem) {
69
+ draggableElem.draggable = true;
52
70
 
53
- draggableElems.on('dragstart', $.proxy(this.onDragStart, this));
54
- draggableElems.on('dragenter', $.proxy(this.onDragEnter, this));
55
- draggableElems.on('dragover', $.proxy(this.onDragOver, this));
56
- draggableElems.on('dragend', $.proxy(this.onDragEnd, this));
57
- draggableElems.on('drop', $.proxy(this.onDragDrop, this));
58
- draggableElems.on('mousedown', $.proxy(this.onDraggableMouseDown, this));
71
+ Romo.on(draggableElem, 'dragstart', Romo.proxy(this._onDragStart, this));
72
+ Romo.on(draggableElem, 'dragenter', Romo.proxy(this._onDragEnter, this));
73
+ Romo.on(draggableElem, 'dragover', Romo.proxy(this._onDragOver, this));
74
+ Romo.on(draggableElem, 'dragend', Romo.proxy(this._onDragEnd, this));
75
+ Romo.on(draggableElem, 'drop', Romo.proxy(this._onDragDrop, this));
76
+ Romo.on(draggableElem, 'mousedown', Romo.proxy(this._onDraggableMouseDown, this));
59
77
 
60
- var handleElems = draggableElems.find(this.handleSelector);
61
- handleElems.on('mousedown', $.proxy(this.onHandleMouseDown, this));
78
+ var handleElem = Romo.find(draggableElem, this.handleSelector)[0];
79
+ Romo.on(handleElem, 'mousedown', Romo.proxy(this._onHandleMouseDown, this));
80
+ }, this));
62
81
 
63
- this.draggableElems = this.draggableElems.add(draggableElems);
82
+ this.draggableElems = this.draggableElems.concat(draggableElems);
64
83
  this._resetGrabClasses();
65
84
  }
66
85
 
67
- RomoSortable.prototype.doInitPlaceholder = function() {
68
- var tag;
69
- try {
70
- tag = this.draggableElems.get(0).tagName;
71
- } catch(e) {
72
- tag = /^ul|ol$/i.test(this.elem.tagName) ? 'li' : 'div';
73
- }
74
- this.placeholderElem = $('<' + tag + '/>');
75
- this.placeholderElem.addClass(this.placeholderClass);
86
+ RomoSortable.prototype._resetGrabClasses = function() {
87
+ this.draggableElems.forEach(Romo.proxy(function(draggableElem) {
88
+ handleElem = Romo.find(draggableElem, this.handleSelector)[0];
89
+ if(handleElem === undefined){ handleElem = draggableElem; }
90
+
91
+ Romo.addClass(handleElem, 'romo-sortable-grab');
92
+ Romo.removeClass(handleElem, 'romo-sortable-grabbing');
93
+ }, this));
94
+ }
76
95
 
77
- this.placeholderElem.on('dragover', $.proxy(this.onDragOver, this));
78
- this.placeholderElem.on('drop', $.proxy(this.onDragDrop, this));
96
+ // event functions
97
+
98
+ RomoSortable.prototype.romoEvFn._onBindDraggableElems = function(e, draggableElems) {
99
+ this._bindDraggableElems(draggableElems);
79
100
  }
80
101
 
81
- RomoSortable.prototype.onDragStart = function(e) {
102
+ RomoSortable.prototype.romoEvFn._onDragStart = function(e) {
82
103
  if(!this.draggableSelected){ return false; }
83
104
 
84
105
  e.stopPropagation();
85
- e.originalEvent.dataTransfer.effectAllowed = 'move';
106
+ e.dataTransfer.effectAllowed = 'move';
86
107
 
87
108
  // IE fix
88
109
  try {
89
110
  // FF fix, it won't drag without some data being set
90
- e.originalEvent.dataTransfer.setData('text/plain', null);
111
+ e.dataTransfer.setData('text/plain', null);
91
112
  } catch(e) {}
92
113
 
93
- this.draggedElem = $(e.target);
94
- this.draggedElem.addClass(this.draggingClass);
114
+ this.draggedElem = e.target;
115
+ if (this.draggingClass() !== undefined) {
116
+ Romo.addClass(this.draggedElem, this.draggingClass());
117
+ }
95
118
 
96
119
  // we need to disable Romo's parentRemovedObserver mutation
97
120
  // observer which would remove any child elems (ie modal,
@@ -102,137 +125,148 @@ RomoSortable.prototype.onDragStart = function(e) {
102
125
  // the drag is finished.
103
126
  // we manually enable the mutation observer for the dragged
104
127
  // elem below after we do the `insertBefore` call.
105
- this.draggedElem.data('romo-parent-removed-observer-disabled', true);
128
+ Romo.setData(this.draggedElem, 'romo-parent-removed-observer-disabled', true);
106
129
 
107
- this.draggedIndex = this.draggedElem.index();
130
+ var elems = Romo.children(Romo.parent(this.draggedElem));
131
+ this.draggedIndex = elems.indexOf(this.draggedElem);
108
132
 
109
- this.placeholderElem.css({ 'height': this.draggedElem.height() });
133
+ Romo.setStyle(this.placeholderElem, 'height', Romo.css(this.draggedElem, 'height'));
110
134
 
111
- this.elem.trigger('sortable:dragStart', [this.draggedElem, this]);
135
+ Romo.trigger(this.elem, 'romoSortable:dragStart', [this.draggedElem, this]);
112
136
  }
113
137
 
114
- RomoSortable.prototype.onDragEnter = function(e) {
138
+ RomoSortable.prototype.romoEvFn._onDragEnter = function(e) {
115
139
  e.preventDefault();
116
140
  e.stopPropagation();
117
141
 
118
142
  // return if event is fired on the placeholder
119
- if(this.placeholderElem.get(0) === e.currentTarget){ return; }
143
+ if(this.placeholderElem === e.currentTarget){ return; }
120
144
 
121
- this.placeholderElem.show();
122
- this.draggedElem.hide();
145
+ Romo.show(this.placeholderElem);
146
+ Romo.hide(this.draggedElem);
123
147
 
124
148
  // if event is not fired on the sortable
125
- var overSortableElem = this.elem.get(0) === e.currentTarget;
126
- var clientX = e.originalEvent.clientX;
127
- var clientY = e.originalEvent.clientY;
149
+ var overSortableElem = this.elem === e.currentTarget;
150
+ var clientX = e.clientX;
151
+ var clientY = e.clientY;
128
152
  if (!overSortableElem) {
129
153
  // if we are in the same elem and moving the same direction, exit out
130
- var overSameElem = this.draggedOverElem &&
131
- this.draggedOverElem.get(0) === e.currentTarget;
154
+ var overSameElem = this.draggedOverElem !== undefined &&
155
+ this.draggedOverElem === e.currentTarget;
132
156
  var sameDirection = (this.dragDirection === 'down' && clientY > this.lastY) ||
133
157
  (this.dragDirection === 'up' && clientY < this.lastY);
134
158
  if(overSameElem && sameDirection){ return; }
135
159
 
136
160
  // remove dragged over classes from previous elem
137
- if(this.draggedOverElem){ this.draggedOverElem.removeClass(this.dragOverClass); }
138
- this.draggedOverElem = $(e.currentTarget);
139
- this.lastY = clientY;
140
- this.draggedOverElem.addClass(this.dragOverClass);
161
+ if(this.draggedOverElem !== undefined && this.dragOverClass() !== undefined) {
162
+ Romo.removeClass(this.draggedOverElem, this.dragOverClass());
163
+ }
164
+ this.draggedOverElem = e.currentTarget;
165
+ this.lastY = clientY;
166
+ if (this.dragOverClass() !== undefined) {
167
+ Romo.addClass(this.draggedOverElem, this.dragOverClass());
168
+ }
141
169
 
142
170
  // insert the placeholder according to the dragging direction
143
- if (this.placeholderElem.index() < this.draggedOverElem.index()) {
171
+ var elems = Romo.children(Romo.parent(this.placeholderElem));
172
+ var placeholderIndex = elems.indexOf(this.placeholderElem);
173
+
174
+ elems = Romo.children(Romo.parent(this.draggedOverElem));
175
+ var draggedOverIndex = elems.indexOf(this.draggedOverElem);
176
+
177
+ if (placeholderIndex < draggedOverIndex) {
144
178
  this.dragDirection = 'down';
145
179
  } else {
146
180
  this.dragDirection = 'up';
147
181
  }
182
+
148
183
  var insertMethod = this.dragDirection === 'down' ? 'after' : 'before';
149
- this.draggedOverElem[insertMethod](this.placeholderElem);
184
+ Romo[insertMethod](this.draggedOverElem, this.placeholderElem);
150
185
  }
151
186
 
152
- this.elem.trigger('sortable:dragMove', [clientX, clientY, this.draggedElem, this]);
187
+ Romo.trigger(this.elem, 'romoSortable:dragMove', [clientX, clientY, this.draggedElem, this]);
153
188
  }
154
189
 
155
- RomoSortable.prototype.onDragOver = function(e) {
190
+ RomoSortable.prototype.romoEvFn._onDragOver = function(e) {
156
191
  // This is how you allow an element to receive a drop event.
157
192
  e.preventDefault();
158
193
  e.stopPropagation();
159
194
  }
160
195
 
161
- RomoSortable.prototype.onDragEnd = function(e) {
196
+ RomoSortable.prototype.romoEvFn._onDragEnd = function(e) {
162
197
  e.stopPropagation();
163
198
  e.preventDefault();
164
199
 
165
- if(!this.draggedElem){ return; }
200
+ if(this.draggedElem === undefined){ return; }
166
201
 
167
- this.draggableElems.removeClass(this.dragOverClass);
168
- this.draggedElem.removeClass(this.draggingClass);
169
- this.draggedElem.show();
170
- this.placeholderElem.hide();
202
+ if (this.dragOverClass() !== undefined) {
203
+ Romo.removeClass(this.draggableElems, this.dragOverClass());
204
+ }
205
+ if (this.draggingClass() !== undefined) {
206
+ Romo.removeClass(this.draggedElem, this.draggingClass());
207
+ }
208
+ Romo.show(this.draggedElem);
209
+ Romo.hide(this.placeholderElem);
171
210
  this._resetGrabClasses();
172
211
 
173
- this.elem.trigger('sortable:dragStop', [this.draggedElem, this]);
212
+ Romo.trigger(this.elem, 'romoSortable:dragStop', [this.draggedElem, this]);
174
213
 
175
- this.draggedElem = this.draggedIndex = this.draggableSelected = null;
176
- this.draggedOverElem = this.dragDirection = this.lastY = null;
214
+ this.draggedElem = undefined;
215
+ this.draggedIndex = undefined;
216
+ this.draggableSelected = undefined;
217
+ this.draggedOverElem = undefined;
218
+ this.dragDirection = undefined;
219
+ this.lastY = undefined;
177
220
  }
178
221
 
179
- RomoSortable.prototype.onDragDrop = function(e) {
222
+ RomoSortable.prototype.romoEvFn._onDragDrop = function(e) {
180
223
  e.stopPropagation();
181
224
  e.preventDefault();
182
225
 
183
- if(!this.draggedElem){ return; }
226
+ if(this.draggedElem === undefined){ return; }
184
227
 
185
- this.draggedElem.insertBefore(this.placeholderElem);
186
- this.draggedElem.show();
228
+ Romo.before(this.placeholderElem, this.draggedElem);
229
+ Romo.show(this.draggedElem);
187
230
 
188
231
  // manually enable Romo's parentRemovedObserver mutation
189
232
  // observer which resumes removing any child elems (ie modal,
190
233
  // dropdown, tooltip popups) like normal.
191
234
  // we have to put this in a timeout so the reactor loop has a
192
235
  // chance to run the mutation observer before we re-enable
193
- setTimeout($.proxy(function() {
194
- this.draggedElem.data('romo-parent-removed-observer-disabled', false);
195
- }, this), 1);
236
+ Romo.pushFn(Romo.proxy(function() {
237
+ Romo.setData(this.draggedElem, 'romo-parent-removed-observer-disabled', false);
238
+ }, this));
196
239
 
197
- var newIndex = this.draggedElem.index();
240
+ var elems = Romo.children(Romo.parent(this.draggedElem));
241
+ var newIndex = elems.indexOf(this.draggedElem);
198
242
  if (newIndex !== this.draggedIndex) {
199
- this.elem.trigger('sortable:change', [this.draggedElem, this]);
243
+ Romo.trigger(this.elem, 'romoSortable:change', [this.draggedElem, this]);
200
244
  }
201
- this.elem.trigger('sortable:dragDrop', [this.draggedElem, this]);
245
+ Romo.trigger(this.elem, 'romoSortable:dragDrop', [this.draggedElem, this]);
202
246
  }
203
247
 
204
- RomoSortable.prototype.onDraggableMouseDown = function(e) {
248
+ RomoSortable.prototype.romoEvFn._onDraggableMouseDown = function(e) {
205
249
  // if our draggable elem doesn't have a handle then it's draggable
206
- var draggableElem = $(e.currentTarget);
207
- if(draggableElem.find(this.handleSelector).size() === 0) {
208
- draggableElem.removeClass('romo-sortable-grab');
209
- draggableElem.addClass('romo-sortable-grabbing');
250
+ var draggableElem = e.currentTarget;
251
+ if(Romo.find(draggableElem, this.handleSelector).length === 0) {
252
+ Romo.removeClass(draggableElem, 'romo-sortable-grab');
253
+ Romo.addClass(draggableElem, 'romo-sortable-grabbing');
210
254
  this.draggableSelected = true;
211
255
  }
212
256
  }
213
257
 
214
- RomoSortable.prototype.onHandleMouseDown = function(e) {
258
+ RomoSortable.prototype.romoEvFn._onHandleMouseDown = function(e) {
215
259
  this.draggableSelected = true;
216
- var handleElem = $(e.currentTarget);
217
- handleElem.removeClass('romo-sortable-grab');
218
- handleElem.addClass('romo-sortable-grabbing');
260
+ var handleElem = e.currentTarget;
261
+ Romo.removeClass(handleElem, 'romo-sortable-grab');
262
+ Romo.addClass(handleElem, 'romo-sortable-grabbing');
219
263
  }
220
264
 
221
- RomoSortable.prototype.onWindowBodyMouseUp = function(e) {
265
+ RomoSortable.prototype.romoEvFn._onWindowBodyMouseUp = function(e) {
222
266
  this.draggableSelected = false;
223
267
  this._resetGrabClasses();
224
268
  }
225
269
 
226
- RomoSortable.prototype._resetGrabClasses = function() {
227
- this.draggableElems.each($.proxy(function(index, item) {
228
- draggableElem = $(item);
229
- handleElem = draggableElem.find(this.handleSelector);
230
- if(handleElem.size() === 0){ handleElem = draggableElem; }
231
- handleElem.addClass('romo-sortable-grab');
232
- handleElem.removeClass('romo-sortable-grabbing');
233
- }, this));
234
- }
270
+ // init
235
271
 
236
- Romo.onInitUI(function(e) {
237
- $(e.target).find('[data-romo-sortable-auto="true"]').romoSortable();
238
- });
272
+ Romo.addElemsInitSelector('[data-romo-sortable-auto="true"]', RomoSortable);
@@ -1,113 +1,98 @@
1
1
  //fgnass.github.com/spin.js#v2.0.1
2
2
  !function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.Spinner=b()}(this,function(){"use strict";function a(a,b){var c,d=document.createElement(a||"div");for(c in b)d[c]=b[c];return d}function b(a){for(var b=1,c=arguments.length;c>b;b++)a.appendChild(arguments[b]);return a}function c(a,b,c,d){var e=["opacity",b,~~(100*a),c,d].join("-"),f=.01+c/d*100,g=Math.max(1-(1-a)/b*(100-f),a),h=j.substring(0,j.indexOf("Animation")).toLowerCase(),i=h&&"-"+h+"-"||"";return l[e]||(m.insertRule("@"+i+"keyframes "+e+"{0%{opacity:"+g+"}"+f+"%{opacity:"+a+"}"+(f+.01)+"%{opacity:1}"+(f+b)%100+"%{opacity:"+a+"}100%{opacity:"+g+"}}",m.cssRules.length),l[e]=1),e}function d(a,b){var c,d,e=a.style;for(b=b.charAt(0).toUpperCase()+b.slice(1),d=0;d<k.length;d++)if(c=k[d]+b,void 0!==e[c])return c;return void 0!==e[b]?b:void 0}function e(a,b){for(var c in b)a.style[d(a,c)||c]=b[c];return a}function f(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];for(var d in c)void 0===a[d]&&(a[d]=c[d])}return a}function g(a,b){return"string"==typeof a?a:a[b%a.length]}function h(a){this.opts=f(a||{},h.defaults,n)}function i(){function c(b,c){return a("<"+b+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',c)}m.addRule(".spin-vml","behavior:url(#default#VML)"),h.prototype.lines=function(a,d){function f(){return e(c("group",{coordsize:k+" "+k,coordorigin:-j+" "+-j}),{width:k,height:k})}function h(a,h,i){b(m,b(e(f(),{rotation:360/d.lines*a+"deg",left:~~h}),b(e(c("roundrect",{arcsize:d.corners}),{width:j,height:d.width,left:d.radius,top:-d.width>>1,filter:i}),c("fill",{color:g(d.color,a),opacity:d.opacity}),c("stroke",{opacity:0}))))}var i,j=d.length+d.width,k=2*j,l=2*-(d.width+d.length)+"px",m=e(f(),{position:"absolute",top:l,left:l});if(d.shadow)for(i=1;i<=d.lines;i++)h(i,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(i=1;i<=d.lines;i++)h(i);return b(a,m)},h.prototype.opacity=function(a,b,c,d){var e=a.firstChild;d=d.shadow&&d.lines||0,e&&b+d<e.childNodes.length&&(e=e.childNodes[b+d],e=e&&e.firstChild,e=e&&e.firstChild,e&&(e.opacity=c))}}var j,k=["webkit","Moz","ms","O"],l={},m=function(){var c=a("style",{type:"text/css"});return b(document.getElementsByTagName("head")[0],c),c.sheet||c.styleSheet}(),n={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",direction:1,speed:1,trail:100,opacity:.25,fps:20,zIndex:2e9,className:"spinner",top:"50%",left:"50%",position:"absolute"};h.defaults={},f(h.prototype,{spin:function(b){this.stop();{var c=this,d=c.opts,f=c.el=e(a(0,{className:d.className}),{position:d.position,width:0,zIndex:d.zIndex});d.radius+d.length+d.width}if(e(f,{left:d.left,top:d.top}),b&&b.insertBefore(f,b.firstChild||null),f.setAttribute("role","progressbar"),c.lines(f,c.opts),!j){var g,h=0,i=(d.lines-1)*(1-d.direction)/2,k=d.fps,l=k/d.speed,m=(1-d.opacity)/(l*d.trail/100),n=l/d.lines;!function o(){h++;for(var a=0;a<d.lines;a++)g=Math.max(1-(h+(d.lines-a)*n)%l*m,d.opacity),c.opacity(f,a*d.direction+i,g,d);c.timeout=c.el&&setTimeout(o,~~(1e3/k))}()}return c},stop:function(){var a=this.el;return a&&(clearTimeout(this.timeout),a.parentNode&&a.parentNode.removeChild(a),this.el=void 0),this},lines:function(d,f){function h(b,c){return e(a(),{position:"absolute",width:f.length+f.width+"px",height:f.width+"px",background:b,boxShadow:c,transformOrigin:"left",transform:"rotate("+~~(360/f.lines*k+f.rotate)+"deg) translate("+f.radius+"px,0)",borderRadius:(f.corners*f.width>>1)+"px"})}for(var i,k=0,l=(f.lines-1)*(1-f.direction)/2;k<f.lines;k++)i=e(a(),{position:"absolute",top:1+~(f.width/2)+"px",transform:f.hwaccel?"translate3d(0,0,0)":"",opacity:f.opacity,animation:j&&c(f.opacity,f.trail,l+k*f.direction,f.lines)+" "+1/f.speed+"s linear infinite"}),f.shadow&&b(i,e(h("#000","0 0 4px #000"),{top:"2px"})),b(d,b(i,h(g(f.color,k),"0 0 1px rgba(0,0,0,.1)")));return d},opacity:function(a,b,c){b<a.childNodes.length&&(a.childNodes[b].style.opacity=c)}});var o=e(a("group"),{behavior:"url(#default#VML)"});return!d(o,"transform")&&o.adj?i():j=d(o,"animation"),h});
3
3
 
4
- $.fn.romoIndicator = function() {
5
- return $.map(this, function(element) {
6
- return new RomoIndicator(element);
7
- });
8
- }
9
-
10
- var RomoIndicator = function(element) {
11
- this.elem = $(element);
12
- this.elemStyle = this.elem.attr('style');
4
+ var RomoSpinner = RomoComponent(function(elem) {
5
+ this.elem = elem;
13
6
 
14
7
  this.doInit();
8
+ this._bindElem();
15
9
 
16
- this.elem.on('indicator:triggerStart', $.proxy(this.onStart, this));
17
- this.elem.on('indicator:triggerStop', $.proxy(this.onStop, this));
18
-
19
- if (this.elem.data('romo-indicator-stop-on-pageshow') !== false) {
20
- $(window).on("pageshow", $.proxy(function(e) {
21
- this.elem.trigger('indicator:triggerStop');
22
- }, this));
23
- }
24
-
25
- this.elem.trigger('indicator:ready', [this]);
26
- }
27
-
28
- RomoIndicator.prototype.doInit = function() {
29
- // override as needed
30
- }
31
-
32
- RomoIndicator.prototype.onStart = function(e, basisSize) {
33
- if (e !== undefined) {
34
- e.preventDefault();
35
- }
36
-
37
- this.doStart(basisSize);
38
- }
39
-
40
- RomoIndicator.prototype.onStop = function(e) {
41
- if (e !== undefined) {
42
- e.preventDefault();
43
- }
44
-
45
- this.doStop();
46
- }
10
+ Romo.trigger(this.elem, 'romoSpinner:ready', [this]);
11
+ });
47
12
 
48
- RomoIndicator.prototype.doStart = function(customBasisSize) {
49
- var basisSize = customBasisSize;
50
- if (basisSize === undefined) {
51
- basisSize = this.elem.data('romo-indicator-basis-size');
52
- }
53
- if (basisSize === undefined) {
54
- basisSize = Math.min(
55
- parseInt(Romo.getComputedStyle(this.elem[0], "width")),
56
- parseInt(Romo.getComputedStyle(this.elem[0], "height"))
57
- )
58
- }
13
+ RomoSpinner.prototype.doStart = function(customBasisSize) {
14
+ var basisSize = (
15
+ customBasisSize ||
16
+ Romo.data(this.elem, 'romo-spinner-basis-size') ||
17
+ Math.min(parseInt(Romo.css(this.elem, "width"), 10), parseInt(Romo.css(this.elem, "height"), 10))
18
+ );
59
19
 
60
20
  var spinnerOpts = {
61
- lines: 11, // The number of lines to draw
62
- width: 2, // The line thickness
63
- length: parseInt(basisSize) / 4.5, // The length of each line
64
- radius: parseInt(basisSize) / 5.5, // The radius of the inner circle
65
- corners: 1, // Corner roundness (0..1)
66
- rotate: 0, // The rotation offset
67
- direction: 1, // 1: clockwise, -1: counterclockwise
68
- color: this.elem.css('color'), // #rgb or #rrggbb or array of colors
69
- speed: 1, // Rounds per second
70
- trail: 60, // Afterglow percentage
71
- shadow: false, // Whether to render a shadow
72
- hwaccel: false, // Whether to use hardware acceleration
73
- className: 'spinner', // The CSS class to assign to the spinner
74
- zIndex: 1000, // The z-index (defaults to 2000000000)
75
- top: '50%', // Top position relative to parent
76
- left: '50%'// Left position relative to parent
21
+ lines: 11, // The number of lines to draw
22
+ width: 2, // The line thickness
23
+ length: parseInt(basisSize, 10) / 4.5, // The length of each line
24
+ radius: parseInt(basisSize, 10) / 5.5, // The radius of the inner circle
25
+ corners: 1, // Corner roundness (0..1)
26
+ rotate: 0, // The rotation offset
27
+ direction: 1, // 1: clockwise, -1: counterclockwise
28
+ color: Romo.css(this.elem, 'color'), // #rgb or #rrggbb or array of colors
29
+ speed: 1, // Rounds per second
30
+ trail: 60, // Afterglow percentage
31
+ shadow: false, // Whether to render a shadow
32
+ hwaccel: false, // Whether to use hardware acceleration
33
+ className: 'spinner', // The CSS class to assign to the spinner
34
+ zIndex: 1000, // The z-index (defaults to 2000000000)
35
+ top: '50%', // Top position relative to parent
36
+ left: '50%' // Left position relative to parent
77
37
  };
78
38
  this.spinner = new Spinner(spinnerOpts);
79
39
 
80
- this.elemHtml = this.elem.html();
81
- this.elemStyle = this.elem.attr('style');
82
- this.elem.css({
83
- 'position': 'relative',
84
- 'width': this.elem.css('width'),
85
- 'height': this.elem.css('height'),
86
- });
87
- this.elem.html('');
88
- this.spinner.spin(this.elem[0]);
89
- this.elem.trigger('indicator:start', [this]);
40
+ this.elemHtml = this.elem.innerHTML;
41
+ this.elemStyle = Romo.attr(this.elem, 'style');
42
+
43
+ Romo.setStyle(this.elem, 'position', 'relative');
44
+ Romo.setStyle(this.elem, 'width', Romo.css(this.elem, 'width'));
45
+ Romo.setStyle(this.elem, 'height', Romo.css(this.elem, 'height'));
46
+
47
+ Romo.updateHtml(this.elem, '');
48
+ this.spinner.spin(this.elem);
49
+
50
+ Romo.trigger(this.elem, 'romoSpinner:start', [this]);
90
51
  }
91
52
 
92
- RomoIndicator.prototype.doStop = function() {
53
+ RomoSpinner.prototype.doStop = function() {
93
54
  if (this.spinner !== undefined) {
94
55
  this.spinner.stop();
95
56
  this.spinner = undefined;
96
57
  }
97
58
  if (this.elemHtml !== undefined) {
98
- this.elem.html(this.elemHtml);
59
+ this.elem.innerHTML = this.elemHtml;
99
60
  }
100
- this.elem.css({
101
- 'position': '',
102
- 'width': '',
103
- 'height': '',
104
- });
61
+ Romo.rmStyle(this.elem, 'position');
62
+ Romo.rmStyle(this.elem, 'width');
63
+ Romo.rmStyle(this.elem, 'height');
64
+
105
65
  if (this.elemStyle !== undefined) {
106
- this.elem.attr('style', this.elemStyle);
66
+ Romo.setAttr(this.elem, 'style', this.elemStyle);
107
67
  }
108
- this.elem.trigger('indicator:stop', [this]);
68
+ Romo.trigger(this.elem, 'romoSpinner:stop', [this]);
109
69
  }
110
70
 
111
- Romo.onInitUI(function(e) {
112
- Romo.initUIElems(e, '[data-romo-indicator-auto="true"]').romoIndicator();
113
- });
71
+ // private
72
+
73
+ RomoSpinner.prototype._bindElem = function() {
74
+ this.elemStyle = Romo.attr(this.elem, 'style');
75
+
76
+ Romo.on(this.elem, 'romoSpinner:triggerStart', Romo.proxy(this._onStart, this));
77
+ Romo.on(this.elem, 'romoSpinner:triggerStop', Romo.proxy(this._onStop, this));
78
+
79
+ if (Romo.data(this.elem, 'romo-spinner-stop-on-pageshow') !== false) {
80
+ Romo.on(window, "pageshow", Romo.proxy(function(e) {
81
+ Romo.trigger(this.elem, 'romoSpinner:triggerStop');
82
+ }, this));
83
+ }
84
+ }
85
+
86
+ // event functions
87
+
88
+ RomoSpinner.prototype.romoEvFn._onStart = function(e, basisSize) {
89
+ this.doStart(basisSize);
90
+ }
91
+
92
+ RomoSpinner.prototype.romoEvFn._onStop = function(e) {
93
+ this.doStop();
94
+ }
95
+
96
+ // init
97
+
98
+ Romo.addElemsInitSelector('[data-romo-spinner-auto="true"]', RomoSpinner);