Hi Olaf,
Thanks for the "food for thought".
You can visit
www.jobstriker.com again, the functionality you thought
of is implemented.It is simpler than I thought using JQuery. Was just
busy all day job hunting. Man's got to eat, right lol :)
Anyway, dont want to give you the run around so here goes, i dont have
a blog(or want one ;)) or anything and I dont know the depth of how
much you know about html, javascript so im just going to comment my
code to walk you through it, instead of documenting it.
Please do let me know if there is any more clarification needed.
The below code works with JQuery so, if you wish to use vanilla
javascript, this will not work.
hmm. so lets get to it then :)
//Variable boolean value to show/hide close(x) box initialized to
false
var added=false;
function search()
{
//Callback function required by google class--to be called at the end
of a search
var gcscPostSearch={};
gcscPostSearch.uiAddOn=function()
{//checking the above initialized variable's value which is false
the first time
if(!added)
{
//prepending the close button top of the results
$("#results").prepend("<div class='clearsearch'><span
class='navigation_style'>Clear Search / Close (x)</span></div>");
//changing the set value ot the variable to prevent it from getting
written again in the case of multiple search
added=true;
}
//Here - Olaf is how the content div gets hidden
$('#content').hide();
//style for the results -- specific to my site
jobstriker.com ,
obviously change it to suit your needs.
$("#results .gsc-results").css("font-family","Arial,Helvetica,sans-
serif")
.css("border-left","1px solid #D4E0F2")
.css("border-top","1px solid #D4E0F2")
.css("border-right","1px solid #D4E0F2")
.css("border-bottom","1px solid #D4E0F2")
.css("padding","10px 0 10px 10px");
$("#results .gsc-result:link").css("text-decoration","none");
$("#results .gsc-result:hover").css("text-decoration","none");
$("#results .gsc-result:visited").css("text-decoration","none");
$("#results div.gs-visibleUrl.gs-visibleUrl-long").css
("display","none");
$("#results div.gs-visibleUrl.gs-visibleUrl-short").css
("display","none");
$("#results div.gsc-trailing-more-results").css("display","none");
$("#results div.gsc-tabHeader.gsc-tabhActive").css
("display","none");
$("#results .gsc-resultsHeader").css("display","none");
$("#results .gsc-tabsArea").css("display","none");
//styling the clear search button/box
$("#results .clearsearch").css("border-left","1px solid #D4E0F2")
.css("background","#D4E0F2").css("padding","3px 3px 3px 3px")
.css("cursor","pointer").css("float","right");
//here olaf is where we show the content again on click of the close
button
$("#results .clearsearch").click(function(){$('#content').show
(),triggerGoogleSearch();});};
//google stuff :)
var d=new google.search.DrawOptions();
//get a key for your website and place it instead of
YOUR_KEY_GOES_HERE
var c=new google.search.CustomSearchControl("YOUR_KEY_GOES_HERE");
//opens links from the search results in the same window
c.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
//Specify what you want your visitors to read when there are no
results to display
c.setNoResultsString("Sorry! We could not find what you are
looking for.");
//calls the method on google search completion - thanks to Jeff
c.setSearchCompleteCallback
(gcscPostSearch,gcscPostSearch.uiAddOn);
//the input field on your website
d.setInput(document.getElementById("query_input"));
//specify the results div --where results of your search are shown
c.draw(document.getElementById("results"),d);}
//calls googles ajax api
Basically that's it, I have even used jquery to write the input field,
so if a browser has javascript disabled the search box including the
box image, does not get created, nor does the translation.
So basically if you write the box using jquery your site will degrade
well...
//writes the image background of the search box, this is also specific
to my site
just a tip, so if a visitor goes to your site, with javascript
disabled, they wont see the
search box or image...its not hard coded, just generated.
$("#search_box").css({"background-image":"url(http://
www.jobstriker.com/images/bg_search_box.png)","background-repeat":"no-repeat","float":"right","margin-top":"25px","width":"201px","height":"31px"});
//writes the input field
$("#search_box").append(" <input type='text' value='Search'
id='query_input' style='float:left; padding:0; margin:6px 0 0 6px;
border:0; width:159px; background:none' />");
//simple focus on blur clears the "Search" value
$("#query_input").focus(function(){if(this.value==this.defaultValue)
{this.value="";}}).blur(function(){if(!this.value.length)
{this.value=this.defaultValue;}});
Hope this helps buddy, for working example, go to
http://www.jobstriker.com
Cheers,
Jim.
Ps: No donation required lol, did you happen to see the ads on
jobstriker.com ;) hint! hint!
On Nov 5, 8:23 am, Jim <
goreansp...@gmail.com> wrote:
> Hi Olaf,
>
> Thank you, glad you liked the way I implemented the Api using jquery.
>
> It is possible to replace the content with the search, using some
> simple tricks.
> Now, the question arises, if your users are done searching and clear
> the search
> now you would want the original content of the page back.
> So well how you going to do it?
> One solution is to save the content from your main div(which holds all
> your content)
> into a variable, and place it in a session/cookie.
> It will have all the tags, and on clicking the clear button it would/
> should
> write all your content back from that variable into your content div.
>
> I should, add this method is heavy on resources, if you noticedhttp://www.jobstriker.comhas a translation feature, in which
> Mozilla, or Safarihttp://www.jobstriker.comwill load faster than in other browsers as
> ...
>
> read more »