11/* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.*/
2+ var exampleNameList = [ ] ;
3+
24$ ( document ) . ready ( function ( ) {
35 window . initI18N ( function ( ) {
6+ generateExampleNameList ( ) ;
47 initPage ( ) ;
58 bindEvents ( ) ;
69 sidebarScrollFix ( ) ;
710} ) ;
811} ) ;
9-
1012var aceEditor ;
1113var containExamples = true ;
1214
@@ -16,6 +18,17 @@ function initPage() {
1618 screenResize ( ) ;
1719}
1820
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+
1932
2033//获取示例页面的配置信息
2134function getActiveExampleConfig ( ) {
@@ -89,14 +102,17 @@ function loadExampleHtml() {
89102 if ( ! locationParam ) {
90103 return ;
91104 }
105+ if ( exampleNameList . indexOf ( locationParam ) === - 1 ) {
106+ window . location . href = window . location . origin + '/web/404.html' ;
107+ return ;
108+ }
92109 var href = window . location . toString ( ) ;
93110 var mapUrl = href . substr ( 0 , href . lastIndexOf ( '/' ) + 1 ) ;
94111 mapUrl = mapUrl + locationParam + ".html" ;
95112 if ( ! mapUrl ) {
96113 return ;
97114 }
98115 var isError = false ;
99- var notFoundPath = '/web/404.html' ;
100116 var response = $ . ajax ( {
101117 url : mapUrl ,
102118 async : false ,
@@ -105,18 +121,12 @@ function loadExampleHtml() {
105121 isError = true ;
106122 }
107123 } ) ;
108- if ( response && response . status === 302 ) {
109- var location = response . getResponseHeader ( 'Location' ) ;
110- if ( location && location . indexOf ( notFoundPath ) !== - 1 ) {
111- isError = true ;
112- }
113- }
114124 var html = response . responseText ;
115125 if ( html && html != "" && ! isError ) {
116126 $ ( '#editor' ) . val ( html ) ;
117127 loadPreview ( html ) ;
118128 } else {
119- window . location . href = window . location . origin + notFoundPath ;
129+ window . location . href = window . location . origin + '/web/404.html' ;
120130 }
121131}
122132
0 commit comments