From 3830edd5479850e8d1f569ce9310238b05b22711 Mon Sep 17 00:00:00 2001 From: "Daniel St.Jacques" Date: Thu, 5 Oct 2017 21:19:15 -0400 Subject: [PATCH 1/2] Fixed selector typo in test --- tests/unit/toastr-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/toastr-tests.js b/tests/unit/toastr-tests.js index 71b704e7..d16f8927 100644 --- a/tests/unit/toastr-tests.js +++ b/tests/unit/toastr-tests.js @@ -20,7 +20,7 @@ var selectors = { container: 'div#toast-container', toastInfo: 'div#toast-container > div.toast-info', - toastWarning: 'div#toast-container > div.toast-success', + toastWarning: 'div#toast-container > div.toast-warning', toastError: 'div#toast-container > div.toast-error', toastSuccess: 'div#toast-container > div.toast-success' }; From 02a74d49f44477bf5de2f530c95debdb83c3efa1 Mon Sep 17 00:00:00 2001 From: "Daniel St.Jacques" Date: Thu, 5 Oct 2017 21:22:38 -0400 Subject: [PATCH 2/2] Add custom toast type --- demo.html | 23 +++++++++++++++++++++++ toastr.js | 14 +++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/demo.html b/demo.html index 7e124d68..f89f1b9d 100644 --- a/demo.html +++ b/demo.html @@ -10,6 +10,10 @@ .row { margin-left: 0; } + .toast-custom { + background-color: #0000A0; + background-image: url("data:image/gif;base64,R0lGOD lhCwAOAMQfAP////7+/vj4+Hh4eHd3d/v7+/Dw8HV1dfLy8ubm5vX19e3t7fr 6+nl5edra2nZ2dnx8fMHBwYODg/b29np6eujo6JGRkeHh4eTk5LCwsN3d3dfX 13Jycp2dnevr6////yH5BAEAAB8ALAAAAAALAA4AAAVq4NFw1DNAX/o9imAsB tKpxKRd1+YEWUoIiUoiEWEAApIDMLGoRCyWiKThenkwDgeGMiggDLEXQkDoTh CKNLpQDgjeAsY7MHgECgx8YR8oHwNHfwADBACGh4EDA4iGAYAEBAcQIg0Dk gcEIQA7") !important; + } @@ -93,6 +97,13 @@

toastr

+ +
@@ -215,6 +226,15 @@

Links

return msg; }; + $('#toastTypeGroup').click(function() { + var toastType = $("#toastTypeGroup input:radio:checked").val(); + if (toastType === 'custom') { + $('#customClassContainer').show(); + } else { + $('#customClassContainer').hide(); + } + }); + $('#closeButton').click(function() { if($(this).is(':checked')) { $('#addBehaviorOnToastCloseClick').prop('disabled', false); @@ -249,6 +269,9 @@

Links

preventDuplicates: $('#preventDuplicates').prop('checked'), onclick: null }; + if (shortCutFunction === 'custom') { + toastr.options.iconClass = $('#customClass').val(); + } if ($('#addBehaviorOnToastClick').prop('checked')) { toastr.options.onclick = function () { diff --git a/toastr.js b/toastr.js index f48cb73d..522048ea 100644 --- a/toastr.js +++ b/toastr.js @@ -21,11 +21,13 @@ error: 'error', info: 'info', success: 'success', - warning: 'warning' + warning: 'warning', + custom: 'custom' }; var toastr = { clear: clear, + custom: custom, remove: remove, error: error, getContainer: getContainer, @@ -99,6 +101,16 @@ }); } + function custom(message, title, optionsOverride) { + return notify({ + type: toastType.custom, + iconClass: getOptions().iconClass, + message: message, + optionsOverride: optionsOverride, + title: title + }); + } + function clear($toastElement, clearOptions) { var options = getOptions(); if (!$container) { getContainer(options); }