| 1 |
jQuery(document).ready(function () { |
| 2 |
|
| 3 |
// to fix conflict with bootstrap tooltip |
| 4 |
jQuery.widget.bridge('uitooltip', jQuery.ui.tooltip); |
| 5 |
jQuery(document).uitooltip({ |
| 6 |
items:"span.tooltip", |
| 7 |
track:true, |
| 8 |
content:function () |
| 9 |
{ |
| 10 |
var element = jQuery(this); |
| 11 |
return element.parents('.tooltipcontainer').children('.tooltipcontent').html(); |
| 12 |
} |
| 13 |
}); |
| 14 |
|
| 15 |
jQuery('input[type=radio][name=mwp_setup_installation_hosting_type]').change(function() { |
| 16 |
if (this.value == 2) { |
| 17 |
jQuery('input[name="mwp_setup_installation_system_type"]').removeAttr("disabled"); |
| 18 |
jQuery('#mwp_setup_os_type').fadeIn(500); |
| 19 |
} |
| 20 |
else { |
| 21 |
jQuery('input[name="mwp_setup_installation_system_type"]').attr("disabled", "disabled"); |
| 22 |
jQuery('#mwp_setup_os_type').fadeOut(500); |
| 23 |
} |
| 24 |
}); |
| 25 |
|
| 26 |
jQuery('#mwp_setup_planning_backup').change(function() { |
| 27 |
if (jQuery(this).is(':checked')) { |
| 28 |
jQuery('#mwp_setup_tr_backup_method').fadeIn(500); |
| 29 |
jQuery('#mwp_setup_backup_method').removeAttr('disabled'); |
| 30 |
} |
| 31 |
else { |
| 32 |
jQuery('#mwp_setup_tr_backup_method').fadeOut(500); |
| 33 |
jQuery('#mwp_setup_backup_method').attr('disabled', 'disabled'); |
| 34 |
} |
| 35 |
}); |
| 36 |
|
| 37 |
jQuery('#mwp_setup_backup_method').on('change', function() { |
| 38 |
var bkmethod = jQuery(this).val(); |
| 39 |
jQuery('.mainwp-backups-notice').hide(); |
| 40 |
jQuery('.mainwp-backups-notice[method="' + bkmethod + '"]').show(); |
| 41 |
}); |
| 42 |
|
| 43 |
jQuery('#mwp_setup_manage_planning').change(function() { |
| 44 |
if ((jQuery(this).val() == 2) && (jQuery('#mwp_setup_type_hosting').val() == 3)) { |
| 45 |
jQuery('#mwp_setup_hosting_notice').fadeIn(500); |
| 46 |
} else { |
| 47 |
jQuery('#mwp_setup_hosting_notice').fadeOut(1000); |
| 48 |
} |
| 49 |
}) |
| 50 |
|
| 51 |
jQuery('#mwp_setup_manage_planning').change(function() { |
| 52 |
mainwp_setup_showhide_hosting_notice(); |
| 53 |
}) |
| 54 |
jQuery('#mwp_setup_type_hosting').change(function() { |
| 55 |
mainwp_setup_showhide_hosting_notice(); |
| 56 |
}) |
| 57 |
}); |
| 58 |
|
| 59 |
mainwp_setup_auth_uptime_robot = function(url) { |
| 60 |
window.open(url, 'Authorize Uptime Robot', 'height=600,width=700'); |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
mainwp_setup_showhide_hosting_notice = function() { |
| 66 |
if ((jQuery('#mwp_setup_manage_planning').val() == 2) && (jQuery('#mwp_setup_type_hosting').val() == 3)) { |
| 67 |
jQuery('#mwp_setup_hosting_notice').fadeIn(500); |
| 68 |
} else { |
| 69 |
jQuery('#mwp_setup_hosting_notice').fadeOut(500); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
mainwp_setup_grab_extension = function(retring, pRegisterLater) { |
| 74 |
var parent = jQuery("#mwp_setup_auto_install_loading"); |
| 75 |
var statusEl = parent.find('span.status'); |
| 76 |
var loadingEl = parent.find("i"); |
| 77 |
|
| 78 |
var extProductId = jQuery('#mwp_setup_extension_product_id').val(); |
| 79 |
if (extProductId == '') { |
| 80 |
statusEl.css('color', 'red'); |
| 81 |
statusEl.html(' ' + "ERROR: empty extension product id.").fadeIn(); |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
var data = { |
| 86 |
action:'mainwp_setup_extension_getextension', |
| 87 |
productId: extProductId, |
| 88 |
register_later: pRegisterLater |
| 89 |
}; |
| 90 |
|
| 91 |
if (retring == true) { |
| 92 |
statusEl.css('color', '#0074a2'); |
| 93 |
statusEl.html(' ' + "Connection error detected. The Verify Certificate option has been switched to NO. Retrying...").fadeIn(); |
| 94 |
} else |
| 95 |
statusEl.hide(); |
| 96 |
|
| 97 |
loadingEl.show(); |
| 98 |
jQuery.post(ajaxurl, data, function (response) |
| 99 |
{ |
| 100 |
loadingEl.hide(); |
| 101 |
var undefError = false; |
| 102 |
if (response) { |
| 103 |
if (response.result == 'SUCCESS') { |
| 104 |
jQuery('#mwp_setup-install-extension').html(response.data); |
| 105 |
mainwp_setup_extension_install(pRegisterLater); |
| 106 |
} else if (response.error) { |
| 107 |
statusEl.css('color', 'red'); |
| 108 |
statusEl.html(response.error).fadeIn(); |
| 109 |
} else if (response.retry_action && response.retry_action == 1){ |
| 110 |
mainwp_setup_grab_extension(true, pRegisterLater); |
| 111 |
return false; |
| 112 |
} else { |
| 113 |
undefError = true; |
| 114 |
} |
| 115 |
} else { |
| 116 |
undefError = true; |
| 117 |
} |
| 118 |
|
| 119 |
if (undefError) { |
| 120 |
statusEl.css('color', 'red'); |
| 121 |
statusEl.html('<i class="fa fa-exclamation-circle"></i> Undefined error!').fadeIn(); |
| 122 |
} |
| 123 |
}, 'json'); |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
mainwp_setup_extension_install = function(pRegisterLater) { |
| 128 |
var pExtToInstall = jQuery('.mwp_setup_extension_installing .extension_to_install'); |
| 129 |
var loadingEl = pExtToInstall.find('.ext_installing i'); |
| 130 |
var statusEl = pExtToInstall.find('.ext_installing .status'); |
| 131 |
loadingEl.show(); |
| 132 |
statusEl.css('color', '#000'); |
| 133 |
statusEl.html('Installing...'); |
| 134 |
|
| 135 |
var data = { |
| 136 |
action:'mainwp_setup_extension_downloadandinstall', |
| 137 |
download_link: pExtToInstall.attr('download-link'), |
| 138 |
security: mainwpSetupLocalize.nonce |
| 139 |
}; |
| 140 |
|
| 141 |
jQuery.ajax({ |
| 142 |
type: 'POST', |
| 143 |
url: ajaxurl, |
| 144 |
data: data, |
| 145 |
success: function() { return function (res_data) { |
| 146 |
loadingEl.hide(); |
| 147 |
var reg = new RegExp('<mainwp>(.*)</mainwp>'); |
| 148 |
var matches = reg.exec(res_data); |
| 149 |
var response = ''; |
| 150 |
var failed = true; |
| 151 |
if (matches) { |
| 152 |
response_json = matches[1]; |
| 153 |
response = jQuery.parseJSON(response_json ); |
| 154 |
} |
| 155 |
if (response != '') { |
| 156 |
if (response.result == 'SUCCESS') { |
| 157 |
failed = false; |
| 158 |
statusEl.css('color', '#21759B') |
| 159 |
statusEl.html(response.output).show(); |
| 160 |
jQuery('.mwp_setup_extension_installing').append('<span class="extension_installed_success" slug="' + response.slug + '"></span>'); |
| 161 |
if (!pRegisterLater) { |
| 162 |
jQuery('#mwp_setup_active_extension').fadeIn(500); |
| 163 |
mainwp_setup_extension_activate(false); |
| 164 |
} |
| 165 |
} else if (response.error) { |
| 166 |
statusEl.css('color', 'red'); |
| 167 |
statusEl.html('<strong><i class="fa fa-exclamation-circle"></i> ERROR:</strong> ' + response.error).show(); |
| 168 |
} else { |
| 169 |
statusEl.css('color', 'red'); |
| 170 |
statusEl.html('<i class="fa fa-exclamation-circle"></i> Undefined error!').show(); |
| 171 |
} |
| 172 |
} else { |
| 173 |
statusEl.css('color', 'red'); |
| 174 |
statusEl.html('<i class="fa fa-exclamation-circle"></i> Undefined error!').show(); |
| 175 |
} |
| 176 |
if (failed) { |
| 177 |
jQuery('#mwp_setup-install-extension').append(jQuery('#mwp_setup_extension_retry_install')[0].innerHTML); |
| 178 |
} |
| 179 |
} }() |
| 180 |
}); |
| 181 |
return false; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
mainwp_setup_extension_activate_plugin = function(pRegisterLater) { |
| 186 |
var plugins = []; |
| 187 |
jQuery('.extension_installed_success').each(function() { |
| 188 |
plugins.push(jQuery(this).attr('slug')); |
| 189 |
}); |
| 190 |
|
| 191 |
if (plugins.length == 0) { |
| 192 |
return; |
| 193 |
} |
| 194 |
|
| 195 |
var data = { |
| 196 |
action:'mainwp_setup_extension_activate_plugin', |
| 197 |
plugins: plugins, |
| 198 |
security: mainwpSetupLocalize.nonce |
| 199 |
}; |
| 200 |
|
| 201 |
jQuery.post(ajaxurl, data, function(response) { |
| 202 |
if (response == 'SUCCESS') { |
| 203 |
if (!pRegisterLater) { |
| 204 |
jQuery('#mwp_setup_active_extension').fadeIn(500); |
| 205 |
mainwp_setup_extension_activate(false); |
| 206 |
} |
| 207 |
} else { |
| 208 |
|
| 209 |
} |
| 210 |
}); |
| 211 |
} |
| 212 |
|
| 213 |
mainwp_setup_extension_activate = function(retring) |
| 214 |
{ |
| 215 |
var parent = jQuery("#mwp_setup_grabing_api_key_loading"); |
| 216 |
var statusEl = parent.find('span.status'); |
| 217 |
var loadingEl = parent.find("i"); |
| 218 |
var extensionSlug = jQuery('#mwp_setup_extension_product_id').attr('slug'); |
| 219 |
var data = { |
| 220 |
action:'mainwp_setup_extension_grabapikey', |
| 221 |
slug:extensionSlug |
| 222 |
}; |
| 223 |
|
| 224 |
if (retring == true) { |
| 225 |
statusEl.css('color', '#0074a2'); |
| 226 |
statusEl.html(' ' + "Connection error detected. The Verify Certificate option has been switched to NO. Retrying...").fadeIn(); |
| 227 |
} else |
| 228 |
statusEl.hide(); |
| 229 |
|
| 230 |
loadingEl.show(); |
| 231 |
jQuery.post(ajaxurl, data, function (response) |
| 232 |
{ |
| 233 |
loadingEl.hide(); |
| 234 |
if (response) { |
| 235 |
if (response.result == 'SUCCESS') { |
| 236 |
statusEl.css('color', '#0074a2'); |
| 237 |
statusEl.html('<i class="fa fa-check-circle"></i> ' + "Extension has been activated successfully!").fadeIn(); |
| 238 |
} else if (response.error) { |
| 239 |
statusEl.css('color', 'red'); |
| 240 |
statusEl.html(response.error).fadeIn(); |
| 241 |
} else if (response.retry_action && response.retry_action == 1){ |
| 242 |
jQuery("#mainwp_api_sslVerifyCertificate").val(0); |
| 243 |
mainwp_setup_extension_activate(true); |
| 244 |
return false; |
| 245 |
} else { |
| 246 |
statusEl.css('color', 'red'); |
| 247 |
statusEl.html('<i class="fa fa-exclamation-circle"></i> Undefined error!').fadeIn(); |
| 248 |
} |
| 249 |
} else { |
| 250 |
statusEl.css('color', 'red'); |
| 251 |
statusEl.html('<i class="fa fa-exclamation-circle"></i> Undefined error!').fadeIn(); |
| 252 |
} |
| 253 |
}, 'json'); |
| 254 |
}; |
| 255 |
|
| 256 |
jQuery(document).ready(function () { |
| 257 |
jQuery('.mwp_remove_email').live('click', function () { |
| 258 |
jQuery(this).closest('.mwp_email_box').remove(); |
| 259 |
return false; |
| 260 |
}); |
| 261 |
jQuery('#mwp_add_other_email').live('click', function () { |
| 262 |
jQuery('#mwp_add_other_email').before('<div class="mwp_email_box"><input type="text" name="mainwp_options_email[]" size="35" value=""/> <a href="#" class="mwp_remove_email"><i class="fa fa-minus-circle fa-lg mainwp-red" aria-hidden="true"></i></a></div>'); |
| 263 |
return false; |
| 264 |
}); |
| 265 |
}); |
| 266 |
|
| 267 |
|