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

backbone.hammer

v1.0.1

Published

Declarative HammerJS touch events for Backbone Views

Downloads

364

Readme

backbone.hammer

v1.0.1

A Hammerjs adapater for Backbone. Enables hammerjs event bindings for Backbone Views. For attaching touch events in the same style as Backbone delegateEvents. Works with or without AMD.

wercker status

Install with npm

$ npm install --save backbone.hammer

Install with Bower

$ bower install --save backbone.hammer

Usage

Depends on the Hammerjs jQuery plugin, jQuery and, of course, Backbone & Underscore.

var view = new Backbone.View({
  hammerEvents: {
    'swipeleft h1': 'handleSwipe',
    'tap h1': 'handleTap'
  },
  hammerOptions: {
    tap: true
  },
  handleSwipe: function(){
    console.log('Stop.');
  },
  handleTap: function(){
    console.log('Hammer time!');
  }
});

view.$('h1').trigger('swipeleft');
// → "Stop."
view.$('h1').trigger('tap');
// → "Hammer time!"

// Access the view's hammer instance
view.hammer();
// → view.$el.hammer()

Works alongside delegateEvents and undelegateEvents, so normal event bindings will be uneffected by adding hammer events.

API

All additional methods are attached to Backbone.View.prototype.

View.prototype.initialize/constructor new Backbone.View([options])

View constructors will accept two additional options that will be automatically attached to instances, hammerOptions and hammerEvents. See examples above for passing these directly to a constructor.

View.prototype.delegateHammerEvents delegateHammerEvents([events])

Uses hammer's jQuery interface to attach delegated hammer events to the view's element. Accepts an optional events object that will be used in place of View.prototpe.events. Unbinds any previously bound hammer events prior to attaching new events. Called simultaneously with delegateEvents.

View.prototype.undelegateHammerEvents undelegateHammerEvents()

Removes any bound event handlers that were created with delegateHammerEvents. Automatically called by undelegateEvents, so hammer events are removed along with other events on the view.

View.prototype.hammer hammer([options])

Returns the hammer instance for the view's element, directly exposing the hammer API if you need to create hammer events directly.

In most cases, the default behavior of creating a hammer instance on the view's el will be sufficient. This method can be overridden if you'd like to declare touch events on another element, just make sure to return a call to the hammer jQuery plugin:

hammer: function(options){
  return this.$('.touch-area').hammer(options);
}

Backbone.hammerOptions

Default settings for any view that uses hammerEvents. See the hammer docs for more info.

Backbone.hammerOptions = {
  prevent_default: true
};

License

MIT