(function ($) {
$(function () {
$( '.apct-tabs-trigger' ).click(function(){
$( '.apct-tabs-trigger' ).removeClass( 'nav-tab-active' );
$(this).addClass( 'nav-tab-active' );
var board_id = 'tab-'+$(this).attr('id');
$('.apct-tab-contents').hide();
$('#'+board_id).show();
var board_class = $(this).attr('id');
if((board_class=="apct-about")||(board_class=="apct-shorcode")||(board_class=="apct-custom-settings")){$('.apct-setting-form').hide();}
else{$('.apct-setting-form').show();}
});
/** JS For Template preview **/
$(".testim-common").first().addClass( "temp-active" );
$('#testimonial-template').on('click', function() {
template_value = $(this).val();
var array_break = template_value.split('-');
var current_id = array_break[1];
$('#tesim-temp-demo-'+current_id).removeClass('temp-active');
$('.testim-common').hide();
$(this).addClass( 'temp-active' );
$('#tesim-temp-demo-'+current_id).show();
});
//Js For Media Uploader
$('#apct_upload_image_button').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function(e){
var uploaded_image = image.state().get('selection').first();
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
$('#apct_upload_image_url').val(image_url);
tb_remove();
});
});
//Show hide custom input field on radio button on setting option
$('input[name="testim_display_num"]').bind('change',function(){
var showOrHide = ($(this).val() == 'custom') ? true : false;
$('.custom-display-testim-num').toggle(showOrHide);
});
//Generate color field for rest of the fields
$('.apct-color-field').wpColorPicker();
//Generate preview for typography
$(".apct-font-select").change(function(){
var font_family = $( "#testimonial-google-font option:selected" ).val();
var replaced_font = font_family.replace(' ', '+');
if( font_family != 'default'){
$('#apct-font-family').append("");
$('#apct-font-family').css("font-family",font_family);
}else{
$('#apct-font-family').css("font-family",'inherit');
}
});
//color picker for background color
var myOptions = {
palettes: true,
change: function(event, ui){
$('.apct-font-demo-wrap').css('background-color',ui.color.toString());
//alert(ui.color.toString());
},
};
$('#testim_bg_color').wpColorPicker(myOptions);
//color picker for font color
var myOptions = {
palettes: true,
change: function(event, ui){
$('.apct-font-demo-wrap #apct-font-family').css('color',ui.color.toString());
//alert(ui.color.toString());
},
};
$('#testim_author_title_color').wpColorPicker(myOptions);
$("#testim_font_size").keyup(function() {
$('#apct-font-family').css({
'font-size': $(this).val() + 'px'
});
});
//display dynamic shorcode on jquery on generate shortcode button clicked
$(".apct-shortcode-button").click(function(){
testim_type = $( "#testimonial-type option:selected" ).val();
testim_template = $( "#testimonial-template option:selected" ).val();
testim_number = ($("input[name=testim_display_num]:checked").attr('id') == 'testim-all')?$("input[name=testim_display_num]:checked").val():$('#custom-display-testim-num').val();
enable_custom_layout= ($("input[name=testim_custom_design]").attr('checked'))?'disable':'enable';
show_title = ($("input[name=show_testim_title]").attr('checked'))?'show':'hide';
show_comp_detail = ($("input[name=show_testim_comp_name]").attr('checked'))?'show':'hide';
show_rating = ($("input[name=testim_rating_type]").attr('checked'))?'show':'hide';
testim_orderby = $("#testim_order_by_iand option:selected" ).val();
testim_ordertype = $("#testim_order_by_ascdsc option:selected" ).val();
show_date = ($("input[name=testim_publication_date]").attr('checked'))?'show':'hide';
show_image = ($("input[name=testim_featured_image]").attr('checked'))?'show':'hide';
show_email = ($("input[name=show_author_email]").attr('checked'))?'show':'hide';
$( "#apct-generated-shortcode" ).html( "[ap_custom_testimonial " + "type='" + testim_type + "' " + "template='" + testim_template + "' " + "display_num='" + testim_number +
"' " +"custom_layout='" + enable_custom_layout + "' " + "title='" + show_title + "' " +"comp_detail='" + show_comp_detail + "' " +"email='" + show_email + "' " +"rating='" + show_rating + "' " +"order_by='" + testim_orderby +
"' " +"order_type='" + testim_ordertype + "' " +"date='" + show_date + "' " +"image='" + show_image + "']" );
});
/** Backend Js for Popup to display full detail about Testimonial */
$('.testinomial-view-entry > a').click(function(e) {
var entry_id = $(this).data('entry-id');
$.ajax({
url: apct_backend_js_params.ajax_url,
data: {
entry_id: entry_id,
_wpnonce: apct_backend_js_params.ajax_nonce,
action: 'apct_testimonial_view_actions'
},
type: 'post',
beforeSend: function () {
$('#boxes').fadeIn(300, function () {
$('.apct-view-wrap').show();
$('.apct-overlay').show();
});
},
success: function (res) {
$('.apct-view-wrap').hide();
$('#boxes').html(res);
}
});
/** Entry Popup Close */
$(document).mouseup(function (e) {
var popup = $(".boxes");
if (!$('.boxes').is(e.target) && !popup.is(e.target) && popup.has(e.target).length == 0) {
popup.fadeOut(100);
$('.boxes').html('');
$('.apct-overlay').fadeOut(100);
}
});
$('body').on('click','.apct-popup-close', function () {
$('.boxes').fadeOut(100, function () {
$('.loading').html('');
$('.boxes').html('');
});
$('.boxes').fadeOut(100);
$('.apct-overlay').fadeOut(100);
});
});
/** restrict alphabetical input for input field */
$('.apct_restrict').keydown(function(event) {
// Allow special chars + arrows
if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9
|| event.keyCode == 27 || event.keyCode == 13
|| (event.keyCode == 65 && event.ctrlKey === true)
|| (event.keyCode >= 35 && event.keyCode <= 39)){
return;
}else {
// If it's not a number stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
/** Add Scroll to Top */
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.apct-scrollToTop').fadeIn();
} else {
$('.apct-scrollToTop').fadeOut();
}
});
$('.apct-scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},400);
return false;
});
});
}(jQuery));