cf7d.js
5.9 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
jQuery(document).ready(function($) {
jQuery('#cf7d-list-field').sortable({
placeholder: "sortable-placeholder"
});
jQuery('#cf7d-list-field li span.dashicons').click(function(event) {
var $this = jQuery(this);
var $parent = $this.parent();
var $custom_label = $parent.find('.txt_show');
//currently visible
if ($this.hasClass('dashicons-visibility')) {
$this.removeClass('dashicons-visibility').addClass('dashicons-hidden');
$parent.removeClass('show').addClass('hide');
$custom_label.val('0');
} else if ($this.hasClass('dashicons-hidden')) {
$this.removeClass('dashicons-hidden').addClass('dashicons-visibility');
$parent.removeClass('hide').addClass('show');
$custom_label.val('1');
}
});
/*jQuery('#doaction').click(function(event) {
alert('This function is not available for demo');
return false;
});
jQuery('#doaction2').click(function(event) {
alert('This function is not available for demo');
return false;
});*/
/*
* Edit value
*/
jQuery('a.cf7d-edit-value').click(function(event) {
var rid = jQuery(this).data('rid');
jQuery('form#cf7d-modal-form-edit-value div[name="rid"]').text( rid);
jQuery('form#cf7d-modal-form-edit-value div[class^="field-"]').text('Loading...');
jQuery.ajax({
url: ajaxurl + '?action=cf7d_edit_value',
type: 'POST',
data: {'rid': rid},
})
.done(function(data) {
var json = jQuery.parseJSON(data);
jQuery.each(json, function(index, el) {
if(index=="map"){
var myLatLng = new google.maps.LatLng(23.14746, 113.34175376);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("allmap"), myOptions);
var cur_Lat = 39.92755606634672;
var cur_Lng = 116.37930297851597;
if(el!=''){
var c = el.split(",");
cur_Lat = c[0];
cur_Lng = c[1];
}
var newLatLng = new google.maps.LatLng(cur_Lat,cur_Lng);
marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: newLatLng
});
map.setCenter(newLatLng,12);
}else{
jQuery('form#cf7d-modal-form-edit-value .field-' + index).html(el);
}
});
jQuery('#cf7d-modal-form-edit-value').removeClass('loading');
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
/*
* Change theme
*/
var cf7d_cookie_theme = readCookie('cf7d-admin-list');
if (cf7d_cookie_theme == null) {
createCookie('cf7d-admin-list', 'vertical', 30);
}
cf7d_cookie_theme = readCookie('cf7d-admin-list');
if (cf7d_cookie_theme == 'horizontal') {
jQuery('.cf7d-switch-theme-vertical').removeClass('active');
jQuery('.cf7d-switch-theme-horizontal').addClass('active');
} else {
jQuery('.cf7d-switch-theme-vertical').addClass('active');
jQuery('.cf7d-switch-theme-horizontal').removeClass('active');
}
jQuery('.cf7d-admin-table').addClass(cf7d_cookie_theme);
jQuery('.cf7d-switch-theme').click(function(event) {
var $this = jQuery(this);
jQuery('.cf7d-switch-theme').removeClass('active');
$this.addClass('active');
if ($this.hasClass('cf7d-switch-theme-horizontal')) {
jQuery('.cf7d-admin-table').addClass('horizontal');
createCookie('cf7d-admin-list', 'horizontal', 30);
} else {
jQuery('.cf7d-admin-table').removeClass('horizontal');
createCookie('cf7d-admin-list', 'vertical', 30);
}
});
/*
* Search
*/
jQuery('#cf7d-search-btn').click(function(event) {
var $this = jQuery(this);
var form = jQuery('#cf7d-admin-action-frm');
var q = jQuery('#cf7d-search-q').val();
if (q != "") {
var fid = jQuery('input[name="fid"]', form).val();
var url = $this.data('url');
location.replace(url + '&fid=' + fid + '&search=' + q)
} else {
return false;
}
});
/**
* Export
*/
/*jQuery('#cf7d-export').on('change', function() {
var $val = $(this).find(":selected").val();
if ($val != -1) {
var $fid = jQuery(this).data('fid');
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: {'action': 'cf7d_export_entry', 'type': 'csv', 'fid': $fid}
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
});
}
});*/
});
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
$(document).ready(function(){
$("#cf7d-list-field-for-edit li.submit_user_id-display,#cf7d-list-field-for-edit li._wpcf7_captcha_challenge_CAPCHA-display,#cf7d-list-field-for-edit li._wpnonce-display,#cf7d-list-field-for-edit li.capcha-display").css('height','0').css('overflow','hidden')
})