diff options
author | Treer <treer.git@the-bordello.com> | 2016-04-30 21:36:19 +1000 |
---|---|---|
committer | Treer <treer.git@the-bordello.com> | 2016-04-30 21:36:19 +1000 |
commit | 45654ffc5cc4532c2189c88d46a0374038b53c9f (patch) | |
tree | fc1c9949dcabd360c120d318c9fe3181d47c8f42 /library/font_awesome/src/assets/js/search.js | |
parent | 931a4fafe316b23bacf92ac1ff35f9b8467415dd (diff) | |
download | volse-hubzilla-45654ffc5cc4532c2189c88d46a0374038b53c9f.tar.gz volse-hubzilla-45654ffc5cc4532c2189c88d46a0374038b53c9f.tar.bz2 volse-hubzilla-45654ffc5cc4532c2189c88d46a0374038b53c9f.zip |
update font-awesome library to 4.6.1
Perhaps this should be done as a submodule instead?
Diffstat (limited to 'library/font_awesome/src/assets/js/search.js')
-rw-r--r-- | library/font_awesome/src/assets/js/search.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/library/font_awesome/src/assets/js/search.js b/library/font_awesome/src/assets/js/search.js new file mode 100644 index 000000000..1c4d447f1 --- /dev/null +++ b/library/font_awesome/src/assets/js/search.js @@ -0,0 +1,92 @@ +$(function() { + var SearchView = Backbone.View.extend({ + events: { + "click #search-clear": "clear" + }, + + initialize: function() { + this.algolia = algoliasearch("M19DXW5X0Q", "c79b2e61519372a99fa5890db070064c"); + this.algoliaHelper = algoliasearchHelper(this.algolia, "font_awesome"); + this.template = _.template($("#results-template").html()); + + this.$searchInput = this.$("#search-input"); + this.$searchResultsSection = this.$("#search-results"); + this.$searchInputClear = this.$("#search-clear"); + this.$iconsSection = this.$("#icons"); + + this.$searchInput.on("keyup", _.debounce(_.bind(this.search, this), 200)); + this.algoliaHelper.on("result", _.bind(this.showResults, this)); + }, + + search: function(event) { + var query = this.$searchInput.val(); + + if (query !== "") { + this. algoliaHelper.setQuery(query).search(); + } else { + this.clearResults(); + } + }, + + clear: function(event) { + event.preventDefault(); + + this.clearResults(); + }, + + showResults: function(content, state) { + this.$searchResultsSection.html(""); + this.$searchResultsSection.removeClass("hide"); + this.$searchInputClear.removeClass("hide"); + this.$iconsSection.addClass("hide"); + + var results = []; + + _.each(content.hits, function(result) { + results.push(new SearchResultView({ result: result }).render()) + }); + + this.$searchResultsSection.html(this.template({ content: content, results: results.join("") })); + }, + + clearResults: function() { + this.$searchInput.val("").focus(); + this.$searchResultsSection.addClass("hide"); + this.$searchResultsSection.html(""); + this.$searchInputClear.addClass("hide"); + this.$iconsSection.removeClass("hide"); + } + }); + + var SearchResultView = Backbone.View.extend({ + initialize: function(options) { + this.template = _.template($("#result-template").html()); + this.result = options.result + }, + + render: function() { + var matches = []; + + this.pullMatches(matches, this.result._highlightResult.aliases); + this.pullMatches(matches, this.result._highlightResult.synonyms); + + return this.template({ result: this.result, matches: matches }); + }, + + pullMatches: function(matches, list) { + if (list !== undefined) { + _.each(list, function(highlight) { + if (highlight.matchLevel !== "none") { + matches.push(highlight.value) + } + }) + } + } + }); + + var $searchViewElement = $("[data-view=search]"); + + if ($searchViewElement.length > 0) { + new SearchView({ el: $searchViewElement }); + } +}); |