PageSourceSearch

https://onlineservices.nakheel.com/Assets/JS/JQuery-Confirm/JS/jquery-confirm.js?v=639089958405992272

js nakheel.com collected 2026-10-02 04:48:30 UTC 16,986 bytes, 473 lines download raw bytes

1/*!
2 * jquery-confirm v2.0.0 (http://craftpip.github.io/jquery-confirm/)
3 * Author: Boniface Pereira
4 * Website: www.craftpip.com
5 * Contact: [email protected]
6 *
7 * Copyright 2013-2015 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 ($) {
17    "use strict";
18    $.fn.confirm = function (options) {
19        if(typeof options === 'undefined') options = {};
20        /*
21         *  Alias of jconfirm to emulate native confirm
22         */
23        var $this = $(this);
24        $this.on('click', function (e) {
25            e.preventDefault();
26            if ($this.attr('href'))
27                options['confirm'] = function () {
28                    location.href = $this.attr('href');
29                };
30            $.confirm(options);
31        });
32        return $this;
33    };
34    $.confirm = function (options) {
35        /*
36         *  Alias of jconfirm
37         */
38        return jconfirm(options);
39    };
40    $.alert = function (options) {
41        /*
42         *  Alias of jconfirm
43         */
44        options.cancelButton = false;
45        return jconfirm(options);
46    };
47    $.dialog = function (options) {
48        /*
49         *  Alias of jconfirm
50         */
51        options.cancelButton = false;
52        options.confirmButton = false;
53        options.confirmKeys = [13];
54        return jconfirm(options);
55    };
56    jconfirm = function (options) {
57        if (typeof options === 'undefined')
58            options = {};
59        /*
60         * initial function for calling.
61         */
62        if (jconfirm.defaults) {
63            /*
64             * Merge global defaults with plugin defaults
65             */
66            $.extend(jconfirm.pluginDefaults, jconfirm.defaults);
67        }
68        /*
69         * merge options with plugin defaults.
70         */
71        var options = $.extend({}, jconfirm.pluginDefaults, options);
72        return new Jconfirm(options);
73    };
74    Jconfirm = function (options) {
75        /*
76         * constructor function Jconfirm,
77         * options = user options.
78         */
79        $.extend(this, options);
80        this._init();
81    };
82    Jconfirm.prototype = {
83        _init: function () {
84            var that = this;
85            this._rand = Math.round(Math.random() * 99999);
86            this._buildHTML();
87            this._bindEvents();
88            setTimeout(function () {
89                that.open();
90            }, 0);
91        },
92        animations: ['anim-scale', 'anim-top', 'anim-bottom', 'anim-left', 'anim-right', 'anim-zoom', 'anim-opacity', 'anim-none', 'anim-rotate', 'anim-rotatex', 'anim-rotatey', 'anim-scalex', 'anim-scaley'],
93        _buildHTML: function () {
94            /*
95             * Cleaning animations.
96             */
97            this.animation = 'anim-' + this.animation.toLowerCase();
98            this.closeAnimation = 'anim-' + this.closeAnimation.toLowerCase();
99
100            /*
101             * Append html to body.
102             */
103            this.$el = $(this.template).appendTo(this.container).addClass(this.theme);
104            this.$el.find('.jconfirm-box-container').addClass(this.columnClass);
105
106            this.CSS = {
107                '-webkit-transition-duration': this.animationSpeed / 5000 + 's',
108                'transition-duration': this.animationSpeed / 5000 + 's',
109                '-webkit-transition-timing-function': 'cubic-bezier(.38,1.28,.2, ' + this.animationBounce + ')',
110                'transition-timing-function': 'cubic-bezier(.38,1.28,.2, ' + this.animationBounce + ')'
111            };
112            //0.27, 1.12, 0.32
113            this.$el.find('.jconfirm-bg').css(this.CSS);
114            this.$b = this.$el.find('.jconfirm-box').css(this.CSS).addClass(this.animation);
115            this.$body = this.$b; // alias
116
117            /*
118             * Add rtl class if rtl option has selected
119             */
120            if (this.rtl)
121                this.$el.addClass("rtl");
122
123            /*
124             * Setup title contents
125             */
126            this.$title = this.$el.find('div.title');
127            this.setTitle();
128            this.contentDiv = this.$el.find('div.content');
129            this.$content = this.contentDiv; // alias
130
131            /*
132             * Settings up buttons
133             */
134            this.$btnc = this.$el.find('.buttons');
135            if (this.confirmButton && this.confirmButton.trim() !== '') {
136                this.$confirmButton = $('<button class="btn">' + this.confirmButton + '</button>').appendTo(this.$btnc).addClass(this.confirmButtonClass);
137            }
138
139            if (this.cancelButton && this.cancelButton.trim() !== '') {
140                this.$cancelButton = $('<button class="btn">' + this.cancelButton + '</button>').appendTo(this.$btnc).addClass(this.cancelButtonClass);
141            }
142
143            if (!this.confirmButton && !this.cancelButton) {
144                this.$btnc.remove();
145            }
146
147            if (!this.confirmButton && !this.cancelButton && this.closeIcon === null) {
148                this.$closeButton = this.$b.find('.closeIcon').show();
149            }
150
151            if (this.closeIcon === true) {
152                this.$closeButton = this.$b.find('.closeIcon').show();
153            }
154
155            this.setContent();
156
157            if (this.autoClose)
158                this._startCountDown();
159        },
160        setTitle: function (string) {
161            this.title = (typeof string !== 'undefined') ? string : this.title;
162
163            if (this.title && this.$title) {
164                this.$title.html('<i class="' + this.icon + '"></i> ' + this.title);
165            } else {
166                this.$title.remove();
167            }
168        },
169        setContent: function (string) {
170            var that = this;
171            this.content = (string) ? string : this.content;
172            var animate = (string) ? true : false;
173
174            /*
175             * Set content.
176             */
177            if (typeof this.content === 'boolean') {
178                if (!this.content)
179                    this.contentDiv.remove(); else
180                    console.error('Invalid option for property content: passed TRUE');
181            } else if (typeof this.content === 'string') {
182
183                if (this.content.substr(0, 4).toLowerCase() === 'url:') {
184                    this.contentDiv.html('');
185                    this.$btnc.find('button').prop('disabled', true);
186                    var url = this.content.substring(4, this.content.length);
187                    $.get(url).done(function (html) {
188                        that.contentDiv.html(html);
189                    }).always(function (data, status, xhr) {
190                        if (typeof that.contentLoaded === 'function')
191                            that.contentLoaded(data, status, xhr);
192
193                        that.$btnc.find('button').prop('disabled', false);
194                        that.setDialogCenter();
195                    });
196                } else {
197                    this.contentDiv.html(this.content);
198                }
199
200            } else if (typeof this.content === 'function') {
201
202                this.contentDiv.html('');
203                this.$btnc.find('button').attr('disabled', 'disabled');
204
205                var promise = this.content(this);
206                if (typeof promise !== 'object') {
207                    console.error('The content function must return jquery promise.');
208                } else if (typeof promise.always !== 'function') {
209                    console.error('The object returned is not a jquery promise.');
210                } else {
211                    promise.always(function (data, status) {
212                        that.$btnc.find('button').removeAttr('disabled');
213                        that.setDialogCenter();
214                    });
215                }
216
217            } else {
218                console.error('Invalid option for property content, passed: ' + typeof this.content);
219            }
220
221            this.setDialogCenter(animate);
222        },
223        _startCountDown: function () {
224            var opt = this.autoClose.split('|');
225            if (/cancel/.test(opt[0]) && this.type === 'alert') {
226                return false;
227            } else if (/confirm|cancel/.test(opt[0])) {
228                this.$cd = $('<span class="countdown">').appendTo(this['$' + opt[0] + 'Button']);
229                var that = this;
230                that.$cd.parent().click();
231                var time = opt[1] / 1000;
232                this.interval = setInterval(function () {
233                    that.$cd.html(' [' + (time -= 1) + ']');
234                    if (time === 0) {
235                        that.$cd.parent().trigger('click');
236                        clearInterval(that.interval);
237                    }
238                }, 1000);
239            } else {
240                console.error('Invalid option ' + opt[0] + ', must be confirm/cancel');
241            }
242        },
243        _bindEvents: function () {
244            var that = this;
245            var boxClicked = false;
246
247            this.$el.find('.jconfirm-scrollpane').click(function (e) {
248                // ignore propagated clicks
249                if (!boxClicked) {
250                    // background clicked
251                    if (that.backgroundDismiss) {
252                        that.cancel();
253                        that.close();
254                    } else {
255                        that.$b.addClass('hilight');
256                        setTimeout(function () {
257                            that.$b.removeClass('hilight');
258                        }, 400);
259                    }
260                }
261                boxClicked = false;
262            });
263
264            this.$el.find('.jconfirm-box').click(function (e) {
265                boxClicked = true;
266            });
267
268            if (this.$confirmButton) {
269                this.$confirmButton.click(function (e) {
270                    e.preventDefault();
271                    var r = that.confirm(that.$b);
272                    that.onAction('confirm');
273
274                    if (typeof r === 'undefined' || r)
275                        that.close();
276                });
277            }
278            if (this.$cancelButton) {
279                this.$cancelButton.click(function (e) {
280                    e.preventDefault();
281                    var r = that.cancel(that.$b);
282                    that.onAction('cancel');
283
284                    if (typeof r === 'undefined' || r)
285                        that.close();
286                });
287            }
288            if (this.$closeButton) {
289                this.$closeButton.click(function (e) {
290                    e.preventDefault();
291                    that.cancel();
292                    that.onAction('close');
293                    that.close();
294                });
295            }
296            if (this.keyboardEnabled) {
297                setTimeout(function () {
298                    $(window).on('keyup.' + this._rand, function (e) {
299                        that.reactOnKey(e);
300                    });
301                }, 500);
302            }
303
304            $(window).on('resize.' + this._rand, function () {
305                that.setDialogCenter(true);
306            });
307        },
308        reactOnKey: function key(e) {
309
310            /*
311             * prevent keyup event if the dialog is not last!
312             */
313            var a = $('.jconfirm');
314            if (a.eq(a.length - 1)[0] !== this.$el[0])
315                return false;
316
317            var key = e.which;
318            // Do not react if Enter/Space is pressed on input elements
319            if (this.contentDiv.find(':input').is(':focus') && /13|32/.test(key))
320                return false;
321
322            if ($.inArray(key, this.cancelKeys) !== -1) {
323                /*
324                 * Cancel key pressed.
325                 */
326                if (!this.backgroundDismiss) {
327                    /*
328                     * If background dismiss is false, Glow the modal.
329                     */
330                    this.$el.find('.jconfirm-bg').click();
331                    return false;
332                }
333
334                if (this.$cancelButton) {
335                    this.$cancelButton.click();
336                } else {
337                    this.close();
338                }
339            }
340            if ($.inArray(key, this.confirmKeys) !== -1) {
341                /*
342                 * Confirm key pressed.
343                 */
344                if (this.$confirmButton) {
345                    this.$confirmButton.click();
346                }
347            }
348        },
349        setDialogCenter: function (animate) {
350            var windowHeight = $(window).height();
351            var boxHeight = this.$b.outerHeight();
352            var topMargin = (windowHeight - boxHeight) / 2;
353            var minMargin = 100;
354            if (boxHeight > (windowHeight - minMargin)) {
355                var style = {
356                    'margin-top': minMargin / 2,
357                    'margin-bottom': minMargin / 2
358                }
359            } else {
360                var style = {
361                    'margin-top': topMargin
362                }
363            }
364            if (animate) {
365                this.$b.animate(style, {
366                    duration: this.animationSpeed,
367                    queue: false
368                });
369            } else {
370                this.$b.css(style);
371            }
372        },
373        close: function () {
374            var that = this;
375
376            if (this.isClosed())
377                return false;
378
379            if (typeof this.onClose === 'function')
380                this.onClose();
381            /*
382             unbind the window resize & keyup event.
383             */
384            $(window).unbind('resize.' + this._rand);
385            if (this.keyboardEnabled)
386                $(window).unbind('keyup.' + this._rand);
387
388            that.$el.find('.jconfirm-bg').removeClass('seen');
389            this.$b.addClass(this.closeAnimation);
390            var closeTimer = (this.closeAnimation == 'anim-none') ? 0 : this.animationSpeed;
391            setTimeout(function () {
392                that.$el.remove();
393            }, closeTimer + 50); // wait 50 miliseconds more, for the animation to end gracefully.
394
395            jconfirm.record.closed += 1;
396            jconfirm.record.currentlyOpen -= 1;
397
398            if (jconfirm.record.currentlyOpen < 1)
399                $('body').removeClass('jconfirm-noscroll');
400
401            return true;
402        },
403        open: function () {
404            var that = this;
405            if (this.isClosed())
406                return false;
407
408            that.$el.find('.jconfirm-bg').addClass('seen');
409
410            $('body').addClass('jconfirm-noscroll');
411            this.$b.removeClass(this.animations.join(' '));
412            this.$b.find('input[autofocus]:visible:first').focus();
413            jconfirm.record.opened += 1;
414            jconfirm.record.currentlyOpen += 1;
415            if (typeof this.onOpen === 'function')
416                this.onOpen();
417
418            var jcr = 'jconfirm-box' + this._rand;
419            this.$b.attr('aria-labelledby', jcr).attr('tabindex', -1).focus();
420            if (this.$title)
421                this.$title.attr('id', jcr); else if (this.$content)
422                this.$content.attr('id', jcr);
423
424            return true;
425        },
426        isClosed: function () {
427            return this.$el.css('display') === '';
428        }
429    };
430
431    jconfirm.pluginDefaults = {
432        template: '<div class="jconfirm"><div class="jconfirm-bg"></div><div class="jconfirm-scrollpane"><div class="container"><div class="row"><div class="jconfirm-box-container span6 offset3"><div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1"><div class="closeIcon"><span class="glyphicon glyphicon-remove"></span></div><div class="title"></div><div class="content"></div><div class="buttons"></div><div class="jquery-clear"></div></div></div></div></div></div></div>',
433        title: 'Hello',
434        content: 'Are you sure to continue?',
435        contentLoaded: function () {
436        },
437        icon: '',
438        confirmButton: 'Okay',
439        cancelButton: 'Cancel',
440        confirmButtonClass: 'btn-default',
441        cancelButtonClass: 'btn-default',
442        theme: 'white',
443        animation: 'zoom',
444        closeAnimation: 'scale',
445        animationSpeed: 500,
446        animationBounce: 1.2,
447        keyboardEnabled: false,
448        rtl: false,
449        confirmKeys: [13, 32], // ENTER or SPACE key
450        cancelKeys: [27], // ESC key
451        container: 'body',
452        confirm: function () {
453        },
454        cancel: function () {
455        },
456        backgroundDismiss: true,
457        autoClose: false,
458        closeIcon: null,
459        columnClass: 'col-md-4 col-md-offset-4',
460        onOpen: function () {
461        },
462        onClose: function () {
463        },
464        onAction: function () {
465        }
466    };
467
468    jconfirm.record = {
469        opened: 0,
470        closed: 0,
471        currentlyOpen: 0
472    };
473})(jQuery);

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.