From c94fb32c7a3c28b18a27460aa2447eeec1fac1de Mon Sep 17 00:00:00 2001 From: Pascal Szewczyk Date: Mon, 18 Jul 2016 23:23:54 +0200 Subject: uikit added --- js/components/search.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 js/components/search.js (limited to 'js/components/search.js') diff --git a/js/components/search.js b/js/components/search.js new file mode 100755 index 0000000..6f8a46e --- /dev/null +++ b/js/components/search.js @@ -0,0 +1,92 @@ +/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ +(function(addon) { + + var component; + + if (window.UIkit) { + component = addon(UIkit); + } + + if (typeof define == "function" && define.amd) { + define("uikit-search", ["uikit"], function(){ + return component || addon(UIkit); + }); + } + +})(function(UI){ + + "use strict"; + + UI.component('search', { + defaults: { + msgResultsHeader : 'Search Results', + msgMoreResults : 'More Results', + msgNoResults : 'No results found', + template : '', + + renderer: function(data) { + + var opts = this.options; + + this.dropdown.append(this.template({"items":data.results || [], "msgResultsHeader":opts.msgResultsHeader, "msgMoreResults": opts.msgMoreResults, "msgNoResults": opts.msgNoResults})); + this.show(); + } + }, + + boot: function() { + + // init code + UI.$html.on("focus.search.uikit", "[data-uk-search]", function(e) { + var ele =UI.$(this); + + if (!ele.data("search")) { + UI.search(ele, UI.Utils.options(ele.attr("data-uk-search"))); + } + }); + }, + + 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(){ + $this.element[$this.autocomplete.input.val() ? "addClass":"removeClass"]("uk-active"); + }).closest("form").on("reset", function(){ + $this.value=""; + $this.element.removeClass("uk-active"); + }); + + 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(); + } + }); + + this.element.data("search", this); + } + }); +}); -- cgit v1.2.3