@@ -218,9 +218,11 @@ UI.Panel = function ( position ) {
218
218
219
219
UI . Element . call ( this ) ;
220
220
221
- this . dom = document . createElement ( 'div' ) ;
222
- this . dom . style . position = position || 'relative' ;
223
- this . dom . style . marginBottom = '10px' ;
221
+ var dom = document . createElement ( 'div' ) ;
222
+ dom . style . position = position || 'relative' ;
223
+ dom . style . marginBottom = '10px' ;
224
+
225
+ this . dom = dom ;
224
226
225
227
// this.dom.addEventListener( 'mousedown', function ( event ) { event.preventDefault() }, false );
226
228
@@ -248,8 +250,10 @@ UI.Text = function ( position ) {
248
250
249
251
UI . Element . call ( this ) ;
250
252
251
- this . dom = document . createElement ( 'span' ) ;
252
- this . dom . style . position = position || 'relative' ;
253
+ var dom = document . createElement ( 'span' ) ;
254
+ dom . style . position = position || 'relative' ;
255
+
256
+ this . dom = dom ;
253
257
254
258
return this ;
255
259
@@ -274,10 +278,12 @@ UI.Input = function ( position ) {
274
278
275
279
var scope = this ;
276
280
277
- this . dom = document . createElement ( 'input' ) ;
278
- this . dom . style . position = position || 'relative' ;
279
- this . dom . style . marginTop = '-2px' ;
280
- this . dom . style . marginLeft = '-2px' ;
281
+ var dom = document . createElement ( 'input' ) ;
282
+ dom . style . position = position || 'relative' ;
283
+ dom . style . marginTop = '-2px' ;
284
+ dom . style . marginLeft = '-2px' ;
285
+
286
+ this . dom = dom ;
281
287
282
288
this . onChangeCallback = null ;
283
289
@@ -324,12 +330,14 @@ UI.Select = function ( position ) {
324
330
325
331
var scope = this ;
326
332
327
- this . dom = document . createElement ( 'select' ) ;
328
- this . dom . style . position = position || 'relative' ;
329
- this . dom . style . width = '64px' ;
330
- this . dom . style . height = '16px' ;
331
- this . dom . style . border = '0px' ;
332
- this . dom . style . padding = '0px' ;
333
+ var dom = document . createElement ( 'select' ) ;
334
+ dom . style . position = position || 'relative' ;
335
+ dom . style . width = '64px' ;
336
+ dom . style . height = '16px' ;
337
+ dom . style . border = '0px' ;
338
+ dom . style . padding = '0px' ;
339
+
340
+ this . dom = dom ;
333
341
334
342
this . onChangeCallback = null ;
335
343
@@ -405,9 +413,11 @@ UI.Checkbox = function ( position ) {
405
413
406
414
var scope = this ;
407
415
408
- this . dom = document . createElement ( 'input' ) ;
409
- this . dom . type = 'checkbox' ;
410
- this . dom . style . position = position || 'relative' ;
416
+ var dom = document . createElement ( 'input' ) ;
417
+ dom . type = 'checkbox' ;
418
+ dom . style . position = position || 'relative' ;
419
+
420
+ this . dom = dom ;
411
421
412
422
this . onChangeCallback = null ;
413
423
@@ -454,14 +464,16 @@ UI.Color = function ( position ) {
454
464
455
465
var scope = this ;
456
466
457
- this . dom = document . createElement ( 'input' ) ;
458
- this . dom . type = 'color' ;
459
- this . dom . style . position = position || 'relative' ;
460
- this . dom . style . width = '64px' ;
461
- this . dom . style . height = '16px' ;
462
- this . dom . style . border = '0px' ;
463
- this . dom . style . padding = '0px' ;
464
- this . dom . style . backgroundColor = 'transparent' ;
467
+ var dom = document . createElement ( 'input' ) ;
468
+ dom . type = 'color' ;
469
+ dom . style . position = position || 'relative' ;
470
+ dom . style . width = '64px' ;
471
+ dom . style . height = '16px' ;
472
+ dom . style . border = '0px' ;
473
+ dom . style . padding = '0px' ;
474
+ dom . style . backgroundColor = 'transparent' ;
475
+
476
+ this . dom = dom ;
465
477
466
478
this . onChangeCallback = null ;
467
479
@@ -508,23 +520,18 @@ UI.Number = function ( position ) {
508
520
509
521
var scope = this ;
510
522
511
- this . dom = document . createElement ( 'span' ) ;
512
- this . dom . style . position = position || 'relative' ;
513
-
514
- var display = document . createElement ( 'span' ) ;
515
- display . style . color = '#0080f0' ;
516
- display . style . fontSize = '12px' ;
517
- display . style . cursor = 'col-resize' ;
518
- display . textContent = '0.00' ;
519
- this . dom . appendChild ( display ) ;
523
+ var dom = document . createElement ( 'input' ) ;
524
+ dom . style . position = position || 'relative' ;
525
+ dom . style . color = '#0080f0' ;
526
+ dom . style . fontSize = '12px' ;
527
+ dom . style . cursor = 'col-resize' ;
528
+ dom . style . backgroundColor = 'transparent' ;
529
+ dom . style . borderColor = 'transparent' ;
530
+ dom . style . marginTop = '-2px' ;
531
+ dom . style . marginLegt = '-2px' ;
532
+ dom . value = '0.00' ;
520
533
521
- var input = document . createElement ( 'input' ) ;
522
- input . style . display = 'none' ;
523
- input . style . width = '100%' ;
524
- input . style . marginTop = '-2px' ;
525
- input . style . marginLeft = '-2px' ;
526
- input . style . fontSize = '12px' ;
527
- this . dom . appendChild ( input ) ;
534
+ this . dom = dom ;
528
535
529
536
this . min = - Infinity ;
530
537
this . max = Infinity ;
@@ -540,7 +547,7 @@ UI.Number = function ( position ) {
540
547
541
548
distance = 0 ;
542
549
543
- onMouseDownValue = parseFloat ( display . textContent ) ;
550
+ onMouseDownValue = parseFloat ( dom . value ) ;
544
551
545
552
document . addEventListener ( 'mousemove' , onMouseMove , false ) ;
546
553
document . addEventListener ( 'mouseup' , onMouseUp , false ) ;
@@ -556,7 +563,7 @@ UI.Number = function ( position ) {
556
563
557
564
var number = onMouseDownValue + ( distance / ( event . shiftKey ? 10 : 100 ) ) ;
558
565
559
- display . textContent = Math . min ( scope . max , Math . max ( scope . min , number ) ) . toFixed ( 2 ) ;
566
+ dom . value = Math . min ( scope . max , Math . max ( scope . min , number ) ) . toFixed ( 2 ) ;
560
567
561
568
if ( scope . onChangeCallback ) scope . onChangeCallback ( ) ;
562
569
@@ -567,66 +574,58 @@ UI.Number = function ( position ) {
567
574
document . removeEventListener ( 'mousemove' , onMouseMove , false ) ;
568
575
document . removeEventListener ( 'mouseup' , onMouseUp , false ) ;
569
576
570
- if ( Math . abs ( distance ) < 1 ) {
571
-
572
- display . style . display = 'none' ;
573
-
574
- input . value = display . textContent ;
577
+ if ( Math . abs ( distance ) < 2 ) {
575
578
576
- input . addEventListener ( 'change' , onInputChange , false ) ;
577
- input . addEventListener ( 'blur' , onInputBlur , false ) ;
578
- input . addEventListener ( 'keyup' , onInputKeyUp , false ) ;
579
-
580
- input . style . display = '' ;
581
-
582
- input . focus ( ) ;
583
- input . select ( ) ;
579
+ dom . focus ( ) ;
580
+ dom . select ( ) ;
584
581
585
582
}
586
583
587
584
} ;
588
585
589
- var onInputChange = function ( event ) {
586
+ var onChange = function ( event ) {
590
587
591
- var number = parseFloat ( input . value ) ;
588
+ var number = parseFloat ( dom . value ) ;
592
589
593
590
if ( isNaN ( number ) === false ) {
594
591
595
- display . textContent = number . toFixed ( 2 ) ;
592
+ dom . value = number ;
596
593
597
594
if ( scope . onChangeCallback ) scope . onChangeCallback ( ) ;
598
595
599
596
}
600
597
601
598
} ;
602
599
603
- var onInputBlur = function ( event ) {
600
+ var onFocus = function ( event ) {
601
+
602
+ dom . style . backgroundColor = '' ;
603
+ dom . style . borderColor = '' ;
604
+
605
+ } ;
604
606
605
- display . style . display = '' ;
607
+ var onBlur = function ( event ) {
606
608
607
- input . removeEventListener ( 'change' , onInputChange ) ;
608
- input . removeEventListener ( 'blur' , onInputBlur ) ;
609
- input . removeEventListener ( 'keyup' , onInputKeyUp ) ;
610
- input . style . display = 'none' ;
609
+ dom . style . backgroundColor = 'transparent' ;
610
+ dom . style . borderColor = 'transparent' ;
611
611
612
612
} ;
613
613
614
- var onInputKeyUp = function ( event ) {
614
+ var onKeyUp = function ( event ) {
615
615
616
616
if ( event . keyCode == 13 ) {
617
617
618
- display . style . display = '' ;
619
-
620
- input . removeEventListener ( 'change' , onInputChange ) ;
621
- input . removeEventListener ( 'blur' , onInputBlur ) ;
622
- input . removeEventListener ( 'keyup' , onInputKeyUp ) ;
623
- input . style . display = 'none' ;
618
+ onBlur ( ) ;
624
619
625
620
}
626
621
627
622
} ;
628
623
629
- display . addEventListener ( 'mousedown' , onMouseDown , false ) ;
624
+ dom . addEventListener ( 'mousedown' , onMouseDown , false ) ;
625
+ dom . addEventListener ( 'change' , onChange , false ) ;
626
+ dom . addEventListener ( 'focus' , onFocus , false ) ;
627
+ dom . addEventListener ( 'blur' , onBlur , false ) ;
628
+ dom . addEventListener ( 'keyup' , onKeyUp , false ) ;
630
629
631
630
return this ;
632
631
@@ -636,13 +635,13 @@ UI.Number.prototype = Object.create( UI.Element.prototype );
636
635
637
636
UI . Number . prototype . getValue = function ( ) {
638
637
639
- return parseFloat ( this . dom . children [ 0 ] . textContent ) ;
638
+ return parseFloat ( this . dom . value ) ;
640
639
641
640
} ;
642
641
643
642
UI . Number . prototype . setValue = function ( value ) {
644
643
645
- this . dom . children [ 0 ] . textContent = value . toFixed ( 2 ) ;
644
+ this . dom . value = value . toFixed ( 2 ) ;
646
645
647
646
return this ;
648
647
@@ -672,7 +671,9 @@ UI.Break = function () {
672
671
673
672
UI . Element . call ( this ) ;
674
673
675
- this . dom = document . createElement ( 'br' ) ;
674
+ var dom = document . createElement ( 'br' ) ;
675
+
676
+ this . dom = dom ;
676
677
677
678
return this ;
678
679
@@ -687,8 +688,10 @@ UI.HorizontalRule = function ( position ) {
687
688
688
689
UI . Element . call ( this ) ;
689
690
690
- this . dom = document . createElement ( 'hr' ) ;
691
- this . dom . style . position = position || 'relative' ;
691
+ var dom = document . createElement ( 'hr' ) ;
692
+ dom . style . position = position || 'relative' ;
693
+
694
+ this . dom = dom ;
692
695
693
696
return this ;
694
697
@@ -705,8 +708,10 @@ UI.Button = function ( position ) {
705
708
706
709
var scope = this ;
707
710
708
- this . dom = document . createElement ( 'button' ) ;
709
- this . dom . style . position = position || 'relative' ;
711
+ var dom = document . createElement ( 'button' ) ;
712
+ dom . style . position = position || 'relative' ;
713
+
714
+ this . dom = dom ;
710
715
711
716
this . onClickCallback = null ;
712
717
0 commit comments