100 lines
4.1 KiB
JavaScript
100 lines
4.1 KiB
JavaScript
|
/*
|
||
|
* To change this template, choose Tools | Templates
|
||
|
* and open the template in the editor.
|
||
|
*/
|
||
|
!function($) {
|
||
|
$(function() {
|
||
|
$body = $("body");
|
||
|
$(document).on({
|
||
|
ajaxStart: function() { $body.addClass("loading"); },
|
||
|
ajaxStop: function() { $body.removeClass("loading"); }
|
||
|
});
|
||
|
function event(where){
|
||
|
$("#alert .alert").alert();
|
||
|
$(where+'.dropdown-toggle').dropdown();
|
||
|
|
||
|
$(where+" a").each(function(that){
|
||
|
if($(this).attr("rel")!=="external")
|
||
|
$(this).click(function(e){
|
||
|
load($(this).attr('href'),{},($(this).attr('rel')=="tab"));
|
||
|
return false;
|
||
|
});
|
||
|
});
|
||
|
|
||
|
$(where+" form").submit(function(e){
|
||
|
e.stopPropagation();
|
||
|
//e.preventDefault();
|
||
|
if($(this).attr("back"))
|
||
|
back=window.location.href;
|
||
|
else
|
||
|
back=null;
|
||
|
load($(this).attr("action"),{data:$(this).serialize(), type:$(this).attr("method"),back:back},($(this).attr('rel')=="tab"));
|
||
|
return false;
|
||
|
});
|
||
|
$(where+" form label.has-error").parent(".form-group").addClass("has-error")
|
||
|
}
|
||
|
function load(pageurl,conf,tab){
|
||
|
data = {};
|
||
|
typemethode = "GET";
|
||
|
back = false;
|
||
|
if(conf['data'])
|
||
|
data = conf['data'];
|
||
|
if(conf['type'])
|
||
|
typemethode = conf['type'];
|
||
|
if(conf['back'] && conf['back'].indexOf("logout")== -1 && conf['back'].indexOf("login")== -1 )
|
||
|
back = conf['back'];
|
||
|
//e.preventDefault();
|
||
|
/*
|
||
|
if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
|
||
|
if commented, html5 nonsupported browers will reload the page to the specified link.
|
||
|
*/
|
||
|
$.ajax({url:pageurl,data:data,type:typemethode,success: function(data){
|
||
|
alert = data.split('<!-- alert -->')[1].split('<!-- /alert -->')[0]+$('#alert').html();
|
||
|
$('#alert').html(alert);
|
||
|
|
||
|
if(back){
|
||
|
load(back,{},tab);
|
||
|
}else if(tab){
|
||
|
navbar = data.split('<!-- tab -->')[1].split('<!-- /tab -->')[0];
|
||
|
$('#tab').html(navbar);
|
||
|
event("#tab");
|
||
|
}else{
|
||
|
navbar = data.split('<!-- navbar -->')[1].split('<!-- /navbar -->')[0];
|
||
|
$('#navbar').html(navbar);
|
||
|
event("#navbar");
|
||
|
|
||
|
container = data.split('<!-- container -->')[1].split('<!-- /container -->')[0];
|
||
|
$('#container').html(container);
|
||
|
event("#container");
|
||
|
|
||
|
barright = data.split('<!-- barright -->')[1].split('<!-- /barright -->')[0];
|
||
|
$('#barright').html(barright);
|
||
|
event("#barright");
|
||
|
|
||
|
barleft = data.split('<!-- barleft -->')[1].split('<!-- /barleft -->')[0];
|
||
|
$('#barleft').html(barleft);
|
||
|
event("#barleft");
|
||
|
}
|
||
|
},error:function(data){
|
||
|
alert = data.responseText.split('<title>')[1].split('</title>')[0]
|
||
|
alert = "<div class=\"alert alert-danger\">"+
|
||
|
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>"+
|
||
|
alert
|
||
|
+ "</div>"
|
||
|
+$('#alert').html();
|
||
|
$('#alert').html(alert);
|
||
|
|
||
|
container = data.responseText.split('<!-- container -->')[1].split('<!-- /container -->')[0];
|
||
|
$('#container').html(container);
|
||
|
event("#container");
|
||
|
}});
|
||
|
if(pageurl!=window.location){
|
||
|
window.history.pushState({path:pageurl},'',pageurl);
|
||
|
}
|
||
|
};
|
||
|
event("");
|
||
|
});
|
||
|
}(window.jQuery);
|
||
|
|
||
|
|