{"id":4363,"date":"2010-05-01T15:10:33","date_gmt":"2010-05-01T22:10:33","guid":{"rendered":"http:\/\/3.408"},"modified":"2010-05-01T15:10:33","modified_gmt":"2010-05-01T22:10:33","slug":"using-jetpack-sdk-0-3-context-menu-api","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/labs\/2010\/05\/using-jetpack-sdk-0-3-context-menu-api\/","title":{"rendered":"Using Jetpack SDK 0.3: Context Menu API"},"content":{"rendered":"<p>You&#8217;re probably familiar with context menus, they&#8217;re the menus that appear as a result of a right-click on a web page or browser element.  Interacting with context menus quickly becomes a part of everyday web surfing as they provide shortcuts for many general tasks. But there are probably special shortcuts you&#8217;d include in them if you could such as editing an image, sending a quote to Twitter, or translating the text content of an element.  Good news, you can use the brand-spanking-new <a href=\"https:\/\/jetpack.mozillalabs.com\/sdk\/latest\/docs\/#module\/jetpack-core\/context-menu\">Context Menu API<\/a> introduced in <a href=\"http:\/\/mozillalabs.com\/jetpack\/2010\/04\/29\/announcing-jetpack-sdk-0-3\/\">version 0.3 of the Jetpack SDK<\/a> to do just that!<!--more--><\/p>\n<h2>Editing an image with Picnik<\/h2>\n<p>Picnik is a web-based image editor that lets you modify images in a variety of ways, like resizing, cropping, red-eye removal and more.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/mozillalabs.com\/jetpack\/files\/2010\/04\/picnik_logo_w_examples.gif\" alt=\"\" \/><\/p>\n<h2>How it&#8217;s made<\/h2>\n<p>I can&#8217;t wait to start editing images, so let&#8217;s make it possible to get an image up and ready to edit on Picnik in one click! Here&#8217;s what the code looks like:<\/p>\n<pre style=\"font-family: Consolas;font-size: 12px;margin: 20px 0px 20px 30px\">exports.main = function(options, callbacks) {\n\n    var contextMenu = require(\"context-menu\");\n\n    var editImageItem = contextMenu.Item({\n        label: \"Edit image with Picnik\",\n        onClick: function (context) {\n            require('tabs').Tabs.add('http:\/\/www.picnik.com\/?import=' + escape(context.node.src), true);\n        },\n        context: 'img'\n    });\n\n    contextMenu.add(editImageItem);\n\n}\n<\/pre>\n<p>For official modules provided by the Jetpack SDK, you don&#8217;t have to worry about copying their js file(s) into your extension&#8217;s packages directory, simply retrieve their functionality via the <em>require()<\/em> statement. For your own modules (like my tabs  module used in the code above, which is a stand-in until we release the native tabs API) you will need to ensure that they are included in the lib directory of your extension package.<\/p>\n<h2>What it looks like<\/h2>\n<p>Here&#8217;s a shot of the extension&#8217;s addition to the context menu that appears when an image is clicked:<\/p>\n<p><img decoding=\"async\" style=\"border: 1px solid #999;background: #efefef;padding: 4px\" src=\"http:\/\/mozillalabs.com\/jetpack\/files\/2010\/04\/image-editing-context-menu.png\" alt=\"\" \/><\/p>\n<p>After clicking &#8220;Edit image with Picnik&#8221;, the image will open in a new tab ready for editing:<\/p>\n<p><img decoding=\"async\" style=\"border: 1px solid #999;background: #efefef;padding: 4px\" src=\"http:\/\/mozillalabs.com\/jetpack\/files\/2010\/04\/in-picnik-editing.png\" alt=\"\" \/><\/p>\n<h2>Get the source files<\/h2>\n<p>Download the <a href=\"http:\/\/people.mozilla.com\/~dbuchner\/demos\/extensions\/image-editor.zip\">Picnik Image Editor package<\/a> and unpack it to the <em>packages\/<\/em> subdirectory of your Jetpack SDK directory. Make sure the SDK is activated per the <a href=\"https:\/\/jetpack.mozillalabs.com\/sdk\/latest\/docs\/\">instructions<\/a> in the docs. Then enter the <em>image-editor\/<\/em> subdirectory and execute the command <em>cfx -a firefox run<\/em> to try it out.<\/p>\n<h2>Install the extension<\/h2>\n<p>To use the extension, you can install <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/158233\/\">Picnik Image Editor<\/a> from addons.mozilla.org.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;re probably familiar with context menus, they&#8217;re the menus that appear as a result of a right-click on a web page or browser element. Interacting with context menus quickly becomes a part of everyday web surfing as they provide shortcuts &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/labs\/2010\/05\/using-jetpack-sdk-0-3-context-menu-api\/\">Continue reading<\/a><\/p>\n","protected":false},"author":229,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts\/4363"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/users\/229"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/comments?post=4363"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/posts\/4363\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/media?parent=4363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/categories?post=4363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/labs\/wp-json\/wp\/v2\/tags?post=4363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}