Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key to enable/disable all input #281

Closed
Mottie opened this issue Jun 24, 2014 · 0 comments
Closed

Add key to enable/disable all input #281

Mottie opened this issue Jun 24, 2014 · 0 comments

Comments

@Mottie
Copy link
Owner

Mottie commented Jun 24, 2014

Add a new key to emulate this demo

$('#keyboard').keyboard({
    visible: function (e, kb, el) {
        if (!kb.$keyboard.find('.ui-keyboard-lock').length) {
            // add lock button
            kb.$keyboard.append('<button class="ui-keyboard-button ui-keyboard-lock ui-state-default ui-corner-all"><span class="ui-icon-unlocked ui-icon"></span></button>');
            kb.$keyboard.find('.ui-keyboard-lock').click(function () {
                var locked = !$(this).find('span').hasClass('ui-icon-locked');
                // prevent physical keyboard from working
                kb.$preview.prop('readonly', locked);
                // disable all buttons
                kb.$keyboard.find('.ui-keyboard-button')
                    .not('.ui-keyboard-lock')
                    .prop('disabled', locked)
                    .attr('aria-disabled', locked);
                $(this).find('span')
                    .toggleClass('ui-icon-locked', locked)
                    .toggleClass('ui-icon-unlocked', !locked);
                // stop auto typing
                if (locked && kb.typing_options) {
                    kb.typing_options.text = '';
                }
            });
        }
    }
})
// activate the typing extension
.addTyping();

$('button.open').click(function () {
    var keyboard = $('#keyboard').getkeyboard();
    keyboard
        .reveal()
        .typeIn('Type on the keyboard', 500, function (kb) {
            // do something after text is added (kb = keyboard)
            // kb.accept(); // close keyboard and accept changes
        });
});

Note: The lock button should use an image instead of jQuery UI's "ui-icon-unlocked" and "ui-icon-locked" class names, as in the demo. This will allow developers to remain independent of the jQuery UI if so desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant