Am I subscribing to YUI Menu events improperly? - keyboard

I've read and followed YUI's tutorial for subscribing to Menu events. I also looked through the API and bits of the code for Menu, MenuBar, and Custom Events, but the following refuses to work
// oMenuBar is a MenuBar instance with submenus
var buyMenu = oMenuBar.getSubmenus()[1];
// this works
buyMenu.subscribe('show', onShow, {foo: 'bar'}, false);
// using the subscribe method doesn't work
buyMenu.subscribe('mouseOver', onMouseOver, {foo: 'bar'}, false);
// manually attaching a listener doesn't work
YAHOO.util.Event.addListener(buyMenu, 'mouseOver', onMouseOver);
// http://developer.yahoo.com/yui/docs/YAHOO.widget.Menu.html#event_keyPressEvent
// there is a keyPress Event, but no spelling of it will trigger the handler
buyMenu.subscribe('keypress', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keypressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPress', onShow, {foo: 'bar'}, false);
Functionally, I'm trying to attach a keyPress listener for each submenu of the MenuBar. I do not want to add Bubbling library as a dependency.

Todd Kloots here, author of the YUI Menu widget. When you are subscribing to DOM-based events, the event name is all lower case. So, for the "mouseover" event, subscribe as follows:
buyMenu.subscribe('mouseover', onMouseOver, {foo: 'bar'}, false);
Regarding your keypress event handler: you are subscribing correctly. However, remember that any key-related event handlers will only fire if the Menu has focus. So, make sure your Menu has focus before testing your key-related event handlers. Also - I would recommend listening for the "keydown" event rather than "keypress" as not all keys result in the firing of the "keypress" event in IE.
If you have any other questions, please direct them to the ydn-javascript Y! Group as I monitor the messages on that group frequently.
I hope that helps.
Todd

Based on my testing, the following will work:
oMenu.subscribe('keypress', function () { alert("I'm your friendly neighborhood keypress listener.")});
but that only fires when the Menu is receiving the keypress event, so it would need to already have focus.

Does onShow point to a function?
eg.
var onShow = function()
{
alert("Click!");
}

Related

How to tell if a window failed to close in Electron?

Is there a way in Electron to tell if a window was not successfully closed?
win.once("closed", () => {
// send message to the page running in the renderer process that the window was closed
});
win.close();
Assuming that I'm not cancelling the close in the close or beforeunload handler, can the window still fail to close, or can I be sure that a message will always be sent to the guest page?
I just came to this issue as well, what I did is simply wait for a few hundred milliseconds, if the callback is called, then most likely, this window has failed to close:
win.on('close', () => setTimeout(() => console.log('failed to close'), 300))
Have a look at this property in the doc:
win.closed
A Boolean that is set to true after the child window gets closed.
And this other bit too:
win.destroy()
Force closing the window, the unload and beforeunload
event won’t be emitted for the web page, and close event will also not
be emitted for this window, but it guarantees the closed event will be
emitted.
With that, you should have all the info you need to create a function that insure you that the window closes:
function forceClose(window) {
// try close first
window.close()
// force with destroy
if(!window.closed) {
window.destroy()
}
//just logging out the event
window.on('closed', (e) => {
console.log(e)
})
}
// in your code, instead of calling win.close()
forceClose(win)

PubNub. Presence leave trigger event doesn't fire

I'm testing Pubnub 3.7.1. But I have a problem with the leave event trigger that doesn't fired.
I can only see the join and timeout trigger event. Here is some code that I use:
pubnub.subscribe({
channel: 'channel',
presence: manageUsers,
message: showMessage
});
function manageUsers(message, event, channel) {
console.log(message);
}
What could be the problem?
Thanks.
UDATE:
Another thing is when I enter in a channel where there are some people connected, I can't get their presence data. I can only get their presence data from new users.
Here is the example:
http://plnkr.co/edit/qlqhb677CZhTeR8Sa52x?p=preview
Your code works as expected.
When a user join, it triggers a 'join' action, and when the user goes idle, the action becomes 'timeout'.
The 'leave' action occurs when a user unsubcribe from the channel.
e.g.
byeButton.click(function(){
pubnub.unsubscribe({
channel : 'channel_1',
callback: function(m){
console.log(m.action); // should print 'leave'
}
});
});
See more at:
https://www.pubnub.com/docs/javascript/api/reference.html#unsubscribe

How to put a DELAY in an FADEIN

So, I've got this:
$('header').fadeIn(1000, function() {
// Animation complete
});
$('#intro').fadeIn(3000, function() {
// Animation complete
});
And now I want the second one to come in later, so with a delay. But where in the code do I put this?
EDIT: Got it, thanks!
If you want to start the second animation after the first one, you should do this
$('header').fadeIn(1000, function() {
$('#intro').fadeIn(3000, function() {
// Animation complete
});
});
jQuery maintains a queue of effects per element. You are animating 2 elements so they will fire simultaneously.
More info: http://api.jquery.com/queue/
You can nest the functions but that's going to get difficult if you want 10 effects.
Here's a good solution:
https://stackoverflow.com/a/11354378/907253

Is there a way to trigger plotselected event without triggering plotclick event?

I need click events in the chart.
But I also need to allow user to select a range to zoom in.
Click events are registered properly. However on doing a selection, it triggers both plotselected and plotclick events.
How do I prevent the plotclick event from being triggered while plotselected is triggered?
Selection plugin: https://github.com/flot/flot/blob/master/jquery.flot.selection.js
Currently no, there's no way to avoid getting both events.
One solution might be to remove the 'clickable' option and instead listen to the 'plotunselected' event, which is triggered by a click without drag.
The problem is plotselected triggering plotclick event.
The following conditional check solved my problem.
$("#graph").bind("plotclick", function (event, pos, item) {
if (item == undefined) return false;
// the rest of the click event here
});
resting's answer didn't quite work for me as my use case needed to handle the plotclick event even if there was no item clicked.
I was able to determine if an event was a plotselection vs plotclick event in the plotclick event handler by setting a variable in the plotselection event handler and then checking it in the plotclick handler:
var plotSelectionEvent = false;
$("#placeholder").bind("plotselected", function (event, ranges) {
plotSelectionEvent = true;
// rest of the plot selection event code
});
$("#placeholder").bind("plotclick", function (event, pos, item) {
// check if this event was originally a plot selection event
// reset the variable and return if it was
if (plotSelectionEvent) {
plotSelectionEvent = false;
return;
}
// rest of the plot selection event code
});

Catching jPlayer full screen event

I'm trying to catch jPlayer full screen event using the following code:
mainPlayer.bind($.jPlayer.event.resize, function(event) {
alert("size changed");
});
But the event isn't fired neither when I press full screen button nor when I press ESC to exit full screen mode.
Check your mainPlayer variable and make sure it references the jQuery jPlayer object. For troubleshooting, try:
$('#yourJPlayerID').bind($.jPlayer.event.resize, function(event) {
alert("size changed");
});

Resources