| 1 |
(function($) { |
| 2 |
$(document).ready( function() { |
| 3 |
$( '#cntctfrm_additions_options' ).change( function() { |
| 4 |
if ( $( this ).is( ':checked' ) ) { |
| 5 |
$( '.cntctfrm_additions_block' ).removeClass( 'cntctfrm_hidden' ); |
| 6 |
$( '#cntctfrm_hide_additional_settings' ).css( 'display', 'block' ); |
| 7 |
} else { |
| 8 |
$( '.cntctfrm_additions_block' ).addClass( 'cntctfrm_hidden' ); |
| 9 |
$( '#cntctfrm_show_additional_settings' ).css( 'display', 'none' ); |
| 10 |
$( '#cntctfrm_hide_additional_settings' ).css( 'display', 'none' ); |
| 11 |
} |
| 12 |
}); |
| 13 |
if ( $( '#cntctfrm_additions_options' ).is( ':checked' ) ) { |
| 14 |
$( '#cntctfrm_show_additional_settings' ).css( 'display', 'block' ); |
| 15 |
$( '.cntctfrm_additions_block' ).addClass( 'cntctfrm_hidden' ); |
| 16 |
} |
| 17 |
$( '#cntctfrm_show_additional_settings' ).click( function() { |
| 18 |
$( this ).css( 'display', 'none' ); |
| 19 |
$( '#cntctfrm_hide_additional_settings' ).css( 'display', 'block' ); |
| 20 |
$( '.cntctfrm_additions_block' ).removeClass( 'cntctfrm_hidden' ); |
| 21 |
}); |
| 22 |
$( '#cntctfrm_hide_additional_settings' ).click( function() { |
| 23 |
$( this ).css( 'display', 'none' ); |
| 24 |
$( '#cntctfrm_show_additional_settings' ).css( 'display', 'block' ); |
| 25 |
$( '.cntctfrm_additions_block' ).addClass( 'cntctfrm_hidden' ); |
| 26 |
}); |
| 27 |
|
| 28 |
$( '#cntctfrm_change_label' ).change( function() { |
| 29 |
if ( $( this ).is( ':checked' ) ) { |
| 30 |
$( '.cntctfrm_change_label_block' ).removeClass( 'cntctfrm_hidden' ); |
| 31 |
} else { |
| 32 |
$( '.cntctfrm_change_label_block' ).addClass( 'cntctfrm_hidden' ); |
| 33 |
} |
| 34 |
}); |
| 35 |
$( '#cntctfrm_display_add_info' ).change( function() { |
| 36 |
if ( $( this ).is( ':checked' ) ) { |
| 37 |
$( '.cntctfrm_display_add_info_block' ).removeClass( 'cntctfrm_hidden' ); |
| 38 |
} else { |
| 39 |
$( '.cntctfrm_display_add_info_block' ).addClass( 'cntctfrm_hidden' ); |
| 40 |
} |
| 41 |
}); |
| 42 |
$( '#cntctfrm_add_language_button' ).click( function() { |
| 43 |
$.ajax({ |
| 44 |
url: '../wp-admin/admin-ajax.php',/* update_url, */ |
| 45 |
type: "POST", |
| 46 |
data: "action=cntctfrm_add_language&lang=" + $( '#cntctfrm_languages' ).val(), |
| 47 |
success: function( result ) { |
| 48 |
var lang_val = $( '#cntctfrm_languages' ).val(); |
| 49 |
$( '.cntctfrm_change_label_block .cntctfrm_language_tab, .cntctfrm_action_after_send_block .cntctfrm_language_tab' ).each( function() { |
| 50 |
$( this ).addClass( 'hidden' ); |
| 51 |
}); |
| 52 |
$( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).first().clone().appendTo( '.cntctfrm_change_label_block' ).removeClass( 'hidden' ).removeClass( 'cntctfrm_tab_en' ).addClass( 'cntctfrm_tab_' + lang_val ); |
| 53 |
$( '.cntctfrm_action_after_send_block .cntctfrm_language_tab' ).first().clone().insertBefore( '#cntctfrm_before' ).removeClass( 'hidden' ).removeClass( 'cntctfrm_tab_en' ).addClass( 'cntctfrm_tab_' + lang_val ); |
| 54 |
$( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).last().find( 'input' ).each( function() { |
| 55 |
$( this ).val( '' ); |
| 56 |
$( this ).attr( 'name', $( this ).attr( 'name' ).replace( '[en]', '[' + lang_val + ']' ) ); |
| 57 |
}); |
| 58 |
var text = $( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).last().find( '.cntctfrm_info' ).last().text(); |
| 59 |
text = text.replace( 'lang=en', 'lang=' + lang_val ); |
| 60 |
text = text.replace( ' or [contact_form]', '' ); |
| 61 |
$( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).last().find( '.cntctfrm_info' ).last().text( text ); |
| 62 |
$( '.cntctfrm_action_after_send_block .cntctfrm_language_tab' ).last().find( 'input' ).val( '' ).attr( 'name', $( '.cntctfrm_action_after_send_block .cntctfrm_language_tab' ).last().find( 'input' ).attr( 'name' ).replace( '[en]', '[' + lang_val + ']' ) ); |
| 63 |
text = $( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).last().find( '.cntctfrm_info' ).last().text(); |
| 64 |
text = text.replace( 'lang=en', 'lang=' + lang_val ); |
| 65 |
text = text.replace( ' or [contact_form]', '' ); |
| 66 |
$( '.cntctfrm_action_after_send_block .cntctfrm_language_tab' ).last().find( '.cntctfrm_info' ).last().text( text ); |
| 67 |
$( '.cntctfrm_change_label_block .cntctfrm_label_language_tab, .cntctfrm_action_after_send_block .cntctfrm_label_language_tab' ).each( function() { |
| 68 |
$( this ).removeClass( 'cntctfrm_active' ); |
| 69 |
}); |
| 70 |
$( '.cntctfrm_change_label_block .clear' ).prev().clone().attr( 'id', 'cntctfrm_label_' + lang_val ).addClass( 'cntctfrm_active' ).html( $( '#cntctfrm_languages option:selected' ).text() + ' <span class="cntctfrm_delete" rel="' + lang_val + '">X</span>').insertBefore( '.cntctfrm_change_label_block .clear' ); |
| 71 |
$( '.cntctfrm_action_after_send_block .clear' ).prev().clone().attr( 'id', 'cntctfrm_label_' + lang_val ).addClass( 'cntctfrm_active' ).html( $( '#cntctfrm_languages option:selected' ).text() + ' <span class="cntctfrm_delete" rel="' + lang_val + '">X</span>').insertBefore( '.cntctfrm_action_after_send_block .clear' ); |
| 72 |
$( '#cntctfrm_languages option:selected' ).remove(); |
| 73 |
}, |
| 74 |
error: function( request, status, error ) { |
| 75 |
alert( error + request.status ); |
| 76 |
} |
| 77 |
}); |
| 78 |
}); |
| 79 |
$( '.cntctfrm_language_tab_block' ).css( 'display', 'none' ); |
| 80 |
$( '.cntctfrm_language_tab_block_mini' ).css( 'display', 'block' ); |
| 81 |
$( '.cntctfrm_help_box' ).mouseover( function() { |
| 82 |
$( this ).children().css( 'display', 'block' ); |
| 83 |
}); |
| 84 |
$( '.cntctfrm_help_box' ).mouseout( function() { |
| 85 |
$( this ).children().css( 'display', 'none' ); |
| 86 |
}); |
| 87 |
|
| 88 |
/* add notice about changing in the settings page */ |
| 89 |
$( '#cntctfrm_settings_form input' ).bind( "change click select", function() { |
| 90 |
if ( $( this ).attr( 'id' ) != 'cntctfrm_hide_additional_settings' && $( this ).attr( 'id' ) != 'cntctfrm_show_additional_settings' && $( this ).attr( 'type' ) != 'submit' ) { |
| 91 |
$( '.updated.fade' ).css( 'display', 'none' ); |
| 92 |
$( '#cntctfrm_settings_notice' ).css( 'display', 'block' ); |
| 93 |
}; |
| 94 |
}); |
| 95 |
$( 'select[name="cntctfrm_user_email"]').focus( function() { |
| 96 |
$('#cntctfrm_select_email_user').attr( 'checked', 'checked' ); |
| 97 |
$( '.updated.fade' ).css( 'display', 'none' ); |
| 98 |
$( '#cntctfrm_settings_notice' ).css( 'display', 'block' ); |
| 99 |
}); |
| 100 |
}); |
| 101 |
$(document).on( "click", ".cntctfrm_language_tab_block_mini", function() { |
| 102 |
if ( $( '.cntctfrm_language_tab_block' ).css( 'display' ) == 'none' ) { |
| 103 |
$( '.cntctfrm_language_tab_block' ).css( 'display', 'block' ); |
| 104 |
$( '.cntctfrm_language_tab_block_mini' ).css( 'background-position', '1px -3px' ); |
| 105 |
} else { |
| 106 |
$( '.cntctfrm_language_tab_block' ).css( 'display', 'none' ); |
| 107 |
$( '.cntctfrm_language_tab_block_mini' ).css( 'background-position', '' ); |
| 108 |
} |
| 109 |
}); |
| 110 |
$(document).on( "click", ".cntctfrm_change_label_block .cntctfrm_label_language_tab", function() { |
| 111 |
$( '.cntctfrm_label_language_tab' ).each( function() { |
| 112 |
$( this ).removeClass( 'cntctfrm_active' ); |
| 113 |
}); |
| 114 |
var index = $( '.cntctfrm_change_label_block .cntctfrm_label_language_tab' ).index( $( this ) ); |
| 115 |
$( this ).addClass( 'cntctfrm_active' ); |
| 116 |
var blocks = $( '.cntctfrm_action_after_send_block .cntctfrm_label_language_tab' ); |
| 117 |
$( blocks[ index ] ).addClass( 'cntctfrm_active' ); |
| 118 |
$( '.cntctfrm_language_tab' ).each( function() { |
| 119 |
$( this ).addClass( 'hidden' ); |
| 120 |
}); |
| 121 |
$( '.' + this.id.replace( 'label', 'tab' ) ).removeClass( 'hidden' ); |
| 122 |
}); |
| 123 |
$(document).on( "click", ".cntctfrm_action_after_send_block .cntctfrm_label_language_tab", function() { |
| 124 |
$( '.cntctfrm_label_language_tab' ).each( function() { |
| 125 |
$( this ).removeClass( 'cntctfrm_active' ); |
| 126 |
}); |
| 127 |
var index = $( '.cntctfrm_action_after_send_block .cntctfrm_label_language_tab' ).index( $( this ) ); |
| 128 |
$( this ).addClass( 'cntctfrm_active' ); |
| 129 |
var blocks = $( '.cntctfrm_change_label_block .cntctfrm_label_language_tab' ); |
| 130 |
$( blocks[ index ] ).addClass( 'cntctfrm_active' ); |
| 131 |
$( '.cntctfrm_language_tab' ).each( function() { |
| 132 |
$( this ).addClass( 'hidden' ); |
| 133 |
}); |
| 134 |
console.log( this.id.replace( 'text', 'tab' ), index ); |
| 135 |
$( '.' + this.id.replace( 'text', 'tab' ) ).removeClass( 'hidden' ); |
| 136 |
}); |
| 137 |
$(document).on( "click", ".cntctfrm_delete", function( event ) { |
| 138 |
event.stopPropagation(); |
| 139 |
if ( confirm( confirm_text ) ) { |
| 140 |
var lang = $( this ).attr( 'rel' ); |
| 141 |
$.ajax({ |
| 142 |
url: '../wp-admin/admin-ajax.php',/* update_url, */ |
| 143 |
type: "POST", |
| 144 |
data: "action=cntctfrm_remove_language&lang="+lang, |
| 145 |
success: function( result ) { |
| 146 |
$( '#cntctfrm_label_' + lang + ', #cntctfrm_text_' + lang + ', .cntctfrm_tab_' + lang ).each( function() { |
| 147 |
$( this ).remove(); |
| 148 |
}); |
| 149 |
$( '.cntctfrm_change_label_block .cntctfrm_label_language_tab' ).removeClass( 'cntctfrm_active' ).first().addClass( 'cntctfrm_active' ); |
| 150 |
$( '.cntctfrm_action_after_send_block .cntctfrm_label_language_tab' ).removeClass( 'cntctfrm_active' ).first().addClass( 'cntctfrm_active' ); |
| 151 |
$( '.cntctfrm_change_label_block .cntctfrm_language_tab' ).addClass( 'hidden' ).first().removeClass( 'hidden' ); |
| 152 |
$( '.cntctfrm_action_after_send_block .cntctfrm_language_tab' ).addClass( 'hidden' ).first().removeClass( 'hidden' ); |
| 153 |
}, |
| 154 |
error: function( request, status, error ) { |
| 155 |
alert( error + request.status ); |
| 156 |
} |
| 157 |
}); |
| 158 |
} |
| 159 |
}); |
| 160 |
})(jQuery); |