7
7
function MoinMoin ( ) {
8
8
"use strict" ;
9
9
}
10
+
10
11
// Utility function to add a message to moin flash area. Message can be removed by clicking on it.
11
12
MoinMoin . prototype . MOINFLASHINFO = "moin-flash moin-flash-info" ;
12
13
MoinMoin . prototype . MOINFLASHWARNING = "moin-flash moin-flash-warning" ;
@@ -19,14 +20,12 @@ MoinMoin.prototype.moinFlashMessage = function (classes, message) {
19
20
} ) ;
20
21
} ;
21
22
22
-
23
23
// if /template/dictionary.js has not been loaded, untranslated strings will be returned by _(...)
24
24
function _ ( text ) {
25
25
"use strict" ;
26
26
return $ . i18n . _ ( text ) ;
27
27
}
28
28
29
-
30
29
// return true if browser localStorage is available
31
30
function localStorageAvailable ( ) {
32
31
"use strict" ;
@@ -41,44 +40,70 @@ function localStorageAvailable() {
41
40
}
42
41
}
43
42
44
- // executed when user clicks button to toggle modify textarea between fixed/variable width fonts
45
- function moinFontChange ( ) {
43
+ // executed on page ready, if this is a modify view add action to Cancel button
44
+ function cancelEdit ( ) {
46
45
"use strict" ;
47
- $ ( ".moin-edit-content" ) . toggleClass ( "moin-fixed-width" ) ;
46
+ $ ( '.moin-cancel' ) . click ( function ( ) {
47
+ // do not ask to leave page; any edits will be lost, but browser back button may restore edits
48
+ $ ( '#moin-modify' ) . removeClass ( 'moin-changed-input' ) ;
49
+ window . location = $ ( '#moin-wiki-root' ) . val ( ) + '/' + $ ( '#moin-item-name' ) . val ( ) ;
50
+ } ) ;
51
+ }
52
+
53
+ // Initial user settings
54
+ MoinMoin . prototype . userSettings = {
55
+ 'user-actions-collapsed' : true ,
56
+ 'view-options-collapsed' : true ,
57
+ 'item-actions-collapsed' : true
58
+ } ;
59
+
60
+ MoinMoin . prototype . loadUserSettings = function ( ) {
48
61
if ( localStorageAvailable ( ) ) {
49
- if ( $ ( ".moin-edit-content" ) . hasClass ( "moin-fixed-width" ) ) {
50
- localStorage . setItem ( "moin-textarea-font" , "moin-fixed-width" ) ;
51
- } else {
52
- localStorage . setItem ( "moin-textarea-font" , "" ) ;
62
+ let jsonData = localStorage . getItem ( "moin-user-settings" ) ;
63
+ if ( jsonData ) {
64
+ this . userSettings = JSON . parse ( jsonData ) ;
53
65
}
54
66
}
55
67
}
56
68
57
- // executed on page ready, change textarea font to last saved value fixed/proportional
58
- function moinFontChangeOnReady ( ) {
59
- "use strict" ;
60
- if ( $ ( ".moin-edit-content" ) ) {
61
- if ( localStorageAvailable ( ) ) {
62
- if ( localStorage . getItem ( "moin-textarea-font" ) === "moin-fixed-width" ) {
63
- $ ( ".moin-edit-content" ) . addClass ( "moin-fixed-width" ) ;
64
- } else {
65
- $ ( ".moin-edit-content" ) . removeClass ( "moin-fixed-width" ) ;
66
- }
67
- }
69
+ MoinMoin . prototype . saveUserSettings = function ( ) {
70
+ if ( localStorageAvailable ( ) ) {
71
+ localStorage . setItem ( "moin-user-settings" , JSON . stringify ( this . userSettings ) ) ;
68
72
}
69
73
}
70
74
75
+ MoinMoin . prototype . applyUserSettings = function ( ) {
71
76
72
- // executed on page ready, if this is a modify view add action to Cancel button
73
- function cancelEdit ( ) {
74
- "use strict" ;
75
- $ ( '.moin-cancel' ) . click ( function ( ) {
76
- // do not ask to leave page; any edits will be lost, but browser back button may restore edits
77
- $ ( '#moin-modify' ) . removeClass ( 'moin-changed-input' ) ;
78
- window . location = $ ( '#moin-wiki-root' ) . val ( ) + '/' + $ ( '#moin-item-name' ) . val ( ) ;
79
- } ) ;
80
- }
77
+ if ( this . userSettings [ 'user-actions-collapsed' ] ) {
78
+ $ ( '#moin-user-actions' ) . addClass ( 'hidden' ) ;
79
+ $ ( '.moin-useractions > i' ) . removeClass ( 'fa-rotate-90' ) ;
80
+ } else {
81
+ $ ( '#moin-user-actions' ) . removeClass ( 'hidden' ) ;
82
+ $ ( '.moin-useractions > i' ) . addClass ( 'fa-rotate-90' ) ;
83
+ }
84
+
85
+ if ( this . userSettings [ 'view-options-collapsed' ] ) {
86
+ $ ( '#moin-view-options' ) . addClass ( 'hidden' ) ;
87
+ $ ( '.moin-viewoptions > i' ) . removeClass ( 'fa-rotate-90' ) ;
88
+ } else {
89
+ $ ( '#moin-view-options' ) . removeClass ( 'hidden' ) ;
90
+ $ ( '.moin-viewoptions > i' ) . addClass ( 'fa-rotate-90' ) ;
91
+ }
92
+
93
+ if ( this . userSettings [ 'item-actions-collapsed' ] ) {
94
+ $ ( '#moin-item-actions' ) . addClass ( 'hidden' ) ;
95
+ $ ( '.moin-itemactions > i' ) . removeClass ( 'fa-rotate-90' ) ;
96
+ } else {
97
+ $ ( '#moin-item-actions' ) . removeClass ( 'hidden' ) ;
98
+ $ ( '.moin-itemactions > i' ) . addClass ( 'fa-rotate-90' ) ;
99
+ }
81
100
101
+ if ( this . userSettings [ "textarea-use-fixed-width-font" ] ) {
102
+ $ ( ".moin-edit-content" ) . addClass ( "moin-fixed-width" ) ;
103
+ } else {
104
+ $ ( ".moin-edit-content" ) . removeClass ( "moin-fixed-width" ) ;
105
+ }
106
+ }
82
107
83
108
// Highlight currently selected link in side panel. Executed on page load
84
109
MoinMoin . prototype . selected_link = function ( ) {
@@ -760,6 +785,9 @@ $(document).ready(function () {
760
785
"use strict" ;
761
786
var moin = new MoinMoin ( ) ;
762
787
788
+ moin . loadUserSettings ( )
789
+ moin . applyUserSettings ( ) ;
790
+
763
791
moin . diffScroll ( ) ;
764
792
moin . selected_link ( ) ;
765
793
moin . initTransclusionOverlays ( ) ;
@@ -781,26 +809,41 @@ $(document).ready(function () {
781
809
moin . toggleSubtree ( this ) ;
782
810
} ) ;
783
811
784
- $ ( '.moin-useractions' ) . click ( function ( ) {
812
+ $ ( '.moin-useractions' ) . click ( function ( event ) {
813
+ event . preventDefault ( ) ;
785
814
$ ( '#moin-user-actions' ) . toggleClass ( 'hidden' ) ;
786
815
$ ( '.moin-useractions > i' ) . toggleClass ( 'fa-rotate-90' ) ;
787
- return false ;
816
+ moin . userSettings [ 'user-actions-collapsed' ] = $ ( '#moin-user-actions' ) . hasClass ( 'hidden' ) ;
817
+ moin . saveUserSettings ( ) ;
788
818
} ) ;
789
819
790
- $ ( '.moin-viewoptions' ) . click ( function ( ) {
820
+ $ ( '.moin-viewoptions' ) . click ( function ( event ) {
821
+ event . preventDefault ( ) ;
791
822
$ ( '#moin-view-options' ) . toggleClass ( 'hidden' ) ;
792
823
$ ( '.moin-viewoptions > i' ) . toggleClass ( 'fa-rotate-90' ) ;
793
- return false ;
824
+ moin . userSettings [ 'view-options-collapsed' ] = $ ( '#moin-view-options' ) . hasClass ( 'hidden' ) ;
825
+ moin . saveUserSettings ( ) ;
794
826
} ) ;
795
827
796
- $ ( '.moin-itemactions' ) . click ( function ( ) {
828
+ $ ( '.moin-itemactions' ) . click ( function ( event ) {
829
+ event . preventDefault ( ) ;
797
830
$ ( '#moin-item-actions' ) . toggleClass ( 'hidden' ) ;
798
831
$ ( '.moin-itemactions > i' ) . toggleClass ( 'fa-rotate-90' ) ;
799
- return false ;
832
+ moin . userSettings [ 'item-actions-collapsed' ] = $ ( '#moin-item-actions' ) . hasClass ( 'hidden' ) ;
833
+ moin . saveUserSettings ( ) ;
834
+ } ) ;
835
+
836
+ // executed when user clicks button to toggle modify textarea between fixed/variable width fonts
837
+ $ ( '#moin-toggle-fixed-font-button' ) . on ( 'click' , function ( event ) {
838
+ event . preventDefault ( ) ;
839
+ $ ( ".moin-edit-content" ) . toggleClass ( "moin-fixed-width" ) ;
840
+ moin . userSettings [ 'textarea-use-fixed-width-font' ] = $ ( ".moin-edit-content" ) . hasClass ( "moin-fixed-width" ) ;
841
+ moin . saveUserSettings ( ) ;
800
842
} ) ;
801
843
802
844
moin . enhanceUserSettings ( ) ;
803
845
moin . enhanceEdit ( ) ;
846
+
804
847
$ ( '.moin-sortable' ) . tablesorter ( ) ;
805
848
806
849
$ ( '#moin-modify' ) . on ( 'change keyup keydown' , 'input, textarea, select' , function ( e ) {
@@ -859,8 +902,6 @@ $(document).ready(function () {
859
902
}
860
903
} ) ;
861
904
862
- moinFontChangeOnReady ( ) ;
863
-
864
905
$ ( 'textarea.moin-autosize' ) . autosize ( ) ;
865
906
866
907
showAllOptions ( ) ;
0 commit comments