/public/js/js.js
https://bitbucket.org/thrabal/smartlib · JavaScript · 144 lines · 109 code · 28 blank · 7 comment · 28 complexity · f8927263768a03866aa7958748230066 MD5 · raw file
- /**
- * @author Tom
- */
- $(document).ready(function () {
- $('.istooltip').tooltip()
- $(".alert").alert()
- $('.nav-tabs').button()
- $(document).ajaxStart(function(){
- $('#loading').css({'top':( $(window).height() / 2 ) - 25 + 'px', 'z-index' : '99999'});
- $('#loading').show();
- });
- $(document).ajaxStop(function(){
- $('#loading').hide();
- });
- $('body').on('submit', "form.ajax", function(e){
- var myCallback;
- var data_method = 'POST'
- if($(this).attr('data-callback') != undefined) {myCallback = $(this).attr('data-callback');}
- if($(this).attr('data-method') != undefined) { data_method = $(this).attr('data-method'); }
- $.ajax({
- type: data_method,
- cache: false,
- url: $(this).attr('action'),
- data: $(this).serialize(),
- dataType: 'json',
- success: function(data) {
- successAjax(data.where, data.action, data.output, myCallback);
- }
- ,complete: function() {
- //complete(false);
- }
- });
- return false;
- });
- $('body').on('click', "a.ajax", function(e){
- var myCallback = null;
- var data_method = 'get';
- e.preventDefault();
- //$('#systemove-hlaseni').fadeOut();
- if($(this).attr('data-callback') != undefined) { myCallback = $(this).attr('data-callback'); }
- if($(this).attr('data-method') != undefined) { data_method = $(this).attr('data-method'); }
- $.ajax({
- type: data_method,
- cache: false,
- url: $(this).attr('href'),
- dataType: 'json',
- success: function(data) {
- successAjax(data.where, data.action, data.output, myCallback);
- }
- , complete : function(){
- //complete(false);
- }
- });
- return false;
- });
- // --- hide or show some element
- $('.hideable-menu').on('click', function(){
- var id_hide = $(this).attr('data-hide');
- if($(id_hide).css('display') == 'none')
- {
- $(id_hide).fadeIn();
- if( $(this).children(".left").length == 1){ $(this).children(".right").hide(); $(this).children(".left").css('display' , 'inline-block'); }
- }
- else
- {
- $(id_hide).fadeOut();
- if( $(this).children(".left").length == 1){ $(this).children(".left").hide(); $(this).children(".right").css('display' , 'inline-block'); }
- }
- })
- });
- function successAjax(where, action, output, myCallback)
- {
- var counter = 0;
- $.each(action, function() { // for each action
- if(this == "redirect")
- {
- window.location.href = where[counter]
- }
- if(this == "output")
- {
- $(where[counter]).hide();
- $(where[counter]).html(output[counter]).fadeTo('slow', 1);
- }
- else if(this == "append")
- {
- $(where[counter]).append(output[counter]).fadeTo('slow', 1);
- }else if(this == "remove")
- {
- $(where[counter]).fadeOut('slow', function() { $(where[counter]).remove(); });
- }else if(this == "ok")
- {
- $('#flash ' + where[counter]).html(output[counter]);
- $('#flash').css({'left' : parseInt($(window).width() / 2) - parseInt($('#flash').width() / 2), 'top' : '25px'});
- $('#flash').fadeIn();
- $('#ok').show();
- $('body').on('click', this, function() {
- $('#flash').fadeOut(function(){
- $('#ok').hide();
- });
- });
- }
- else if(this == 'warning')
- {
- $('#flash ' + where[counter]).html(output[counter]);
- $('#flash').css({'left' : parseInt($(window).width() / 2) - parseInt($('#flash').width() / 2), 'top' : '25px'});
- $('#flash').fadeIn();
- $('#warning').show();
- $('body').on('click', function() {
- $('#flash').fadeOut(function(){
- $('#warning').hide();
- });
- });
- }
- counter = counter + 1;
- }); // for each action
- }