2019-04-23 20:47:55 +00:00
|
|
|
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2015-11-30 21:30:54 +00:00
|
|
|
(function(addon) {
|
|
|
|
|
|
|
|
var component;
|
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
if (window.UIkit2) {
|
|
|
|
component = addon(UIkit2);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
if (typeof define == 'function' && define.amd) {
|
|
|
|
define('uikit-search', ['uikit'], function(){
|
|
|
|
return component || addon(UIkit2);
|
2015-11-30 21:30:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
})(function(UI){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
UI.component('search', {
|
|
|
|
defaults: {
|
|
|
|
msgResultsHeader : 'Search Results',
|
|
|
|
msgMoreResults : 'More Results',
|
|
|
|
msgNoResults : 'No results found',
|
|
|
|
template : '<ul class="uk-nav uk-nav-search uk-autocomplete-results">\
|
|
|
|
{{#msgResultsHeader}}<li class="uk-nav-header uk-skip">{{msgResultsHeader}}</li>{{/msgResultsHeader}}\
|
|
|
|
{{#items && items.length}}\
|
|
|
|
{{~items}}\
|
|
|
|
<li data-url="{{!$item.url}}">\
|
|
|
|
<a href="{{!$item.url}}">\
|
|
|
|
{{{$item.title}}}\
|
|
|
|
{{#$item.text}}<div>{{{$item.text}}}</div>{{/$item.text}}\
|
|
|
|
</a>\
|
|
|
|
</li>\
|
|
|
|
{{/items}}\
|
|
|
|
{{#msgMoreResults}}\
|
|
|
|
<li class="uk-nav-divider uk-skip"></li>\
|
|
|
|
<li class="uk-search-moreresults" data-moreresults="true"><a href="#" onclick="jQuery(this).closest(\'form\').submit();">{{msgMoreResults}}</a></li>\
|
|
|
|
{{/msgMoreResults}}\
|
|
|
|
{{/end}}\
|
|
|
|
{{^items.length}}\
|
|
|
|
{{#msgNoResults}}<li class="uk-skip"><a>{{msgNoResults}}</a></li>{{/msgNoResults}}\
|
|
|
|
{{/end}}\
|
|
|
|
</ul>',
|
|
|
|
|
|
|
|
renderer: function(data) {
|
|
|
|
|
2016-03-13 02:51:59 +00:00
|
|
|
var opts = this.options;
|
2015-11-30 21:30:54 +00:00
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
this.dropdown.append(this.template({items:data.results || [], msgResultsHeader:opts.msgResultsHeader, msgMoreResults: opts.msgMoreResults, msgNoResults: opts.msgNoResults}));
|
2015-11-30 21:30:54 +00:00
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
boot: function() {
|
|
|
|
|
|
|
|
// init code
|
2018-03-03 16:43:27 +00:00
|
|
|
UI.$html.on('focus.search.uikit', '[data-uk-search]', function(e) {
|
2015-11-30 21:30:54 +00:00
|
|
|
var ele =UI.$(this);
|
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
if (!ele.data('search')) {
|
|
|
|
UI.search(ele, UI.Utils.options(ele.attr('data-uk-search')));
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
var $this = this;
|
|
|
|
|
|
|
|
this.autocomplete = UI.autocomplete(this.element, this.options);
|
|
|
|
|
|
|
|
this.autocomplete.dropdown.addClass('uk-dropdown-search');
|
|
|
|
|
|
|
|
this.autocomplete.input.on("keyup", function(){
|
2018-03-03 16:43:27 +00:00
|
|
|
$this.element[$this.autocomplete.input.val() ? 'addClass':'removeClass']('uk-active');
|
2015-11-30 21:30:54 +00:00
|
|
|
}).closest("form").on("reset", function(){
|
2018-03-03 16:43:27 +00:00
|
|
|
$this.value = '';
|
|
|
|
$this.element.removeClass('uk-active');
|
2015-11-30 21:30:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.on('selectitem.uk.autocomplete', function(e, data) {
|
|
|
|
if (data.url) {
|
|
|
|
location.href = data.url;
|
|
|
|
} else if(data.moreresults) {
|
|
|
|
$this.autocomplete.input.closest('form').submit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
this.element.data('search', this);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|