6

I'm trying to get hammer js events working with backbone but can't get it to respond to events. I've tried the following already..

http://cijug.net/tech/2013/01/16/backbone-hammer/

https://gist.github.com/kjantzer/4279025

I've also put below piece of code in my view

initialize: function(){
    this.events = _.extend({}, this.defaultEvents, this.events||{});      
}

JS Fiddle : http://jsfiddle.net/XcYhD/

Code

<div id="swiping"></div>

JS

AppView = Backbone.View.extend({

  el: '#swiping',          

  events: {
    'swipe': 'swipeMe'
  },

  render: function(){             
    this.$el.html('<h2>Swipe Me</h2>');
  },

  swipeMe: function(e){                
    alert('swiped ' + e.direction);
  }

});

var view = new AppView();
view.render(); 

Libraries Included - hammer.js , jquery.specialevent.hammer.js , etc..

Anyway to get it working ?

user1184100
  • 6,742
  • 29
  • 80
  • 121
  • Possible duplicate/solution: http://stackoverflow.com/questions/16067989/overriding-backbone-view-delegateevents-so-the-events-object-can-include-mobile. – Loamhoof Apr 18 '13 at 13:19

1 Answers1

11

You don't need the special events plugin, I'd just go with the jquery plugin and then run the hammer() function in your render.

  render: function(){             
    this.$el.html('<h2>Swipe Me</h2>');
    this.$el.hammer();
  },

Here's an updated fiddle: http://jsfiddle.net/XcYhD/20/

Chris MacDonald
  • 5,975
  • 4
  • 34
  • 35
Bryan Clark
  • 2,542
  • 1
  • 15
  • 19