exports["test Content URL Option"] = function(assert) { const { Panel } = require('sdk/panel'); const URL_STRING = "about:buildconfig"; const HTML_CONTENT = "<html><title>Test</title><p>This is a test.</p></html>"; let dataURL = "data:text/html;charset=utf-8," + encodeURIComponent(HTML_CONTENT); let panel = Panel({ contentURL: URL_STRING }); assert.pass("contentURL accepts a string URL."); assert.equal(panel.contentURL, URL_STRING, "contentURL is the string to which it was set."); panel.destroy(); panel = Panel({ contentURL: dataURL }); assert.pass("contentURL accepts a data: URL."); panel.destroy(); panel = Panel({}); assert.ok(panel.contentURL == null, "contentURL is undefined."); panel.destroy(); assert.throws(() => Panel({ contentURL: "foo" }), /The `contentURL` option must be a valid URL./, "Panel throws an exception if contentURL is not a URL."); };
exports["test Hide Before Show"] = function(assert, done) { const { Panel } = require('sdk/panel'); let showCalled = false; let hideCalled = false; let panel1 = Panel({ onShow: function () { showCalled = true; }, onHide: function () { hideCalled = true; } }); panel1.show(); panel1.hide(); let panel2 = Panel({ onShow: function () { if (showCalled) { assert.ok(hideCalled, 'should not emit show without also emitting hide'); } else { assert.ok(!hideCalled, 'should not emit hide without also emitting show'); } panel1.destroy(); panel2.destroy(); done(); }, }); panel2.show(); };
exports['test Only One Panel Open Concurrently'] = function (assert, done) { const loader = Loader(module); const { Panel } = loader.require('sdk/panel') let panelA = Panel({ contentURL: 'about:buildconfig' }); let panelB = Panel({ contentURL: 'about:buildconfig', onShow: function () { // When loading two panels simulataneously, only the second // should be shown, never showing the first assert.equal(panelA.isShowing, false, 'First panel is hidden'); assert.equal(panelB.isShowing, true, 'Second panel is showing'); panelC.show(); } }); let panelC = Panel({ contentURL: 'about:buildconfig', onShow: function () { assert.equal(panelA.isShowing, false, 'First panel is hidden'); assert.equal(panelB.isShowing, false, 'Second panel is hidden'); assert.equal(panelC.isShowing, true, 'Third panel is showing'); done(); } }); panelA.show(); panelB.show(); };
exports['test panel contextmenu validation'] = function(assert) { const loader = Loader(module); const { Panel } = loader.require('sdk/panel'); let panel = Panel({}); assert.equal(panel.contextMenu, false, 'contextMenu option is `false` by default'); panel.destroy(); panel = Panel({ contextMenu: false }); assert.equal(panel.contextMenu, false, 'contextMenu option is `false`'); panel.contextMenu = true; assert.equal(panel.contextMenu, true, 'contextMenu option accepts boolean values'); panel.destroy(); panel = Panel({ contextMenu: true }); assert.equal(panel.contextMenu, true, 'contextMenu option is `true`'); panel.contextMenu = false; assert.equal(panel.contextMenu, false, 'contextMenu option accepts boolean values'); assert.throws(() => Panel({contextMenu: 1}), /The option "contextMenu" must be one of the following types: boolean, undefined, null/, 'contextMenu only accepts boolean or nil values'); panel = Panel(); assert.throws(() => panel.contextMenu = 1, /The option "contextMenu" must be one of the following types: boolean, undefined, null/, 'contextMenu only accepts boolean or nil values'); loader.unload(); }
exports.main = function(options, callbacks) { console.log("My ID is " + self.id); // Load the sample HTML into a string. var helloHTML = self.data.load("sample.html"); // Let's now modify it... helloHTML = replaceMom(helloHTML); // ... and then create a panel that displays it. var myPanel = panels.Panel({ contentURL: "data:text/html," + helloHTML }); // Load the URL of the sample image. var iconURL = self.data.url("mom.png"); // Create a widget that displays the image. We'll attach the panel to it. // When you click the widget, the panel will pop up. widgets.Widget({ id: "test-widget", label: "Mom", contentURL: iconURL, panel: myPanel }); // If you run cfx with --static-args='{"quitWhenDone":true}' this program // will automatically quit Firefox when it's done. if (options.staticArgs.quitWhenDone) callbacks.quit(); }
function attachBackgroundPage() { var backgroundPage = panel.Panel({ contentURL: "./background.html", contentScriptFile: "./js/bundle-background.js" }); attachWorker(backgroundPage); }
function setupSettingPanel() { return panel.Panel({ width: 420, height: 180, contentURL: data.url('setting.html'), contentScriptFile: [ data.url('jquery-1.6.4.min.js'), data.url("dump.js"), data.url('setting.js') ], contentScriptWhen: 'ready', onShow: function() { this.postMessage({kind: "init", translateLang: storage.translateLang}); }, onHide: function() { this.postMessage({kind: "save"}); }, onMessage: function(msg) { switch (msg.kind) { case 'save': // console.p(msg); storage.translateLang.from = msg.from; storage.translateLang.to = msg.to; break; case 'close': this.hide(); break; } } }); }
function setupPanel() { return panel.Panel({ width: 730, height: 340, contentURL: data.url('text-translate.html'), contentScriptFile: [ data.url('jquery-1.6.4.min.js'), data.url("dump.js"), data.url('text-translate.js') ], contentScriptWhen: 'ready', onShow: function() { }, onHide: function() { }, onMessage: function(msg) { switch (msg.kind) { case 'translate': var self = this, fromLang = msg.from, toLang = (msg.to == "") ? locale.getMylang() : msg.to; // bingTranlator.translate2(msg.text, fromLang, toLang, function(text) { bingTranlator.translatePost(msg.text, fromLang, toLang, function(text) { // notify("Translate!!", text); self.postMessage(text); }); break; case 'close': this.hide(); break; } } }); }
function init() { let pnl = panel.Panel({ width: 620, height: 400, contentURL: data.url("easyshare.html"), contentScriptFile: data.url("easyshare.js"), contentScriptWhen: "ready", onShow: function () { let p = { podUrl: prefs.podUrl, publisherWidth: prefs.publisherWidth, publisherHeight: prefs.publisherHeight, bitlyLogin: prefs.bitlyLogin, bitlyApikey: prefs.bitlyApikey }; this.port.emit("prefs", p); } }); pnl.port.on("warning", function () { const _ = require("sdk/l10n").get; require("sdk/notifications").notify({ text: _("warning").replace(/\\n/g, "\n"), iconURL: data.url("warning.jpg") }); pnl.hide(); }); return pnl; }
exports.init = function(){ panel = Panel.Panel({ width:350, height:150, contentURL: Data.get("html/options-panel.html"), contentScriptFile: [ Data.get("js/get-options.js"), Data.get("js/optionspage.js")] }); panel.on("show",function(){ //send the referrer state to the panel panel.port.emit("show",PrefServ.getter("network.http.sendRefererHeader")); }); panel.port.on("chosen-options",function(state){ // set referer PrefServ.setter("network.http.sendRefererHeader",state) }); };
exports.testChromeInPanel = function(assert, done) { let panel = Panel({ contentURL: "chrome://test/content/panel.html", contentScriptWhen: "start", contentScriptFile: data.url("panel.js") }); var intervalId; panel.once("show", _ => { clearInterval(intervalId); assert.pass("panel shown"); panel.port.once("echo", _ => { assert.pass("got echo"); panel.destroy(); assert.pass("panel is destroyed"); done(); }); panel.port.emit("echo"); }); // NOTE: hack needed to prevents random test timeout (probably due to the // setTimeout used in the 'panel.show' method: // https://github.com/mozilla/addon-sdk/blob/a19bd8c/lib/sdk/panel/utils.js#L78) intervalId = setInterval( _ => { panel.show(); }, 50); };
function onFocus() { browserWindow.removeEventListener("focus", onFocus, true); let panel = Panel({ contentScript: "self.postMessage('')", contentScriptWhen: "end", contentURL: "data:text/html;charset=utf-8,", height: 10, width: 10, onMessage: function (message) { // Make sure that attempting to resize a panel while it isn't // visible doesn't cause an error. panel.resize(1, 1); panel.show(); }, onShow: function () { panel.resize(100,100); panel.hide(); }, onHide: function () { assert.ok((panel.width == 100) && (panel.height == 100), "The panel was resized."); if (activeWindow) activeWindow.focus(); done(); } }); getActiveView(panel); }
exports["test Show Hide Panel"] = function(assert, done) { const { Panel } = require('sdk/panel'); let { getActiveView } = require('sdk/view/core'); let panel = Panel({ contentScript: "self.postMessage('')", contentScriptWhen: "end", contentURL: "data:text/html;charset=utf-8,", onMessage: function (message) { panel.show(); }, onShow: function () { assert.pass("The panel was shown."); assert.equal(this, panel, "The 'this' object is the panel."); assert.equal(this.isShowing, true, "panel.isShowing == true."); panel.hide(); }, onHide: function () { assert.pass("The panel was hidden."); assert.equal(this, panel, "The 'this' object is the panel."); assert.equal(this.isShowing, false, "panel.isShowing == false."); panel.destroy(); done(); } }); getActiveView(panel); };
onMiddleClick: function (e, tbb) { if (!iPanel) { //Do not load it on initialization iPanel = panel.Panel({ width: config.panels.iPanel.width, height: config.panels.iPanel.height, contentURL: data.url('info.html'), contentScriptFile: [ data.url('info/jsoneditor/jsoneditor.js'), data.url('info/info.js') ], contentScriptWhen: 'ready' }); } IDExtractor(tabs.activeTab.url, function (videoID) { if (!videoID) return; iPanel.show(tbb); youtube.videoInfo(videoID).then( function (info) { iPanel.port.emit('info', info); }, function (e) { notify(_('name'), e); } ); }); },
exports.testChromeInPanel = function*(assert) { let panel = Panel({ contentURL: 'chrome://test/content/panel.html', contentScriptWhen: 'end', contentScriptFile: data.url('panel.js') }); yield new Promise(resolve => panel.port.once('start', resolve)); assert.pass('start was emitted'); yield new Promise(resolve => { panel.once('show', resolve); panel.show(); }); assert.pass('panel shown'); yield new Promise(resolve => { panel.port.once('echo', resolve); panel.port.emit('echo'); }); assert.pass('got echo'); panel.destroy(); assert.pass('panel is destroyed'); }
exports["test Change Content URL"] = function(assert, done) { const { Panel } = require('sdk/panel'); const { getActiveView } = require("sdk/view/core"); let panel = Panel({ contentURL: "about:blank", contentScript: "self.port.emit('ready', document.location.href);" }); getActiveView(panel); let count = 0; panel.port.on("ready", function (location) { count++; if (count == 1) { assert.equal(location, "about:blank"); assert.equal(panel.contentURL, "about:blank"); panel.contentURL = "about:buildconfig"; } else { assert.equal(location, "about:buildconfig"); assert.equal(panel.contentURL, "about:buildconfig"); panel.destroy(); done(); } }); };
exports['test nested popups'] = function (assert, done) { let loader = Loader(module); let { Panel } = loader.require('sdk/panel'); let { getActiveView } = loader.require('sdk/view/core'); let url = '<select><option>1<option>2<option>3</select>'; let getContentWindow = panel => { return getActiveView(panel).querySelector('iframe').contentWindow; } let panel = Panel({ contentURL: 'data:text/html;charset=utf-8,' + encodeURIComponent(url), onShow: () => { ready(getContentWindow(panel)).then(({ window, document }) => { let select = document.querySelector('select'); let event = document.createEvent('UIEvent'); event.initUIEvent('popupshowing', true, true, window, null); select.dispatchEvent(event); assert.equal( select, getContentWindow(panel).document.querySelector('select'), 'select is still loaded in panel' ); done(); }); } }); panel.show(); };
exports.main = function() { // this item should only work on textareas // console.log('installing menu item for text areas'); markdownPanel = panel.Panel( { width: 600, height: 200, contentURL: data.url('markdown.html'), contentScriptFile: data.url('markdown-result.js') }); markdownPanel.port.on('hide-panel', function() { markdownPanel.hide(); }); var w = widget.Widget({ id: "markdown-widget", label: "Copy to Markdown results", contentURL: data.url("markdown.png"), panel: markdownPanel, onClick: function() { this.panel.show(); } }); var item = contextMenu.Item({ label: 'Copy as Markdown', image: data.url('markdown.png'), contentScriptFile: data.url('copy-me-some-markdown.js'), onMessage: markdown.handlePaste }); item.context.add(contextMenu.SelectionContext()); };
function addToolbarButtons(){ toolbarButton = ToggleButton({ id:'awesome-screenshot-toolbarbutton', label:'Awesome Screenshot', icon:{ "16":'./img/icon16.png', "32":'./img/icon32.png', "64":'./img/icon64.png' }, onChange:toolbarChange }); popupPanel = panel.Panel({ width:300, height:100, contentURL:data.url('popup.html'), onHide:popupHide }); popupPanel.port.on('capture',function(text){ switch (text){ case 'visible': capture('visible'); break; case 'entire': capture('entire'); break; case 'options': optionsPanel.port.emit("message",{name:'sendoption',data:storage.options}); optionsPanel.show(); break; } popupPanel.hide(); }); }
exports["test Panel Focus Not Set"] = function(assert, done) { const { Panel } = require('sdk/panel'); const FM = Cc["@mozilla.org/focus-manager;1"]. getService(Ci.nsIFocusManager); let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"]. getService(Ci.nsIWindowMediator). getMostRecentWindow("navigator:browser"); // Make sure there is a focused element browserWindow.document.documentElement.focus(); // Get the current focused element let focusedElement = FM.focusedElement; let panel = Panel({ contentURL: "about:buildconfig", onShow: function () { assert.ok(focusedElement !== FM.focusedElement, "The panel takes the focus away."); done(); } }); panel.show(); };
exports["test panel addon global object"] = function*(assert) { const { merge } = require("sdk/util/object"); let loader = Loader(module, null, null, { modules: { "sdk/self": merge({}, self, { data: merge({}, self.data, {url: fixtures.url}) }) } }); const { Panel } = loader.require('sdk/panel'); let panel = Panel({ contentURL: "./test-trusted-document.html" }); panel.show(); yield wait(panel, "show"); panel.port.emit('addon-to-document', 'ok'); yield wait(panel.port, "document-to-addon"); assert.pass("Received an event from the document"); loader.unload(); }
function displayPlayground( selection ) { let tsPanel = panel.Panel({ height: 500, width: 2000, contentURL: 'http://www.typescriptlang.org/Playground/#src=' + selection }); tsPanel.show(); tsPanel.on( 'hide', tsPanel.destroy ); }
// display the config panel when icon is clicked function doConfig(state, isMenu) { if (isMenu==false) { // Toggle listening enableListening(!simpleStorage.storage.enable); return; } var url = tabs.activeTab.url; // only for http(s) sites var match = url.match(new RegExp("^https?:\\/\\/([^/]+)")) var domain = null; var agent = ""; if (match!=null) { domain = match[1]; mydebug("Click:"+simpleStorage.storage.mapping[domain]); var agent = getMatchingAgent(domain); } // Open a new tab in the currently active window. var panels = require('sdk/panel'); var siteConfigDlg = panels.Panel({ width: 640, height: 500, contentURL: require("sdk/self").data.url('config.html'), contentScriptFile: [ data.url('jquery-2.1.3.min.js'), data.url('jquery-ui.min.js'), data.url('config.js') ], // messages from the config panel onMessage: function(params) { // first item: command // second item: data if (params[0]=="add") { var domain = params[1]; var agent = params[2]; if (agent && domain) { mydebug("msg: " + agent); if (agent=="") delete simpleStorage.storage.mapping[domain]; else simpleStorage.storage.mapping[domain] = agent; mydebug("Save:"+simpleStorage.storage.mapping[domain]); siteConfigDlg.hide(); } } else if (params[0]=="remove") { delete simpleStorage.storage.mapping[params[1]]; } else if (params[0]=="enable") { enableListening(params[1]); } }, onShow: function() { this.postMessage([domain, agent, simpleStorage.storage.enable, simpleStorage.storage.mapping]); } }); siteConfigDlg.show(); }
exports.main = function(options, callbacks) { // On a platform with neither dnssd nor avahi-browse, we're SOL. if (!zeroconf.isSupportedPlatform()) { return; } /** Toolbar button. */ var button = ToggleButton({ id: 'ciaociao-btn', label: 'Ciaociao', icon: { '16': self.data.url('img/icon-16.png'), '32': self.data.url('img/icon-32.png'), '48': self.data.url('img/icon-48.png'), '64': self.data.url('img/icon-64.png') }, contextMenu: true, onChange: openPanel }); /** Panel showing the service list. */ var panel = panels.Panel({ contentURL: self.data.url('www/panel.html'), contentScriptFile: self.data.url('js/panel.js'), contentStyleFile: self.data.url('css/panel.css'), onHide: function() { // Unpress toggle button. button.state('window', {checked: false}); } }); /** * Open a clicked link in the panel in a new tab. */ panel.port.on('click', function(msg) { tabs.open(msg); panel.hide(); }); /** * Show panel with (previously discovered) services. */ function openPanel(state) { if (!state.checked) return; panel.port.emit('flush'); zeroconf.discover(panel); panel.show({ position: button }); } }
onMessage: function({ href, location }) { let { width, height } = getWindowDetails(); let panel = Panel({ width: width - Math.round(width * .2), height: height - Math.round(height * .2), contentURL: URL(href, location) }); panel.on('hide', panel.destroy); panel.show(); }
function getPanel(button){ return Panel({ width: config.PANEL_SIZE_UNEXPLAINED.width, height: config.PANEL_SIZE_UNEXPLAINED.height, focus: false, contentURL: data.url("./ui/doorhanger.html"), contentScriptFile: data.url("./ui/doorhanger.js"), onShow: onPanelShow, onHide: onPanelHide }); }
function OpenPanel(url){ var pluspanel=panel.Panel({ height: prefs.height, //Tener configuracion width: prefs.width, //Tener configuracion contentURL: url }); pluspanel.show(); }
function go(){ // on end pageMod.PageMod({ include: "*", contentScriptFile: [data.url("js/lib/jquery-1.11.2.min.js"), data.url("js/artAdder.js"), data.url("js/document_end.js")], onAttach : communication }) // on ready // pageMod.PageMod({ // include: "*", // contentScriptFile: [data.url("js/lib/jquery-1.11.2.min.js"), // data.url("js/document_start.js")], // contentScriptWhen : 'ready' // }) // popup var panel,button panel = panels.Panel({ contentURL: self.data.url("popup.html"), onHide: function (){ button.state('window', {checked: false}) } }) communication(panel) button = ToggleButton({ id: "my-button", label: "Add-Art", icon: { "16": "./images/icon-16.png", "32": "./images/icon-32.png", "64": "./images/icon-64.png" }, onChange: function (state) { if (state.checked) { panel.show({ position: button }) } } }) // installed for the first time? if (!ss.storage.lastOpen) { ss.storage.lastOpen = Date.now() tabs.open('http://add-art.org/update') } }
function handleChange(state) { var panel = panels.Panel({ contentURL: self.data.url("bugBasket.htm"), onHide: handleHide }); if (state.checked) { panel.show({ position: button }); } }
dropdown.port.on('openSettings', function() { var subscriptionCache = ss.storage.subscriptionCache; var settings = Panel({ contentURL: data.url('settings.html'), contentScriptOptions: { subscriptions: subscriptionCache ? subscriptionCache.split("\n") : [], proxyConfig: sp.prefs.proxyConfig, userProxyRules: ProxyRule.findAll(), subscriptionURL: sp.prefs.subscriptionURL }, height: 500, width: 700 }); settings.port.on('updateProxy', function(newValue) { sp.prefs.proxyConfig = newValue; }); settings.port.on('updateRule', function(newRule) { new ProxyRule(newRule).save(); reloadUserProxyRules(); }); settings.port.on('removeRule', function(rule) { console.log('removing rule: ', rule); var ruleInStorage = ProxyRule.find(rule); if (ruleInStorage) { ruleInStorage.destroy(); reloadUserProxyRules(); } }); settings.port.on('updateSubscriptionURL', function(newURL) { console.log("newURL: ", newURL); sp.prefs.subscriptionURL = newURL; // sp.prefs.reloadSubscription = !sp.prefs.reloadSubscription; require('./proxy').reloadSubscription(true, function() { subscriptionCache = ss.storage.subscriptionCache; settings.port.emit('subscriptionUpdatedAt', { updatedAt: new Date(), subscriptions: subscriptionCache ? subscriptionCache.split("\n") : [] }); }); }); settings.show(panelPosition); dropdown.hide(); });