Skip to content

Commit a8c64f2

Browse files
committed
Add ability to install plugins from the Integrations page.
1 parent 30d2a5b commit a8c64f2

File tree

5 files changed

+286
-83
lines changed

5 files changed

+286
-83
lines changed

assets/css/integrations.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
transition: all 1.5s;
2424
}
2525

26+
.hcaptcha-integrations table tr.install:before,
2627
.hcaptcha-integrations table tr.on:before,
2728
.hcaptcha-integrations table tr.off:before {
2829
visibility: visible;
@@ -46,6 +47,7 @@
4647
background-image: url( '../images/spinner-white.svg' );
4748
}
4849

50+
.hcaptcha-integrations table tr.install:after,
4951
.hcaptcha-integrations table tr.on:after,
5052
.hcaptcha-integrations table tr.off:after {
5153
visibility: visible;
@@ -56,6 +58,10 @@
5658
background-size: auto 80%;
5759
}
5860

61+
.hcaptcha-integrations table tr.install:after {
62+
background-image: url( '../images/spinner-gold.svg' );
63+
}
64+
5965
.hcaptcha-integrations table tr.on:after {
6066
background-image: url( '../images/spinner-green.svg' );
6167
}
@@ -113,7 +119,7 @@
113119
background-color: #d63638;
114120
}
115121

