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