';
// Remove link and parent li from action links and move it to bottom row
var dismissLink = document.querySelector( '.jetpack-plugin-search__dismiss' );
dismissLink.parentNode.parentNode.removeChild( dismissLink.parentNode );
document.querySelector( '.jetpack-plugin-search__bottom' ).appendChild( dismissLink );
}
},
/**
* Check if plugin card list nodes changed. If there's a Jetpack PSH card, replace the bottom row.
* @param {array} mutationsList
*/
replaceOnNewResults: function ( mutationsList ) {
mutationsList.forEach( function ( mutation ) {
if (
'childList' === mutation.type &&
1 === document.querySelectorAll( '.plugin-card-jetpack-plugin-search' ).length
) {
JetpackPSH.replaceCardBottom();
}
} );
},
dismiss: function ( moduleName ) {
document.getElementById( 'the-list' ).removeChild( JetpackPSH.getCard() );
$.ajax( {
url: jpsh.base_rest_url + '/hints',
method: 'post',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', jpsh.nonce );
},
data: JSON.stringify( {
hint: moduleName,
} ),
contentType: 'application/json',
dataType: 'json',
} ).done( function () {
JetpackPSH.trackEvent( 'wpa_plugin_search_dismiss', moduleName );
} );
},
ajaxActivateModule: function ( moduleName ) {
var $moduleBtn = JetpackPSH.$pluginFilter.find( '#plugin-select-activate' );
$moduleBtn.toggleClass( 'install-now updating-message' );
$moduleBtn.prop( 'disabled', true );
$moduleBtn.text( jpsh.activating );
var data = {};
data[ moduleName ] = true;
$.ajax( {
url: jpsh.base_rest_url + '/settings',
method: 'post',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', jpsh.nonce );
},
data: JSON.stringify( data ),
contentType: 'application/json',
dataType: 'json',
} )
.done( function () {
JetpackPSH.updateButton( moduleName );
JetpackPSH.trackEvent( 'wpa_plugin_search_activate', moduleName );
} )
.error( function () {
$moduleBtn.toggleClass( 'install-now updating-message' );
} );
},
// Remove onclick handler, disable loading spinner, update button to redirect to module settings.
updateButton: function ( moduleName ) {
$.ajax( {
url: jpsh.base_rest_url + '/module/' + moduleName,
method: 'get',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', jpsh.nonce );
},
dataType: 'json',
} ).done( function ( response ) {
var $moduleBtn = JetpackPSH.$pluginFilter.find( '#plugin-select-activate' );
$moduleBtn.prop( 'onclick', null ).off( 'click' );
$moduleBtn.toggleClass( 'install-now updating-message' );
$moduleBtn.text( jpsh.activated );
setTimeout( function () {
var url = 'https://jetpack.com/redirect/?source=plugin-hint-learn-' + moduleName,
label = jpsh.getStarted,
classes = 'jetpack-plugin-search__primary button',
track = 'configure';
// If the feature has options in Jetpack admin UI, link to them.
if ( response.options && 0 < Object.keys( response.options ).length ) {
url = $moduleBtn.data( 'configure-url' );
label = jpsh.manageSettings;
classes += ' jetpack-plugin-search__configure';
} else {
// If it has no options, the Get started button will be displayed so remove the Learn more link if it's there.
var learnMore = document.querySelector( '.jetpack-plugin-search__learn-more' );
learnMore.parentNode.removeChild( learnMore );
classes += ' jetpack-plugin-search__get-started';
track = 'get_started';
}
$moduleBtn.replaceWith(
'