/public/js/js.js
JavaScript | 144 lines | 109 code | 28 blank | 7 comment | 28 complexity | f8927263768a03866aa7958748230066 MD5 | raw file
1/**
2 * @author Tom
3 */
4
5$(document).ready(function () {
6
7$('.istooltip').tooltip()
8$(".alert").alert()
9$('.nav-tabs').button()
10
11$(document).ajaxStart(function(){
12 $('#loading').css({'top':( $(window).height() / 2 ) - 25 + 'px', 'z-index' : '99999'});
13 $('#loading').show();
14});
15
16$(document).ajaxStop(function(){
17 $('#loading').hide();
18});
19
20$('body').on('submit', "form.ajax", function(e){
21
22 var myCallback;
23 var data_method = 'POST'
24
25 if($(this).attr('data-callback') != undefined) {myCallback = $(this).attr('data-callback');}
26 if($(this).attr('data-method') != undefined) { data_method = $(this).attr('data-method'); }
27
28 $.ajax({
29 type: data_method,
30 cache: false,
31 url: $(this).attr('action'),
32 data: $(this).serialize(),
33 dataType: 'json',
34 success: function(data) {
35
36 successAjax(data.where, data.action, data.output, myCallback);
37 }
38 ,complete: function() {
39 //complete(false);
40 }
41
42 });
43
44 return false;
45
46 });
47
48 $('body').on('click', "a.ajax", function(e){
49 var myCallback = null;
50 var data_method = 'get';
51 e.preventDefault();
52 //$('#systemove-hlaseni').fadeOut();
53
54 if($(this).attr('data-callback') != undefined) { myCallback = $(this).attr('data-callback'); }
55 if($(this).attr('data-method') != undefined) { data_method = $(this).attr('data-method'); }
56
57 $.ajax({
58 type: data_method,
59 cache: false,
60 url: $(this).attr('href'),
61 dataType: 'json',
62 success: function(data) {
63 successAjax(data.where, data.action, data.output, myCallback);
64 }
65 , complete : function(){
66 //complete(false);
67 }
68
69
70
71 });
72
73 return false;
74
75 });
76
77 // --- hide or show some element
78 $('.hideable-menu').on('click', function(){
79
80 var id_hide = $(this).attr('data-hide');
81
82 if($(id_hide).css('display') == 'none')
83 {
84 $(id_hide).fadeIn();
85 if( $(this).children(".left").length == 1){ $(this).children(".right").hide(); $(this).children(".left").css('display' , 'inline-block'); }
86 }
87 else
88 {
89 $(id_hide).fadeOut();
90 if( $(this).children(".left").length == 1){ $(this).children(".left").hide(); $(this).children(".right").css('display' , 'inline-block'); }
91 }
92 })
93
94});
95
96function successAjax(where, action, output, myCallback)
97{
98 var counter = 0;
99 $.each(action, function() { // for each action
100 if(this == "redirect")
101 {
102 window.location.href = where[counter]
103 }
104 if(this == "output")
105 {
106 $(where[counter]).hide();
107 $(where[counter]).html(output[counter]).fadeTo('slow', 1);
108 }
109 else if(this == "append")
110 {
111 $(where[counter]).append(output[counter]).fadeTo('slow', 1);
112 }else if(this == "remove")
113 {
114 $(where[counter]).fadeOut('slow', function() { $(where[counter]).remove(); });
115 }else if(this == "ok")
116 {
117 $('#flash ' + where[counter]).html(output[counter]);
118 $('#flash').css({'left' : parseInt($(window).width() / 2) - parseInt($('#flash').width() / 2), 'top' : '25px'});
119 $('#flash').fadeIn();
120 $('#ok').show();
121 $('body').on('click', this, function() {
122 $('#flash').fadeOut(function(){
123 $('#ok').hide();
124 });
125
126 });
127 }
128 else if(this == 'warning')
129 {
130 $('#flash ' + where[counter]).html(output[counter]);
131 $('#flash').css({'left' : parseInt($(window).width() / 2) - parseInt($('#flash').width() / 2), 'top' : '25px'});
132
133 $('#flash').fadeIn();
134 $('#warning').show();
135 $('body').on('click', function() {
136 $('#flash').fadeOut(function(){
137 $('#warning').hide();
138 });
139
140 });
141 }
142 counter = counter + 1;
143 }); // for each action
144}