npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-keybind

v1.0.0

Published

A small AngularJS module to bind specific keypress events to methods.

Downloads

10

Readme

angular-keybind

MIT License Coverage Status NPM version CircleCI

:abc: :nut_and_bolt: A small AngularJS module to bind specific keypress events to methods.

At times you may need to attach specific functionality to an element based on specific key input. For simple cases, AngularJS has a built in solution called ngKeyup that works well. At other times you may need something with a bit more power. angular-keybind was built to solve this more complex use case.

:tv: Demo

Comments and Pull Requests welcome!

Contents

Installation

NPM

npm install angular-keybind --save

Bower

bower install angular-keybind --save

Manually

Add the script to your HTML:

<script src="../path/to/your/(npm|bower)_components/angular-keybind/dist/angular-keybind.js"></script>

##Dependencies

  • Angular.js (^1.4.0)

Usage

Include bc.AngularKeybind as a dependency in your project:

angular.module('YourModule', ['bc.AngularKeybind']);

Use the directive as an attribute on any element that can be focused (it doesn't need to be an input). It will listen for keypress events on the element and fire the associated method.

<!--
  13 is the key code for 'enter'
  32 is the key code for 'space'
-->
<input
  bc-keybind
  bc-keys="['13, '32']"
  bc-method="vm.myMethod"
>
<!--
  Notice! When passing in the method reference, parenthesis `()` should not be added.
-->
export class YourController {

    constructor() {}

    // I will be called if either enter or space is triggered while the element has focus
    myMethod(event) {
        console.log('One of our keys was pressed!');
        console.log('Original event object: ', event);
    }

}

:tv: Demo

Attributes

Most use cases will only need to use bc-keys and bc-method. For more advanced cases, a second and third set of attributes can be used.

| Attribute | Accepts | Details | |--------------|---------|---------| | bc-keys | Array | Expects an array of key codes | | bc-method | Method | Expects a method which will be called when a keypress matches one of the keys passed into bc-keys | | bc-keys2 | Array | Expects an array of key codes | | bc-method2 | Method | Expects a method which will be called when a keypress matches one of the keys passed into bc-keys2 | | bc-keys3 | Array | Expects an array of key codes | | bc-method3 | Method | Expects a method which will be called when a keypress matches one of the keys passed into bc-keys3 |

Learn more about keycodes on css-tricks

<!--
  In this more advanced use-case we need 'enter' to trigger a specific method.
  We also need a separate method to be triggered when any arrow key is used.
-->
<input
  bc-keybind
  bc-keys="['13']"
  bc-method="vm.myMethodForEnter"
  bc-keys="['37', '38', '39', '40']"
  bc-method2="vm.myMethodForArrows"
>
export class YourController {

    constructor() {}

    // I will be called if any key from the `bc-keys` array is used while the element has focus
    myMethodForEnter(event) {
        console.log('One of the `bc-keys` keys was pressed! Pressed key: ', event.which);
    }

    // I will be called if any key from the `bc-keys2` array is used while the element has focus
    myMethodForArrows(event) {
        console.log('One of the `bc-keys2` keys was pressed! Pressed key: ', event.which);
    }

}

:tv: Demo

Development

  • npm run build - Build JS
  • npm run watch - Watch JS and rebuild on change
  • npm run test - Run tests
  • npm run watch:tests - Watch for changes in .spec.js files and re-run the tests