From 648f75875fa2283232fe2c509dac69d54c1d60f1 Mon Sep 17 00:00:00 2001 From: jangajack Date: Sat, 2 Jun 2018 12:53:23 +1000 Subject: [PATCH 1/2] typeBasedOverrides added a feature to include message type specific overrides so that each message of a specific type can have a different default set of options. This supports the same set of options that optionsOverride supports. --- toastr.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/toastr.js b/toastr.js index 1f804394..b9ac05b4 100644 --- a/toastr.js +++ b/toastr.js @@ -190,7 +190,8 @@ preventDuplicates: false, progressBar: false, progressClass: 'toast-progress', - rtl: false + rtl: false, + typeBasedOverrides: {} }; } @@ -201,7 +202,12 @@ function notify(map) { var options = getOptions(); - var iconClass = map.iconClass || options.iconClass; + + // extend the options object with type specific overrides + if (typeof (options.typeBasedOverrides[map.type]) !== 'undefined') { + options = $.extend(options, options.typeBasedOverrides[map.type]); + iconClass = options.typeBasedOverrides[map.type] || iconClass; + } if (typeof (map.optionsOverride) !== 'undefined') { options = $.extend(options, map.optionsOverride); From 5f04573f46be0bfcb539431ea8068a3c27b93af0 Mon Sep 17 00:00:00 2001 From: "johnschram@gmail.com" Date: Sat, 2 Jun 2018 14:51:07 +1000 Subject: [PATCH 2/2] Allows users to create type specific option sets while maintaining the options hierarchy. -- uses new options object property typeBasedOverrides where typeBasedOverrides is an object with child objects of each type that accept the same parameters as overrideOptions options = { typeBasedOverrides: { info: {}, success: {}, warning: {}, error: {} } see https://github.com/CodeSeven/toastr/issues/571 --- toastr.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toastr.js b/toastr.js index b9ac05b4..0b910334 100644 --- a/toastr.js +++ b/toastr.js @@ -202,11 +202,13 @@ function notify(map) { var options = getOptions(); + + var iconClass = map.iconClass || options.iconClass; // extend the options object with type specific overrides if (typeof (options.typeBasedOverrides[map.type]) !== 'undefined') { options = $.extend(options, options.typeBasedOverrides[map.type]); - iconClass = options.typeBasedOverrides[map.type] || iconClass; + iconClass = options.typeBasedOverrides[map.type].iconClass || iconClass; } if (typeof (map.optionsOverride) !== 'undefined') {