Merge branch 'updated-search'

This commit is contained in:
Travis Chase 2015-09-01 13:49:13 -05:00
commit 54cb358b02
15 changed files with 227 additions and 144 deletions

View file

@ -59,5 +59,6 @@ PLATFORMS
DEPENDENCIES
jekyll (~> 1.0)
less (~> 2.5.0)
safe_yaml (~> 1.0.4)
sass (~> 3.0)
therubyracer

View file

@ -1,30 +0,0 @@
<div class="filter-parent" id="search">
<label for="filter-by"><i class="fa fa-search"></i></label>
<input placeholder="Search icons" id="filter-by" class="form-control input-lg" tabindex="1">
<a href="#" id="filter-clear" class="fa fa-times"></a>
</div>
<script>
try {
window.filterSet = JSON.parse('{{ icons | flattenIconFilters | jsonify }}');
} catch (e) {
console.error('Invalid JSON data!');
window.filterSet = [];
}
</script>
<section id="filter">
<h2 class="page-header text-muted">Search for '<span class="text-color-default" id="filter-val"></span>'</h2>
<div class="row fontawesome-icon-list">
{% for icon in icons %}
<div class="fa-hover col-md-3 col-sm-4 filter-icon"
data-filter="{{ icon.class }}{% for alias in icon.aliases %}|{{ alias }}{% endfor %}{% for filter in icon.filter %}|{{ filter }}{% endfor %}">
<a href="{{ page.relative_path }}icon/{{ icon.id }}"><i class="fa fa-{{ icon.class }}"></i> {{ icon.class }}{% if icon.alias_of %} <span class="text-muted">(alias)</span>{% endif %}</a>
</div>
{% endfor %}
</div>
<div id="no-search-results">
<div class="alert alert-warning" role="alert"><i class="fa fa-warning margin-right-sm"></i>No icons matching <strong>'<span></span>'</strong> were found.</div>
</div>
<div class="alert alert-info" role="alert"><i class="fa fa-exclamation-circle margin-right-sm"></i>Tags are added by the community. Do you think your search query should return an icon? Send a pull request on <a href="https://github.com/FortAwesome/Font-Awesome/blob/master/CONTRIBUTING.md#suggesting-icon-keyword-additionremoval">GitHub</a>!</div>
</section>

View file

@ -19,7 +19,7 @@
<span class="sr-only">Toggle navigation</span>
<i class="fa fa-bars fa-lg"></i>
</button>
<a class="navbar-brand" href="{{ page.relative_path }}"><i class="fae fae-logo"></i></a>
<a class="navbar-brand" href="{{ page.relative_path }}"><i class="fas fas-logo"></i></a>
</div>
<div class="navbar-collapse collapse">

View file

@ -59,7 +59,11 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/{{ site.jquery.version }}/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/{{ site.jquery_validate.version }}/jquery.validate.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/{{ site.bootstrap.version }}/js/bootstrap.min.js"></script>
<script src="{{ page.relative_path}}assets/js/tabcomplete.min.js"></script>
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
<script src="https://cdn.jsdelivr.net/algoliasearch.helper/2/algoliasearch.helper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.2/backbone-min.js"></script>
<script src="{{ page.relative_path }}assets/js/site.js"></script>
<script src="{{ page.relative_path }}assets/js/search.js"></script>
</body>
</html>

BIN
src/assets/img/algolia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

92
src/assets/js/search.js Normal file
View file

