@@ -11,20 +11,29 @@ import "../css/editor-libs/common.css";
11
11
import "../css/editable-css.css" ;
12
12
13
13
( function ( ) {
14
- const exampleChoiceList = document . getElementById ( "example-choice-list" ) ;
15
- const exampleChoices = exampleChoiceList . querySelectorAll ( ".example-choice" ) ;
14
+ const exampleChoiceList = document . getElementById (
15
+ "example-choice-list" ,
16
+ ) as HTMLElement ;
17
+
18
+ const exampleChoices = exampleChoiceList . querySelectorAll (
19
+ ".example-choice" ,
20
+ ) as NodeListOf < HTMLElement > ;
16
21
const exampleDeclarations = Array . from (
17
22
exampleChoices ,
18
- ( choice ) => choice . querySelector ( "code" ) . textContent ,
23
+ ( choice ) => choice . querySelector ( "code" ) ? .textContent ,
19
24
) ;
20
- const editorWrapper = document . getElementById ( "editor-wrapper" ) ;
21
- const output = document . getElementById ( "output" ) ;
22
- const warningNoSupport = document . getElementById ( "warning-no-support" ) ;
23
-
24
- const originalChoices = [ ] ;
25
+ const editorWrapper = document . getElementById (
26
+ "editor-wrapper" ,
27
+ ) as HTMLElement ;
28
+ const output = document . getElementById ( "output" ) as HTMLElement ;
29
+ const warningNoSupport = document . getElementById (
30
+ "warning-no-support" ,
31
+ ) as HTMLElement ;
32
+
33
+ const originalChoices : string [ ] = [ ] ;
25
34
let initialChoice = 0 ;
26
35
27
- function applyCodeMirror ( target , code ) {
36
+ function applyCodeMirror ( target : HTMLElement , code : string ) {
28
37
return initCodeEditor ( target , code , languageCSS ( ) , {
29
38
lineNumbers : false ,
30
39
} ) ;
@@ -42,14 +51,16 @@ import "../css/editable-css.css";
42
51
const exampleChoice = exampleChoices [ i ] ;
43
52
const choiceButton = document . createElement ( "button" ) ;
44
53
const choiceButtonText = document . createElement ( "span" ) ;
45
- const choiceCode = exampleChoice . querySelector ( "code" ) ;
46
- const copyButton = exampleChoice . getElementsByClassName ( "copy" ) [ 0 ] ;
54
+ const choiceCode = exampleChoice . querySelector ( "code" ) as HTMLElement ;
55
+ const copyButton = exampleChoice . getElementsByClassName (
56
+ "copy" ,
57
+ ) [ 0 ] as HTMLButtonElement ;
47
58
48
- originalChoices . push ( choiceCode . textContent ) ;
59
+ originalChoices . push ( choiceCode . textContent || "" ) ;
49
60
50
61
const codeMirrorEditor = applyCodeMirror (
51
- exampleChoice . querySelector ( "pre" ) ,
52
- choiceCode . textContent ,
62
+ exampleChoice . querySelector ( "pre" ) as HTMLElement ,
63
+ choiceCode . textContent || "" ,
53
64
) ;
54
65
55
66
choiceButton . setAttribute ( "type" , "button" ) ;
@@ -82,11 +93,12 @@ import "../css/editable-css.css";
82
93
* reset all the CSS examples to their original state
83
94
*/
84
95
function handleResetEvents ( ) {
85
- const resetButton = document . getElementById ( "reset" ) ;
96
+ const resetButton = document . getElementById ( "reset" ) as HTMLElement ;
86
97
87
98
resetButton . addEventListener ( "click" , ( ) => {
88
99
exampleChoices . forEach ( ( e , i ) => {
89
- const preEl = e . querySelector ( "pre" ) ;
100
+ const preEl = e . querySelector ( "pre" ) as HTMLElement ;
101
+
90
102
// Remove original codemirror
91
103
for ( const e of preEl . children ) {
92
104
e . remove ( ) ;
@@ -100,16 +112,16 @@ import "../css/editable-css.css";
100
112
101
113
// if there is an initial choice set, set it as selected
102
114
if ( initialChoice ) {
103
- mceEvents . onChoose ( exampleChoices [ initialChoice ] ) ;
104
- clippy . toggleClippy ( exampleChoices [ initialChoice ] ) ;
115
+ mceEvents . onChoose ( exampleChoices [ initialChoice ] as HTMLElement ) ;
116
+ clippy . toggleClippy ( exampleChoices [ initialChoice ] as HTMLElement ) ;
105
117
} else {
106
- mceEvents . onChoose ( exampleChoices [ 0 ] ) ;
107
- clippy . toggleClippy ( exampleChoices [ 0 ] ) ;
118
+ mceEvents . onChoose ( exampleChoices [ 0 ] as HTMLElement ) ;
119
+ clippy . toggleClippy ( exampleChoices [ 0 ] as HTMLElement ) ;
108
120
}
109
121
} ) ;
110
122
}
111
123
112
- function indexOf ( exampleChoices , choice ) {
124
+ function indexOf ( exampleChoices : NodeListOf < Element > , choice : Element ) {
113
125
for ( let i = 0 , l = exampleChoices . length ; i < l ; i ++ ) {
114
126
if ( exampleChoices [ i ] === choice ) {
115
127
return i ;
@@ -126,23 +138,24 @@ import "../css/editable-css.css";
126
138
function handleChoiceHover ( ) {
127
139
for ( let i = 0 , l = exampleChoices . length ; i < l ; i ++ ) {
128
140
const choice = exampleChoices [ i ] ;
129
- const copyBtn = choice . querySelector ( ".copy" ) ;
141
+ const copyBtn = choice . querySelector ( ".copy" ) as HTMLElement ;
142
+
130
143
copyBtn . setAttribute ( "aria-label" , "Copy to clipboard" ) ;
131
144
132
145
choice . addEventListener ( "mouseover" , ( ) => {
133
- copyBtn . setAttribute ( "aria-hidden" , false ) ;
146
+ copyBtn . setAttribute ( "aria-hidden" , " false" ) ;
134
147
} ) ;
135
148
choice . addEventListener ( "mouseout" , ( ) => {
136
- copyBtn . setAttribute ( "aria-hidden" , true ) ;
149
+ copyBtn . setAttribute ( "aria-hidden" , " true" ) ;
137
150
} ) ;
138
151
}
139
152
}
140
153
141
154
/* only show the live code view if JS is enabled and the property is supported. */
142
155
if ( cssEditorUtils . isAnyDeclarationSetSupported ( exampleDeclarations ) ) {
143
156
enableLiveEditor ( ) ;
144
- mceEvents . onChoose ( exampleChoices [ initialChoice ] ) ;
145
- clippy . toggleClippy ( exampleChoices [ initialChoice ] ) ;
157
+ mceEvents . onChoose ( exampleChoices [ initialChoice ] as HTMLElement ) ;
158
+ clippy . toggleClippy ( exampleChoices [ initialChoice ] as HTMLElement ) ;
146
159
} else {
147
160
warningNoSupport . classList . remove ( "hidden" ) ;
148
161
}
0 commit comments