The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | page.title=Search Results
|
| 2 | @jd:body
|
| 3 |
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 4 | <script src="http://www.google.com/jsapi" type="text/javascript"></script>
|
Scott Main | d644edb | 2010-01-25 14:47:46 -0800 | [diff] [blame] | 5 | <script src="{@docRoot}assets/jquery-history.js" type="text/javascript"></script>
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 6 | <script type="text/javascript">
|
| 7 | var tabIndex = 0;
|
| 8 |
|
| 9 | google.load('search', '1');
|
| 10 |
|
| 11 | function OnLoad() {
|
| 12 | document.getElementById("search_autocomplete").style.color = "#000";
|
| 13 |
|
| 14 | // create search control
|
| 15 | searchControl = new google.search.SearchControl();
|
| 16 |
|
| 17 | // use our existing search form and use tabs when multiple searchers are used
|
| 18 | drawOptions = new google.search.DrawOptions();
|
| 19 | drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
|
| 20 | drawOptions.setInput(document.getElementById("search_autocomplete"));
|
| 21 |
|
| 22 | // configure search result options
|
| 23 | searchOptions = new google.search.SearcherOptions();
|
| 24 | searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
|
| 25 |
|
| 26 | // configure each of the searchers, for each tab
|
| 27 | devSiteSearcher = new google.search.WebSearch();
|
| 28 | devSiteSearcher.setUserDefinedLabel("All");
|
| 29 | devSiteSearcher.setSiteRestriction("001482626316274216503:zu90b7s047u");
|
| 30 |
|
| 31 | devGuideSearcher = new google.search.WebSearch();
|
| 32 | devGuideSearcher.setUserDefinedLabel("Dev Guide");
|
| 33 | devGuideSearcher.setSiteRestriction("http://developer.android.com/guide/");
|
| 34 |
|
| 35 | referenceSearcher = new google.search.WebSearch();
|
| 36 | referenceSearcher.setUserDefinedLabel("Reference");
|
| 37 | referenceSearcher.setSiteRestriction("http://developer.android.com/reference/");
|
| 38 |
|
| 39 | blogSearcher = new google.search.WebSearch();
|
| 40 | blogSearcher.setUserDefinedLabel("Blog");
|
| 41 | blogSearcher.setSiteRestriction("http://android-developers.blogspot.com");
|
| 42 |
|
| 43 | groupsSearcher = new google.search.WebSearch();
|
| 44 | groupsSearcher.setUserDefinedLabel("Developer Groups");
|
| 45 | groupsSearcher.setSiteRestriction("001283715400630100512:ggqrtvkztwm");
|
| 46 |
|
| 47 | sourceSiteSearcher = new google.search.WebSearch();
|
| 48 | sourceSiteSearcher.setUserDefinedLabel("Android Source");
|
| 49 | sourceSiteSearcher.setSiteRestriction("http://source.android.com");
|
| 50 |
|
| 51 | // add each searcher to the search control
|
| 52 | searchControl.addSearcher(devSiteSearcher, searchOptions);
|
| 53 | searchControl.addSearcher(devGuideSearcher, searchOptions);
|
| 54 | searchControl.addSearcher(referenceSearcher, searchOptions);
|
| 55 | searchControl.addSearcher(groupsSearcher, searchOptions);
|
| 56 | searchControl.addSearcher(sourceSiteSearcher, searchOptions);
|
| 57 | searchControl.addSearcher(blogSearcher, searchOptions);
|
| 58 |
|
| 59 | // configure result options
|
| 60 | searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
|
| 61 | searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
|
| 62 | searchControl.setTimeoutInterval(google.search.SearchControl.TIMEOUT_LONG);
|
| 63 | searchControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING);
|
| 64 |
|
| 65 | // upon ajax search, refresh the url and search title
|
| 66 | searchControl.setSearchStartingCallback(this, function(control, searcher, query) {
|
Scott Main | 13e4ee1 | 2011-10-03 15:37:36 -0700 | [diff] [blame] | 67 | $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
| 68 |
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 69 | // save the tab index from the hash
|
| 70 | tabIndex = location.hash.split("&t=")[1];
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 71 | $.history.add('q=' + query + '&t=' + tabIndex);
|
Scott Main | 13e4ee1 | 2011-10-03 15:37:36 -0700 | [diff] [blame] | 72 | });
|
| 73 |
|
| 74 | searchControl.setSearchCompleteCallback(this, function(control, searcher) {
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 75 | openTab();
|
| 76 | });
|
| 77 |
|
| 78 | // draw the search results box
|
| 79 | searchControl.draw(document.getElementById("leftSearchControl"), drawOptions);
|
| 80 |
|
| 81 | // get query and execute the search
|
| 82 | if (location.hash.indexOf("&t=") != -1) {
|
| 83 | searchControl.execute(decodeURI(getQuery(location.hash)));
|
| 84 | }
|
| 85 |
|
| 86 | document.getElementById("search_autocomplete").focus();
|
| 87 | addTabListeners();
|
| 88 | }
|
| 89 | // End of OnLoad
|
| 90 |
|
| 91 |
|
| 92 | google.setOnLoadCallback(OnLoad, true);
|
| 93 |
|
| 94 | // when an event on the browser history occurs (back, forward, load) perform a search
|
| 95 | $(window).history(function(e, hash) {
|
| 96 | var query = decodeURI(getQuery(hash));
|
| 97 | searchControl.execute(query);
|
| 98 |
|
| 99 | $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
| 100 | });
|
| 101 |
|
| 102 | // forcefully regain key-up event control (previously jacked by search api)
|
| 103 | $("#search_autocomplete").keyup(function(event) {
|
| 104 | return search_changed(event, false, '/');
|
| 105 | });
|
| 106 |
|
| 107 | // open a tab, specified by its array position
|
| 108 | function openTab() {
|
| 109 | tabIndex = location.hash.split("&t=")[1];
|
| 110 |
|
| 111 | // show the appropriate tab
|
| 112 | var tabHeaders = $(".gsc-tabHeader");
|
| 113 | $(tabHeaders[tabIndex]).click();
|
| 114 | }
|
| 115 |
|
| 116 | // add event listeners to each tab so we can track the browser history
|
| 117 | function addTabListeners() {
|
| 118 | var tabHeaders = $(".gsc-tabHeader");
|
| 119 | for (var i = 0; i < tabHeaders.length; i++) {
|
| 120 | $(tabHeaders[i]).attr("id",i).click(function() {
|
| 121 | var tabHeaders = $(".gsc-tabHeader");
|
Scott Main | c0cd11f | 2009-09-24 20:33:34 -0700 | [diff] [blame] | 122 | var tabIndex = $(this).attr("id");
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 123 | $.history.add('q=' + getQuery(location.hash) + '&t=' + tabIndex); // update the hash with the new tab
|
| 124 | });
|
| 125 | }
|
| 126 | }
|
| 127 |
|
Scott Main | c0cd11f | 2009-09-24 20:33:34 -0700 | [diff] [blame] | 128 | function getQuery(hash) {
|
Scott Main | 702a6ca | 2011-06-22 12:07:40 -0700 | [diff] [blame] | 129 | var hashParts = hash.split('&t=');
|
| 130 | var queryParts = hashParts[0].split('=');
|
| 131 | return queryParts[1];
|
| 132 | }
|
| 133 |
|
| 134 | /* returns the given string with all HTML brackets converted to entities
|
| 135 | TODO: move this to the site's JS library */
|
| 136 | function escapeHTML(string) {
|
| 137 | return string.replace(/</g,"<")
|
| 138 | .replace(/>/g,">");
|
| 139 | }
|
| 140 |
|
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | </script>
|
| 142 |
|
| 143 | <div id="mainBodyFixed" style="width:auto; margin:20px">
|
| 144 | <h2 id="searchTitle">search results</h2>
|
| 145 | <img src="{@docRoot}assets/images/hr_gray_main.jpg" />
|
| 146 | <div><br /></div>
|
| 147 | <div id="leftSearchControl" class="search-control">Loading...</div>
|
| 148 | </div>
|