event-contextmenu-debug.js revision f66812a0791dd11c23b677fc167c30a4aff065f8
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * Provides extended keyboard support for the "contextmenu" event such that:
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * <li>The browser's default context menu is suppressed regardless of how the event was triggered</li>
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * <li>On Windows the "contextmenu" event is fired consistently regardless of whether the user pressed the Menu key or Shift + F10</li>
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * <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>
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * <li>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>
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * @module event-contextmenu
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith * @requires event
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith on: function (node, subscription, notifier, filter) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith handles.push(Event._attach(["contextmenu", function (e) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Any developer listening for contextmenu event is likely
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // going to call preventDefault() to prevent the display of
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // the browser's context menu. So, you know, save them a step.
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith handles.push(node[filter ? "delegate" : "on"]("keydown", function (e) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith (isMac && e.ctrlKey && shiftKey && e.altKey && keyCode == 77)) { // M
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Need to call preventDefault() here b/c:
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // 1) To prevent IE's menubar from gaining focus when the
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // user presses Shift + F10
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // 2) In Firefox for Win, Shift + F10 will display a contextmenu,
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // but won't fire the contextmenu event. So, need to call
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // preventDefault() to prevent the display of the
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // browser's contextmenu
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Protect against instances where xy and might not be returned,
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // for example if the target is the document.
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith clientX = (x + (target.offsetWidth/2)) - scrollX;
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith clientY = (y + (target.offsetHeight/2)) - scrollY;
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // When the contextmenu is fired from the keyboard
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // clientX, clientY, pageX or pageY aren't set to useful
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // values. So, we follow Safari's model here of setting
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // the x & x coords to the center of the event target.
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Don't need to call notifier.fire(e) when the Menu key
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // is pressed as it fires contextmenu by default.
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // In IE the call to preventDefault() for Shift + F10
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // prevents the contextmenu event from firing, so we need
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // to call notifier.fire(e)
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Need to also call notifier.fire(e) for gecko win since
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Shift + F10 doesn't fire the contextmenu event
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // Lastly, also need to call notifier.fire(e) for
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // webkit for Mac && gecko for Mac since Shift + Ctrl + Option + M
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith // doesn't fire the contextmenu event when VoiceOver isn't enabled
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith if (((ie || (isWin && gecko)) && shiftF10) || isMac) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith detach: function (node, subscription, notifier) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith Y.each(subscription._handles, function (handle) {
f66812a0791dd11c23b677fc167c30a4aff065f8Luke Smith}, '@VERSION@' ,{requires:['event-synthetic', 'dom-screen']});