| 1 |
/* global wsrw_admin_notices */ |
| 2 |
|
| 3 |
/** |
| 4 |
* WSRW Dismissible Notices. |
| 5 |
* |
| 6 |
* @since 1.6.7.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
'use strict'; |
| 10 |
|
| 11 |
var WSRWAdminWideNotices = window.WSRWAdminWideNotices || ( function ( document, window, $ ) { |
| 12 |
|
| 13 |
/** |
| 14 |
* Public functions and properties. |
| 15 |
* |
| 16 |
* @since 1.6.7.1 |
| 17 |
* |
| 18 |
* @type {object} |
| 19 |
*/ |
| 20 |
var app = { |
| 21 |
|
| 22 |
/** |
| 23 |
* Start the engine. |
| 24 |
* |
| 25 |
* @since 1.6.7.1 |
| 26 |
*/ |
| 27 |
init: function () { |
| 28 |
|
| 29 |
$( app.ready ); |
| 30 |
}, |
| 31 |
|
| 32 |
/** |
| 33 |
* Document ready. |
| 34 |
* |
| 35 |
* @since 1.6.7.1 |
| 36 |
*/ |
| 37 |
ready: function () { |
| 38 |
|
| 39 |
app.events(); |
| 40 |
}, |
| 41 |
|
| 42 |
/** |
| 43 |
* Dismissible notices events. |
| 44 |
* |
| 45 |
* @since 1.6.7.1 |
| 46 |
*/ |
| 47 |
events: function () { |
| 48 |
|
| 49 |
$( document ).on( |
| 50 |
'click', |
| 51 |
'.wsrw-notice .notice-dismiss, .wsrw-notice .wsrw-notice-dismiss', |
| 52 |
app.dismissNotice |
| 53 |
); |
| 54 |
}, |
| 55 |
|
| 56 |
/** |
| 57 |
* Dismiss notice event handler. |
| 58 |
* |
| 59 |
* @since 1.6.7.1 |
| 60 |
* |
| 61 |
* @param {object} e Event object. |
| 62 |
* */ |
| 63 |
dismissNotice: function ( e ) { |
| 64 |
|
| 65 |
if ( e.target.classList.contains( 'wsrw-notice-dismiss' ) ) { |
| 66 |
$( this ).closest( '.wsrw-notice' ).slideUp(); |
| 67 |
} |
| 68 |
|
| 69 |
$.post( |
| 70 |
wsrw_admin_notices.ajax_url, |
| 71 |
{ |
| 72 |
action: 'wsrw_notice_dismiss', |
| 73 |
_wpnonce: wsrw_admin_notices.nonce, |
| 74 |
id: ( $( this ).closest( '.wsrw-notice' ).attr( 'id' ) || '' ).replace( 'wsrw-notice-', '' ), |
| 75 |
} |
| 76 |
); |
| 77 |
}, |
| 78 |
}; |
| 79 |
|
| 80 |
return app; |
| 81 |
|
| 82 |
}( document, window, jQuery ) ); |
| 83 |
|
| 84 |
// Initialize. |
| 85 |
WSRWAdminWideNotices.init(); |
| 86 |
|