-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_old.html
More file actions
140 lines (138 loc) · 6.56 KB
/
index_old.html
File metadata and controls
140 lines (138 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<!-- The title and meta data are changed by the active module-->
<title></title>
<meta name="description" content="">
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel="icon" href="data:,">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.css" />
</head>
<body>
<!-- Typical website layout, the contents are dynamiclly updated by modules-->
<div id=header></div>
<div id=content></div>
<div id=footer></div>
<div id=app style='display:none'></div>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"></script>
</body>
<script boot-up>
//------------------------------------
$vm={};$vm.ver=[0.74,0.47]; //increase ver[0] if any module changed, increase ver[1] if vm.js changed
$vm.debug=1;
//------------------------------------
//setup modules location
$vm.hosting_path=window.location.href.substring(0, window.location.href.split('?')[0].lastIndexOf('/'));
if(window.location.hostname=='127.0.0.1' || window.location.hostname=='localhost') $vm.localhost=true;
//------------------------------------
//where are your start modules
$vm.start_modules=[
"$H/0/frame.html", //app frame work
]
for(i in $vm.start_modules) $vm.start_modules[i]=$vm.start_modules[i].replace('$H',$vm.hosting_path);
//------------------------------------
//modules used immediately
$vm.module_list={
//you can add modules here directly
"home": {url:"$H/0/home.html",router:1},
"app": {url:"$H/0/app.html"},
"header": {url:"$H/0/header.html"},
"footer": {url:"$H/0/footer.html"},
"vmext": {url:"$H/0/vm-extension.html"},
};
for(p in $vm.module_list) $vm.module_list[p].url=$vm.module_list[p].url.replace('$H',$vm.hosting_path);
//------------------------------------
//all other modules, used on demand
$vm.app_modules=[
//you can add a js file that will add mmodules to the $vm.module_list
"$H/module-list.js",
]
for(i in $vm.app_modules) $vm.app_modules[i]=$vm.app_modules[i].replace('$H',$vm.hosting_path);
//------------------------------------
//called by framework
$vm.start=function(){
$vm.load_component('header',$vm.root_layout_header,{});
$vm.load_component('footer',$vm.root_layout_footer,{});
$vm.load_component('app',$vm.root_layout_app,{});
$vm.install_module('vmext','',{},function(name,id){});
}
//------------------------------------
//------------------------------------
//Do not need to chang the following code in most cases
//The following code will load a framework module and on demand module list
//------------------------------------
$VmAPI={};$vm.start_time=new Date().getTime();
//------------------------------------
$vm.root_layout_header='header';
$vm.root_layout_content_slot='content'
$vm.root_layout_footer='footer';
$vm.root_layout_app='app';
//---------------------------------------------
$vm._I=0; $vm._N=$vm.start_modules.length;
$vm._boot=function(){
$vm._I++;
if($vm._I==$vm._N){
$vm._start();
}
}
//------------------------------------------
$vm._J=0; $vm._JN=$vm.app_modules.length;
$vm._boot2=function(){
$vm._J++;
if($vm._J==$vm._JN){
console.log("module list is ready "+(new Date().getTime()-$vm.start_time)+'ms');
$vm.all_module=1;
}
}
//------------------------------------------
$vm._id=1;
//---------------------------------------------
var apppath=window.location.href.substring(0, window.location.href.lastIndexOf('/')).split('\/?')[0];
console.log("start point "+(new Date().getTime()-$vm.start_time)+'ms');
$($vm.start_modules).each(function(index,url){
var ver=localStorage.getItem(apppath+url+"ver");
var txt=localStorage.getItem(apppath+url+"txt");
if(ver!=$vm.ver[0] || txt==null || $vm.localhost==true){
$.get(url+'?_='+new Date().getTime(),function(new_txt){
localStorage.setItem(apppath+url+"txt",new_txt);
localStorage.setItem(apppath+url+"ver",$vm.ver[0]);
console.log('loading from url, done at '+(new Date().getTime()-$vm.start_time)+'ms. '+url );
$('#content').append(new_txt.replace(/__ID/g,'_'+(index+1)));
$vm._boot();
},'text');
}
else{
console.log('loading from storage. done at '+(new Date().getTime()-$vm.start_time)+'ms. '+url+' '+ver+'/'+$vm.ver[0]);
$('#content').append(txt.replace(/__ID/g,'_'+(index+1)));
$vm._boot();
}
})
//---------------------------------------------
//(delayed) load module-list js and run;
setTimeout(function (){
var T=0;
$($vm.app_modules).each(function(index,url){
T+=10;
setTimeout(function (){
var ver=localStorage.getItem(apppath+url+"ver");
var txt=localStorage.getItem(apppath+url+"txt");
if(ver!=$vm.ver[0] || txt==null || $vm.localhost==true){
$.get(url+'?_='+new Date().getTime(),function(new_txt){
localStorage.setItem(apppath+url+"txt",new_txt);
localStorage.setItem(apppath+url+"ver",$vm.ver[0]);
console.log('loading from url, done at '+(new Date().getTime()-$vm.start_time)+'ms. '+url);
eval(new_txt);
$vm._boot2();
},'text');
}
else{
console.log('loading from storage, done at '+(new Date().getTime()-$vm.start_time)+'ms. '+url+' '+ver+'/'+$vm.ver[0]);
eval(txt);
$vm._boot2();
}
},10+T);
})
},10);
//---------------------------------------------
</script>
</html>