Sha256: 758869853b3552a9fa6055905a94435800b046a784ed8d930e45fecd2fa013f3

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

window.onload = function () {
    var sjs = SimpleJekyllSearch({
        searchInput: document.getElementById('searchbar'),
        resultsContainer: document.getElementById('search-results'),
        json: '/search.json',
        searchResultTemplate: '<a href="{url}" target="_blank">{title}</a>',
        noResultsText: ''
    });

    /* hack ios safari unfocus */
    if (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent))
        document.body.firstElementChild.tabIndex = 1;

    var $labelGroup = document.querySelector(".posts-labelgroup");
    var $searchbar = document.getElementById("searchbar");
    var $postLabel = document.getElementById("posts-label");
    var $searchResults = document.querySelector(".search-results");
    var labelWidth = $postLabel.scrollWidth;
    $postLabel.style.width = labelWidth + "px";

    $labelGroup.addEventListener("click", function (e) {
        $searchResults.style.display = null;
        $postLabel.style.width = "0";
        $labelGroup.setAttribute("class", "posts-labelgroup focus-within");
        $searchbar.focus();
        e.stopPropagation();
    }, false);

    $labelGroup.addEventListener("mouseleave", function () {
        document.body.onclick = searchCollapse;
    });

    var searchCollapse = function (e) {
        $searchResults.style.display = "none";
        $labelGroup.setAttribute("class", "posts-labelgroup");
        $postLabel.style.width = labelWidth + "px";
        document.body.onclick = null;
    };
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plainwhite-0.11 assets/js/search.js