Hammer js nested events? - javascript

I'm trying to some kind of pattern for my web app,
so if the user swipes up and left, respectively it will trigger an event
How to do that with hammer js? It seems like using recognizeWith() API but I don't quite understand the usage.

I was trying to do the exact same thing recently with Hammer.js but found it way more difficult than it should be. I ended up writing a library myself to do exactly this.
https://www.npmjs.com/package/swipey.js
The listener will fire a callback when the user does a valid swipe. The callback will receive an object with some details such as "direction", which in your case would be "up-left"

Related

Send keys from an electron application?

The only thing I can find related to this is sendInputEvent.
There's a couple problems with it.
It seems that it can only be called from the main window thread. I need this to happen when someone clicks a button in the application.
It doesn't even seem to work at all even from the main window thread. Example, this doesn't seem to do anything:
code:
setTimeout(function() {
win.webContents.sendInputEvent({keyCode: 'Tab', type: 'keyDown', modifiers: ['alt']});
}, 3000);
I want to send some key strokes after the alt-tab as well, and the API says that the function only works if the window is focused.
It looks like RobotJS might work for this, but it seems a bit heavy-handed for something that is one line in other languages (e.g. SendKeys.Send). Also it looks like it requires building it manually. All in all I'm trying to keep my absolute dependency count to a minimum if possible.
Any ideas?
I agree RobotJS is a beast for that task and instead I would go for node-key-sender
I would also not send the ALT-TAB keystroke and instead would use window.hide() or window.minimize. You can read more here: Electron API docs for minimize() and hide()
It has all the features you need and would work even after you unfocus from your electron window. The only caveat is that it uses Java Runtime behind the scenes

How can I listen any of the document event in JavaScript

I am using the Elementor plugin in WordPress, and I'd like to know what events are triggered by this plugin while the preview page is loading.
So, I don't know how ( and if that's possible of course ) can listen to any triggered events and log them in the console.
At the moment I have tried several solutions I found on the internet, including the monitorEvents(document.body), but I took no valuable information as the common solutions on the internet are related to common events, like mouse events, keyboard events, elements load events, etc.
For example, from the Elementor plugin documentation I know that there is an event called elementor:init, but using all those methods available currently on the internet, I cannot catch that kind of event.
Keep in mind, I don't mind if it's possible to see the data emitted for the given event. I am happy with only see the event name.
Also, keep in mind that I need this information just for debugging purposes. So, if you have any alternative method that can let me access the events, will be very welcome. For example, let's say, if there's a kind of events registry in the window, and I can access it, then this could be also very helpfull.
So is there any way to check the triggered events using JavaScript?

onpagechanged for flipview (winjs)

I would like to know if the flipview control of the winjs library (win8) has got an event, which it called when the page turns, no matter if by keyboard or by mouseclick or swiping?
I was Googling for it, but i could just find other methods which does not fire at the right moment.
is there maybe a way you can make such events?
You should use the onpagechanged event. This will fire when the user switches pages no matter the mechanism.
Try using the pagecompleted event. Used it in one of my apps and it worked. Hope it works for you too :)

ignoring a touchend event when preceded by a touchmove event

Using jquery, I have an event that fires on touchend. I do not want that event to fire when the user scrolls (touchmove). The only thing I've found on SO is this this, but I don't like it. It feels hacky. It hurts my head to think that there isn't away to figure this out without setting a global flag, simply to check if a touchmove has occurred.
Is there anyway to figure the order of events out? Some wrapper that encapsulates all the touch events that occurred. Because this is for work and the powers that be don't want to bloat our code base with libraries, I can't use an external library, but if anyone knows a library that has this functionality that i could peruse for inspiration that would also be helpful.

How can I use Google's/MBP FastButton code with backbone events

Buttons are slow on mobiles (at least 300ms delay in most browsers due to drag detection among other things). Google wrote some javascript to fix this:
http://code.google.com/mobile/articles/fast_buttons.html
The Mobile HTML5 Boilerplate people integrated this into their package:
https://github.com/h5bp/mobile-boilerplate/blob/master/js/mylibs/helper.js#L86
I want to figure out how I can easily use this with backbone. Something like:
events: {
"fastbutton button.save": "save"
}
Where fastbutton replaces click or mousedown with the fast button code. I expect that I will need to rewrite the MPB.fastbutton code a bit. Has anybody done this?
Instead of creating 'fastbuttons' everywhere, it's probably saner to use a library like FastClick that will transparently convert touches to click events on the touched element and get rid of that 300ms delay.
It's as easy as new FastClick(document.body) and you're ready to go.
The advantage of that approach is that if or when the behaviour of touch events changes on mobile devices so that there's no delay on elements with a click event registered, you can just change one line of code to drop the library instead of changing all your code to convert 'fastbuttons' to regular buttons. Maintainability is always good.
I'm pretty sure, this won't work the way you'd like it to. Instead of having an additional event, like say "fastclick", you have to define an element as beeing a fastButton. You actually have to create an instance of fastbutton on which you pass the element and the code like this:
new MBP.fastButton($("button.save"), function() { this.save(); }.bind(this));
In case of backbone, you can easily do this in the initialize() function instead of the events object.
// sorry, just read that you are not really looking for this :)

Categories

Resources