uikit-rails 0.0.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -3
- data/Gemfile +2 -1
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +0 -1
- data/assets/fonts/FontAwesome.otf +0 -0
- data/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/assets/fonts/fontawesome-webfont.woff +0 -0
- data/assets/fonts/fontawesome-webfont.woff2 +0 -0
- data/assets/javascripts/components/accordion.js +174 -0
- data/assets/javascripts/components/accordion.min.js +2 -0
- data/assets/javascripts/components/autocomplete.js +334 -0
- data/assets/javascripts/components/autocomplete.min.js +2 -0
- data/assets/javascripts/components/datepicker.js +3166 -0
- data/assets/javascripts/components/datepicker.min.js +3 -0
- data/assets/javascripts/components/form-password.js +67 -0
- data/assets/javascripts/components/form-password.min.js +2 -0
- data/assets/javascripts/components/form-select.js +70 -0
- data/assets/javascripts/components/form-select.min.js +2 -0
- data/assets/javascripts/components/grid.js +527 -0
- data/assets/javascripts/components/grid.min.js +2 -0
- data/assets/javascripts/components/htmleditor.js +623 -0
- data/assets/javascripts/components/htmleditor.min.js +2 -0
- data/assets/javascripts/components/lightbox.js +555 -0
- data/assets/javascripts/components/lightbox.min.js +2 -0
- data/assets/javascripts/components/nestable.js +638 -0
- data/assets/javascripts/components/nestable.min.js +2 -0
- data/assets/javascripts/components/notify.js +189 -0
- data/assets/javascripts/components/notify.min.js +2 -0
- data/assets/javascripts/components/pagination.js +147 -0
- data/assets/javascripts/components/pagination.min.js +2 -0
- data/assets/javascripts/components/parallax.js +435 -0
- data/assets/javascripts/components/parallax.min.js +2 -0
- data/assets/javascripts/components/search.js +92 -0
- data/assets/javascripts/components/search.min.js +2 -0
- data/assets/javascripts/components/slider.js +531 -0
- data/assets/javascripts/components/slider.min.js +2 -0
- data/assets/javascripts/components/slideset.js +506 -0
- data/assets/javascripts/components/slideset.min.js +2 -0
- data/assets/javascripts/components/slideshow-fx.js +375 -0
- data/assets/javascripts/components/slideshow-fx.min.js +2 -0
- data/assets/javascripts/components/slideshow.js +562 -0
- data/assets/javascripts/components/slideshow.min.js +2 -0
- data/assets/javascripts/components/sortable.js +688 -0
- data/assets/javascripts/components/sortable.min.js +2 -0
- data/assets/javascripts/components/sticky.js +359 -0
- data/assets/javascripts/components/sticky.min.js +2 -0
- data/assets/javascripts/components/timepicker.js +192 -0
- data/assets/javascripts/components/timepicker.min.js +2 -0
- data/assets/javascripts/components/tooltip.js +234 -0
- data/assets/javascripts/components/tooltip.min.js +2 -0
- data/assets/javascripts/components/upload.js +260 -0
- data/assets/javascripts/components/upload.min.js +2 -0
- data/assets/javascripts/core/alert.js +66 -0
- data/assets/javascripts/core/alert.min.js +2 -0
- data/assets/javascripts/core/button.js +157 -0
- data/assets/javascripts/core/button.min.js +2 -0
- data/assets/javascripts/core/core.js +730 -0
- data/assets/javascripts/core/core.min.js +2 -0
- data/assets/javascripts/core/cover.js +95 -0
- data/assets/javascripts/core/cover.min.js +2 -0
- data/assets/javascripts/core/dropdown.js +514 -0
- data/assets/javascripts/core/dropdown.min.js +2 -0
- data/assets/javascripts/core/grid.js +114 -0
- data/assets/javascripts/core/grid.min.js +2 -0
- data/assets/javascripts/core/modal.js +384 -0
- data/assets/javascripts/core/modal.min.js +2 -0
- data/assets/javascripts/core/nav.js +136 -0
- data/assets/javascripts/core/nav.min.js +2 -0
- data/assets/javascripts/core/offcanvas.js +180 -0
- data/assets/javascripts/core/offcanvas.min.js +2 -0
- data/assets/javascripts/core/scrollspy.js +208 -0
- data/assets/javascripts/core/scrollspy.min.js +2 -0
- data/assets/javascripts/core/smooth-scroll.js +62 -0
- data/assets/javascripts/core/smooth-scroll.min.js +2 -0
- data/assets/javascripts/core/switcher.js +309 -0
- data/assets/javascripts/core/switcher.min.js +2 -0
- data/assets/javascripts/core/tab.js +167 -0
- data/assets/javascripts/core/tab.min.js +2 -0
- data/assets/javascripts/core/toggle.js +120 -0
- data/assets/javascripts/core/toggle.min.js +2 -0
- data/assets/javascripts/core/touch.js +175 -0
- data/assets/javascripts/core/touch.min.js +2 -0
- data/assets/javascripts/core/utility.js +289 -0
- data/assets/javascripts/core/utility.min.js +2 -0
- data/assets/javascripts/uikit-components.js +23 -0
- data/assets/javascripts/uikit.js +3706 -0
- data/assets/javascripts/uikit.min.js +3 -0
- data/assets/stylesheets/components/accordion.scss +94 -0
- data/assets/stylesheets/components/autocomplete.scss +102 -0
- data/assets/stylesheets/components/datepicker.scss +197 -0
- data/assets/stylesheets/components/dotnav.scss +212 -0
- data/assets/stylesheets/components/form-advanced.scss +128 -0
- data/assets/stylesheets/components/form-file.scss +63 -0
- data/assets/stylesheets/components/form-password.scss +74 -0
- data/assets/stylesheets/components/form-select.scss +66 -0
- data/assets/stylesheets/components/htmleditor.scss +269 -0
- data/assets/stylesheets/components/nestable.scss +229 -0
- data/assets/stylesheets/components/notify.scss +190 -0
- data/assets/stylesheets/components/placeholder.scss +66 -0
- data/assets/stylesheets/components/progress.scss +173 -0
- data/assets/stylesheets/components/search.scss +309 -0
- data/assets/stylesheets/components/slidenav.scss +183 -0
- data/assets/stylesheets/components/slider.scss +131 -0
- data/assets/stylesheets/components/slideshow.scss +208 -0
- data/assets/stylesheets/components/sortable.scss +122 -0
- data/assets/stylesheets/components/sticky.scss +64 -0
- data/assets/stylesheets/components/tooltip.scss +177 -0
- data/assets/stylesheets/components/upload.scss +34 -0
- data/assets/stylesheets/core/alert.scss +141 -0
- data/assets/stylesheets/core/animation.scss +599 -0
- data/assets/stylesheets/core/article.scss +139 -0
- data/assets/stylesheets/core/badge.scss +110 -0
- data/assets/stylesheets/core/base-noconflict.scss +397 -0
- data/assets/stylesheets/core/base.scss +541 -0
- data/assets/stylesheets/core/block.scss +153 -0
- data/assets/stylesheets/core/breadcrumb.scss +86 -0
- data/assets/stylesheets/core/button.scss +406 -0
- data/assets/stylesheets/core/close.scss +132 -0
- data/assets/stylesheets/core/column.scss +209 -0
- data/assets/stylesheets/core/comment.scss +172 -0
- data/assets/stylesheets/core/contrast.scss +493 -0
- data/assets/stylesheets/core/cover.scss +70 -0
- data/assets/stylesheets/core/description-list.scss +71 -0
- data/assets/stylesheets/core/dropdown.scss +280 -0
- data/assets/stylesheets/core/flex.scss +320 -0
- data/assets/stylesheets/core/form.scss +627 -0
- data/assets/stylesheets/core/grid.scss +688 -0
- data/assets/stylesheets/core/icon.scss +897 -0
- data/assets/stylesheets/core/list.scss +102 -0
- data/assets/stylesheets/core/modal.scss +341 -0
- data/assets/stylesheets/core/nav.scss +468 -0
- data/assets/stylesheets/core/navbar.scss +325 -0
- data/assets/stylesheets/core/offcanvas.scss +168 -0
- data/assets/stylesheets/core/overlay.scss +534 -0
- data/assets/stylesheets/core/pagination.scss +197 -0
- data/assets/stylesheets/core/panel.scss +332 -0
- data/assets/stylesheets/core/print.scss +59 -0
- data/assets/stylesheets/core/subnav.scss +213 -0
- data/assets/stylesheets/core/switcher.scss +38 -0
- data/assets/stylesheets/core/tab.scss +368 -0
- data/assets/stylesheets/core/table.scss +147 -0
- data/assets/stylesheets/core/text.scss +128 -0
- data/assets/stylesheets/core/thumbnail.scss +122 -0
- data/assets/stylesheets/core/thumbnav.scss +122 -0
- data/assets/stylesheets/core/utility.scss +606 -0
- data/assets/stylesheets/core/variables.scss +23 -0
- data/assets/stylesheets/uikit-components.scss +22 -0
- data/assets/stylesheets/uikit-mixins.scss +327 -0
- data/assets/stylesheets/uikit-variables.scss +817 -0
- data/assets/stylesheets/uikit.scss +56 -0
- data/lib/uikit-rails.rb +2 -2
- data/lib/uikit-rails/engine.rb +11 -1
- data/lib/uikit-rails/version.rb +1 -3
- data/uikit-rails.gemspec +15 -16
- metadata +169 -44
- data/README.rb +0 -1
- data/vendor/assets/javascripts/ui.card.js +0 -115
- data/vendor/assets/javascripts/ui.color-picker.js +0 -351
- data/vendor/assets/javascripts/ui.confirmation.js +0 -133
- data/vendor/assets/javascripts/ui.dialog.js +0 -252
- data/vendor/assets/javascripts/ui.emitter.js +0 -99
- data/vendor/assets/javascripts/ui.js +0 -1641
- data/vendor/assets/javascripts/ui.menu.js +0 -238
- data/vendor/assets/javascripts/ui.notification.js +0 -240
- data/vendor/assets/javascripts/ui.overlay.js +0 -79
- data/vendor/assets/javascripts/ui.split-button.js +0 -108
- data/vendor/assets/stylesheets/ui.card.css +0 -55
- data/vendor/assets/stylesheets/ui.color-picker.css +0 -6
- data/vendor/assets/stylesheets/ui.confirmation.css +0 -7
- data/vendor/assets/stylesheets/ui.css +0 -337
- data/vendor/assets/stylesheets/ui.dialog.css +0 -92
- data/vendor/assets/stylesheets/ui.menu.css +0 -32
- data/vendor/assets/stylesheets/ui.notification.css +0 -107
- data/vendor/assets/stylesheets/ui.overlay.css +0 -16
- data/vendor/assets/stylesheets/ui.split-button.css +0 -27
@@ -1,351 +0,0 @@
|
|
1
|
-
|
2
|
-
/**
|
3
|
-
* Expose `ColorPicker`.
|
4
|
-
*/
|
5
|
-
|
6
|
-
exports.ColorPicker = ColorPicker;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* RGB util.
|
10
|
-
*/
|
11
|
-
|
12
|
-
function rgb(r,g,b) {
|
13
|
-
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
|
14
|
-
}
|
15
|
-
|
16
|
-
/**
|
17
|
-
* RGBA util.
|
18
|
-
*/
|
19
|
-
|
20
|
-
function rgba(r,g,b,a) {
|
21
|
-
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')';
|
22
|
-
}
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Mouse position util.
|
26
|
-
*/
|
27
|
-
|
28
|
-
function localPos(e) {
|
29
|
-
var offset = $(e.target).offset();
|
30
|
-
return {
|
31
|
-
x: e.pageX - offset.left
|
32
|
-
, y: e.pageY - offset.top
|
33
|
-
};
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Initialize a new `ColorPicker`.
|
38
|
-
*
|
39
|
-
* Emits:
|
40
|
-
*
|
41
|
-
* - `change` with the given color object
|
42
|
-
*
|
43
|
-
* @api public
|
44
|
-
*/
|
45
|
-
|
46
|
-
function ColorPicker() {
|
47
|
-
ui.Emitter.call(this);
|
48
|
-
this._colorPos = {};
|
49
|
-
this.el = $(html);
|
50
|
-
this.main = this.el.find('.main').get(0);
|
51
|
-
this.spectrum = this.el.find('.spectrum').get(0);
|
52
|
-
$(this.main).bind('selectstart', function(e){ e.preventDefault() });
|
53
|
-
$(this.spectrum).bind('selectstart', function(e){ e.preventDefault() });
|
54
|
-
this.hue(rgb(255, 0, 0));
|
55
|
-
this.spectrumEvents();
|
56
|
-
this.mainEvents();
|
57
|
-
this.w = 180;
|
58
|
-
this.h = 180;
|
59
|
-
this.render();
|
60
|
-
}
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Inherit from `Emitter.prototype`.
|
64
|
-
*/
|
65
|
-
|
66
|
-
ColorPicker.prototype = new ui.Emitter;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Set width / height to `n`.
|
70
|
-
*
|
71
|
-
* @param {Number} n
|
72
|
-
* @return {ColorPicker} for chaining
|
73
|
-
* @api public
|
74
|
-
*/
|
75
|
-
|
76
|
-
ColorPicker.prototype.size = function(n){
|
77
|
-
return this
|
78
|
-
.width(n)
|
79
|
-
.height(n);
|
80
|
-
};
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Set width to `n`.
|
84
|
-
*
|
85
|
-
* @param {Number} n
|
86
|
-
* @return {ColorPicker} for chaining
|
87
|
-
* @api public
|
88
|
-
*/
|
89
|
-
|
90
|
-
ColorPicker.prototype.width = function(n){
|
91
|
-
this.w = n;
|
92
|
-
this.render();
|
93
|
-
return this;
|
94
|
-
};
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Set height to `n`.
|
98
|
-
*
|
99
|
-
* @param {Number} n
|
100
|
-
* @return {ColorPicker} for chaining
|
101
|
-
* @api public
|
102
|
-
*/
|
103
|
-
|
104
|
-
ColorPicker.prototype.height = function(n){
|
105
|
-
this.h = n;
|
106
|
-
this.render();
|
107
|
-
return this;
|
108
|
-
};
|
109
|
-
|
110
|
-
/**
|
111
|
-
* Spectrum related events.
|
112
|
-
*
|
113
|
-
* @api private
|
114
|
-
*/
|
115
|
-
|
116
|
-
ColorPicker.prototype.spectrumEvents = function(){
|
117
|
-
var self = this
|
118
|
-
, canvas = $(this.spectrum)
|
119
|
-
, down;
|
120
|
-
|
121
|
-
function update(e) {
|
122
|
-
var offsetY = localPos(e).y
|
123
|
-
, color = self.hueAt(offsetY - 4);
|
124
|
-
self.hue(color.toString());
|
125
|
-
self.emit('change', color);
|
126
|
-
self._huePos = offsetY;
|
127
|
-
self.render();
|
128
|
-
}
|
129
|
-
|
130
|
-
canvas.mousedown(function(e){
|
131
|
-
e.preventDefault();
|
132
|
-
down = true;
|
133
|
-
update(e);
|
134
|
-
});
|
135
|
-
|
136
|
-
canvas.mousemove(function(e){
|
137
|
-
if (down) update(e);
|
138
|
-
});
|
139
|
-
|
140
|
-
canvas.mouseup(function(){
|
141
|
-
down = false;
|
142
|
-
});
|
143
|
-
};
|
144
|
-
|
145
|
-
/**
|
146
|
-
* Hue / lightness events.
|
147
|
-
*
|
148
|
-
* @api private
|
149
|
-
*/
|
150
|
-
|
151
|
-
ColorPicker.prototype.mainEvents = function(){
|
152
|
-
var self = this
|
153
|
-
, canvas = $(this.main)
|
154
|
-
, down;
|
155
|
-
|
156
|
-
function update(e) {
|
157
|
-
var color;
|
158
|
-
self._colorPos = localPos(e);
|
159
|
-
color = self.colorAt(self._colorPos.x, self._colorPos.y);
|
160
|
-
self.color(color.toString());
|
161
|
-
self.emit('change', color);
|
162
|
-
|
163
|
-
self.render();
|
164
|
-
}
|
165
|
-
|
166
|
-
canvas.mousedown(function(e){
|
167
|
-
down = true;
|
168
|
-
update(e);
|
169
|
-
});
|
170
|
-
|
171
|
-
canvas.mousemove(function(e){
|
172
|
-
if (down) update(e);
|
173
|
-
});
|
174
|
-
|
175
|
-
canvas.mouseup(function(){
|
176
|
-
down = false;
|
177
|
-
});
|
178
|
-
};
|
179
|
-
|
180
|
-
/**
|
181
|
-
* Get the RGB color at `(x, y)`.
|
182
|
-
*
|
183
|
-
* @param {Number} x
|
184
|
-
* @param {Number} y
|
185
|
-
* @return {Object}
|
186
|
-
* @api private
|
187
|
-
*/
|
188
|
-
|
189
|
-
ColorPicker.prototype.colorAt = function(x, y){
|
190
|
-
var data = this.main.getContext('2d').getImageData(x, y, 1, 1).data;
|
191
|
-
return {
|
192
|
-
r: data[0]
|
193
|
-
, g: data[1]
|
194
|
-
, b: data[2]
|
195
|
-
, toString: function(){
|
196
|
-
return rgb(this.r, this.g, this.b);
|
197
|
-
}
|
198
|
-
};
|
199
|
-
};
|
200
|
-
|
201
|
-
/**
|
202
|
-
* Get the RGB value at `y`.
|
203
|
-
*
|
204
|
-
* @param {Type} name
|
205
|
-
* @return {Type}
|
206
|
-
* @api private
|
207
|
-
*/
|
208
|
-
|
209
|
-
ColorPicker.prototype.hueAt = function(y){
|
210
|
-
var data = this.spectrum.getContext('2d').getImageData(0, y, 1, 1).data;
|
211
|
-
return {
|
212
|
-
r: data[0]
|
213
|
-
, g: data[1]
|
214
|
-
, b: data[2]
|
215
|
-
, toString: function(){
|
216
|
-
return rgb(this.r, this.g, this.b);
|
217
|
-
}
|
218
|
-
};
|
219
|
-
};
|
220
|
-
|
221
|
-
/**
|
222
|
-
* Get or set `color`.
|
223
|
-
*
|
224
|
-
* @param {String} color
|
225
|
-
* @return {String|ColorPicker}
|
226
|
-
* @api public
|
227
|
-
*/
|
228
|
-
|
229
|
-
ColorPicker.prototype.color = function(color){
|
230
|
-
// TODO: update pos
|
231
|
-
if (0 == arguments.length) return this._color;
|
232
|
-
this._color = color;
|
233
|
-
return this;
|
234
|
-
};
|
235
|
-
|
236
|
-
/**
|
237
|
-
* Get or set hue `color`.
|
238
|
-
*
|
239
|
-
* @param {String} color
|
240
|
-
* @return {String|ColorPicker}
|
241
|
-
* @api public
|
242
|
-
*/
|
243
|
-
|
244
|
-
ColorPicker.prototype.hue = function(color){
|
245
|
-
// TODO: update pos
|
246
|
-
if (0 == arguments.length) return this._hue;
|
247
|
-
this._hue = color;
|
248
|
-
return this;
|
249
|
-
};
|
250
|
-
|
251
|
-
/**
|
252
|
-
* Render with the given `options`.
|
253
|
-
*
|
254
|
-
* @param {Object} options
|
255
|
-
* @api public
|
256
|
-
*/
|
257
|
-
|
258
|
-
ColorPicker.prototype.render = function(options){
|
259
|
-
options = options || {};
|
260
|
-
this.renderMain(options);
|
261
|
-
this.renderSpectrum(options);
|
262
|
-
};
|
263
|
-
|
264
|
-
/**
|
265
|
-
* Render spectrum.
|
266
|
-
*
|
267
|
-
* @api private
|
268
|
-
*/
|
269
|
-
|
270
|
-
ColorPicker.prototype.renderSpectrum = function(options){
|
271
|
-
var el = this.el
|
272
|
-
, canvas = this.spectrum
|
273
|
-
, ctx = canvas.getContext('2d')
|
274
|
-
, pos = this._huePos
|
275
|
-
, w = this.w * .12
|
276
|
-
, h = this.h;
|
277
|
-
|
278
|
-
canvas.width = w;
|
279
|
-
canvas.height = h;
|
280
|
-
|
281
|
-
var grad = ctx.createLinearGradient(0, 0, 0, h);
|
282
|
-
grad.addColorStop(0, rgb(255, 0, 0));
|
283
|
-
grad.addColorStop(.15, rgb(255, 0, 255));
|
284
|
-
grad.addColorStop(.33, rgb(0, 0, 255));
|
285
|
-
grad.addColorStop(.49, rgb(0, 255, 255));
|
286
|
-
grad.addColorStop(.67, rgb(0, 255, 0));
|
287
|
-
grad.addColorStop(.84, rgb(255, 255, 0));
|
288
|
-
grad.addColorStop(1, rgb(255, 0, 0));
|
289
|
-
|
290
|
-
ctx.fillStyle = grad;
|
291
|
-
ctx.fillRect(0, 0, w, h);
|
292
|
-
|
293
|
-
// pos
|
294
|
-
if (!pos) return;
|
295
|
-
ctx.fillStyle = rgba(0,0,0, .3);
|
296
|
-
ctx.fillRect(0, pos, w, 1);
|
297
|
-
ctx.fillStyle = rgba(255,255,255, .3);
|
298
|
-
ctx.fillRect(0, pos + 1, w, 1);
|
299
|
-
};
|
300
|
-
|
301
|
-
/**
|
302
|
-
* Render hue/luminosity canvas.
|
303
|
-
*
|
304
|
-
* @api private
|
305
|
-
*/
|
306
|
-
|
307
|
-
ColorPicker.prototype.renderMain = function(options){
|
308
|
-
var el = this.el
|
309
|
-
, canvas = this.main
|
310
|
-
, ctx = canvas.getContext('2d')
|
311
|
-
, w = this.w
|
312
|
-
, h = this.h
|
313
|
-
, x = (this._colorPos.x || w) + .5
|
314
|
-
, y = (this._colorPos.y || 0) + .5;
|
315
|
-
|
316
|
-
canvas.width = w;
|
317
|
-
canvas.height = h;
|
318
|
-
|
319
|
-
var grad = ctx.createLinearGradient(0, 0, w, 0);
|
320
|
-
grad.addColorStop(0, rgb(255, 255, 255));
|
321
|
-
grad.addColorStop(1, this._hue);
|
322
|
-
|
323
|
-
ctx.fillStyle = grad;
|
324
|
-
ctx.fillRect(0, 0, w, h);
|
325
|
-
|
326
|
-
grad = ctx.createLinearGradient(0, 0, 0, h);
|
327
|
-
grad.addColorStop(0, rgba(255, 255, 255, 0));
|
328
|
-
grad.addColorStop(1, rgba(0, 0, 0, 1));
|
329
|
-
|
330
|
-
ctx.fillStyle = grad;
|
331
|
-
ctx.fillRect(0, 0, w, h);
|
332
|
-
|
333
|
-
// pos
|
334
|
-
var rad = 10;
|
335
|
-
ctx.save();
|
336
|
-
ctx.beginPath();
|
337
|
-
ctx.lineWidth = 1;
|
338
|
-
|
339
|
-
// outer dark
|
340
|
-
ctx.strokeStyle = rgba(0,0,0,.5);
|
341
|
-
ctx.arc(x, y, rad / 2, 0, Math.PI * 2, false);
|
342
|
-
ctx.stroke();
|
343
|
-
|
344
|
-
// outer light
|
345
|
-
ctx.strokeStyle = rgba(255,255,255,.5);
|
346
|
-
ctx.arc(x, y, rad / 2 - 1, 0, Math.PI * 2, false);
|
347
|
-
ctx.stroke();
|
348
|
-
|
349
|
-
ctx.beginPath();
|
350
|
-
ctx.restore();
|
351
|
-
};
|
@@ -1,133 +0,0 @@
|
|
1
|
-
|
2
|
-
/**
|
3
|
-
* Expose `Confirmation`.
|
4
|
-
*/
|
5
|
-
|
6
|
-
exports.Confirmation = Confirmation;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Return a new `Confirmation` dialog with the given
|
10
|
-
* `title` and `msg`.
|
11
|
-
*
|
12
|
-
* @param {String} title or msg
|
13
|
-
* @param {String} msg
|
14
|
-
* @return {Dialog}
|
15
|
-
* @api public
|
16
|
-
*/
|
17
|
-
|
18
|
-
exports.confirm = function(title, msg){
|
19
|
-
switch (arguments.length) {
|
20
|
-
case 2:
|
21
|
-
return new Confirmation({ title: title, message: msg });
|
22
|
-
case 1:
|
23
|
-
return new Confirmation({ message: title });
|
24
|
-
}
|
25
|
-
};
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Initialize a new `Confirmation` dialog.
|
29
|
-
*
|
30
|
-
* Options:
|
31
|
-
*
|
32
|
-
* - `title` dialog title
|
33
|
-
* - `message` a message to display
|
34
|
-
*
|
35
|
-
* Emits:
|
36
|
-
*
|
37
|
-
* - `cancel` the user pressed cancel or closed the dialog
|
38
|
-
* - `ok` the user clicked ok
|
39
|
-
* - `show` when visible
|
40
|
-
* - `hide` when hidden
|
41
|
-
*
|
42
|
-
* @param {Object} options
|
43
|
-
* @api public
|
44
|
-
*/
|
45
|
-
|
46
|
-
function Confirmation(options) {
|
47
|
-
ui.Dialog.call(this, options);
|
48
|
-
};
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Inherit from `Dialog.prototype`.
|
52
|
-
*/
|
53
|
-
|
54
|
-
Confirmation.prototype = new ui.Dialog;
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Change "cancel" button `text`.
|
58
|
-
*
|
59
|
-
* @param {String} text
|
60
|
-
* @return {Confirmation}
|
61
|
-
* @api public
|
62
|
-
*/
|
63
|
-
|
64
|
-
Confirmation.prototype.cancel = function(text){
|
65
|
-
this.el.find('.cancel').text(text);
|
66
|
-
return this;
|
67
|
-
};
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Change "ok" button `text`.
|
71
|
-
*
|
72
|
-
* @param {String} text
|
73
|
-
* @return {Confirmation}
|
74
|
-
* @api public
|
75
|
-
*/
|
76
|
-
|
77
|
-
Confirmation.prototype.ok = function(text){
|
78
|
-
this.el.find('.ok').text(text);
|
79
|
-
return this;
|
80
|
-
};
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Show the confirmation dialog and invoke `fn(ok)`.
|
84
|
-
*
|
85
|
-
* @param {Function} fn
|
86
|
-
* @return {Confirmation} for chaining
|
87
|
-
* @api public
|
88
|
-
*/
|
89
|
-
|
90
|
-
Confirmation.prototype.show = function(fn){
|
91
|
-
ui.Dialog.prototype.show.call(this);
|
92
|
-
this.el.find('.ok').focus();
|
93
|
-
this.callback = fn || function(){};
|
94
|
-
return this;
|
95
|
-
};
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Render with the given `options`.
|
99
|
-
*
|
100
|
-
* Emits "cancel" event.
|
101
|
-
* Emits "ok" event.
|
102
|
-
*
|
103
|
-
* @param {Object} options
|
104
|
-
* @api public
|
105
|
-
*/
|
106
|
-
|
107
|
-
Confirmation.prototype.render = function(options){
|
108
|
-
ui.Dialog.prototype.render.call(this, options);
|
109
|
-
var self = this
|
110
|
-
, actions = $(html);
|
111
|
-
|
112
|
-
this.el.addClass('confirmation');
|
113
|
-
this.el.append(actions);
|
114
|
-
|
115
|
-
this.on('close', function(){
|
116
|
-
self.emit('cancel');
|
117
|
-
self.callback(false);
|
118
|
-
});
|
119
|
-
|
120
|
-
actions.find('.cancel').click(function(e){
|
121
|
-
e.preventDefault();
|
122
|
-
self.emit('cancel');
|
123
|
-
self.callback(false);
|
124
|
-
self.hide();
|
125
|
-
});
|
126
|
-
|
127
|
-
actions.find('.ok').click(function(e){
|
128
|
-
e.preventDefault();
|
129
|
-
self.emit('ok');
|
130
|
-
self.callback(true);
|
131
|
-
self.hide();
|
132
|
-
});
|
133
|
-
};
|