@@ -20,6 +20,9 @@ let selectedTheme: string = location.hash.split('/')[1];
2020let availableThemes : string [ ] = [ 'material' , 'fabric' , 'bootstrap' ] ;
2121let isHashChanged : boolean = true ;
2222let isButtonClick : boolean = false ;
23+ let themeRegex : RegExp = / # \/ ( m a t e r i a l | f a b r i c | b o o t s t r a p ) / i;
24+ let defaultSamples : any = [ ] ;
25+ let samplePath : string [ ] = [ ] ;
2326
2427interface DestroyMethod extends HTMLElement {
2528 destroy : Function ;
@@ -253,9 +256,22 @@ function routeDefault(): void {
253256 window . location . href = '#/' + selectedTheme + '/chart/line.html' ;
254257 isInitRedirected = true ;
255258 } ) ;
256- bypassed . add ( ( request : Object ) => {
257- loadPage ( '404' ) ;
259+ bypassed . add ( ( request : string ) => {
260+ let hash : string [ ] = request . split ( '.html' ) [ 0 ] . split ( '/' ) ;
261+ if ( samplePath . indexOf ( hash . slice ( 1 ) . join ( '/' ) ) === - 1 ) {
262+ let path : string ;
263+ for ( let sample of samplePath ) {
264+ if ( sample . indexOf ( hash [ 1 ] + '/' ) !== - 1 ) {
265+ path = hash [ 0 ] + '/' + sample + '.html' ;
266+ break ;
267+ }
268+ }
269+ location . hash = path ? path : '#/material/chart/line.html' ;
270+ location . hash = '#/' + hash [ 0 ] + '/' + ( defaultSamples [ hash [ 1 ] ] || 'chart/line.html' ) ;
271+ isInitRedirected = true ;
272+ }
258273 } ) ;
274+
259275}
260276
261277function wireEvents ( ) : void {
@@ -296,12 +312,14 @@ function loadTheme(theme: string): void {
296312}
297313function addRoutes ( samplesList : Controls [ ] ) : void {
298314 for ( let node of samplesList ) {
315+ defaultSamples [ node . directory ] = node . directory + '/' + node . samples [ 0 ] . url + '.html' ;
299316 let dataManager : DataManager = new DataManager ( node . samples ) ;
300317 let samples : Samples [ ] & { [ key : string ] : Object } [ ] = < Samples [ ] & { [ key : string ] : Object } [ ] >
301318 dataManager . executeLocal ( new Query ( ) . sortBy ( 'order' , 'ascending' ) ) ;
302319 for ( let subNode of samples ) {
303320 let control : string = node . directory ;
304321 let sample : string = subNode . url ;
322+ samplePath = samplePath . concat ( control + '/' + sample ) ;
305323 let sampleName : string = node . name + ' / ' + ( ( node . name !== subNode . category ) ?
306324 ( subNode . category + ' / ' ) : '' ) + subNode . name ;
307325 let selectedTheme : string = location . hash . split ( '/' ) [ 1 ] ? location . hash . split ( '/' ) [ 1 ] : 'material' ;
@@ -536,6 +554,16 @@ function parseHash(newHash: string, oldHash: string): void {
536554function checkSampleLength ( directory : string ) : boolean {
537555 let data : DataManager = new DataManager ( samplesList ) ;
538556 let controls : Controls [ ] = < Controls [ ] > data . executeLocal ( new Query ( ) . where ( 'directory' , 'equal' , directory ) ) ;
557+ if ( ! controls . length ) {
558+ let hash : string = location . hash ;
559+ let split : string [ ] = hash . split ( '/' ) ;
560+ if ( ! themeRegex . test ( hash ) && split . length === 3 ) {
561+ location . hash = '#/material/' + split [ 1 ] + '/' + split [ 2 ] ;
562+ } else {
563+ location . hash = '#/material/chart/line.html' ;
564+ }
565+ location . reload ( ) ;
566+ }
539567 return controls [ 0 ] . samples . length > 1 ;
540568}
541569
0 commit comments