PageSourceSearch

https://nyxgameawards.com/vendor/jquery-confirm/js/jquery-confirm.js

js nyxgameawards.com collected 2026-09-25 03:04:18 UTC 50,505 bytes, 1,345 lines download raw bytes

1/*!
2 * jquery-confirm v3.3.2 (http://craftpip.github.io/jquery-confirm/)
3 * Author: Boniface Pereira
4 * Website: www.craftpip.com
5 * Contact: [email protected]
6 *
7 * Copyright 2013-2017 jquery-confirm
8 * Licensed under MIT (https://github.com/craftpip/jquery-confirm/blob/master/LICENSE)
9 */
10
11if (typeof jQuery === 'undefined') {
12    throw new Error('jquery-confirm requires jQuery');
13}
14
15var jconfirm, Jconfirm;
16(function ($, window) {
17    "use strict";
18
19    $.fn.confirm = function (options, option2) {
20        if (typeof options === 'undefined') options = {};
21        if (typeof options === 'string') {
22            options = {
23                content: options,
24                title: (option2) ? option2 : false
25            };
26        }
27        /*
28         *  Alias of $.confirm to emulate native confirm()
29         */
30        $(this).each(function () {
31            var $this = $(this);
32            if ($this.attr('jc-attached')) {
33                console.warn('jConfirm has already been attached to this element ', $this[0]);
34                return;
35            }
36
37            $this.on('click', function (e) {
38                e.preventDefault();
39                var jcOption = $.extend({}, options);
40                if ($this.attr('data-title'))
41                    jcOption['title'] = $this.attr('data-title');
42                if ($this.attr('data-content'))
43                    jcOption['content'] = $this.attr('data-content');
44                if (typeof jcOption['buttons'] == 'undefined')
45                    jcOption['buttons'] = {};
46
47                jcOption['$target'] = $this;
48                if ($this.attr('href') && Object.keys(jcOption['buttons']).length == 0) {
49                    var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
50                    var firstBtn = Object.keys(buttons)[0];
51                    jcOption['buttons'] = buttons;
52                    jcOption.buttons[firstBtn].action = function () {
53                        location.href = $this.attr('href');
54                    };
55                }
56                jcOption['closeIcon'] = false;
57                var instance = $.confirm(jcOption);
58            });
59
60            $this.attr('jc-attached', true);
61        });
62        return $(this);
63    };
64    $.confirm = function (options, option2) {
65        if (typeof options === 'undefined') options = {};
66        if (typeof options === 'string') {
67            options = {
68                content: options,
69                title: (option2) ? option2 : false
70            };
71        }
72
73        var putDefaultButtons = !(options['buttons'] == false);
74
75        if (typeof options['buttons'] != 'object')
76            options['buttons'] = {};
77
78        if (Object.keys(options['buttons']).length == 0 && putDefaultButtons) {
79            var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
80            options['buttons'] = buttons;
81        }
82
83        /*
84         *  Alias of jconfirm
85         */
86        return jconfirm(options);
87    };
88    $.alert = function (options, option2) {
89        if (typeof options === 'undefined') options = {};
90        if (typeof options === 'string') {
91            options = {
92                content: options,
93                title: (option2) ? option2 : false
94            };
95        }
96
97        var putDefaultButtons = !(options['buttons'] == false);
98
99        if (typeof options.buttons != 'object')
100            options.buttons = {};
101
102        if (Object.keys(options['buttons']).length == 0 && putDefaultButtons) {
103            var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
104            var firstBtn = Object.keys(buttons)[0];
105            options['buttons'][firstBtn] = buttons[firstBtn];
106        }
107        /*
108         *  Alias of jconfirm
109         */
110        return jconfirm(options);
111    };
112    $.dialog = function (options, option2) {
113        if (typeof options === 'undefined') options = {};
114        if (typeof options === 'string') {
115            options = {
116                content: options,
117                title: (option2) ? option2 : false,
118                closeIcon: function () {
119                    // Just close the modal
120                }
121            };
122        }
123
124        options['buttons'] = {}; // purge buttons
125
126        if (typeof options['closeIcon'] == 'undefined') {
127            // Dialog must have a closeIcon.
128            options['closeIcon'] = function () {
129            }
130        }
131        /*
132         *  Alias of jconfirm
133         */
134        options.confirmKeys = [13];
135        return jconfirm(options);
136    };
137
138    jconfirm = function (options) {
139        if (typeof options === 'undefined') options = {};
140        /*
141         * initial function for calling.
142         */
143        var pluginOptions = $.extend(true, {}, jconfirm.pluginDefaults);
144        if (jconfirm.defaults) {
145            pluginOptions = $.extend(true, pluginOptions, jconfirm.defaults);
146        }
147
148        /*
149         * merge options with plugin defaults.
150         */
151        pluginOptions = $.extend(true, {}, pluginOptions, options);
152        var instance = new Jconfirm(pluginOptions);
153        jconfirm.instances.push(instance);
154        return instance;
155    };
156    Jconfirm = function (options) {
157        /*
158         * constructor function Jconfirm,
159         * options = user options.
160         */
161        $.extend(this, options);
162        this._init();
163    };
164    Jconfirm.prototype = {
165        _init: function () {
166            var that = this;
167
168            if (!jconfirm.instances.length)
169                jconfirm.lastFocused = $('body').find(':focus');
170
171            this._id = Math.round(Math.random() * 99999);
172            /**
173             * contentParsed maintains the contents for $content, before it is put in DOM
174             */
175            this.contentParsed = $(document.createElement('div'));
176
177            if (!this.lazyOpen) {
178                setTimeout(function () {
179                    that.open();
180                }, 0);
181            }
182        },
183        _buildHTML: function () {
184            var that = this;
185
186            // prefix the animation string and store in animationParsed
187            this._parseAnimation(this.animation, 'o');
188            this._parseAnimation(this.closeAnimation, 'c');
189            this._parseBgDismissAnimation(this.backgroundDismissAnimation);
190            this._parseColumnClass(this.columnClass);
191            this._parseTheme(this.theme);
192            this._parseType(this.type);
193
194            /*
195             * Append html.
196             */
197            var template = $(this.template);
198            template.find('.jconfirm-box').addClass(this.animationParsed).addClass(this.backgroundDismissAnimationParsed).addClass(this.typeParsed);
199
200            if (this.typeAnimated)
201                template.find('.jconfirm-box').addClass('jconfirm-type-animated');
202
203            if (this.useBootstrap) {
204                template.find('.jc-bs3-row').addClass(this.bootstrapClasses.row);
205                template.find('.jc-bs3-row').addClass('justify-content-md-center justify-content-sm-center justify-content-xs-center justify-content-lg-center');
206
207                template.find('.jconfirm-box-container').addClass(this.columnClassParsed);
208
209                if (this.containerFluid)
210                    template.find('.jc-bs3-container').addClass(this.bootstrapClasses.containerFluid);
211                else
212                    template.find('.jc-bs3-container').addClass(this.bootstrapClasses.container);
213            } else {
214                template.find('.jconfirm-box').css('width', this.boxWidth);
215            }
216
217            if (this.titleClass)
218                template.find('.jconfirm-title-c').addClass(this.titleClass);
219
220            template.addClass(this.themeParsed);
221            var ariaLabel = 'jconfirm-box' + this._id;
222            template.find('.jconfirm-box').attr('aria-labelledby', ariaLabel).attr('tabindex', -1);
223            template.find('.jconfirm-content').attr('id', ariaLabel);
224            if (this.bgOpacity !== null)
225                template.find('.jconfirm-bg').css('opacity', this.bgOpacity);
226            if (this.rtl)
227                template.addClass('jconfirm-rtl');
228
229            this.$el = template.appendTo(this.container);
230            this.$jconfirmBoxContainer = this.$el.find('.jconfirm-box-container');
231            this.$jconfirmBox = this.$body = this.$el.find('.jconfirm-box');
232            this.$jconfirmBg = this.$el.find('.jconfirm-bg');
233            this.$title = this.$el.find('.jconfirm-title');
234            this.$titleContainer = this.$el.find('.jconfirm-title-c');
235            this.$content = this.$el.find('div.jconfirm-content');
236            this.$contentPane = this.$el.find('.jconfirm-content-pane');
237            this.$icon = this.$el.find('.jconfirm-icon-c');
238            this.$closeIcon = this.$el.find('.jconfirm-closeIcon');
239            this.$holder = this.$el.find('.jconfirm-holder');
240            // this.$content.css(this._getCSS(this.animationSpeed, this.animationBounce));
241            this.$btnc = this.$el.find('.jconfirm-buttons');
242            this.$scrollPane = this.$el.find('.jconfirm-scrollpane');
243
244            that.setStartingPoint();
245
246            // for loading content via URL
247            this._contentReady = $.Deferred();
248            this._modalReady = $.Deferred();
249            this.$holder.css({
250                'padding-top': this.offsetTop,
251                'padding-bottom': this.offsetBottom,
252            });
253
254            this.setTitle();
255            this.setIcon();
256            this._setButtons();
257            this._parseContent();
258            this.initDraggable();
259
260            if (this.isAjax)
261                this.showLoading(false);
262
263            $.when(this._contentReady, this._modalReady).then(function () {
264                if (that.isAjaxLoading)
265                    setTimeout(function () {
266                        that.isAjaxLoading = false;
vendor: 17,136 bytes, lines 267-689
267                        that.setContent();
268                        that.setTitle();
269                        that.setIcon();
270                        setTimeout(function () {
271                            that.hideLoading(false);
272                            that._updateContentMaxHeight();
273                        }, 100);
274                        if (typeof that.onContentReady === 'function')
275                            that.onContentReady();
276                    }, 50);
277                else {
278                    // that.setContent();
279                    that._updateContentMaxHeight();
280                    that.setTitle();
281                    that.setIcon();
282                    if (typeof that.onContentReady === 'function')
283                        that.onContentReady();
284                }
285
286                // start countdown after content has loaded.
287                if (that.autoClose)
288                    that._startCountDown();
289            });
290
291            this._watchContent();
292
293            if (this.animation === 'none') {
294                this.animationSpeed = 1;
295                this.animationBounce = 1;
296            }
297
298            this.$body.css(this._getCSS(this.animationSpeed, this.animationBounce));
299            this.$contentPane.css(this._getCSS(this.animationSpeed, 1));
300            this.$jconfirmBg.css(this._getCSS(this.animationSpeed, 1));
301            this.$jconfirmBoxContainer.css(this._getCSS(this.animationSpeed, 1));
302        },
303        _typePrefix: 'jconfirm-type-',
304        typeParsed: '',
305        _parseType: function (type) {
306            this.typeParsed = this._typePrefix + type;
307        },
308        setType: function (type) {
309            var oldClass = this.typeParsed;
310            this._parseType(type);
311            this.$jconfirmBox.removeClass(oldClass).addClass(this.typeParsed);
312        },
313        themeParsed: '',
314        _themePrefix: 'jconfirm-',
315        setTheme: function (theme) {
316            var previous = this.theme;
317            this.theme = theme || this.theme;
318            this._parseTheme(this.theme);
319            if (previous)
320                this.$el.removeClass(previous);
321            this.$el.addClass(this.themeParsed);
322            this.theme = theme;
323        },
324        _parseTheme: function (theme) {
325            var that = this;
326            theme = theme.split(',');
327            $.each(theme, function (k, a) {
328                if (a.indexOf(that._themePrefix) === -1)
329                    theme[k] = that._themePrefix + $.trim(a);
330            });
331            this.themeParsed = theme.join(' ').toLowerCase();
332        },
333        backgroundDismissAnimationParsed: '',
334        _bgDismissPrefix: 'jconfirm-hilight-',
335        _parseBgDismissAnimation: function (bgDismissAnimation) {
336            var animation = bgDismissAnimation.split(',');
337            var that = this;
338            $.each(animation, function (k, a) {
339                if (a.indexOf(that._bgDismissPrefix) === -1)
340                    animation[k] = that._bgDismissPrefix + $.trim(a);
341            });
342            this.backgroundDismissAnimationParsed = animation.join(' ').toLowerCase();
343        },
344        animationParsed: '',
345        closeAnimationParsed: '',
346        _animationPrefix: 'jconfirm-animation-',
347        setAnimation: function (animation) {
348            this.animation = animation || this.animation;
349            this._parseAnimation(this.animation, 'o');
350        },
351        _parseAnimation: function (animation, which) {
352            which = which || 'o'; // parse what animation and store where. open or close?
353            var animations = animation.split(',');
354            var that = this;
355            $.each(animations, function (k, a) {
356                if (a.indexOf(that._animationPrefix) === -1)
357                    animations[k] = that._animationPrefix + $.trim(a);
358            });
359            var a_string = animations.join(' ').toLowerCase();
360            if (which === 'o')
361                this.animationParsed = a_string;
362            else
363                this.closeAnimationParsed = a_string;
364
365            return a_string;
366        },
367        setCloseAnimation: function (closeAnimation) {
368            this.closeAnimation = closeAnimation || this.closeAnimation;
369            this._parseAnimation(this.closeAnimation, 'c');
370        },
371        setAnimationSpeed: function (speed) {
372            this.animationSpeed = speed || this.animationSpeed;
373            // this.$body.css(this._getCSS(this.animationSpeed, this.animationBounce));
374        },
375        columnClassParsed: '',
376        setColumnClass: function (colClass) {
377            if (!this.useBootstrap) {
378                console.warn("cannot set columnClass, useBootstrap is set to false");
379                return;
380            }
381            this.columnClass = colClass || this.columnClass;
382            this._parseColumnClass(this.columnClass);
383            this.$jconfirmBoxContainer.addClass(this.columnClassParsed);
384        },
385        _updateContentMaxHeight: function () {
386            var height = $(window).height() - (this.$jconfirmBox.outerHeight() - this.$contentPane.outerHeight()) - (this.offsetTop + this.offsetBottom);
387            this.$contentPane.css({
388                'max-height': height + 'px'
389            });
390        },
391        setBoxWidth: function (width) {
392            if (this.useBootstrap) {
393                console.warn("cannot set boxWidth, useBootstrap is set to true");
394                return;
395            }
396            this.boxWidth = width;
397            this.$jconfirmBox.css('width', width);
398        },
399        _parseColumnClass: function (colClass) {
400            colClass = colClass.toLowerCase();
401            var p;
402            switch (colClass) {
403                case 'xl':
404                case 'xlarge':
405                    p = 'col-md-12';
406                    break;
407                case 'l':
408                case 'large':
409                    p = 'col-md-8 col-md-offset-2';
410                    break;
411                case 'm':
412                case 'medium':
413                    p = 'col-md-6 col-md-offset-3';
414                    break;
415                case 's':
416                case 'small':
417                    p = 'col-md-4 col-md-offset-4';
418                    break;
419                case 'xs':
420                case 'xsmall':
421                    p = 'col-md-2 col-md-offset-5';
422                    break;
423                default:
424                    p = colClass;
425            }
426            this.columnClassParsed = p;
427        },
428        initDraggable: function () {
429            var that = this;
430            var $t = this.$titleContainer;
431
432            this.resetDrag();
433            if (this.draggable) {
434                $t.on('mousedown', function (e) {
435                    $t.addClass('jconfirm-hand');
436                    that.mouseX = e.clientX;
437                    that.mouseY = e.clientY;
438                    that.isDrag = true;
439                });
440                $(window).on('mousemove.' + this._id, function (e) {
441                    if (that.isDrag) {
442                        that.movingX = e.clientX - that.mouseX + that.initialX;
443                        that.movingY = e.clientY - that.mouseY + that.initialY;
444                        that.setDrag();
445                    }
446                });
447
448                $(window).on('mouseup.' + this._id, function () {
449                    $t.removeClass('jconfirm-hand');
450                    if (that.isDrag) {
451                        that.isDrag = false;
452                        that.initialX = that.movingX;
453                        that.initialY = that.movingY;
454                    }
455                })
456            }
457        },
458        resetDrag: function () {
459            this.isDrag = false;
460            this.initialX = 0;
461            this.initialY = 0;
462            this.movingX = 0;
463            this.movingY = 0;
464            this.mouseX = 0;
465            this.mouseY = 0;
466            this.$jconfirmBoxContainer.css('transform', 'translate(' + 0 + 'px, ' + 0 + 'px)');
467        },
468        setDrag: function () {
469            if (!this.draggable)
470                return;
471
472            this.alignMiddle = false;
473            var boxWidth = this.$jconfirmBox.outerWidth();
474            var boxHeight = this.$jconfirmBox.outerHeight();
475            var windowWidth = $(window).width();
476            var windowHeight = $(window).height();
477            var that = this;
478            var dragUpdate = 1;
479            if (that.movingX % dragUpdate === 0 || that.movingY % dragUpdate === 0) {
480                if (that.dragWindowBorder) {
481                    var leftDistance = (windowWidth / 2) - boxWidth / 2;
482                    var topDistance = (windowHeight / 2) - boxHeight / 2;
483                    topDistance -= that.dragWindowGap;
484                    leftDistance -= that.dragWindowGap;
485
486                    if (leftDistance + that.movingX < 0) {
487                        that.movingX = -leftDistance;
488                    } else if (leftDistance - that.movingX < 0) {
489                        that.movingX = leftDistance;
490                    }
491
492                    if (topDistance + that.movingY < 0) {
493                        that.movingY = -topDistance;
494                    } else if (topDistance - that.movingY < 0) {
495                        that.movingY = topDistance;
496                    }
497                }
498
499                that.$jconfirmBoxContainer.css('transform', 'translate(' + that.movingX + 'px, ' + that.movingY + 'px)');
500            }
501        },
502        _scrollTop: function () {
503            if (typeof pageYOffset !== 'undefined') {
504                //most browsers except IE before #9
505                return pageYOffset;
506            }
507            else {
508                var B = document.body; //IE 'quirks'
509                var D = document.documentElement; //IE with doctype
510                D = (D.clientHeight) ? D : B;
511                return D.scrollTop;
512            }
513        },
514        _watchContent: function () {
515            var that = this;
516            if (this._timer) clearInterval(this._timer);
517
518            var prevContentHeight = 0;
519            this._timer = setInterval(function () {
520                if (that.smoothContent) {
521                    var contentHeight = that.$content.outerHeight() || 0;
522                    if (contentHeight !== prevContentHeight) {
523                        that.$contentPane.css({
524                            'height': contentHeight
525                        }).scrollTop(0);
526                        prevContentHeight = contentHeight;
527                    }
528                    var wh = $(window).height();
529                    var total = that.offsetTop + that.offsetBottom + that.$jconfirmBox.height() - that.$contentPane.height() + that.$content.height();
530                    if (total < wh) {
531                        that.$contentPane.addClass('no-scroll');
532                    } else {
533                        that.$contentPane.removeClass('no-scroll');
534                    }
535                }
536            }, this.watchInterval);
537        },
538        _overflowClass: 'jconfirm-overflow',
539        _hilightAnimating: false,
540        highlight: function () {
541            this.hiLightModal();
542        },
543        hiLightModal: function () {
544            var that = this;
545            if (this._hilightAnimating)
546                return;
547
548            that.$body.addClass('hilight');
549            var duration = parseFloat(that.$body.css('animation-duration')) || 2;
550            this._hilightAnimating = true;
551            setTimeout(function () {
552                that._hilightAnimating = false;
553                that.$body.removeClass('hilight');
554            }, duration * 1000);
555        },
556        _bindEvents: function () {
557            var that = this;
558            this.boxClicked = false;
559
560            this.$scrollPane.click(function (e) { // Ignore propagated clicks
561                if (!that.boxClicked) { // Background clicked
562                    /*
563                     If backgroundDismiss is a function and its return value is truthy
564                     proceed to close the modal.
565                     */
566                    var buttonName = false;
567                    var shouldClose = false;
568                    var str;
569
570                    if (typeof that.backgroundDismiss == 'function')
571                        str = that.backgroundDismiss();
572                    else
573                        str = that.backgroundDismiss;
574
575                    if (typeof str == 'string' && typeof that.buttons[str] != 'undefined') {
576                        buttonName = str;
577                        shouldClose = false;
578                    } else if (typeof str == 'undefined' || !!(str) == true) {
579                        shouldClose = true;
580                    } else {
581                        shouldClose = false;
582                    }
583
584                    if (buttonName) {
585                        var btnResponse = that.buttons[buttonName].action.apply(that);
586                        shouldClose = (typeof btnResponse == 'undefined') || !!(btnResponse);
587                    }
588
589                    if (shouldClose)
590                        that.close();
591                    else
592                        that.hiLightModal();
593                }
594                that.boxClicked = false;
595            });
596
597            this.$jconfirmBox.click(function (e) {
598                that.boxClicked = true;
599            });
600
601            var isKeyDown = false;
602            $(window).on('jcKeyDown.' + that._id, function (e) {
603                if (!isKeyDown) {
604                    isKeyDown = true;
605                }
606            });
607            $(window).on('keyup.' + that._id, function (e) {
608                if (isKeyDown) {
609                    that.reactOnKey(e);
610                    isKeyDown = false;
611                }
612            });
613
614            $(window).on('resize.' + this._id, function () {
615                that._updateContentMaxHeight();
616                setTimeout(function () {
617                    that.resetDrag();
618                }, 100);
619            });
620        },
621        _cubic_bezier: '0.36, 0.55, 0.19',
622        _getCSS: function (speed, bounce) {
623            return {
624                '-webkit-transition-duration': speed / 1000 + 's',
625                'transition-duration': speed / 1000 + 's',
626                '-webkit-transition-timing-function': 'cubic-bezier(' + this._cubic_bezier + ', ' + bounce + ')',
627                'transition-timing-function': 'cubic-bezier(' + this._cubic_bezier + ', ' + bounce + ')'
628            };
629        },
630        _setButtons: function () {
631            var that = this;
632            /*
633             * Settings up buttons
634             */
635
636            var total_buttons = 0;
637            if (typeof this.buttons !== 'object')
638                this.buttons = {};
639
640            $.each(this.buttons, function (key, button) {
641                total_buttons += 1;
642                if (typeof button === 'function') {
643                    that.buttons[key] = button = {
644                        action: button
645                    };
646                }
647
648                that.buttons[key].text = button.text || key;
649                that.buttons[key].btnClass = button.btnClass || 'btn-default';
650                that.buttons[key].action = button.action || function () {
651                    };
652                that.buttons[key].keys = button.keys || [];
653                that.buttons[key].isHidden = button.isHidden || false;
654                that.buttons[key].isDisabled = button.isDisabled || false;
655
656                $.each(that.buttons[key].keys, function (i, a) {
657                    that.buttons[key].keys[i] = a.toLowerCase();
658                });
659
660                var button_element = $('<button type="button" class="btn"></button>')
661                    .html(that.buttons[key].text)
662                    .addClass(that.buttons[key].btnClass)
663                    .prop('disabled', that.buttons[key].isDisabled)
664                    .css('display', that.buttons[key].isHidden ? 'none' : '')
665                    .click(function (e) {
666                        e.preventDefault();
667                        var res = that.buttons[key].action.apply(that, [that.buttons[key]]);
668                        that.onAction.apply(that, [key, that.buttons[key]]);
669                        that._stopCountDown();
670                        if (typeof res === 'undefined' || res)
671                            that.close();
672                    });
673
674                that.buttons[key].el = button_element;
675                that.buttons[key].setText = function (text) {
676                    button_element.html(text);
677                };
678                that.buttons[key].addClass = function (className) {
679                    button_element.addClass(className);
680                };
681                that.buttons[key].removeClass = function (className) {
682                    button_element.removeClass(className);
683                };
684                that.buttons[key].disable = function () {
685                    that.buttons[key].isDisabled = true;
686                    button_element.prop('disabled', true);
687                };
688                that.buttons[key].enable = function () {
689                    that.buttons[key].isDisabled = false;
690                    button_element.prop('disabled', false);
691                };
692                that.buttons[key].show = function () {
693                    that.buttons[key].isHidden = false;
694                    button_element.css('display', '');
695                };
696                that.buttons[key].hide = function () {
697                    that.buttons[key].isHidden = true;
698                    button_element.css('display', 'none');
699                };
700                /*
701                 Buttons are prefixed with $_ or $$ for quick access
702                 */
703                that['$_' + key] = that['$$' + key] = button_element;
704                that.$btnc.append(button_element);
705            });
706
707            if (total_buttons === 0) this.$btnc.hide();
708            if (this.closeIcon === null && total_buttons === 0) {
709                /*
710                 in case when no buttons are present & closeIcon is null, closeIcon is set to true,
711                 set closeIcon to true to explicitly tell to hide the close icon
712                 */
713                this.closeIcon = true;
714            }
715
716            if (this.closeIcon) {
717                if (this.closeIconClass) {
718                    // user requires a custom class.
719                    var closeHtml = '<i class="' + this.closeIconClass + '"></i>';
720                    this.$closeIcon.html(closeHtml);
721                }
722
723                this.$closeIcon.click(function (e) {
724                    e.preventDefault();
725
726                    var buttonName = false;
727                    var shouldClose = false;
728                    var str;
729
730                    if (typeof that.closeIcon == 'function') {
731                        str = that.closeIcon();
732                    } else {
733                        str = that.closeIcon;
734                    }
735
736                    if (typeof str == 'string' && typeof that.buttons[str] != 'undefined') {
737                        buttonName = str;
738                        shouldClose = false;
739                    } else if (typeof str == 'undefined' || !!(str) == true) {
740                        shouldClose = true;
741                    } else {
742                        shouldClose = false;
743                    }
744                    if (buttonName) {
745                        var btnResponse = that.buttons[buttonName].action.apply(that);
746                        shouldClose = (typeof btnResponse == 'undefined') || !!(btnResponse);
747                    }
748                    if (shouldClose) {
749                        that.close();
750                    }
751                });
752                this.$closeIcon.show();
753            } else {
754                this.$closeIcon.hide();
755            }
756        },
757        setTitle: function (string, force) {
758            force = force || false;
759
760            if (typeof string !== 'undefined')
761                if (typeof string == 'string')
762                    this.title = string;
763                else if (typeof string == 'function') {
764                    if (typeof string.promise == 'function')
765                        console.error('Promise was returned from title function, this is not supported.');
766
767                    var response = string();
768                    if (typeof response == 'string')
769                        this.title = response;
770                    else
771                        this.title = false;
772                } else
773                    this.title = false;
774
775            if (this.isAjaxLoading && !force)
776                return;
777
778            this.$title.html(this.title || '');
779            this.updateTitleContainer();
780        },
781        setIcon: function (iconClass, force) {
782            force = force || false;
783
784            if (typeof iconClass !== 'undefined')
785                if (typeof iconClass == 'string')
786                    this.icon = iconClass;
787                else if (typeof iconClass === 'function') {
788                    var response = iconClass();
789                    if (typeof response == 'string')
790                        this.icon = response;
791                    else
792                        this.icon = false;
793                }
794                else
795                    this.icon = false;
796
797            if (this.isAjaxLoading && !force)
798                return;
799
800            this.$icon.html(this.icon ? '<i class="' + this.icon + '"></i>' : '');
801            this.updateTitleContainer();
802        },
803        updateTitleContainer: function () {
804            if (!this.title && !this.icon) {
805                this.$titleContainer.hide();
806            } else {
807                this.$titleContainer.show();
808            }
809        },
810        setContentPrepend: function (content, force) {
811            if (!content)
812                return;
813
814            this.contentParsed.prepend(content);
815        },
816        setContentAppend: function (content) {
817            if (!content)
818                return;
819
820            this.contentParsed.append(content);
821        },
822        setContent: function (content, force) {
823            force = !!force;
824            var that = this;
825            if (content)
826                this.contentParsed.html('').append(content);
827            if (this.isAjaxLoading && !force)
828                return;
829
830            this.$content.html('');
831            this.$content.append(this.contentParsed);
832            setTimeout(function () {
833                that.$body.find('input[autofocus]:visible:first').focus();
834            }, 100);
835        },
836        loadingSpinner: false,
837        showLoading: function (disableButtons) {
838            this.loadingSpinner = true;
839            this.$jconfirmBox.addClass('loading');
840            if (disableButtons)
841                this.$btnc.find('button').prop('disabled', true);
842
843        },
844        hideLoading: function (enableButtons) {
845            this.loadingSpinner = false;
846            this.$jconfirmBox.removeClass('loading');
847            if (enableButtons)
848                this.$btnc.find('button').prop('disabled', false);
849
850        },
851        ajaxResponse: false,
852        contentParsed: '',
853        isAjax: false,
854        isAjaxLoading: false,
855        _parseContent: function () {
856            var that = this;
857            var e = '&nbsp;';
858
859            if (typeof this.content == 'function') {
860                var res = this.content.apply(this);
861                if (typeof res == 'string') {
862                    this.content = res;
863                }
864                else if (typeof res == 'object' && typeof res.al
vendor: 16,930 bytes, lines 864-1345
864ways == 'function') {
865                    // this is ajax loading via promise
866                    this.isAjax = true;
867                    this.isAjaxLoading = true;
868                    res.always(function (data, status, xhr) {
869                        that.ajaxResponse = {
870                            data: data,
871                            status: status,
872                            xhr: xhr
873                        };
874                        that._contentReady.resolve(data, status, xhr);
875                        if (typeof that.contentLoaded == 'function')
876                            that.contentLoaded(data, status, xhr);
877                    });
878                    this.content = e;
879                } else {
880                    this.content = e;
881                }
882            }
883
884            if (typeof this.content == 'string' && this.content.substr(0, 4).toLowerCase() === 'url:') {
885                this.isAjax = true;
886                this.isAjaxLoading = true;
887                var u = this.content.substring(4, this.content.length);
888                $.get(u).done(function (html) {
889                    that.contentParsed.html(html);
890                }).always(function (data, status, xhr) {
891                    that.ajaxResponse = {
892                        data: data,
893                        status: status,
894                        xhr: xhr
895                    };
896                    that._contentReady.resolve(data, status, xhr);
897                    if (typeof that.contentLoaded == 'function')
898                        that.contentLoaded(data, status, xhr);
899                });
900            }
901
902            if (!this.content)
903                this.content = e;
904
905            if (!this.isAjax) {
906                this.contentParsed.html(this.content);
907                this.setContent();
908                that._contentReady.resolve();
909            }
910        },
911        _stopCountDown: function () {
912            clearInterval(this.autoCloseInterval);
913            if (this.$cd)
914                this.$cd.remove();
915        },
916        _startCountDown: function () {
917            var that = this;
918            var opt = this.autoClose.split('|');
919            if (opt.length !== 2) {
920                console.error('Invalid option for autoClose. example \'close|10000\'');
921                return false;
922            }
923
924            var button_key = opt[0];
925            var time = parseInt(opt[1]);
926            if (typeof this.buttons[button_key] === 'undefined') {
927                console.error('Invalid button key \'' + button_key + '\' for autoClose');
928                return false;
929            }
930
931            var seconds = Math.ceil(time / 1000);
932            this.$cd = $('<span class="countdown"> (' + seconds + ')</span>')
933                .appendTo(this['$_' + button_key]);
934
935            this.autoCloseInterval = setInterval(function () {
936                that.$cd.html(' (' + (seconds -= 1) + ') ');
937                if (seconds <= 0) {
938                    that['$$' + button_key].trigger('click');
939                    that._stopCountDown();
940                }
941            }, 1000);
942        },
943        _getKey: function (key) {
944            // very necessary keys.
945            switch (key) {
946                case 192:
947                    return 'tilde';
948                case 13:
949                    return 'enter';
950                case 16:
951                    return 'shift';
952                case 9:
953                    return 'tab';
954                case 20:
955                    return 'capslock';
956                case 17:
957                    return 'ctrl';
958                case 91:
959                    return 'win';
960                case 18:
961                    return 'alt';
962                case 27:
963                    return 'esc';
964                case 32:
965                    return 'space';
966            }
967
968            // only trust alphabets with this.
969            var initial = String.fromCharCode(key);
970            if (/^[A-z0-9]+$/.test(initial))
971                return initial.toLowerCase();
972            else
973                return false;
974        },
975        reactOnKey: function (e) {
976            var that = this;
977
978            /*
979             Prevent keyup event if the dialog is not last!
980             */
981            var a = $('.jconfirm');
982            if (a.eq(a.length - 1)[0] !== this.$el[0])
983                return false;
984
985            var key = e.which;
986            /*
987             Do not react if Enter or Space is pressed on input elements
988             */
989            if (this.$content.find(':input').is(':focus') && /13|32/.test(key))
990                return false;
991
992            var keyChar = this._getKey(key);
993
994            // If esc is pressed
995            if (keyChar === 'esc' && this.escapeKey) {
996                if (this.escapeKey === true) {
997                    this.$scrollPane.trigger('click');
998                }
999                else if (typeof this.escapeKey === 'string' || typeof this.escapeKey === 'function') {
1000                    var buttonKey;
1001                    if (typeof this.escapeKey === 'function') {
1002                        buttonKey = this.escapeKey();
1003                    } else {
1004                        buttonKey = this.escapeKey;
1005                    }
1006
1007                    if (buttonKey)
1008                        if (typeof this.buttons[buttonKey] === 'undefined') {
1009                            console.warn('Invalid escapeKey, no buttons found with key ' + buttonKey);
1010                        } else {
1011                            this['$_' + buttonKey].trigger('click');
1012                        }
1013                }
1014            }
1015
1016            // check if any button is listening to this key.
1017            $.each(this.buttons, function (key, button) {
1018                if (button.keys.indexOf(keyChar) != -1) {
1019                    that['$_' + key].trigger('click');
1020                }
1021            });
1022        },
1023        setDialogCenter: function () {
1024            console.info('setDialogCenter is deprecated, dialogs are centered with CSS3 tables');
1025        },
1026        _unwatchContent: function () {
1027            clearInterval(this._timer);
1028        },
1029        close: function (onClosePayload) {
1030            var that = this;
1031
1032            if (typeof this.onClose === 'function')
1033                this.onClose(onClosePayload);
1034
1035            this._unwatchContent();
1036
1037            /*
1038             unbind the window resize & keyup event.
1039             */
1040            $(window).unbind('resize.' + this._id);
1041            $(window).unbind('keyup.' + this._id);
1042            $(window).unbind('jcKeyDown.' + this._id);
1043
1044            if (this.draggable) {
1045                $(window).unbind('mousemove.' + this._id);
1046                $(window).unbind('mouseup.' + this._id);
1047                this.$titleContainer.unbind('mousedown');
1048            }
1049
1050            that.$el.removeClass(that.loadedClass);
1051            $('body').removeClass('jconfirm-no-scroll-' + that._id);
1052            that.$jconfirmBoxContainer.removeClass('jconfirm-no-transition');
1053
1054            setTimeout(function () {
1055                that.$body.addClass(that.closeAnimationParsed);
1056                that.$jconfirmBg.addClass('jconfirm-bg-h');
1057                var closeTimer = (that.closeAnimation === 'none') ? 1 : that.animationSpeed;
1058
1059                setTimeout(function () {
1060                    that.$el.remove();
1061
1062                    var l = jconfirm.instances;
1063                    var i = jconfirm.instances.length - 1;
1064                    for (i; i >= 0; i--) {
1065                        if (jconfirm.instances[i]._id === that._id) {
1066                            jconfirm.instances.splice(i, 1);
1067                        }
1068                    }
1069
1070                    // Focusing a element, scrolls automatically to that element.
1071                    // no instances should be open, lastFocused should be true, the lastFocused element must exists in DOM
1072                    if (!jconfirm.instances.length) {
1073                        if (that.scrollToPreviousElement && jconfirm.lastFocused && jconfirm.lastFocused.length && $.contains(document, jconfirm.lastFocused[0])) {
1074                            var $lf = jconfirm.lastFocused;
1075                            if (that.scrollToPreviousElementAnimate) {
1076                                var st = $(window).scrollTop();
1077                                var ot = jconfirm.lastFocused.offset().top;
1078                                var wh = $(window).height();
1079                                if (!(ot > st && ot < (st + wh))) {
1080                                    var scrollTo = (ot - Math.round((wh / 3)));
1081                                    $('html, body').animate({
1082                                        scrollTop: scrollTo
1083                                    }, that.animationSpeed, 'swing', function () {
1084                                        // gracefully scroll and then focus.
1085                                        $lf.focus();
1086                                    });
1087                                } else {
1088                                    // the element to be focused is already in view.
1089                                    $lf.focus();
1090                                }
1091                            } else {
1092                                $lf.focus();
1093                            }
1094                            jconfirm.lastFocused = false;
1095                        }
1096                    }
1097
1098                    if (typeof that.onDestroy === 'function')
1099                        that.onDestroy();
1100
1101                }, closeTimer * 0.40);
1102            }, 50);
1103
1104            return true;
1105        },
1106        open: function () {
1107            if (this.isOpen())
1108                return false;
1109
1110            // var that = this;
1111            this._buildHTML();
1112            this._bindEvents();
1113            this._open();
1114
1115            return true;
1116        },
1117        setStartingPoint: function () {
1118            var el = false;
1119
1120            if (this.animateFromElement !== true && this.animateFromElement) {
1121                el = this.animateFromElement;
1122                jconfirm.lastClicked = false;
1123            } else if (jconfirm.lastClicked && this.animateFromElement === true) {
1124                el = jconfirm.lastClicked;
1125                jconfirm.lastClicked = false;
1126            } else {
1127                return false;
1128            }
1129
1130            if (!el)
1131                return false;
1132
1133            var offset = el.offset();
1134
1135            var iTop = el.outerHeight() / 2;
1136            var iLeft = el.outerWidth() / 2;
1137
1138            // placing position of jconfirm modal in center of clicked element
1139            iTop -= this.$jconfirmBox.outerHeight() / 2;
1140            iLeft -= this.$jconfirmBox.outerWidth() / 2;
1141
1142            // absolute position on screen
1143            var sourceTop = offset.top + iTop;
1144            sourceTop = sourceTop - this._scrollTop();
1145            var sourceLeft = offset.left + iLeft;
1146
1147            // window halved
1148            var wh = $(window).height() / 2;
1149            var ww = $(window).width() / 2;
1150
1151            var targetH = wh - this.$jconfirmBox.outerHeight() / 2;
1152            var targetW = ww - this.$jconfirmBox.outerWidth() / 2;
1153
1154            sourceTop -= targetH;
1155            sourceLeft -= targetW;
1156
1157            // Check if the element is inside the viewable window.
1158            if (Math.abs(sourceTop) > wh || Math.abs(sourceLeft) > ww)
1159                return false;
1160
1161            this.$jconfirmBoxContainer.css('transform', 'translate(' + sourceLeft + 'px, ' + sourceTop + 'px)');
1162        },
1163        _open: function () {
1164            var that = this;
1165            if (typeof that.onOpenBefore === 'function')
1166                that.onOpenBefore();
1167
1168            this.$body.removeClass(this.animationParsed);
1169            this.$jconfirmBg.removeClass('jconfirm-bg-h');
1170            this.$body.focus();
1171
1172            that.$jconfirmBoxContainer.css('transform', 'translate(' + 0 + 'px, ' + 0 + 'px)');
1173
1174            setTimeout(function () {
1175                that.$body.css(that._getCSS(that.animationSpeed, 1));
1176                that.$body.css({
1177                    'transition-property': that.$body.css('transition-property') + ', margin'
1178                });
1179                that.$jconfirmBoxContainer.addClass('jconfirm-no-transition');
1180                that._modalReady.resolve();
1181                if (typeof that.onOpen === 'function')
1182                    that.onOpen();
1183
1184                that.$el.addClass(that.loadedClass);
1185            }, this.animationSpeed);
1186        },
1187        loadedClass: 'jconfirm-open',
1188        isClosed: function () {
1189            return !this.$el || this.$el.css('display') === '';
1190        },
1191        isOpen: function () {
1192            return !this.isClosed();
1193        },
1194        toggle: function () {
1195            if (!this.isOpen())
1196                this.open();
1197            else
1198                this.close();
1199        }
1200    };
1201
1202    jconfirm.instances = [];
1203    jconfirm.lastFocused = false;
1204    jconfirm.pluginDefaults = {
1205        template: '' +
1206        '<div class="jconfirm">' +
1207        '<div class="jconfirm-bg jconfirm-bg-h"></div>' +
1208        '<div class="jconfirm-scrollpane">' +
1209        '<div class="jconfirm-row">' +
1210        '<div class="jconfirm-cell">' +
1211        '<div class="jconfirm-holder">' +
1212        '<div class="jc-bs3-container">' +
1213        '<div class="jc-bs3-row">' +
1214        '<div class="jconfirm-box-container jconfirm-animated">' +
1215        '<div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1">' +
1216        '<div class="jconfirm-closeIcon">&times;</div>' +
1217        '<div class="jconfirm-title-c">' +
1218        '<span class="jconfirm-icon-c"></span>' +
1219        '<span class="jconfirm-title"></span>' +
1220        '</div>' +
1221        '<div class="jconfirm-content-pane">' +
1222        '<div class="jconfirm-content"></div>' +
1223        '</div>' +
1224        '<div class="jconfirm-buttons">' +
1225        '</div>' +
1226        '<div class="jconfirm-clear">' +
1227        '</div>' +
1228        '</div>' +
1229        '</div>' +
1230        '</div>' +
1231        '</div>' +
1232        '</div>' +
1233        '</div>' +
1234        '</div>' +
1235        '</div></div>',
1236        title: 'Hello',
1237        titleClass: '',
1238        type: 'default',
1239        typeAnimated: true,
1240        draggable: true,
1241        dragWindowGap: 15,
1242        dragWindowBorder: true,
1243        animateFromElement: true,
1244        /**
1245         * @deprecated
1246         */
1247        alignMiddle: true,
1248        smoothContent: true,
1249        content: 'Are you sure to continue?',
1250        buttons: {},
1251        defaultButtons: {
1252            ok: {
1253                action: function () {
1254                }
1255            },
1256            close: {
1257                action: function () {
1258                }
1259            }
1260        },
1261        contentLoaded: function () {
1262        },
1263        icon: '',
1264        lazyOpen: false,
1265        bgOpacity: null,
1266        theme: 'light',
1267        animation: 'scale',
1268        closeAnimation: 'scale',
1269        animationSpeed: 400,
1270        animationBounce: 1,
1271        escapeKey: true,
1272        rtl: false,
1273        container: 'body',
1274        containerFluid: false,
1275        backgroundDismiss: false,
1276        backgroundDismissAnimation: 'shake',
1277        autoClose: false,
1278        closeIcon: null,
1279        closeIconClass: false,
1280        watchInterval: 100,
1281        columnClass: 'col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1',
1282        boxWidth: '50%',
1283        scrollToPreviousElement: true,
1284        scrollToPreviousElementAnimate: true,
1285        useBootstrap: true,
1286        offsetTop: 40,
1287        offsetBottom: 40,
1288        bootstrapClasses: {
1289            container: 'container',
1290            containerFluid: 'container-fluid',
1291            row: 'row'
1292        },
1293        onContentReady: function () {
1294
1295        },
1296        onOpenBefore: function () {
1297
1298        },
1299        onOpen: function () {
1300
1301        },
1302        onClose: function () {
1303
1304        },
1305        onDestroy: function () {
1306
1307        },
1308        onAction: function () {
1309
1310        }
1311    };
1312
1313    /**
1314     * This refers to the issue #241 and #246
1315     *
1316     * Problem:
1317     * Button A is clicked (keydown) using the Keyboard ENTER key
1318     * A opens the jconfirm modal B,
1319     * B has registered ENTER key for one of its button C
1320     * A is released (keyup), B gets the keyup event and triggers C.
1321     *
1322     * Solution:
1323     * Register a global keydown event, that tells jconfirm if the keydown originated inside jconfirm
1324     */
1325    var keyDown = false;
1326    $(window).on('keydown', function (e) {
1327        if (!keyDown) {
1328            var $target = $(e.target);
1329            var pass = false;
1330            if ($target.closest('.jconfirm-box').length)
1331                pass = true;
1332            if (pass)
1333                $(window).trigger('jcKeyDown');
1334
1335            keyDown = true;
1336        }
1337    });
1338    $(window).on('keyup', function () {
1339        keyDown = false;
1340    });
1341    jconfirm.lastClicked = false;
1342    $(document).on('mousedown', 'button, a', function () {
1343        jconfirm.lastClicked = $(this);
1344    });
1345})(jQuery, window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.