- Timestamp:
- 2019-05-17T18:19:41+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js
r33088 r33095 37 37 this.resizable = false; 38 38 this.dontResize = false; 39 this.autocompleteLabelsList = []; 39 40 40 41 this.shapeOptions = { … … 124 125 that.shapeOptions.description = description; 125 126 that.setSelectedDescription(that.shapeOptions.description); 127 } 128 129 // Also add a COMPLETED description (i.e. when description input box loses focus) 130 // to the autocomplete list of descriptions/labels 131 descriptionInput.onblur = function () { 132 var description = this.value; 133 that.addToAutocompleteLabelsList(description) 126 134 } 127 135 … … 170 178 171 179 } 180 181 $(function () { 182 // Overrides the default autocomplete filter function to 183 // search only from the beginning of the string 184 //resource: https://miroslavpopovic.com/posts/2012/06/jqueryui-autocomplete-filter-words-starting-with-term 185 $.ui.autocomplete.filter = function (array, term) { 186 var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(term), "i"); 187 return $.grep(array, function (value) { 188 return matcher.test(value.label || value.value || value); 189 }); 190 }; 191 192 $(".description").autocomplete({ 193 source: that.autocompleteLabelsList 194 }); 195 }); 196 } 197 198 199 // Ensure only unique labels are added to our autocomplete list 200 MapEditor.prototype.addToAutocompleteLabelsList = function (newLabel) { 201 202 if (!this.autocompleteLabelsList.includes(newLabel)) { 203 // TODO: add to end with push, add to start with unshift or sort alphabetically? 204 this.autocompleteLabelsList.unshift(newLabel); 205 } 172 206 } 173 207 … … 785 819 786 820 for (var i=0; i<map_editor.overlays.length; i++) { 787 var shape = map_editor.overlays[i]; 821 var shape = map_editor.overlays[i]; 822 823 // set up the autocomplete list using saved labels/descriptions 824 map_editor.addToAutocompleteLabelsList(shape.description); 825 788 826 // make the shapes selectable on load: 789 827 if (ShapesUtil.overlayItemIsShape(shape)) {
Note:
See TracChangeset
for help on using the changeset viewer.