Backdrop_v1 Typeahead search

runningcoder typeahead demo backdrop_v1

by Tom Bertrand

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.rawgit.com/running-coder/jquery-typeahead/develop/src/jquery.typeahead.css">
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="https://cdn.rawgit.com/running-coder/jquery-typeahead/develop/src/jquery.typeahead.js"></script>
<nav class="navbar navbar-default navbar-static-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Contact</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="javascript:;" class="js-typeahead-toggle"><i class="fa fa-search"></i></a></li>
            </ul>

            <form>
                <div class="typeahead-container">
                    <div class="typeahead-header">

                        <div class="typeahead-field">
                            <div class="typeahead-backdrop-search-icon js-typeahead-submit">
                                <i class="fa fa-search"></i>
                            </div>
                            <div class="typeahead-query">
                    ...

CSS

.typeahead-container {
    position: absolute !important;
    top: -1000px;
}

.typeahead-container .typeahead-result-count,
.typeahead-container .typeahead-close,
.typeahead-container .typeahead-result-count,
.typeahead-container .typeahead-backdrop-search-icon {
    display: none;
}

.typeahead-container.backdrop {
    width: 100%;
    max-width: none;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.typeahead-container.backdrop input {
    color: #2a9dcc;
    /*background: transparent !important;*/
    border: 0;
    outline: none;
    font-size: 2rem;
    height: auto;
    /*border-bottom: 1px solid #777;*/
}

.typeahead-container.backdrop .typeahead-header {
    background-color: #f8f8f8;
    border-bottom: solid 1px #e7e7e7;
    height: 51px;
}

.typeahead-container.backdrop .typeahead-button {
    display: none;
}

.typeahead-container.backdrop .typeahead-field {
    display: flex;
    height: 100%;
    align-items: center;
}

.typeahead-container.backdrop .typeahead-field {
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

.typeahead-container.backdrop .typeahead-field > * {
    display: inline-block;
}

@media (min-width: 768px) {
    .typeahead-container.backdrop .typeahead-fieldntainer {
        width: 750px;
    }
}

@media (min-width: 992px) {
    .typeahead-container.backdrop .typeahead-field {
        width: 970px;
    }
}

@media (min-width: 1200px) {
    .typeahead-container.backdrop .typeahead-field {
        width: 1170px;
    }
}

.typeahead-container.backdrop .typeahead-result {
    overflow-y: scroll;
    overflow-x: hidden;
    position: absolute;
    width: 100% !important;
    background-color: #fff;
    top: 81px;
    height: calc(100% - 81px);
    -ms-overflow-style: none;
    overflow: -moz-scrollbars-none;
}

.typeahead-container.backdrop .typeahead-result::-webkit-scrollbar {
    width: 0 !important;
}

.typeahead-container.backdrop...

JavaScript

var typeaheadResultCount = $('.js-typeahead-result-count'),
    typeaheadResultCountDefault = typeaheadResultCount.text(),
    typeaheadToggle = $('.js-typeahead-toggle'),
    typeaheadSubmit = $('.js-typeahead-submit');

typeaheadToggle.on('click', function (e) {
    $('.js-typeahead-input').focus();
    // Prevent Typeahead hideLayout from being called on the initial request
    e.stopPropagation();
});

typeaheadSubmit.on('click', function (e) {
    var origin = $(e.currentTarget);

    if (!origin.hasClass('active')) return;
    origin.closest('form')[0].submit();
});

typeof $.typeahead === 'function' && $.typeahead({
    input: ".js-typeahead-input",
    minLength: 2,
    maxItem: 40,
    order: "asc",
    hint: true,
    backdrop: {
        opacity: 1,
        background: '#fff'
    },
    maxItemPerGroup: 30,
    backdropOnFocus: true,
    emptyTemplate: function (query) {
        return 'no result for ' + query;
    },
    source: {
        game: {
            href: "http://www.gamer-hub.com/game/{{id}}/{{display|slugify}}",
            template: function (query, item) {
                return '<div><img src="http://cdn.gamer-hub.com/images/' + this.helper.slugify.call(this, item.display) + '.jpg"></div>'
            },
            url: [{
                url: "http://www.gamer-hub.com/game/list.json",
                dataType: "jsonp"
            }, "data"]
        },
        category: {
            href: "http://www.gamer-hub.com/category/{{id}}/{{display|slugify}}",
            url: [{
                url: "http://www.gamer-hub.com/category/list.json",
                dataType: "jsonp"
            }, "data"]
        },
        tag: {
            href: "http://www.gamer-hub.com/tag/{{id}}/{{display|slugify}}",
            url: [{
                url: "http://www.gamer-hub.com/tag/list.json",
                dataType: "jsonp"
            }, "data"]
        }
    },
    callback: {
        onClick: function (node, a, item, event) {
           ...