Skip to content

Instantly share code, notes, and snippets.

@darkowlzz
Forked from jeffgca/nativewindow.js
Last active August 29, 2015 14:01
Show Gist options
  • Save darkowlzz/8ca445b3e0fbe2210bbd to your computer and use it in GitHub Desktop.
Save darkowlzz/8ca445b3e0fbe2210bbd to your computer and use it in GitHub Desktop.
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;
/**
* opts: an options object that includes a message, a value, buttons, tab id
* and options for the doorhanger.
* note: tab id is optional, if provided it uses the tab id else it uses the
* current tab id of the browserapp.
*/
function showDoorhanger(opts) {
// if no tabid provided, use the current tab id
let tabId = opts.tabId || recent.BrowserApp.selectedTab.id;
return recent.NativeWindow.doorhanger.show(opts.msg, opts.val, opts.buttons,
tabId, opts.options);
}
exports.showDoorhanger = showDoorhanger;
/**
* opts: an options object that includes a message and a tab id of the hanger.
*/
function hideDoorhanger(opts) {
// if no tabid provided, use the current tab id
let tabId = opts.tabId || recent.BrowserApp.selectedTab.id;
return recent.NativeWindow.doorhanger.hide(opts.val, tabId);
}
exports.hideDoorhanger = hideDoorhanger;
/**
* 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