diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index 5b3725d63f..03f42493a2 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -385,6 +385,22 @@ function getCaretPosition(txtarea) { } (function($) { + 'use strict'; + + /** + * Mentions data returned from ajax requests + * @typedef {Object} MentionsData + * @property {string} name User/group name + * @property {string} id User/group ID + * @property {{img: string, group: string}} avatar Avatar data + * @property {string} rank User rank or empty string for groups + * @property {number} priority Priority of data entry + */ + + /** + * Mentions class + * @constructor + */ function Mentions() { let $mentionDataContainer = $('[data-mention-url]:first'); let mentionURL = $mentionDataContainer.data('mentionUrl'); @@ -396,10 +412,20 @@ function getCaretPosition(txtarea) { let cachedAll = []; let cachedSearchKey = 'name'; + /** + * Get default avatar + * @param {string} type Type of avatar; either group or user on any other value + * @returns {string} Default avatar svg code + */ function defaultAvatar(type) { return (type === 'group') ? '' : ''; } + /** + * Get cached keyword for query string + * @param {string} query Query string + * @returns {?string} Cached keyword if one fits query, else empty string if cached keywords exist, null if cached keywords do not exist + */ function getCachedKeyword(query) { if (!cachedNames) { return null; @@ -417,6 +443,13 @@ function getCaretPosition(txtarea) { return ''; } + /** + * Get names matching query + * @param {string} query Query string + * @param {Object.} items List of {@link MentionsData} items + * @param {string} searchKey Key to use for matching items + * @returns {Object.} List of {@link MentionsData} items filtered with query and by searchKey + */ function getMatchedNames(query, items, searchKey) { let i; let len; @@ -430,6 +463,11 @@ function getCaretPosition(txtarea) { return _results; } + /** + * atwho.js remoteFilter callback filter function + * @param {string} query Query string + * @param {function} callback Callback function for filtered items + */ function remoteFilter(query, callback) { /* * Do not make a new request until the previous one for the same query is returned @@ -448,7 +486,7 @@ function getCaretPosition(txtarea) { /* * Use cached values when we can: * 1) There are some names in the cache relevant for the query - * (cache for the query with the same first characters cointains some data) + * (cache for the query with the same first characters contains some data) * 2) We have enough names to display OR * all relevant names have been fetched from the server */ @@ -475,8 +513,8 @@ function getCaretPosition(txtarea) { return $mentionDataContainer.length; }; - this.handle = function(txtarea) { - $(txtarea).atwho({ + this.handle = function(textarea) { + $(textarea).atwho({ at: "@", acceptSpaceBar: true, displayTpl: function(data) {