116-
.hcaptcha-integrations > table ~ table tr th .hcaptcha-integrations-logo[data-installed="0"]:hover::before {
122+
.hcaptcha-integrations > table ~ table tr th .hcaptcha-integrations-logo[data-installed="false"]:hover::before {
117123
background-color: #dba617;
118124
}
119125

assets/images/spinner-gold.svg

Lines changed: 40 additions & 0 deletions
Loading

assets/js/integrations.js

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/* global jQuery, HCaptchaIntegrationsObject, kaggDialog */
22

33
/**
4-
* @param HCaptchaIntegrationsObject.ajaxUrl
4+
* @param HCaptchaIntegrationsObject.CancelBtnText
5+
* @param HCaptchaIntegrationsObject.OKBtnText
56
* @param HCaptchaIntegrationsObject.action
6-
* @param HCaptchaIntegrationsObject.nonce
7-
* @param HCaptchaIntegrationsObject.activateMsg
8-
* @param HCaptchaIntegrationsObject.deactivateMsg
9-
* @param HCaptchaIntegrationsObject.installMsg
7+
* @param HCaptchaIntegrationsObject.activatePluginMsg
108
* @param HCaptchaIntegrationsObject.activateThemeMsg
9+
* @param HCaptchaIntegrationsObject.ajaxUrl
10+
* @param HCaptchaIntegrationsObject.deactivatePluginMsg
1111
* @param HCaptchaIntegrationsObject.deactivateThemeMsg
12-
* @param HCaptchaIntegrationsObject.selectThemeMsg
12+
* @param HCaptchaIntegrationsObject.defaultTheme
13+
* @param HCaptchaIntegrationsObject.installPluginMsg
14+
* @param HCaptchaIntegrationsObject.installThemeMsg
15+
* @param HCaptchaIntegrationsObject.nonce
1316
* @param HCaptchaIntegrationsObject.onlyOneThemeMsg
14-
* @param HCaptchaIntegrationsObject.unexpectedErrorMsg
15-
* @param HCaptchaIntegrationsObject.OKBtnText
16-
* @param HCaptchaIntegrationsObject.CancelBtnText
17+
* @param HCaptchaIntegrationsObject.selectThemeMsg
1718
* @param HCaptchaIntegrationsObject.themes
18-
* @param HCaptchaIntegrationsObject.defaultTheme
19+
* @param HCaptchaIntegrationsObject.unexpectedErrorMsg
1920
*/
2021

2122
/**
@@ -162,6 +163,14 @@ const integrations = function( $ ) {
162163
}
163164

164165
$( '.form-table img' ).on( 'click', function( event ) {
166+
function maybeInstallEntity( confirmation ) {
167+
if ( ! confirmation ) {
168+
return;
169+
}
170+
171+
installEntity();
172+
}
173+
165174
function maybeToggleActivation( confirmation ) {
166175
if ( ! confirmation ) {
167176
return;
@@ -188,32 +197,43 @@ const integrations = function( $ ) {
188197

189198
for ( const [ key, status ] of Object.entries( stati ) ) {
190199
const statusClass = 'hcaptcha-integrations-' + key.replace( /_/g, '-' );
191-
192200
const $tr = $( `tr.${ statusClass }` );
201+
const $logo = $tr.find( '.hcaptcha-integrations-logo' );
193202
const currStatus = isActiveTable( $tr.closest( '.form-table' ) );
194203

204+
if ( status ) {
205+
$logo.attr( 'data-installed', true );
206+
}
207+
195208
if ( currStatus !== status ) {
196209
const $toTable = $tables.eq( status ? 0 : 1 );
197-
const alt = $tr.find( '.hcaptcha-integrations-logo img' ).attr( 'alt' );
210+
const alt = $logo.find( 'img' ).attr( 'alt' );
198211

199212
insertIntoTable( $toTable, alt, $tr );
200213
}
201214
}
202215
}
203216

204-
function toggleActivation() {
205-
const activateClass = activate ? 'on' : 'off';
217+
function installEntity() {
218+
toggleActivation( true );
219+
}
220+
221+
function toggleActivation( install = false ) {
222+
let actionClass = activate ? 'on' : 'off';
223+
actionClass = install ? 'install' : actionClass;
224+
206225
const newTheme = getSelectedTheme();
207226
const data = {
208227
action: HCaptchaIntegrationsObject.action,
209228
nonce: HCaptchaIntegrationsObject.nonce,
229+
install,
210230
activate,
211231
entity,
212232
status,
213233
newTheme,
214234
};
215235

216-
$tr.addClass( activateClass );
236+
$tr.addClass( actionClass );
217237

218238
// noinspection JSVoidFunctionReturnValueUsed
219239
$.post( {
@@ -271,7 +291,7 @@ const integrations = function( $ ) {
271291
}
272292
)
273293
.always( function() {
274-
$tr.removeClass( 'on off' );
294+
$tr.removeClass( 'install on off' );
275295
} );
276296
}
277297

@@ -307,12 +327,12 @@ const integrations = function( $ ) {
307327

308328
if ( $fieldset.attr( 'disabled' ) ) {
309329
title = entity === 'plugin'
310-
? HCaptchaIntegrationsObject.activateMsg
330+
? HCaptchaIntegrationsObject.activatePluginMsg
311331
: HCaptchaIntegrationsObject.activateThemeMsg;
312332
activate = true;
313333
} else {
314334
if ( entity === 'plugin' ) {
315-
title = HCaptchaIntegrationsObject.deactivateMsg;
335+
title = HCaptchaIntegrationsObject.deactivatePluginMsg;
316336
} else {
317337
title = HCaptchaIntegrationsObject.deactivateThemeMsg;
318338
content = '<p>' + HCaptchaIntegrationsObject.selectThemeMsg + '</p>';
@@ -352,8 +372,17 @@ const integrations = function( $ ) {
352372

353373
const $logo = $tr.find( '.hcaptcha-integrations-logo' );
354374

355-
if ( ! $logo.data( 'installed' ) ) {
356-
title = HCaptchaIntegrationsObject.installMsg;
375+
if ( $logo.attr( 'data-installed' ) === 'false' ) {
376+
if ( event.ctrlKey ) {
377+
installEntity();
378+
379+
return;
380+
}
381+
382+
title = entity === 'plugin'
383+
? HCaptchaIntegrationsObject.installPluginMsg
384+
: HCaptchaIntegrationsObject.installThemeMsg;
385+
357386
title = title.replace( '%s', alt );
358387

359388
kaggDialog.confirm( {
@@ -364,7 +393,11 @@ const integrations = function( $ ) {
364393
ok: {
365394
text: HCaptchaIntegrationsObject.OKBtnText,
366395
},
396+
cancel: {
397+
text: HCaptchaIntegrationsObject.CancelBtnText,
398+
},
367399
},
400+
onAction: maybeInstallEntity,
368401
} );
369402

370403
return;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ Instructions for popular native integrations are below:
600600

601601
= 4.9.0 =
602602
* Added compatibility with Ninja Forms v3.8.22.
603+
* Added ability to install plugins from the Integrations page.
603604
* Fixed layout of a modern Jetpack form in outlined and animated styles.
604605
* Fixed fatal error as a consequence of a bug in the TutorLMS.
605606

0 commit comments

Comments
 (0)