From 75815608b97febce430a5f85b7eb7ce737470a12 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 17 Mar 2011 00:40:09 +0100 Subject: First ideas about splitting queries to separate module. --- data/lib/bzpage.js | 67 -------------------------------------------------- data/lib/queries.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/main.js | 1 + 3 files changed, 71 insertions(+), 67 deletions(-) create mode 100644 data/lib/queries.js diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js index 9afb112..d3250ba 100644 --- a/data/lib/bzpage.js +++ b/data/lib/bzpage.js @@ -713,73 +713,6 @@ function getLogin () { return loginStr; } -function getSelection () { - var text = ""; - var selectionObject = window.getSelection(); - if (selectionObject.rangeCount > 0) { - text = selectionObject.getRangeAt(0).toString().trim(); - } - return text; -} - -/** - * Opens a new tab with a query for the given text in the selected component - * - * @param text to be searched for - * @param component String with the component name (maybe latter regexp?) - * @param product (optional) string with the product name, if undefined, - * search in all products - * @return None - * - */ -function queryInNewTab(text, component, product) { - var urlStr = "https://" + window.location.hostname + "/buglist.cgi?query_format=advanced"; - if (product) { - urlStr += "&product=" + product.trim(); - } - if (component) { - if ("equivalentComponents" in constantData) { - var equivCompsArr = constantData.equivalentComponents. - filter(function (REstr) { - return new RegExp(REstr).test(getComponent()); - }, this); - if (equivCompsArr.length > 0) { - component = equivCompsArr[0]; - } - } - urlStr += "&component=" + component.trim(); - } - - // using more complicated query tables here, because they can be more easily - // edited - // for further investigative searches - if (text) { - text = encodeURIComponent(text.trim()); - var searchText = "&field0-0-0=longdesc&type0-0-0=substring&value0-0-0=" - + text - + "&field0-0-1=attach_data.thedata&type0-0-1=substring&value0-0-1=" - + text - + "&field0-0-2=status_whiteboard&type0-0-2=substring&value0-0-2=" - + text; - urlStr += searchText; - postMessage(new Message("OpenURLinTab", urlStr)); - } -} - -/** - * Get the text to search for and prepare other things for the real executive - * function this.queryInNewTab, and run it. - */ -function queryForSelection() { - var text = getSelection(); - if (!text) { - postMessage(new Message("GetClipboard", "queryLocal")); - } - else { - queryInNewTab(text, getComponent(), getProduct()); - } -} - /** * adds a person to the CC list, if it isn't already there * diff --git a/data/lib/queries.js b/data/lib/queries.js new file mode 100644 index 0000000..b43b616 --- /dev/null +++ b/data/lib/queries.js @@ -0,0 +1,70 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; + +function getSelection () { + var text = ""; + var selectionObject = window.getSelection(); + if (selectionObject.rangeCount > 0) { + text = selectionObject.getRangeAt(0).toString().trim(); + } + return text; +} + + +/** + * Opens a new tab with a query for the given text in the selected component + * + * @param text to be searched for + * @param component String with the component name (maybe latter regexp?) + * @param product (optional) string with the product name, if undefined, + * search in all products + * @return None + * + */ +function queryInNewTab(text, component, product) { + var urlStr = "https://" + window.location.hostname + "/buglist.cgi?query_format=advanced"; + if (product) { + urlStr += "&product=" + product.trim(); + } + if (component) { + if ("equivalentComponents" in constantData) { + var equivCompsArr = constantData.equivalentComponents. + filter(function (REstr) { + return new RegExp(REstr).test(getComponent()); + }, this); + if (equivCompsArr.length > 0) { + component = equivCompsArr[0]; + } + } + urlStr += "&component=" + component.trim(); + } + + // using more complicated query tables here, because they can be more easily + // edited + // for further investigative searches + if (text) { + text = encodeURIComponent(text.trim()); + var searchText = "&field0-0-0=longdesc&type0-0-0=substring&value0-0-0=" + + text + + "&field0-0-1=attach_data.thedata&type0-0-1=substring&value0-0-1=" + + text + + "&field0-0-2=status_whiteboard&type0-0-2=substring&value0-0-2=" + + text; + urlStr += searchText; + postMessage(new Message("OpenURLinTab", urlStr)); + } +} + +/** + * Get the text to search for and prepare other things for the real executive + * function this.queryInNewTab, and run it. + */ +function queryForSelection() { + var text = getSelection(); + if (!text) { + postMessage(new Message("GetClipboard", "queryLocal")); + } else { + queryInNewTab(text, getComponent(), getProduct()); + } +} diff --git a/lib/main.js b/lib/main.js index 62c064a..72a5fe8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -116,6 +116,7 @@ var contentScriptLibraries = [ self.data.url('lib/urltest.js'), self.data.url("lib/jumpNextBug.js"), self.data.url("lib/util.js"), + self.data.url("lib/queries.js"), self.data.url("lib/preprocessDuplicates.js"), self.data.url("lib/viewSource.js"), self.data.url("lib/color.js"), -- cgit