Prechádzať zdrojové kódy

Add returned xhr_user_search_url JSON data onto the Suggestion instance

So that it can be used by 3rd party plugins
JC Brand 2 mesiacov pred
rodič
commit
03bea347be

+ 1 - 0
src/plugins/rosterview/utils.js

@@ -368,5 +368,6 @@ export async function getNamesAutoCompleteList(query) {
     return json.map((i) => ({
         label: `${i.fullname} <${i.jid}>`,
         value: `${i.fullname} <${i.jid}>`,
+        ...i, // Return rest of the JSON as well, could be useful to 3rd party plugin
     }));
 }

+ 4 - 1
src/shared/autocomplete/autocomplete.js

@@ -186,10 +186,13 @@ export class AutoComplete extends EventEmitter(Object) {
                 // scroll to highlighted element in case parent's height is fixed
                 this.ul.scrollTop = list[i].offsetTop - this.ul.clientHeight + list[i].clientHeight;
             }
-            this.trigger('suggestion-box-highlight', { 'text': this.suggestions[this.index] });
+            this.trigger('suggestion-box-highlight', { text: this.suggestions[this.index] });
         }
     }
 
+    /**
+     * @param {Element} selected
+     */
     select(selected) {
         if (selected) {
             this.index = siblingIndex(selected);

+ 10 - 9
src/shared/autocomplete/suggestion.js

@@ -3,32 +3,33 @@
  */
 class Suggestion extends String {
     /**
-     * @param { any } data - The auto-complete data. Ideally an object e.g. { label, value },
+     * @param {any} data - The auto-complete data. Ideally an object e.g. { label, value },
      *      which specifies the value and human-presentable label of the suggestion.
-     * @param { string } query - The query string being auto-completed
+     * @param {string} query - The query string being auto-completed
      */
-    constructor (data, query) {
+    constructor(data, query) {
         super();
         const o = Array.isArray(data)
             ? { label: data[0], value: data[1] }
             : typeof data === 'object' && 'label' in data && 'value' in data
-            ? data
-            : { label: data, value: data };
+              ? data
+              : { label: data, value: data };
 
         this.label = o.label || o.value;
         this.value = o.value;
         this.query = query;
+        this.data = data;
     }
 
-    get lenth () {
+    get lenth() {
         return this.label.length;
     }
 
-    toString () {
-        return '' + this.label;
+    toString() {
+        return `${this.label}`;
     }
 
-    valueOf () {
+    valueOf() {
         return this.toString();
     }
 }