});
/**
+ * Handles the search area box.
*
+ * @param jQuery searchArea
*/
WCF.Search.Message.SearchArea = Class.extend({
+ /**
+ * search area object
+ * @var jQuery
+ */
_searchArea: null,
+ /**
+ * Initializes the WCF.Search.Message.SearchArea class.
+ *
+ * @param jQuery searchArea
+ */
init: function(searchArea) {
this._searchArea = searchArea;
- new WCF.Search.Message.KeywordList(this._searchArea.find('input[type=search]'), $.proxy(this._callback, this));
+ var $keywordList = new WCF.Search.Message.KeywordList(this._searchArea.find('input[type=search]'), $.proxy(this._callback, this));
+ $keywordList.setDelay(500);
// forward clicks on the search icon to input field
var self = this;
if (this._searchArea.hasClass('dropdown')) {
var $containerID = this._searchArea.wcfIdentify();
- var $form = this._searchArea.find('form').submit(function() {
+ var $form = this._searchArea.find('form');
+ $form.submit(function() {
+ // copy checkboxes and hidden fields into form
var $dropdownMenu = WCF.Dropdown.getDropdownMenu($containerID);
$dropdownMenu.find('input[type=hidden]').appendTo($form);
}
},
+ /**
+ * Callback for WCF.Search.Message.KeywordList.
+ *
+ * @param object data
+ * @return boolean
+ */
_callback: function(data) {
this._searchArea.find('input[type=search]').val(data.label);
this._searchArea.find('input[type=search]').focus();
*/
_commaSeperated: false,
+ /**
+ * delay in miliseconds before a request is send to the server
+ * @var integer
+ */
+ _delay: 0,
+
/**
* list with values that are excluded from seaching
* @var array
*/
_triggerLength: 3,
+ /**
+ * delay timer
+ * @var WCF.PeriodicalExecuter
+ */
+ _timer: null,
+
/**
* Initializes a new search.
*
}
this._callback = (callback) ? callback : null;
+ this._delay = 0;
this._excludedSearchValues = [];
if (excludedSearchValues) {
this._excludedSearchValues = excludedSearchValues;
}
};
- this._searchInput.parents('.searchBar').addClass('loading');
- this._proxy.setOption('data', {
- actionName: 'getSearchResultList',
- className: this._className,
- interfaceName: 'wcf\\data\\ISearchAction',
- parameters: this._getParameters($parameters)
- });
- this._proxy.sendRequest();
+ if (this._delay) {
+ if (this._timer !== null) {
+ this._timer.stop();
+ }
+
+ var self = this;
+ this._timer = new WCF.PeriodicalExecuter(function() {
+ self._queryServer($parameters);
+
+ self._timer.stop();
+ self._timer = null;
+ }, this._delay);
+ }
+ else {
+ this._queryServer($parameters);
+ }
}
else {
// input below trigger length
}
},
+ /**
+ * Queries the server.
+ *
+ * @param object parameters
+ */
+ _queryServer: function(parameters) {
+ this._searchInput.parents('.searchBar').addClass('loading');
+ this._proxy.setOption('data', {
+ actionName: 'getSearchResultList',
+ className: this._className,
+ interfaceName: 'wcf\\data\\ISearchAction',
+ parameters: this._getParameters(parameters)
+ });
+ this._proxy.sendRequest();
+ },
+
+ /**
+ * Sets query delay in miliseconds.
+ *
+ * @param integer delay
+ */
+ setDelay: function(delay) {
+ this._delay = delay;
+ },
+
/**
* Selects the next item in list.
*/