Browse Source

Update toastr.js to 2.0.3.

pull/57/head
Evan Theurer 12 years ago
parent
commit
525ae4f22e
  1. 104
      static/js/libs/toastr.js

104
static/js/libs/toastr.js

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

Loading…
Cancel
Save