@@ -11,31 +11,13 @@ const editorElement = document.getElementById('editor')
1111const editorElement2 = document . getElementById ( 'editor2' )
1212let editorElementRef = editorElement
1313
14- const undoElement = document . getElementById ( 'undo' )
15- const redoElement = document . getElementById ( 'redo' )
1614const convertElement = document . getElementById ( 'convert' )
1715const mainElement = document . getElementById ( 'mainContent' )
1816
1917const inputs = [ ]
2018const inputValues = new Map ( )
2119
22- for ( let i = 1 ; i < 5 ; i ++ ) {
23- inputs [ i ] = document . createElement ( 'div' )
24- inputs [ i ] . id = `input${ i } `
25- inputs [ i ] . setAttribute ( 'touch-action' , 'none' )
26- inputs [ i ] . classList . add ( 'input' )
27- inputValues . set ( inputs [ i ] . id , '' )
28-
29- const label = document . createElement ( 'label' )
30- label . setAttribute ( 'for' , inputs [ i ] . id )
31- label . innerText = `Input N°${ i } `
32-
33- mainElement . appendChild ( label )
34- mainElement . appendChild ( inputs [ i ] )
35- }
36-
3720/** The two following functions roundFloat and extractPoint are used to get a point coordinates */
38-
3921const floatPrecisionArray = [ 1 , 10 , 100 , 1000 , 10000 , 100000 , 1000000 , 10000000 , 100000000 , 1000000000 ]
4022
4123function roundFloat ( oneFloat , requestedFloatPrecision ) {
@@ -67,23 +49,11 @@ function extractPoint (event, domElement, configuration, offsetTop = 0, offsetLe
6749function addChangedListeners ( editors ) {
6850 editors . forEach ( ( editor ) => {
6951 editor . addEventListener ( 'changed' , ( event ) => {
70- undoElement . disabled = ! event . detail . canUndo
71- redoElement . disabled = ! event . detail . canRedo
7252 convertElement . disabled = event . detail . isEmpty
7353 } )
7454 } )
7555}
7656
77- undoElement . addEventListener ( 'click' , ( ) => {
78- editorElementRef . editor . undo ( )
79- } )
80- redoElement . addEventListener ( 'click' , ( ) => {
81- editorElementRef . editor . redo ( )
82- } )
83- convertElement . addEventListener ( 'click' , ( ) => {
84- editorElementRef . editor . convert ( )
85- } )
86-
8757function addIdleListeners ( editors ) {
8858 editors . forEach ( ( editor ) => {
8959 editor . addEventListener ( 'idle' , ( ) => {
@@ -106,8 +76,7 @@ function addIdleListeners (editors) {
10676 } )
10777}
10878
109- function addInputsPointerDownListener ( inputId ) {
110- const input = document . getElementById ( inputId )
79+ function addPointerEventListener ( input ) {
11180 input . addEventListener ( 'pointerdown' , ( event ) => {
11281 if ( editorElementRef . editor . initialized ) {
11382 pointerDownOnInput = true
@@ -254,11 +223,6 @@ const customGrabber = {
254223 detach
255224}
256225
257- editorElement . addEventListener ( 'loaded' , ( ) => {
258- editorElement . style . display = 'none'
259- editorElement2 . style . display = 'none'
260- } )
261-
262226function initEditors ( editors ) {
263227 editors . forEach ( ( editor ) => {
264228 iink . register ( editor , {
@@ -291,15 +255,35 @@ function initEditors (editors) {
291255 } )
292256}
293257
294- initEditors ( [ editorElement , editorElement2 ] )
295-
296- Array . from ( inputValues . keys ( ) ) . forEach ( ( inputId ) => {
297- addInputsPointerDownListener ( inputId )
258+ convertElement . addEventListener ( 'click' , ( ) => {
259+ editorElementRef . editor . convert ( )
298260} )
299261
262+ initEditors ( [ editorElement , editorElement2 ] )
263+
300264addIdleListeners ( [ editorElement , editorElement2 ] )
265+
301266addChangedListeners ( [ editorElement , editorElement2 ] )
302267
268+ for ( let i = 1 ; i < 5 ; i ++ ) {
269+ const inputEl = document . createElement ( 'div' )
270+ inputEl . id = `input${ i } `
271+ inputEl . setAttribute ( 'touch-action' , 'none' )
272+ inputEl . classList . add ( 'input' )
273+
274+ addPointerEventListener ( inputEl )
275+
276+ const labelEL = document . createElement ( 'label' )
277+ labelEL . setAttribute ( 'for' , inputEl . id )
278+ labelEL . innerText = `Input N°${ i } `
279+
280+ mainElement . appendChild ( labelEL )
281+ mainElement . appendChild ( inputEl )
282+
283+ inputs [ i ] = inputEl
284+ inputValues . set ( inputEl . id , '' )
285+ }
286+
303287window . addEventListener ( 'resize' , ( ) => {
304288 editorElement . editor . resize ( )
305289 editorElement2 . editor . resize ( )
0 commit comments