Welcome to TalkGraphics.com
Results 1 to 10 of 49

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,882

    Default Re: How do I add a search function

    Quote Originally Posted by Hunterdan II View Post
    The script which Acorn kindly shared is also great, if you don't mind repelling visitors who avoid google. It is a growing trend, as increasingly web users resent having their surfing habits and personal preferences harvested as data to be used in targeted advertising - I am one of those. Plus, the very use of a script that sends you to a google page not very elegant. What this basically communicates to some users is this: "You came here to look at my site, but if you want to search it I am going to send you to a google page without you being aware that it is sending you there (i.e., without your permission)" See the problem? I suggest putting a warning line under the search box (e.g. "Google search"), which then will make it okay, as you're not 'ambushing' your visitors.
    I probably can use the same approach with DuckDuckGo (https://duckduckgo.com/?q=site%3Awww...%2F+minimalist seems to work fine).
    In my defence, I did name the file Javascript - Google Site Search Form.web.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  2. #2
    Join Date
    Dec 2014
    Posts
    4

    Default Re: How do I add a search function

    Quote Originally Posted by Acorn View Post
    I probably can use the same approach with DuckDuckGo (https://duckduckgo.com/?q=site%3Awww...%2F+minimalist seems to work fine).
    In my defence, I did name the file Javascript - Google Site Search Form.web.
    I am so sorry, Acorn, I didn't mean to insinuate anything; you have the interest of the community at heart, this is obvious and I appreciate the great advice and input you've contributed. You are motivated by good intent, and that's what matters, in my book

    Like Jaydear I have little skill with coding, and I gave up on dreamweaver since version 4. It does appear that serif are using javascript, one of the scripts they anchor to are located in a folder called 'wpscripts' and include scripts labelled "jquery.js' and 'jsSiteSearch.js'. I am currently building a site so I had a look at the code generated for the search function. I haven't published it yet so it's not available online.

    Maybe some of the code may help make sense:

    On each page where the search box appears (in the head section):
    <script type="text/javascript" src="wpscripts/jquery.js"></script>
    <script type="text/javascript" src="wpscripts/jquery.wputils.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('#site_search_2_input').keypress(function(event) { if ( event.keyCode == 13 ) window.location.href = 'searchresults.html?site_search_results_1='+docume nt.getElementById('site_search_2_input').value+'&d epth=0&swr=false'; });

    $('#site_search_2_button').click(function(event) { window.location.href = 'searchresults.html?site_search_results_1='+docume nt.getElementById('site_search_2_input').value+'&d epth=0&swr=false'; });

    $("a.ActiveButton").bind({ mousedown:function(){if ( $(this).attr('disabled') === undefined ) $(this).addClass('Activated');}, mouseleave:function(){ if ( $(this).attr('disabled') === undefined ) $(this).removeClass('Activated');}, mouseup:function(){ if ( $(this).attr('disabled') === undefined ) $(this).removeClass('Activated');}});
    });
    </script>

    On the page where the search results appear, in the head:
    <script type="text/javascript" src="wpscripts/jsSiteSearch.js"></script> !!place this in the head!!

    !!SCRIPT!!

    function GetSiteSearchResults(newWindow,frameObject,frameOb jectName,fontFace,fontSize,fontColour,linkFace,lin kSize,linkColour,bgColour,resultsText)
    {
    var sTerms="";
    var iDepth = 0;
    var sURL = new String(window.location.href);
    if (sURL.indexOf("swr=true") != -1)
    return;
    if (sURL.indexOf("?") > 0)
    {
    var arrParams = sURL.split("?" );
    var arrURLParams = arrParams[1].split("&" );
    for (var i=0;i<arrURLParams.length;i++)
    {
    var sParam = arrURLParams[i].split("=" );
    var sValue = decodeURIComponent(sParam[1]);
    if( decodeURIComponent(sParam[0]) == frameObjectName)
    sTerms = sValue;
    if( decodeURIComponent(sParam[0]) == "depth")
    iDepth = parseInt(sValue);
    }
    }
    var d=frameObject.document;
    if (sTerms=="") {d.open(); d.write("<html><head></head><body style=\"background: transparent;\"></body></html>" ); d.close();return;}
    var sBack=""; for (i=0; i<iDepth; i++) sBack+='..\\\\';
    d.open();
    d.write("<!doctype html>" );
    d.write("<html lang=\"en\">" );
    d.write("<head>" );
    d.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" );
    d.write("</head>" );
    d.write("<body style=\"margin: 0px 0px 0px 0px; font-family: "+fontFace+"; font-size: "+fontSize+"; color: "+fontColour+"; background: "+bgColour+";\">" );
    d.write("<div id=\"wpSearchResults\"></div>" );
    d.write("<script type=\"text/javascript\">" );
    d.write("var wordMap = new Array(\" habitasse platea dictumst mauris rutrum enim vitae mauris proin mattis eleifend pede pretium ante amet elit quisque tellus dictum eget dapibus sodales lectus pellentesque molestie adipiscing iaculis quis arcu nulla viverra ultricies velit maecenas magna nisl ipsum rhoncus duis nisi sapien nullam tincidunt fringilla integer curabitur felis erat tempus placerat pellentesque purus diam nunc class aptent taciti sociosqu litora torquent conubia\",\" about \",\" case examples illustrate possibilities opportunities tailored online training learning \",\" access tailored online training from here habitasse platea dictumst mauris rutrum enim vitae mauris proin mattis eleifend pede pretium ante amet elit quisque tellus dictum eget dapibus sodales lectus pellentesque molestie adipiscing iaculis quis arcu nulla viverra ultricies velit maecenas magna nisl ipsum rhoncus duis nisi sapien nullam tincidunt fringilla integer curabitur felis erat tempus placerat pellentesque purus diam nunc class aptent taciti sociosqu litora torquent conubia nostra inceptos hymenaeos aenean risus porttitor vestibulum nibh faucibus justo etiam vulputate egestas neque luctus dolor hendrerit tortor metus turpis tristique lacinia suspendisse potenti feugiat lorem consectetuer cras gravida massa accumsan \",\" resources \",\" recommended links \",\" contact page \",\" terms conditions \",\" search results \",\" \" );" );
    d.write("var pageMap = new Array(\"sitename\",\"About\",\"Cases\",\"Train\",\ "Resources\",\"Links\",\"Contact\",\"terms-and-conditions\",\"search_results\",\"Services_details \" );" );
    d.write("var linkMap = new Array(\"index.html\",\"about.html\",\"page3.html\" ,\"train.html\",\"resources.html\",\"links.html\", \"contact.html\",\"page8.html\",\"searchresults.ht ml\",\"page10.html\" );" );
    d.write("var preMap = new Array(\"placerat pellentesque purus diam nunc class aptent taciti sociosqu litora torquent conubia\",\"About \",\"Case examples to illustrate possibilities and opportunities for tailored online training and learning \",\"In hac habitasse platea dictumst Mauris rutrum enim vitae mauris Proin mattis eleifend pede Sed pretium ante sit amet elit Quisque pede tellus dictum eg\",\"Resources \",\"Recommended links \",\"Contact page \",\"Terms and conditions \",\"Search results \",\"\" );" );
    d.write("function doNav(ind)" );
    d.write("{" );
    if (newWindow)
    d.write(" window.open(\""+sBack+"\"+linkMap[ind],\"_blank\" );" );
    else
    d.write(" parent.window.location.href=linkMap[ind];" );
    d.write("}" );
    d.write("function wpDoSearch(searchTerms){" );
    d.write("var terms = searchTerms.split(\" \" );" );
    d.write("if (terms==\"\") return;" );
    d.write("var results = \"\";" );
    d.write("var resultscount = 0;" );
    d.write("for (var i=0; i<wordMap.length; i++)" );
    d.write("{" );
    d.write(" var found=true;" );
    d.write(" for (var j=0; j<terms.length; j++)" );
    d.write(" if (wordMap[i].indexOf(terms[j].toLowerCase())==-1) found=false;" );
    d.write(" if (found)" );
    d.write(" {" );
    d.write(" results+=\"<a style=\\\"cursor: pointer; font-family: "+linkFace+"; font-size: "+linkSize+"; color: "+linkColour+"; \\\" onclick=\\\"doNav(\"+i+\" );\\\"><u>\"+pageMap[i]+\"</u></a><br>\"+preMap[i]+\"...<br><br>\";" );
    d.write(" resultscount++;" );
    d.write(" }" );
    d.write("}" );
    d.write("document.getElementById(\"wpSearchResults \").innerHTML=resultscount+\" "+resultsText+" \"+searchTerms+\"<br><br>\"+results;" );
    d.write("}" );
    while(sTerms.indexOf("\"") != -1 ) {
    sTerms = sTerms.replace("\"","" );
    };
    d.write("wpDoSearch(\""+sTerms+"\" );" );
    d.write("</script>" );
    d.write("</body></html>" );
    d.close();
    }

    On results page, in the body:
    </div>
    <iframe id="site_search_results_1" name="site_search_results_1" data-results="font-family: 'Verdana'; font-size: 13px; color: #000000;" data-links="font-family: 'Verdana'; font-size: 13px; color: #000000;" style="position:absolute;left:66px;top:166px;width :688px;height:490px;border:none 0px;"></iframe>
    </div>

    Not sure if this will create more confusion than help, but i thought I'd share this info so that someone in the know may be motivated to make sense of it and perhaps develop a similar function for WD.

    Thanks again.
    Last edited by Hunterdan II; 15 December 2014 at 09:12 AM. Reason: correction

 

 

Tags for this Thread

Bookmarks

Posting Permissions

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