bootbox-rails 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -22
- data/Rakefile +2 -10
- data/vendor/assets/javascripts/bootbox.js +328 -195
- metadata +3 -3
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# bootbox-rails
|
1
|
+
# bootbox-rails [](http://travis-ci.org/tanraya/bootbox-rails)
|
2
2
|
|
3
3
|
Wrappers for JavaScript alert(), confirm() and other flexible dialogs using Twitter's bootstrap framework for Rails 3.1+
|
4
4
|
|
@@ -44,24 +44,4 @@ Please see http://paynedigital.com/bootbox for full usage instructions, or head
|
|
44
44
|
|
45
45
|
## License
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
Copyright (C) 2011-2012 by http://rocketscience.it <demerest@gmail.com>
|
50
|
-
|
51
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
52
|
-
of this software and associated documentation files (the "Software"), to deal
|
53
|
-
in the Software without restriction, including without limitation the rights
|
54
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
55
|
-
copies of the Software, and to permit persons to whom the Software is
|
56
|
-
furnished to do so, subject to the following conditions:
|
57
|
-
|
58
|
-
The above copyright notice and this permission notice shall be included in
|
59
|
-
all copies or substantial portions of the Software.
|
60
|
-
|
61
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
62
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
63
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
64
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
65
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
66
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
67
|
-
THE SOFTWARE
|
47
|
+
[The MIT License](https://github.com/tanraya/bootbox-rails/blob/master/MIT-LICENSE)
|
data/Rakefile
CHANGED
@@ -12,16 +12,8 @@ rescue LoadError
|
|
12
12
|
RDoc::Task = Rake::RDocTask
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
rdoc.title = 'BootboxRails'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
# Run tests by default
|
16
|
+
task :default => :spec
|
25
17
|
|
26
18
|
Bundler::GemHelper.install_tasks
|
27
19
|
|
@@ -1,84 +1,26 @@
|
|
1
1
|
/**
|
2
|
-
* bootbox.js
|
2
|
+
* bootbox.js v3.2.0
|
3
3
|
*
|
4
4
|
* http://bootboxjs.com/license.txt
|
5
5
|
*/
|
6
|
-
var bootbox = window.bootbox || (function($) {
|
6
|
+
var bootbox = window.bootbox || (function(document, $) {
|
7
|
+
/*jshint scripturl:true sub:true */
|
7
8
|
|
8
9
|
var _locale = 'en',
|
9
10
|
_defaultLocale = 'en',
|
10
11
|
_animate = true,
|
11
12
|
_backdrop = 'static',
|
13
|
+
_defaultHref = 'javascript:;',
|
14
|
+
_classes = '',
|
15
|
+
_btnClasses = {},
|
12
16
|
_icons = {},
|
13
17
|
/* last var should always be the public object we'll return */
|
14
18
|
that = {};
|
15
19
|
|
20
|
+
|
16
21
|
/**
|
17
|
-
*
|
18
|
-
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
22
|
+
* public API
|
19
23
|
*/
|
20
|
-
var _locales = {
|
21
|
-
'en' : {
|
22
|
-
OK : 'OK',
|
23
|
-
CANCEL : 'Cancel',
|
24
|
-
CONFIRM : 'OK'
|
25
|
-
},
|
26
|
-
'fr' : {
|
27
|
-
OK : 'OK',
|
28
|
-
CANCEL : 'Annuler',
|
29
|
-
CONFIRM : 'D\'accord'
|
30
|
-
},
|
31
|
-
'de' : {
|
32
|
-
OK : 'OK',
|
33
|
-
CANCEL : 'Abbrechen',
|
34
|
-
CONFIRM : 'Akzeptieren'
|
35
|
-
},
|
36
|
-
'es' : {
|
37
|
-
OK : 'OK',
|
38
|
-
CANCEL : 'Cancelar',
|
39
|
-
CONFIRM : 'Aceptar'
|
40
|
-
},
|
41
|
-
'br' : {
|
42
|
-
OK : 'OK',
|
43
|
-
CANCEL : 'Cancelar',
|
44
|
-
CONFIRM : 'Sim'
|
45
|
-
},
|
46
|
-
'nl' : {
|
47
|
-
OK : 'OK',
|
48
|
-
CANCEL : 'Annuleren',
|
49
|
-
CONFIRM : 'Accepteren'
|
50
|
-
},
|
51
|
-
'ru' : {
|
52
|
-
OK : 'OK',
|
53
|
-
CANCEL : 'Отмена',
|
54
|
-
CONFIRM : 'Применить'
|
55
|
-
},
|
56
|
-
'it' : {
|
57
|
-
OK : 'OK',
|
58
|
-
CANCEL : 'Annulla',
|
59
|
-
CONFIRM : 'Conferma'
|
60
|
-
}
|
61
|
-
};
|
62
|
-
|
63
|
-
function _translate(str, locale) {
|
64
|
-
// we assume if no target locale is probided then we should take it from current setting
|
65
|
-
if (locale == null) {
|
66
|
-
locale = _locale;
|
67
|
-
}
|
68
|
-
if (typeof _locales[locale][str] == 'string') {
|
69
|
-
return _locales[locale][str];
|
70
|
-
}
|
71
|
-
|
72
|
-
// if we couldn't find a lookup then try and fallback to a default translation
|
73
|
-
|
74
|
-
if (locale != _defaultLocale) {
|
75
|
-
return _translate(str, _defaultLocale);
|
76
|
-
}
|
77
|
-
|
78
|
-
// if we can't do anything then bail out with whatever string was passed in - last resort
|
79
|
-
return str;
|
80
|
-
}
|
81
|
-
|
82
24
|
that.setLocale = function(locale) {
|
83
25
|
for (var i in _locales) {
|
84
26
|
if (i == locale) {
|
@@ -87,23 +29,30 @@ var bootbox = window.bootbox || (function($) {
|
|
87
29
|
}
|
88
30
|
}
|
89
31
|
throw new Error('Invalid locale: '+locale);
|
90
|
-
}
|
32
|
+
};
|
91
33
|
|
92
34
|
that.addLocale = function(locale, translations) {
|
93
|
-
if (typeof _locales[locale]
|
35
|
+
if (typeof _locales[locale] === 'undefined') {
|
94
36
|
_locales[locale] = {};
|
95
37
|
}
|
96
38
|
for (var str in translations) {
|
97
39
|
_locales[locale][str] = translations[str];
|
98
40
|
}
|
99
|
-
}
|
41
|
+
};
|
100
42
|
|
101
43
|
that.setIcons = function(icons) {
|
102
44
|
_icons = icons;
|
103
|
-
if (typeof _icons !== 'object' || _icons
|
45
|
+
if (typeof _icons !== 'object' || _icons === null) {
|
104
46
|
_icons = {};
|
105
47
|
}
|
106
|
-
}
|
48
|
+
};
|
49
|
+
|
50
|
+
that.setBtnClasses = function(btnClasses) {
|
51
|
+
_btnClasses = btnClasses;
|
52
|
+
if (typeof _btnClasses !== 'object' || _btnClasses === null) {
|
53
|
+
_btnClasses = {};
|
54
|
+
}
|
55
|
+
};
|
107
56
|
|
108
57
|
that.alert = function(/*str, label, cb*/) {
|
109
58
|
var str = "",
|
@@ -132,17 +81,20 @@ var bootbox = window.bootbox || (function($) {
|
|
132
81
|
break;
|
133
82
|
default:
|
134
83
|
throw new Error("Incorrect number of arguments: expected 1-3");
|
135
|
-
break;
|
136
84
|
}
|
137
85
|
|
138
86
|
return that.dialog(str, {
|
139
|
-
|
140
|
-
"
|
87
|
+
// only button (ok)
|
88
|
+
"label" : label,
|
89
|
+
"icon" : _icons.OK,
|
90
|
+
"class" : _btnClasses.OK,
|
141
91
|
"callback": cb
|
142
92
|
}, {
|
143
|
-
|
93
|
+
// ensure that the escape key works; either invoking the user's
|
94
|
+
// callback or true to just close the dialog
|
95
|
+
"onEscape": cb || true
|
144
96
|
});
|
145
|
-
}
|
97
|
+
};
|
146
98
|
|
147
99
|
that.confirm = function(/*str, labelCancel, labelOk, cb*/) {
|
148
100
|
var str = "",
|
@@ -179,27 +131,37 @@ var bootbox = window.bootbox || (function($) {
|
|
179
131
|
break;
|
180
132
|
default:
|
181
133
|
throw new Error("Incorrect number of arguments: expected 1-4");
|
182
|
-
break;
|
183
134
|
}
|
184
135
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
"callback": function() {
|
189
|
-
if (typeof cb == 'function') {
|
190
|
-
cb(false);
|
191
|
-
}
|
136
|
+
var cancelCallback = function() {
|
137
|
+
if (typeof cb === 'function') {
|
138
|
+
return cb(false);
|
192
139
|
}
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
cb(true);
|
199
|
-
}
|
140
|
+
};
|
141
|
+
|
142
|
+
var confirmCallback = function() {
|
143
|
+
if (typeof cb === 'function') {
|
144
|
+
return cb(true);
|
200
145
|
}
|
201
|
-
}
|
202
|
-
|
146
|
+
};
|
147
|
+
|
148
|
+
return that.dialog(str, [{
|
149
|
+
// first button (cancel)
|
150
|
+
"label" : labelCancel,
|
151
|
+
"icon" : _icons.CANCEL,
|
152
|
+
"class" : _btnClasses.CANCEL,
|
153
|
+
"callback": cancelCallback
|
154
|
+
}, {
|
155
|
+
// second button (confirm)
|
156
|
+
"label" : labelOk,
|
157
|
+
"icon" : _icons.CONFIRM,
|
158
|
+
"class" : _btnClasses.CONFIRM,
|
159
|
+
"callback": confirmCallback
|
160
|
+
}], {
|
161
|
+
// escape key bindings
|
162
|
+
"onEscape": cancelCallback
|
163
|
+
});
|
164
|
+
};
|
203
165
|
|
204
166
|
that.prompt = function(/*str, labelCancel, labelOk, cb, defaultVal*/) {
|
205
167
|
var str = "",
|
@@ -244,7 +206,6 @@ var bootbox = window.bootbox || (function($) {
|
|
244
206
|
break;
|
245
207
|
default:
|
246
208
|
throw new Error("Incorrect number of arguments: expected 1-5");
|
247
|
-
break;
|
248
209
|
}
|
249
210
|
|
250
211
|
var header = str;
|
@@ -253,28 +214,45 @@ var bootbox = window.bootbox || (function($) {
|
|
253
214
|
var form = $("<form></form>");
|
254
215
|
form.append("<input autocomplete=off type=text value='" + defaultVal + "' />");
|
255
216
|
|
256
|
-
var
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
cb(null);
|
262
|
-
}
|
217
|
+
var cancelCallback = function() {
|
218
|
+
if (typeof cb === 'function') {
|
219
|
+
// yep, native prompts dismiss with null, whereas native
|
220
|
+
// confirms dismiss with false...
|
221
|
+
return cb(null);
|
263
222
|
}
|
264
|
-
}
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
cb(
|
270
|
-
form.find("input[type=text]").val()
|
271
|
-
);
|
272
|
-
}
|
223
|
+
};
|
224
|
+
|
225
|
+
var confirmCallback = function() {
|
226
|
+
if (typeof cb === 'function') {
|
227
|
+
return cb(form.find("input[type=text]").val());
|
273
228
|
}
|
229
|
+
};
|
230
|
+
|
231
|
+
var div = that.dialog(form, [{
|
232
|
+
// first button (cancel)
|
233
|
+
"label" : labelCancel,
|
234
|
+
"icon" : _icons.CANCEL,
|
235
|
+
"class" : _btnClasses.CANCEL,
|
236
|
+
"callback": cancelCallback
|
237
|
+
}, {
|
238
|
+
// second button (confirm)
|
239
|
+
"label" : labelOk,
|
240
|
+
"icon" : _icons.CONFIRM,
|
241
|
+
"class" : _btnClasses.CONFIRM,
|
242
|
+
"callback": confirmCallback
|
274
243
|
}], {
|
275
|
-
|
244
|
+
// prompts need a few extra options
|
245
|
+
"header" : header,
|
246
|
+
// explicitly tell dialog NOT to show the dialog...
|
247
|
+
"show" : false,
|
248
|
+
"onEscape": cancelCallback
|
276
249
|
});
|
277
250
|
|
251
|
+
// ... the reason the prompt needs to be hidden is because we need
|
252
|
+
// to bind our own "shown" handler, after creating the modal but
|
253
|
+
// before any show(n) events are triggered
|
254
|
+
// @see https://github.com/makeusabrew/bootbox/issues/69
|
255
|
+
|
278
256
|
div.on("shown", function() {
|
279
257
|
form.find("input[type=text]").focus();
|
280
258
|
|
@@ -286,61 +264,21 @@ var bootbox = window.bootbox || (function($) {
|
|
286
264
|
});
|
287
265
|
});
|
288
266
|
|
289
|
-
|
290
|
-
}
|
291
|
-
|
292
|
-
that.modal = function(/*str, label, options*/) {
|
293
|
-
var str;
|
294
|
-
var label;
|
295
|
-
var options;
|
296
|
-
|
297
|
-
var defaultOptions = {
|
298
|
-
"onEscape": null,
|
299
|
-
"keyboard": true,
|
300
|
-
"backdrop": _backdrop
|
301
|
-
};
|
267
|
+
div.modal("show");
|
302
268
|
|
303
|
-
|
304
|
-
|
305
|
-
str = arguments[0];
|
306
|
-
break;
|
307
|
-
case 2:
|
308
|
-
str = arguments[0];
|
309
|
-
if (typeof arguments[1] == 'object') {
|
310
|
-
options = arguments[1];
|
311
|
-
} else {
|
312
|
-
label = arguments[1];
|
313
|
-
}
|
314
|
-
break;
|
315
|
-
case 3:
|
316
|
-
str = arguments[0];
|
317
|
-
label = arguments[1];
|
318
|
-
options = arguments[2];
|
319
|
-
break;
|
320
|
-
default:
|
321
|
-
throw new Error("Incorrect number of arguments: expected 1-3");
|
322
|
-
break;
|
323
|
-
}
|
269
|
+
return div;
|
270
|
+
};
|
324
271
|
|
325
|
-
|
272
|
+
that.dialog = function(str, handlers, options) {
|
273
|
+
var buttons = "",
|
274
|
+
callbacks = [];
|
326
275
|
|
327
|
-
if (
|
328
|
-
options =
|
329
|
-
} else {
|
330
|
-
options = defaultOptions;
|
276
|
+
if (!options) {
|
277
|
+
options = {};
|
331
278
|
}
|
332
279
|
|
333
|
-
return that.dialog(str, [], options);
|
334
|
-
}
|
335
|
-
|
336
|
-
that.dialog = function(str, handlers, options) {
|
337
|
-
var hideSource = null,
|
338
|
-
buttons = "",
|
339
|
-
callbacks = [],
|
340
|
-
options = options || {};
|
341
|
-
|
342
280
|
// check for single object and convert to array if necessary
|
343
|
-
if (handlers
|
281
|
+
if (typeof handlers === 'undefined') {
|
344
282
|
handlers = [];
|
345
283
|
} else if (typeof handlers.length == 'undefined') {
|
346
284
|
handlers = [handlers];
|
@@ -349,6 +287,7 @@ var bootbox = window.bootbox || (function($) {
|
|
349
287
|
var i = handlers.length;
|
350
288
|
while (i--) {
|
351
289
|
var label = null,
|
290
|
+
href = null,
|
352
291
|
_class = null,
|
353
292
|
icon = '',
|
354
293
|
callback = null;
|
@@ -398,7 +337,14 @@ var bootbox = window.bootbox || (function($) {
|
|
398
337
|
icon = "<i class='"+handlers[i]['icon']+"'></i> ";
|
399
338
|
}
|
400
339
|
|
401
|
-
|
340
|
+
if (handlers[i]['href']) {
|
341
|
+
href = handlers[i]['href'];
|
342
|
+
}
|
343
|
+
else {
|
344
|
+
href = _defaultHref;
|
345
|
+
}
|
346
|
+
|
347
|
+
buttons = "<a data-handler='"+i+"' class='btn "+_class+"' href='" + href + "'>"+icon+""+label+"</a>" + buttons;
|
402
348
|
|
403
349
|
callbacks[i] = callback;
|
404
350
|
}
|
@@ -406,13 +352,15 @@ var bootbox = window.bootbox || (function($) {
|
|
406
352
|
// @see https://github.com/makeusabrew/bootbox/issues/46#issuecomment-8235302
|
407
353
|
// and https://github.com/twitter/bootstrap/issues/4474
|
408
354
|
// for an explanation of the inline overflow: hidden
|
355
|
+
// @see https://github.com/twitter/bootstrap/issues/4854
|
356
|
+
// for an explanation of tabIndex=-1
|
409
357
|
|
410
|
-
var parts = ["<div class='bootbox modal' style='overflow:hidden;'>"];
|
358
|
+
var parts = ["<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>"];
|
411
359
|
|
412
360
|
if (options['header']) {
|
413
361
|
var closeButton = '';
|
414
362
|
if (typeof options['headerCloseButton'] == 'undefined' || options['headerCloseButton']) {
|
415
|
-
closeButton = "<a href='
|
363
|
+
closeButton = "<a href='"+_defaultHref+"' class='close'>×</a>";
|
416
364
|
}
|
417
365
|
|
418
366
|
parts.push("<div class='modal-header'>"+closeButton+"<h3>"+options['header']+"</h3></div>");
|
@@ -422,7 +370,7 @@ var bootbox = window.bootbox || (function($) {
|
|
422
370
|
parts.push("<div class='modal-body'></div>");
|
423
371
|
|
424
372
|
if (buttons) {
|
425
|
-
parts.push("<div class='modal-footer'>"+buttons+"</div>")
|
373
|
+
parts.push("<div class='modal-footer'>"+buttons+"</div>");
|
426
374
|
}
|
427
375
|
|
428
376
|
parts.push("</div>");
|
@@ -436,73 +384,258 @@ var bootbox = window.bootbox || (function($) {
|
|
436
384
|
div.addClass("fade");
|
437
385
|
}
|
438
386
|
|
439
|
-
|
440
|
-
|
387
|
+
var optionalClasses = (typeof options.classes === 'undefined') ? _classes : options.classes;
|
388
|
+
if (optionalClasses) {
|
389
|
+
div.addClass(optionalClasses);
|
390
|
+
}
|
441
391
|
|
442
|
-
|
443
|
-
|
444
|
-
|
392
|
+
// now we've built up the div properly we can inject the content whether it was a string or a jQuery object
|
393
|
+
div.find(".modal-body").html(str);
|
394
|
+
|
395
|
+
function onCancel(source) {
|
396
|
+
// for now source is unused, but it will be in future
|
397
|
+
var hideModal = null;
|
398
|
+
if (typeof options.onEscape === 'function') {
|
399
|
+
// @see https://github.com/makeusabrew/bootbox/issues/91
|
400
|
+
hideModal = options.onEscape();
|
401
|
+
}
|
445
402
|
|
446
|
-
|
447
|
-
|
448
|
-
typeof options.onEscape == 'function') {
|
449
|
-
options.onEscape();
|
403
|
+
if (hideModal !== false) {
|
404
|
+
div.modal('hide');
|
450
405
|
}
|
451
|
-
}
|
406
|
+
}
|
452
407
|
|
453
408
|
// hook into the modal's keyup trigger to check for the escape key
|
454
|
-
|
455
|
-
|
456
|
-
|
409
|
+
div.on('keyup.dismiss.modal', function(e) {
|
410
|
+
// any truthy value passed to onEscape will dismiss the dialog
|
411
|
+
// as long as the onEscape function (if defined) doesn't prevent it
|
412
|
+
if (e.which === 27 && options.onEscape) {
|
413
|
+
onCancel('escape');
|
457
414
|
}
|
458
415
|
});
|
459
416
|
|
460
|
-
//
|
461
|
-
div.
|
462
|
-
|
417
|
+
// handle close buttons too
|
418
|
+
div.on('click', 'a.close', function(e) {
|
419
|
+
e.preventDefault();
|
420
|
+
onCancel('close');
|
421
|
+
});
|
422
|
+
|
423
|
+
// well, *if* we have a primary - give the first dom element focus
|
424
|
+
div.on('shown', function() {
|
425
|
+
div.find("a.btn-primary:first").focus();
|
426
|
+
});
|
427
|
+
|
428
|
+
div.on('hidden', function() {
|
429
|
+
div.remove();
|
463
430
|
});
|
464
431
|
|
465
432
|
// wire up button handlers
|
466
|
-
div.on('click', '.modal-footer a
|
433
|
+
div.on('click', '.modal-footer a', function(e) {
|
434
|
+
|
467
435
|
var handler = $(this).data("handler"),
|
468
436
|
cb = callbacks[handler],
|
469
437
|
hideModal = null;
|
470
438
|
|
471
|
-
|
439
|
+
// sort of @see https://github.com/makeusabrew/bootbox/pull/68 - heavily adapted
|
440
|
+
// if we've got a custom href attribute, all bets are off
|
441
|
+
if (typeof handler !== 'undefined' &&
|
442
|
+
typeof handlers[handler]['href'] !== 'undefined') {
|
443
|
+
|
444
|
+
return;
|
445
|
+
}
|
446
|
+
|
447
|
+
e.preventDefault();
|
448
|
+
|
449
|
+
if (typeof cb === 'function') {
|
472
450
|
hideModal = cb();
|
473
451
|
}
|
474
|
-
|
475
|
-
|
476
|
-
|
452
|
+
|
453
|
+
// the only way hideModal *will* be false is if a callback exists and
|
454
|
+
// returns it as a value. in those situations, don't hide the dialog
|
455
|
+
// @see https://github.com/makeusabrew/bootbox/pull/25
|
456
|
+
if (hideModal !== false) {
|
477
457
|
div.modal("hide");
|
478
458
|
}
|
479
459
|
});
|
480
460
|
|
481
|
-
|
482
|
-
options.keyboard = (typeof options.onEscape == 'function');
|
483
|
-
}
|
484
|
-
|
461
|
+
// stick the modal right at the bottom of the main body out of the way
|
485
462
|
$("body").append(div);
|
486
463
|
|
487
464
|
div.modal({
|
488
|
-
|
489
|
-
|
465
|
+
// unless explicitly overridden take whatever our default backdrop value is
|
466
|
+
backdrop : (typeof options.backdrop === 'undefined') ? _backdrop : options.backdrop,
|
467
|
+
// ignore bootstrap's keyboard options; we'll handle this ourselves (more fine-grained control)
|
468
|
+
keyboard : false,
|
469
|
+
// @ see https://github.com/makeusabrew/bootbox/issues/69
|
470
|
+
// we *never* want the modal to be shown before we can bind stuff to it
|
471
|
+
// this method can also take a 'show' option, but we'll only use that
|
472
|
+
// later if we need to
|
473
|
+
show : false
|
490
474
|
});
|
491
475
|
|
476
|
+
// @see https://github.com/makeusabrew/bootbox/issues/64
|
477
|
+
// @see https://github.com/makeusabrew/bootbox/issues/60
|
478
|
+
// ...caused by...
|
479
|
+
// @see https://github.com/twitter/bootstrap/issues/4781
|
480
|
+
div.on("show", function(e) {
|
481
|
+
$(document).off("focusin.modal");
|
482
|
+
});
|
483
|
+
|
484
|
+
if (typeof options.show === 'undefined' || options.show === true) {
|
485
|
+
div.modal("show");
|
486
|
+
}
|
487
|
+
|
492
488
|
return div;
|
493
|
-
}
|
489
|
+
};
|
490
|
+
|
491
|
+
/**
|
492
|
+
* #modal is deprecated in v3; it can still be used but no guarantees are
|
493
|
+
* made - have never been truly convinced of its merit but perhaps just
|
494
|
+
* needs a tidyup and some TLC
|
495
|
+
*/
|
496
|
+
that.modal = function(/*str, label, options*/) {
|
497
|
+
var str;
|
498
|
+
var label;
|
499
|
+
var options;
|
500
|
+
|
501
|
+
var defaultOptions = {
|
502
|
+
"onEscape": null,
|
503
|
+
"keyboard": true,
|
504
|
+
"backdrop": _backdrop
|
505
|
+
};
|
506
|
+
|
507
|
+
switch (arguments.length) {
|
508
|
+
case 1:
|
509
|
+
str = arguments[0];
|
510
|
+
break;
|
511
|
+
case 2:
|
512
|
+
str = arguments[0];
|
513
|
+
if (typeof arguments[1] == 'object') {
|
514
|
+
options = arguments[1];
|
515
|
+
} else {
|
516
|
+
label = arguments[1];
|
517
|
+
}
|
518
|
+
break;
|
519
|
+
case 3:
|
520
|
+
str = arguments[0];
|
521
|
+
label = arguments[1];
|
522
|
+
options = arguments[2];
|
523
|
+
break;
|
524
|
+
default:
|
525
|
+
throw new Error("Incorrect number of arguments: expected 1-3");
|
526
|
+
}
|
527
|
+
|
528
|
+
defaultOptions['header'] = label;
|
529
|
+
|
530
|
+
if (typeof options == 'object') {
|
531
|
+
options = $.extend(defaultOptions, options);
|
532
|
+
} else {
|
533
|
+
options = defaultOptions;
|
534
|
+
}
|
535
|
+
|
536
|
+
return that.dialog(str, [], options);
|
537
|
+
};
|
538
|
+
|
494
539
|
|
495
540
|
that.hideAll = function() {
|
496
541
|
$(".bootbox").modal("hide");
|
497
|
-
}
|
542
|
+
};
|
498
543
|
|
499
544
|
that.animate = function(animate) {
|
500
545
|
_animate = animate;
|
501
|
-
}
|
546
|
+
};
|
502
547
|
|
503
548
|
that.backdrop = function(backdrop) {
|
504
549
|
_backdrop = backdrop;
|
550
|
+
};
|
551
|
+
|
552
|
+
that.classes = function(classes) {
|
553
|
+
_classes = classes;
|
554
|
+
};
|
555
|
+
|
556
|
+
/**
|
557
|
+
* private API
|
558
|
+
*/
|
559
|
+
|
560
|
+
/**
|
561
|
+
* standard locales. Please add more according to ISO 639-1 standard. Multiple language variants are
|
562
|
+
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
563
|
+
*/
|
564
|
+
var _locales = {
|
565
|
+
'br' : {
|
566
|
+
OK : 'OK',
|
567
|
+
CANCEL : 'Cancelar',
|
568
|
+
CONFIRM : 'Sim'
|
569
|
+
},
|
570
|
+
'da' : {
|
571
|
+
OK : 'OK',
|
572
|
+
CANCEL : 'Annuller',
|
573
|
+
CONFIRM : 'Accepter'
|
574
|
+
},
|
575
|
+
'de' : {
|
576
|
+
OK : 'OK',
|
577
|
+
CANCEL : 'Abbrechen',
|
578
|
+
CONFIRM : 'Akzeptieren'
|
579
|
+
},
|
580
|
+
'en' : {
|
581
|
+
OK : 'OK',
|
582
|
+
CANCEL : 'Cancel',
|
583
|
+
CONFIRM : 'OK'
|
584
|
+
},
|
585
|
+
'es' : {
|
586
|
+
OK : 'OK',
|
587
|
+
CANCEL : 'Cancelar',
|
588
|
+
CONFIRM : 'Aceptar'
|
589
|
+
},
|
590
|
+
'fr' : {
|
591
|
+
OK : 'OK',
|
592
|
+
CANCEL : 'Annuler',
|
593
|
+
CONFIRM : 'D\'accord'
|
594
|
+
},
|
595
|
+
'it' : {
|
596
|
+
OK : 'OK',
|
597
|
+
CANCEL : 'Annulla',
|
598
|
+
CONFIRM : 'Conferma'
|
599
|
+
},
|
600
|
+
'nl' : {
|
601
|
+
OK : 'OK',
|
602
|
+
CANCEL : 'Annuleren',
|
603
|
+
CONFIRM : 'Accepteren'
|
604
|
+
},
|
605
|
+
'pl' : {
|
606
|
+
OK : 'OK',
|
607
|
+
CANCEL : 'Anuluj',
|
608
|
+
CONFIRM : 'Potwierdź'
|
609
|
+
},
|
610
|
+
'ru' : {
|
611
|
+
OK : 'OK',
|
612
|
+
CANCEL : 'Отмена',
|
613
|
+
CONFIRM : 'Применить'
|
614
|
+
},
|
615
|
+
};
|
616
|
+
|
617
|
+
function _translate(str, locale) {
|
618
|
+
// we assume if no target locale is probided then we should take it from current setting
|
619
|
+
if (typeof locale === 'undefined') {
|
620
|
+
locale = _locale;
|
621
|
+
}
|
622
|
+
if (typeof _locales[locale][str] === 'string') {
|
623
|
+
return _locales[locale][str];
|
624
|
+
}
|
625
|
+
|
626
|
+
// if we couldn't find a lookup then try and fallback to a default translation
|
627
|
+
|
628
|
+
if (locale != _defaultLocale) {
|
629
|
+
return _translate(str, _defaultLocale);
|
630
|
+
}
|
631
|
+
|
632
|
+
// if we can't do anything then bail out with whatever string was passed in - last resort
|
633
|
+
return str;
|
505
634
|
}
|
506
635
|
|
507
636
|
return that;
|
508
|
-
|
637
|
+
|
638
|
+
}(document, window.jQuery));
|
639
|
+
|
640
|
+
// @see https://github.com/makeusabrew/bootbox/issues/71
|
641
|
+
window.bootbox = bootbox;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootbox-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -83,9 +83,9 @@ executables: []
|
|
83
83
|
extensions: []
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
|
+
- lib/bootbox-rails/engine.rb
|
86
87
|
- lib/bootbox-rails.rb
|
87
88
|
- lib/tasks/bootbox-rails_tasks.rake
|
88
|
-
- lib/bootbox-rails/engine.rb
|
89
89
|
- vendor/assets/javascripts/bootbox.js
|
90
90
|
- MIT-LICENSE
|
91
91
|
- Rakefile
|