uccser/cs-field-guide

View on GitHub
csfieldguide/static/interactives/delayed-checkbox/js/delayed-checkbox.js

Summary

Maintainability
A
0 mins
Test Coverage
var DelayedCheckbox = {};
DelayedCheckbox.delay = 1500;
DelayedCheckbox.clicks = 0;

$('#interactive-delayed-checkbox-box').on('change', function(event) {
    toggleCheckbox();
    setTimeout(function(){
        toggleCheckbox();
        DelayedCheckbox.clicks++;
        if (DelayedCheckbox.clicks < 10) {
            $("#interactive-delayed-checkbox-counter").html(DelayedCheckbox.clicks);
        } else {
            $("#interactive-delayed-checkbox-counter").html('many');
        }
    }, DelayedCheckbox.delay);
});

function toggleCheckbox() {
    var $checkbox = $("#interactive-delayed-checkbox-box");
    if ($checkbox.prop('checked')) {
        $checkbox.prop('checked', false);
    } else {
        $checkbox.prop('checked', true);
    }
}