*/
_mentionStart: '',
+ /**
+ * delay timer to only send requests after user paused typing
+ * @var WCF.PeriodicalExecuter
+ */
+ _timer: null,
+
/**
* Initalizes user suggestions for the CKEditor with the given textarea id.
*
}
this._textarea = $('#' + editorID);
+ this._timer = null;
// get associated (ready) CKEditor object and add event listeners
CKEDITOR.on('instanceReady', $.proxy(function(event) {
}, this));
this._proxy = new WCF.Action.Proxy({
+ autoAbortPrevious: true,
success: $.proxy(this._success, this)
});
},
}
if (this._dropdownMenu.is(':visible')) {
- if (event.data.keyCode === 13) { // enter
- this._dropdownMenu.children('li').eq(this._itemIndex).trigger('click');
+ if (event.data.keyCode === $.ui.keyCode.ENTER) {
+ var $itemIndex = this._itemIndex;
+ this._hideList();
+
+ this._dropdownMenu.children('li').eq($itemIndex).trigger('click');
event.cancel();
}
}
+ else if (event.data.keyCode === $.ui.keyCode.ENTER || event.data.keyCode === $.ui.keyCode.HOME || event.data.keyCode === $.ui.keyCode.PAGE_DOWN || event.data.keyCode === $.ui.keyCode.PAGE_UP || event.data.keyCode === $.ui.keyCode.DOWN || event.data.keyCode === $.ui.keyCode.UP) {
+ // line change, thus abort searches from previous line
+ this._proxy.abortPrevious();
+ if (this._timer !== null) {
+ this._timer.stop();
+ this._timer = null;
+ }
+ }
},
/**
if (!$match.index || $currentText[$match.index - 1].match(/\s/)) {
this._mentionStart = $match[1];
- this._proxy.setOption('data', {
- actionName: 'getSearchResultList',
- className: this._className,
- interfaceName: 'wcf\\data\\ISearchAction',
- parameters: this._getParameters()
- });
- this._proxy.sendRequest();
+ if (this._timer !== null) {
+ this._timer.stop();
+ }
+
+ this._timer = new WCF.PeriodicalExecuter($.proxy(function() {
+ this._proxy.setOption('data', {
+ actionName: 'getSearchResultList',
+ className: this._className,
+ interfaceName: 'wcf\\data\\ISearchAction',
+ parameters: this._getParameters()
+ });
+ this._proxy.sendRequest();
+
+ this._timer.stop();
+ this._timer = null;
+ }, this), 500);
}
}
else {
* Replaces the started mentioning with a chosen username.
*/
_setUsername: function(username) {
+ this._proxy.abortPrevious();
+
var $range = this._ckEditor.getSelection().getRanges()[0];
// remove the beginning of the username and the '@'
$range.selectNodeContents($usernameNode);
$range.collapse(false);
$range.select();
-
+
this._hideList();
},