|
|
|
@ -1,18 +1,17 @@
@@ -1,18 +1,17 @@
|
|
|
|
|
/* |
|
|
|
|
* Toastr |
|
|
|
|
* Version 2.0.1 |
|
|
|
|
* Copyright 2012 John Papa and Hans Fjällemark. |
|
|
|
|
* Copyright 2012-2014 John Papa and Hans Fjällemark. |
|
|
|
|
* All Rights Reserved. |
|
|
|
|
* Use, reproduction, distribution, and modification of this code is subject to the terms and |
|
|
|
|
* conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
|
|
|
|
|
* |
|
|
|
|
* Author: John Papa and Hans Fjällemark |
|
|
|
|
* ARIA Support: Greta Krafsig |
|
|
|
|
* Project: https://github.com/CodeSeven/toastr
|
|
|
|
|
*/ |
|
|
|
|
; (function (define) { |
|
|
|
|
define(['jquery'], function ($) { |
|
|
|
|
return (function () { |
|
|
|
|
var version = '2.0.1'; |
|
|
|
|
var $container; |
|
|
|
|
var listener; |
|
|
|
|
var toastId = 0; |
|
|
|
@ -25,13 +24,14 @@
@@ -25,13 +24,14 @@
|
|
|
|
|
|
|
|
|
|
var toastr = { |
|
|
|
|
clear: clear, |
|
|
|
|
remove: remove, |
|
|
|
|
error: error, |
|
|
|
|
getContainer: getContainer, |
|
|
|
|
info: info, |
|
|
|
|
options: {}, |
|
|
|
|
subscribe: subscribe, |
|
|
|
|
success: success, |
|
|
|
|
version: version, |
|
|
|
|
version: '2.0.3', |
|
|
|
|
warning: warning |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -48,6 +48,18 @@
@@ -48,6 +48,18 @@
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getContainer(options, create) { |
|
|
|
|
if (!options) { options = getOptions(); } |
|
|
|
|
$container = $('#' + options.containerId); |
|
|
|
|
if ($container.length) { |
|
|
|
|
return $container; |
|
|
|
|
} |
|
|
|
|
if(create) { |
|
|
|
|
$container = createContainer(options); |
|
|
|
|
} |
|
|
|
|
return $container; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function info(message, title, optionsOverride) { |
|
|
|
|
return notify({ |
|
|
|
|
type: toastType.info, |
|
|
|
@ -83,27 +95,57 @@
@@ -83,27 +95,57 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clear($toastElement) { |
|
|
|
|
var options = getOptions(); |
|
|
|
|
if (!$container) { getContainer(options); } |
|
|
|
|
if (!clearToast($toastElement, options)) { |
|
|
|
|
clearContainer(options); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function remove($toastElement) { |
|
|
|
|
var options = getOptions(); |
|
|
|
|
if (!$container) { getContainer(options); } |
|
|
|
|
if ($toastElement && $(':focus', $toastElement).length === 0) { |
|
|
|
|
$toastElement[options.hideMethod]({ |
|
|
|
|
duration: options.hideDuration, |
|
|
|
|
easing: options.hideEasing, |
|
|
|
|
complete: function () { removeToast($toastElement); } |
|
|
|
|
}); |
|
|
|
|
removeToast($toastElement); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if ($container.children().length) { |
|
|
|
|
$container[options.hideMethod]({ |
|
|
|
|
$container.remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region Internal Methods
|
|
|
|
|
|
|
|
|
|
function clearContainer(options){ |
|
|
|
|
var toastsToClear = $container.children(); |
|
|
|
|
for (var i = toastsToClear.length - 1; i >= 0; i--) { |
|
|
|
|
clearToast($(toastsToClear[i]), options); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clearToast($toastElement, options){ |
|
|
|
|
if ($toastElement && $(':focus', $toastElement).length === 0) { |
|
|
|
|
$toastElement[options.hideMethod]({ |
|
|
|
|
duration: options.hideDuration, |
|
|
|
|
easing: options.hideEasing, |
|
|
|
|
complete: function () { $container.remove(); } |
|
|
|
|
complete: function () { removeToast($toastElement); } |
|
|
|
|
}); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region Internal Methods
|
|
|
|
|
function createContainer(options) { |
|
|
|
|
$container = $('<div/>') |
|
|
|
|
.attr('id', options.containerId) |
|
|
|
|
.addClass(options.positionClass) |
|
|
|
|
.attr('aria-live', 'polite') |
|
|
|
|
.attr('role', 'alert'); |
|
|
|
|
|
|
|
|
|
$container.appendTo($(options.target)); |
|
|
|
|
return $container; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getDefaults() { |
|
|
|
|
return { |
|
|
|
@ -140,15 +182,12 @@
@@ -140,15 +182,12 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function publish(args) { |
|
|
|
|
if (!listener) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!listener) { return; } |
|
|
|
|
listener(args); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function notify(map) { |
|
|
|
|
var |
|
|
|
|
options = getOptions(), |
|
|
|
|
var options = getOptions(), |
|
|
|
|
iconClass = map.iconClass || options.iconClass; |
|
|
|
|
|
|
|
|
|
if (typeof (map.optionsOverride) !== 'undefined') { |
|
|
|
@ -158,9 +197,8 @@
@@ -158,9 +197,8 @@
|
|
|
|
|
|
|
|
|
|
toastId++; |
|
|
|
|
|
|
|
|
|
$container = getContainer(options); |
|
|
|
|
var |
|
|
|
|
intervalId = null, |
|
|
|
|
$container = getContainer(options, true); |
|
|
|
|
var intervalId = null, |
|
|
|
|
$toastElement = $('<div/>'), |
|
|
|
|
$titleElement = $('<div/>'), |
|
|
|
|
$messageElement = $('<div/>'), |
|
|
|
@ -188,7 +226,7 @@
@@ -188,7 +226,7 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (options.closeButton) { |
|
|
|
|
$closeElement.addClass('toast-close-button'); |
|
|
|
|
$closeElement.addClass('toast-close-button').attr("role", "button"); |
|
|
|
|
$toastElement.prepend($closeElement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -203,14 +241,16 @@
@@ -203,14 +241,16 @@
|
|
|
|
|
$toastElement[options.showMethod]( |
|
|
|
|
{ duration: options.showDuration, easing: options.showEasing, complete: options.onShown } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (options.timeOut > 0) { |
|
|
|
|
intervalId = setTimeout(hideToast, options.timeOut); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$toastElement.hover(stickAround, delayedhideToast); |
|
|
|
|
$toastElement.hover(stickAround, delayedHideToast); |
|
|
|
|
if (!options.onclick && options.tapToDismiss) { |
|
|
|
|
$toastElement.click(hideToast); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (options.closeButton && $closeElement) { |
|
|
|
|
$closeElement.click(function (event) { |
|
|
|
|
if( event.stopPropagation ) { |
|
|
|
@ -246,17 +286,17 @@
@@ -246,17 +286,17 @@
|
|
|
|
|
easing: options.hideEasing, |
|
|
|
|
complete: function () { |
|
|
|
|
removeToast($toastElement); |
|
|
|
|
if (options.onHidden) { |
|
|
|
|
if (options.onHidden && response.state !== 'hidden') { |
|
|
|
|
options.onHidden(); |
|
|
|
|
} |
|
|
|
|
response.state = 'hidden'; |
|
|
|
|
response.endTime = new Date(), |
|
|
|
|
response.endTime = new Date(); |
|
|
|
|
publish(response); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function delayedhideToast() { |
|
|
|
|
function delayedHideToast() { |
|
|
|
|
if (options.timeOut > 0 || options.extendedTimeOut > 0) { |
|
|
|
|
intervalId = setTimeout(hideToast, options.extendedTimeOut); |
|
|
|
|
} |
|
|
|
@ -269,18 +309,6 @@
@@ -269,18 +309,6 @@
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
function getContainer(options) { |
|
|
|
|
if (!options) { options = getOptions(); } |
|
|
|
|
$container = $('#' + options.containerId); |
|
|
|
|
if ($container.length) { |
|
|
|
|
return $container; |
|
|
|
|
} |
|
|
|
|
$container = $('<div/>') |
|
|
|
|
.attr('id', options.containerId) |
|
|
|
|
.addClass(options.positionClass); |
|
|
|
|
$container.appendTo($(options.target)); |
|
|
|
|
return $container; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getOptions() { |
|
|
|
|
return $.extend({}, getDefaults(), toastr.options); |
|
|
|
|