bootbox-rails 0.0.1
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/Gemfile +20 -0
- data/MIT-LICENSE +20 -0
- data/README.md +67 -0
- data/Rakefile +27 -0
- data/lib/bootbox-rails.rb +5 -0
- data/lib/bootbox-rails/engine.rb +4 -0
- data/lib/tasks/bootbox-rails_tasks.rake +4 -0
- data/vendor/assets/javascripts/bootbox.js +508 -0
- metadata +119 -0
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
gem 'sqlite3'
|
5
|
+
|
6
|
+
group :assets do
|
7
|
+
gem 'sass-rails', ">= 3.1.0"
|
8
|
+
gem 'coffee-rails', ">= 3.1.0"
|
9
|
+
gem 'uglifier'
|
10
|
+
gem 'bootstrap-sass', '2.1.0.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'jquery-rails'
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'turn', :require => false
|
17
|
+
gem 'rspec-rails'
|
18
|
+
gem 'capybara'
|
19
|
+
gem 'capybara-webkit'
|
20
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 http://rocketscience.it <demerest@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# bootbox-rails
|
2
|
+
|
3
|
+
Wrappers for JavaScript alert(), confirm() and other flexible dialogs using Twitter's bootstrap framework for Rails 3.1+
|
4
|
+
|
5
|
+
Check out how to use bootbox.js at http://bootboxjs.com/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
First, put this line in your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bootbox-rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
_Don't forget to add `jquery-rails` gem into your `Gemfile`. Also you may use very handy `bootstrap-sass` gem to add full stack of Twitter Bootstrap into your app._
|
16
|
+
|
17
|
+
Then run `bundle install` to update your application's bundle.
|
18
|
+
|
19
|
+
Now you need to edit your `app/assets/javascripts/application.js` file and add the following line:
|
20
|
+
|
21
|
+
```javascript
|
22
|
+
//= require bootbox
|
23
|
+
```
|
24
|
+
|
25
|
+
And you're done!
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Now you able to use modals like this:
|
30
|
+
|
31
|
+
``` html
|
32
|
+
<a href="#" id="link">Click me!</a>
|
33
|
+
|
34
|
+
<script>
|
35
|
+
$(function() {
|
36
|
+
$('#link').click(function() {
|
37
|
+
bootbox.alert("Hello world!");
|
38
|
+
})
|
39
|
+
})
|
40
|
+
</script>
|
41
|
+
```
|
42
|
+
|
43
|
+
Please see http://paynedigital.com/bootbox for full usage instructions, or head over to http://bootboxjs.com for a demo page
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
(The MIT License)
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
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
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,508 @@
|
|
1
|
+
/**
|
2
|
+
* bootbox.js v2.4.2
|
3
|
+
*
|
4
|
+
* http://bootboxjs.com/license.txt
|
5
|
+
*/
|
6
|
+
var bootbox = window.bootbox || (function($) {
|
7
|
+
|
8
|
+
var _locale = 'en',
|
9
|
+
_defaultLocale = 'en',
|
10
|
+
_animate = true,
|
11
|
+
_backdrop = 'static',
|
12
|
+
_icons = {},
|
13
|
+
/* last var should always be the public object we'll return */
|
14
|
+
that = {};
|
15
|
+
|
16
|
+
/**
|
17
|
+
* standard locales. Please add more according to ISO 639-1 standard. Multiple language variants are
|
18
|
+
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
19
|
+
*/
|
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
|
+
that.setLocale = function(locale) {
|
83
|
+
for (var i in _locales) {
|
84
|
+
if (i == locale) {
|
85
|
+
_locale = locale;
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
throw new Error('Invalid locale: '+locale);
|
90
|
+
}
|
91
|
+
|
92
|
+
that.addLocale = function(locale, translations) {
|
93
|
+
if (typeof _locales[locale] == 'undefined') {
|
94
|
+
_locales[locale] = {};
|
95
|
+
}
|
96
|
+
for (var str in translations) {
|
97
|
+
_locales[locale][str] = translations[str];
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
that.setIcons = function(icons) {
|
102
|
+
_icons = icons;
|
103
|
+
if (typeof _icons !== 'object' || _icons == null) {
|
104
|
+
_icons = {};
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
that.alert = function(/*str, label, cb*/) {
|
109
|
+
var str = "",
|
110
|
+
label = _translate('OK'),
|
111
|
+
cb = null;
|
112
|
+
|
113
|
+
switch (arguments.length) {
|
114
|
+
case 1:
|
115
|
+
// no callback, default button label
|
116
|
+
str = arguments[0];
|
117
|
+
break;
|
118
|
+
case 2:
|
119
|
+
// callback *or* custom button label dependent on type
|
120
|
+
str = arguments[0];
|
121
|
+
if (typeof arguments[1] == 'function') {
|
122
|
+
cb = arguments[1];
|
123
|
+
} else {
|
124
|
+
label = arguments[1];
|
125
|
+
}
|
126
|
+
break;
|
127
|
+
case 3:
|
128
|
+
// callback and custom button label
|
129
|
+
str = arguments[0];
|
130
|
+
label = arguments[1];
|
131
|
+
cb = arguments[2];
|
132
|
+
break;
|
133
|
+
default:
|
134
|
+
throw new Error("Incorrect number of arguments: expected 1-3");
|
135
|
+
break;
|
136
|
+
}
|
137
|
+
|
138
|
+
return that.dialog(str, {
|
139
|
+
"label": label,
|
140
|
+
"icon" : _icons.OK,
|
141
|
+
"callback": cb
|
142
|
+
}, {
|
143
|
+
"onEscape": cb
|
144
|
+
});
|
145
|
+
}
|
146
|
+
|
147
|
+
that.confirm = function(/*str, labelCancel, labelOk, cb*/) {
|
148
|
+
var str = "",
|
149
|
+
labelCancel = _translate('CANCEL'),
|
150
|
+
labelOk = _translate('CONFIRM'),
|
151
|
+
cb = null;
|
152
|
+
|
153
|
+
switch (arguments.length) {
|
154
|
+
case 1:
|
155
|
+
str = arguments[0];
|
156
|
+
break;
|
157
|
+
case 2:
|
158
|
+
str = arguments[0];
|
159
|
+
if (typeof arguments[1] == 'function') {
|
160
|
+
cb = arguments[1];
|
161
|
+
} else {
|
162
|
+
labelCancel = arguments[1];
|
163
|
+
}
|
164
|
+
break;
|
165
|
+
case 3:
|
166
|
+
str = arguments[0];
|
167
|
+
labelCancel = arguments[1];
|
168
|
+
if (typeof arguments[2] == 'function') {
|
169
|
+
cb = arguments[2];
|
170
|
+
} else {
|
171
|
+
labelOk = arguments[2];
|
172
|
+
}
|
173
|
+
break;
|
174
|
+
case 4:
|
175
|
+
str = arguments[0];
|
176
|
+
labelCancel = arguments[1];
|
177
|
+
labelOk = arguments[2];
|
178
|
+
cb = arguments[3];
|
179
|
+
break;
|
180
|
+
default:
|
181
|
+
throw new Error("Incorrect number of arguments: expected 1-4");
|
182
|
+
break;
|
183
|
+
}
|
184
|
+
|
185
|
+
return that.dialog(str, [{
|
186
|
+
"label": labelCancel,
|
187
|
+
"icon" : _icons.CANCEL,
|
188
|
+
"callback": function() {
|
189
|
+
if (typeof cb == 'function') {
|
190
|
+
cb(false);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}, {
|
194
|
+
"label": labelOk,
|
195
|
+
"icon" : _icons.CONFIRM,
|
196
|
+
"callback": function() {
|
197
|
+
if (typeof cb == 'function') {
|
198
|
+
cb(true);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}]);
|
202
|
+
}
|
203
|
+
|
204
|
+
that.prompt = function(/*str, labelCancel, labelOk, cb, defaultVal*/) {
|
205
|
+
var str = "",
|
206
|
+
labelCancel = _translate('CANCEL'),
|
207
|
+
labelOk = _translate('CONFIRM'),
|
208
|
+
cb = null,
|
209
|
+
defaultVal = "";
|
210
|
+
|
211
|
+
switch (arguments.length) {
|
212
|
+
case 1:
|
213
|
+
str = arguments[0];
|
214
|
+
break;
|
215
|
+
case 2:
|
216
|
+
str = arguments[0];
|
217
|
+
if (typeof arguments[1] == 'function') {
|
218
|
+
cb = arguments[1];
|
219
|
+
} else {
|
220
|
+
labelCancel = arguments[1];
|
221
|
+
}
|
222
|
+
break;
|
223
|
+
case 3:
|
224
|
+
str = arguments[0];
|
225
|
+
labelCancel = arguments[1];
|
226
|
+
if (typeof arguments[2] == 'function') {
|
227
|
+
cb = arguments[2];
|
228
|
+
} else {
|
229
|
+
labelOk = arguments[2];
|
230
|
+
}
|
231
|
+
break;
|
232
|
+
case 4:
|
233
|
+
str = arguments[0];
|
234
|
+
labelCancel = arguments[1];
|
235
|
+
labelOk = arguments[2];
|
236
|
+
cb = arguments[3];
|
237
|
+
break;
|
238
|
+
case 5:
|
239
|
+
str = arguments[0];
|
240
|
+
labelCancel = arguments[1];
|
241
|
+
labelOk = arguments[2];
|
242
|
+
cb = arguments[3];
|
243
|
+
defaultVal = arguments[4];
|
244
|
+
break;
|
245
|
+
default:
|
246
|
+
throw new Error("Incorrect number of arguments: expected 1-5");
|
247
|
+
break;
|
248
|
+
}
|
249
|
+
|
250
|
+
var header = str;
|
251
|
+
|
252
|
+
// let's keep a reference to the form object for later
|
253
|
+
var form = $("<form></form>");
|
254
|
+
form.append("<input autocomplete=off type=text value='" + defaultVal + "' />");
|
255
|
+
|
256
|
+
var div = that.dialog(form, [{
|
257
|
+
"label": labelCancel,
|
258
|
+
"icon" : _icons.CANCEL,
|
259
|
+
"callback": function() {
|
260
|
+
if (typeof cb == 'function') {
|
261
|
+
cb(null);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
}, {
|
265
|
+
"label": labelOk,
|
266
|
+
"icon" : _icons.CONFIRM,
|
267
|
+
"callback": function() {
|
268
|
+
if (typeof cb == 'function') {
|
269
|
+
cb(
|
270
|
+
form.find("input[type=text]").val()
|
271
|
+
);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}], {
|
275
|
+
"header": header
|
276
|
+
});
|
277
|
+
|
278
|
+
div.on("shown", function() {
|
279
|
+
form.find("input[type=text]").focus();
|
280
|
+
|
281
|
+
// ensure that submitting the form (e.g. with the enter key)
|
282
|
+
// replicates the behaviour of a normal prompt()
|
283
|
+
form.on("submit", function(e) {
|
284
|
+
e.preventDefault();
|
285
|
+
div.find(".btn-primary").click();
|
286
|
+
});
|
287
|
+
});
|
288
|
+
|
289
|
+
return div;
|
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
|
+
};
|
302
|
+
|
303
|
+
switch (arguments.length) {
|
304
|
+
case 1:
|
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
|
+
}
|
324
|
+
|
325
|
+
defaultOptions['header'] = label;
|
326
|
+
|
327
|
+
if (typeof options == 'object') {
|
328
|
+
options = $.extend(defaultOptions, options);
|
329
|
+
} else {
|
330
|
+
options = defaultOptions;
|
331
|
+
}
|
332
|
+
|
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
|
+
// check for single object and convert to array if necessary
|
343
|
+
if (handlers == null) {
|
344
|
+
handlers = [];
|
345
|
+
} else if (typeof handlers.length == 'undefined') {
|
346
|
+
handlers = [handlers];
|
347
|
+
}
|
348
|
+
|
349
|
+
var i = handlers.length;
|
350
|
+
while (i--) {
|
351
|
+
var label = null,
|
352
|
+
_class = null,
|
353
|
+
icon = '',
|
354
|
+
callback = null;
|
355
|
+
|
356
|
+
if (typeof handlers[i]['label'] == 'undefined' &&
|
357
|
+
typeof handlers[i]['class'] == 'undefined' &&
|
358
|
+
typeof handlers[i]['callback'] == 'undefined') {
|
359
|
+
// if we've got nothing we expect, check for condensed format
|
360
|
+
|
361
|
+
var propCount = 0, // condensed will only match if this == 1
|
362
|
+
property = null; // save the last property we found
|
363
|
+
|
364
|
+
// be nicer to count the properties without this, but don't think it's possible...
|
365
|
+
for (var j in handlers[i]) {
|
366
|
+
property = j;
|
367
|
+
if (++propCount > 1) {
|
368
|
+
// forget it, too many properties
|
369
|
+
break;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
if (propCount == 1 && typeof handlers[i][j] == 'function') {
|
374
|
+
// matches condensed format of label -> function
|
375
|
+
handlers[i]['label'] = property;
|
376
|
+
handlers[i]['callback'] = handlers[i][j];
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
if (typeof handlers[i]['callback']== 'function') {
|
381
|
+
callback = handlers[i]['callback'];
|
382
|
+
}
|
383
|
+
|
384
|
+
if (handlers[i]['class']) {
|
385
|
+
_class = handlers[i]['class'];
|
386
|
+
} else if (i == handlers.length -1 && handlers.length <= 2) {
|
387
|
+
// always add a primary to the main option in a two-button dialog
|
388
|
+
_class = 'btn-primary';
|
389
|
+
}
|
390
|
+
|
391
|
+
if (handlers[i]['label']) {
|
392
|
+
label = handlers[i]['label'];
|
393
|
+
} else {
|
394
|
+
label = "Option "+(i+1);
|
395
|
+
}
|
396
|
+
|
397
|
+
if (handlers[i]['icon']) {
|
398
|
+
icon = "<i class='"+handlers[i]['icon']+"'></i> ";
|
399
|
+
}
|
400
|
+
|
401
|
+
buttons += "<a data-handler='"+i+"' class='btn "+_class+"' href='javascript:;'>"+icon+""+label+"</a>";
|
402
|
+
|
403
|
+
callbacks[i] = callback;
|
404
|
+
}
|
405
|
+
|
406
|
+
// @see https://github.com/makeusabrew/bootbox/issues/46#issuecomment-8235302
|
407
|
+
// and https://github.com/twitter/bootstrap/issues/4474
|
408
|
+
// for an explanation of the inline overflow: hidden
|
409
|
+
|
410
|
+
var parts = ["<div class='bootbox modal' style='overflow:hidden;'>"];
|
411
|
+
|
412
|
+
if (options['header']) {
|
413
|
+
var closeButton = '';
|
414
|
+
if (typeof options['headerCloseButton'] == 'undefined' || options['headerCloseButton']) {
|
415
|
+
closeButton = "<a href='javascript:;' class='close'>×</a>";
|
416
|
+
}
|
417
|
+
|
418
|
+
parts.push("<div class='modal-header'>"+closeButton+"<h3>"+options['header']+"</h3></div>");
|
419
|
+
}
|
420
|
+
|
421
|
+
// push an empty body into which we'll inject the proper content later
|
422
|
+
parts.push("<div class='modal-body'></div>");
|
423
|
+
|
424
|
+
if (buttons) {
|
425
|
+
parts.push("<div class='modal-footer'>"+buttons+"</div>")
|
426
|
+
}
|
427
|
+
|
428
|
+
parts.push("</div>");
|
429
|
+
|
430
|
+
var div = $(parts.join("\n"));
|
431
|
+
|
432
|
+
// check whether we should fade in/out
|
433
|
+
var shouldFade = (typeof options.animate === 'undefined') ? _animate : options.animate;
|
434
|
+
|
435
|
+
if (shouldFade) {
|
436
|
+
div.addClass("fade");
|
437
|
+
}
|
438
|
+
|
439
|
+
// now we've built up the div properly we can inject the content whether it was a string or a jQuery object
|
440
|
+
$(".modal-body", div).html(str);
|
441
|
+
|
442
|
+
div.bind('hidden', function() {
|
443
|
+
div.remove();
|
444
|
+
});
|
445
|
+
|
446
|
+
div.bind('hide', function() {
|
447
|
+
if (hideSource == 'escape' &&
|
448
|
+
typeof options.onEscape == 'function') {
|
449
|
+
options.onEscape();
|
450
|
+
}
|
451
|
+
});
|
452
|
+
|
453
|
+
// hook into the modal's keyup trigger to check for the escape key
|
454
|
+
$(document).bind('keyup.modal', function ( e ) {
|
455
|
+
if (e.which == 27) {
|
456
|
+
hideSource = 'escape';
|
457
|
+
}
|
458
|
+
});
|
459
|
+
|
460
|
+
// well, *if* we have a primary - give the last dom element (first displayed) focus
|
461
|
+
div.bind('shown', function() {
|
462
|
+
$("a.btn-primary:last", div).focus();
|
463
|
+
});
|
464
|
+
|
465
|
+
// wire up button handlers
|
466
|
+
div.on('click', '.modal-footer a, a.close', function(e) {
|
467
|
+
var handler = $(this).data("handler"),
|
468
|
+
cb = callbacks[handler],
|
469
|
+
hideModal = null;
|
470
|
+
|
471
|
+
if (typeof cb == 'function') {
|
472
|
+
hideModal = cb();
|
473
|
+
}
|
474
|
+
if (hideModal !== false){
|
475
|
+
e.preventDefault();
|
476
|
+
hideSource = 'button';
|
477
|
+
div.modal("hide");
|
478
|
+
}
|
479
|
+
});
|
480
|
+
|
481
|
+
if (options.keyboard == null) {
|
482
|
+
options.keyboard = (typeof options.onEscape == 'function');
|
483
|
+
}
|
484
|
+
|
485
|
+
$("body").append(div);
|
486
|
+
|
487
|
+
div.modal({
|
488
|
+
"backdrop" : (typeof options.backdrop === 'undefined') ? _backdrop : options.backdrop,
|
489
|
+
"keyboard" : options.keyboard
|
490
|
+
});
|
491
|
+
|
492
|
+
return div;
|
493
|
+
}
|
494
|
+
|
495
|
+
that.hideAll = function() {
|
496
|
+
$(".bootbox").modal("hide");
|
497
|
+
}
|
498
|
+
|
499
|
+
that.animate = function(animate) {
|
500
|
+
_animate = animate;
|
501
|
+
}
|
502
|
+
|
503
|
+
that.backdrop = function(backdrop) {
|
504
|
+
_backdrop = backdrop;
|
505
|
+
}
|
506
|
+
|
507
|
+
return that;
|
508
|
+
})( window.jQuery );
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootbox-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Kozloff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.1.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: gem-release
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.4.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.4.1
|
78
|
+
description: Wrappers for JavaScript alert(), confirm() and other flexible dialogs
|
79
|
+
using Twitter's bootstrap framework for Rails 3.1+
|
80
|
+
email:
|
81
|
+
- demerest@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- lib/bootbox-rails.rb
|
87
|
+
- lib/tasks/bootbox-rails_tasks.rake
|
88
|
+
- lib/bootbox-rails/engine.rb
|
89
|
+
- vendor/assets/javascripts/bootbox.js
|
90
|
+
- MIT-LICENSE
|
91
|
+
- Rakefile
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
homepage: https://github.com/tanraya/bootbox-rails
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.24
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Wrappers for JavaScript alert(), confirm() and other flexible dialogs using
|
118
|
+
Twitter's bootstrap framework for Rails 3.1+
|
119
|
+
test_files: []
|