1
- /* global k2e:false */
1
+ /* globals k2e */
2
2
3
- ( function ( ) {
3
+ ( ( Router ) => {
4
4
5
5
let exportPreparationSem ;
6
6
let docsExport ;
@@ -12,12 +12,14 @@ enyo.kind({
12
12
name : 'k2e.App' ,
13
13
kind : 'FittableRows' ,
14
14
cookieModel : undefined ,
15
+ destroyClipListRouteHandler : undefined ,
16
+ destroyClipRouteHandler : undefined ,
17
+ settingsActive : undefined ,
15
18
published : {
16
19
periodicalTitleSet : undefined ,
17
20
ignoredTitleSet : undefined ,
18
21
documents : undefined ,
19
22
currentThemeClass : 'k2e-document-view-dark' ,
20
- settingsActive : false ,
21
23
currentMainPanel : undefined ,
22
24
currentAppToolbar : undefined ,
23
25
} ,
@@ -29,6 +31,8 @@ enyo.kind({
29
31
{ from : '.$.mainPanels.index' , to : '.currentMainPanel' } ,
30
32
{ from : '.$.appToolbar.index' , to : '.currentAppToolbar' } ,
31
33
{ from : '.$.appToolbarSlideable.value' , to : '.appToolbarSlidePercentage' } ,
34
+ { from : '.$.settings.slidedToMin' , to : '.settingsActive' ,
35
+ transform : ( slidedToMin ) => ! slidedToMin } ,
32
36
] ,
33
37
observers : [
34
38
{ method : 'appToolbarSearchFilterChanged' , path : [ '$.appToolbar.searchFilter' ] } ,
@@ -58,9 +62,11 @@ enyo.kind({
58
62
{ name : 'appToolbar' , kind : 'k2e.AppToolbar' ,
59
63
onExportRequested : 'prepareDocumentsAndExport' ,
60
64
onReloadClippingRequested : 'reloadClippings' ,
61
- onMultiSelectionToggled : 'handleMultiSelectionToggled' } ,
65
+ onMultiSelectionToggled : 'handleMultiSelectionToggled' ,
66
+ onToolbarStateToggled : 'handleToolbarStateToggled' } ,
62
67
] } ,
63
- { name : 'settings' , kind : 'k2e.settings.SettingsSlideable' } ,
68
+ { name : 'settings' , kind : 'k2e.settings.SettingsSlideable' ,
69
+ onToggleAnimateFinish : 'handleToggleAnimateFinish' } ,
64
70
{ kind : 'FittableColumns' , fit : true , components : [
65
71
{ name : 'mainPanels' , kind : 'Panels' , fit : true , arrangerKind : 'CollapsingArranger' ,
66
72
realtimeFit : true , wrap : false , components : [
@@ -78,6 +84,7 @@ enyo.kind({
78
84
79
85
appToolbarSearchFilterChanged,
80
86
appToolbarSlidePercentageChanged,
87
+ handleToolbarStateToggled,
81
88
handleMultiSelectionToggled,
82
89
toggleFullscreen,
83
90
exportDocuments,
@@ -97,6 +104,7 @@ enyo.kind({
97
104
handleClippingsTextChanged,
98
105
handleKeydown,
99
106
handleSettingsToggled,
107
+ handleToggleAnimateFinish,
100
108
handleThemeChanged,
101
109
handleFontSizeChanged,
102
110
handleFontChanged,
@@ -105,13 +113,13 @@ enyo.kind({
105
113
parseKindleClippings,
106
114
reloadClippings,
107
115
loadClippings,
108
- settingsActiveChanged,
109
116
currentMainPanelChanged,
110
117
currentAppToolbarChanged,
111
118
scrollDocumentToTop,
112
119
reflow,
113
120
rendered,
114
121
create,
122
+ destroy,
115
123
} ) ;
116
124
117
125
/////////////////////////////////////////////////////////////
@@ -120,6 +128,18 @@ function appToolbarSearchFilterChanged(/*previous, current, property*/) {
120
128
this . $ . documentSelectorList . scrollToTop ( ) ;
121
129
}
122
130
131
+ function handleToolbarStateToggled ( inSender , { oldState, newState } ) {
132
+ if (
133
+ oldState === this . $ . appToolbar . SELECTED_DOCUMENT_TOOLBAR &&
134
+ newState === this . $ . appToolbar . MAIN_TOOLBAR
135
+ ) {
136
+ // currentMainPanelChanged will handle this
137
+ return ;
138
+ }
139
+
140
+ changeRoute ( this ) ;
141
+ }
142
+
123
143
function appToolbarSlidePercentageChanged ( oldValue , newValue ) {
124
144
if ( ! this . $ . fittableColumns ) {
125
145
return ;
@@ -155,10 +175,6 @@ function handleMultiSelectionToggled(inSender, inEvent) {
155
175
this . $ . documentSelectorList . set ( 'multiSelected' , active ) ;
156
176
}
157
177
158
- function settingsActiveChanged ( /*old, active*/ ) {
159
- this . $ . settings . toggle ( ) ;
160
- }
161
-
162
178
function toggleFullscreen ( ) {
163
179
const isFullscreen = this . isFullscreen ( ) ;
164
180
@@ -372,23 +388,33 @@ function processQueryError(/*inSender, inResponse*/) {
372
388
this . handleQueryEnd ( ) ;
373
389
}
374
390
375
- function handleDocumentSelected ( inSender , inEvent ) {
391
+ function handleDocumentSelected ( inSender , { reSelected, originator } ) {
392
+ // Routing: react on document selection
376
393
const isScreenNarrow = enyo . Panels . isScreenNarrow ( ) ;
377
394
if ( isScreenNarrow ) {
378
395
this . $ . mainPanels . set ( 'index' , DOCUMENT_PANEL ) ;
396
+ this . $ . fittableColumns . applyStyle ( 'padding-bottom' , '0' ) ;
379
397
}
380
- if ( inEvent . reSelected ) {
398
+ if ( reSelected ) {
381
399
return ;
382
400
}
383
401
384
- const docSelector = inEvent . originator ;
402
+ const docSelector = originator ;
385
403
const doc = this . documents . getDocumentByKey ( docSelector . getKey ( ) ) ;
386
404
this . log ( docSelector . get ( 'key' ) ) ;
387
405
this . log ( docSelector . get ( 'index' ) ) ;
388
406
this . log ( doc ) ;
389
407
this . $ . documentControl . set ( 'document' , doc ) ;
390
408
this . $ . appToolbar . set ( 'selectedDocumentTitle' , doc . title ) ;
391
409
this . $ . appToolbarSlideable . animateToMax ( ) ;
410
+
411
+ // on narrow screens the route change will happen in
412
+ // currentMainPanelChanged since the panel also changes
413
+ // along w/ the selected doc
414
+
415
+ if ( ! Router . isNavigating && ! isScreenNarrow ) {
416
+ changeRoute ( this , this . $ . mainPanels . index ) ;
417
+ }
392
418
}
393
419
394
420
function handleDocumentMultiSelected ( /*inSender, inEvent*/ ) {
@@ -481,13 +507,9 @@ function loadClippings(clippingsText) {
481
507
throw ex ;
482
508
}
483
509
484
- const isScreenNarrow = enyo . Panels . isScreenNarrow ( ) ;
485
510
const settings = k2e . settings . SettingsStorage ;
486
511
settings . setSetting ( 'clippingsText' , clippingsText ) ;
487
512
this . $ . documentSelectorList . set ( 'documentsRef' , this . documents ) ;
488
- if ( this . $ . mainPanels . index === SIDEBAR_PANEL && ! isScreenNarrow ) {
489
- this . $ . documentSelectorList . selectNextDocument ( ) ;
490
- }
491
513
}
492
514
493
515
function handleKeydown ( inSender , inEvent ) {
@@ -538,8 +560,12 @@ function handleKeydown(inSender, inEvent) {
538
560
return true ;
539
561
}
540
562
541
- function handleSettingsToggled ( /*inSender, inEvent*/ ) {
542
- this . $ . settings . toggle ( ) ;
563
+ function handleSettingsToggled ( /* inSender, inEvent */ ) {
564
+ this . $ . settings . toggle ( true ) ;
565
+ }
566
+
567
+ function handleToggleAnimateFinish ( ) {
568
+ changeRoute ( this ) ;
543
569
}
544
570
545
571
function handleThemeChanged ( inSender , inEvent ) {
@@ -682,7 +708,7 @@ function reloadClippings() {
682
708
683
709
function handleClippingsCleared ( ) {
684
710
if ( this . $ . settings . isAtMax ( ) ) {
685
- this . set ( 'settingsActive' , false ) ;
711
+ // this.set('settingsActive', false);
686
712
}
687
713
688
714
this . $ . clippingPickerPopup . show ( { autoDismiss : false } ) ;
@@ -698,17 +724,18 @@ function currentMainPanelChanged(old, newIndex) {
698
724
) {
699
725
this . $ . appToolbar . popState ( ) ;
700
726
}
727
+
728
+ changeRoute ( this , newIndex ) ;
701
729
}
702
730
703
- function currentAppToolbarChanged ( oldToolbar ) {
704
- this . log ( oldToolbar ) ;
731
+ function currentAppToolbarChanged ( oldToolbar /* , newToolbar */ ) {
705
732
if ( oldToolbar !== k2e . AppToolbar . SELECTED_DOCUMENT_TOOLBAR ) {
706
733
return ;
707
734
}
708
735
709
- const appToolbarHeight = this . $ . appToolbar . hasNode ( ) . scrollHeight ;
736
+ // const appToolbarHeight = this.$.appToolbar.hasNode().scrollHeight;
710
737
this . $ . toTopButton . addRemoveClass ( 'visible' , false ) ;
711
- this . $ . fittableColumns . applyStyle ( 'padding-bottom' , `${ appToolbarHeight } px` ) ;
738
+ // this.$.fittableColumns.applyStyle('padding-bottom', `${appToolbarHeight}px`);
712
739
this . $ . mainPanels . set ( 'index' , SIDEBAR_PANEL ) ;
713
740
this . $ . appToolbarSlideable . animateToMax ( ) ;
714
741
}
@@ -739,17 +766,38 @@ function reflow() {
739
766
740
767
function rendered ( ) {
741
768
this . inherited ( arguments ) ;
769
+ const isScreenNarrow = enyo . Panels . isScreenNarrow ( ) ;
742
770
if ( ! this . documents ) {
743
771
this . $ . clippingPickerPopup . show ( { autoDismiss : false } ) ;
744
772
}
745
773
this . reflow ( ) ;
746
774
this . $ . sidebar . resize ( ) ;
775
+ Router . resolve ( ) ;
776
+
777
+ // Select the first doc in the doc list on non-narrow displays
778
+ // if none is already selected
779
+
780
+ if (
781
+ ! isScreenNarrow &&
782
+ ! this . $ . documentSelectorList . get ( 'selDocumentSelectorItem' ) &&
783
+ this . $ . mainPanels . index === SIDEBAR_PANEL
784
+ ) {
785
+ this . $ . documentSelectorList . selectNextDocument ( ) ;
786
+ }
747
787
}
748
788
749
789
function create ( ) {
750
790
this . inherited ( arguments ) ;
751
791
const settings = k2e . settings . SettingsStorage ;
752
792
793
+ this . destroyClipListRouteHandler = Router . onClipListRouteChanged (
794
+ handleRouteChange ( this , SIDEBAR_PANEL , k2e . AppToolbar . MAIN_TOOLBAR )
795
+ ) ;
796
+
797
+ this . destroyClipRouteHandler = Router . onClipRouteChanged (
798
+ handleRouteChange ( this , DOCUMENT_PANEL , k2e . AppToolbar . SELECTED_DOCUMENT_TOOLBAR )
799
+ ) ;
800
+
753
801
const cookieModel = new k2e . CookieModel ( ) ;
754
802
cookieModel . fetch ( ) ;
755
803
this . set ( 'cookieModel' , cookieModel ) ;
@@ -771,4 +819,47 @@ function create() {
771
819
exportPreparationSem = new k2e . util . AsyncSemaphore ( { func : this . exportDocuments . bind ( this ) } ) ;
772
820
}
773
821
774
- } ) ( ) ;
822
+ function handleRouteChange ( app , panelId , defaultToolbarId ) {
823
+ return ( key , { settings : settingsActive , toolbar : toolbarId } ) => {
824
+ settingsActive = settingsActive === 'true' ;
825
+ app . $ . mainPanels . set ( 'index' , panelId ) ;
826
+ if ( key !== undefined ) {
827
+ app . $ . documentSelectorList . selectDocument ( key ) ;
828
+ }
829
+ if ( app . get ( 'settingsActive' ) !== settingsActive ) {
830
+ app . $ . settings . toggle ( ) ;
831
+ }
832
+ toolbarId = toolbarId !== undefined ?
833
+ Number . parseInt ( toolbarId , 10 ) :
834
+ defaultToolbarId ;
835
+ if ( app . $ . appToolbar . currentState !== toolbarId ) {
836
+ const pushed = app . $ . appToolbar . tryPushState ( toolbarId ) ;
837
+ if ( ! pushed ) {
838
+ app . $ . appToolbar . popState ( ) ;
839
+ }
840
+ }
841
+ } ;
842
+ }
843
+
844
+ function changeRoute ( app , panelId ) {
845
+ panelId = panelId !== undefined ? panelId : app . $ . mainPanels . index ;
846
+ const doc = app . $ . documentSelectorList . get ( 'selDocumentSelectorItem' ) ;
847
+ if ( ! doc ) {
848
+ return ;
849
+ }
850
+ ( panelId === DOCUMENT_PANEL ?
851
+ Router . tryClipChanged : Router . tryClipListChanged
852
+ ) ( doc . get ( 'key' ) , {
853
+ settings : app . settingsActive ,
854
+ toolbar : app . $ . appToolbar . currentState ,
855
+ } ) ;
856
+ }
857
+
858
+ function destroy ( ) {
859
+ this . inherited ( arguments ) ;
860
+
861
+ this . destroyClipListRouteHandler ( ) ;
862
+ this . destroyClipRouteHandler ( ) ;
863
+ }
864
+
865
+ } ) ( k2e . util . Router ) ;
0 commit comments