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 ;
0 commit comments