Created — forked from anonymous/gist:4093971

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A Jetpack module for mobile

View nativewindow.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
const data = require('self').data;
const menuId;
const utils = require('api-utils/window/utils');
const recent = utils.getMostRecentBrowserWindow();
 
 
/**
* opts: an options object that includes a name, an image and a callback.
* note: the image can only be a file or data uri, see bug 802003
*/
function addMenu(opts) {
let icon = opts.icon || null;
recent.NativeWindow.menu.add(opts.label, icon, opts.callback);
}
 
exports.addMenu = addMenu;
 
/**
* default context objects for contextmenus.
* for docs: https://developer.mozilla.org/en-US/docs/Extensions/Mobile/API/NativeWindow/contextmenus/add
*/
exports.defaultContext = {
matches: function(el) { return true; }
}
exports.textContext = recent.NativeWindow.contextmenus.textContext;
exports.SelectorContext = recent.NativeWindow.contextmenus.SelectorContext;
exports.linkBookmarkableContext = recent.NativeWindow.contextmenus.linkBookmarkableContext;
exports.linkShareableContext = recent.NativeWindow.contextmenus.linkShareableContext;
exports.linkOpenableContext = recent.NativeWindow.contextmenus.linkOpenableContext;
exports.imageSaveableContext = recent.NativeWindow.contextmenus.imageSaveableContext;
 
/**
* opts: an options object that includes a name, a context and a callback.
*/
function addContextMenu(opts) {
recent.NativeWindow.contextmenus.add(
opts.name,
opts.context,
opts.callback
);
};
 
exports.addContextMenu = addContextMenu;
 
/**
* show an android toast. Not particularly useful except for
* in-app notifications or debugging messages?
*/
function showToast(opts) {
let duration = opts.duration || 'short';
recent.NativeWindow.toast.show(opts.message, duration);
};
 
exports.showToast = showToast;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.