lobiboxing-rails 1.2.4

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.
@@ -0,0 +1,1136 @@
1
+ //Author : @arboshiki
2
+ //create lobibox object
3
+ var Lobibox = Lobibox || {};
4
+ (function () {
5
+
6
+ Lobibox.counter = 0;
7
+ //------------------------------------------------------------------------------
8
+ //------------------------------------------------------------------------------
9
+
10
+ //User can set default properties for prompt in the following way
11
+ //Lobibox.prompt.DEFAULT_OPTIONS = object;
12
+ Lobibox.prompt = function (type, options) {
13
+ return new LobiboxPrompt(type, options);
14
+ };
15
+ //User can set default properties for confirm in the following way
16
+ //Lobibox.confirm.DEFAULT_OPTIONS = object;
17
+ Lobibox.confirm = function (options) {
18
+ return new LobiboxConfirm(options);
19
+ };
20
+ //User can set default properties for progress in the following way
21
+ //Lobibox.progress.DEFAULT_OPTIONS = object;
22
+ Lobibox.progress = function (options) {
23
+ return new LobiboxProgress(options);
24
+ };
25
+ //Create empty objects in order user to be able to set default options in the following way
26
+ //Lobibox.error.DEFAULT_OPTIONS = object;
27
+ //Lobibox.success.DEFAULT_OPTIONS = object;
28
+ //Lobibox.warning.DEFAULT_OPTIONS = object;
29
+ //Lobibox.info.DEFAULT_OPTIONS = object;
30
+
31
+ Lobibox.error = {};
32
+ Lobibox.success = {};
33
+ Lobibox.warning = {};
34
+ Lobibox.info = {};
35
+
36
+ //User can set default properties for alert in the following way
37
+ //Lobibox.alert.DEFAULT_OPTIONS = object;
38
+ Lobibox.alert = function (type, options) {
39
+ if (["success", "error", "warning", "info"].indexOf(type) > -1) {
40
+ return new LobiboxAlert(type, options);
41
+ }
42
+ };
43
+ //User can set default properties for window in the following way
44
+ //Lobibox.window.DEFAULT_OPTIONS = object;
45
+ Lobibox.window = function (options) {
46
+ return new LobiboxWindow('window', options);
47
+ };
48
+
49
+
50
+ /**
51
+ * Base prototype for all messageboxes and window
52
+ */
53
+ var LobiboxBase = {
54
+ $type: null,
55
+ $el: null,
56
+ $options: null,
57
+ debug: function () {
58
+ if (this.$options.debug) {
59
+ window.console.debug.apply(window.console, arguments);
60
+ }
61
+ },
62
+ _processInput: function (options) {
63
+ if ($.isArray(options.buttons)) {
64
+ var btns = {};
65
+ for (var i = 0; i < options.buttons.length; i++) {
66
+ btns[options.buttons[i]] = Lobibox.base.OPTIONS.buttons[options.buttons[i]];
67
+ }
68
+ options.buttons = btns;
69
+ }
70
+ options.customBtnClass = options.customBtnClass ? options.customBtnClass : Lobibox.base.DEFAULTS.customBtnClass;
71
+ for (var i in options.buttons) {
72
+ if (options.buttons.hasOwnProperty(i)) {
73
+ var btn = options.buttons[i];
74
+ btn = $.extend({}, Lobibox.base.OPTIONS.buttons[i], btn);
75
+ if (!btn['class']) {
76
+ btn['class'] = options.customBtnClass;
77
+ }
78
+ options.buttons[i] = btn;
79
+ }
80
+ }
81
+ options = $.extend({}, Lobibox.base.DEFAULTS, options);
82
+ if (options.showClass === undefined) {
83
+ options.showClass = Lobibox.base.OPTIONS.showClass;
84
+ }
85
+ if (options.hideClass === undefined) {
86
+ options.hideClass = Lobibox.base.OPTIONS.hideClass;
87
+ }
88
+ if (options.baseClass === undefined) {
89
+ options.baseClass = Lobibox.base.OPTIONS.baseClass;
90
+ }
91
+ if (options.delayToRemove === undefined) {
92
+ options.delayToRemove = Lobibox.base.OPTIONS.delayToRemove;
93
+ }
94
+ if (!options.iconClass) {
95
+ options.iconClass = Lobibox.base.OPTIONS.icons[options.iconSource][this.$type];
96
+ }
97
+ return options;
98
+ },
99
+ _init: function () {
100
+ var me = this;
101
+
102
+ me._createMarkup();
103
+ me.setTitle(me.$options.title);
104
+ if (me.$options.draggable && !me._isMobileScreen()) {
105
+ me.$el.addClass('draggable');
106
+ me._enableDrag();
107
+ }
108
+ if (me.$options.closeButton) {
109
+ me._addCloseButton();
110
+ }
111
+ if (me.$options.closeOnEsc) {
112
+ $(document).on('keyup.lobibox', function (ev) {
113
+ if (ev.which === 27) {
114
+ me.destroy();
115
+ }
116
+ });
117
+ }
118
+ if (me.$options.baseClass) {
119
+ me.$el.addClass(me.$options.baseClass);
120
+ }
121
+ if (me.$options.showClass) {
122
+ me.$el.removeClass(me.$options.hideClass);
123
+ me.$el.addClass(me.$options.showClass);
124
+ }
125
+ me.$el.data('lobibox', me);
126
+ },
127
+
128
+ /**
129
+ * Calculate top, left position based on string keyword
130
+ *
131
+ * @param {string} position "'top', 'center', 'bottom'"
132
+ * @returns {{left: number, top: number}}
133
+ * @private
134
+ */
135
+ _calculatePosition: function (position) {
136
+ var me = this;
137
+ var top;
138
+ if (position === 'top') {
139
+ top = 30;
140
+ } else if (position === 'bottom') {
141
+ top = $(window).outerHeight() - me.$el.outerHeight() - 30;
142
+ } else {
143
+ top = ($(window).outerHeight() - me.$el.outerHeight()) / 2;
144
+ }
145
+ var left = ($(window).outerWidth() - me.$el.outerWidth()) / 2;
146
+ return {
147
+ left: left,
148
+ top: top
149
+ };
150
+ },
151
+
152
+ _createButton: function (type, op) {
153
+ var me = this;
154
+ var btn = $('<button></button>')
155
+ .addClass(op['class'])
156
+ .attr('data-type', type)
157
+ .html(op.text);
158
+ if (me.$options.callback && typeof me.$options.callback === 'function') {
159
+ btn.on('click.lobibox', function (ev) {
160
+ var bt = $(this);
161
+ me._onButtonClick(me.$options.buttons[type], type);
162
+ me.$options.callback(me, bt.data('type'), ev);
163
+ });
164
+ }
165
+ btn.click(function () {
166
+ me._onButtonClick(me.$options.buttons[type], type);
167
+ });
168
+ return btn;
169
+ },
170
+
171
+ _onButtonClick: function (buttonOptions, type) {
172
+ var me = this;
173
+
174
+ if ((type === 'ok' && me.$type === 'prompt' && me.isValid() || me.$type !== 'prompt' || type !== 'ok')
175
+ && buttonOptions && buttonOptions.closeOnClick) {
176
+ me.destroy();
177
+ }
178
+ },
179
+
180
+ _generateButtons: function () {
181
+ var me = this;
182
+ var btns = [];
183
+ for (var i in me.$options.buttons) {
184
+ if (me.$options.buttons.hasOwnProperty(i)) {
185
+ var op = me.$options.buttons[i];
186
+ var btn = me._createButton(i, op);
187
+ btns.push(btn);
188
+ }
189
+ }
190
+ return btns;
191
+ },
192
+ _createMarkup: function () {
193
+ var me = this;
194
+ var lobibox = $('<div class="lobibox"></div>');
195
+ lobibox.attr('data-is-modal', me.$options.modal);
196
+ var header = $('<div class="lobibox-header"></div>')
197
+ .append('<span class="lobibox-title"></span>')
198
+ ;
199
+ var body = $('<div class="lobibox-body"></div>');
200
+ lobibox.append(header);
201
+ lobibox.append(body);
202
+ if (me.$options.buttons && !$.isEmptyObject(me.$options.buttons)) {
203
+ var footer = $('<div class="lobibox-footer"></div>');
204
+ footer.append(me._generateButtons());
205
+ lobibox.append(footer);
206
+ if (Lobibox.base.OPTIONS.buttonsAlign.indexOf(me.$options.buttonsAlign) > -1) {
207
+ footer.addClass('text-' + me.$options.buttonsAlign);
208
+ }
209
+ }
210
+ me.$el = lobibox
211
+ .addClass(Lobibox.base.OPTIONS.modalClasses[me.$type])
212
+ ;
213
+ },
214
+ _setSize: function () {
215
+ var me = this;
216
+ me.setWidth(me.$options.width);
217
+ if (me.$options.height === 'auto') {
218
+ me.setHeight(me.$el.outerHeight());
219
+ } else {
220
+ me.setHeight(me.$options.height);
221
+ }
222
+ },
223
+ _calculateBodyHeight: function (height) {
224
+ var me = this;
225
+ var headerHeight = me.$el.find('.lobibox-header').outerHeight();
226
+ var footerHeight = me.$el.find('.lobibox-footer').outerHeight();
227
+ return height - (headerHeight ? headerHeight : 0) - (footerHeight ? footerHeight : 0);
228
+
229
+ },
230
+
231
+ /**
232
+ * Add backdrop in case if backdrop does not exist
233
+ *
234
+ * @private
235
+ */
236
+ _addBackdrop: function () {
237
+ if ($('.lobibox-backdrop').length === 0) {
238
+ $('body').append('<div class="lobibox-backdrop"></div>');
239
+ }
240
+ },
241
+
242
+ _triggerEvent: function (type) {
243
+ var me = this;
244
+ if (me.$options[type] && typeof me.$options[type] === 'function') {
245
+ me.$options[type](me);
246
+ }
247
+ },
248
+
249
+ _calculateWidth: function (width) {
250
+ var me = this;
251
+ width = Math.min(Math.max(width, me.$options.width), $(window).outerWidth());
252
+ if (width === $(window).outerWidth()) {
253
+ width -= 2 * me.$options.horizontalOffset;
254
+ }
255
+ return width;
256
+ },
257
+
258
+ _calculateHeight: function (height) {
259
+ var me = this;
260
+ console.log(me.$options.height);
261
+ height = Math.min(Math.max(height, me.$options.height), $(window).outerHeight());
262
+ if (height === $(window).outerHeight()) {
263
+ height -= 2 * me.$options.verticalOffset;
264
+ }
265
+ return height;
266
+ },
267
+
268
+ _addCloseButton: function () {
269
+ var me = this;
270
+ var closeBtn = $('<span class="btn-close">&times;</span>');
271
+ me.$el.find('.lobibox-header').append(closeBtn);
272
+ closeBtn.on('mousedown', function (ev) {
273
+ ev.stopPropagation();
274
+ });
275
+ closeBtn.on('click.lobibox', function () {
276
+ me.destroy();
277
+ });
278
+ },
279
+ _position: function () {
280
+ var me = this;
281
+
282
+ me._setSize();
283
+ var pos = me._calculatePosition();
284
+ me.setPosition(pos.left, pos.top);
285
+ },
286
+ _isMobileScreen: function () {
287
+ return $(window).outerWidth() < 768;
288
+ },
289
+ _enableDrag: function () {
290
+ var el = this.$el,
291
+ heading = el.find('.lobibox-header');
292
+
293
+ heading.on('mousedown.lobibox', function (ev) {
294
+ el.attr('offset-left', ev.offsetX);
295
+ el.attr('offset-top', ev.offsetY);
296
+ el.attr('allow-drag', 'true');
297
+ });
298
+ $(document).on('mouseup.lobibox', function () {
299
+ el.attr('allow-drag', 'false');
300
+ });
301
+ $(document).on('mousemove.lobibox', function (ev) {
302
+ if (el.attr('allow-drag') === 'true') {
303
+ var left = ev.clientX - parseInt(el.attr('offset-left'), 10) - parseInt(el.css('border-left-width'), 10);
304
+ var top = ev.clientY - parseInt(el.attr('offset-top'), 10) - parseInt(el.css('border-top-width'), 10);
305
+ el.css({
306
+ left: left,
307
+ top: top
308
+ });
309
+ }
310
+ });
311
+ },
312
+
313
+ /**
314
+ * Set the message of messagebox
315
+ *
316
+ * @param {string} msg "new message of messagebox"
317
+ * @returns {LobiboxBase}
318
+ * @private
319
+ */
320
+ _setContent: function (msg) {
321
+ var me = this;
322
+ me.$el.find('.lobibox-body').html(msg);
323
+ return me;
324
+ },
325
+
326
+ _beforeShow: function () {
327
+ var me = this;
328
+ me._triggerEvent('onShow');
329
+ },
330
+
331
+ _afterShow: function () {
332
+ var me = this;
333
+ Lobibox.counter++;
334
+ me.$el.attr('data-nth', Lobibox.counter);
335
+ if (!me.$options.draggable){
336
+ $(window).on('resize.lobibox-'+me.$el.attr('data-nth'), function(){
337
+ me.refreshWidth();
338
+ me.refreshHeight();
339
+ me.$el.css('left', '50%').css('margin-left', '-'+(me.$el.width()/2)+'px');
340
+ me.$el.css('top', '50%').css('margin-top', '-'+(me.$el.height()/2)+'px');
341
+ });
342
+ }
343
+
344
+ me._triggerEvent('shown');
345
+ },
346
+
347
+ _beforeClose: function () {
348
+ var me = this;
349
+ me._triggerEvent('beforeClose');
350
+ },
351
+
352
+ _afterClose: function () {
353
+ var me = this;
354
+ if (!me.$options.draggable){
355
+ $(window).off('resize.lobibox-'+me.$el.attr('data-nth'));
356
+ }
357
+ me._triggerEvent('closed');
358
+ },
359
+ //------------------------------------------------------------------------------
360
+ //--------------------------PUBLIC METHODS--------------------------------------
361
+ //------------------------------------------------------------------------------
362
+
363
+ /**
364
+ * Hide the messagebox
365
+ *
366
+ * @returns {LobiboxBase}
367
+ */
368
+ hide: function () {
369
+ var me = this;
370
+ if (me.$options.hideClass) {
371
+ me.$el.removeClass(me.$options.showClass);
372
+ me.$el.addClass(me.$options.hideClass);
373
+ setTimeout(function () {
374
+ callback();
375
+ }, me.$options.delayToRemove);
376
+ } else {
377
+ callback();
378
+ }
379
+ function callback() {
380
+ me.$el.addClass('lobibox-hidden');
381
+ if ($('.lobibox[data-is-modal=true]:not(.lobibox-hidden)').length === 0) {
382
+ $('.lobibox-backdrop').remove();
383
+ $('body').removeClass(Lobibox.base.OPTIONS.bodyClass);
384
+ }
385
+ }
386
+
387
+ return this;
388
+ },
389
+
390
+ /**
391
+ * Removes the messagebox from document
392
+ *
393
+ * @returns {LobiboxBase}
394
+ */
395
+ destroy: function () {
396
+ var me = this;
397
+ me._beforeClose();
398
+ if (me.$options.hideClass) {
399
+ me.$el.removeClass(me.$options.showClass).addClass(me.$options.hideClass);
400
+ setTimeout(function () {
401
+ callback();
402
+ }, me.$options.delayToRemove);
403
+ } else {
404
+ callback();
405
+ }
406
+ function callback() {
407
+ me.$el.remove();
408
+ if ($('.lobibox[data-is-modal=true]').length === 0) {
409
+ $('.lobibox-backdrop').remove();
410
+ $('body').removeClass(Lobibox.base.OPTIONS.bodyClass);
411
+ }
412
+ me._afterClose();
413
+ }
414
+
415
+ return this;
416
+ },
417
+
418
+ /**
419
+ * Set the width of messagebox
420
+ *
421
+ * @param {number} width "new width of messagebox"
422
+ * @returns {LobiboxBase}
423
+ */
424
+ setWidth: function (width) {
425
+ var me = this;
426
+ me.$el.css('width', me._calculateWidth(width));
427
+ return me;
428
+ },
429
+
430
+ refreshWidth: function(){
431
+ this.setWidth(this.$el.width());
432
+ },
433
+
434
+ refreshHeight: function(){
435
+ this.setHeight(this.$el.height());
436
+ },
437
+
438
+ /**
439
+ * Set the height of messagebox
440
+ *
441
+ * @param {number} height "new height of messagebox"
442
+ * @returns {LobiboxBase}
443
+ */
444
+ setHeight: function (height) {
445
+ var me = this;
446
+ me.$el.css('height', me._calculateHeight(height))
447
+ .find('.lobibox-body')
448
+ .css('height', me._calculateBodyHeight(me.$el.innerHeight()));
449
+ return me;
450
+ },
451
+
452
+ /**
453
+ * Set the width and height of messagebox
454
+ *
455
+ * @param {number} width "new width of messagebox"
456
+ * @param {number} height "new height of messagebox"
457
+ * @returns {LobiboxBase}
458
+ */
459
+ setSize: function (width, height) {
460
+ var me = this;
461
+ me.setWidth(width);
462
+ me.setHeight(height);
463
+ return me;
464
+ },
465
+
466
+ /**
467
+ * Set position of messagebox
468
+ *
469
+ * @param {number|String} left "left coordinate of messsagebox or string representaing position. Available: ('top', 'center', 'bottom')"
470
+ * @param {number} top
471
+ * @returns {LobiboxBase}
472
+ */
473
+ setPosition: function (left, top) {
474
+ var pos;
475
+ if (typeof left === 'number' && typeof top === 'number') {
476
+ pos = {
477
+ left: left,
478
+ top: top
479
+ };
480
+ } else if (typeof left === 'string') {
481
+ pos = this._calculatePosition(left);
482
+ }
483
+ this.$el.css(pos);
484
+ return this;
485
+ },
486
+ /**
487
+ * Set the title of messagebox
488
+ *
489
+ * @param {string} title "new title of messagebox"
490
+ * @returns {LobiboxBase}
491
+ */
492
+ setTitle: function (title) {
493
+ return this.$el.find('.lobibox-title').html(title);
494
+ },
495
+
496
+ /**
497
+ * Get the title of messagebox
498
+ *
499
+ * @returns {string}
500
+ */
501
+ getTitle: function () {
502
+ return this.$el.find('.lobibox-title').html();
503
+ },
504
+
505
+ /**
506
+ * Show messagebox
507
+ *
508
+ * @returns {LobiboxBase}
509
+ */
510
+ show: function () {
511
+ var me = this,
512
+ $body = $('body');
513
+
514
+ me._beforeShow();
515
+
516
+ me.$el.removeClass('lobibox-hidden');
517
+ $body.append(me.$el);
518
+ if (me.$options.buttons) {
519
+ var buttons = me.$el.find('.lobibox-footer').children();
520
+ buttons[0].focus();
521
+ }
522
+ if (me.$options.modal) {
523
+ $body.addClass(Lobibox.base.OPTIONS.bodyClass);
524
+ me._addBackdrop();
525
+ }
526
+ if (me.$options.delay !== false) {
527
+ setTimeout(function () {
528
+ me.destroy();
529
+ }, me.$options.delay);
530
+ }
531
+ me._afterShow();
532
+ return me;
533
+ }
534
+ };
535
+ //User can set default options by this variable
536
+ Lobibox.base = {};
537
+ Lobibox.base.OPTIONS = {
538
+ bodyClass: 'lobibox-open',
539
+
540
+ modalClasses: {
541
+ 'error': 'lobibox-error',
542
+ 'success': 'lobibox-success',
543
+ 'info': 'lobibox-info',
544
+ 'warning': 'lobibox-warning',
545
+ 'confirm': 'lobibox-confirm',
546
+ 'progress': 'lobibox-progress',
547
+ 'prompt': 'lobibox-prompt',
548
+ 'default': 'lobibox-default',
549
+ 'window': 'lobibox-window'
550
+ },
551
+ buttonsAlign: ['left', 'center', 'right'],
552
+ buttons: {
553
+ ok: {
554
+ 'class': 'lobibox-btn lobibox-btn-default',
555
+ text: 'OK',
556
+ closeOnClick: true
557
+ },
558
+ cancel: {
559
+ 'class': 'lobibox-btn lobibox-btn-cancel',
560
+ text: 'Cancel',
561
+ closeOnClick: true
562
+ },
563
+ yes: {
564
+ 'class': 'lobibox-btn lobibox-btn-yes',
565
+ text: 'Yes',
566
+ closeOnClick: true
567
+ },
568
+ no: {
569
+ 'class': 'lobibox-btn lobibox-btn-no',
570
+ text: 'No',
571
+ closeOnClick: true
572
+ }
573
+ },
574
+ icons: {
575
+ bootstrap: {
576
+ confirm: 'glyphicon glyphicon-question-sign',
577
+ success: 'glyphicon glyphicon-ok-sign',
578
+ error: 'glyphicon glyphicon-remove-sign',
579
+ warning: 'glyphicon glyphicon-exclamation-sign',
580
+ info: 'glyphicon glyphicon-info-sign'
581
+ },
582
+ fontAwesome: {
583
+ confirm: 'fa fa-question-circle',
584
+ success: 'fa fa-check-circle',
585
+ error: 'fa fa-times-circle',
586
+ warning: 'fa fa-exclamation-circle',
587
+ info: 'fa fa-info-circle'
588
+ }
589
+ }
590
+ };
591
+ Lobibox.base.DEFAULTS = {
592
+ horizontalOffset: 5, //If the messagebox is larger (in width) than window's width. The messagebox's width is reduced to window width - 2 * horizontalOffset
593
+ verticalOffset: 5, //If the messagebox is larger (in height) than window's height. The messagebox's height is reduced to window height - 2 * verticalOffset
594
+ width: 600,
595
+ height: 'auto', // Height is automatically calculated by width
596
+ closeButton: true, // Show close button or not
597
+ draggable: false, // Make messagebox draggable
598
+ customBtnClass: 'lobibox-btn lobibox-btn-default', // Class for custom buttons
599
+ modal: true,
600
+ debug: false,
601
+ buttonsAlign: 'center', // Position where buttons should be aligned
602
+ closeOnEsc: true, // Close messagebox on Esc press
603
+ delayToRemove: 200, // Time after which lobibox will be removed after remove call. (This option is for hide animation to finish)
604
+ delay: false, // Time to remove lobibox after shown
605
+ baseClass: 'animated-super-fast', // Base class to add all messageboxes
606
+ showClass: 'zoomIn', // Show animation class
607
+ hideClass: 'zoomOut', // Hide animation class
608
+ iconSource: 'bootstrap', // "bootstrap" or "fontAwesome" the library which will be used for icons
609
+
610
+ //events
611
+ //When messagebox show is called but before it is actually shown
612
+ onShow: null,
613
+ //After messagebox is shown
614
+ shown: null,
615
+ //When messagebox remove method is called but before it is actually hidden
616
+ beforeClose: null,
617
+ //After messagebox is hidden
618
+ closed: null
619
+ };
620
+ //------------------------------------------------------------------------------
621
+ //-------------------------LobiboxPrompt----------------------------------------
622
+ //------------------------------------------------------------------------------
623
+ function LobiboxPrompt(type, options) {
624
+ this.$input = null;
625
+ this.$type = 'prompt';
626
+ this.$promptType = type;
627
+
628
+ options = $.extend({}, Lobibox.prompt.DEFAULT_OPTIONS, options);
629
+
630
+ this.$options = this._processInput(options);
631
+
632
+ this._init();
633
+ this.debug(this);
634
+ }
635
+
636
+ LobiboxPrompt.prototype = $.extend({}, LobiboxBase, {
637
+ constructor: LobiboxPrompt,
638
+
639
+ _processInput: function (options) {
640
+ var me = this;
641
+
642
+ var mergedOptions = LobiboxBase._processInput.call(me, options);
643
+ mergedOptions.buttons = {
644
+ ok: Lobibox.base.OPTIONS.buttons.ok,
645
+ cancel: Lobibox.base.OPTIONS.buttons.cancel
646
+ };
647
+ options = $.extend({}, mergedOptions, LobiboxPrompt.DEFAULT_OPTIONS, options);
648
+ return options;
649
+ },
650
+
651
+ _init: function () {
652
+ var me = this;
653
+ LobiboxBase._init.call(me);
654
+ me.show();
655
+ },
656
+
657
+ _afterShow: function () {
658
+ var me = this;
659
+ me._setContent(me._createInput())._position();
660
+ me.$input.focus();
661
+ LobiboxBase._afterShow.call(me);
662
+ },
663
+
664
+ _createInput: function () {
665
+ var me = this,
666
+ label;
667
+ if (me.$options.multiline) {
668
+ me.$input = $('<textarea></textarea>').attr('rows', me.$options.lines);
669
+ } else {
670
+ me.$input = $('<input type="' + me.$promptType + '"/>');
671
+ }
672
+ me.$input.addClass('lobibox-input').attr(me.$options.attrs);
673
+ if (me.$options.value) {
674
+ me.setValue(me.$options.value);
675
+ }
676
+ if (me.$options.label) {
677
+ label = $('<label>' + me.$options.label + '</label>');
678
+ }
679
+ return $('<div></div>').append(label, me.$input);
680
+ },
681
+
682
+ /**
683
+ * Set value of input
684
+ *
685
+ * @param {string} val "value of input"
686
+ * @returns {LobiboxPrompt}
687
+ */
688
+ setValue: function (val) {
689
+ this.$input.val(val);
690
+ return this;
691
+ },
692
+
693
+ /**
694
+ * Get value of input
695
+ *
696
+ * @returns {String}
697
+ */
698
+ getValue: function () {
699
+ return this.$input.val();
700
+ },
701
+
702
+ isValid: function () {
703
+ var me = this,
704
+ $error = me.$el.find('.lobibox-input-error-message');
705
+
706
+ if (me.$options.required && !me.getValue()){
707
+ me.$input.addClass('invalid');
708
+ if ($error.length === 0){
709
+ me.$el.find('.lobibox-body').append('<p class="lobibox-input-error-message">'+me.$options.errorMessage+'</p>');
710
+ me._position();
711
+ me.$input.focus();
712
+ }
713
+ return false;
714
+ }
715
+ me.$input.removeClass('invalid');
716
+ $error.remove();
717
+ me._position();
718
+ me.$input.focus();
719
+
720
+ return true;
721
+ }
722
+ });
723
+
724
+ LobiboxPrompt.DEFAULT_OPTIONS = {
725
+ width: 400,
726
+ attrs: {}, // Object of any valid attribute of input field
727
+ value: '', // Value which is given to textfield when messagebox is created
728
+ multiline: false, // Set this true for multiline prompt
729
+ lines: 3, // This works only for multiline prompt. Number of lines
730
+ type: 'text', // Prompt type. Available types (text|number|color)
731
+ label: '', // Set some text which will be shown exactly on top of textfield
732
+ required: true,
733
+ errorMessage: 'The field is required'
734
+ };
735
+ //------------------------------------------------------------------------------
736
+ //-------------------------LobiboxConfirm---------------------------------------
737
+ //------------------------------------------------------------------------------
738
+ function LobiboxConfirm(options) {
739
+ this.$type = 'confirm';
740
+
741
+ // options = $.extend({}, Lobibox.confirm.DEFAULT_OPTIONS, options);
742
+
743
+ this.$options = this._processInput(options);
744
+ this._init();
745
+ this.debug(this);
746
+ }
747
+
748
+ LobiboxConfirm.prototype = $.extend({}, LobiboxBase, {
749
+ constructor: LobiboxConfirm,
750
+
751
+ _processInput: function (options) {
752
+ var me = this;
753
+
754
+ var mergedOptions = LobiboxBase._processInput.call(me, options);
755
+ mergedOptions.buttons = {
756
+ yes: Lobibox.base.OPTIONS.buttons.yes,
757
+ no: Lobibox.base.OPTIONS.buttons.no
758
+ };
759
+ options = $.extend({}, mergedOptions, Lobibox.confirm.DEFAULTS, options);
760
+ return options;
761
+ },
762
+
763
+ _init: function () {
764
+ var me = this;
765
+
766
+ LobiboxBase._init.call(me);
767
+ me.show();
768
+ },
769
+
770
+ _afterShow: function () {
771
+ var me = this;
772
+
773
+ var d = $('<div></div>');
774
+ if (me.$options.iconClass) {
775
+ d.append($('<div class="lobibox-icon-wrapper"></div>')
776
+ .append('<i class="lobibox-icon ' + me.$options.iconClass + '"></i>'))
777
+ ;
778
+ }
779
+ d.append('<div class="lobibox-body-text-wrapper"><span class="lobibox-body-text">' + me.$options.msg + '</span></div>');
780
+ me._setContent(d.html());
781
+
782
+ me._position();
783
+
784
+ LobiboxBase._afterShow.call(me);
785
+ }
786
+ });
787
+
788
+ Lobibox.confirm.DEFAULTS = {
789
+ title: 'Question',
790
+ width: 500
791
+ };
792
+ //------------------------------------------------------------------------------
793
+ //-------------------------LobiboxAlert------------------------------------------
794
+ //------------------------------------------------------------------------------
795
+ function LobiboxAlert(type, options) {
796
+ this.$type = type;
797
+
798
+ // options = $.extend({}, Lobibox.alert.DEFAULT_OPTIONS, Lobibox[type].DEFAULT_OPTIONS, options);
799
+
800
+ this.$options = this._processInput(options);
801
+
802
+ this._init();
803
+ this.debug(this);
804
+ }
805
+
806
+ LobiboxAlert.prototype = $.extend({}, LobiboxBase, {
807
+ constructor: LobiboxAlert,
808
+
809
+ _processInput: function (options) {
810
+
811
+ // ALERT_OPTIONS = $.extend({}, LobiboxAlert.OPTIONS, Lobibox.alert.DEFAULTS);
812
+ var me = this;
813
+ var mergedOptions = LobiboxBase._processInput.call(me, options);
814
+ mergedOptions.buttons = {
815
+ ok: Lobibox.base.OPTIONS.buttons.ok
816
+ };
817
+
818
+ options = $.extend({}, mergedOptions, Lobibox.alert.OPTIONS[me.$type], Lobibox.alert.DEFAULTS, options);
819
+
820
+ return options;
821
+ },
822
+
823
+ _init: function () {
824
+ var me = this;
825
+ LobiboxBase._init.call(me);
826
+ me.show();
827
+ },
828
+
829
+ _afterShow: function () {
830
+ var me = this;
831
+
832
+ var d = $('<div></div>');
833
+ if (me.$options.iconClass) {
834
+ d.append($('<div class="lobibox-icon-wrapper"></div>')
835
+ .append('<i class="lobibox-icon ' + me.$options.iconClass + '"></i>'))
836
+ ;
837
+ }
838
+ d.append('<div class="lobibox-body-text-wrapper"><span class="lobibox-body-text">' + me.$options.msg + '</span></div>');
839
+ me._setContent(d.html());
840
+ me._position();
841
+
842
+ LobiboxBase._afterShow.call(me);
843
+ }
844
+ });
845
+ Lobibox.alert.OPTIONS = {
846
+ warning: {
847
+ title: 'Warning'
848
+ },
849
+ info: {
850
+ title: 'Information'
851
+ },
852
+ success: {
853
+ title: 'Success'
854
+ },
855
+ error: {
856
+ title: 'Error'
857
+ }
858
+ };
859
+ //User can set default options by this variable
860
+ Lobibox.alert.DEFAULTS = {};
861
+ //------------------------------------------------------------------------------
862
+ //-------------------------LobiboxProgress--------------------------------------
863
+ //------------------------------------------------------------------------------
864
+ function LobiboxProgress(options) {
865
+ this.$type = 'progress';
866
+ this.$progressBarElement = null;
867
+ this.$options = this._processInput(options);
868
+ this.$progress = 0;
869
+
870
+ this._init();
871
+ this.debug(this);
872
+ }
873
+
874
+ LobiboxProgress.prototype = $.extend({}, LobiboxBase, {
875
+ constructor: LobiboxProgress,
876
+
877
+ _processInput: function (options) {
878
+ var me = this;
879
+ var mergedOptions = LobiboxBase._processInput.call(me, options);
880
+
881
+ options = $.extend({}, mergedOptions, Lobibox.progress.DEFAULTS, options);
882
+ return options;
883
+ },
884
+
885
+ _init: function () {
886
+ var me = this;
887
+
888
+ LobiboxBase._init.call(me);
889
+ me.show();
890
+ },
891
+
892
+ _afterShow: function () {
893
+ var me = this;
894
+
895
+ if (me.$options.progressTpl) {
896
+ me.$progressBarElement = $(me.$options.progressTpl);
897
+ } else {
898
+ me.$progressBarElement = me._createProgressbar();
899
+ }
900
+ var label;
901
+ if (me.$options.label) {
902
+ label = $('<label>' + me.$options.label + '</label>');
903
+ }
904
+ var innerHTML = $('<div></div>').append(label, me.$progressBarElement);
905
+ me._setContent(innerHTML);
906
+ me._position();
907
+
908
+ LobiboxBase._afterShow.call(me);
909
+ },
910
+
911
+ _createProgressbar: function () {
912
+ var me = this;
913
+ var outer = $('<div class="lobibox-progress-bar-wrapper lobibox-progress-outer"></div>')
914
+ .append('<div class="lobibox-progress-bar lobibox-progress-element"></div>')
915
+ ;
916
+ if (me.$options.showProgressLabel) {
917
+ outer.append('<span class="lobibox-progress-text" data-role="progress-text"></span>');
918
+ }
919
+
920
+ return outer;
921
+ },
922
+
923
+ /**
924
+ * Set progress value
925
+ *
926
+ * @param {number} progress "progress value"
927
+ * @returns {LobiboxProgress}
928
+ */
929
+ setProgress: function (progress) {
930
+ var me = this;
931
+ if (me.$progress === 100) {
932
+ return;
933
+ }
934
+ progress = Math.min(100, Math.max(0, progress));
935
+ me.$progress = progress;
936
+ me._triggerEvent('progressUpdated');
937
+ if (me.$progress === 100) {
938
+ me._triggerEvent('progressCompleted');
939
+ }
940
+ me.$el.find('.lobibox-progress-element').css('width', progress.toFixed(1) + "%");
941
+ me.$el.find('[data-role="progress-text"]').html(progress.toFixed(1) + "%");
942
+ return me;
943
+ },
944
+
945
+ /**
946
+ * Get progress value
947
+ *
948
+ * @returns {number}
949
+ */
950
+ getProgress: function () {
951
+ return this.$progress;
952
+ }
953
+ });
954
+
955
+ Lobibox.progress.DEFAULTS = {
956
+ width: 500,
957
+ showProgressLabel: true, // Show percentage of progress
958
+ label: '', // Show progress label
959
+ progressTpl: false, //Template of progress bar
960
+
961
+ //Events
962
+ progressUpdated: null,
963
+ progressCompleted: null
964
+ };
965
+ //------------------------------------------------------------------------------
966
+ //-------------------------LobiboxWindow----------------------------------------
967
+ //------------------------------------------------------------------------------
968
+ function LobiboxWindow(type, options) {
969
+ this.$type = type;
970
+
971
+ this.$options = this._processInput(options);
972
+
973
+ this._init();
974
+ this.debug(this);
975
+ }
976
+
977
+ LobiboxWindow.prototype = $.extend({}, LobiboxBase, {
978
+ constructor: LobiboxWindow,
979
+ _processInput: function (options) {
980
+ var me = this;
981
+ var mergedOptions = LobiboxBase._processInput.call(me, options);
982
+
983
+ if (options.content && typeof options.content === 'function') {
984
+ options.content = options.content();
985
+ }
986
+ if (options.content instanceof jQuery) {
987
+ options.content = options.content.clone();
988
+ }
989
+ options = $.extend({}, mergedOptions, Lobibox.window.DEFAULTS, options);
990
+ return options;
991
+ },
992
+
993
+ _init: function () {
994
+ var me = this;
995
+
996
+ LobiboxBase._init.call(me);
997
+ me.setContent(me.$options.content);
998
+ if (me.$options.url && me.$options.autoload) {
999
+ if (!me.$options.showAfterLoad) {
1000
+ me.show();
1001
+ }
1002
+ me.load(function () {
1003
+ if (me.$options.showAfterLoad) {
1004
+ me.show();
1005
+ }
1006
+ });
1007
+ } else {
1008
+ me.show();
1009
+ }
1010
+ },
1011
+
1012
+ _afterShow: function () {
1013
+ var me = this;
1014
+
1015
+ me._position();
1016
+
1017
+ LobiboxBase._afterShow.call(me);
1018
+ },
1019
+
1020
+ /**
1021
+ * Setter method for <code>params</code> option
1022
+ *
1023
+ * @param {object} params "new params"
1024
+ * @returns {LobiboxWindow}
1025
+ */
1026
+ setParams: function (params) {
1027
+ var me = this;
1028
+ me.$options.params = params;
1029
+ return me;
1030
+ },
1031
+ /**
1032
+ * Getter method for <code>params</code>
1033
+ *
1034
+ * @returns {object}
1035
+ */
1036
+ getParams: function () {
1037
+ var me = this;
1038
+ return me.$options.params;
1039
+ },
1040
+ /**
1041
+ * Setter method of <code>loadMethod</code> option
1042
+ *
1043
+ * @param {string} method "new method"
1044
+ * @returns {LobiboxWindow}
1045
+ */
1046
+ setLoadMethod: function (method) {
1047
+ var me = this;
1048
+ me.$options.loadMethod = method;
1049
+ return me;
1050
+ },
1051
+ /**
1052
+ * Getter method for <code>loadMethod</code> option
1053
+ *
1054
+ * @returns {string}
1055
+ */
1056
+ getLoadMethod: function () {
1057
+ var me = this;
1058
+ return me.$options.loadMethod;
1059
+ },
1060
+ /**
1061
+ * Setter method of <code>content</code> option.
1062
+ * Change the content of window
1063
+ *
1064
+ * @param {string} content "new content"
1065
+ * @returns {LobiboxWindow}
1066
+ */
1067
+ setContent: function (content) {
1068
+ var me = this;
1069
+ me.$options.content = content;
1070
+ me.$el.find('.lobibox-body').html('').append(content);
1071
+ return me;
1072
+ },
1073
+ /**
1074
+ * Getter method of <code>content</code> option
1075
+ *
1076
+ * @returns {string}
1077
+ */
1078
+ getContent: function () {
1079
+ var me = this;
1080
+ return me.$options.content;
1081
+ },
1082
+ /**
1083
+ * Setter method of <code>url</code> option
1084
+ *
1085
+ * @param {string} url "new url"
1086
+ * @returns {LobiboxWindow}
1087
+ */
1088
+ setUrl: function (url) {
1089
+ this.$options.url = url;
1090
+ return this;
1091
+ },
1092
+ /**
1093
+ * Getter method of <code>url</code> option
1094
+ *
1095
+ * @returns {String}
1096
+ */
1097
+ getUrl: function () {
1098
+ return this.$options.url;
1099
+ },
1100
+ /**
1101
+ * Loads content to window by ajax from specific url
1102
+ *
1103
+ * @param {Function} callback "callback function"
1104
+ * @returns {LobiboxWindow}
1105
+ */
1106
+ load: function (callback) {
1107
+ var me = this;
1108
+ if (!me.$options.url) {
1109
+ return me;
1110
+ }
1111
+ $.ajax(me.$options.url, {
1112
+ method: me.$options.loadMethod,
1113
+ data: me.$options.params
1114
+ }).done(function (res) {
1115
+ me.setContent(res);
1116
+ if (callback && typeof callback === 'function') {
1117
+ callback(res);
1118
+ }
1119
+ });
1120
+ return me;
1121
+ }
1122
+ });
1123
+
1124
+ Lobibox.window.DEFAULTS = {
1125
+ width: 480,
1126
+ height: 600,
1127
+ content: '', // HTML Content of window
1128
+ url: '', // URL which will be used to load content
1129
+ draggable: true, // Override default option
1130
+ autoload: true, // Auto load from given url when window is created
1131
+ loadMethod: 'GET', // Ajax method to load content
1132
+ showAfterLoad: true, // Show window after content is loaded or show and then load content
1133
+ params: {} // Parameters which will be send by ajax for loading content
1134
+ };
1135
+
1136
+ })();