|
Post by Wormopolis on Oct 8, 2010 0:06:35 GMT -8
Browser Tested: IE, Chrome and FF placement: main footer
this code will remember the search words you entered on the search page and when the results come up, it will highlight them with whatever CSS you decide
code:
<style type="text/css"> .highlightresults{background-color:#FF0000;color:#FFFFFF} </style>
<script type="text/javascript"> <!-- // highlight search words in search results // by Wormopolis - www.wormocodes.com // v 1.52 // do not repost - keep header intact
if (pb_action=='search') { function captureWords() { expTime=new Date(); expTime.setFullYear(expTime.setFullYear()+1); document.cookie='searchCapture='+escape(document.searchForm.search.value)+'; expires='+expTime; } if (document.addEventListener) { document.searchForm.addEventListener('submit',captureWords,true); } else { document.searchForm.attachEvent('onsubmit',captureWords); } } if (pb_action=='search2') { function checkChild(obj, rgxtxt) { if (obj.className && obj.className.match(/(code|highlightresults)/i)) return; if (obj.childNodes.length>1) { var ccn=obj.firstChild; while (ccn) { var nxtccn=ccn.nextSibling; checkChild(ccn, rgxtxt); ccn=nxtccn; } } else { if (obj.nodeName.match(/text/i)) { if (obj.nodeValue.match(rgxtxt)) { sp=document.createElement('span'); //shoutout to Eton for the replace hint! sp.innerHTML=obj.nodeValue.replace(rgxtxt,function (str){return '<font class="highlightresults">'+str+'</font>';}); obj.parentNode.replaceChild(sp, obj); } } else { if (obj.firstChild) checkChild(obj.firstChild, rgxtxt); } } }
capturedWords=(document.cookie.match(/searchCapture=(.*?)($|;)/) ? RegExp.$1 : false); if (capturedWords) { capturedWords='('+(unescape(capturedWords)).split(/\s+?/).join('|')+')'; rgxCapturedWords=new RegExp(capturedWords,'ig'); expTime=new Date(); expTime.setFullYear(expTime.setFullYear()-1); document.cookie='searchCapture=null; expires='+expTime; for (tds=document.getElementsByTagName('td'), w=0; w<tds.length; w++) { if (tds[w].width=='80%') { for (fnt=tds[w].getElementsByTagName('font'), f=0; f<fnt.length; f++) { if (fnt[f].innerHTML.match(rgxCapturedWords)) { checkChild(fnt[f], rgxCapturedWords); } } } } } }
// --> </script>
Preview: using it on this site now
|
|
|
Post by Wormopolis on Oct 10, 2010 18:15:31 GMT -8
version update 1.5: upgraded code to remove some loops and a new regexp method to make it faster.
|
|
|
Post by Wormopolis on Oct 14, 2010 17:28:20 GMT -8
version update 1.51: fixed small bug caused by empty search string
|
|
|
Post by Streamstrider on Oct 5, 2011 2:24:25 GMT -8
I tried using it on RS, but it's not working. . . . XD
|
|
|
Post by Wormopolis on Oct 5, 2011 23:54:56 GMT -8
do you see it working on this forum?
as a guest, your entire search form is hidden for some reason.
|
|
|
Post by Streamstrider on Oct 6, 2011 0:19:51 GMT -8
Yeah, it's working here on WormoCodes. Does the code already have a highlight color specified? (And I really don't know why it's not showing. I'll check it momentarily.
|
|
|
Post by Wormopolis on Oct 6, 2011 11:08:16 GMT -8
th code just sets up a classname. what I use here on WC is
<style type="text/css">.highlightresults{background-color:#FF0000;color:#FFFFFF}</style>
added into global headers
|
|
|
Post by Streamstrider on Oct 6, 2011 17:20:16 GMT -8
|
|
|
Post by Wormopolis on Oct 6, 2011 23:07:11 GMT -8
I should probably add that into the code. I guess I figured everyone would just know to do that already since CSS is so widely used.
|
|
|
Post by Streamstrider on Oct 7, 2011 16:09:14 GMT -8
Yeah, but not everyone knows how to add the CSS into the headers or footers and make it work. The way you had it worded, it sounded to me like there was supposed to be a setting in the code for that. Then I could find one, and I got confused about how I was supposed to add a highlight color that specifically related to the code. xD Sometimes I make things a little too complicated. . . .
|
|
|
Post by Wormopolis on Oct 8, 2011 0:23:47 GMT -8
I added in the default CSS to the top of the code. PPL can change it to how they want it to look for their forum.
|
|
|
Post by Streamstrider on Oct 9, 2011 0:39:10 GMT -8
Awesomesauce. Thanks for all the help!
|
|
|
Post by Wormopolis on Jan 18, 2012 21:04:52 GMT -8
version upgrade 1.52: made it work in chrome
|
|
feeleash
Not New Member
Posts: 1
feeleash said 0 great things
|
Post by feeleash on Jan 19, 2012 23:59:36 GMT -8
Hello!
I tried to put the script in main footer and the css in the global header but still nothing happens...
|
|
|
Post by Wormopolis on Jan 22, 2012 21:48:53 GMT -8
does it work for you on THIS site? URL?
|
|