--- a/browser/components/preferences/in-content/SearchEach.js
+++ b/browser/components/preferences/in-content/SearchEach.js
@@ -1,143 +1,207 @@
console.log('in the SearchEach file');
-let mainSeachEmelemt = document.querySelectorAll('#searchTextIMF');
+let mainSearchElement = document.querySelectorAll('#searchTextIMF');
+
+document.getElementById("searchTextIMF").addEventListener("command", searchFunc);
function hideShowSearch () {
-
+
let mainSearchEnable = Services.prefs.getBoolPref('browser.preference.search')
- mainSeachEmelemt.forEach(function (node){
+ mainSearchElement.forEach(function (node){
let vis = node.style;
if (mainSearchEnable)
{
vis.display = 'block';
}
else
{
vis.display = 'none';
}
});
+ //if (!TransientPrefs.prefShouldBeVisible("browser.tabs.warnOnOpen"))
+ // document.getElementById("warnOpenMany").hidden = true
+
+
+
}
-function searchFunc(element) {
- if(mainSeachEmelemt[0].value){
- console.time('SearchTime');
+function searchFunc(event) {
+ let element = event.target;
+ //Controller
+ let controller = getSelectionController();
+ let findSelection = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
+ findSelection.removeAllRanges();
- //Controller
- let controller = getSelectionController();
- let findSelection = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND);
- findSelection.removeAllRanges()
+ if(element.value){
+ console.time('SearchTime');
//Building the range for highlighted areas
let rootPreferences = document.getElementById('mainPrefPane')//.querySelectorAll('*')
let rootPreferencesChildren = rootPreferences.childNodes
//Remove later, used for the debugs
let foundCounter = 0;
for (let i = 0; i<rootPreferences.childElementCount; i++){
- if(nodeRecursion(rootPreferencesChildren[i], mainSeachEmelemt[0].value, findSelection)){
+ if(nodeRecursion(rootPreferencesChildren[i], element.value, findSelection)){
foundCounter++; //<Remove this
rootPreferencesChildren[i].setAttribute('hidden', 'false');
}else{
rootPreferencesChildren[i].setAttribute('hidden', 'true');
}
}
console.log('found and highlighted: ', foundCounter) //<Remove later
console.timeEnd('SearchTime')
} else{
- console.log("Empty string not searching")
+ console.log("Empty string not searching, clearing shit instead");
}
}
-
-mainSeachEmelemt.innerHTML = ''
+mainSearchElement.innerHTML = ''
+mainSearchElement.value = ''
hideShowSearch();
- /**
- * Check that the passed string matches the filter arguments.
- *
- * @param String str
- * to search for filter words in.
- * @param String filter
- * is a string containing all of the words to filter on.
- * @returns boolean
- */
- function stringMatchesFilters (str, filter) {
+/**
+ * Check that the passed string matches the filter arguments.
+ *
+ * @param String str
+ * to search for filter words in.
+ * @param String filter
+ * is a string containing all of the words to filter on.
+ * @returns boolean
+ */
+function stringMatchesFilters (str, filter) {
if (!filter || !str) {
- return true;
+ return true;
}
let searchStr = str.toLowerCase();
let filterStrings = filter.toLowerCase().split(/\s+/);
return !filterStrings.some(function (f) {
- return searchStr.indexOf(f) == -1;
+ return searchStr.indexOf(f) == -1;
});
- }
+}
+function nodeRecursion(nodeObject, searchPhrase, findSelection) {
+ let foundIn = false
+ if(nodeObject.childElementCount == 0){
+ let leafTextNodes, otherTextNodes = []
+ let listOfWords = searchPhrase.trim().split()
+ if(nodeObject){
+ leafTextNodes = textNodesUnder(nodeObject)
+ }
+ if(nodeObject.boxObject){
+ otherTextNodes = textNodesUnder(nodeObject.boxObject)
+ }
+
+ if (leafTextNodes || otherTextNodes){
+ //console.log(nodeObject)
+ //console.log(leafTextNodes,otherTextNodes)
+ }
+
+ leafTextNodes.forEach(function (node) {
+ //console.log(node
+ listOfWords.forEach(function (word){
+ let boolAns = searchWord(node,node.textContent,word,findSelection)
+ foundIn = foundIn || boolAns
+ });
+ });
+ otherTextNodes.forEach(function (node) {
+ //console.log(node)
+ listOfWords.forEach(function (word){
+ let boolAns = searchWord(node,node.textContent,word,findSelection)
+ foundIn = foundIn || boolAns
+ });
+ });
+ }
+ for(let i=0; i<nodeObject.childElementCount; i++){
+ let boolAns = nodeRecursion(nodeObject.childNodes[i], searchPhrase, findSelection)
+ foundIn = foundIn || boolAns
+ //foundIn = foundIn || nodeRecursion(nodeObject.childNodes[i], searchPhrase, findSelection)
+ }
+ return foundIn
+}
+/*
function nodeRecursion(nodeObject, searchPhrase, findSelection) {
- if(nodeObject.childElementCount == 0 &&
- (getTextContentAttribute(nodeObject,searchPhrase) //||
+ console.log(nodeObject)
+ if(nodeObject.childElementCount == 0 //&&
+ //(getTextContentAttribute(nodeObject,searchPhrase) ||
//getLabelAttribute(nodeObject,searchPhrase))
- )) {
+ // (textNodesUnder(nodeObject) || textNodesUnder(nodeObject.boxObject))
+ ) {
//Drill down deeper
//if(nodeObject.boxObject){
// getRangeObject(nodeObject.boxObject, searchPhrase.trim().split(), range);
//}
+
// Finding Text nodes in leaf node
let leaf = textNodesUnder(nodeObject)
let listOfWords = searchPhrase.trim().split()
- console.log("Leaf")
- console.log(leaf)
+ //console.log("Leaf")
+ //console.log(leaf)
leaf.forEach(function (node) {
- console.log(node)
+ //console.log(node)
listOfWords.forEach(function (word){
searchWord(node,node.textContent,word,findSelection)
});
});
-
+ // Checkboxes, radio buttons
let anonymous = textNodesUnder(nodeObject.boxObject)
let anonymousTextContent = ''
+ let anonymousLabelContent = ''
+ let nodeSizes = []
+ let nodeLengthCounter = 0
+ //console.log("anonymousTextContent", nodeObject, anonymous)
anonymous.forEach(function (node) {
anonymousTextContent += node.textContent
+ anonymousLabelContent += node.label
+ nodeLengthCounter += node.length
+ //console.log("itter:",node, anonymousTextContent,anonymousLabelContent,nodeLengthCounter)
+ nodeSizes.push(nodeLengthCounter)
});
- console.log("anonymousTextContent")
- console.log(anonymousTextContent)
-
+
+ //console.log(anonymousTextContent)
+
+ listOfWords.forEach(function (word){
+ multiSearch(anonymous,nodeSizes,anonymousTextContent,word,findSelection)
+ });
+
/*
allTextNodes.forEach(function (node) {
listOfWords.forEach(function (word){
searchWord(node,node.textContent,word,range)
});
});
- */
+ *
return true
}
let foundInChild = false
for (let i = 0; i<nodeObject.childElementCount; i++){
foundInChild = foundInChild || nodeRecursion(nodeObject.childNodes[i],searchPhrase, findSelection)
}
- return foundInChild
+ //return foundInChild
}
+ */
//http://stackoverflow.com/questions/10730309/find-all-text-nodes-in-html-page
function textNodesUnder(node) {
let all = [];
for (node=node.firstChild;node;node=node.nextSibling){
- if (node.nodeType==3) all.push(node);
+ if (node.nodeType===node.TEXT_NODE) all.push(node);
else all = all.concat(textNodesUnder(node));
}
return all;
}
/*
function getRangeObject(elementObject, listOfWords, range){
let firstChildElement = elementObject.firstChild
@@ -165,19 +229,31 @@ hideShowSearch();
// Add each found word to range
for(let i=0;i<indices.length; i++){
let range = document.createRange();
range.setStart(textNode, indices[i]);
range.setEnd(textNode, (indices[i]+word.length) );
findSelection.addRange(range); // Add each range to be highlighted
}
+ return indices.length > 0
+ }
-
+ function multiSearch(textNodes, nodeSizes, textSearch, word, findSelection){
+ let regExp = new RegExp(word,'gi')
+ let result,indices = []
+ while( (result=regExp.exec(textSearch)) ){
+ indices.push(result.index)
+ }
+
+ //console.log("multiSearch")
+ //console.log(textNodes)
+ //console.log(nodeSizes)
+ //console.log(indices)
}
function getTextContentAttribute(nodeObject,searchPhrase){
if(typeof nodeObject.textContent == 'string' && nodeObject.textContent != ''
&& stringMatchesFilters(nodeObject.textContent, searchPhrase)){
/*
words = searchPhrase.trim().split()
for(let i=0; i<words.length; i++){