Commit 31a43028 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

TypeAhead.js: type ahead elements now must have .qfq-typeahead class in order...

TypeAhead.js: type ahead elements now must have .qfq-typeahead class in order to be configured. Streamlined data-* attribute names.
parent 7b9ced59
...@@ -24,7 +24,7 @@ var QfqNS = QfqNS || {}; ...@@ -24,7 +24,7 @@ var QfqNS = QfqNS || {};
*/ */
n.TypeAhead.install = function (typeahead_endpoint) { n.TypeAhead.install = function (typeahead_endpoint) {
$('.qfq-type-ahead').each(function () { $('.qfq-typeahead').each(function () {
var $element = $(this); var $element = $(this);
var suggestions = new Bloodhound({ var suggestions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('key', 'value'), datumTokenizer: Bloodhound.tokenizers.obj.whitespace('key', 'value'),
...@@ -48,6 +48,7 @@ var QfqNS = QfqNS || {}; ...@@ -48,6 +48,7 @@ var QfqNS = QfqNS || {};
{ {
display: 'value', display: 'value',
source: suggestions, source: suggestions,
limit: n.TypeAhead.getLimit($element),
templates: { templates: {
suggestion: function (obj) { suggestion: function (obj) {
return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>"; return "<div>" + n.TypeAhead.htmlEncode(obj.value) + "</div>";
...@@ -69,8 +70,12 @@ var QfqNS = QfqNS || {}; ...@@ -69,8 +70,12 @@ var QfqNS = QfqNS || {};
return endpoint + "?query=%QUERY" + "&sip=" + n.TypeAhead.getSip(element); return endpoint + "?query=%QUERY" + "&sip=" + n.TypeAhead.getSip(element);
}; };
n.TypeAhead.getLimit = function ($element) {
return $element.data('typeahead-limit');
};
n.TypeAhead.getSip = function ($element) { n.TypeAhead.getSip = function ($element) {
return $element.data('sip'); return $element.data('typeahead-sip');
}; };
n.TypeAhead.getName = function ($element) { n.TypeAhead.getName = function ($element) {
...@@ -82,15 +87,15 @@ var QfqNS = QfqNS || {}; ...@@ -82,15 +87,15 @@ var QfqNS = QfqNS || {};
}; };
n.TypeAhead.getMinLength = function ($element) { n.TypeAhead.getMinLength = function ($element) {
return $element.data('ta-min-length') || 2; return $element.data('typeahead-minlength') || 2;
}; };
n.TypeAhead.getHighlight = function ($element) { n.TypeAhead.getHighlight = function ($element) {
return $element.data('ta-higlight') || true; return $element.data('typeahead-highlight') || true;
}; };
n.TypeAhead.getHint = function ($element) { n.TypeAhead.getHint = function ($element) {
return $element.data('ta-hint') || true; return $element.data('typeahead-hint') || true;
}; };
n.TypeAhead.htmlEncode = function (value) { n.TypeAhead.htmlEncode = function (value) {
......
...@@ -88,8 +88,8 @@ ...@@ -88,8 +88,8 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<input id="dropdown1" type="text" class="form-control qfq-type-ahead" name="dropdown1" <input id="dropdown1" type="text" class="form-control qfq-typeahead" name="dropdown1"
data-sip="abcde" data-template="template1"> data-typeahead-sip="abcde" data-template="template1">
</div> </div>
</div> </div>
...@@ -100,8 +100,8 @@ ...@@ -100,8 +100,8 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<input id="dropdown2" type="text" class="form-control qfq-type-ahead" name="dropdown2" <input id="dropdown2" type="text" class="form-control qfq-typeahead" name="dropdown2"
data-sip="abcdef"> data-typeahead-sip="abcdef">
</div> </div>
</div> </div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment