Sha256: eb4fec988e12363ef4eb28ba13db25c863034764f6f33fdd3be21133588e28f8

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

"use strict";

/*
Search related functions
*/

let submitTimer, submitInterval, intervals = 1;
let queryElement = document.getElementById("query");
let autoSearchEnabled = "<%= Sail.configuration.enable_search_auto_submit %>";
let progress = document.getElementById("search-submit-progress");
let menu = document.getElementById("sort-menu");
let orderButton = document.getElementById("btn-order");

function submitSearch() {
    document.getElementById("search-form").submit();
}

function advanceProgress() {
    progress.value = intervals;
    intervals += 1;
}

function clearTimer() {
    clearTimeout(submitTimer);
    clearTimeout(submitInterval);
    intervals = 1;
}

function afterTypingQuery() {
    progress.style.display = "inline-block";
    clearTimer();
    submitTimer = setTimeout(submitSearch, 2000);
    submitInterval = setInterval(advanceProgress, 20);
}

function toggleSortMenu() {
    if (menu.style.display === "none") {
        menu.style.display = "block";
    } else {
        menu.style.display = "none";
    }
}

function handleGenericClick(event) {
    let target = event.target;

    if (target === menu || menu.contains(target) || target === orderButton || orderButton.contains(target)) {
        return;
    }

    menu.style.display = "none";
}

if (autoSearchEnabled === "true") {
    queryElement.addEventListener("keyup", afterTypingQuery);
    queryElement.addEventListener("keydown", clearTimer);
}

orderButton.addEventListener("click", toggleSortMenu);
document.body.addEventListener("click", handleGenericClick);

/*
Refresh related functions
 */

let refreshButtons = document.getElementsByClassName("refresh-button");

function refreshClick() {
    let button = this;

    if (!button.className.includes("active")) {
        button.classList.add("active");
        setTimeout(function() { button.classList.remove("active"); }, 500);
    }
}

for(var i = 0; i < refreshButtons.length; i++) refreshButtons[i].addEventListener("click", refreshClick);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sail-2.1.1 app/assets/javascripts/settings.js.erb
sail-2.1.0 app/assets/javascripts/settings.js.erb