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

ember-responds-to

v1.5.1

Published

Ember mixins for browser event handling.

Downloads

19

Readme

Ember-responds-to

npm version npm Ember Observer Score Build Status

This Ember CLI addon makes it easy to handle browser events in your components.

  • resize and orientationchange events trigger resize and call resize.
  • scroll events trigger scroll and call scroll.
  • enter keydown events trigger enterKeydown and call enterKeydown.
  • esc keydown events trigger escKeydown and call escKeydown.
  • print events trigger print and call print.

The scroll and resize events are debounced using requestAnimationFrame.

The enter and esc keydown event handlers are called in LIFO order and each can stop "propagation" with a truthy return value.

The print event is detected with matchMedia so does not support IE9 and below (see http://caniuse.com/#feat=matchmedia for browser support).

Usage

Install the addon.

ember install ember-responds-to

Import the mixins in a component and use the events or the handlers.

import Component from '@ember/component';
import RespondsToEnterKeydown from 'ember-responds-to/mixins/responds-to-enter-keydown';
import RespondsToEscKeydown from 'ember-responds-to/mixins/responds-to-esc-keydown';
import RespondsToResize from 'ember-responds-to/mixins/responds-to-resize';
import RespondsToScroll from 'ember-responds-to/mixins/responds-to-scroll';
import RespondsToPrint from 'ember-responds-to/mixins/responds-to-print';
import { on } from '@ember/object/evented';

export default Component.extend(
  RespondsToEnterKeydown,
  RespondsToEscKeydown,
  RespondsToResize,
  RespondsToScroll,
  RespondsToPrint,
{

  classNameBindings: [ 'isLandscape:landscape:portrait' ],

  enterKeydown() {
    this.sendAction('submit');
  },

  escKeydown() {
    this.sendAction('close');
  },

  logResize: on('resize', function () {
    console.log('resize event triggered');
  }),

  logScroll: on('scroll', function () {
    console.log('scroll event triggered');
  }),

  logPrint: on('print', function () {
    console.log('print event triggered');
  }),

  resize: () => console.log('resize handler called'),
  scroll: () => console.log('scroll handler called'),
  print: () => console.log('print handler called'),

  setLandscape: on('didInsertElement', 'resize', function () {
    this.set('isLandscape', window.innerWidth > window.innerHeight);
  }),

});

In CI

If you use phantomjs for testing you need to include a polyfill for requestAnimationFrame. To do so, add the file at https://gist.github.com/paulirish/1579671 to vendor/ and add the following line to your ember-cli-build.js.

app.import('vendor/rAF.js', { type: 'test' });