var Core function var Form function var Link function Base class Core

 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
var Core = function(){}
var Form = function(){}
var Link = function(){}
/* Base class */
Core.prototype.open_loader = function(){
$('body').append('<div id="load"><img src="'+imgLoader.src+'" /></div>');
$('#load').show();
}
Core.prototype.close_loader = function(){
$('#load').remove();
}
Core.prototype.response_parser = function( response ){
action = response.action;
var insert_errors = function(){
$("input").removeClass('error');
jQuery.each(action.args.errors, function(){
if ( this == '__all__' ) {
$("input").addClass('error');
} else {
$("[name="+this+"]").addClass('error');
}
})
}
var redirect = function(){
window.location = action.args.location;
}
var event = function(){
$.ItqEvent(action.args.text, {'theme': action.args.theme});
}
var new_rating = function(){
var rating = (!action.args.rating)? "0" : action.args.rating;
$('#rating-' + action.args.id).html(rating);
$.ItqEvent(action.args.text, {'theme': action.args.theme})
}
var add_answer = function(){
if(action.args.success == true) {
$('#answers').append(action.args.html);
} else {
$.ItqEvent(action.args.text, {'theme': action.args.theme});
}
}
var bookmark_del = function(){
$('#bookmark-' + action.args.id).remove();
$.ItqEvent(action.args.text, {'theme': 'success'})
}
var profile_save = function(){
$.ItqEvent(action.args.text, {'theme': action.args.theme});
}
eval(action.func + '()');
}
/* Ajax links working class */
Link.prototype = new Core();
Link.prototype.ajax_link = function(o, d){
$.ajax({
type: 'post',
data: d,
url: o.href,
success: this.response_parser,
dataType: 'json'
});
}
/* Form working class */
Form.prototype = new Core();
Form.prototype.ajax_form = function( selector ){
$(selector).ajaxForm({
data: {'selector': selector },
success: this.response_parser,
dataType: 'json'
});
}