cf7-2-post-save-draft.js
2.3 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
(function( $ ) {
'use strict';
$(document).ready(function(){
var $save = $('form.wpcf7-form input[type=submit].cf7_2_post_save'), style;
if(cf72post_save.paint){
var sbmt = $('form.wpcf7-form input[type=submit]').get(0);
if(sbmt){
sbmt = window.getComputedStyle(sbmt);
style = document.createElement('style');
style.setAttribute('id','c2p-save-button');
style.type = "text/css";
style.innerText = 'input[type=submit].cf7_2_post_save:not(:hover){background:'+sbmt['color']+';color:'+sbmt['background-color']+';border-color:'+sbmt['background-color']+'}';
document.head.appendChild(style);
}
}
$save.each(function(){
var $form = $(this).closest("form.wpcf7-form");
//localized cf72post_save.disabled = true if form is not mapped.
$('input[type=submit].wpcf7-submit', $form).on('click', function(event){
var $this = $(this);
var isSave = 'false';
if($this.is('.cf7_2_post_save')){
if(cf72post_save.disabled) {
$this.parent().append('<span class="wpcf7-warning">'+cf72post_save.error+'</span>')
event.stopPropagation();
return false;
}
isSave = 'true';
$(':input',$form).each(function(){
var $this = $(this);
switch(true){
case $this.is(':checked'):
$this.prop("defaultChecked", true);
break;
case $this.is('select'):
var values = $this.val();
if(!$.isArray(values)) values = [values];
$('option', $this).each(function(){
var $option = $(this);
$option[0].defaultSelected= false;
if(values.indexOf($option.val()) >= 0){
$option[0].defaultSelected=true;
}
});
break;
default:
$this.prop("defaultValue", $this.val());
break;
}
});
}
$('input[type=hidden].cf7_2_post_draft', $form).val(isSave);
});
//verify if a message box is available
if( !$('div.wpcf7-response-output', $form).length){
$form.append('<div class="wpcf7-response-output wpcf7-display-none"></div>')
}
});
});
})( jQuery );