diff --git a/src/_includes/icons/filter.html b/src/_includes/icons/filter.html new file mode 100644 index 000000000..a41157963 --- /dev/null +++ b/src/_includes/icons/filter.html @@ -0,0 +1,36 @@ +
+ + + +
+ +<{% if page.navbar_active == "icons" %}div{% else %}section{% endif %} id="filter"> + + {% if page.navbar_active != "icons" %} +
+ You asked, Font Awesome delivers with {{ icons | version:site.fontawesome.minor_version | size }} shiny new icons in version {{ site.fontawesome.minor_version }}. + Want to request new icons? Here's how. +
+ {% endif %} + +
+ {% for icon in icons %} +
+ fa-{{ icon.class }}{% if icon.alias_of %} (alias){% endif %} +
+ {% endfor %} +
+
+ + +
+ + diff --git a/src/_layouts/base.html b/src/_layouts/base.html index 0552122c2..0cc5dc5ee 100644 --- a/src/_layouts/base.html +++ b/src/_layouts/base.html @@ -58,6 +58,7 @@ + diff --git a/src/_plugins/flatten_icon_filters.rb b/src/_plugins/flatten_icon_filters.rb new file mode 100644 index 000000000..1e3daff80 --- /dev/null +++ b/src/_plugins/flatten_icon_filters.rb @@ -0,0 +1,38 @@ +## +# Flattens the icons object to a one-dimensional array of possible search terms. + +require 'set' + +module Jekyll + module FlattenArray + def flattenIconFilters(icons) + flattened = Set.new + icons.each do |icon| + toAdd = [] + + toAdd.push(icon["class"].downcase) # Add class as a filter value + + # Add any existing aliases as a filter value + if not icon["aliases"].nil? + icon["aliases"].each do |iconAlias| + toAdd.push(iconAlias.downcase) + end + end + + # Add any existing filters as a filter value + if not icon["filter"].nil? + icon["filter"].each do |iconFilter| + toAdd.push(iconFilter.downcase) + end + end + flattened.merge(toAdd) + + print toAdd if toAdd.include? true + print toAdd if toAdd.include? false + end + return flattened.to_a # .to_a because we can't jsonify a + end + end +end + +Liquid::Template.register_filter(Jekyll::FlattenArray) diff --git a/src/assets/js/site.js b/src/assets/js/site.js index 731798048..38b6eb07b 100644 --- a/src/assets/js/site.js +++ b/src/assets/js/site.js @@ -3,4 +3,67 @@ $(function() { $('#icon-carousel').carousel({ interval: 5000 }); + + var $filter_by = $('#filter-by'); + + // Filter icons + if($filter_by.length) { + var $filter_val = $('#filter-val'); + var $filter = $('#filter'); + var $other = $('#new, #web-application, #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.click(function(e) { + e.preventDefault(); + $filter_by.val('').trigger('keyup').focus(); + }); + + + $filter_by.keyup(function() { + var $this = $(this); + var val = $this.val().toLowerCase(); + $filter.toggle(!!val); + $other.toggle(!val); + $clear.toggleClass('gone', !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(); + } + }).trigger('keyup'); + } + + function inFilter(val, filter) { + for (var i = 0; i < filter.length; i++) { + if (filter[i].match(val)) return true; + } + return false; + } }); diff --git a/src/assets/js/tabcomplete.min.js b/src/assets/js/tabcomplete.min.js new file mode 100644 index 000000000..f4c1fdf87 --- /dev/null +++ b/src/assets/js/tabcomplete.min.js @@ -0,0 +1,6 @@ +/*! + * 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("
").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