Integrate Hammer.js problems

Ask, and ye shall receive.
AppMaker
Posts: 5
Joined: 15:13, 24 Sep 2015

Integrate Hammer.js problems

Postby AppMaker » 00:24, 13 Oct 2015

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?

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: Integrate Hammer.js problems

Postby Fredrik » 09:43, 13 Oct 2015

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.

AppMaker
Posts: 5
Joined: 15:13, 24 Sep 2015

Re: Integrate Hammer.js problems

Postby AppMaker » 15:56, 13 Oct 2015

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.

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: Integrate Hammer.js problems

Postby Fredrik » 16:06, 13 Oct 2015

To illustrate, I think it should be like this:

Code: Select all

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

AppMaker
Posts: 5
Joined: 15:13, 24 Sep 2015

Re: Integrate Hammer.js problems

Postby AppMaker » 18:01, 13 Oct 2015

Yes, you are right. That fixed it.

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

Thanks!


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 19 guests