vendor
5 days ago
connect.js
5 days ago
connect.min.js
5 days ago
smtp-about.js
5 days ago
smtp-about.min.js
5 days ago
smtp-activelayer-wc.js
5 days ago
smtp-activelayer-wc.min.js
5 days ago
smtp-admin-notices.js
5 days ago
smtp-admin-notices.min.js
5 days ago
smtp-admin.js
5 days ago
smtp-admin.min.js
5 days ago
smtp-ai-mcp.js
5 days ago
smtp-ai-mcp.min.js
5 days ago
smtp-code-snippets.js
5 days ago
smtp-code-snippets.min.js
5 days ago
smtp-dashboard-widget.js
5 days ago
smtp-dashboard-widget.min.js
5 days ago
smtp-notifications.js
5 days ago
smtp-notifications.min.js
5 days ago
smtp-recommendations.js
5 days ago
smtp-recommendations.min.js
5 days ago
smtp-tools-debug-events.js
5 days ago
smtp-tools-debug-events.min.js
5 days ago
smtp-notifications.js
186 lines
| 1 | /* global wp_mail_smtp, ajaxurl */ |
| 2 | |
| 3 | /** |
| 4 | * WP Mail SMTP Admin Notifications. |
| 5 | * |
| 6 | * @since 2.3.0 |
| 7 | */ |
| 8 | |
| 9 | 'use strict'; |
| 10 | |
| 11 | var WPMailSMTPAdminNotifications = window.WPMailSMTPAdminNotifications || ( function( document, window, $ ) { |
| 12 | |
| 13 | /** |
| 14 | * Elements holder. |
| 15 | * |
| 16 | * @since 2.3.0 |
| 17 | * |
| 18 | * @type {object} |
| 19 | */ |
| 20 | var el = { |
| 21 | $notifications: $( '#wp-mail-smtp-notifications' ), |
| 22 | $nextButton: $( '#wp-mail-smtp-notifications .navigation .next' ), |
| 23 | $prevButton: $( '#wp-mail-smtp-notifications .navigation .prev' ), |
| 24 | $adminBarCounter: $( '#wp-admin-bar-wp-mail-smtp-menu .wp-mail-smtp-admin-bar-menu-notification-counter' ), |
| 25 | }; |
| 26 | |
| 27 | /** |
| 28 | * Public functions and properties. |
| 29 | * |
| 30 | * @since 2.3.0 |
| 31 | * |
| 32 | * @type {object} |
| 33 | */ |
| 34 | var app = { |
| 35 | |
| 36 | /** |
| 37 | * Start the engine. |
| 38 | * |
| 39 | * @since 2.3.0 |
| 40 | */ |
| 41 | init: function() { |
| 42 | |
| 43 | $( app.ready ); |
| 44 | }, |
| 45 | |
| 46 | /** |
| 47 | * Document ready. |
| 48 | * |
| 49 | * @since 2.3.0 |
| 50 | */ |
| 51 | ready: function() { |
| 52 | |
| 53 | app.updateNavigation(); |
| 54 | app.events(); |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * Register JS events. |
| 59 | * |
| 60 | * @since 2.3.0 |
| 61 | */ |
| 62 | events: function() { |
| 63 | |
| 64 | el.$notifications |
| 65 | .on( 'click', '.dismiss', app.dismiss ) |
| 66 | .on( 'click', '.next', app.navNext ) |
| 67 | .on( 'click', '.prev', app.navPrev ); |
| 68 | }, |
| 69 | |
| 70 | /** |
| 71 | * Click on the Dismiss notification button. |
| 72 | * |
| 73 | * @since 2.3.0 |
| 74 | * |
| 75 | * @param {object} event Event object. |
| 76 | */ |
| 77 | dismiss: function( event ) { |
| 78 | |
| 79 | if ( el.$currentMessage.length === 0 ) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | // AJAX call - update option. |
| 84 | var data = { |
| 85 | action: 'wp_mail_smtp_notification_dismiss', |
| 86 | nonce: wp_mail_smtp.nonce, |
| 87 | id: el.$currentMessage.data( 'message-id' ), |
| 88 | }; |
| 89 | |
| 90 | $.post( ajaxurl, data, function( response ) { |
| 91 | if ( ! response.success ) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | // Update counter. |
| 96 | var count = parseInt( el.$adminBarCounter.text(), 10 ); |
| 97 | if ( count > 1 ) { |
| 98 | --count; |
| 99 | el.$adminBarCounter.html( '<span>' + count + '</span>' ); |
| 100 | } else { |
| 101 | el.$adminBarCounter.remove(); |
| 102 | } |
| 103 | |
| 104 | // Remove notification. |
| 105 | var $nextMessage = el.$nextMessage.length < 1 ? el.$prevMessage : el.$nextMessage; |
| 106 | |
| 107 | if ( $nextMessage.length === 0 ) { |
| 108 | el.$notifications.remove(); |
| 109 | } else { |
| 110 | el.$currentMessage.remove(); |
| 111 | $nextMessage.addClass( 'current' ); |
| 112 | app.updateNavigation(); |
| 113 | } |
| 114 | } ); |
| 115 | }, |
| 116 | |
| 117 | /** |
| 118 | * Click on the Next notification button. |
| 119 | * |
| 120 | * @since 2.3.0 |
| 121 | * |
| 122 | * @param {object} event Event object. |
| 123 | */ |
| 124 | navNext: function( event ) { |
| 125 | |
| 126 | if ( el.$nextButton.hasClass( 'disabled' ) ) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | el.$currentMessage.removeClass( 'current' ); |
| 131 | el.$nextMessage.addClass( 'current' ); |
| 132 | |
| 133 | app.updateNavigation(); |
| 134 | }, |
| 135 | |
| 136 | /** |
| 137 | * Click on the Previous notification button. |
| 138 | * |
| 139 | * @since 2.3.0 |
| 140 | * |
| 141 | * @param {object} event Event object. |
| 142 | */ |
| 143 | navPrev: function( event ) { |
| 144 | |
| 145 | if ( el.$prevButton.hasClass( 'disabled' ) ) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | el.$currentMessage.removeClass( 'current' ); |
| 150 | el.$prevMessage.addClass( 'current' ); |
| 151 | |
| 152 | app.updateNavigation(); |
| 153 | }, |
| 154 | |
| 155 | /** |
| 156 | * Update navigation buttons. |
| 157 | * |
| 158 | * @since 2.3.0 |
| 159 | */ |
| 160 | updateNavigation: function() { |
| 161 | |
| 162 | el.$currentMessage = el.$notifications.find( '.wp-mail-smtp-notifications-message.current' ); |
| 163 | el.$nextMessage = el.$currentMessage.next( '.wp-mail-smtp-notifications-message' ); |
| 164 | el.$prevMessage = el.$currentMessage.prev( '.wp-mail-smtp-notifications-message' ); |
| 165 | |
| 166 | if ( el.$nextMessage.length === 0 ) { |
| 167 | el.$nextButton.addClass( 'disabled' ); |
| 168 | } else { |
| 169 | el.$nextButton.removeClass( 'disabled' ); |
| 170 | } |
| 171 | |
| 172 | if ( el.$prevMessage.length === 0 ) { |
| 173 | el.$prevButton.addClass( 'disabled' ); |
| 174 | } else { |
| 175 | el.$prevButton.removeClass( 'disabled' ); |
| 176 | } |
| 177 | }, |
| 178 | }; |
| 179 | |
| 180 | return app; |
| 181 | |
| 182 | }( document, window, jQuery ) ); |
| 183 | |
| 184 | // Initialize. |
| 185 | WPMailSMTPAdminNotifications.init(); |
| 186 |