Changeset 33096
- Timestamp:
- 2019-05-17T19:41:19+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js
r33095 r33096 1 2 1 3 2 function MapEditor(id) { … … 174 173 return message; 175 174 } 176 } 177 } 178 179 } 180 181 $(function() {175 } 176 } 177 } 178 179 // Having got our unique (set) of descriptions/labels, we're ready to set it up as the source for our autocomplete list 180 $(function setupAutocompleteLabelsList() { 182 181 // Overrides the default autocomplete filter function to 183 182 // search only from the beginning of the string … … 200 199 MapEditor.prototype.addToAutocompleteLabelsList = function (newLabel) { 201 200 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); 201 if (newLabel !== "" && !this.autocompleteLabelsList.includes(newLabel)) { 202 // add to autocomplete list and sort alphabetically 203 this.autocompleteLabelsList.push(newLabel); 204 this.autocompleteLabelsList.sort(); 205 205 } 206 206 } … … 803 803 MapEditor.prototype.LOAD = function (json_str, nodeID) { 804 804 this.mapEditorHistory.historyOverlayPush(); 805 806 805 807 806 // This seems to convert the map_store object into an array and forces array index access, instead of convenient property access using nodeID 808 807 //Object.values(gsmap_store)[0]; // Always gets top level section's map-editor, not what we want. … … 817 816 818 817 map_editor.overlays = new_overlays; 819 818 819 var labels_hashmap = {}; 820 820 for (var i=0; i<map_editor.overlays.length; i++) { 821 821 var shape = map_editor.overlays[i]; 822 822 823 // set up the autocomplete list using saved labels/descriptions 824 map_editor.addToAutocompleteLabelsList(shape.description); 823 // set up the autocomplete list using saved labels/descriptions 824 //map_editor.addToAutocompleteLabelsList(shape.description); // inefficient in ensuring uniqueness of values, use (hash)map 825 if (shape.description !== "") { 826 labels_hashmap[shape.description] = 1; // we just want the shape.description added to the map as key, don't care about value 827 // so that we can maintain a list of unique descriptions 828 } 825 829 826 830 // make the shapes selectable on load: … … 834 838 835 839 this.mapEditorHistory.presentOverlayPush(); 840 841 var keys = Object.keys(labels_hashmap); 842 // DO NOT assign "this.autocompleteLabelsList = keys(labels_hashmap);" 843 // Because Javascript is like Java and (in this) like C, not like C++. JavaScript uses Call-By-Sharing for objects: 844 // when reference addresses that are overwritten inside functions, 845 // the new address local to the function is not remembered/visible back outside the function 846 // https://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language 847 // Instead, push.apply=addAll elements of keys to our autocomplete list, see 848 // https://stackoverflow.com/questions/35658464/what-is-the-equivalent-of-java-collection-addall-for-javascript-arrays/35658514 849 this.autocompleteLabelsList.push.apply(this.autocompleteLabelsList, keys); // addAll keys to our autocompleteLabelsList 850 this.autocompleteLabelsList.sort(); 836 851 } 837 852
Note:
See TracChangeset
for help on using the changeset viewer.