<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CB1, INC. &#187; google</title>
	<atom:link href="http://www.cb1inc.com/category/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cb1inc.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Sep 2011 17:54:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Integrating Google AJAX Search API on Your Website</title>
		<link>http://www.cb1inc.com/2008/09/11/integrating-google-ajax-search-api-on-your-website/</link>
		<comments>http://www.cb1inc.com/2008/09/11/integrating-google-ajax-search-api-on-your-website/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 02:47:40 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[dojo]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I recently had to integrate search capabilities into a website I worked on.  I chose to use the <a href="http://code.google.com/apis/ajaxsearch/">Google AJAX Search API</a>.  I needed the form field display to be very customized and clean.  I do leverage the <a href="http://dojotoolkit.org">Dojo Javascript Toolkit</a> to help with the boilerplate DOM and event stuff.

<div align="center"><img alt="Search Form" src="/sites/default/blog/20080910-searchform.gif"/></div>

The first thing you need to do is <a href="http://code.google.com/apis/ajaxsearch/signup.html">sign up for a new key</a>:

<div align="center"><a href="http://code.google.com/apis/ajaxsearch/signup.html"><img alt="Sign-up for an AJAX Search API Key" src="/sites/default/blog/20080910-signuppage.gif"/></a></div>

Once you get the key, you're ready to start coding your own custom search form.

Begin by adding the the following to your <code>&#60;head&#62;</code> tag:

<pre><code>&#60;script src="http://www.google.com/jsapi?key=&#60;KEY GOES HERE&#62;"
    type="text/javascript"&#62;&#60;/script&#62;</code></pre>

Since my example uses Dojo, you need to include Dojo for my code to work.  If you don't already use Dojo, you can simply include it by adding the following to the &#60;head&#62;:

<pre><code>&#60;script src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"
    type="text/javascript"&#62;&#60;/script&#62;</code></pre>

Next we need to add our code that performs the search. First tell the Google API to load the search API:

<pre><code>&#60;script type="text/javascript"&#62;
google.load("search", "1", {"nocss":true,"nooldnames":true});</code></pre>

Next we need to initialize our page when the page loads:

<pre><code>dojo.addOnLoad(function(){
    var results = dojo.byId("results");
    var cursor = dojo.byId("cursor");
    var ws = new google.search.WebSearch();
    ws.setNoHtmlGeneration();</code></pre>

Be sure to set the domain you want to search.  The LARGE_RESULTSET will return the maximum number of results Google allows, which is usually 8 results.

<pre><code>    ws.setSiteRestriction("example.com");
    ws.setResultSetSize(google.search.Search.LARGE_RESULTSET);</code></pre>

Next we need to tell the <code>WebSearch</code> object the function we want called after the results are returned.  The 3rd argument to <code>setSearchCompleteCallback()</code> is an array with a reference to our <code>WebSearch</code> instance.  This array gets passed to our callback function when the callback is fired.

<pre><code>    ws.setSearchCompleteCallback(null, function(w){
        if(!w.results){return;}
        results.innerHTML = "";
        cursor.innerHTML = "";
        var d = dojo.doc.createElement("div");
        results.appendChild(d);
        for(var i=0,len=w.results.length; i&#60;len; i++){
            var r = w.results[i];</code></pre>

Our <code>WebSearch</code> object has a <code>createResultHtml()</code> function that creates an the DOM nodes of our result, but it adds a bunch of crap and forces the result to open in a new window.  So, to fix that, we use Dojo to go clean up the nodes before adding them to the page.

<pre><code>            w.createResultHtml(r);
            if(r.html){
                var n = r.html.cloneNode(true);
                dojo.query(".gs-visibleUrl", n).forEach(function(p){
                    p.parentNode.removeChild(p);
                });
                dojo.query(".gs-watermark", n).forEach(function(p){
                    p.parentNode.removeChild(p);
                });
                dojo.query("a", n).forEach(function(p){
                    if(p.getAttribute("target")){
                        p.removeAttribute("target");
                    }
                });
                results.appendChild(n);
            }
        }
        if(w.cursor){
            var cn = dojo.doc.createElement("div");
            cn.className = "gsc-cursor";
            var label = dojo.doc.createElement("div");
            label.innerHTML = "Pages:";
            label.className = "label";
            cn.appendChild(label);
            for(var i=0, len=w.cursor.pages.length; i&#60;len; i++){
                var pn = dojo.doc.createElement("div");
                pn.className = "gsc-cursor-page";
                if(i == w.cursor.currentPageIndex){
                    pn.className += " gsc-cursor-current-page";
                }
                pn.innerHTML = w.cursor.pages[i].label;
                pn.idx = i;
                dojo.connect(pn, "onclick", function(evt){
                    ws.gotoPage(evt.target.idx);
                });
                cn.appendChild(pn);
            }
            cursor.appendChild(cn);
        }
    }, [ws]);</code></pre>

If you want to execute a search when the page loads, then you can fire <code>execute()</code> with the criteria.

<pre><code>    ws.execute("");</code></pre>

Finally we need to wire up the search button and form.  We don't care about the event details, we just want to execute the search for the current value in the search criteria field.

<pre><code>    function query(evt){
        dojo.stopEvent(evt);
        ws.execute(dojo.trim(dojo.byId("searchCriteria").value));
    }
    dojo.connect(dojo.byId("searchButton"), "onclick", query);
    dojo.connect(dojo.byId("searchForm"), "onsubmit", query);
});
&#60;/script&#62;</code></pre>

