1
1
/* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.*/
2
+ var exampleNameList = [ ] ;
3
+
2
4
$ ( document ) . ready ( function ( ) {
3
5
window . initI18N ( function ( ) {
6
+ generateExampleNameList ( ) ;
4
7
initPage ( ) ;
5
8
bindEvents ( ) ;
6
9
sidebarScrollFix ( ) ;
7
10
} ) ;
8
11
} ) ;
9
-
10
12
var aceEditor ;
11
13
var containExamples = true ;
12
14
@@ -16,6 +18,17 @@ function initPage() {
16
18
screenResize ( ) ;
17
19
}
18
20
21
+ function generateExampleNameList ( ) {
22
+ var config = window . exampleConfig ;
23
+ Object . keys ( config ) . forEach ( ( menuItem ) => {
24
+ config [ menuItem ] . content && Object . keys ( config [ menuItem ] . content ) . forEach ( ( secondMenuItem ) => {
25
+ config [ menuItem ] . content [ secondMenuItem ] . content && config [ menuItem ] . content [ secondMenuItem ] . content . forEach ( ( exampleInfo ) => {
26
+ exampleNameList . push ( exampleInfo . fileName ) ;
27
+ } ) ;
28
+ } ) ;
29
+ } ) ;
30
+ }
31
+
19
32
20
33
//获取示例页面的配置信息
21
34
function getActiveExampleConfig ( ) {
@@ -89,14 +102,17 @@ function loadExampleHtml() {
89
102
if ( ! locationParam ) {
90
103
return ;
91
104
}
105
+ if ( exampleNameList . indexOf ( locationParam ) === - 1 ) {
106
+ window . location . href = window . location . origin + '/web/404.html' ;
107
+ return ;
108
+ }
92
109
var href = window . location . toString ( ) ;
93
110
var mapUrl = href . substr ( 0 , href . lastIndexOf ( '/' ) + 1 ) ;
94
111
mapUrl = mapUrl + locationParam + ".html" ;
95
112
if ( ! mapUrl ) {
96
113
return ;
97
114
}
98
115
var isError = false ;
99
- var notFoundPath = '/web/404.html' ;
100
116
var response = $ . ajax ( {
101
117
url : mapUrl ,
102
118
async : false ,
@@ -105,18 +121,12 @@ function loadExampleHtml() {
105
121
isError = true ;
106
122
}
107
123
} ) ;
108
- if ( response && response . status === 302 ) {
109
- var location = response . getResponseHeader ( 'Location' ) ;
110
- if ( location && location . indexOf ( notFoundPath ) !== - 1 ) {
111
- isError = true ;
112
- }
113
- }
114
124
var html = response . responseText ;
115
125
if ( html && html != "" && ! isError ) {
116
126
$ ( '#editor' ) . val ( html ) ;
117
127
loadPreview ( html ) ;
118
128
} else {
119
- window . location . href = window . location . origin + notFoundPath ;
129
+ window . location . href = window . location . origin + '/web/404.html' ;
120
130
}
121
131
}
122
132
0 commit comments