| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | window.Defender = window.Defender || {}; |
| 2 | 2 | |
| 3 | 3 | //Added extra parameter to allow for some actions to keep modal open |
| 4 | -Defender.showNotification = function (type, message, closeModal) { | |
| 4 | +Defender.showNotification = function (type, message, autoClose = false) { | |
| 5 | 5 | var jq = jQuery; |
| 6 | 6 | var html = '<div class="sui-floating-notices"><div role="alert" id="defender-notification" class="sui-notice" aria-live="assertive"></div></div>'; |
| 7 | 7 | if (jq('body').find('#defender-notification').size() === 0) { |
| 8 | 8 | jq('.sui-wrap').prepend(html); |
| @@ -10,15 +10,11 @@ | ||
| 10 | 10 | jq('#defender-notification').closest('.sui-floating-notices').replaceWith(jQuery(html)); |
| 11 | 11 | } |
| 12 | 12 | var options = { |
| 13 | 13 | type: 'green', |
| 14 | - icon: 'info', | |
| 15 | - dismiss: { | |
| 16 | - show: true, | |
| 17 | - label: 'Click to close', | |
| 18 | - tooltip: 'Dismiss' | |
| 19 | - } | |
| 14 | + icon: 'info' | |
| 20 | 15 | } |
| 16 | + | |
| 21 | 17 | if (type === 'error') { |
| 22 | 18 | options.type = 'red'; |
| 23 | 19 | } else if (type === 'warning') { |
| 24 | 20 | options.type = 'warning'; |
| @@ -24,16 +20,30 @@ | ||
| 24 | 20 | options.type = 'warning'; |
| 25 | 21 | } else if (type === 'info') { |
| 26 | 22 | options.type = 'blue'; |
| 27 | 23 | } |
| 24 | + | |
| 25 | + if (true === autoClose) { | |
| 26 | + options.autoclose = { | |
| 27 | + show: true, | |
| 28 | + timeout: 5000 | |
| 29 | + }; | |
| 30 | + } else { | |
| 31 | + options.dismiss = { | |
| 32 | + show: true, | |
| 33 | + label: 'Click to close', | |
| 34 | + tooltip: 'Dismiss' | |
| 35 | + }; | |
| 36 | + } | |
| 37 | + | |
| 28 | 38 | SUI.openNotice('defender-notification', '<p>' + message + '</p>', options); |
| 29 | 39 | } |
| 30 | 40 | |
| 31 | 41 | /** |
| 32 | 42 | * Filter default wp.i18n.__ function |
| 33 | - * `wpdef` is our domain | |
| 43 | + * `defender-security` is our domain | |
| 34 | 44 | */ |
| 35 | -wp.hooks.addFilter( 'i18n.gettext_wpdef', 'defender', function ( translation, text ) { | |
| 45 | +wp.hooks.addFilter( 'i18n.gettext_defender-security', 'defender', function ( translation, text ) { | |
| 36 | 46 | if ( defenderGetText && defenderGetText[ text ] ) { |
| 37 | 47 | return defenderGetText[ text ]; |
| 38 | 48 | } |
| 39 | 49 | |