In the body of your page, add the following markup to define the form:

<pre><code>&#60;div&#62;
    &#60;form id="searchForm"&#62;
        &#60;input type="text" autocomplete="off" id="searchCriteria" value=""/&#62;
        &#60;a href="#" id="searchButton"&#62;&#60;span&#62;Search&#60;/span&#62;&#60;/a&#62;
    &#60;/form&#62;
&#60;/div&#62;
&#60;div id="results"&#62;&#60;/div&#62;
&#60;div id="cursor"&#62;&#60;/div&#62;</code></pre>

For clarity, I removed all styling.  One thing you'll notice is the "Search" button is an <code>&#60;a&#62;</code> tag instead of an <code>&#60;input&#62;</code> tag so that it could be more easily be styled.

Aside from our text field and search button, there are some CSS styles you can tweak for the search results and pagination:

<pre><code>&#60;style type="text/css"&#62;
.gs-result{padding:6px 0;}
.gsc-cursor{display:inline;padding:10px 0;}
.gsc-cursor .label{color:#000;display:inline;font-weight:bold;margin-right:8px;}
.gsc-cursor-page{cursor:pointer;color:#00F;display:inline;margin-right:8px;
text-decoration:underline;}
.gsc-cursor-current-page{color:#000;font-weight:bold;text-decoration:none;}
&#60;/style&#62;</code></pre>

That's all there is to it.  Load the page up and do a search!

<div align="center"><img alt="Search Results" src="/sites/default/blog/20080910-searchresults.gif"/></div>
]]></description>
			<content:encoded><![CDATA[<p>I recently had to integrate search capabilities into a website I worked on.  I chose to use the <a href="http://code.google.com/apis/ajaxsearch/">Google AJAX Search API</a>.  I needed the form field display to be very customized and clean.  I do leverage the <a href="http://dojotoolkit.org">Dojo Javascript Toolkit</a> to help with the boilerplate DOM and event stuff.</p>
<div align="center"><img alt="Search Form" src="/wp-content/uploads/2009/12/20080910-searchform.gif"/></div>
<p>The first thing you need to do is <a href="http://code.google.com/apis/ajaxsearch/signup.html">sign up for a new key</a>:</p>
<div align="center"><a href="http://code.google.com/apis/ajaxsearch/signup.html"><img alt="Sign-up for an AJAX Search API Key" src="/wp-content/uploads/2009/12/20080910-signuppage.gif"/></a></div>
<p>Once you get the key, you&#8217;re ready to start coding your own custom search form.</p>
<p>Begin by adding the the following to your <code>&lt;head&gt;</code> tag:</p>
<pre class="brush: xml; title: ;">
&lt;script src=&quot;http://www.google.com/jsapi?key=&lt;KEY GOES HERE&gt;&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Since my example uses Dojo, you need to include Dojo for my code to work.  If you don&#8217;t already use Dojo, you can simply include it by adding the following to the &lt;head&gt;:</p>
<pre class="brush: xml; title: ;">
&lt;script src=&quot;http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Next we need to add our code that performs the search. First tell the Google API to load the search API:</p>
<pre class="brush: xml; title: ;">
&lt;script type=&quot;text/javascript&quot;&gt;
google.load(&quot;search&quot;, &quot;1&quot;, {&quot;nocss&quot;:true,&quot;nooldnames&quot;:true});
</pre>
<p>Next we need to initialize our page when the page loads:</p>
<pre class="brush: jscript; title: ;">
dojo.addOnLoad(function(){
    var results = dojo.byId(&quot;results&quot;);
    var cursor = dojo.byId(&quot;cursor&quot;);
    var ws = new google.search.WebSearch();
    ws.setNoHtmlGeneration();
</pre>
<p>Be sure to set the domain you want to search.  The LARGE_RESULTSET will return the maximum number of results Google allows, which is usually 8 results.</p>
<pre class="brush: jscript; title: ;">
    ws.setSiteRestriction(&quot;example.com&quot;);
    ws.setResultSetSize(google.search.Search.LARGE_RESULTSET);
</pre>
<p>Next we need to tell the <code>WebSearch</code> object the function we want called after the results are returned.  The 3rd argument to <code>setSearchCompleteCallback()</code> is an array with a reference to our <code>WebSearch</code> instance.  This array gets passed to our callback function when the callback is fired.</p>
<pre class="brush: jscript; title: ;">
    ws.setSearchCompleteCallback(null, function(w){
        if(!w.results){return;}
        results.innerHTML = &quot;&quot;;
        cursor.innerHTML = &quot;&quot;;
        var d = dojo.doc.createElement(&quot;div&quot;);
        results.appendChild(d);
        for(var i=0,len=w.results.length; i&amp;lt;len; i++){
            var r = w.results[i];
</pre>
<p>Our <code>WebSearch</code> object has a <code>createResultHtml()</code> function that creates an the DOM nodes of our result, but it adds a bunch of crap and forces the result to open in a new window.  So, to fix that, we use Dojo to go clean up the nodes before adding them to the page.</p>
<pre class="brush: jscript; title: ;">
            w.createResultHtml(r);
            if(r.html){
                var n = r.html.cloneNode(true);
                dojo.query(&quot;.gs-visibleUrl&quot;, n).forEach(function(p){
                    p.parentNode.removeChild(p);
                });
                dojo.query(&quot;.gs-watermark&quot;, n).forEach(function(p){
                    p.parentNode.removeChild(p);
                });
                dojo.query(&quot;a&quot;, n).forEach(function(p){
                    if(p.getAttribute(&quot;target&quot;)){
                        p.removeAttribute(&quot;target&quot;);
                    }
                });
                results.appendChild(n);
            }
        }
        if(w.cursor){
            var cn = dojo.doc.createElement(&quot;div&quot;);
            cn.className = &quot;gsc-cursor&quot;;
            var label = dojo.doc.createElement(&quot;div&quot;);
            label.innerHTML = &quot;Pages:&quot;;
            label.className = &quot;label&quot;;
            cn.appendChild(label);
            for(var i=0, len=w.cursor.pages.length; i&amp;lt;len; i++){
                var pn = dojo.doc.createElement(&quot;div&quot;);
                pn.className = &quot;gsc-cursor-page&quot;;
                if(i == w.cursor.currentPageIndex){
                    pn.className += &quot; gsc-cursor-current-page&quot;;
                }
                pn.innerHTML = w.cursor.pages[i].label;
                pn.idx = i;
                dojo.connect(pn, &quot;onclick&quot;, function(evt){
                    ws.gotoPage(evt.target.idx);
                });
                cn.appendChild(pn);
            }
            cursor.appendChild(cn);
        }
    }, [ws]);
</pre>
<p>If you want to execute a search when the page loads, then you can fire <code>execute()</code> with the criteria.</p>
<pre class="brush: jscript; title: ;">
    ws.execute(&quot;&quot;);
</pre>
<p>Finally we need to wire up the search button and form.  We don&#8217;t care about the event details, we just want to execute the search for the current value in the search criteria field.</p>
<pre class="brush: jscript; title: ;">
    function query(evt){
        dojo.stopEvent(evt);
        ws.execute(dojo.trim(dojo.byId(&quot;searchCriteria&quot;).value));
    }
    dojo.connect(dojo.byId(&quot;searchButton&quot;), &quot;onclick&quot;, query);
    dojo.connect(dojo.byId(&quot;searchForm&quot;), &quot;onsubmit&quot;, query);
});
&lt;/script&gt;
</pre>
<p>In the body of your page, add the following markup to define the form:</p>
<pre class="brush: xml; title: ;">
&lt;div&gt;
    &lt;form id=&quot;searchForm&quot;&gt;
        &lt;input type=&quot;text&quot; autocomplete=&quot;off&quot; id=&quot;searchCriteria&quot; value=&quot;&quot;/&gt;
        &lt;a href=&quot;#&quot; id=&quot;searchButton&quot;&gt;&lt;span&gt;Search&lt;/span&gt;&lt;/a&gt;
    &lt;/form&gt;
&lt;/div&gt;
&lt;div id=&quot;results&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;cursor&quot;&gt;&lt;/div&gt;
</pre>
<p>For clarity, I removed all styling.  One thing you&#8217;ll notice is the &#8220;Search&#8221; button is an <code>&lt;a&gt;</code> tag instead of an <code>&lt;input&gt;</code> tag so that it could be more easily be styled.</p>
<p>Aside from our text field and search button, there are some CSS styles you can tweak for the search results and pagination:</p>
<pre class="brush: css; title: ;">
&lt;style type=&quot;text/css&quot;&gt;
.gs-result{padding:6px 0;}
.gsc-cursor{display:inline;padding:10px 0;}
.gsc-cursor .label{color:#000;display:inline;font-weight:bold;margin-right:8px;}
.gsc-cursor-page{cursor:pointer;color:#00F;display:inline;margin-right:8px;
text-decoration:underline;}
.gsc-cursor-current-page{color:#000;font-weight:bold;text-decoration:none;}
&lt;/style&gt;
</pre>
<p>That&#8217;s all there is to it.  Load the page up and do a search!</p>
<div align="center"><img alt="Search Results" src="/wp-content/uploads/2009/12/20080910-searchresults.gif"/></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2008/09/11/integrating-google-ajax-search-api-on-your-website/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dojo Toolkit Module Moved to Google Code</title>
		<link>http://www.cb1inc.com/2008/08/18/dojo-toolkit-module-moved-to-google-code/</link>
		<comments>http://www.cb1inc.com/2008/08/18/dojo-toolkit-module-moved-to-google-code/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 03:32:49 +0000</pubDate>
		<dc:creator>Chris Barber</dc:creator>
				<category><![CDATA[dojo toolkit module]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Tonight I moved the Dojo Toolkit Module to Google Code!  The new project URL is:

<ul><li>http://code.google.com/p/dojo-toolkit-module/</li></ul>

Why? I simply don't have the time and have lost the desire to continue work on this module.  Who's going to maintain the module from now on?  No idea.  This project needs someone who can take the reins and bring this module into the present.

If you are interested, <a href="http://www.cb1inc.com/contact">contact me</a> and let me know what your thoughts are for the future of the Dojo Toolkit Module.
]]></description>
			<content:encoded><![CDATA[<p>Tonight I moved the Dojo Toolkit Module to Google Code!  The new project URL is:</p>
<ul>
<li><a href="http://code.google.com/p/dojo-toolkit-module">http://code.google.com/p/dojo-toolkit-module</a></li>
</ul>
<p>Why? I simply don&#8217;t have the time and have lost the desire to continue work on this module.  Who&#8217;s going to maintain the module from now on?  No idea.  This project needs someone who can take the reins and bring this module into the present.</p>
<p>If you are interested, <a href="/contact/">contact me</a> and let me know what your thoughts are for the future of the Dojo Toolkit Module.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cb1inc.com/2008/08/18/dojo-toolkit-module-moved-to-google-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

