Sha256: 2787414ecd8d4e8d3b50404cd4aa6f78f696a46c4661e1a47869ebc418db3bda

Contents?: true

Size: 1.04 KB

Versions: 28

Compression:

Stored size: 1.04 KB

Contents

/**
 * adds a bindScoped method to Mousetrap that allows you to
 * bind specific keyboard shortcuts that will work only within
 * certain context
 * inside a text input field
 *
 * usage:
 * Mousetrap.bindScoped('.some-class', 'ctrl+s', _saveChanges);
 */
Mousetrap = (function(Mousetrap) {
    var _scopedCallbacks = {},
        _originalStopCallback = Mousetrap.stopCallback;

    Mousetrap.stopCallback = function(e, element, combo, sequence) {
        var selector = _scopedCallbacks[combo] || _scopedCallbacks[sequence];
        if (selector) {
            return !$(element).is(selector);
        }

        return _originalStopCallback(e, element, combo);
    };

    Mousetrap.bindScoped = function(selector, keys, callback, action) {
        Mousetrap.bind(keys, callback, action);

        if (keys instanceof Array) {
            for (var i = 0; i < keys.length; i++) {
                _scopedCallbacks[keys[i]] = selector;
            }
            return;
        }

        _scopedCallbacks[keys] = selector;
    };

    return Mousetrap;
}) (Mousetrap);

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
houston-core-0.9.2 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.9.1 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.9.0 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.9.0.rc1 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.4 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.3 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.2 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.1 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.0 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.0.pre2 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.8.0.pre app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.7.0 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.7.0.beta4 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.7.0.beta3 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.7.0.beta2 app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.7.0.beta app/assets/javascripts/houston/app/mousetrap-bind-scoped.js
houston-core-0.6.3 app/assets/javascripts/app/mousetrap-bind-scoped.js
houston-core-0.6.2 app/assets/javascripts/app/mousetrap-bind-scoped.js
houston-core-0.6.1 app/assets/javascripts/app/mousetrap-bind-scoped.js
houston-core-0.6.0 app/assets/javascripts/app/mousetrap-bind-scoped.js