contextmenu.js revision e456dceed80992a528fd8dfed0ebedf3598a4adb
/**
* Provides extended keyboard support for the "contextmenu" event such that:
* <ul>
* <li>The browser's default context menu is suppressed regardless of how the event is triggered.</li>
* <li>On Windows the "contextmenu" event is fired consistently regardless of whether the user pressed the Menu key or Shift + F10.</li>
* <li>When the "contextmenu" event is fired via the keyboard, the pageX, pageY, clientX and clientY properties reference the center of the event target. This makes it easy for "contextmenu" event listeners to position an overlay in response to the event by not having to worry about special handling of the x and y coordinates based on the device that fired the event.</li>
* <li>For Webkit and Gecko on the Mac it enables the use of the Shift + Control + Option + M keyboard shortcut to fire the "contextmenu" event, which (by default) is only available when VoiceOver (the screen reader on the Mac) is enabled.</li>
* <li>For Opera on the Mac it ensures the "contextmenu" event is fired when the user presses Shift + Command + M (Opera's context menu keyboard shortcut).</li>
* </ul>
* @module event-contextmenu
* @requires event
*/
eventData = {},
conf = {
var handles = [];
// Any developer listening for the "contextmenu" event is likely
// going to call preventDefault() to prevent the display of
// the browser's context menu. So, you know, save them a step.
e.preventDefault();
if (data) {
}
}, node]));
var target = this.getDOMNode(),
macWebkitAndGeckoShortcut = (isMac && (webkit || gecko) && ctrlKey && shiftKey && e.altKey && mKey),
// Note: The context menu keyboard shortcut for Opera on the Mac is Shift + Cmd (metaKey) + M,
// but e.metaKey is false for Opera, and Opera sets e.ctrlKey to true instead.
clientX = 0,
clientY = 0,
xy,
x,
y;
// Need to call preventDefault() here b/c:
// 1) To prevent IE's menubar from gaining focus when the
// user presses Shift + F10
// 2) In Firefox and Opera for Win, Shift + F10 will display a
// context menu, but won't fire the "contextmenu" event. So, need
// to call preventDefault() to prevent the display of the
// browser's context menu
// 3) For Opera on the Mac the context menu keyboard shortcut
// (Shift + Cmd + M) will display a context menu, but like Firefox
// and Opera on windows, Opera doesn't fire a "contextmenu" event,
// so preventDefault() is just used to supress Opera's
// default context menu.
e.preventDefault();
}
x = xy[0];
y = xy[1];
// Protect against instances where xy and might not be returned,
// for example if the target is the document.
if (!Y.Lang.isUndefined(x)) {
}
// When the "contextmenu" event is fired from the keyboard
// clientX, clientY, pageX or pageY aren't set to useful
// values. So, we follow Safari's model here of setting
// the x & x coords to the center of the event target.
};
}
// Don't need to call notifier.fire(e) when the Menu key
// is pressed as it fires the "contextmenu" event by default.
//
// In IE the call to preventDefault() for Shift + F10
// prevents the "contextmenu" event from firing, so we need
// to call notifier.fire(e)
//
// Need to also call notifier.fire(e) for Gecko and Opera since
// neither Shift + F10 or Shift + Cmd + M fire the "contextmenu" event.
//
// Lastly, also need to call notifier.fire(e) for all Mac browsers
// since neither Shift + Ctrl + Option + M (Webkit and Gecko) or
// Shift + Command + M (Opera) fire the "contextmenu" event.
}
}
}, filter));
},
});
}
};