callback.js
2.12 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
function ajaxFormCheck ($el, $callback)
{
if (jQuery.type( $el ) === 'string')
{
$el = $($el);
}
if ($el.validationEngine('validate'))
{
if ($callback)
{
$callback.call();
}
return true;
}
return false;
}
function callbackAction ($array)
{
return $.ajax({
type: 'POST',
url: '/ajax/callback.php',
dataType: 'json',
data: $.param ($array['json']),
error: function()
{
alert ('Error');
}
});
}
function loadModal($html, $class)
{
delModal();
var winW = document.body.offsetWidth,
$body =
'<div class="modal-box-overlay"></div>'
+ '<div class="modal-box ' + $class + '">'
+ '<div class="wrp">'
+ '<div class="modal-box-close"></div>'
+ '<div class="inside">'
+ '</div>';
+ '</div>';
$('body').append($body);
$('.modal-box .inside').html($html);
$('.modal-box').css('left', ((winW - $('.modal-box').width()) / 2) + 'px');
}
function delModal()
{
$('.modal-box').remove();
$('.modal-box-overlay').remove();
}
$(document).ready(function()
{
$("#callback-button").click(function ()
{
callbackAction ({
'json': {
'jaction': 'getForm'
}
}).done(function ($result)
{
loadModal($result.html, 'callback');
})
});
if (typeof jQuery.fn.live == 'function' && jQuery.isFunction(jQuery.fn.live))
{
$(".modal-box-close").live('click', function()
{
delModal();
});
$("#callback-form .submit").live('click', function(e)
{
e.preventDefault();
ajaxFormCheck('#callback-form', function()
{
callbackAction ({
'json': $.extend(
{
'jaction': 'save',
},
transForm.serialize('#callback-form')
)
}).done(function ($result)
{
loadModal($result.html, 'callback');
});
})
});
}
});