|
1 |
| -define(["BaseInput"], function (BaseInput) { |
| 1 | +define(["../notjQuery", "BaseInput"], function ($, BaseInput) { |
2 | 2 |
|
3 | 3 | "use strict";
|
4 | 4 |
|
5 | 5 | class TermInput extends BaseInput {
|
6 | 6 | constructor(input) {
|
7 | 7 | super(input);
|
8 | 8 |
|
9 |
| - this.separator = ' '; |
| 9 | + this.separator = this.input.dataset.termSeparator || ' '; |
10 | 10 | this.ignoreSpaceUntil = null;
|
11 | 11 | this.ignoreSpaceSince = null;
|
12 | 12 | }
|
13 | 13 |
|
| 14 | + bind() { |
| 15 | + if (this.isReadOnlyMode()) { |
| 16 | + $(this.termContainer).on('click', '[data-index]', this.onTermClick, this); |
| 17 | + } |
| 18 | + |
| 19 | + return super.bind(); |
| 20 | + } |
| 21 | + |
14 | 22 | reset() {
|
15 | 23 | super.reset();
|
16 | 24 |
|
@@ -61,6 +69,32 @@ define(["BaseInput"], function (BaseInput) {
|
61 | 69 | super.complete(input, data);
|
62 | 70 | }
|
63 | 71 |
|
| 72 | + renderTerm(termData, termIndex) { |
| 73 | + if (! this.isReadOnlyMode()) { |
| 74 | + return super.renderTerm(termData, termIndex); |
| 75 | + } |
| 76 | + |
| 77 | + let label = $.render( |
| 78 | + '<label><input type="button" class="term-badge"><i class="fa fa-trash trash-icon"></i></label>' |
| 79 | + ); |
| 80 | + |
| 81 | + if (termData.class) { |
| 82 | + label.classList.add(termData.class); |
| 83 | + } |
| 84 | + |
| 85 | + if (termData.title) { |
| 86 | + label.title = termData.title; |
| 87 | + } |
| 88 | + |
| 89 | + label.dataset.label = termData.label; |
| 90 | + label.dataset.search = termData.search; |
| 91 | + label.dataset.index = termIndex; |
| 92 | + |
| 93 | + label.firstChild.value = termData.label; |
| 94 | + |
| 95 | + return label; |
| 96 | + } |
| 97 | + |
64 | 98 | /**
|
65 | 99 | * Event listeners
|
66 | 100 | */
|
@@ -122,6 +156,12 @@ define(["BaseInput"], function (BaseInput) {
|
122 | 156 | }
|
123 | 157 | }
|
124 | 158 | }
|
| 159 | + |
| 160 | + onTermClick(event) { |
| 161 | + let termIndex = event.target.parentNode.dataset.index; |
| 162 | + this.removeTerm(event.target.parentNode); |
| 163 | + this.moveFocusForward(termIndex - 1); |
| 164 | + } |
125 | 165 | }
|
126 | 166 |
|
127 | 167 | return TermInput;
|
|
0 commit comments