summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/_inc/jetpack-jitm.js')
-rw-r--r--plugins/jetpack/_inc/jetpack-jitm.js41
1 files changed, 40 insertions, 1 deletions
diff --git a/plugins/jetpack/_inc/jetpack-jitm.js b/plugins/jetpack/_inc/jetpack-jitm.js
index cffccf5e..544a833f 100644
--- a/plugins/jetpack/_inc/jetpack-jitm.js
+++ b/plugins/jetpack/_inc/jetpack-jitm.js
@@ -31,9 +31,22 @@ jQuery( document ).ready( function( $ ) {
html += '</div>';
}
html += '</div>';
+ if ( envelope.activate_module ) {
+ html += '<div class="jitm-banner__action" id="jitm-banner__activate">';
+ html += '<a href="#" data-module="' + envelope.activate_module + '" type="button" class="jitm-button is-compact is-primary jptracks" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-' + envelope.id + '-activate_module">' + window.jitm_config.activate_module_text + '</a>';
+ html += '</div>';
+ }
if ( envelope.CTA.message ) {
+ var ctaClasses = 'jitm-button is-compact jptracks';
+ if (
+ envelope.CTA.primary &&
+ null === envelope.activate_module
+ ) {
+ ctaClasses += ' is-primary';
+ }
+
html += '<div class="jitm-banner__action">';
- html += '<a href="' + envelope.url + '" target="' + ( envelope.CTA.newWindow === false ? '_self' : '_blank') + '" rel="noopener noreferrer" title="' + envelope.CTA.message + '" data-module="' + envelope.feature_class + '" type="button" class="jitm-button is-compact ' + ( envelope.CTA.primary ? 'is-primary' : '' ) + ' jptracks" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-' + envelope.id + '">' + envelope.CTA.message + '</a>';
+ html += '<a href="' + envelope.url + '" target="' + ( envelope.CTA.newWindow === false ? '_self' : '_blank' ) + '" rel="noopener noreferrer" title="' + envelope.CTA.message + '" data-module="' + envelope.feature_class + '" type="button" class="' + ctaClasses + '" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-' + envelope.id + '">' + envelope.CTA.message + '</a>';
html += '</div>';
}
html += '<a href="#" data-module="' + envelope.feature_class + '" class="jitm-banner__dismiss"></a>';
@@ -80,6 +93,32 @@ jQuery( document ).ready( function( $ ) {
// Add to Jetpack notices within the Jetpack settings app.
$template.prependTo( $( '#jp-admin-notices' ) );
+
+ // Handle Module activation button if it exists.
+ $template.find( '#jitm-banner__activate a' ).click( function() {
+ var $activate_button = $( this );
+
+ // Do not allow any requests if the button is disabled.
+ if ( $activate_button.attr( 'disabled' ) ) {
+ return false;
+ }
+
+ // Make request to activate module.
+ $.ajax( {
+ url: window.jitm_config.api_root + 'jetpack/v4/module/' + $activate_button.data( 'module' ) + '/active',
+ method: 'POST',
+ beforeSend: function( xhr ) {
+ xhr.setRequestHeader( 'X-WP-Nonce', $el.data( 'nonce' ) );
+
+ // Change the button status to disabled as the change is in progress.
+ $( '#jitm-banner__activate a' ).text( window.jitm_config.activating_module_text );
+ $( '#jitm-banner__activate a' ).attr( 'disabled', true );
+ }
+ } ).done( function() {
+ $( '#jitm-banner__activate a' ).text( window.jitm_config.activated_module_text );
+ $( '#jitm-banner__activate a' ).attr( 'disabled', true );
+ } );
+ } );
};
$( '.jetpack-jitm-message' ).each( function() {