| 1 |
jQuery(document).ready(function ($) { |
| 2 |
$('.kad-panel-left .nav-tab-link').click(function (event) { |
| 3 |
event.preventDefault(); |
| 4 |
var contain = $(this).closest('.kad-panel-left') |
| 5 |
var panel = contain.find('.nav-tab-wrapper'); |
| 6 |
var active = panel.find('.nav-tab-active'); |
| 7 |
var opencontent = $(this).closest('.kad-panel-contain').find('.nav-tab-content.panel_open'); |
| 8 |
var contentid = $(this).data('tab-id'); |
| 9 |
var tab = panel.find('a[data-tab-id="'+contentid+'"]'); |
| 10 |
if (active.data('tab-id') == contentid ) { |
| 11 |
//leave |
| 12 |
} else { |
| 13 |
tab.addClass('nav-tab-active'); |
| 14 |
active.removeClass('nav-tab-active'); |
| 15 |
opencontent.removeClass('panel_open'); |
| 16 |
$('#'+contentid).addClass('panel_open'); |
| 17 |
} |
| 18 |
|
| 19 |
return false; |
| 20 |
|
| 21 |
}); |
| 22 |
}); |
| 23 |
/** |
| 24 |
* Ajax install the Theme Plugin |
| 25 |
* |
| 26 |
*/ |
| 27 |
(function($, window, document, undefined){ |
| 28 |
"use strict"; |
| 29 |
|
| 30 |
$(function(){ |
| 31 |
$('.kt-trigger-plugin-install').on( 'click', function( event ) { |
| 32 |
var $button = $( event.target ); |
| 33 |
event.preventDefault(); |
| 34 |
/** |
| 35 |
* Keep button from running twice |
| 36 |
*/ |
| 37 |
if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
function ajax_callback(response){ |
| 42 |
if(typeof response === "object" && typeof response.message !== "undefined"){ |
| 43 |
// The plugin is done (installed, updated and activated). |
| 44 |
if(typeof response.done != "undefined" && response.done){ |
| 45 |
buttonStatusInstalled( $button.data('installed-label') ); |
| 46 |
activatePlugin(); |
| 47 |
} else if( typeof response.url != "undefined" ){ |
| 48 |
// we have an ajax url action to perform. |
| 49 |
jQuery.post(response.url, response, ajax_callback).fail(ajax_callback); |
| 50 |
}else{ |
| 51 |
// error processing this plugin |
| 52 |
buttonStatusDisabled( 'Error' ); |
| 53 |
} |
| 54 |
} else { |
| 55 |
// The TGMPA returns a whole page as response, so check, if this plugin is done. |
| 56 |
activatePlugin(); |
| 57 |
} |
| 58 |
} |
| 59 |
/** |
| 60 |
* Install a plugin |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
function installPlugin(){ |
| 65 |
|
| 66 |
if ( $button.hasClass( 'install-toolkit' ) ) { |
| 67 |
buttonStatusInProgress( $button.data('installing-label') ); |
| 68 |
jQuery.post(toolkit_welcome_params.ajaxurl, { |
| 69 |
action: "kadence_import_plugin", |
| 70 |
wpnonce: toolkit_welcome_params.wpnonce, |
| 71 |
}, ajax_callback).fail( ajax_callback ); |
| 72 |
|
| 73 |
} else { |
| 74 |
$.ajax({ |
| 75 |
url : $button.data('install-url'), |
| 76 |
type: 'GET', |
| 77 |
data: {}, |
| 78 |
beforeSend: function () { |
| 79 |
buttonStatusInProgress( $button.data('installing-label') ); |
| 80 |
}, |
| 81 |
success: function( reposnse ) { |
| 82 |
buttonStatusInstalled( $button.data('installed-label') ); |
| 83 |
activatePlugin(); |
| 84 |
}, |
| 85 |
error: function (xhr, ajaxOptions, thrownError) { |
| 86 |
// Installation failed |
| 87 |
buttonStatusDisabled( 'Error' ); |
| 88 |
} |
| 89 |
}); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Activate a plugin |
| 95 |
* |
| 96 |
* @return void |
| 97 |
*/ |
| 98 |
function activatePlugin(){ |
| 99 |
|
| 100 |
$.ajax({ |
| 101 |
url : $button.data('activate-url'), |
| 102 |
type: 'GET', |
| 103 |
data: {}, |
| 104 |
beforeSend: function () { |
| 105 |
buttonStatusInProgress( $button.data('activating-label') ); |
| 106 |
}, |
| 107 |
success: function( reposnse ) { |
| 108 |
buttonStatusDisabled( $button.data('activated-label') ); |
| 109 |
if ( $button.data('redirect-url') ) { |
| 110 |
location.replace( $button.data('redirect-url') ); |
| 111 |
} |
| 112 |
}, |
| 113 |
error: function (xhr, ajaxOptions, thrownError) { |
| 114 |
// Activation failed |
| 115 |
console.log( xhr.responseText ); |
| 116 |
buttonStatusDisabled( 'Error' ); |
| 117 |
} |
| 118 |
}); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Change button status to in-progress |
| 123 |
* |
| 124 |
* @return void |
| 125 |
*/ |
| 126 |
function buttonStatusInProgress( message ){ |
| 127 |
$button.addClass('updating-message').removeClass('button-disabled kt-not-installed installed').text( message ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Change button status to disabled |
| 132 |
* |
| 133 |
* @return void |
| 134 |
*/ |
| 135 |
function buttonStatusDisabled( message ){ |
| 136 |
$button.removeClass('updating-message kt-not-installed installed') |
| 137 |
.addClass('button-disabled') |
| 138 |
.text( message ); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Change button status to installed |
| 143 |
* |
| 144 |
* @return void |
| 145 |
*/ |
| 146 |
function buttonStatusInstalled( message ){ |
| 147 |
$button.removeClass('updating-message kt-not-installed') |
| 148 |
.addClass('installed') |
| 149 |
.text( message ); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
if( $button.data('action') === 'install' ){ |
| 154 |
installPlugin(); |
| 155 |
} else if( $button.data('action') === 'activate' ){ |
| 156 |
activatePlugin(); |
| 157 |
} |
| 158 |
}); |
| 159 |
}); |
| 160 |
})(jQuery, window, document); |