Giter Site home page Giter Site logo

gunjankothari / backbone.hammer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wookiehangover/backbone.hammer

0.0 1.0 0.0 346 KB

Hammerjs events for Backbone

Home Page: http://wookiehangover.github.io/backbone.hammer/

JavaScript 76.97% HTML 23.03%

backbone.hammer's Introduction

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

backbone.hammer's People

Contributors

acjay avatar enotionz avatar ullmark avatar wookiehangover avatar codepunkt avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.