Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hammer JS not working with backbone

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 ?

like image 760
user1184100 Avatar asked Apr 18 '13 13:04

user1184100


1 Answers

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/

like image 125
Bryan Clark Avatar answered Nov 08 '22 20:11

Bryan Clark