Skip to content

Commit

Permalink
Bringing bower up to 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TimFerrell committed Mar 13, 2015
1 parent 58d8e77 commit a3c37aa
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 95 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toastr",
"version": "2.1.0",
"version": "2.1.1",
"main": ["toastr.js", "toastr.css"],
"dependencies": {
"jquery": ">=1.6.3"
Expand Down
Empty file modified toastr.css
100644 → 100755
Empty file.
225 changes: 133 additions & 92 deletions toastr.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Toastr
* Copyright 2012-2014
* Copyright 2012-2015
* Authors: John Papa, Hans Fjällemark, and Tim Ferrell.
* All Rights Reserved.
* Use, reproduction, distribution, and modification of this code is subject to the terms and
Expand All @@ -10,6 +10,7 @@
*
* Project: https://github.com/CodeSeven/toastr
*/
/* global define */
; (function (define) {
define(['jquery'], function ($) {
return (function () {
Expand All @@ -32,15 +33,16 @@
options: {},
subscribe: subscribe,
success: success,
version: '2.1.0',
version: '2.1.1',
warning: warning
};

var previousToast;

return toastr;

//#region Accessible Methods
////////////////

function error(message, title, optionsOverride) {
return notify({
type: toastType.error,
Expand Down Expand Up @@ -97,10 +99,10 @@
});
}

function clear($toastElement) {
function clear($toastElement, clearOptions) {
var options = getOptions();
if (!$container) { getContainer(options); }
if (!clearToast($toastElement, options)) {
if (!clearToast($toastElement, options, clearOptions)) {
clearContainer(options);
}
}
Expand All @@ -116,9 +118,8 @@
$container.remove();
}
}
//#endregion

//#region Internal Methods
// internal functions

function clearContainer (options) {
var toastsToClear = $container.children();
Expand All @@ -127,8 +128,9 @@
}
}

function clearToast ($toastElement, options) {
if ($toastElement && $(':focus', $toastElement).length === 0) {
function clearToast ($toastElement, options, clearOptions) {
var force = clearOptions && clearOptions.force ? clearOptions.force : false;
if ($toastElement && (force || $(':focus', $toastElement).length === 0)) {
$toastElement[options.hideMethod]({
duration: options.hideDuration,
easing: options.hideEasing,
Expand Down Expand Up @@ -179,7 +181,7 @@
titleClass: 'toast-title',
messageClass: 'toast-message',
target: 'body',
closeHtml: '<button>&times;</button>',
closeHtml: '<button type="button">&times;</button>',
newestOnTop: true,
preventDuplicates: false,
progressBar: false
Expand All @@ -192,117 +194,156 @@
}

function notify(map) {
var options = getOptions(),
iconClass = map.iconClass || options.iconClass;

if (options.preventDuplicates) {
if (map.message === previousToast) {
return;
} else {
previousToast = map.message;
}
}
var options = getOptions();
var iconClass = map.iconClass || options.iconClass;

if (typeof (map.optionsOverride) !== 'undefined') {
options = $.extend(options, map.optionsOverride);
iconClass = map.optionsOverride.iconClass || iconClass;
}

if (shouldExit(options, map)) { return; }

toastId++;

$container = getContainer(options, true);
var intervalId = null,
$toastElement = $('<div/>'),
$titleElement = $('<div/>'),
$messageElement = $('<div/>'),
$progressElement = $('<div/>'),
$closeElement = $(options.closeHtml),
progressBar = {
intervalId: null,
hideEta: null,
maxHideTime: null
},
response = {
toastId: toastId,
state: 'visible',
startTime: new Date(),
options: options,
map: map
};

if (map.iconClass) {
$toastElement.addClass(options.toastClass).addClass(iconClass);
}

if (map.title) {
$titleElement.append(map.title).addClass(options.titleClass);
$toastElement.append($titleElement);
}
var intervalId = null;
var $toastElement = $('<div/>');
var $titleElement = $('<div/>');
var $messageElement = $('<div/>');
var $progressElement = $('<div/>');
var $closeElement = $(options.closeHtml);
var progressBar = {
intervalId: null,
hideEta: null,
maxHideTime: null
};
var response = {
toastId: toastId,
state: 'visible',
startTime: new Date(),
options: options,
map: map
};

if (map.message) {
$messageElement.append(map.message).addClass(options.messageClass);
$toastElement.append($messageElement);
personalizeToast();

displayToast();

handleEvents();

publish(response);

if (options.debug && console) {
console.log(response);
}

if (options.closeButton) {
$closeElement.addClass('toast-close-button').attr('role', 'button');
$toastElement.prepend($closeElement);
return $toastElement;

function personalizeToast() {
setIcon();
setTitle();
setMessage();
setCloseButton();
setProgressBar();
setSequence();
}

if (options.progressBar) {
$progressElement.addClass('toast-progress');
$toastElement.prepend($progressElement);
function handleEvents() {
$toastElement.hover(stickAround, delayedHideToast);
if (!options.onclick && options.tapToDismiss) {
$toastElement.click(hideToast);
}

if (options.closeButton && $closeElement) {
$closeElement.click(function (event) {
if (event.stopPropagation) {
event.stopPropagation();
} else if (event.cancelBubble !== undefined && event.cancelBubble !== true) {
event.cancelBubble = true;
}
hideToast(true);
});
}

if (options.onclick) {
$toastElement.click(function () {
options.onclick();
hideToast();
});
}
}

$toastElement.hide();
if (options.newestOnTop) {
$container.prepend($toastElement);
} else {
$container.append($toastElement);
function displayToast() {
$toastElement.hide();

$toastElement[options.showMethod](
{duration: options.showDuration, easing: options.showEasing, complete: options.onShown}
);

if (options.timeOut > 0) {
intervalId = setTimeout(hideToast, options.timeOut);
progressBar.maxHideTime = parseFloat(options.timeOut);
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
if (options.progressBar) {
progressBar.intervalId = setInterval(updateProgress, 10);
}
}
}
$toastElement[options.showMethod](
{duration: options.showDuration, easing: options.showEasing, complete: options.onShown}
);

if (options.timeOut > 0) {
intervalId = setTimeout(hideToast, options.timeOut);
progressBar.maxHideTime = parseFloat(options.timeOut);
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
if (options.progressBar) {
progressBar.intervalId = setInterval(updateProgress, 10);

function setIcon() {
if (map.iconClass) {
$toastElement.addClass(options.toastClass).addClass(iconClass);
}
}

$toastElement.hover(stickAround, delayedHideToast);
if (!options.onclick && options.tapToDismiss) {
$toastElement.click(hideToast);
function setSequence() {
if (options.newestOnTop) {
$container.prepend($toastElement);
} else {
$container.append($toastElement);
}
}

if (options.closeButton && $closeElement) {
$closeElement.click(function (event) {
if (event.stopPropagation) {
event.stopPropagation();
} else if (event.cancelBubble !== undefined && event.cancelBubble !== true) {
event.cancelBubble = true;
}
hideToast(true);
});
function setTitle() {
if (map.title) {
$titleElement.append(map.title).addClass(options.titleClass);
$toastElement.append($titleElement);
}
}

if (options.onclick) {
$toastElement.click(function () {
options.onclick();
hideToast();
});
function setMessage() {
if (map.message) {
$messageElement.append(map.message).addClass(options.messageClass);
$toastElement.append($messageElement);
}
}

publish(response);
function setCloseButton() {
if (options.closeButton) {
$closeElement.addClass('toast-close-button').attr('role', 'button');
$toastElement.prepend($closeElement);
}
}

if (options.debug && console) {
console.log(response);
function setProgressBar() {
if (options.progressBar) {
$progressElement.addClass('toast-progress');
$toastElement.prepend($progressElement);
}
}

return $toastElement;
function shouldExit(options, map) {
if (options.preventDuplicates) {
if (map.message === previousToast) {
return true;
} else {
previousToast = map.message;
}
}
return false;
}

function hideToast(override) {
if ($(':focus', $toastElement).length && !override) {
Expand Down Expand Up @@ -359,9 +400,9 @@
$toastElement = null;
if ($container.children().length === 0) {
$container.remove();
previousToast = undefined;
}
}
//#endregion

})();
});
Expand Down
Empty file modified toastr.less
100644 → 100755
Empty file.
Loading

0 comments on commit a3c37aa

Please sign in to comment.