From baub at yahoo.com Tue Apr 19 19:38:26 2005 From: baub at yahoo.com (Christophe) Date: Tue Apr 19 21:46:07 2005 Subject: [Conquery] Fix to selection not working for firefox 1.0.3 Message-ID: <20050420013827.5510.qmail@web31902.mail.mud.yahoo.com> Hello, This is my first message on the list and maybe the issue has been resolved already but I thought I might as well just post this anyway since this is working for me. JS object clean up in FF 1.0.3 prevents some of the objects used by Conquery to work any more. Other objects need to be used. To use the fix on windows: 0- Make sure conquery 1.5.2 is installed. 1- Access the conquery.jar file under C:\Documents and Settings\YOURACCOUNTNAME\Application Data\Mozilla\Firefox\Profiles\a6ftep47.default\extensions\{34fba747-cbc2-4929-b00d-0e523ee94a6f}\chrome 2- Uncompress the jar and replace the conquery.js file under content/conquery with the text file at the bottom of the post. 3- Recompress the jar 4- Restart FF. My very simple changes have been annotated with the baub tag in the conquery.js file. Hope this helps to release an official build soon. -Christophe Baubert ------------------------------------------------------ conquery.js ----------------------------------------------------- var cqrPageSelection = ""; var cqrPageURL = ""; var cqrPageHost = ""; var cqrLinkURL = ""; var cqrImgName = ""; var cqrImgURL = ""; var cqrPageTitle = ""; var cqrAction = ""; var cqrActionPrompt = ""; var cqrConfigLastWillId = ""; var cqrConfigLastWillCtrl = false; var cqrTabRef = ""; var cqrWndRef = ""; if (cqrMailFlag){ var browser = getMessageBrowser(); }else{ var browser = getBrowser(); } //Tools menu handler function HandleToolsMenu(event){ try{ if (event.target.childNodes[0] && (event.target.childNodes[0].id == "menu_ToolsPopup" || event.target.childNodes[0].id == "taskPopup")){ var cqr_cfg = window.document.getElementById('cq-cfg-menu'); //This will require restarting, i know, but perfomance is important :) //cqrHideFromTools = prfs_ReadItem("Main.HideFromTools"); if (cqr_cfg) cqr_cfg.hidden = cqrHideFromTools; } //masking any error }catch(err){} } /// HotMenu. Many thanks to Henrik Gulbrandsen for developing this! function RegisterContextMenuListener(){ browser.addEventListener("contextmenu", HandleContextMenu, true); } function HandleInsertedNode(event){ // somehow this sub breaks up the top menu ("File", "Edit" e.t.c) of Mozilla 1.7a, bild 2004010508 // ...and somehow HotMenu works without this :)) // if (event.target.id == "content"){ // RegisterContextMenuListener(); // } } document.addEventListener("DOMNodeInserted", HandleInsertedNode, false); document.addEventListener("DOMMenuItemActive", HandleToolsMenu, true); RegisterContextMenuListener(); function HandleContextMenu(event){ cqrLinkURL = findParentNode(event.originalTarget, "a"); cqrImgObj = findParentNode(event.originalTarget, "img"); if (cqrImgObj){ cqrImgURL = cqrAbsURI(cqrImgObj.baseURI, cqrImgObj.src); cqrImgName = getFNameFromURI(cqrImgURL); } if (!cqrLinkURL) {cqrLinkURL = ""} //Strange bug in Thunderbird: when passing event.shiftKey to another function, that function //actually gets not boolean value as expected, but whole event object. Have no time to play with this, so: var kShift = ""; if (event.shiftKey || event.ctrlKey ){kShift = "yes"} //kShift = event.shiftKey; prfs_LoadMain(); if ((kShift) && (cqrUseHotMenu)){ //var box = getBrowser().boxObject; var box = browser.boxObject; MouseX = event.screenX - box.screenX + box.x; MouseY = event.screenY - box.screenY + box.y; document.popupNode = event.target; event.preventDefault(); hotmenu(kShift, MouseX, MouseY); } else { //FillMenu(kShift) } } function hotmenu(kShift, x, y){ try{ var hotmenu = window.document.getElementById("cq-hotmenu"); if (!hotmenu) { hotmenu = window.document.createElement("menupopup"); hotmenu.id = "cq-hotmenu"; window.document.documentElement.appendChild(hotmenu); } hotmenu.setAttribute("position", "at_pointer"); //at_pointer FillMenu(kShift, ""); if (cqrMailFlag){ var offx = -210; var offy = -260; } else { var offx = 2; var offy = 2; } //hotmenu.showPopup(browser, MouseX + offx, MouseY + offy, "context", "bottomleft", "topleft"); hotmenu.showPopup(browser, x, y, "context", "", ""); }catch(er){cqerr(er, "hotmenu sub")} } function FillMenu(kShift, allshowif){ try{ var updated = false; var recommend = []; var doc = window.document; var ppMenu = doc.getElementById("cq-ppm"); if ((kShift) && (cqrUseHotMenu)) { ppMenu = doc.getElementById("cq-hotmenu"); } prfs_LoadMain(); lastDirState = rdir(cqrPlugsDir); if (srcupdated()) { updated = "true"; plg_QuickLoadAll(); } getPageParams(); prfs_UpdateEntries(); while (ppMenu.hasChildNodes()) {ppMenu.removeChild(ppMenu.lastChild)} var entries = EntryHash._Items(); for (entry in entries){ if (entries[entry].blocked) continue; if (entries[entry].Context){ var ppItem = doc.createElement("menuitem"); ppItem.setAttribute("class", "menuitem-iconic"); if (!entries[entry].iconpath){ if (cqrHTTPIcon){ icourl = url2host(entries[entry].Action); if (icourl) {ppItem.setAttribute("image", icourl + "/favicon.ico")}; } }else{ ppItem.setAttribute("image", "file://" + entries[entry].iconpath); } ppItem.setAttribute("label", " " + entries[entry].Title); ppItem.setAttribute("tooltiptext", cqrMess.GetStringFromName('cqr.menu.plgToolTip')); ppItem.setAttribute("oncommand", "ProcessEntry(event.ctrlKey, '"+entries[entry].eId+"')"); ppMenu.appendChild(ppItem); }//else{ if (entries[entry].showif){ //re = new RegExp(entries[entry].showif,"im"); re = entries[entry].si_compiled; trg = SubstVars(entries[entry].sitarget, entries[entry]); cqrShowAlternatives=false; //res = re.exec(cqrPageSelection); res = re.exec(trg); re.lastIndex=0; if (res || allshowif){ EntryHash[entries[entry].eId].lastmatch = res; // dump("Matched values:\n"); // for (each in res){ // dump(each + ": " + res[each] + "\n"); // } if (!entries[entry].Context) recommend[entry]=""; } else { EntryHash[entries[entry].eId].lastmatch = []; EntryHash[entries[entry].eId].lastmatch[0] = trg; } } // } } if (recommend.length){ ppMenu.appendChild(doc.createElement("menuseparator")); for (each in recommend){ var ppItem = doc.createElement("menuitem"); ppItem.setAttribute("class", "menuitem-iconic"); if (!entries[each].iconpath){ if (cqrHTTPIcon){ icourl = url2host(entries[each].Action); if (icourl) {ppItem.setAttribute("image", icourl + "/favicon.ico")}; } }else{ ppItem.setAttribute("image", "file://" + entries[each].iconpath); } ppItem.setAttribute("label", entries[each].Title); ppItem.setAttribute("tooltiptext", cqrMess.GetStringFromName('cqr.menu.plgToolTip')); ppItem.setAttribute("oncommand", "ProcessEntry(event.ctrlKey, '"+entries[each].eId+"')"); ppMenu.appendChild(ppItem); } } lastDirState = null; ppMenu = null; ppItem = null; entries = null; //masking any possible error }catch(er){} } function detecttrg(evnt){ if (evnt.originalTarget.localName == "menuseparator") FillMenu(false,true); } function ProcessEntry(ctrl, EntryId){ //getPageParams(); var entry = EntryHash._Item(EntryId); if (ctrl) cqrShowAlternatives = true; //if plugin not loaded - load it if (!entry.Inputs){ entry = plg_ReadData(entry.filepath); entry.Context = EntryHash[EntryId].Context; entry.lastmatch = EntryHash[EntryId].lastmatch; EntryHash._AddEntryObj(entry, entry.eId); } PrepareAction(entry); if (cqrcancel){ resetenv(); return; } if (cqrMailFlag){ //doc = window.document; try{ if (entry.Action){ var cqrurl = cqrAction; } else { var cqrurl = entry.Action; } firstpass = true; for (each in QueryHash){ if (firstpass){ cqrurl = cqrurl + "?" + each + "=" + QueryHash[each]; firstpass = false; } else { cqrurl = cqrurl + "&" + each + "=" + QueryHash[each]; } } var mess = Components.classes["@mozilla.org/messenger;1"].getService(Components.interfaces.nsIMessenger); mess.launchExternalURL(encodeURI(cqrurl)); resetenv(); return; }catch(er){cqerr(er, "ProcessEntry sub (mail)")} } //var browser = getBrowser(); if ((cqrAction) && (!entry.Inputs)){ if (cqrOpenRes != "win_fg") { tab = browser.addTab(cqrAction); if (cqrOpenRes == "tab_fg") browser.selectedTab = tab; } else { window.open(cqrAction); } resetenv(); return; } if ((cqrOpenRes == "win_fg") || (cqrOpenRes == "win_bg")) { myTabRef = window.open(); if (cqrOpenRes == "win_bg") window.focus(); } else { myTabRef = browser.addTab(); if (cqrOpenRes == "tab_fg") browser.selectedTab = myTabRef; } window.setTimeout('formIt("'+ EntryId + '");', 70); } function formIt(EntryId){ var entry = EntryHash._Item(EntryId); if ((cqrOpenRes == "win_fg") || (cqrOpenRes == "win_bg")) { doc = myTabRef.document; } else { tabBr = getBrowser().getBrowserForTab(myTabRef); doc = tabBr.contentDocument; } try{ var sbmt = null; var frm = doc.createElementNS("http://www.w3.org/1999/xhtml", "form"); frm.setAttribute("name", "cqrform"); if (entry.Action){ frm.setAttribute("action", cqrAction); } else { frm.setAttribute("action", entry.Action); } frm.setAttribute("method", entry.Method); frm.setAttribute("style", "display: none;"); frm.setAttribute("accept-charset", entry.qcharset); if (cqrMailFlag) frm.setAttribute("target", "_blank"); for (each in QueryHash){ // we should be aware of :)) if (each == "submit"){ sbmt = doc.createElementNS("http://www.w3.org/1999/xhtml", "input"); sbmt.setAttribute("type", "submit"); sbmt.setAttribute("name", each); sbmt.setAttribute("value", QueryHash[each]); frm.appendChild(sbmt); continue; } var inp = doc.createElementNS("http://www.w3.org/1999/xhtml", "input"); inp.setAttribute("type", "hidden"); inp.setAttribute("name", each); inp.setAttribute("value", QueryHash[each]); frm.appendChild(inp); } doc.documentElement.appendChild(frm); if (sbmt!=null){ frm.submit.click(); } else { frm.submit(); } } catch(er){cqerr(er, "formIt sub")} resetenv(); } function PrepareAction(EntryObj){ try{ cqrAction = SubstVars(EntryObj.Action, EntryObj); for (i in EntryObj.Inputs){ QueryHash[EntryObj.Inputs[i].def.name] = SubstVars(EntryObj.Inputs[i].def.value, EntryObj); } if (cqrShowAlternatives) window.openDialog("chrome://conquery/content/list.xul","_blank", "centerscreen,chrome,modal,resizable=yes", EntryObj); }catch(er){cqerr(er, "PrepareAction sub")} } function SubstVars(str, EntryObj){ var retstr = ""; //ire = new RegExp("\\[:(\\w+)(:(\\d*))?\\]", "ig"); cqrvars = cqrSIRe.exec(str); //si_target = EntryObj.sitarget; lastind = 0; if (cqrvars){ while (cqrvars){ tmpstr = str.substring(lastind, cqrSIRe.lastIndex); switch("[:"+cqrvars[1]+"]"){ case "[:selection]": if (!cqrPageSelection) cqrShowAlternatives=true; retstr += tmpstr.replace("[:selection]", cqrPageSelection); break; case "[:url]": retstr += tmpstr.replace("[:url]", cqrPageURL); break; case "[:linkurl]": retstr += tmpstr.replace("[:linkurl]", cqrLinkURL); break; case "[:imgurl]": retstr += tmpstr.replace("[:imgurl]", cqrImgURL); break; case "[:imgname]": retstr += tmpstr.replace("[:imgname]", cqrImgName); break; case "[:host]": retstr += tmpstr.replace("[:host]", cqrPageHost); break; case "[:title]": retstr += tmpstr.replace("[:title]", cqrPageTitle); break; case "[:text]": retstr += tmpstr.replace("[:text]", ""); break; case "[:matched]": var matchnum = Number(cqrvars[3]); if (isNaN(matchnum)) matchnum = 0; if (EntryObj.lastmatch[matchnum]){ retstr += tmpstr.replace(cqrvars[0], EntryObj.lastmatch[matchnum]); }else{ retstr += tmpstr.replace(cqrvars[0], ""); } break; case "[:prompt]": cqrShowAlternatives=true; retstr += tmpstr.replace("[:prompt]", ""); break; //if variable is not recognized default: retstr += tmpstr; } //ire.lastIndex = 0; lastind = cqrSIRe.lastIndex; cqrvars = cqrSIRe.exec(str); } retstr += str.substring(lastind); } else {retstr = str} return retstr; } function processRe(){ } function OpenCfgDialog(){ window.openDialog("chrome://conquery/content/conquery-pref.xul", cqrMess.GetStringFromName('cqr.cfg.wTitle'), "centerscreen,chrome,modal,resizable=yes"); if (cqrConfigLastWillId){ ProcessEntry(cqrConfigLastWillCtrl, cqrConfigLastWillId); cqrConfigLastWillId = ""; } } function getPageParams(){ var focusedWindow = document.commandDispatcher.focusedWindow; //baub line bellow before change to fix empty selection // cqrPageSelection = String(focusedWindow.__proto__.getSelection.call(focusedWindow)); var cqrd = window._content.document; //baub addition for fix cqrPageSelection = cqrd.getSelection?cqrd.getSelection():'';//baub addition for fix try{ cqrPageURL = focusedWindow.location.href; }catch(er){cqrPageURL=""} try{ cqrPageHost = focusedWindow.location.host; }catch(er){cqrPageHost=""} try{ cqrPageTitle = focusedWindow.document.title; }catch(er){cqrPageTitle=""} } function resetenv(){ QueryHash = new Object(); cqrPageSelection = ""; cqrPageURL = ""; cqrPageHost = ""; cqrLinkURL = ""; cqrImgName = ""; cqrImgURL = ""; cqrPageTitle = ""; cqrAction = ""; cqrConfigLastWillId = ""; cqrConfigLastWillCtrl = false; cqrShowAlternatives = false; cqrcancel = false; cqrTabRef = ""; cqrWndRef = ""; }