Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
webbingbrasil/adminlte-theme / assets / js / keypressAction.js
Size: Mime:
;(function ( $, window, document, undefined ) {
    var pluginName = "keypressAction",
        defaults = {};

    // The actual plugin constructor
    function keypressAction ( element, options ) {
        this.element = element;
        this.settings = $.extend( {}, defaults, options );
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }

    $.extend(keypressAction.prototype, {
        bindKeyToRoute: function (key, route) {
            var self = this;
            self.bindKeyToCallback(key, function(e) {
                window.location = route;
                return false;
            });
        },
        bindKeyToCallback: function (key, callback) {
            Mousetrap.bind([key], callback);
        },
        init: function () {
            var self = this;
            $.each(this.settings.actions, function( index, object ) {
                if(object.callback != undefined){
                    self.bindKeyToCallback(object.key, object.callback);
                }else {
                    self.bindKeyToRoute(object.key, object.route);
                }
            });
        }
    });

    $.fn[ pluginName ] = function ( options ) {
        this.each(function() {
            if ( !$.data( this, "plugin_" + pluginName ) ) {
                $.data( this, "plugin_" + pluginName, new keypressAction( this, options ) );
            }
        });

        // chain jQuery functions
        return this;
    };

})( jQuery, window, document );