PageSourceSearch

https://prh.fi/stato/js/lib/toastr.js

js prh.fi collected 2026-09-24 08:46:33 UTC 10,519 bytes, 414 lines download raw bytes

vendor: 3,581 bytes, lines 1-145
1// 
2/*
3 * Toastr
4 * Copyright 2012-2015
5 * Authors: John Papa, Hans Fjällemark, and Tim Ferrell.
6 * All Rights Reserved.
7 * Use, reproduction, distribution, and modification of this code is subject to the terms and
8 * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
9 *
10 * ARIA Support: Greta Krafsig
11 *
12 * Project: https://github.com/CodeSeven/toastr
13 */
14/* global define */
15; (function (define) {
16	define(['jquery'], function ($) {
17		return (function () {
18			var $container;
19			var listener;
20			var toastId = 0;
21			var toastType = {
22				error: 'error',
23				info: 'info',
24				success: 'success',
25				warning: 'warning'
26			};
27
28			var toastr = {
29				clear: clear,
30				remove: remove,
31				error: error,
32				getContainer: getContainer,
33				info: info,
34				options: {},
35				subscribe: subscribe,
36				success: success,
37				version: '2.1.1',
38				warning: warning
39			};
40
41			var previousToast;
42
43			return toastr;
44
45			////////////////
46
47			function error(message, title, optionsOverride) {
48				return notify({
49					type: toastType.error,
50					iconClass: getOptions().iconClasses.error,
51					message: message,
52					optionsOverride: optionsOverride,
53					title: title
54				});
55			}
56
57			function getContainer(options, create) {
58				if (!options) { options = getOptions(); }
59				$container = $('#' + options.containerId);
60				if ($container.length) {
61					return $container;
62				}
63				if (create) {
64					$container = createContainer(options);
65				}
66				return $container;
67			}
68
69			function info(message, title, optionsOverride) {
70				return notify({
71					type: toastType.info,
72					iconClass: getOptions().iconClasses.info,
73					message: message,
74					optionsOverride: optionsOverride,
75					title: title
76				});
77			}
78
79			function subscribe(callback) {
80				listener = callback;
81			}
82
83			function success(message, title, optionsOverride) {
84				return notify({
85					type: toastType.success,
86					iconClass: getOptions().iconClasses.success,
87					message: message,
88					optionsOverride: optionsOverride,
89					title: title
90				});
91			}
92
93			function warning(message, title, optionsOverride) {
94				return notify({
95					type: toastType.warning,
96					iconClass: getOptions().iconClasses.warning,
97					message: message,
98					optionsOverride: optionsOverride,
99					title: title
100				});
101			}
102
103			function clear($toastElement, clearOptions) {
104				var options = getOptions();
105				if (!$container) { getContainer(options); }
106				if (!clearToast($toastElement, options, clearOptions)) {
107					clearContainer(options);
108				}
109			}
110
111			function remove($toastElement) {
112				var options = getOptions();
113				if (!$container) { getContainer(options); }
114				if ($toastElement && $(':focus', $toastElement).length === 0) {
115					removeToast($toastElement);
116					return;
117				}
118				if ($container.children().length) {
119					$container.remove();
120				}
121			}
122
123			// internal functions
124
125			function clearContainer (options) {
126				var toastsToClear = $container.children();
127				for (var i = toastsToClear.length - 1; i >= 0; i--) {
128					clearToast($(toastsToClear[i]), options);
129				}
130			}
131
132			function clearToast ($toastElement, options, clearOptions) {
133				var force = clearOptions && clearOptions.force ? clearOptions.force : false;
134				if ($toastElement && (force || $(':focus', $toastElement).length === 0)) {
135					$toastElement[options.hideMethod]({
136						duration: options.hideDuration,
137						easing: options.hideEasing,
138						complete: function () { removeToast($toastElement); }
139					});
140					return true;
141				}
142				return false;
143			}
144
145			function createContainer(options) {
146				$container = $('<div/>')
147					.attr('id', options.containerId)
148					.addClass(options.positionClass)
149					.attr('aria-live', 'polite')
150					.attr('role', 'alert');
151
152				$container.appendTo($(options.target));
153				return $container;
154			}
155
156			function getDefaults() {
157				return {
158					tapToDismiss: true,
159					toastClass: 'toast',
160					containerId: 'toast-container',
161					debug: false,
162
163					showMethod: 'fadeIn', //fadeIn, slideDown, and show are built into jQuery
164					showDuration: 300,
165					showEasing: 'swing', //swing and linear are built into jQuery
166					onShown: undefined,
167					hideMethod: 'fadeOut',
168					hideDuration: 1000,
169					hideEasing: 'swing',
170					onHidden: undefined,
171
172					extendedTimeOut: 1000,
173					iconClasses: {
174						error: 'toast-error',
175						info: 'toast-info',
176						success: 'toast-success',
177						warning: 'toast-warning'
178					},
179					iconClass: 'toast-info',
180					positionClass: 'toast-top-right',
181					timeOut: 5000, // Set timeOut and extendedTimeOut to 0 to make it sticky
182					titleClass: 'toast-title',
183					messageClass: 'toast-message',
184					target: 'body',
185					closeHtml: '<button type="button">&times;</button>',
186					newestOnTop: true,
187					preventDuplicates: false,
188					preventOpenDuplicates: false,
189					progressBar: false
190				};
191			}
192
193			function publish(args) {
194				if (!listener) { return; }
195				listener(args);
196			}
197
198			function notify(map) {
199				var options = getOptions();
200				var iconClass = map.iconClass || options.iconClass;
201
202				if (typeof (map.optionsOverride) !== 'undefined') {
203					options = $.extend(options, map.optionsOverride);
204					iconClass = map.optionsOverride.iconClass || iconClass;
205				}
206
207				if (shouldExit(options, map)) { return; }
208
209				toastId++;
210
211				$container = getContainer(options, true);
212
213				var intervalId = null;
214				var $toastElement = $('<div/>');
215				var $titleElement = $('<div/>');
216				var $messageElement = $('<div/>');
217				var $progressElement = $('<div/>');
218				var $closeElement = $(options.closeHtml);
219				var progressBar = {
220					intervalId: null,
221					hideEta: null,
222					maxHideTime: null
223				};
224				var response = {
225					toastId: toastId,
226					state: 'visible',
227					startTime: new Date(),
228					options: options,
229					map: map
230				};
231
232				personalizeToast();
233
234				displayToast();
235
236				handleEvents();
237
238				publish(response);
239
240				if (options.debug && console) {
241					console.log(response);
242				}
243
244				return $toastElement;
245
246				function personalizeToast() {
247					setIcon();
248					setTitle();
249					setMessage();
250					setCloseButton();
251					setProgressBar();
252					setSequence();
253				}
254
255				function handleEvents() {
256					$toastElement.hover(stickAround, delayedHideToast);
257					if (!options.onclick && options.tapToDismiss) {
258						$toastElement.click(hideToast);
259					}
260
261					if (options.closeButton && $closeElement) {
262						$closeElement.click(function (event) {
263							if (event.stopPropagation) {
264								event.stopPropagation();
265							} else if (event.cancelBubble !== undefined && event.cancelBubble !== true) {
266								event.cancelBubble = true;
267							}
268							hideToast(true);
269						});
270					}
271
272					if (options.onclick) {
273						$toastElement.click(function () {
274							options.onclick();
275							hideToast();
276						});
277					}
278				}
279
280				function displayToast() {
281					$toastElement.hide();
282
283					$toastElement[options.showMethod](
284						{duration: options.showDuration, easing: options.showEasing, complete: options.onShown}
285					);
286
287					if (options.timeOut > 0) {
288						intervalId = setTimeout(hideToast, options.timeOut);
289						progressBar.maxHideTime = parseFloat(options.timeOut);
290						progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
291						if (options.progressBar) {
292							progressBar.intervalId = setInterval(updateProgress, 10);
293						}
294					}
295				}
296
297				function setIcon() {
298					if (map.iconClass) {
299						$toastElement.addClass(options.toastClass).addClass(iconClass);
300					}
301				}
302
303				function setSequence() {
304					if (options.newestOnTop) {
305						$container.prepend($toastElement);
306					} else {
307						$container.append($toastElement);
308					}
309				}
310
311				function setTitle() {
312					if (map.title) {
313						$titleElement.append(map.title).addClass(options.titleClass);
314						$toastElement.append($titleElement);
315					}
316				}
317
318				function setMessage() {
319					if (map.message) {
320						$messageElement.append(map.message).addClass(options.messageClass);
321						$toastElement.append($messageElement);
322					}
323				}
324
325				function setCloseButton() {
326					if (options.closeButton) {
327						$closeElement.addClass('toast-close-button').attr('role', 'button');
vendor: 2,343 bytes, lines 328-414
328						$toastElement.prepend($closeElement);
329					}
330				}
331
332				function setProgressBar() {
333					if (options.progressBar) {
334						$progressElement.addClass('toast-progress');
335						$toastElement.prepend($progressElement);
336					}
337				}
338
339				function shouldExit(options, map) {
340					if (options.preventDuplicates) {
341						if (map.message === previousToast) {
342							return true;
343						} else {
344							previousToast = map.message;
345						}
346					}
347					return false;
348				}
349
350				function hideToast(override) {
351					if ($(':focus', $toastElement).length && !override) {
352						return;
353					}
354					clearTimeout(progressBar.intervalId);
355					return $toastElement[options.hideMethod]({
356						duration: options.hideDuration,
357						easing: options.hideEasing,
358						complete: function () {
359							removeToast($toastElement);
360							if (options.onHidden && response.state !== 'hidden') {
361								options.onHidden();
362							}
363							response.state = 'hidden';
364							response.endTime = new Date();
365							publish(response);
366						}
367					});
368				}
369
370				function delayedHideToast() {
371					if (options.timeOut > 0 || options.extendedTimeOut > 0) {
372						intervalId = setTimeout(hideToast, options.extendedTimeOut);
373						progressBar.maxHideTime = parseFloat(options.extendedTimeOut);
374						progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
375					}
376				}
377
378				function stickAround() {
379					clearTimeout(intervalId);
380					progressBar.hideEta = 0;
381					$toastElement.stop(true, true)[options.showMethod](
382						{duration: options.showDuration, easing: options.showEasing}
383					);
384				}
385
386				function updateProgress() {
387					var percentage = ((progressBar.hideEta - (new Date().getTime())) / progressBar.maxHideTime) * 100;
388					$progressElement.width(percentage + '%');
389				}
390			}
391
392			function getOptions() {
393				return $.extend({}, getDefaults(), toastr.options);
394			}
395
396			function removeToast($toastElement) {
397				if (!$container) { $container = getContainer(); }
398				if ($toastElement.is(':visible')) {
399					return;
400				}
401				$toastElement.remove();
402				$toastElement = null;
403				if ($container.children().length === 0) {
404					$container.remove();
405					previousToast = undefined;
406				}
407			}
408
409		})();
410	});
411}(typeof define === 'function' && define.amd ? define : function (deps, factory) {
412	window['toastr'] = factory(window['jQuery']);
413}));
414// 

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.