2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-14 03:05:43 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-14 03:05:43 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-02-02 20:16:09 +01:00
|
|
|
function TextSearchFacet(div, config, options) {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._div = div;
|
|
|
|
this._config = config;
|
2017-11-14 14:51:42 +01:00
|
|
|
if (!("invert" in this._config)) {
|
|
|
|
this._config.invert = false;
|
|
|
|
}
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
this._options = options;
|
|
|
|
|
|
|
|
this._query = config.query || null;
|
|
|
|
this._timerID = null;
|
|
|
|
|
|
|
|
this._initializeUI();
|
2017-11-14 14:51:42 +01:00
|
|
|
this._update();
|
2010-02-02 20:16:09 +01:00
|
|
|
}
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
TextSearchFacet.reconstruct = function(div, uiState) {
|
2011-08-14 03:05:43 +02:00
|
|
|
return new TextSearchFacet(div, uiState.c, uiState.o);
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
2010-04-17 08:58:30 +02:00
|
|
|
TextSearchFacet.prototype.dispose = function() {
|
|
|
|
};
|
|
|
|
|
2010-03-23 19:53:29 +01:00
|
|
|
TextSearchFacet.prototype.reset = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._query = null;
|
|
|
|
this._div.find(".input-container input").each(function() { this.value = ""; });
|
2010-03-23 19:53:29 +01:00
|
|
|
};
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
TextSearchFacet.prototype.getUIState = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var json = {
|
|
|
|
c: this.getJSON(),
|
|
|
|
o: this._options
|
|
|
|
};
|
|
|
|
|
|
|
|
return json;
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
2010-02-02 20:16:09 +01:00
|
|
|
TextSearchFacet.prototype.getJSON = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var o = {
|
|
|
|
type: "text",
|
|
|
|
name: this._config.name,
|
|
|
|
columnName: this._config.columnName,
|
|
|
|
mode: this._config.mode,
|
|
|
|
caseSensitive: this._config.caseSensitive,
|
2017-11-14 14:51:42 +01:00
|
|
|
invert: this._config.invert,
|
2011-08-14 03:05:43 +02:00
|
|
|
query: this._query
|
|
|
|
};
|
|
|
|
return o;
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.hasSelection = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
return this._query !== null;
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._initializeUI = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
this._div.empty().show().html(
|
2017-11-14 14:51:42 +01:00
|
|
|
'<div class="facet-title" bind="facetTitle">' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'<div class="grid-layout layout-tightest layout-full"><table><tr>' +
|
2013-07-05 09:30:37 +02:00
|
|
|
'<td width="1%"><a href="javascript:{}" title="'+$.i18n._('core-facets')["remove-facet"]+'" class="facet-title-remove" bind="removeButton"> </a></td>' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'<td>' +
|
2017-11-14 14:51:42 +01:00
|
|
|
'<a href="javascript:{}" class="facet-choice-link" bind="resetButton">'+$.i18n._('core-facets')["reset"]+'</a>' +
|
|
|
|
'<a href="javascript:{}" class="facet-choice-link" bind="invertButton">'+$.i18n._('core-facets')["invert"]+'</a>' +
|
|
|
|
'<span bind="titleSpan"></span>' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'</td>' +
|
|
|
|
'</tr></table></div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="facet-text-body"><div class="grid-layout layout-tightest layout-full"><table>' +
|
|
|
|
'<tr><td colspan="4"><div class="input-container"><input bind="input" /></div></td></tr>' +
|
|
|
|
'<tr>' +
|
2016-09-19 15:03:30 +02:00
|
|
|
'<td width="1%"><input type="checkbox" bind="caseSensitiveCheckbox" id="caseSensitiveCheckbox" /></td><td><label for="caseSensitiveCheckbox">'+$.i18n._('core-facets')["case-sensitive"]+'</label></td>' +
|
|
|
|
'<td width="1%"><input type="checkbox" bind="regexCheckbox" id="regexCheckbox" /></td><td><label for="regexCheckbox">'+$.i18n._('core-facets')["regular-exp"]+'</label></td>' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'</tr>' +
|
|
|
|
'</table></div></div>'
|
|
|
|
);
|
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts = DOM.bind(this._div);
|
2011-08-14 03:05:43 +02:00
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.titleSpan.text(this._config.name);
|
2011-08-14 03:05:43 +02:00
|
|
|
if (this._config.caseSensitive) {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.caseSensitiveCheckbox.attr("checked", "true");
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
2017-11-15 19:31:41 +01:00
|
|
|
if (this._config.mode === "regex") {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.regexCheckbox.attr("checked", "true");
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.removeButton.click(function() { self._remove(); });
|
|
|
|
this._elmts.resetButton.click(function() { self._reset(); });
|
|
|
|
this._elmts.invertButton.click(function() { self._invert(); });
|
2011-08-14 03:05:43 +02:00
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.caseSensitiveCheckbox.bind("change", function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
self._config.caseSensitive = this.checked;
|
|
|
|
if (self._query !== null && self._query.length > 0) {
|
|
|
|
self._scheduleUpdate();
|
2010-03-23 00:01:53 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
});
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.regexCheckbox.bind("change", function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
self._config.mode = this.checked ? "regex" : "text";
|
|
|
|
if (self._query !== null && self._query.length > 0) {
|
|
|
|
self._scheduleUpdate();
|
2010-03-23 00:01:53 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this._query) {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.input[0].value = this._query;
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
2013-06-23 19:37:29 +02:00
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.input.bind("keyup change input",function(evt) {
|
2015-04-18 21:48:35 +02:00
|
|
|
// Ignore non-character keyup changes
|
|
|
|
if(evt.type === "keyup" && (this.value === self._query || this.value === '' && !self._query)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
self._query = this.value;
|
|
|
|
self._scheduleUpdate();
|
|
|
|
}).focus();
|
2013-06-23 19:37:29 +02:00
|
|
|
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.updateState = function(data) {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._update();
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.render = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._setRangeIndicators();
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._reset = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._query = null;
|
2017-11-14 15:37:16 +01:00
|
|
|
this._config.mode = "text";
|
|
|
|
this._config.caseSensitive = false;
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.input.val([]);
|
|
|
|
this._elmts.caseSensitiveCheckbox.prop("checked", false);
|
|
|
|
this._elmts.regexCheckbox.prop("checked", false);
|
|
|
|
this._config.invert = false;
|
|
|
|
|
|
|
|
this._updateRest();
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._invert = function() {
|
|
|
|
this._config.invert = !this._config.invert;
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
this._updateRest();
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._remove = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
ui.browsingEngine.removeFacet(this);
|
|
|
|
|
|
|
|
this._div = null;
|
|
|
|
this._config = null;
|
|
|
|
this._options = null;
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
2017-11-14 14:51:42 +01:00
|
|
|
TextSearchFacet.prototype._update = function () {
|
|
|
|
var invert = this._config.invert;
|
|
|
|
if (invert) {
|
|
|
|
this._elmts.facetTitle.addClass("facet-title-inverted");
|
|
|
|
this._elmts.invertButton.addClass("facet-mode-inverted");
|
|
|
|
} else {
|
|
|
|
this._elmts.facetTitle.removeClass("facet-title-inverted");
|
|
|
|
this._elmts.invertButton.removeClass("facet-mode-inverted");
|
|
|
|
}
|
2017-11-15 19:31:41 +01:00
|
|
|
};
|
2017-11-14 14:51:42 +01:00
|
|
|
|
2010-02-02 20:16:09 +01:00
|
|
|
TextSearchFacet.prototype._scheduleUpdate = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
if (!this._timerID) {
|
|
|
|
var self = this;
|
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self._updateRest();
|
|
|
|
}, 500);
|
|
|
|
}
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._updateRest = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
Refine.update({ engineChanged: true });
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|