@ -0,0 +1,92 @@
$(function() {
var SearchView = Backbone.View.extend({
events: {
"keyup #search-input": "search",
"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.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 });
}
});

View file

@ -1,4 +1,4 @@
$(function() {
$(function () {
$("#newsletter").validate();
var ads = [
@ -28,7 +28,6 @@ $(function() {
},
{
quote: "<strong>Black Tie</strong>, from the creator of Font Awesome. On sale at the Kickstarter price for a limited time.",
class: "black-tie",
@ -40,6 +39,18 @@ $(function() {
class: "black-tie",
url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_5_clean_minimalist&utm_campaign=promo_4.4_update",
btn_text: "Check it Out!"
},
{
quote: "Want a different icon look? Check out <strong>Black Tie</strong>, our new multi-weight icon set.",
class: "black-tie",
url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_6_different_look&utm_campaign=promo_4.4_update",
btn_text: "Check it Out!"
},
{
quote: "Check out <strong>Black Tie</strong>, our new multi-weight icon set!",
class: "black-tie",
url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_7_our_new_multi_weight&utm_campaign=promo_4.4_update",
btn_text: "Check it Out!"
}
];
@ -52,87 +63,8 @@ $(function() {
$('[data-toggle="popover"]').popover();
var $filter_by = $('#filter-by');
// Filter icons
if($filter_by.length) {
var $filter_val = $('#filter-val');
var $filter = $('#filter');
var $other = $('#new, #web-application, #hand, #transportation, #gender, #form-control, #medical, #currency, #text-editor, #directional, #video-player, #brand, #file-type, #spinner, #payment, #chart');
var $clear = $('#filter-clear');
var $no_results = $('#no-search-results');
var $icons = $('.filter-icon', $filter);
// Add tab completion
$filter_by.tabcomplete(filterSet, {
arrowKeys: true
});
$clear.on('click', function(e) {
e.preventDefault();
$filter_by
.val('')
.trigger('input')
.trigger('keyup')
.focus();
$clear.addClass('hide'); // Hide clear button
});
$filter_by.on('keyup', function() {
var $this = $(this);
var val = $this.val().toLowerCase();
$filter.toggle(!!val);
$other.toggle(!val);
$clear.toggleClass('hide', !val);
$filter_val.text(val);
if(!val) return;
var resultsCount = 0;
$icons.each(function() {
var filter = $(this).attr('data-filter').split('|');
var show = inFilter(val, filter);
if (!show) {
if (val.slice(-1) === 's') {
// Try to be smart. Make plural terms singular.
show = inFilter(val.slice(0, -1), filter);
}
}
if (show) resultsCount++;
$(this).toggle(!!show);
});
if( resultsCount == 0 && val.length != 0 ) {
$no_results.find('span').text(val);
$no_results.show();
} else {
$no_results.hide();
}
});
}
function inFilter(val, filter) {
for (var i = 0; i < filter.length; i++) {
if (filter[i].match(val)) return true;
}
return false;
}
$filter_by
.val('')
.trigger('input')
.trigger('keyup')
.focus();
if ($clear) {
$clear.addClass('hide'); // Hide clear button
}
function selectFonticonsAd() {
random_number = Math.floor( Math.random() * ads.length );
random_number = Math.floor(Math.random() * ads.length);
random_ad = ads[random_number];
$('#banner').addClass(random_ad.class);

View file

@ -1,6 +0,0 @@
/*!
* tabcomplete
* http://github.com/erming/tabcomplete
* v1.4.1
*/
!function(a){function b(b,c,d){return a.grep(c,function(a){return d?!a.indexOf(b):!a.toLowerCase().indexOf(b.toLowerCase())})}function c(b){var c=this,d=c.prev(".hint");c.css({backgroundColor:"transparent",position:"relative"}),d.length||(c.options.wrapInput&&c.wrap(a("<div>").css({position:"relative",height:c.css("height"),display:c.css("display")})),d=c.clone().attr("tabindex",-1).removeAttr("id name placeholder").addClass("hint").insertBefore(c),d.css({position:"absolute"}));var e="";if("undefined"!=typeof b){var f=c.val();e=f+b.substr(f.split(/ |\n/).pop().length)}d.val(e)}function d(a){var b=this,c=b.val();a&&(b.val(c+a.substr(c.split(/ |\n/).pop().length)),b[0].selectionStart=c.length)}var e={backspace:8,tab:9,up:38,down:40};a.tabcomplete={},a.tabcomplete.defaultOptions={after:"",arrowKeys:!1,hint:"placeholder",match:b,caseSensitive:!1,minLength:1,wrapInput:!0},a.fn.tab=a.fn.tabcomplete=function(b,f){if(this.length>1)return this.each(function(){a(this).tabcomplete(b,f)});var g=this.prop("tagName");if("INPUT"==g||"TEXTAREA"==g){this.options=f=a.extend(a.tabcomplete.defaultOptions,f),this.unbind(".tabcomplete"),this.prev(".hint").remove();var h=this,i=!1,j=-1,k=[],l="",m=a.noop;switch(f.hint){case"placeholder":m=c;break;case"select":m=d}return this.on("input.tabcomplete",function(){var c=h.val(),d=c.split(/ |\n/).pop();j=-1,l="",k=[],h[0].selectionStart==c.length&&d.length&&(k=f.match(d,b,f.caseSensitive),f.after&&(k=a.map(k,function(a){return a+f.after}))),h.trigger("match",k.length),f.hint&&(("select"!=f.hint||!i)&&d.length>=f.minLength?m.call(h,k[0]):m.call(h,"")),i&&(i=!1)}),this.on("keydown.tabcomplete",function(a){var b=a.which;if(b==e.tab||f.arrowKeys&&(b==e.up||b==e.down)){if(a.preventDefault(),b!=e.up)j++;else{if(-1==j)return;0==j?j=k.length-1:j--}var c=k[j%k.length];if(!c)return;var d=h.val();if(l=l||d.split(/ |\n/).pop(),l.length<f.minLength)return;var g="select"==f.hint?d:d.substr(0,h[0].selectionStart-l.length)+c;h.val(g),"select"==f.hint&&(h[0].selectionStart=g.length),l=c,h.trigger("tabcomplete",l),f.hint&&m.call(h,"")}else a.which==e.backspace&&(i=!0,j=-1,l="")}),f.hint&&m.call(this,""),this}}}(jQuery);

View file

@ -8,6 +8,7 @@
@import "site/bootstrap/jumbotron";
@import "site/bootstrap/wells";
@import "site/bootstrap/type";
@import "site/bootstrap/alerts";
@import "site/bootstrap/modals";
@import "site/layout";
@ -25,6 +26,7 @@
@import "site/fusion-ad";
@import "site/bsap-ad";
@import "site/sumome";
@import "site/algolia";
@import "site/responsive/screen-lg";
@import "site/responsive/screen-md";

View file

@ -0,0 +1,12 @@
.algolia {
margin-top: -20px;
padding-top: 49px;
a {
color: @text-color;
&:hover { color: @link-hover-color; }
}
.fas-algolia {
font-size: 32px;
vertical-align: middle;
}
}

View file

@ -0,0 +1 @@
.alert-link { text-decoration: underline; }

View file

@ -107,6 +107,10 @@
@state-info-bg: @blue-lighter;
@state-info-border: darken(spin(@state-info-bg, -10), 7%);
@state-danger-text: @brand-danger;
@state-danger-bg: mix(@state-danger-text,#fff,10%);
@state-danger-border: darken(spin(@state-danger-bg, -10), 5%);
// Carousel
@carousel-text-shadow: 0 1px 0 rgba(255,255,255,0.25);

View file

@ -2,6 +2,7 @@
margin-top: 22px;
.fa-hover {
a {
.text-ellipsis;
display: block;
color: @gray-darker;
line-height: 32px;

View file

@ -1,25 +1,40 @@
.filter-parent {
#search {
position: relative;
font-size: 18px;
padding-top: 40px;
margin: -20px auto 50px;
margin: -20px auto 0px;
label {
position: absolute;
left: 17px;
top: 50px;
top: 51px;
}
#filter-by, .hint {
#search-input, .hint {
padding-left: 43px;
padding-right: 43px;
border-radius: 23px;
}
.hint {
color: #aaa;
}
#filter-clear {
#search-clear {
text-decoration: none;
position: absolute;
right: 18px;
top: 53px;
top: 54px;
color: @text-muted;
&:hover {
color: mix(#000, @text-muted, 20%);
}
}
}
#search-results {
em {
font-style: normal;
text-decoration: underline;
}
}

View file

@ -10,7 +10,7 @@ relative_path: ../
{% include jumbotron.html %}
{% include stripe-social.html %}
<div class="container">
<div class="container" data-view="search">
{% capture stripe_ad_content %}
<p class="lead">
You asked, Font Awesome delivers with {{ icons | version:site.fontawesome.minor_version | size }} shiny new icons in version {{ site.fontawesome.minor_version }}.
@ -21,22 +21,77 @@ relative_path: ../
{% endcapture %}
{% include stripe-ad.html %}
{% include icons/filter.html %}
<div class="row">
<div class="col-md-10 col-sm-9">
<section id="search">
<label for="search-input"><i class="fa fa-search"></i></label>
<input id="search-input" class="form-control input-lg" placeholder="Search icons" autocomplete="off" spellcheck="false" autocorrect="off" tabindex="1">
<a id="search-clear" href="#" class="fa fa-times-circle hide"></a>
</section>
</div>
<div class="col-md-2 col-sm-3 padding-left-none hidden-xs">
<div class="algolia">
by <a href="https://algolia.com"><i class="fas fas-algolia"></i></a>
</div>
</div>
</div>
{% include icons/new.html %}
{% include icons/web-application.html %}
{% include icons/hand.html %}
{% include icons/transportation.html %}
{% include icons/gender.html %}
{% include icons/file-type.html %}
{% include icons/spinner.html %}
{% include icons/form-control.html %}
{% include icons/payment.html %}
{% include icons/chart.html %}
{% include icons/currency.html %}
{% include icons/text-editor.html %}
{% include icons/directional.html %}
{% include icons/video-player.html %}
{% include icons/brand.html %}
{% include icons/medical.html %}
<div id="search-results" class="hide"></div>
<div id="icons">
{% include icons/new.html %}
{% include icons/web-application.html %}
{% include icons/hand.html %}
{% include icons/transportation.html %}
{% include icons/gender.html %}
{% include icons/file-type.html %}
{% include icons/spinner.html %}
{% include icons/form-control.html %}
{% include icons/payment.html %}
{% include icons/chart.html %}
{% include icons/currency.html %}
{% include icons/text-editor.html %}
{% include icons/directional.html %}
{% include icons/video-player.html %}
{% include icons/brand.html %}
{% include icons/medical.html %}
</div>
<script type="text/template" id="results-template">
<h2 class="page-header">Search for '<span class="text-color-default"><%= content.query %></span>'</h2>
<% if (content.nbHits > 0) { %>
<div class="row fontawesome-icon-list">
<%= results %>
</div>
<% } else { %>
<div class="alert alert-danger text-lg" role="alert">
<h3 class="margin-top margin-bottom-lg"><i class="fa fa-meh-o"></i> Oops! No icons matched your query.</h3>
A few things that might help:
<ol>
<li>
Use <a class="alert-link" href="https://fonticons.com">Fonticons</a> (our latest project) to add your
own icons and take your icon game to the next level!
</li>
<li>
Really, really want to see an icon in Font Awesome?
<a class="alert-link" href="mailto:dave@fonticons.com">Drop me an email</a> to commission the icons you need!
</li>
<li>
Are we missing something in our search results?
<a class="alert-link" href="https://github.com/FortAwesome/Font-Awesome/issues/new">Open an issue on GitHub!</a>
(Make sure to <a class="alert-link" href="https://github.com/FortAwesome/Font-Awesome/issues">search existing
issues first</a>.)
</li>
</ol>
</div>
<% } %>
</script>
<script type="text/template" id="result-template">
<div class="fa-hover col-md-3 col-sm-4">
<a href="{{ page.relative_path }}icon/<%= result.name %>">
<i class="fa <%= result.css_class %>"></i> <%= result._highlightResult.name.value %>
<% if (matches.length > 0) { %>
<span class="text-muted">(<%= matches.join(", ") %>)</span>
<% } %>
</a>
</div>
</script>
</div>