forked from brainstormforce/wp-freshdesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfd-script.js
85 lines (81 loc) · 3.13 KB
/
fd-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// JavaScript Document
jQuery(document).ready(function(){
if( window.location.href.indexOf("page=wp-freshdesk") != -1 ) {
var hashTxt = window.location.hash.substr(1);
if( hashTxt == '' ) {
hashTxt = 'api-tab';
window.location.hash = hashTxt;
}
var arr = hashTxt.split('-');
jQuery( '.nav-tab' ).removeClass( "nav-tab-active" );
jQuery( '#' + arr[1] + '-' + arr[0] ).addClass( "nav-tab-active" );
jQuery( '.fd-tabs' ).hide();
jQuery( '#' + hashTxt ).show();
jQuery('#' + hashTxt + ' form').attr('action', 'options.php#' + hashTxt);
jQuery( 'html, body' ).scrollTop(0);
}
if( jQuery("#use_apikey").val() == 'on' ) {
jQuery( "#api_username" ).parent().parent().hide();
jQuery( "#api_pwd" ).parent().parent().hide();
jQuery( "#freshdesk_apikey" ).parent().parent().show();
} else {
jQuery( "#freshdesk_apikey" ).parent().parent().hide();
jQuery( "#api_username" ).parent().parent().show();
jQuery( "#api_pwd" ).parent().parent().show();
}
jQuery('#api-tab').submit(function(){
if(/^[A-Za-z\d\s]+$/.test(jQuery("#freshdesk_url").val())){
return true;
} else {
alert("Invalid URL");
return false;
}
});
jQuery('#use_apikey').change(function(){
if( jQuery("#use_apikey").val() == 'on' ) {
jQuery( "#freshdesk_apikey" ).removeAttr("readonly");
jQuery( "#api_username" ).attr( "readonly", "readonly" );
jQuery( "#api_pwd" ).attr( "readonly", "readonly" );
jQuery( "#api_username" ).parent().parent().hide();
jQuery( "#api_pwd" ).parent().parent().hide();
jQuery( "#freshdesk_apikey" ).parent().parent().show();
} else {
jQuery( "#api_username" ).removeAttr("readonly");
jQuery( "#api_pwd" ).removeAttr("readonly");
jQuery( "#freshdesk_apikey" ).attr( "readonly", "readonly" );
jQuery( "#freshdesk_apikey" ).parent().parent().hide();
jQuery( "#api_username" ).parent().parent().show();
jQuery( "#api_pwd" ).parent().parent().show();
}
});
jQuery('#freshdesk_enable').change(function(){
if( jQuery("#freshdesk_enable").is(':checked') ) {
jQuery( "#freshdesk_sharedkey" ).removeAttr("readonly");
} else {
jQuery( "#freshdesk_sharedkey" ).attr( "readonly", "readonly" );
}
});
jQuery('.nav-tab').click(function(){
var id = jQuery(this).attr('id');
var arr = id.split('-');
jQuery( '.nav-tab' ).removeClass( "nav-tab-active" );
jQuery( this ).addClass( "nav-tab-active" );
jQuery( '.fd-tabs' ).hide();
jQuery( '#' + arr[1] + '-' + arr[0] ).show();
window.location.hash = arr[1] + '-' + arr[0];
jQuery('#' + arr[1] + '-' + arr[0] + ' form').attr('action', 'options.php#' + arr[1] + '-' + arr[0]);
jQuery( 'html, body' ).scrollTop(0);
});
jQuery('.fd-toggle').click(function(){
var id = jQuery(this).attr('id');
if( jQuery("#"+id).is(':checked') ) {
jQuery( "#"+id+'-p' ).removeClass( "fd-use-apikey-no" );
jQuery( "#"+id+'-p' ).addClass( "fd-use-apikey-yes" );
jQuery( "#"+id+'-p' ).html( "Yes" );
} else {
jQuery( "#"+id+'-p' ).removeClass( "fd-use-apikey-yes" );
jQuery( "#"+id+'-p' ).addClass( "fd-use-apikey-no" );
jQuery( "#"+id+'-p' ).html( "No" );
}
});
});