Sha256: 4f31f70697b4f66f0adb54d7b0523dfbc62773fe4162df7584bc7ad4c3ce570d

Contents?: true

Size: 1.95 KB

Versions: 17

Compression:

Stored size: 1.95 KB

Contents

$(function(){
  var $typeahead = $('[data-typeahead]');
  var $form = $typeahead.parents('form');
  var searchURL = $form.attr('action');

  function displayTemplate(result) {
    return result.name;
  }

  function suggestionTemplate(result) {
    var t = '<div class="list-group-item clearfix">';
    t += '<span class="doc-name">' + result.name + '</span>';
    if (result.parent_name) {
     t += '<span class="doc-parent-name label">' + result.parent_name + '</span>';
    }
    t += '</div>';
    return t;
  }

  $typeahead.one('focus', function() {
    $form.addClass('loading');

    $.getJSON(searchURL).then(function(searchData) {
      const searchIndex = lunr(function() {
        this.ref('url');
        this.field('name');
        this.field('abstract');
        for (const [url, doc] of Object.entries(searchData)) {
          this.add({url: url, name: doc.name, abstract: doc.abstract});
        }
      });

      $typeahead.typeahead(
        {
          highlight: true,
          minLength: 3,
          autoselect: true
        },
        {
          limit: 10,
          display: displayTemplate,
          templates: { suggestion: suggestionTemplate },
          source: function(query, sync) {
            const lcSearch = query.toLowerCase();
            const results = searchIndex.query(function(q) {
                q.term(lcSearch, { boost: 100 });
                q.term(lcSearch, {
                  boost: 10,
                  wildcard: lunr.Query.wildcard.TRAILING
                });
            }).map(function(result) {
              var doc = searchData[result.ref];
              doc.url = result.ref;
              return doc;
            });
            sync(results);
          }
        }
      );
      $form.removeClass('loading');
      $typeahead.trigger('focus');
    });
  });

  var baseURL = searchURL.slice(0, -"search.json".length);

  $typeahead.on('typeahead:select', function(e, result) {
    window.location = baseURL + result.url;
  });
});

Version data entries

17 entries across 14 versions & 1 rubygems

Version Path
jazzy-0.13.7 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.7 lib/jazzy/themes/apple/assets/js/jazzy.search.js
jazzy-0.13.6 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.6 lib/jazzy/themes/apple/assets/js/jazzy.search.js
jazzy-0.13.5 lib/jazzy/themes/apple/assets/js/jazzy.search.js
jazzy-0.13.5 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.4 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.3 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.2 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.1 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.13.0 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.12.0 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.11.2 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.11.1 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.11.0 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.10.0 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js
jazzy-0.9.6 lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js