修复模板重复加载的问题

需要在 avalon.ready()之后再进行其他动作,需要先初始化模板路径。
This commit is contained in:
virusdefender 2015-08-08 09:43:32 +08:00
parent 6e8baca8c9
commit fff7fae323

View File

@ -1,42 +1,47 @@
define("admin", ["jquery", "avalon"], function($, avalon){ define("admin", ["jquery", "avalon"], function ($, avalon) {
function li_active(selector){
avalon.ready(function () {
function li_active(selector) {
$(selector).attr("class", "list-group-item active"); $(selector).attr("class", "list-group-item active");
} }
function li_inactive(selector){ function li_inactive(selector) {
$(".list-group-item").attr("class", "list-group-item"); $(".list-group-item").attr("class", "list-group-item");
} }
function show_template(url){ function show_template(url) {
$("#loading-gif").show(); $("#loading-gif").show();
vm.template_url = url; vm.template_url = url;
} }
var hash = window.location.hash.substring(1);
if (!hash) {
hash = "index/index";
}
var vm = avalon.define({ var vm = avalon.define({
$id: "admin", $id: "admin",
template_url: "template/index/index.html", template_url: "template/" + hash + ".html",
hide_loading: function(){ hide_loading: function () {
$("#loading-gif").hide(); $("#loading-gif").hide();
} }
}); });
var hash = window.location.hash.substring(1); avalon.scan();
if(hash){
li_active("#li-" + hash.replace("/", "-")); li_active("#li-" + hash.replace("/", "-"));
show_template("template/" + hash + ".html");
}else {
li_active("#li-index-index");
}
window.onhashchange = function() { window.onhashchange = function () {
var hash = window.location.hash.substring(1); var hash = window.location.hash.substring(1);
if(hash){ if (hash) {
li_inactive(".list-group-item"); li_inactive(".list-group-item");
li_active("#li-" + hash.replace("/", "-")); li_active("#li-" + hash.replace("/", "-"));
show_template("template/" + hash + ".html"); show_template("template/" + hash + ".html");
} }
}; };
});
}); });