@@ -16,26 +16,7 @@ var charMap = {
16
16
this . opt . commonality = 2 ;
17
17
}
18
18
19
- // Load in commonly used symbols in a common category
20
- var charMapCommon = localStorage . getItem ( 'charMapCommon' ) ;
21
- if ( charMapCommon ) {
22
- this . commonCategories = JSON . parse ( charMapCommon ) ;
23
-
24
- var sortable = [ ] ;
25
- for ( var char in this . commonCategories ) {
26
- if ( this . commonCategories [ char ] >= this . opt . commonality ) {
27
- sortable . push ( { char : char , count : this . commonCategories [ char ] } )
28
- sortable . sort (
29
- function ( a , b ) {
30
- return a . count - b . count
31
- }
32
- ) . reverse ( ) ;
33
- }
34
- }
35
-
36
- this . categories . Common = sortable ;
37
- }
38
-
19
+ this . loadCommon ( ) ;
39
20
40
21
// Create the dialog element
41
22
var container = document . createElement ( 'div' ) ;
@@ -89,7 +70,66 @@ var charMap = {
89
70
}
90
71
91
72
} ,
73
+ loadCommon : function ( ) {
74
+ // Load in commonly used symbols in a common category
75
+ var charMapCommon = localStorage . getItem ( 'charMapCommon' ) ;
76
+ if ( charMapCommon ) {
77
+ this . commonCategories = JSON . parse ( charMapCommon ) ;
92
78
79
+ var sortable = [ ] ;
80
+ for ( var char in this . commonCategories ) {
81
+ if ( this . commonCategories [ char ] >= this . opt . commonality ) {
82
+ sortable . push ( { char : char , count : this . commonCategories [ char ] } )
83
+ sortable . sort (
84
+ function ( a , b ) {
85
+ return a . count - b . count
86
+ }
87
+ ) . reverse ( ) ;
88
+ }
89
+ }
90
+
91
+ this . categories . Common = sortable ;
92
+ }
93
+ } ,
94
+
95
+ updateCommon : function ( ) {
96
+ var outputCommon = [ ] ;
97
+ var common = document . querySelector ( '.charMapCategory[data-category=Common]' ) ;
98
+ this . loadCommon ( ) ;
99
+ if ( common ) {
100
+ common . innerHTML = '' ;
101
+ for ( var c = 0 ; c < this . categories . Common . length ; ++ c ) {
102
+ cat = this . categories . Common [ c ] ;
103
+
104
+
105
+ if ( outputCommon . indexOf ( cat . char ) > - 1 ) {
106
+ continue ;
107
+ }
108
+ outputCommon . push ( cat . char ) ;
109
+
110
+
111
+ li = document . createElement ( 'li' ) ;
112
+ li . innerHTML = cat . char ;
113
+ if ( cat . entity ) {
114
+ li . innerHTML = cat . entity ;
115
+ }
116
+
117
+ li . setAttribute ( 'data-char' , li . innerHTML ) ;
118
+
119
+ if ( cat . name ) {
120
+ li . setAttribute ( 'data-name' , cat . name ) ;
121
+ }
122
+
123
+ if ( cat . entity ) {
124
+ li . setAttribute ( 'data-entity' , cat . entity ) ;
125
+ }
126
+
127
+ li . addEventListener ( 'click' , this . onClick . bind ( this ) ) ;
128
+
129
+ common . appendChild ( li ) ;
130
+ }
131
+ }
132
+ } ,
93
133
onClick : function ( event ) {
94
134
var char = event . target . getAttribute ( 'data-char' ) ;
95
135
var charMapCommon = JSON . parse ( ( localStorage . getItem ( 'charMapCommon' ) || '{}' ) ) ;
@@ -103,7 +143,7 @@ var charMap = {
103
143
}
104
144
105
145
localStorage . setItem ( 'charMapCommon' , JSON . stringify ( charMapCommon ) ) ;
106
-
146
+ this . updateCommon ( ) ;
107
147
if ( typeof this . opt . onClick == 'function' ) {
108
148
this . opt . onClick ( char ) ;
109
149
}
@@ -2531,6 +2571,6 @@ var charMap = {
2531
2571
}
2532
2572
} ;
2533
2573
2534
- if ( typeof modules != 'undefined' ) {
2535
- modules . exports = charMap ;
2574
+ if ( typeof module != 'undefined' ) {
2575
+ module . exports = charMap ;
2536
2576
}
0 commit comments