lobibox-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/lib/lobibox/rails.rb +8 -0
- data/lib/lobibox/rails/version.rb +5 -0
- data/vendor/assets/javascripts/lobibox.js +1339 -0
- data/vendor/assets/javascripts/lobibox/messageboxes.js +1008 -0
- data/vendor/assets/javascripts/lobibox/notifications.js +330 -0
- data/vendor/assets/stylesheets/lobibox.css +980 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b9dca7e5bcd8bf05dee71f0dfa3f77a0c706878
|
4
|
+
data.tar.gz: ec09f94024f03b5074cd7ca446df73dc7ea1af12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3daa135e054d01eafefaaa3e1e4cc321958fa02ba0fcd4d62e6955bd5e2377dacabe6d054091ec886bedcaa3ba3dd1799c2e86be5d09d407882444111dc1d8f
|
7
|
+
data.tar.gz: 1429e3a542b59c1023e01f9dac7c612f6020c06f336f80262e8c5af291f2516b550030609733819c9516590db8dca10f165edc87304dcd4f4aea8ce1df239444
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Adam Griffis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# lobibox-rails
|
2
|
+
|
3
|
+
lobibox-rails wraps the [lobibox](https://github.com/arboshiki/lobibox) library in a rails engine for simple
|
4
|
+
use with the asset pipeline provided by rails 4.0. The gem includes the development (non-minified)
|
5
|
+
source for ease of exploration. The asset pipeline will minify in production.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add the following to your gemfile:
|
10
|
+
|
11
|
+
gem 'lobibox-rails'
|
12
|
+
|
13
|
+
Add the following directive to your Javascript manifest file (application.js):
|
14
|
+
|
15
|
+
//= require lobibox
|
16
|
+
//= require lobibox/messageboxes
|
17
|
+
//= require lobibox/notifications
|
18
|
+
|
19
|
+
Application.css
|
20
|
+
|
21
|
+
//= require lobibox
|
22
|
+
|
23
|
+
## Versioning
|
24
|
+
|
25
|
+
lobibox-rails 1.0.0 == lobibox.js 1.0.0
|
@@ -0,0 +1,1339 @@
|
|
1
|
+
//Author : @arboshiki
|
2
|
+
//create lobibox object
|
3
|
+
var Lobibox = Lobibox || {};
|
4
|
+
(function(){
|
5
|
+
|
6
|
+
//------------------------------------------------------------------------------
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
|
9
|
+
//User can set default properties for prompt in the following way
|
10
|
+
//Lobibox.prompt.DEFAULT_OPTIONS = object;
|
11
|
+
Lobibox.prompt = function (type, options) {
|
12
|
+
return new LobiboxPrompt(type, options);
|
13
|
+
};
|
14
|
+
//User can set default properties for confirm in the following way
|
15
|
+
//Lobibox.confirm.DEFAULT_OPTIONS = object;
|
16
|
+
Lobibox.confirm = function (options) {
|
17
|
+
return new LobiboxConfirm(options);
|
18
|
+
};
|
19
|
+
//User can set default properties for progress in the following way
|
20
|
+
//Lobibox.progress.DEFAULT_OPTIONS = object;
|
21
|
+
Lobibox.progress = function (options) {
|
22
|
+
return new LobiboxProgress(options);
|
23
|
+
};
|
24
|
+
//Create empty objects in order user to be able to set default options in the following way
|
25
|
+
//Lobibox.error.DEFAULT_OPTIONS = object;
|
26
|
+
//Lobibox.success.DEFAULT_OPTIONS = object;
|
27
|
+
//Lobibox.warning.DEFAULT_OPTIONS = object;
|
28
|
+
//Lobibox.info.DEFAULT_OPTIONS = object;
|
29
|
+
|
30
|
+
Lobibox.error = {};
|
31
|
+
Lobibox.success = {};
|
32
|
+
Lobibox.warning = {};
|
33
|
+
Lobibox.info = {};
|
34
|
+
|
35
|
+
//User can set default properties for alert in the following way
|
36
|
+
//Lobibox.alert.DEFAULT_OPTIONS = object;
|
37
|
+
Lobibox.alert = function (type, options) {
|
38
|
+
if (["success", "error", "warning", "info"].indexOf(type) > -1) {
|
39
|
+
return new LobiboxAlert(type, options);
|
40
|
+
}
|
41
|
+
};
|
42
|
+
//User can set default properties for window in the following way
|
43
|
+
//Lobibox.window.DEFAULT_OPTIONS = object;
|
44
|
+
Lobibox.window = function (options) {
|
45
|
+
return new LobiboxWindow('window', options);
|
46
|
+
};
|
47
|
+
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Base prototype for all messageboxes and window
|
51
|
+
*/
|
52
|
+
var LobiboxBase = {
|
53
|
+
$type : null,
|
54
|
+
$el : null,
|
55
|
+
$options : null,
|
56
|
+
debug : function(){
|
57
|
+
if (this.$options.debug){
|
58
|
+
window.console.debug.apply(window.console, arguments);
|
59
|
+
}
|
60
|
+
},
|
61
|
+
_processInput: function(options){
|
62
|
+
var me = this;
|
63
|
+
if ($.isArray(options.buttons)){
|
64
|
+
var btns = {};
|
65
|
+
for (var i=0; i<options.buttons.length; i++){
|
66
|
+
var btn = Lobibox.base.OPTIONS.buttons[options.buttons[i]];
|
67
|
+
|
68
|
+
btns[options.buttons[i]] = btn;
|
69
|
+
}
|
70
|
+
options.buttons = btns;
|
71
|
+
}
|
72
|
+
options.customBtnClass = options.customBtnClass ? options.customBtnClass : Lobibox.base.DEFAULTS.customBtnClass;
|
73
|
+
for (var i in options.buttons){
|
74
|
+
var btn = options.buttons[i];
|
75
|
+
if (options.buttons.hasOwnProperty(i)){
|
76
|
+
btn = $.extend({}, Lobibox.base.OPTIONS.buttons[i], btn);
|
77
|
+
if ( ! btn['class']){
|
78
|
+
btn['class'] = options.customBtnClass;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
options.buttons[i] = btn;
|
82
|
+
}
|
83
|
+
options = $.extend({}, Lobibox.base.DEFAULTS, options);
|
84
|
+
if (options.showClass === undefined) {
|
85
|
+
options.showClass = Lobibox.base.OPTIONS.showClass;
|
86
|
+
}
|
87
|
+
if (options.hideClass === undefined) {
|
88
|
+
options.hideClass = Lobibox.base.OPTIONS.hideClass;
|
89
|
+
}
|
90
|
+
if (options.baseClass === undefined) {
|
91
|
+
options.baseClass = Lobibox.base.OPTIONS.baseClass;
|
92
|
+
}
|
93
|
+
if (options.delayToRemove === undefined) {
|
94
|
+
options.delayToRemove = Lobibox.base.OPTIONS.delayToRemove;
|
95
|
+
}
|
96
|
+
return options;
|
97
|
+
},
|
98
|
+
_init: function(){
|
99
|
+
var me = this;
|
100
|
+
|
101
|
+
me._createMarkup();
|
102
|
+
me.setTitle(me.$options.title);
|
103
|
+
if (me.$options.draggable && ! me._isMobileScreen()){
|
104
|
+
me.$el.addClass('draggable');
|
105
|
+
me._enableDrag();
|
106
|
+
}
|
107
|
+
if (me.$options.closeButton){
|
108
|
+
me._addCloseButton();
|
109
|
+
}
|
110
|
+
if (me.$options.closeOnEsc){
|
111
|
+
$(document).on('keyup.lobibox', function(ev){
|
112
|
+
if (ev.which === 27){
|
113
|
+
me.destroy();
|
114
|
+
}
|
115
|
+
});
|
116
|
+
}
|
117
|
+
if (me.$options.baseClass){
|
118
|
+
me.$el.addClass(me.$options.baseClass);
|
119
|
+
}
|
120
|
+
if (me.$options.showClass){
|
121
|
+
me.$el.removeClass(me.$options.hideClass);
|
122
|
+
me.$el.addClass(me.$options.showClass);
|
123
|
+
}
|
124
|
+
me.$el.data('lobibox', me);
|
125
|
+
},
|
126
|
+
/**
|
127
|
+
*
|
128
|
+
*
|
129
|
+
* @param {String} position "'top', 'center', 'bottom'"
|
130
|
+
* @returns {Object}
|
131
|
+
*/
|
132
|
+
_calculatePosition: function(position){
|
133
|
+
var me = this;
|
134
|
+
var top;
|
135
|
+
if (position === 'top'){
|
136
|
+
top = 30;
|
137
|
+
}else if (position === 'bottom'){
|
138
|
+
top = $(window).outerHeight() - me.$el.outerHeight() - 30;
|
139
|
+
}else{
|
140
|
+
top = ($(window).outerHeight() - me.$el.outerHeight())/2;
|
141
|
+
}
|
142
|
+
var left = ($(window).outerWidth() - me.$el.outerWidth())/2;
|
143
|
+
return {
|
144
|
+
left: left,
|
145
|
+
top: top
|
146
|
+
};
|
147
|
+
},
|
148
|
+
_createButton: function(type, op){
|
149
|
+
var me = this;
|
150
|
+
var btn = $('<button></button>')
|
151
|
+
.addClass(op['class'])
|
152
|
+
.attr('data-type', type)
|
153
|
+
.html(op.text);
|
154
|
+
if (me.$options.callback && typeof me.$options.callback === 'function') {
|
155
|
+
btn.on('click.lobibox', function(ev){
|
156
|
+
var bt = $(this);
|
157
|
+
if (me.$options.buttons[type] && me.$options.buttons[type].closeOnClick){
|
158
|
+
me.destroy();
|
159
|
+
}
|
160
|
+
me.$options.callback(me, bt.data('type'), ev);
|
161
|
+
});
|
162
|
+
}
|
163
|
+
btn.click(function() {
|
164
|
+
if (me.$options.buttons[type] && me.$options.buttons[type].closeOnClick){
|
165
|
+
me.destroy();
|
166
|
+
}
|
167
|
+
});
|
168
|
+
return btn;
|
169
|
+
},
|
170
|
+
_generateButtons: function(){
|
171
|
+
var me = this;
|
172
|
+
var btns = [];
|
173
|
+
for (var i in me.$options.buttons){
|
174
|
+
if (me.$options.buttons.hasOwnProperty(i)){
|
175
|
+
var op = me.$options.buttons[i];
|
176
|
+
var btn = me._createButton(i, op);
|
177
|
+
btns.push(btn);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
return btns;
|
181
|
+
},
|
182
|
+
_createMarkup: function(){
|
183
|
+
var me = this;
|
184
|
+
var lobibox = $('<div class="lobibox"></div>');
|
185
|
+
lobibox.attr('data-is-modal', me.$options.modal);
|
186
|
+
var header = $('<div class="lobibox-header"></div>')
|
187
|
+
.append('<span class="lobibox-title"></span>')
|
188
|
+
;
|
189
|
+
var body = $('<div class="lobibox-body"></div>');
|
190
|
+
lobibox.append(header);
|
191
|
+
lobibox.append(body);
|
192
|
+
if (me.$options.buttons && ! $.isEmptyObject(me.$options.buttons)){
|
193
|
+
var footer = $('<div class="lobibox-footer"></div>');
|
194
|
+
footer.append(me._generateButtons());
|
195
|
+
lobibox.append(footer);
|
196
|
+
if (Lobibox.base.OPTIONS.buttonsAlign.indexOf(me.$options.buttonsAlign) > -1){
|
197
|
+
footer.addClass('text-'+me.$options.buttonsAlign);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
me.$el = lobibox
|
201
|
+
.addClass(Lobibox.base.OPTIONS.modalClasses[me.$type])
|
202
|
+
;
|
203
|
+
},
|
204
|
+
_setSize: function(){
|
205
|
+
var me = this;
|
206
|
+
me.setWidth(me.$options.width);
|
207
|
+
if (me.$options.height === 'auto'){
|
208
|
+
me.setHeight(me.$el.outerHeight());
|
209
|
+
}else{
|
210
|
+
me.setHeight(me.$options.height);
|
211
|
+
}
|
212
|
+
},
|
213
|
+
_calculateBodyHeight: function(height){
|
214
|
+
var me = this;
|
215
|
+
var headerHeight = me.$el.find('.lobibox-header').outerHeight();
|
216
|
+
var footerHeight = me.$el.find('.lobibox-footer').outerHeight();
|
217
|
+
return height - (headerHeight ? headerHeight : 0) - (footerHeight ? footerHeight : 0);
|
218
|
+
|
219
|
+
},
|
220
|
+
/**
|
221
|
+
* Add backdrop in case if backdrop does not exist
|
222
|
+
*
|
223
|
+
* @returns {void}
|
224
|
+
*/
|
225
|
+
_addBackdrop: function(){
|
226
|
+
if ($('.lobibox-backdrop').length === 0){
|
227
|
+
$('body').append('<div class="lobibox-backdrop"></div>');
|
228
|
+
}
|
229
|
+
},
|
230
|
+
_triggerEvent: function(type){
|
231
|
+
var me = this;
|
232
|
+
if (me.$options[type] && typeof me.$options[type] === 'function'){
|
233
|
+
me.$options[type](me);
|
234
|
+
}
|
235
|
+
},
|
236
|
+
_calculateWidth: function(width){
|
237
|
+
var me = this;
|
238
|
+
width = Math.min($(window).outerWidth(), width);
|
239
|
+
if (width === $(window).outerWidth()){
|
240
|
+
width -= 2 * me.$options.horizontalOffset;
|
241
|
+
}
|
242
|
+
return width;
|
243
|
+
},
|
244
|
+
_calculateHeight: function(height){
|
245
|
+
return Math.min($(window).outerHeight(), height);
|
246
|
+
},
|
247
|
+
_addCloseButton: function () {
|
248
|
+
var me = this;
|
249
|
+
var closeBtn = $('<span class="btn-close">×</span>');
|
250
|
+
me.$el.find('.lobibox-header').append(closeBtn);
|
251
|
+
closeBtn.on('mousedown', function(ev){
|
252
|
+
ev.stopPropagation();
|
253
|
+
});
|
254
|
+
closeBtn.on('click.lobibox', function (ev) {
|
255
|
+
me.destroy();
|
256
|
+
});
|
257
|
+
},
|
258
|
+
_position: function () {
|
259
|
+
var me = this;
|
260
|
+
|
261
|
+
me._setSize();
|
262
|
+
var pos = me._calculatePosition();
|
263
|
+
me.setPosition(pos.left, pos.top);
|
264
|
+
},
|
265
|
+
_isMobileScreen: function () {
|
266
|
+
if ($(window).outerWidth() < 768) {
|
267
|
+
return true;
|
268
|
+
}
|
269
|
+
return false;
|
270
|
+
},
|
271
|
+
_enableDrag: function () {
|
272
|
+
var el = this.$el;
|
273
|
+
var heading = el.find('.lobibox-header');
|
274
|
+
heading.on('mousedown.lobibox', function (ev) {
|
275
|
+
el.attr('offset-left', ev.offsetX);
|
276
|
+
el.attr('offset-top', ev.offsetY);
|
277
|
+
el.attr('allow-drag', 'true');
|
278
|
+
});
|
279
|
+
$(document).on('mouseup.lobibox', function (ev) {
|
280
|
+
el.attr('allow-drag', 'false');
|
281
|
+
});
|
282
|
+
$(document).on('mousemove.lobibox', function (ev) {
|
283
|
+
if (el.attr('allow-drag') === 'true') {
|
284
|
+
var left = ev.clientX - parseInt(el.attr('offset-left'), 10) - parseInt(el.css('border-left-width'), 10);
|
285
|
+
var top = ev.clientY - parseInt(el.attr('offset-top'), 10) - parseInt(el.css('border-top-width'), 10);
|
286
|
+
el.css({
|
287
|
+
left: left,
|
288
|
+
top: top
|
289
|
+
});
|
290
|
+
// el.css({
|
291
|
+
// right: $(document).outerWidth() - (left + el.outerWidth() + 2),
|
292
|
+
// bottom: $(document).outerHeight() - (top + el.outerHeight() + 2)
|
293
|
+
// });
|
294
|
+
}
|
295
|
+
});
|
296
|
+
// el.draggable({
|
297
|
+
// handle: '.lobibox-header'
|
298
|
+
// });
|
299
|
+
// el.css('position', '');
|
300
|
+
},
|
301
|
+
/**
|
302
|
+
* Set the message of messagebox
|
303
|
+
*
|
304
|
+
* @param {String} msg "new message of messagebox"
|
305
|
+
* @returns {Instance}
|
306
|
+
*/
|
307
|
+
_setContent: function (msg) {
|
308
|
+
var me = this;
|
309
|
+
me.$el.find('.lobibox-body').html(msg);
|
310
|
+
return me;
|
311
|
+
},
|
312
|
+
//------------------------------------------------------------------------------
|
313
|
+
//--------------------------PUBLIC METHODS--------------------------------------
|
314
|
+
//------------------------------------------------------------------------------
|
315
|
+
/**
|
316
|
+
* Hide the messagebox
|
317
|
+
*
|
318
|
+
* @returns {Instance}
|
319
|
+
*/
|
320
|
+
hide: function () {
|
321
|
+
var me = this;
|
322
|
+
if (me.$options.hideClass) {
|
323
|
+
me.$el.removeClass(me.$options.showClass);
|
324
|
+
me.$el.addClass(me.$options.hideClass);
|
325
|
+
setTimeout(function () {
|
326
|
+
callback();
|
327
|
+
}, me.$options.delayToRemove);
|
328
|
+
} else {
|
329
|
+
callback();
|
330
|
+
}
|
331
|
+
function callback(){
|
332
|
+
me.$el.addClass('lobibox-hidden');
|
333
|
+
if ($('.lobibox[data-is-modal=true]:not(.lobibox-hidden)').length === 0) {
|
334
|
+
$('.lobibox-backdrop').remove();
|
335
|
+
$('body').removeClass(Lobibox.base.OPTIONS.bodyClass);
|
336
|
+
}
|
337
|
+
}
|
338
|
+
return this;
|
339
|
+
},
|
340
|
+
/**
|
341
|
+
* Removes the messagebox from document
|
342
|
+
*
|
343
|
+
* @returns {Instance}
|
344
|
+
*/
|
345
|
+
destroy: function () {
|
346
|
+
var me = this;
|
347
|
+
me._triggerEvent('beforeClose');
|
348
|
+
if (me.$options.hideClass) {
|
349
|
+
me.$el.removeClass(me.$options.showClass);
|
350
|
+
me.$el.addClass(me.$options.hideClass);
|
351
|
+
setTimeout(function(){
|
352
|
+
callback();
|
353
|
+
},me.$options.delayToRemove);
|
354
|
+
}else{
|
355
|
+
callback();
|
356
|
+
}
|
357
|
+
function callback(){
|
358
|
+
me.$el.remove();
|
359
|
+
if ($('.lobibox[data-is-modal=true]').length === 0) {
|
360
|
+
$('.lobibox-backdrop').remove();
|
361
|
+
$('body').removeClass(Lobibox.base.OPTIONS.bodyClass);
|
362
|
+
}
|
363
|
+
me._triggerEvent('closed');
|
364
|
+
}
|
365
|
+
return this;
|
366
|
+
},
|
367
|
+
/**
|
368
|
+
* Set the width of messagebox
|
369
|
+
*
|
370
|
+
* @param {Integer} width "new width of messagebox"
|
371
|
+
* @returns {Instance}
|
372
|
+
*/
|
373
|
+
setWidth: function (width) {
|
374
|
+
width = this._calculateWidth(width);
|
375
|
+
this.$el.css('width', width);
|
376
|
+
return this;
|
377
|
+
},
|
378
|
+
/**
|
379
|
+
* Set the height of messagebox
|
380
|
+
*
|
381
|
+
* @param {Integer} height "new height of messagebox"
|
382
|
+
* @returns {Instance}
|
383
|
+
*/
|
384
|
+
setHeight: function (height) {
|
385
|
+
var me = this;
|
386
|
+
height = me._calculateHeight(height);
|
387
|
+
me.$el.css('height', height);
|
388
|
+
var bHeight = me._calculateBodyHeight(me.$el.innerHeight());
|
389
|
+
me.$el.find('.lobibox-body').css('height', bHeight);
|
390
|
+
return me;
|
391
|
+
},
|
392
|
+
/**
|
393
|
+
* Set the width and height of messagebox
|
394
|
+
*
|
395
|
+
* @param {Integer} width "new width of messagebox"
|
396
|
+
* @param {Integer} height "new height of messagebox"
|
397
|
+
* @returns {Instance}
|
398
|
+
*/
|
399
|
+
setSize: function (width, height) {
|
400
|
+
var me = this;
|
401
|
+
me.setWidth(width);
|
402
|
+
me.setHeight(height);
|
403
|
+
return me;
|
404
|
+
},
|
405
|
+
/**
|
406
|
+
* Set position of messagebox
|
407
|
+
*
|
408
|
+
* @param {Integer|String} left "left coordinate of messsagebox or string representaing position. Available: ('top', 'center', 'bottom')"
|
409
|
+
* @param {Integer} top
|
410
|
+
* @returns {Instance}
|
411
|
+
*/
|
412
|
+
setPosition: function (left, top) {
|
413
|
+
var me = this;
|
414
|
+
var position;
|
415
|
+
if (typeof left === 'number' && typeof top === 'number'){
|
416
|
+
position = {
|
417
|
+
left: left,
|
418
|
+
top: top
|
419
|
+
};
|
420
|
+
}else if (typeof left === 'string'){
|
421
|
+
position = me._calculatePosition(left);
|
422
|
+
}
|
423
|
+
me.$el.css(position);
|
424
|
+
return me;
|
425
|
+
},
|
426
|
+
/**
|
427
|
+
* Set the title of messagebox
|
428
|
+
*
|
429
|
+
* @param {String} title "new title of messagebox"
|
430
|
+
* @returns {Instance}
|
431
|
+
*/
|
432
|
+
setTitle: function (title) {
|
433
|
+
var me = this;
|
434
|
+
me.$el.find('.lobibox-title').html(title);
|
435
|
+
return me;
|
436
|
+
},
|
437
|
+
/**
|
438
|
+
* Get the title of messagebox
|
439
|
+
*
|
440
|
+
* @returns {String}
|
441
|
+
*/
|
442
|
+
getTitle: function(){
|
443
|
+
var me = this;
|
444
|
+
return me.$el.find('.lobibox-title').html();
|
445
|
+
},
|
446
|
+
/**
|
447
|
+
* Show messagebox
|
448
|
+
*
|
449
|
+
* @returns {Instance}
|
450
|
+
*/
|
451
|
+
show: function () {
|
452
|
+
var me = this;
|
453
|
+
me._triggerEvent('onShow');
|
454
|
+
me.$el.removeClass('lobibox-hidden');
|
455
|
+
$('body').append(me.$el);
|
456
|
+
if (me.$options.modal) {
|
457
|
+
$('body').addClass(Lobibox.base.OPTIONS.bodyClass);
|
458
|
+
me._addBackdrop();
|
459
|
+
}
|
460
|
+
me._triggerEvent('shown');
|
461
|
+
return me;
|
462
|
+
}
|
463
|
+
};
|
464
|
+
//User can set default options by this variable
|
465
|
+
Lobibox.base = {};
|
466
|
+
Lobibox.base.OPTIONS = {
|
467
|
+
bodyClass : 'lobibox-open',
|
468
|
+
|
469
|
+
modalClasses : {
|
470
|
+
'error' : 'lobibox-error',
|
471
|
+
'success' : 'lobibox-success',
|
472
|
+
'info' : 'lobibox-info',
|
473
|
+
'warning' : 'lobibox-warning',
|
474
|
+
'confirm' : 'lobibox-confirm',
|
475
|
+
'progress' : 'lobibox-progress',
|
476
|
+
'prompt' : 'lobibox-prompt',
|
477
|
+
'default' : 'lobibox-default',
|
478
|
+
'window' : 'lobibox-window'
|
479
|
+
},
|
480
|
+
buttonsAlign: ['left', 'center', 'right'],
|
481
|
+
buttons: {
|
482
|
+
ok: {
|
483
|
+
'class': 'lobibox-btn lobibox-btn-default',
|
484
|
+
text: 'OK',
|
485
|
+
closeOnClick: true
|
486
|
+
},
|
487
|
+
cancel: {
|
488
|
+
'class': 'lobibox-btn lobibox-btn-cancel',
|
489
|
+
text: 'Cancel',
|
490
|
+
closeOnClick: true
|
491
|
+
},
|
492
|
+
yes: {
|
493
|
+
'class': 'lobibox-btn lobibox-btn-yes',
|
494
|
+
text: 'Yes',
|
495
|
+
closeOnClick: true
|
496
|
+
},
|
497
|
+
no: {
|
498
|
+
'class': 'lobibox-btn lobibox-btn-no',
|
499
|
+
text: 'No',
|
500
|
+
closeOnClick: true
|
501
|
+
}
|
502
|
+
}
|
503
|
+
};
|
504
|
+
Lobibox.base.DEFAULTS = {
|
505
|
+
horizontalOffset: 5, //If the messagebox is larger (in width) than window's width. The messagebox's width is reduced to window width - 2 * horizontalOffset
|
506
|
+
width : 600,
|
507
|
+
height : 'auto', // Height is automatically given calculated by width
|
508
|
+
closeButton : true, // Show close button or not
|
509
|
+
draggable : false, // Make messagebox draggable
|
510
|
+
customBtnClass : 'lobibox-btn lobibox-btn-default', // Class for custom buttons
|
511
|
+
modal : true,
|
512
|
+
debug : false,
|
513
|
+
buttonsAlign : 'center', // Position where buttons should be aligned
|
514
|
+
closeOnEsc : true, // Close messagebox on Esc press
|
515
|
+
delayToRemove : 200,
|
516
|
+
baseClass : 'animated-super-fast',
|
517
|
+
showClass : 'zoomIn',
|
518
|
+
hideClass : 'zoomOut',
|
519
|
+
|
520
|
+
|
521
|
+
//events
|
522
|
+
//When messagebox show is called but before it is actually shown
|
523
|
+
onShow : null,
|
524
|
+
//After messagebox is shown
|
525
|
+
shown : null,
|
526
|
+
//When messagebox remove method is called but before it is actually hidden
|
527
|
+
beforeClose : null,
|
528
|
+
//After messagebox is hidden
|
529
|
+
closed : null
|
530
|
+
};
|
531
|
+
//------------------------------------------------------------------------------
|
532
|
+
//-------------------------LobiboxPrompt----------------------------------------
|
533
|
+
//------------------------------------------------------------------------------
|
534
|
+
function LobiboxPrompt (type, options){
|
535
|
+
this.$input = null;
|
536
|
+
this.$type = 'prompt';
|
537
|
+
this.$promptType = type;
|
538
|
+
|
539
|
+
options = $.extend({}, Lobibox.prompt.DEFAULT_OPTIONS, options);
|
540
|
+
|
541
|
+
this.$options = this._processInput(options);
|
542
|
+
|
543
|
+
this._init();
|
544
|
+
this.debug(this);
|
545
|
+
};
|
546
|
+
|
547
|
+
LobiboxPrompt.prototype = $.extend({}, LobiboxBase, {
|
548
|
+
constructor: LobiboxPrompt,
|
549
|
+
|
550
|
+
_processInput: function(options){
|
551
|
+
var me = this;
|
552
|
+
|
553
|
+
var mergedOptions = LobiboxBase._processInput.call(me, options);
|
554
|
+
mergedOptions.buttons = {
|
555
|
+
ok: Lobibox.base.OPTIONS.buttons.ok,
|
556
|
+
cancel: Lobibox.base.OPTIONS.buttons.cancel
|
557
|
+
};
|
558
|
+
options = $.extend({}, mergedOptions, LobiboxPrompt.DEFAULT_OPTIONS, options);
|
559
|
+
return options;
|
560
|
+
},
|
561
|
+
_init: function(){
|
562
|
+
var me = this;
|
563
|
+
|
564
|
+
LobiboxBase._init.call(me);
|
565
|
+
|
566
|
+
me.show();
|
567
|
+
me._setContent(me._createInput());
|
568
|
+
// me.$input.focus();
|
569
|
+
me._position();
|
570
|
+
me.$input.focus();
|
571
|
+
},
|
572
|
+
_createInput: function(){
|
573
|
+
var me = this;
|
574
|
+
var label;
|
575
|
+
if (me.$options.multiline){
|
576
|
+
me.$input = $('<textarea></textarea>');
|
577
|
+
me.$input.attr('rows' , me.$options.lines);
|
578
|
+
}else{
|
579
|
+
me.$input = $('<input type="'+me.$promptType+'"/>');
|
580
|
+
}
|
581
|
+
me.$input.addClass('lobibox-input');
|
582
|
+
me.$input.attr(me.$options.attrs);
|
583
|
+
if (me.$options.value){
|
584
|
+
me.setValue(me.$options.value);
|
585
|
+
}
|
586
|
+
if (me.$options.label){
|
587
|
+
label = $('<label>'+me.$options.label+'</label>');
|
588
|
+
}
|
589
|
+
var innerHTML = $('<div></div>').append(label, me.$input);
|
590
|
+
return innerHTML;
|
591
|
+
},
|
592
|
+
/**
|
593
|
+
* Set value of input
|
594
|
+
*
|
595
|
+
* @param {Strin} val "value of input"
|
596
|
+
* @returns {Instance}
|
597
|
+
*/
|
598
|
+
setValue: function(val){
|
599
|
+
this.$input.val(val);
|
600
|
+
return this;
|
601
|
+
},
|
602
|
+
/**
|
603
|
+
* Get value of input
|
604
|
+
*
|
605
|
+
* @returns {String}
|
606
|
+
*/
|
607
|
+
getValue: function(){
|
608
|
+
return this.$input.val();
|
609
|
+
}
|
610
|
+
});
|
611
|
+
|
612
|
+
LobiboxPrompt.DEFAULT_OPTIONS = {
|
613
|
+
width: 400,
|
614
|
+
attrs : {}, // Object of any valid attribute of input field
|
615
|
+
value: '', // Value which is given to textfield when messagebox is created
|
616
|
+
multiline: false, // Set this true for multiline prompt
|
617
|
+
lines: 3, // This works only for multiline prompt. Number of lines
|
618
|
+
type: 'text', // Prompt type. Available types (text|number|color)
|
619
|
+
label: '' // Set some text which will be shown exactly on top of textfield
|
620
|
+
};
|
621
|
+
//------------------------------------------------------------------------------
|
622
|
+
//-------------------------LobiboxConfirm---------------------------------------
|
623
|
+
//------------------------------------------------------------------------------
|
624
|
+
function LobiboxConfirm (options){
|
625
|
+
this.$type = 'confirm';
|
626
|
+
|
627
|
+
// options = $.extend({}, Lobibox.confirm.DEFAULT_OPTIONS, options);
|
628
|
+
|
629
|
+
this.$options = this._processInput(options);
|
630
|
+
this._init();
|
631
|
+
this.debug(this);
|
632
|
+
};
|
633
|
+
|
634
|
+
LobiboxConfirm.prototype = $.extend({}, LobiboxBase, {
|
635
|
+
constructor: LobiboxConfirm,
|
636
|
+
|
637
|
+
_processInput: function(options){
|
638
|
+
var me = this;
|
639
|
+
|
640
|
+
var mergedOptions = LobiboxBase._processInput.call(me, options);
|
641
|
+
mergedOptions.buttons = {
|
642
|
+
yes: Lobibox.base.OPTIONS.buttons.yes,
|
643
|
+
no: Lobibox.base.OPTIONS.buttons.no
|
644
|
+
};
|
645
|
+
options = $.extend({}, mergedOptions, Lobibox.confirm.DEFAULTS, options);
|
646
|
+
return options;
|
647
|
+
},
|
648
|
+
|
649
|
+
_init: function(){
|
650
|
+
var me = this;
|
651
|
+
|
652
|
+
LobiboxBase._init.call(me);
|
653
|
+
me.show();
|
654
|
+
var d = $('<div></div>');
|
655
|
+
if (me.$options.iconClass){
|
656
|
+
d.append($('<div class="lobibox-icon-wrapper"></div>')
|
657
|
+
.append('<i class="lobibox-icon '+me.$options.iconClass+'"></i>'))
|
658
|
+
;
|
659
|
+
}
|
660
|
+
d.append('<div class="lobibox-body-text-wrapper"><span class="lobibox-body-text">'+me.$options.msg+'</span></div>');
|
661
|
+
me._setContent(d.html());
|
662
|
+
|
663
|
+
me._position();
|
664
|
+
}
|
665
|
+
});
|
666
|
+
|
667
|
+
Lobibox.confirm.DEFAULTS = {
|
668
|
+
title : 'Question',
|
669
|
+
width : 500,
|
670
|
+
iconClass : 'glyphicon glyphicon-question-sign'
|
671
|
+
};
|
672
|
+
//------------------------------------------------------------------------------
|
673
|
+
//-------------------------LobiboxAlert------------------------------------------
|
674
|
+
//------------------------------------------------------------------------------
|
675
|
+
function LobiboxAlert (type, options){
|
676
|
+
this.$type = type;
|
677
|
+
|
678
|
+
// options = $.extend({}, Lobibox.alert.DEFAULT_OPTIONS, Lobibox[type].DEFAULT_OPTIONS, options);
|
679
|
+
|
680
|
+
this.$options = this._processInput(options);
|
681
|
+
|
682
|
+
this._init();
|
683
|
+
this.debug(this);
|
684
|
+
};
|
685
|
+
|
686
|
+
LobiboxAlert.prototype = $.extend({}, LobiboxBase, {
|
687
|
+
constructor: LobiboxAlert,
|
688
|
+
|
689
|
+
_processInput: function(options){
|
690
|
+
|
691
|
+
// ALERT_OPTIONS = $.extend({}, LobiboxAlert.OPTIONS, Lobibox.alert.DEFAULTS);
|
692
|
+
|
693
|
+
var me = this;
|
694
|
+
var mergedOptions = LobiboxBase._processInput.call(me, options);
|
695
|
+
mergedOptions.buttons = {
|
696
|
+
ok: Lobibox.base.OPTIONS.buttons.ok
|
697
|
+
};
|
698
|
+
options = $.extend({}, mergedOptions, Lobibox.alert.OPTIONS[me.$type], Lobibox.alert.DEFAULTS, options);
|
699
|
+
// window.console.log(options);
|
700
|
+
// options = $.extend({}, mergedOptions, LobiboxAlert.DEFAULT_OPTIONS, options);
|
701
|
+
// if (options.iconClass === true){
|
702
|
+
// options.iconClass = ALERT_OPTIONS[me.$type].iconClass;
|
703
|
+
// }
|
704
|
+
|
705
|
+
return options;
|
706
|
+
},
|
707
|
+
|
708
|
+
_init: function(){
|
709
|
+
var me = this;
|
710
|
+
LobiboxBase._init.call(me);
|
711
|
+
me.show();
|
712
|
+
|
713
|
+
var d = $('<div></div>');
|
714
|
+
if (me.$options.iconClass){
|
715
|
+
d.append($('<div class="lobibox-icon-wrapper"></div>')
|
716
|
+
.append('<i class="lobibox-icon '+me.$options.iconClass+'"></i>'))
|
717
|
+
;
|
718
|
+
}
|
719
|
+
d.append('<div class="lobibox-body-text-wrapper"><span class="lobibox-body-text">'+me.$options.msg+'</span></div>');
|
720
|
+
me._setContent(d.html());
|
721
|
+
me._position();
|
722
|
+
}
|
723
|
+
});
|
724
|
+
Lobibox.alert.OPTIONS = {
|
725
|
+
warning: {
|
726
|
+
title: 'Warning',
|
727
|
+
iconClass: 'glyphicon glyphicon-question-sign'
|
728
|
+
},
|
729
|
+
info: {
|
730
|
+
title: 'Information',
|
731
|
+
iconClass: 'glyphicon glyphicon-info-sign'
|
732
|
+
},
|
733
|
+
success: {
|
734
|
+
title: 'Success',
|
735
|
+
iconClass: 'glyphicon glyphicon-ok-sign'
|
736
|
+
},
|
737
|
+
error: {
|
738
|
+
title: 'Error',
|
739
|
+
iconClass: 'glyphicon glyphicon-remove-sign'
|
740
|
+
}
|
741
|
+
};
|
742
|
+
//User can set default options by this variable
|
743
|
+
Lobibox.alert.DEFAULTS = {
|
744
|
+
// title:
|
745
|
+
// iconClass:
|
746
|
+
};
|
747
|
+
//------------------------------------------------------------------------------
|
748
|
+
//-------------------------LobiboxProgress--------------------------------------
|
749
|
+
//------------------------------------------------------------------------------
|
750
|
+
function LobiboxProgress (options){
|
751
|
+
this.$type = 'progress';
|
752
|
+
this.$progressBarElement = null,
|
753
|
+
|
754
|
+
this.$options = this._processInput(options);
|
755
|
+
this.$progress = 0;
|
756
|
+
|
757
|
+
this._init();
|
758
|
+
this.debug(this);
|
759
|
+
};
|
760
|
+
|
761
|
+
LobiboxProgress.prototype = $.extend({}, LobiboxBase, {
|
762
|
+
constructor: LobiboxProgress,
|
763
|
+
|
764
|
+
_processInput: function(options){
|
765
|
+
var me = this;
|
766
|
+
var mergedOptions = LobiboxBase._processInput.call(me, options);
|
767
|
+
|
768
|
+
options = $.extend({}, mergedOptions, Lobibox.progress.DEFAULTS, options);
|
769
|
+
return options;
|
770
|
+
},
|
771
|
+
_init: function(){
|
772
|
+
var me = this;
|
773
|
+
|
774
|
+
LobiboxBase._init.call(me);
|
775
|
+
me.show();
|
776
|
+
if (me.$options.progressTpl){
|
777
|
+
me.$progressBarElement = $(me.$options.progressTpl);
|
778
|
+
}else{
|
779
|
+
me.$progressBarElement = me._createProgressbar();
|
780
|
+
}
|
781
|
+
var label;
|
782
|
+
if (me.$options.label){
|
783
|
+
label = $('<label>'+me.$options.label+'</label>');
|
784
|
+
}
|
785
|
+
var innerHTML = $('<div></div>').append(label, me.$progressBarElement);
|
786
|
+
me._setContent(innerHTML);
|
787
|
+
me._position();
|
788
|
+
},
|
789
|
+
_createProgressbar: function(){
|
790
|
+
var me = this;
|
791
|
+
var outer = $('<div class="lobibox-progress-bar-wrapper lobibox-progress-outer"></div>')
|
792
|
+
.append('<div class="lobibox-progress-bar lobibox-progress-element"></div>')
|
793
|
+
;
|
794
|
+
if (me.$options.showProgressLabel){
|
795
|
+
outer.append('<span class="lobibox-progress-text" data-role="progress-text"></span>');
|
796
|
+
}
|
797
|
+
|
798
|
+
return outer;
|
799
|
+
},
|
800
|
+
/**
|
801
|
+
* Set progress value
|
802
|
+
*
|
803
|
+
* @param {Integer} progress "progress value"
|
804
|
+
* @returns {Instance}
|
805
|
+
*/
|
806
|
+
setProgress: function(progress){
|
807
|
+
var me = this;
|
808
|
+
if (me.$progress === 100){
|
809
|
+
return;
|
810
|
+
}
|
811
|
+
progress = Math.min(100, Math.max(0, progress));
|
812
|
+
me.$progress = progress;
|
813
|
+
me._triggerEvent('progressUpdated');
|
814
|
+
if (me.$progress === 100){
|
815
|
+
me._triggerEvent('progressCompleted');
|
816
|
+
}
|
817
|
+
me.$el.find('.lobibox-progress-element').css('width', progress.toFixed(1)+"%");
|
818
|
+
me.$el.find('[data-role="progress-text"]').html(progress.toFixed(1)+"%");
|
819
|
+
return me;
|
820
|
+
},
|
821
|
+
/**
|
822
|
+
* Get progress value
|
823
|
+
*
|
824
|
+
* @returns {Integer}
|
825
|
+
*/
|
826
|
+
getProgress: function(){
|
827
|
+
return this.$progress;
|
828
|
+
}
|
829
|
+
});
|
830
|
+
|
831
|
+
Lobibox.progress.DEFAULTS = {
|
832
|
+
width : 500,
|
833
|
+
showProgressLabel : true, // Show percentage of progress
|
834
|
+
label : '', // Show progress label
|
835
|
+
progressTpl : false, //Template of progress bar
|
836
|
+
|
837
|
+
//Events
|
838
|
+
progressUpdated : null,
|
839
|
+
progressCompleted : null
|
840
|
+
};
|
841
|
+
//------------------------------------------------------------------------------
|
842
|
+
//-------------------------LobiboxWindow----------------------------------------
|
843
|
+
//------------------------------------------------------------------------------
|
844
|
+
function LobiboxWindow(type, options) {
|
845
|
+
this.$type = type;
|
846
|
+
|
847
|
+
this.$options = this._processInput(options);
|
848
|
+
|
849
|
+
this._init();
|
850
|
+
this.debug(this);
|
851
|
+
}
|
852
|
+
;
|
853
|
+
|
854
|
+
LobiboxWindow.prototype = $.extend({}, LobiboxBase, {
|
855
|
+
constructor: LobiboxWindow,
|
856
|
+
_processInput: function(options) {
|
857
|
+
var me = this;
|
858
|
+
var mergedOptions = LobiboxBase._processInput.call(me, options);
|
859
|
+
|
860
|
+
if (options.content && typeof options.content === 'function'){
|
861
|
+
options.content = options.content();
|
862
|
+
}
|
863
|
+
if (options.content instanceof jQuery){
|
864
|
+
options.content = options.content.clone();
|
865
|
+
}
|
866
|
+
options = $.extend({}, mergedOptions, Lobibox.window.DEFAULTS, options);
|
867
|
+
return options;
|
868
|
+
},
|
869
|
+
_init: function() {
|
870
|
+
var me = this;
|
871
|
+
|
872
|
+
LobiboxBase._init.call(me);
|
873
|
+
me.setContent(me.$options.content);
|
874
|
+
if (me.$options.url && me.$options.autoload){
|
875
|
+
if ( ! me.$options.showAfterLoad){
|
876
|
+
me.show();
|
877
|
+
me._position();
|
878
|
+
}
|
879
|
+
me.load(function(){
|
880
|
+
if (me.$options.showAfterLoad) {
|
881
|
+
me.show();
|
882
|
+
me._position();
|
883
|
+
}
|
884
|
+
});
|
885
|
+
}else{
|
886
|
+
me.show();
|
887
|
+
me._position();
|
888
|
+
}
|
889
|
+
},
|
890
|
+
/**
|
891
|
+
* Setter method for <code>params</code> option
|
892
|
+
*
|
893
|
+
* @param {Object} params "new params"
|
894
|
+
* @returns {Instance}
|
895
|
+
*/
|
896
|
+
setParams: function(params){
|
897
|
+
var me = this;
|
898
|
+
me.$options.params = params;
|
899
|
+
return me;
|
900
|
+
},
|
901
|
+
/**
|
902
|
+
* Getter method for <code>params</code>
|
903
|
+
*
|
904
|
+
* @returns {Object}
|
905
|
+
*/
|
906
|
+
getParams: function(){
|
907
|
+
var me = this;
|
908
|
+
return me.$options.params;
|
909
|
+
},
|
910
|
+
/**
|
911
|
+
* Setter method of <code>loadMethod</code> option
|
912
|
+
*
|
913
|
+
* @param {String} method "new method"
|
914
|
+
* @returns {Instance}
|
915
|
+
*/
|
916
|
+
setLoadMethod: function(method){
|
917
|
+
var me = this;
|
918
|
+
me.$options.loadMethod = method;
|
919
|
+
return me;
|
920
|
+
},
|
921
|
+
/**
|
922
|
+
* Getter method for <code>loadMethod</code> option
|
923
|
+
*
|
924
|
+
* @returns {String}
|
925
|
+
*/
|
926
|
+
getLoadMethod: function(){
|
927
|
+
var me = this;
|
928
|
+
return me.$options.loadMethod;
|
929
|
+
},
|
930
|
+
/**
|
931
|
+
* Setter method of <code>content</code> option.
|
932
|
+
* Change the content of window
|
933
|
+
*
|
934
|
+
* @param {String} content "new content"
|
935
|
+
* @returns {Instance}
|
936
|
+
*/
|
937
|
+
setContent: function(content){
|
938
|
+
var me = this;
|
939
|
+
me.$options.content = content;
|
940
|
+
me.$el.find('.lobibox-body').html('').append(content);
|
941
|
+
return me;
|
942
|
+
},
|
943
|
+
/**
|
944
|
+
* Getter method of <code>content</code> option
|
945
|
+
*
|
946
|
+
* @returns {String}
|
947
|
+
*/
|
948
|
+
getContent: function(){
|
949
|
+
var me = this;
|
950
|
+
return me.$options.content;
|
951
|
+
},
|
952
|
+
/**
|
953
|
+
* Setter method of <code>url</code> option
|
954
|
+
*
|
955
|
+
* @param {String} url "new url"
|
956
|
+
* @returns {Instance}
|
957
|
+
*/
|
958
|
+
setUrl : function(url){
|
959
|
+
this.$options.url = url;
|
960
|
+
return this;
|
961
|
+
},
|
962
|
+
/**
|
963
|
+
* Getter method of <code>url</code> option
|
964
|
+
*
|
965
|
+
* @returns {String}
|
966
|
+
*/
|
967
|
+
getUrl : function(){
|
968
|
+
return this.$options.url;
|
969
|
+
},
|
970
|
+
/**
|
971
|
+
* Loads content to window by ajax from specific url
|
972
|
+
*
|
973
|
+
* @param {Function} callback "callback function"
|
974
|
+
* @returns {Instance}
|
975
|
+
*/
|
976
|
+
load: function(callback){
|
977
|
+
var me = this;
|
978
|
+
if ( ! me.$options.url){
|
979
|
+
return me;
|
980
|
+
}
|
981
|
+
$.ajax(me.$options.url, {
|
982
|
+
method: me.$options.loadMethod,
|
983
|
+
data: me.$options.params
|
984
|
+
}).done(function(res) {
|
985
|
+
me.setContent(res);
|
986
|
+
if (callback && typeof callback === 'function'){
|
987
|
+
callback(res);
|
988
|
+
}
|
989
|
+
});
|
990
|
+
return me;
|
991
|
+
}
|
992
|
+
});
|
993
|
+
|
994
|
+
Lobibox.window.DEFAULTS = {
|
995
|
+
width : 480,
|
996
|
+
height : 600,
|
997
|
+
content : '', // HTML Content of window
|
998
|
+
url : '', // URL which will be used to load content
|
999
|
+
draggable : true, // Override default option
|
1000
|
+
autoload : true, // Auto load from given url when window is created
|
1001
|
+
loadMethod : 'GET', // Ajax method to load content
|
1002
|
+
showAfterLoad : true, // Show window after content is loaded or show and then load content
|
1003
|
+
params : {} // Parameters which will be send by ajax for loading content
|
1004
|
+
};
|
1005
|
+
|
1006
|
+
})();
|
1007
|
+
|
1008
|
+
|
1009
|
+
|
1010
|
+
//Author : @arboshiki
|
1011
|
+
/**
|
1012
|
+
* Generates random string of n length.
|
1013
|
+
* String contains only letters and numbers
|
1014
|
+
*
|
1015
|
+
* @param {int} n
|
1016
|
+
* @returns {String}
|
1017
|
+
*/
|
1018
|
+
Math.randomString = function(n) {
|
1019
|
+
var text = "";
|
1020
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
1021
|
+
|
1022
|
+
for (var i = 0; i < n; i++)
|
1023
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
1024
|
+
|
1025
|
+
return text;
|
1026
|
+
};
|
1027
|
+
var Lobibox = Lobibox || {};
|
1028
|
+
(function(){
|
1029
|
+
|
1030
|
+
var LobiboxNotify = function(type, options) {
|
1031
|
+
//------------------------------------------------------------------------------
|
1032
|
+
//----------------PROTOTYPE VARIABLES-------------------------------------------
|
1033
|
+
//------------------------------------------------------------------------------
|
1034
|
+
this.$type;
|
1035
|
+
this.$options;
|
1036
|
+
this.$el;
|
1037
|
+
this.$sound;
|
1038
|
+
//------------------------------------------------------------------------------
|
1039
|
+
//-----------------PRIVATE VARIABLES--------------------------------------------
|
1040
|
+
//------------------------------------------------------------------------------
|
1041
|
+
var me = this;
|
1042
|
+
//------------------------------------------------------------------------------
|
1043
|
+
//-----------------PRIVATE FUNCTIONS--------------------------------------------
|
1044
|
+
//------------------------------------------------------------------------------
|
1045
|
+
var _processInput = function(options){
|
1046
|
+
|
1047
|
+
if (options.size === 'mini' || options.size === 'large'){
|
1048
|
+
options.width = options.width || Lobibox.notify.OPTIONS[options.size].width;
|
1049
|
+
}
|
1050
|
+
options = $.extend({}, Lobibox.notify.OPTIONS[me.$type], Lobibox.notify.DEFAULTS, options);
|
1051
|
+
|
1052
|
+
|
1053
|
+
if (options.size !== 'mini' && options.title === true){
|
1054
|
+
options.title = Lobibox.notify.OPTIONS[me.$type].title;
|
1055
|
+
}else if (options.size === 'mini' && options.title === true){
|
1056
|
+
options.title = false;
|
1057
|
+
}
|
1058
|
+
if (options.icon === true){
|
1059
|
+
options.icon = Lobibox.notify.OPTIONS[me.$type].icon;
|
1060
|
+
}
|
1061
|
+
if (options.sound === true){
|
1062
|
+
options.sound = Lobibox.notify.OPTIONS[me.$type].sound;
|
1063
|
+
}
|
1064
|
+
if (options.sound){
|
1065
|
+
options.sound = options.soundPath + options.sound + options.soundExt;
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
return options;
|
1069
|
+
};
|
1070
|
+
var _init = function(){
|
1071
|
+
// Create notification
|
1072
|
+
var notify = _createNotify();
|
1073
|
+
var wrapper = _createNotifyWrapper();
|
1074
|
+
_appendInWrapper(notify, wrapper);
|
1075
|
+
|
1076
|
+
me.$el = notify;
|
1077
|
+
if (me.$options.sound){
|
1078
|
+
var snd = new Audio(me.$options.sound); // buffers automatically when created
|
1079
|
+
snd.play();
|
1080
|
+
}
|
1081
|
+
me.$el.data('lobibox', me);
|
1082
|
+
};
|
1083
|
+
var _appendInWrapper = function($el, $wrapper){
|
1084
|
+
if (me.$options.size === 'normal'){
|
1085
|
+
$wrapper.append($el);
|
1086
|
+
}else if (me.$options.size === 'mini'){
|
1087
|
+
$el.addClass('notify-mini');
|
1088
|
+
$wrapper.append($el);
|
1089
|
+
}else if (me.$options.size === 'large'){
|
1090
|
+
var tabPane = _createTabPane();
|
1091
|
+
tabPane.append($el);
|
1092
|
+
var tabControl = _createTabControl(tabPane.attr('id'));
|
1093
|
+
$wrapper.find('.tab-content').append(tabPane);
|
1094
|
+
$wrapper.find('.nav-tabs').append(tabControl);
|
1095
|
+
tabControl.find('>a').tab('show');
|
1096
|
+
}
|
1097
|
+
};
|
1098
|
+
var _createTabControl = function(tabPaneId){
|
1099
|
+
var $li = $('<li></li>');
|
1100
|
+
$('<a href="#'+tabPaneId+'"></a>')
|
1101
|
+
.attr('data-toggle', 'tab')
|
1102
|
+
.attr('role', 'tab')
|
1103
|
+
.append('<i class="tab-control-icon ' + me.$options.icon + '"></i>')
|
1104
|
+
.appendTo($li);
|
1105
|
+
$li.addClass(Lobibox.notify.OPTIONS[me.$type]['class']);
|
1106
|
+
return $li;
|
1107
|
+
};
|
1108
|
+
var _createTabPane = function(){
|
1109
|
+
var $pane = $('<div></div>')
|
1110
|
+
.addClass('tab-pane')
|
1111
|
+
.attr('id', Math.randomString(10));
|
1112
|
+
return $pane;
|
1113
|
+
};
|
1114
|
+
var _createNotifyWrapper = function(){
|
1115
|
+
var selector;
|
1116
|
+
if (me.$options.size === 'large'){
|
1117
|
+
selector = '.lobibox-notify-wrapper-large';
|
1118
|
+
}else{
|
1119
|
+
selector = '.lobibox-notify-wrapper';
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
var classes = me.$options.position.split(" ");
|
1123
|
+
selector += "."+classes.join('.');
|
1124
|
+
var wrapper = $(selector);
|
1125
|
+
if (wrapper.length === 0){
|
1126
|
+
wrapper = $('<div></div>')
|
1127
|
+
.addClass(selector.replace(/\./g, ' ').trim())
|
1128
|
+
.appendTo($('body'));
|
1129
|
+
if (me.$options.size === 'large'){
|
1130
|
+
wrapper.append($('<ul class="nav nav-tabs"></ul>'))
|
1131
|
+
.append($('<div class="tab-content"></div>'));
|
1132
|
+
}
|
1133
|
+
}
|
1134
|
+
return wrapper;
|
1135
|
+
};
|
1136
|
+
var _createNotify = function(){
|
1137
|
+
var notify = $('<div class="lobibox-notify"></div>')
|
1138
|
+
// Add color class
|
1139
|
+
.addClass(Lobibox.notify.OPTIONS[me.$type]['class'])
|
1140
|
+
// Add default animation class
|
1141
|
+
.addClass(Lobibox.notify.OPTIONS['class'])
|
1142
|
+
// Add specific animation class
|
1143
|
+
.addClass(me.$options.showClass);
|
1144
|
+
|
1145
|
+
// Create icon wrapper class
|
1146
|
+
var iconWrapper = $('<div class="lobibox-notify-icon"></div>').appendTo(notify);
|
1147
|
+
|
1148
|
+
// Add image or icon depending on given parameters
|
1149
|
+
if (me.$options.img) {
|
1150
|
+
var img = iconWrapper.append('<img src="' + me.$options.img + '"/>');
|
1151
|
+
iconWrapper.append(img);
|
1152
|
+
} else if (me.$options.icon) {
|
1153
|
+
var icon = iconWrapper.append('<i class="' + me.$options.icon + '"></i>');
|
1154
|
+
iconWrapper.append(icon);
|
1155
|
+
}else{
|
1156
|
+
notify.addClass('without-icon');
|
1157
|
+
}
|
1158
|
+
// Create body, append title and message in body and append body in notification
|
1159
|
+
var $body = $('<div></div>')
|
1160
|
+
.addClass('lobibox-notify-body')
|
1161
|
+
.append('<div class="lobibox-notify-msg">' + me.$options.msg + '</div>')
|
1162
|
+
.appendTo(notify);
|
1163
|
+
if (me.$options.title){
|
1164
|
+
$body.prepend('<div class="lobibox-notify-title">' + me.$options.title + '<div>');
|
1165
|
+
}
|
1166
|
+
_addCloseButton(notify);
|
1167
|
+
if (me.$options.size === 'normal' || me.$options.size === 'mini'){
|
1168
|
+
_addCloseOnClick(notify);
|
1169
|
+
_addDelay(notify);
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
// Give width to notification
|
1173
|
+
if (me.$options.width){
|
1174
|
+
notify.css('width', _calculateWidth(me.$options.width));
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
return notify;
|
1178
|
+
};
|
1179
|
+
var _addCloseButton = function($el){
|
1180
|
+
if ( ! me.$options.closable){
|
1181
|
+
return;
|
1182
|
+
}
|
1183
|
+
var close = $('<span class="lobibox-close">×</span>');
|
1184
|
+
$el.append(close);
|
1185
|
+
close.click(function(ev){
|
1186
|
+
me.remove();
|
1187
|
+
});
|
1188
|
+
};
|
1189
|
+
var _addCloseOnClick = function($el){
|
1190
|
+
if ( ! me.$options.closeOnClick){
|
1191
|
+
return;
|
1192
|
+
}
|
1193
|
+
$el.click(function(){
|
1194
|
+
me.remove();
|
1195
|
+
});
|
1196
|
+
};
|
1197
|
+
var _addDelay = function($el){
|
1198
|
+
if ( ! me.$options.delay){
|
1199
|
+
return;
|
1200
|
+
}
|
1201
|
+
if (me.$options.delayIndicator){
|
1202
|
+
var delay = $('<div class="lobibox-delay-indicator"><div></div></div>');
|
1203
|
+
$el.append(delay);
|
1204
|
+
}
|
1205
|
+
var time = 0;
|
1206
|
+
var interval = 1000/30;
|
1207
|
+
var timer = setInterval(function(){
|
1208
|
+
time += interval;
|
1209
|
+
var width = 100 * time / me.$options.delay;
|
1210
|
+
if (width >= 100){
|
1211
|
+
width = 100;
|
1212
|
+
me.remove();
|
1213
|
+
timer = clearInterval(timer);
|
1214
|
+
}
|
1215
|
+
if (me.$options.delayIndicator){
|
1216
|
+
delay.find('div').css('width', width+"%");
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
}, interval);
|
1220
|
+
};
|
1221
|
+
var _findTabToActivate = function($li){
|
1222
|
+
var $itemToActivate = $li.prev();
|
1223
|
+
if ($itemToActivate.length === 0){
|
1224
|
+
$itemToActivate = $li.next();
|
1225
|
+
}
|
1226
|
+
if ($itemToActivate.length === 0){
|
1227
|
+
return null;
|
1228
|
+
}
|
1229
|
+
return $itemToActivate.find('>a');
|
1230
|
+
};
|
1231
|
+
var _calculateWidth = function(width){
|
1232
|
+
width = Math.min($(window).outerWidth(), width);
|
1233
|
+
return width;
|
1234
|
+
};
|
1235
|
+
//------------------------------------------------------------------------------
|
1236
|
+
//----------------PROTOTYPE FUNCTIONS-------------------------------------------
|
1237
|
+
//------------------------------------------------------------------------------
|
1238
|
+
/**
|
1239
|
+
* Delete the notification
|
1240
|
+
*
|
1241
|
+
* @returns {Instance}
|
1242
|
+
*/
|
1243
|
+
this.remove = function(){
|
1244
|
+
me.$el.removeClass(me.$options.showClass)
|
1245
|
+
.addClass(me.$options.hideClass);
|
1246
|
+
var parent = me.$el.parent();
|
1247
|
+
var wrapper = parent.closest('.lobibox-notify-wrapper-large');
|
1248
|
+
|
1249
|
+
var href = '#' + parent.attr('id');
|
1250
|
+
|
1251
|
+
var $li = wrapper.find('>.nav-tabs>li:has(a[href="' + href + '"])');
|
1252
|
+
$li.addClass(Lobibox.notify.OPTIONS['class'])
|
1253
|
+
.addClass(me.$options.hideClass);
|
1254
|
+
setTimeout(function(){
|
1255
|
+
if (me.$options.size === 'normal' || me.$options.size === 'mini'){
|
1256
|
+
me.$el.remove();
|
1257
|
+
}else if (me.$options.size === 'large'){
|
1258
|
+
|
1259
|
+
var $itemToActivate = _findTabToActivate($li);
|
1260
|
+
if ($itemToActivate){
|
1261
|
+
$itemToActivate.tab('show');
|
1262
|
+
}
|
1263
|
+
$li.remove();
|
1264
|
+
parent.remove();
|
1265
|
+
}
|
1266
|
+
}, 500);
|
1267
|
+
return me;
|
1268
|
+
};
|
1269
|
+
//------------------------------------------------------------------------------
|
1270
|
+
//------------------------------------------------------------------------------
|
1271
|
+
//------------------------------------------------------------------------------
|
1272
|
+
this.$type = type;
|
1273
|
+
this.$options = _processInput(options);
|
1274
|
+
// window.console.log(me);
|
1275
|
+
_init();
|
1276
|
+
};
|
1277
|
+
|
1278
|
+
Lobibox.notify = function(type, options){
|
1279
|
+
if (["info", "warning", "error", "success"].indexOf(type) > -1){
|
1280
|
+
return new LobiboxNotify(type, options);
|
1281
|
+
}
|
1282
|
+
};
|
1283
|
+
//User can set default options to this variable
|
1284
|
+
Lobibox.notify.DEFAULTS = {
|
1285
|
+
title: true, // Title of notification. If you do not include the title in options it will automatically takes its value
|
1286
|
+
//from Lobibox.notify.OPTIONS object depending of the type of the notifications or set custom string. Set this false to disable title
|
1287
|
+
size: 'normal', // normal, mini, large
|
1288
|
+
soundPath: 'src/sounds/', // The folder path where sounds are located
|
1289
|
+
soundExt: '.ogg', // Default extension for all sounds
|
1290
|
+
showClass: 'zoomIn', // Show animation class.
|
1291
|
+
hideClass: 'zoomOut', // Hide animation class.
|
1292
|
+
icon: true, // Icon of notification. Leave as is for default icon or set custom string
|
1293
|
+
msg: '', // Message of notification
|
1294
|
+
img: null, // Image source string
|
1295
|
+
closable: true, // Make notifications closable
|
1296
|
+
delay: 5000, // Hide notification after this time (in miliseconds)
|
1297
|
+
delayIndicator: true, // Show timer indicator
|
1298
|
+
closeOnClick: true, // Close notifications by clicking on them
|
1299
|
+
width: 400, // Width of notification box
|
1300
|
+
sound: true, // Sound of notification. Set this false to disable sound. Leave as is for default sound or set custom soud path
|
1301
|
+
position: "bottom right" // Place to show notification. Available options: "top left", "top right", "bottom left", "bottom right"
|
1302
|
+
};
|
1303
|
+
//This variable is necessary.
|
1304
|
+
Lobibox.notify.OPTIONS = {
|
1305
|
+
'class': 'animated-fast',
|
1306
|
+
large: {
|
1307
|
+
width: 500
|
1308
|
+
},
|
1309
|
+
mini: {
|
1310
|
+
'class': 'notify-mini'
|
1311
|
+
},
|
1312
|
+
success: {
|
1313
|
+
'class': 'lobibox-notify-success',
|
1314
|
+
'title': 'Success',
|
1315
|
+
'icon': 'glyphicon glyphicon-ok-sign',
|
1316
|
+
sound: 'sound2'
|
1317
|
+
},
|
1318
|
+
error: {
|
1319
|
+
'class': 'lobibox-notify-error',
|
1320
|
+
'title': 'Error',
|
1321
|
+
'icon': 'glyphicon glyphicon-remove-sign',
|
1322
|
+
sound: 'sound4'
|
1323
|
+
},
|
1324
|
+
warning: {
|
1325
|
+
'class': 'lobibox-notify-warning',
|
1326
|
+
'title': 'Warning',
|
1327
|
+
'icon': 'glyphicon glyphicon-exclamation-sign',
|
1328
|
+
sound: 'sound5'
|
1329
|
+
},
|
1330
|
+
info: {
|
1331
|
+
'class': 'lobibox-notify-info',
|
1332
|
+
'title': 'Information',
|
1333
|
+
'icon': 'glyphicon glyphicon-info-sign',
|
1334
|
+
sound: 'sound6'
|
1335
|
+
}
|
1336
|
+
};
|
1337
|
+
})();
|
1338
|
+
|
1339
|
+
|