@@ -112,18 +112,27 @@ export class ProcPageManager {
112
112
113
113
// Check for forward-back history navigation
114
114
window . addEventListener ( "popstate" , ( e ) => {
115
- let newPage = this . getPageURL ( ) ;
116
- if ( newPage != this . curPageName ) {
115
+ let urlData = this . getPageURL ( ) ;
116
+ let newPage = urlData . page ;
117
+
118
+ if ( ! this . pageListing . hasOwnProperty ( newPage ) ) {
119
+ console . warn ( "Page not found in pageListing: " + newPage ) ;
120
+ newPage = this . defaultPage ;
121
+ }
117
122
123
+ if ( newPage != this . curPageName ) {
118
124
// Swap page content
119
125
this . changePage ( newPage ) ;
120
126
121
127
// Run page theming and callback functions
122
- if ( this . pageListing . hasOwnProperty ( newPage ) ) {
123
- this . curPageName = newPage ;
124
- this . curPage = this . pageListing [ newPage ] [ "obj" ] ;
125
- this . postLoad ( ) ;
126
- }
128
+ this . curPageName = newPage ;
129
+ this . curPage = this . pageListing [ newPage ] [ "obj" ] ;
130
+ this . postLoad ( ) ;
131
+ }
132
+
133
+ if ( urlData . section != null ) {
134
+ let pageData = this . pageListing [ newPage ] [ "pageData" ] ;
135
+ pageData . activateSection ( urlData . section ) ;
127
136
}
128
137
} ) ;
129
138
@@ -177,7 +186,10 @@ export class ProcPageManager {
177
186
} ) ;
178
187
179
188
// Rectify the URL state and set the current page
180
- let pageURL = this . getPageURL ( ) ;
189
+ let pageURLData = this . getPageURL ( ) ;
190
+ let pageURL = pageURLData . page ;
191
+ let pageSection = pageURLData . section ;
192
+
181
193
182
194
// Find the dom user clickable actions
183
195
this . findDomUserEvents ( ) ;
@@ -213,6 +225,7 @@ export class ProcPageManager {
213
225
this . updateDocumentMetaData ( pageURL ) ;
214
226
}
215
227
228
+
216
229
this . curPageName = pageURL ;
217
230
218
231
@@ -302,6 +315,14 @@ export class ProcPageManager {
302
315
//this.runHidePages();
303
316
this . activateNavButton ( this . curPageName ) ;
304
317
318
+ // Check the current page section
319
+ if ( pageSection != null && pageSection != "" ) {
320
+ let pageData = this . pageListing [ pageURL ] [ "pageData" ] ;
321
+ if ( pageData ) {
322
+ pageData . activateSection ( pageSection ) ;
323
+ }
324
+ }
325
+
305
326
}
306
327
307
328
// -- -- --
@@ -371,7 +392,7 @@ export class ProcPageManager {
371
392
// -- -- --
372
393
373
394
/**
374
- * @method getPageURL
395
+ * @method triggerDomEvent
375
396
* @returns {string } - The current page URL
376
397
* @description Retrieves the current page URL from the browser's address bar
377
398
*/
@@ -495,7 +516,10 @@ export class ProcPageManager {
495
516
496
517
let pageObj = pageData [ pageKey ] . buildPage ( ) ;
497
518
this . pageListing [ pageKey ] [ "obj" ] = pageObj ;
498
- console . log ( pageObj )
519
+
520
+ // Connect when sections change, to update the page manager
521
+ // This is used for history state pushes to a `folder/page` URL
522
+ pageData [ pageKey ] . subscribe ( this . sectionChangeCallback . bind ( this ) ) ;
499
523
} ) ;
500
524
501
525
}
@@ -640,7 +664,16 @@ export class ProcPageManager {
640
664
}
641
665
642
666
// Update URL page display & history state
643
- this . shiftHistoryState ( pageName ) ;
667
+ let pageData = this . pageListing [ pageName ] [ 'pageData' ] ;
668
+ let prevSection = pageData [ 'prevSection' ] ;
669
+ let sectionData = pageData [ 'sectionData' ] [ prevSection ] ;
670
+ if ( sectionData && sectionData . hasOwnProperty ( "htmlName" ) ) {
671
+ let htmlName = sectionData [ "htmlName" ] ;
672
+ let formattedURL = this . formatURL ( pageName , htmlName ) ;
673
+ this . shiftHistoryState ( formattedURL ) ;
674
+ } else {
675
+ this . shiftHistoryState ( pageName ) ;
676
+ }
644
677
645
678
// Update Meta Data
646
679
this . updateDocumentMetaData ( pageName ) ;
@@ -710,8 +743,9 @@ export class ProcPageManager {
710
743
shiftHistoryState ( pageName ) {
711
744
let urlDisplay = pageName ;
712
745
713
- if ( urlDisplay . includes ( ".htm" ) ) {
714
- urlDisplay = urlDisplay . split ( "." ) [ 0 ] ;
746
+ let urlCheck = urlDisplay . split ( "/" ) [ 0 ] ;
747
+ if ( urlCheck . includes ( ".htm" ) ) {
748
+ urlCheck = urlCheck . split ( "." ) [ 0 ] ;
715
749
}
716
750
717
751
// Check for specific capitalization of file url names
@@ -728,6 +762,7 @@ export class ProcPageManager {
728
762
urlDisplay += ".htm" ;
729
763
}
730
764
765
+ /*
731
766
let urlFolderPath = window.location.pathname;
732
767
if( urlFolderPath.includes(".htm") ){
733
768
urlFolderPath = urlFolderPath.split("/");
@@ -737,12 +772,51 @@ export class ProcPageManager {
737
772
urlFolderPath = urlFolderPath+"/";
738
773
}
739
774
let url = window.location.origin + urlFolderPath + urlDisplay;
775
+ */
776
+ if ( ! urlDisplay . startsWith ( "/" ) ) {
777
+ urlDisplay = "/" + urlDisplay ;
778
+ }
779
+ let url = window . location . origin + urlDisplay ;
740
780
window . history . pushState ( { path :url } , '' , url ) ;
741
781
742
782
}
743
783
784
+ /**
785
+ * Recieve page section change callback from the page itself
786
+ *
787
+ * This is used to push state to the browser history when the page has a section change
788
+ * @method sectionChangeCallback
789
+ * @param {Object } sectionData - Data object containing section information
790
+ */
744
791
sectionChangeCallback ( sectionData ) {
745
- console . log ( sectionData ) ;
792
+ let pageName = null ;
793
+ let sectionName = null ;
794
+ if ( ! sectionData || ! sectionData . hasOwnProperty ( "page" ) ) {
795
+ pageName = this . curPageName ;
796
+ } else {
797
+ pageName = sectionData [ 'dir' ] ;
798
+ if ( sectionData . hasOwnProperty ( "page" ) ) {
799
+ sectionName = sectionData [ 'page' ] ;
800
+ }
801
+ }
802
+
803
+ let formattedURL = this . formatURL ( pageName , sectionName ) ;
804
+ this . shiftHistoryState ( formattedURL ) ;
805
+ }
806
+
807
+ /**
808
+ * Format URL from page + section callback
809
+ */
810
+ formatURL ( pageName , sectionName ) {
811
+ let urlDisplay = pageName ;
812
+
813
+ if ( sectionName != null ) {
814
+ urlDisplay += "/" + sectionName ;
815
+ }
816
+ if ( ! urlDisplay . includes ( ".htm" ) ) {
817
+ urlDisplay += ".htm" ;
818
+ }
819
+ return urlDisplay ;
746
820
}
747
821
748
822
@@ -772,8 +846,15 @@ export class ProcPageManager {
772
846
this . checkForRedirect ( ) ;
773
847
774
848
// Pull base name from the url
775
- let url = window . location . href ;
849
+ let url = window . location . pathname ;
850
+
851
+ if ( url == "/index.htm" || url == "/" ) {
852
+ this . shiftHistoryState ( this . defaultPage ) ;
853
+ return { 'page' :this . defaultPage , 'section' :null } ;
854
+ }
855
+
776
856
let urlSplit = url . split ( "/" ) ;
857
+
777
858
let urlLast = urlSplit [ urlSplit . length - 1 ] ;
778
859
if ( urlLast != "" ) {
779
860
let urlSplitDot = urlLast . split ( "." ) ;
@@ -782,11 +863,32 @@ export class ProcPageManager {
782
863
ret = urlPage ;
783
864
}
784
865
}
785
- if ( ret . toLowerCase ( ) == "index" ) {
786
- ret = this . defaultPage ;
787
- this . shiftHistoryState ( ret ) ;
866
+
867
+ urlSplit = urlSplit . filter ( ( path ) => { return path != "" ; } ) ;
868
+
869
+
870
+ let urlFolderPath = null ;
871
+ let urlPagePath = urlSplit . pop ( ) ;
872
+ if ( urlSplit . length > 0 ) {
873
+ urlFolderPath = urlSplit . join ( "/" ) ;
788
874
}
789
- return ret ;
875
+
876
+ let pageCheck = ( urlFolderPath || urlPagePath ) . toLowerCase ( ) ;
877
+ if ( pageCheck . includes ( ".htm" ) ) {
878
+ pageCheck = pageCheck . split ( "." ) [ 0 ] ;
879
+ }
880
+
881
+ if ( ( urlFolderPath == null || urlFolderPath == "" ) && urlPagePath != "" ) {
882
+ urlFolderPath = urlPagePath ;
883
+ urlPagePath = "" ;
884
+ }
885
+ urlFolderPath = urlFolderPath . replace ( / \. h t m / g, "" ) ;
886
+ if ( urlFolderPath == "" ) {
887
+ urlFolderPath = this . defaultPage ;
888
+ urlPagePath = "" ;
889
+ }
890
+
891
+ return { 'page' :urlFolderPath , 'section' :urlPagePath } ;
790
892
}
791
893
792
894
0 commit comments