add site
This commit is contained in:
72
Site/Inspection/js/modules/pageloader.js
Normal file
72
Site/Inspection/js/modules/pageloader.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
module -
|
||||
description: 模块描述
|
||||
version: 模块版本
|
||||
createContent: 产生模块正文
|
||||
*/
|
||||
|
||||
define(function () {
|
||||
var _loader = {
|
||||
links: '',
|
||||
content: '',
|
||||
init: function () {
|
||||
$(function () {
|
||||
$(window).on('hashchange', function (e) {
|
||||
var hash = location.hash;
|
||||
if (hash == null || hash.length <= 1) {
|
||||
$(_loader.links).filter('[data-module]').removeClass('selected');
|
||||
$(_loader.content).empty();
|
||||
return;
|
||||
}
|
||||
hash = hash.substring(1);
|
||||
_loader.jump(hash);
|
||||
});
|
||||
|
||||
// page loaded
|
||||
var hash = location.hash;
|
||||
if (hash != null && hash.length > 1) {
|
||||
hash = hash.substring(1);
|
||||
//$(_loader.links).filter('[data-module="' + hash + '"]').addClass('selected');
|
||||
_loader.jump(hash);
|
||||
}
|
||||
else {
|
||||
//$(_loader.links).first().addClass('selected');
|
||||
hash = $(_loader.links).filter('[data-module]').first().addClass('selected').attr("data-module");
|
||||
_loader.jump(hash);
|
||||
}
|
||||
|
||||
//var links = $(_loader.links).filter('[data-module]');
|
||||
//links.click(function (e) {
|
||||
// // load module
|
||||
// var module = $(e.target).data('module');
|
||||
// location.hash = module;
|
||||
//});
|
||||
});
|
||||
},
|
||||
jump: function (hash) {
|
||||
var module = null;
|
||||
var ps = undefined;
|
||||
if (hash && hash.indexOf('/') > 0) {
|
||||
ps = hash.split('/');
|
||||
module = ps[0];
|
||||
ps.splice(0, 1);
|
||||
}
|
||||
else
|
||||
module = hash;
|
||||
|
||||
if (module) {
|
||||
$(_loader.links).filter('[data-module]').removeClass('selected');
|
||||
$(_loader.links).filter('[data-module="' + hash + '"]').addClass('selected');
|
||||
require(['modules/' + module], function (m) {
|
||||
$(_loader.content).empty().append(m.createContent(ps));
|
||||
});
|
||||
}
|
||||
//else {
|
||||
// require(['modules/' + module], function (m) {
|
||||
// $(_loader.content).empty().append(m.createContent());
|
||||
// });
|
||||
//}
|
||||
}
|
||||
};
|
||||
return _loader;
|
||||
});
|
Reference in New Issue
Block a user