-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjframes.js
59 lines (52 loc) · 1.41 KB
/
jframes.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
jQuery(function($){
var $doc = $(document);
function getLoader(){
return $('[jf-loading-template]').html();
}
$doc.on('click', '[jf-load]', function(e){
var $this = $(this)
var url = $(this).attr('jf-load');
var $container = $('[jf-container="'+$this.attr('jf-into')+'"]');
if ($container.length === 0) {
$container = $this.closest('[jf-container]');
}
$container.load(url);
$container.html(getLoader());
e.preventDefault();
});
$('[jf-container]').each(function(){
var url = $(this).attr('jf-init');
if (url) {
$(this).load(url);
$(this).html(getLoader());
}
});
$doc.on('click', '[jf-container] [jf-clear]', function(e){
e.preventDefault();
var $target = $(this).closest('[jf-container]');
$target.html('');
});
$doc.on('submit', 'form[jf-form]', function(e){
e.preventDefault();
var $form = $(this);
if ($form.is('[jf-replace]')) {
var $target = $form
} else{
var $target = $form.closest('[jf-container]');
}
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
success: function(response, status, xhr) {
if (response.redirect) {
window.location.replace(response.redirect);
}
else{
$target.html(response);
}
}
});
$target.html(getLoader());
});
});