Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Arrow Set the priority to all and not to the FIRST found

    Hi everyone,

    Venegal (Thx) wrote the majority of the following script and I must say , he did a great job.
    there are a few extensions to script that are needed.
    I hope someone can help(if not himself).

    the priority within the searched user words and the found content on the site have been set to "the first found" will be hilited. e.g:

    1. the wonderfull holidays
    2. Sunny holidays
    3. holidays in Spain

    No.1 (div) only would be hilited if the user search words were e.g: "sunny holidays in Spain".
    So this is where I need help: I need the priority to be set so that all three divs would be hilited if the word "holidays" (for example) were searched for.

    I hope I am not asking for too much.

    Thx and greets to Venegal and Old Pedant.

    the Script:

    Code:
    function toggle(id, status){
    	document.getElementById(id).style.visibility = status;
    }
    function populateSearchField(){
    	var specialChars = "\\.+*?[^]$(){}=!<>|:,-=/";
    	var ignoreList = ["a", "the"];
    
    	var i, j, searchFld, keywords;
    	if (!(searchFld = document.getElementsByName('formcontent')[0])) return;
    	if (!(keywords = document.referrer.match(/[pq]=(.*?)&/))) return;
    	var preg_quote = function(str){return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, "\\$1");}
    	keywords = decodeURIComponent(keywords[1]).replace(new RegExp('[' + preg_quote(specialChars) + ']', 'g'), ' ').split(/[\+ ]/);
    	for (i = 0; i < keywords.length; i++){
    		for (j = 0; j < ignoreList.length; j++) if (!keywords[i] || (keywords[i] == ignoreList[j])) {
    			keywords.splice(i--, 1);
    			break;
    		}
    	}
    	searchFld.value = keywords.join(' ');
    }
    
    function keywordMatch(keywords, text) {
    	var result = 0;
    	for (var i in keywords) {
    		if (text.match(new RegExp("(^| )" + keywords[i] + "( |$)", "i"))) {
    			result++;
    		};
    	}
    	return result;
    }
    
    function showTextContent() { 
    	var i, bestMatch, maxNumberOfMatches = 0;
    	var divs = document.getElementById("ts-1").getElementsByTagName('div');
    	var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
    	for (i = 0; i < divs.length; i++) {
    		var div = divs[i];
    		var divcontent = div.lastChild.nodeValue;
    		if ((numberOfMatches = keywordMatch(keywords, divcontent)) > maxNumberOfMatches) {
    			maxNumberOfMatches = numberOfMatches;
    			bestMatch = div;
    		}
    	}
    	if (bestMatch) 
    		bestMatch.onmouseover();
    		
    	else { 
    	
    		toggle('fo-test200','visible');
    	}
    } 
    
    window.onload = function(){
    populateSearchField();
    showTextContent();
    }

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Is that really how it works? This part here
    Code:
    		if ((numberOfMatches = keywordMatch(keywords, divcontent)) > maxNumberOfMatches) {
    			maxNumberOfMatches = numberOfMatches;
    			bestMatch = div;
    		}
    suggests that not the first match is used, but the one where the most words match.

    If you want to highlight all the matching divs, try changing the showTextContent function to something like this:
    Code:
    function showTextContent() { 
    	var i, matches = [];
    	var div, divcontent, divs = document.getElementById("ts-1").getElementsByTagName('div');
    	var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
    
    	for (i = 0; i < divs.length; i++) {
    		div = divs[i];
    		divcontent = div.lastChild.nodeValue;
    		if (keywordMatch(keywords, divcontent)) {
    			matches.push(div);
    		}
    	}
    	if (matches[0]) 
    		for (i = 0; i < matches.length; i++) {
    			matches[i].onmouseover();
    		}	
    	else {	
    		toggle('fo-test200', 'visible');
    	}
    }
    Last edited by venegal; 07-24-2009 at 07:32 PM.

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    hey Vevegal,
    nice to here from you again,


    it didn't work, in fact its exactly the same as before, it simply take the first option

    kind thx for your help

  • #4
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Your secrecy doesn't do you much good.

    Here's an example of that exact same code you got there, the only changes being that the keywords are coming from a DOM element rather than the referrer, and that there is no highlighting but the results are simply printed out. You can clearly see that it is working as expected:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>keyword matches</title>
    
    
    <script type = "text/javascript">
    function toggle(id, status){
    	document.getElementById(id).style.visibility = status;
    }
    function populateSearchField(){
    	var specialChars = "\\.+*?[^]$(){}=!<>|:,-=/";
    	var ignoreList = ["a", "the"];
    
    	var i, j, searchFld, keywords;
    	if (!(searchFld = document.getElementsByName('formcontent')[0])) return;
    	//if (!(keywords = document.referrer.match(/[pq]=(.*?)&/))) return;
    	keywords = ['', document.getElementById('keywords').value];
    	var preg_quote = function(str){return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, "\\$1");}
    	keywords = decodeURIComponent(keywords[1]).replace(new RegExp('[' + preg_quote(specialChars) + ']', 'g'), ' ').split(/[\+ ]/);
    	for (i = 0; i < keywords.length; i++){
    		for (j = 0; j < ignoreList.length; j++) if (!keywords[i] || (keywords[i] == ignoreList[j])) {
    			keywords.splice(i--, 1);
    			break;
    		}
    	}
    	searchFld.value = keywords.join(' ');
    }
    
    function keywordMatch(keywords, text) {
    	var result = 0;
    	for (var i in keywords) {
    		if (text.match(new RegExp("(^| )" + keywords[i] + "( |$)", "i"))) {
    			result++;
    		};
    	}
    	return result;
    }
    
    function showTextContent() { 
    	var i, bestMatch, maxNumberOfMatches = 0;
    	var divs = document.getElementById("ts-1").getElementsByTagName('div');
    	var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
    	for (i = 0; i < divs.length; i++) {
    		var div = divs[i];
    		var divcontent = div.lastChild.nodeValue;
    		if ((numberOfMatches = keywordMatch(keywords, divcontent)) > maxNumberOfMatches) {
    			maxNumberOfMatches = numberOfMatches;
    			bestMatch = div;
    		}
    	}
    	if (bestMatch) 
    //		bestMatch.onmouseover();
    		document.getElementById('result').innerHTML = 'best match: "' + bestMatch.innerHTML + '" with ' + maxNumberOfMatches + ' matches';
    		
    	else { 
    	
    //		toggle('fo-test200','visible');
    		document.getElementById('result').innerHTML = 'no matches';
    	}
    } 
    
    window.onload = function(){
    	populateSearchField();
    	showTextContent();
    }
    
    </script>
    
    </head>
    
    <body>
    
    Keywords:<br />
    <input type="text" id="keywords" value="the sunny holidays in Spain" /><br /><br />
    
    Keywords without ignored words:<br />
    <input type="text" name="formcontent" /><br /><br />
    
    
    The divs:<br />
    <div id="ts-1">
    	<div>the wonderful holidays</div>
    	<div>Sunny holidays</div>
    	<div>holidays in Spain</div>
    </div>
    <br />
    <div id="result"></div>
    </body>
    
    </html>
    So, whatever isn't working, it's not to be found in the snippet you posted, and unless you are willing to show some more there's nothing more I can do.

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Venegal,
    thx for the help...

    the second script that you sent me works well see below.
    Code:
    function showTextContent() { 
     var i, matches = [];
     var div, divcontent, divs = document.getElementById("ts-1").getElementsByTagName('div');
     var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
     
     for (i = 0; i < divs.length; i++) {
      div = divs[i];
      divcontent = div.lastChild.nodeValue;
      if (keywordMatch(keywords, divcontent)) {
       matches.push(div);
      }
     }
     if (matches[0]) 
      for (i = 0; i < matches.length; i++) {
       matches[i].onmouseover(toggle('fo-test2000','visible')); //--------------------mistake here
      } 
     else { 
      toggle('fo-test200', 'visible');
     }
    }
    All divs are hilited
    How can I integrate the:
    Code:
    document.getElementById('fo-test2000').innerHTML = maxNumberOfMatches + " matches"; //-------------------------output code
    into the script ?

    thx a bunch
    Last edited by dododidi; 07-24-2009 at 09:48 PM.

  • #6
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Well how do you want it to be integrated? When only the best match was highlighted, it showed the number of matched keywords of that best match. Now that you highlight a bunch of divs, what dou you want to be shown?

  • #7
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    in the first script that you sent me, the green Div at the top of the page of showed for example " 3 Matches"
    the second script doesn't do that, and as the divs are only hilited, i would also like to show the user why they are hilited.

    added:

    if you take a look again at the vid6back1.html and the vid6bak10.html then you will see what I mean
    Last edited by dododidi; 07-24-2009 at 10:21 PM.

  • #8
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    The second script doesn't do that because I don't know what exactly you want it to show. Say, 3 divs are highlighted. What do you want the green div to show? The number of keyword matches of the one div that matched best? Or the number of matching divs? Or the number of keyword matches of each individual matched div when hovering over them?

    And how exactly do you want to show the user why they are highlighted?

  • #9
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    sorry it appears that I am confusing you.

    I only want the number of matching divs to be shown in the green box.
    the user can already see directly below that box which words he used

  • #10
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Oh, that's not too hard:
    Code:
    function showTextContent(){
        var i, matches = [];
        var div, divcontent, divs = document.getElementById("ts-1").getElementsByTagName('div');
        var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
        
        for (i = 0; i < divs.length; i++) {
            div = divs[i];
            divcontent = div.lastChild.nodeValue;
            if (keywordMatch(keywords, divcontent)) {
                matches.push(div);
            }
        }
        if (matches[0]) {
    		document.getElementById('fo-test2000').innerHTML = matches.length + " matches";
    		for (i = 0; i < matches.length; i++) {
    			matches[i].onmouseover(toggle('fo-test2000', 'visible'));
    		}
    	}
    	else {
    		toggle('fo-test200', 'visible');
    	}
    }
    Edit: Lost a few words during copypasting. Fixed now.
    Last edited by venegal; 07-24-2009 at 11:42 PM.

  • Users who have thanked venegal for this post:

    dododidi (07-24-2009)

  • #11
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    hmmm strange,

    the green div appears but its empty

  • #12
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Brilliant, thx a lot Venegal

    I'll be in touch

  • #13
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Damm it,
    I've been looking at the site in Moz. FF and everthing was just fine, then I had a look in IE7 and nothing works in there.

    before using the new addons in the script it was ok

    take a look at vid6bak10.html

    any ideas?

    I have seen many complaints about .innerHTML

    hier is the complete script:
    Code:
    function disappear(){
    		window.setTimeout("document.getElementById('gaga').style.display='none';",9000);
    	   	window.setTimeout("document.getElementById('ts-1').style.visibility='visible';",9500); 
    	   return false;
    	
    	} 
    	
    	disappear(); {
    	seeme();{
    	
    	}	
       }
    
    function toggle(id, status){
    	document.getElementById(id).style.visibility = status;
    }
    function populateSearchField(){
    	var specialChars = "\\.+*?[^]$(){}=!<>|:,-=/";
    	var ignoreList = ["a", "the"];
    
    	var i, j, searchFld, keywords;
    	if (!(searchFld = document.getElementsByName('formcontent')[0])) return;
    	if (!(keywords = document.referrer.match(/[pq]=(.*?)&/))) return;
    	keywords = ['', document.getElementById('keywords').value];
    	var preg_quote = function(str){return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, "\\$1");}
    	keywords = decodeURIComponent(keywords[1]).replace(new RegExp('[' + preg_quote(specialChars) + ']', 'g'), ' ').split(/[\+ ]/);
    	for (i = 0; i < keywords.length; i++){
    		for (j = 0; j < ignoreList.length; j++) if (!keywords[i] || (keywords[i] == ignoreList[j])) {
    			keywords.splice(i--, 1);
    			break;
    		}
    	}
    	searchFld.value = keywords.join(' ');
    }
    
    function keywordMatch(keywords, text) {
    	var result = 0;
    	for (var i in keywords) {
    		if (text.match(new RegExp("(^| )" + keywords[i] + "( |$)", "i"))) {
    			result++;
    		};
    	}
    	return result;
    }
    
    function showTextContent() { 
     var i, matches = [];
     var div, divcontent, divs = document.getElementById("ts-1").getElementsByTagName('div');
     var keywords = document.getElementsByName('formcontent')[0].value.split(' ');
     
     for (i = 0; i < divs.length; i++) {
      div = divs[i];
      divcontent = div.lastChild.nodeValue;
      if (keywordMatch(keywords, divcontent)) {
       matches.push(div);
      }
     }
     if (matches[0]) {
    		document.getElementById('fo-test2000').innerHTML = matches.length + " matches / Treffer";
    		for (i = 0; i < matches.length; i++) {
    			matches[i].onmouseover(toggle('fo-test2000', 'visible'));
    		}
    	}
    	else {
    		toggle('fo-test200', 'visible');
    	}
    }
    
    
    
    populateSearchField();
    showTextContent();
    Last edited by dododidi; 07-25-2009 at 12:39 AM.

  • #14
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    For starters
    Code:
    {
    	seeme();{
    	
    	}	
       }
    seeme isn't defined. And what about those object literals? That doesn't make much sense.

  • #15
    Regular Coder
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    101
    Thanks
    10
    Thanked 0 Times in 0 Posts
    well I was sure you would find something in there that was wrong
    I wrote thos scripts for the preloader and put them in there without window.onload simply because they loaded after the page, taking up to 20 seconds. So that was just trial and error and it worked perfectly.

    Code:
    seeme();{
    	
    	}
    ok i've taken that out, I seemed to have just forgotten those entries
    Last edited by dododidi; 07-25-2009 at 01:07 AM.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •