Browse Source

Merge branch 'updated-search'

Travis Chase 10 years ago
parent
commit
54cb358b02

+ 1 - 0
Gemfile.lock

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

+ 0 - 30
src/_includes/icons/filter.html

@@ -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>

+ 1 - 1
src/_includes/navbar.html

@@ -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">

+ 5 - 1
src/_layouts/base.html

@@ -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


+ 92 - 0
src/assets/js/search.js

@@ -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 });
+    }
+});

+ 14 - 82
src/assets/js/site.js

@@ -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);

File diff suppressed because it is too large
+ 0 - 5
src/assets/js/tabcomplete.min.js


+ 2 - 0
src/assets/less/site.less

@@ -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";

+ 12 - 0
src/assets/less/site/algolia.less

@@ -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;
+  }
+}

+ 1 - 0
src/assets/less/site/bootstrap/alerts.less

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

+ 4 - 0
src/assets/less/site/bootstrap/variables.less

@@ -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);

+ 1 - 0
src/assets/less/site/fontawesome-icon-list.less

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

+ 21 - 6
src/assets/less/site/search.less

@@ -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;
   }
 }

+ 73 - 18
src/icons.html

@@ -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>

Some files were not shown because too many files changed in this diff