Morgan B wrote:how do I clear the selection?
Try this:
Code: Select all
var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection();
if (!selection.isCollapsed) {
selection.collapse(selection.focusNode, selection.focusOffset);
}
You can use an empty string to clear the textarea value.
Code: Select all
document.getElementById("sidebar").contentDocument.
getElementById("web-panels-browser").contentDocument.
getElementById("source").value = "";
Morgan B wrote:tried to use something like listener version
Try something like:
Code: Select all
var uid = "gWebPanelURI_" + this.id; // unique identifier
if (typeof window[uid] == "undefined") {
window[uid] = ""; // declare global variable
}
function openWebPanel2(aTitle, aURI) {
toggleSidebar("viewWebPanelsSidebar", true);
document.getElementById("sidebar-title").value = aTitle;
var sidebar = document.getElementById("sidebar");
if (sidebar.docShell &&
sidebar.contentDocument &&
sidebar.contentDocument.getElementById("web-panels-browser")) {
sidebar.contentWindow.loadWebPanel(aURI);
sidebar.contentDocument.getElementById("web-panels-browser").
addEventListener("load", listener, true);
if (window[uid]) {
window[uid] = "";
sidebar.removeEventListener("load", asyncOpenWebPanel2, true);
}
} else {
if (!window[uid]) {
sidebar.addEventListener("load", asyncOpenWebPanel2, true);
}
window[uid] = aURI;
}
}
function asyncOpenWebPanel2(aEvent) {
var sidebar = document.getElementById("sidebar");
if (window[uid] &&
sidebar.contentDocument &&
sidebar.contentDocument.getElementById("web-panels-browser")) {
sidebar.contentWindow.loadWebPanel(window[uid]);
sidebar.contentDocument.getElementById("web-panels-browser").
addEventListener("load", listener, true);
}
window[uid] = "";
sidebar.removeEventListener("load", asyncOpenWebPanel2, true);
}
function listener(aEvent) {
aEvent.currentTarget.removeEventListener(aEvent.type, listener, true);
aEvent.originalTarget.getElementById("source").value = text;
aEvent.originalTarget.getElementById("gt-submit").click();
}
var title = "Google Translate";
var uri = "http://translate.google.com/?hl=en&eotf=0&sl=en&tl=ru";
var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection();
if (!selection.isCollapsed) {
var text = selection.toString();
openWebPanel2(title, uri);
}
I rewrote the openWebPanel and asyncOpenWebPanel functions in the browser.js file to come up with the code.
http://mxr.mozilla.org/mozilla-release/ ... browser.js