Labs/Jetpack/Reboot/JEP/112: Difference between revisions

Jump to navigation Jump to search
Updated: 1) onCommand -> onClick, and 2) onClick is passed the clicked item, not data
(→‎Separator: Separators don't take options, can't be added to top-level menu)
(Updated: 1) onCommand -> onClick, and 2) onClick is passed the clicked item, not data)
Line 153: Line 153:
; label: The label of the menuitem, a string.  Required.
; label: The label of the menuitem, a string.  Required.


; onCommand: An optional function that will be called when the menuitem is clicked.  It is called as <tt>onCommand(contextObj, data)</tt>.  <tt>contextObj</tt> is an object describing the context in which the menu was invoked.  See [[#Context Descriptions]].  <tt>data</tt> is the item's <tt>data</tt> property.
; onClick: An optional function that will be called when the menuitem is clicked.  It is called as <tt>onClick(contextObj, item)</tt>.  <tt>contextObj</tt> is an object describing the context in which the menu was invoked.  See [[#Context Descriptions]].  <tt>item</tt> is the item itself.


</blockquote>
</blockquote>
Line 175: Line 175:
; label: The label of the menuitem, a string.
; label: The label of the menuitem, a string.


; onCommand: An optional function that will be called when any of the item's descendants is clicked.  (The commands of descendants are invoked first, in a bottom-up, bubbling manner.)  It is called as <tt>onCommand(contextObj, data)</tt>.  <tt>contextObj</tt> is an object describing the context in which the menu was invoked.  See [[#Context Descriptions]].  <tt>data</tt> is the <tt>data</tt> property of the item that was selected or <tt>undefined</tt> if the selected item has no data.
; onClick: An optional function that will be called when any of the item's descendants is clicked.  (The commands of descendants are invoked first, in a bottom-up, bubbling manner.)  It is called as <tt>onClick(contextObj, item)</tt>.  <tt>contextObj</tt> is an object describing the context in which the menu was invoked.  See [[#Context Descriptions]].  <tt>item</tt> is the item that was clicked.


</blockquote>
</blockquote>
Line 218: Line 218:
var editImageItem = contextMenu.Item({
var editImageItem = contextMenu.Item({
   label: "Edit Image",
   label: "Edit Image",
   onCommand: function (context) {
   onClick: function (context) {
     editImage(context.node.src);
     editImage(context.node.src);
   },
   },
Line 235: Line 235:
var searchMenu = contextMenu.Menu({
var searchMenu = contextMenu.Menu({
   label: "Search",
   label: "Search",
   onCommand: function (context, data) {
   onClick: function (context, item) {
     context.window.location.href = data + selection.text;
     context.window.location.href = item.data + selection.text;
   },
   },
   context: selectionExists,
   context: selectionExists,
Line 256: Line 256:
var pageSourceItem = contextMenu.Item({
var pageSourceItem = contextMenu.Item({
   label: "Edit Page Source",
   label: "Edit Page Source",
   onCommand: function (context) {
   onClick: function (context) {
     editSource(context.document.URL);
     editSource(context.document.URL);
   },
   },
Line 269: Line 269:
var editImagesItem = contextMenu.Item({
var editImagesItem = contextMenu.Item({
   label: "Edit Page Images",
   label: "Edit Page Images",
   onCommand: function (context) {
   onClick: function (context) {
     var imgNodes = context.document.querySelectorAll("img");
     var imgNodes = context.document.querySelectorAll("img");
     editImages(imgNodes);
     editImages(imgNodes);
Confirmed users
764

edits

Navigation menu