@@ -56,6 +56,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
56
56
$ ( this . termContainer ) . on ( 'keyup' , '[data-label]' , this . onKeyUp , this ) ;
57
57
$ ( this . termContainer ) . on ( 'focusout' , '[data-index]' , this . onTermFocusOut , this ) ;
58
58
$ ( this . termContainer ) . on ( 'focusin' , '[data-index]' , this . onTermFocus , this ) ;
59
+ $ ( this . termContainer ) . on ( 'click' , '[data-index]' , this . onTermClick , this ) ;
59
60
60
61
// Copy/Paste
61
62
$ ( this . input ) . on ( 'paste' , this . onPaste , this ) ;
@@ -468,7 +469,14 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
468
469
}
469
470
470
471
renderTerm ( termData , termIndex ) {
471
- let label = $ . render ( '<label><input type="text"></label>' ) ;
472
+ let inputContainer ;
473
+ if ( this . isReadOnlyMode ( ) ) {
474
+ inputContainer = '<label><input type="button"><i class="icon-cancel term-icon"></i></label>' ;
475
+ } else {
476
+ inputContainer = '<label><input type="input"></label>' ;
477
+ }
478
+
479
+ let label = $ . render ( inputContainer ) ;
472
480
473
481
if ( termData . class ) {
474
482
label . classList . add ( termData . class ) ;
@@ -539,7 +547,10 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
539
547
toFocus = this . input ;
540
548
}
541
549
542
- toFocus . selectionStart = toFocus . selectionEnd = 0 ;
550
+ if ( ! this . isReadOnlyMode ( ) ) {
551
+ toFocus . selectionStart = toFocus . selectionEnd = 0 ;
552
+ }
553
+
543
554
$ ( toFocus ) . focus ( ) ;
544
555
545
556
return toFocus ;
@@ -562,7 +573,10 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
562
573
toFocus = this . input ;
563
574
}
564
575
565
- toFocus . selectionStart = toFocus . selectionEnd = toFocus . value . length ;
576
+ if ( ! this . isReadOnlyMode ( ) ) {
577
+ toFocus . selectionStart = toFocus . selectionEnd = toFocus . value . length ;
578
+ }
579
+
566
580
$ ( toFocus ) . focus ( ) ;
567
581
568
582
return toFocus ;
@@ -657,6 +671,8 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
657
671
}
658
672
}
659
673
674
+ let arrowUpOrLeft = this . isTermDirectionVertical ( ) ? 'ArrowUp' : 'ArrowLeft' ;
675
+ let arrowDownOrRight = this . isTermDirectionVertical ( ) ? 'ArrowDown' : 'ArrowRight' ;
660
676
let removedTerms ;
661
677
switch ( event . key ) {
662
678
case ' ' :
@@ -723,14 +739,17 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
723
739
this . saveTerm ( input , false ) ;
724
740
}
725
741
break ;
726
- case 'ArrowLeft' :
727
- if ( input . selectionStart === 0 && this . hasTerms ( ) ) {
742
+ case arrowUpOrLeft :
743
+ if ( ( input . selectionStart === 0 || input . selectionStart === null && this . isReadOnlyMode ( ) )
744
+ && this . hasTerms ( ) ) {
728
745
event . preventDefault ( ) ;
729
746
this . moveFocusBackward ( ) ;
730
747
}
731
748
break ;
732
- case 'ArrowRight' :
733
- if ( input . selectionStart === input . value . length && this . hasTerms ( ) ) {
749
+ case arrowDownOrRight :
750
+ if ( ( input . selectionStart === input . value . length
751
+ || input . selectionStart === null && this . isReadOnlyMode ( ) )
752
+ && this . hasTerms ( ) ) {
734
753
event . preventDefault ( ) ;
735
754
this . moveFocusForward ( ) ;
736
755
}
@@ -812,6 +831,20 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
812
831
}
813
832
}
814
833
834
+ onTermClick ( event ) {
835
+ if ( this . isReadOnlyMode ( ) ) {
836
+ this . removeTerm ( event . target . parentNode ) ;
837
+ }
838
+ }
839
+
840
+ isReadOnlyMode ( ) {
841
+ return this . input . dataset . termMode === 'read-only'
842
+ }
843
+
844
+ isTermDirectionVertical ( ) {
845
+ return this . input . dataset . termDirection === 'vertical'
846
+ }
847
+
815
848
onButtonClick ( event ) {
816
849
if ( ! this . hasSyntaxError ( ) ) {
817
850
// Register current input value, otherwise it's not included
0 commit comments