Page 1 of 1

Integrate Hammer.js problems

Posted: 00:24, 13 Oct 2015
by AppMaker
Hi,

this is most likely a general javascript but I can't figure out the problem.

I am trying to load in the library hammer.js. I am using it with one of the Evothings examples.


This is my script sources:

Code: Select all

   <script src="cordova.js"></script>
   <script src="libs/evothings/evothings.js"></script>
   <script src="libs/evothings/easyble/easyble.js"></script>
   
   <script src="libs/jquery/jquery.js"></script>
   <script src="libs/Hammer/hammer.min.js"></script>
   <script src="libs/Hammer/jquery.hammer.js"></script>
   <script src="app.js"></script>


Code: Select all

app.initialize =  function() 
{
$("#Button1").hammer().bind("press", console.log("Pressed"));
}


When the code loads, the console logs "Pressed" without being pressed. It also will not work when I press the button.

I am not sure why it is doing this. Any ideas?

Re: Integrate Hammer.js problems

Posted: 09:43, 13 Oct 2015
by Fredrik
I haven't used hammer.js, but I think the second argument to bind() must be a function, and you're passing the return value of console.log(), which means console.log() is executed before anything else and never again.

Re: Integrate Hammer.js problems

Posted: 15:56, 13 Oct 2015
by AppMaker
I think it is supposed to be an event listener and only execute when a "Press" event happens.

I thought it might be something with how evothings.js loads the scripts. Not sure though. I'll keep digging into it.

Re: Integrate Hammer.js problems

Posted: 16:06, 13 Oct 2015
by Fredrik
To illustrate, I think it should be like this:

Code: Select all

app.initialize =  function()
{
   $("#Button1").hammer().bind("press", function() {
      console.log("Pressed");
   });
}

Re: Integrate Hammer.js problems

Posted: 18:01, 13 Oct 2015
by AppMaker
Yes, you are right. That fixed it.

Don't know how I didn't see that.

Thanks!