PageSourceSearch

https://cityofdenhamsprings.com/Scripts/noty/jquery.noty.js

js cityofdenhamsprings.com collected 2026-09-24 09:32:37 UTC 16,161 bytes, 480 lines download raw bytes

1/**
2 * noty - jQuery Notification Plugin v2.2.0
3 * Contributors: https://github.com/needim/noty/graphs/contributors
4 *
5 * Examples and Documentation - http://needim.github.com/noty/
6 *
7 * Licensed under the MIT licenses:
8 * http://www.opensource.org/licenses/mit-license.php
9 *
10 **/
11
12if (typeof Object.create !== 'function') {
13    Object.create = function (o) {
14        function F() {
15        }
16
17        F.prototype = o;
18        return new F();
19    };
20}
21
22(function ($) {
23
24    var NotyObject = {
25
26        init:function (options) {
27
28            // Mix in the passed in options with the default options
29            this.options = $.extend({}, $.noty.defaults, options);
30
31            this.options.layout = (this.options.custom) ? $.noty.layouts['inline'] : $.noty.layouts[this.options.layout];
32
33			if ($.noty.themes[this.options.theme])
34            	this.options.theme = $.noty.themes[this.options.theme];
35			else
36				options.themeClassName = this.options.theme;
37
38            delete options.layout;
39            delete options.theme;
40
41            this.options = $.extend({}, this.options, this.options.layout.options);
42            this.options.id = 'noty_' + (new Date().getTime() * Math.floor(Math.random() * 1000000));
43
44            this.options = $.extend({}, this.options, options);
45
46            // Build the noty dom initial structure
47            this._build();
48
49            // return this so we can chain/use the bridge with less code.
50            return this;
51        }, // end init
52
53        _build:function () {
54
55            // Generating noty bar
56            var $bar = $('<div class="noty_bar noty_type_' + this.options.type + '"></div>').attr('id', this.options.id);
57            $bar.append(this.options.template).find('.noty_text').html(this.options.text);
58
59            this.$bar = (this.options.layout.parent.object !== null) ? $(this.options.layout.parent.object).css(this.options.layout.parent.css).append($bar) : $bar;
60
61			if (this.options.themeClassName)
62				this.$bar.addClass(this.options.themeClassName).addClass('noty_container_type_' + this.options.type);
63
64            // Set buttons if available
65            if (this.options.buttons) {
66
67                // If we have button disable closeWith & timeout options
68                this.options.closeWith = [];
69                this.options.timeout = false;
70
71                var $buttons = $('<div/>').addClass('noty_buttons');
72
73                (this.options.layout.parent.object !== null) ? this.$bar.find('.noty_bar').append($buttons) : this.$bar.append($buttons);
74
75                var self = this;
76
77                $.each(this.options.buttons, function (i, button) {
78                    var $button = $('<button/>').addClass((button.addClass) ? button.addClass : 'gray').html(button.text).attr('id', button.id ? button.id : 'button-' + i)
79                        .appendTo(self.$bar.find('.noty_buttons'))
80                        .bind('click', function () {
81                            if ($.isFunction(button.onClick)) {
82                                button.onClick.call($button, self);
83                            }
84                        });
85                });
86            }
87
88            // For easy access
89            this.$message = this.$bar.find('.noty_message');
90            this.$closeButton = this.$bar.find('.noty_close');
91            this.$buttons = this.$bar.find('.noty_buttons');
92
93            $.noty.store[this.options.id] = this; // store noty for api
94
95        }, // end _build
96
97        show:function () {
98
99            var self = this;
100
101			(self.options.custom) ? self.options.custom.find(self.options.layout.container.selector).append(self.$bar) : $(self.options.layout.container.selector).append(self.$bar);
102
103			if (self.options.theme && self.options.theme.style)
104            	self.options.theme.style.apply(self);
105
106            ($.type(self.options.layout.css) === 'function') ? this.options.layout.css.apply(self.$bar) : self.$bar.css(this.options.layout.css || {});
107
108            self.$bar.addClass(self.options.layout.addClass);
109
110            self.options.layout.container.style.apply($(self.options.layout.container.selector));
111
112            self.showing = true;
113
114			if (self.options.theme && self.options.theme.style)
115            	self.options.theme.callback.onShow.apply(this);
116
117            if ($.inArray('click', self.options.closeWith) > -1)
118                self.$bar.css('cursor', 'pointer').one('click', function (evt) {
119                    self.stopPropagation(evt);
120                    if (self.options.callback.onCloseClick) {
121                        self.options.callback.onCloseClick.apply(self);
122                    }
123                    self.close();
124                });
125
126            if ($.inArray('hover', self.options.closeWith) > -1)
127                self.$bar.one('mouseenter', function () {
128                    self.close();
129                });
130
131            if ($.inArray('button', self.options.closeWith) > -1)
132                self.$closeButton.one('click', function (evt) {
133                    self.stopPropagation(evt);
134                    self.close();
135                });
136
137            if ($.inArray('button', self.options.closeWith) == -1)
138                self.$closeButton.remove();
139
140            if (self.options.callback.onShow)
141                self.options.callback.onShow.apply(self);
142
143            self.$bar.animate(
144                self.options.animation.open,
145                self.options.animation.speed,
146                self.options.animation.easing,
147                function () {
148                    if (self.options.callback.afterShow) self.options.callback.afterShow.apply(self);
149                    self.showing = false;
150                    self.shown = true;
151                });
152
153            // If noty is have a timeout option
154            if (self.options.timeout)
155                self.$bar.delay(self.options.timeout).promise().done(function () {
156                    self.close();
157                });
158
159            return this;
160
161        }, // end show
162
163        close:function () {
164
165            if (this.closed) return;
166            if (this.$bar && this.$bar.hasClass('i-am-closing-now')) return;
167
168            var self = this;
169
170            if (this.showing) {
171              self.$bar.queue(
172                function () {
173                  self.close.apply(self);
174                }
175              )
176              return;
177            }
178
179            if (!this.shown && !this.showing) { // If we are still waiting in the queue just delete from queue
180                var queue = [];
181                $.each($.noty.queue, function (i, n) {
182                    if (n.options.id != self.options.id) {
183                        queue.push(n);
184                    }
185                });
186                $.noty.queue = queue;
187                return;
188            }
189
190            self.$bar.addClass('i-am-closing-now');
191
192            if (self.options.callback.onClose) {
193                self.options.callback.onClose.apply(self);
194            }
195
196            self.$bar.clearQueue().stop().animate(
197                self.options.animation.close,
198                self.options.animation.speed,
199                self.options.animation.easing,
200                function () {
201                    if (self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
202                })
203                .promise().done(function () {
204
205                    // Modal Cleaning
206                    if (self.options.modal) {
207                        $.notyRenderer.setModalCount(-1);
208                        if ($.notyRenderer.getModalCount() == 0) $('.noty_modal').fadeOut('fast', function () {
209                            $(this).remove();
210                        });
211                    }
212
213                    // Layout Cleaning
214                    $.notyRenderer.setLayoutCountFor(self, -1);
215                    if ($.notyRenderer.getLayoutCountFor(self) == 0) $(self.options.layout.container.selector).remove();
216
217                    // Make sure self.$bar has not been removed before attempting to remove it
218                    if (typeof self.$bar !== 'undefined' && self.$bar !== null ) {
219                        self.$bar.remove();
220                        self.$bar = null;
221                        self.closed = true;
222                    }
223
224                    delete $.noty.store[self.options.id]; // deleting noty from store
225
226                    self.options.theme.callback.onClose.apply(self);
227
228                    if (!self.options.dismissQueue) {
229                        // Queue render
230                        $.noty.ontap = true;
231
232                        $.notyRenderer.render();
233                    }
234
235					if (self.options.maxVisible > 0 && self.options.dismissQueue) {
236						$.notyRenderer.render();
237					}
238                })
239
240        }, // end close
241
242        setText:function (text) {
243            if (!this.closed) {
244                this.options.text = text;
245                this.$bar.find('.noty_text').html(text);
246            }
247            return this;
248        },
249
250        setType:function (type) {
251            if (!this.closed) {
252                this.options.type = type;
253                this.options.theme.style.apply(this);
254                this.options.theme.callback.onShow.apply(this);
255            }
256            return this;
257        },
258
259        setTimeout:function (time) {
260            if (!this.closed) {
261                var self = this;
262                this.options.timeout = time;
263                self.$bar.delay(self.options.timeout).promise().done(function () {
264                    self.close();
265                });
266            }
267            return this;
268        },
269
270        stopPropagation:function (evt) {
271            evt = evt || window.event;
272            if (typeof evt.stopPropagation !== "undefined") {
273                evt.stopPropagation();
274            } else {
275                evt.cancelBubble = true;
276            }
277        },
278
279        closed:false,
280        showing:false,
281        shown:false
282
283    }; // end NotyObject
284
285    $.notyRenderer = {};
286
287    $.notyRenderer.init = function (options) {
288
289        // Renderer creates a new noty
290        var notification = Object.create(NotyObject).init(options);
291
292		if (notification.options.killer)
293			$.noty.closeAll();
294
295        (notification.options.force) ? $.noty.queue.unshift(notification) : $.noty.queue.push(notification);
296
297        $.notyRenderer.render();
298
299        return ($.noty.returns == 'object') ? notification : notification.options.id;
300    };
301
302    $.notyRenderer.render = function () {
303
304        var instance = $.noty.queue[0];
305
306        if ($.type(instance) === 'object') {
307            if (instance.options.dismissQueue) {
308				if (instance.options.maxVisible > 0) {
309					if ($(instance.options.layout.container.selector + ' li').length < instance.options.maxVisible) {
310						$.notyRenderer.show($.noty.queue.shift());
311					} else {
312
313					}
314				} else {
315					$.notyRenderer.show($.noty.queue.shift());
316				}
317            } else {
318                if ($.noty.ontap) {
319                    $.notyRenderer.show($.noty.queue.shift());
320                    $.noty.ontap = false;
321                }
322            }
323        } else {
324            $.noty.ontap = true; // Queue is over
325        }
326
327    };
328
329    $.notyRenderer.show = function (notification) {
330
331        if (notification.options.modal) {
332            $.notyRenderer.createModalFor(notification);
333            $.notyRenderer.setModalCount(+1);
334        }
335
336        // Where is the container?
337		if (notification.options.custom) {
338			if (notification.options.custom.find(notification.options.layout.container.selector).length == 0) {
339				notification.options.custom.append($(notification.options.layout.container.object).addClass('i-am-new'));
340			} else {
341				notification.options.custom.find(notification.options.layout.container.selector).removeClass('i-am-new');
342			}
343		} else {
344			if ($(notification.options.layout.container.selector).length == 0) {
345				$('body').append($(notification.options.layout.container.object).addClass('i-am-new'));
346			} else {
347				$(notification.options.layout.container.selector).removeClass('i-am-new');
348			}
349		}
350
351        $.notyRenderer.setLayoutCountFor(notification, +1);
352
353        notification.show();
354    };
355
356    $.notyRenderer.createModalFor = function (notification) {
357        if ($('.noty_modal').length == 0)
358            $('<div/>').addClass('noty_modal').data('noty_modal_count', 0).css(notification.options.theme.modal.css).prependTo($('body')).fadeIn('fast');
359    };
360
361    $.notyRenderer.getLayoutCountFor = function (notification) {
362        return $(notification.options.layout.container.selector).data('noty_layout_count') || 0;
363    };
364
365    $.notyRenderer.setLayoutCountFor = function (notification, arg) {
366        return $(notification.options.layout.container.selector).data('noty_layout_count', $.notyRenderer.getLayoutCountFor(notification) + arg);
367    };
368
369    $.notyRenderer.getModalCount = function () {
370        return $('.noty_modal').data('noty_modal_count') || 0;
371    };
372
373    $.notyRenderer.setModalCount = function (arg) {
374        return $('.noty_modal').data('noty_modal_count', $.notyRenderer.getModalCount() + arg);
375    };
376
377    // This is for custom container
378    $.fn.noty = function (options) {
379        options.custom = $(this);
380        return $.notyRenderer.init(options);
381    };
382
383    $.noty = {};
384    $.noty.queue = [];
385    $.noty.ontap = true;
386    $.noty.layouts = {};
387    $.noty.themes = {};
388    $.noty.returns = 'object';
389    $.noty.store = {};
390
391    $.noty.get = function (id) {
392        return $.noty.store.hasOwnProperty(id) ? $.noty.store[id] : false;
393    };
394
395    $.noty.close = function (id) {
396        return $.noty.get(id) ? $.noty.get(id).close() : false;
397    };
398
399    $.noty.setText = function (id, text) {
400        return $.noty.get(id) ? $.noty.get(id).setText(text) : false;
401    };
402
403    $.noty.setType = function (id, type) {
404        return $.noty.get(id) ? $.noty.get(id).setType(type) : false;
405    };
406
407    $.noty.clearQueue = function () {
408        $.noty.queue = [];
409    };
410
411    $.noty.closeAll = function () {
412        $.noty.clearQueue();
413        $.each($.noty.store, function (id, noty) {
414            noty.close();
415        });
416    };
417
418    var windowAlert = window.alert;
419
420    $.noty.consumeAlert = function (options) {
421        window.alert = function (text) {
422            if (options)
423                options.text = text;
424            else
425                options = {text:text};
426
427            $.notyRenderer.init(options);
428        };
429    };
430
431    $.noty.stopConsumeAlert = function () {
432        window.alert = windowAlert;
433    };
434
435    $.noty.defaults = {
436        layout:'top',
437        theme:'defaultTheme',
438        type:'alert',
439        text:'',
440        dismissQueue:true,
441        template:'<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
442        animation:{
443            open:{height:'toggle'},
444            close:{height:'toggle'},
445            easing:'swing',
446            speed:500
447        },
448        timeout:false,
449        force:false,
450        modal:false,
451        maxVisible:5,
452		killer: false,
453        closeWith:['click'],
454        callback:{
455            onShow:function () {
456            },
457            afterShow:function () {
458            },
459            onClose:function () {
460            },
461            afterClose:function () {
462            },
463            onCloseClick:function () {
464            }
465        },
466        buttons:false
467    };
468
469    $(window).resize(function () {
470        $.each($.noty.layouts, function (index, layout) {
471            layout.container.style.apply($(layout.container.selector));
472        });
473    });
474
475})(jQuery);
476
477// Helpers
478window.noty = function noty(options) {
479    return jQuery.notyRenderer.init(options);
480};

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.