PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.3.4
Ever Compare – Products Compare Plugin for WooCommerce v1.3.4
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / assets / js / plugins_install_manager.js

plugins_install_manager.js in Ever Compare – Products Compare Plugin for WooCommerce 1.3.4, at assets/js/plugins_install_manager.js

158 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Plugins Install manager JS
3 */
4 ;( function ( $ ) {
5 'use strict';
6
7 // Tab Menu
8 $(".htrp-admin-tabs").on('click', 'a', function(e){
9 e.preventDefault();
10 var $this = $(this),
11 $target = $this.attr('href');
12
13 $this.addClass('htrp-active').parent().siblings().children('a').removeClass('htrp-active');
14 $( '.htrp-admin-tab-pane'+ $target ).addClass('htrp-active').siblings().removeClass('htrp-active');
15 });
16
17 /*
18 * Plugin Installation Manager
19 */
20 var PluginInstallManager = {
21
22 init: function(){
23 $( document ).on('click','.htrp-install-now', PluginInstallManager.installNow );
24 $( document ).on('click','.htrp-activate-now', PluginInstallManager.activatePlugin);
25 $( document ).on('wp-plugin-install-success', PluginInstallManager.installingSuccess);
26 $( document ).on('wp-plugin-install-error', PluginInstallManager.installingError);
27 $( document ).on('wp-plugin-installing', PluginInstallManager.installingProcess);
28 },
29
30 /**
31 * Installation Error.
32 */
33 installingError: function( e, response ) {
34 e.preventDefault();
35 var $card = $( '.htrp-plugin-' + response.slug );
36 $button = $card.find( '.button' );
37 $button.removeClass( 'button-primary' ).addClass( 'disabled' ).html( wp.updates.l10n.installFailedShort );
38 },
39
40 /**
41 * Installing Process
42 */
43 installingProcess: function(e, args){
44 e.preventDefault();
45 var $card = $( '.htrp-plugin-' + args.slug ),
46 $button = $card.find( '.button' );
47 $button.text( htrp_params.buttontxt.installing ).addClass( 'updating-message' );
48 },
49
50 /**
51 * Plugin Install Now
52 */
53 installNow: function(e){
54 e.preventDefault();
55
56 var $button = $( e.target ),
57 $plugindata = $button.data('pluginopt');
58
59 if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
60 return;
61 }
62 if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
63 wp.updates.requestFilesystemCredentials( e );
64 $( document ).on( 'credential-modal-cancel', function() {
65 var $message = $( '.htrp-install-now.updating-message' );
66 $message.removeClass( 'updating-message' ).text( wp.updates.l10n.installNow );
67 wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
68 });
69 }
70 wp.updates.installPlugin( {
71 slug: $plugindata['slug']
72 });
73
74 },
75
76 /**
77 * After Plugin Install success
78 */
79 installingSuccess: function( e, response ) {
80 var $message = $( '.htrp-plugin-' + response.slug ).find( '.button' );
81
82 var $plugindata = $message.data('pluginopt');
83
84 $message.removeClass( 'htrp-install-now installed button-disabled updated-message' )
85 .addClass( 'updating-message' )
86 .html( htrp_params.buttontxt.activating );
87
88 setTimeout( function() {
89 $.ajax( {
90 url: htrp_params.ajaxurl,
91 type: 'POST',
92 data: {
93 action : htrp_params.text_domain+'_ajax_plugin_activation',
94 location : $plugindata['location'],
95 nonce : htrp_params.nonce,
96 },
97 } ).done( function( result ) {
98 if ( result.success ) {
99 $message.removeClass( 'button-primary htrp-install-now htrp-activate-now updating-message' )
100 .attr( 'disabled', 'disabled' )
101 .addClass( 'disabled' )
102 .text( htrp_params.buttontxt.active );
103
104 } else {
105 $message.removeClass( 'updating-message' );
106 }
107
108 });
109
110 }, 1200 );
111
112 },
113
114 /**
115 * Plugin Activate
116 */
117 activatePlugin: function( e, response ) {
118 e.preventDefault();
119
120 var $button = $( e.target ),
121 $plugindata = $button.data('pluginopt');
122
123 if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
124 return;
125 }
126
127 $button.addClass( 'updating-message button-primary' ).html( htrp_params.buttontxt.activating );
128
129 $.ajax( {
130 url: htrp_params.ajaxurl,
131 type: 'POST',
132 data: {
133 action : htrp_params.text_domain+'_ajax_plugin_activation',
134 location : $plugindata['location'],
135 nonce : htrp_params.nonce,
136 },
137 }).done( function( response ) {
138 if ( response.success ) {
139 $button.removeClass( 'button-primary htrp-install-now htrp-activate-now updating-message' )
140 .attr( 'disabled', 'disabled' )
141 .addClass( 'disabled' )
142 .text( htrp_params.buttontxt.active );
143 }
144 });
145
146 },
147
148
149 };
150
151 /**
152 * Initialize PluginInstallManager
153 */
154 $( document ).ready( function() {
155 PluginInstallManager.init();
156 });
157
158 } )( jQuery );