/* Copyright (c) 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var RelatedSearchFinder = { find: function() { var count = 0; //document.getElementsByClassName('searchterm').each(function(node) { $$('.searchterm').each(function(node) { new RelatedSearch(node, ++count); }); } }; var RelatedSearch = Class.create(); RelatedSearch.prototype = { initialize: function(e, id) { this.holder = e; this.id = id; this.domId = 'relatedsearch' + this.id; var content = this.holder.innerHTML; if (content.blank()) { this.showContent = ''; this.hideContent = ''; } else { this.showContent = '' + content + ''; this.hideContent = '' + content + ''; } this.holder.innerHTML = '' + this.showContent + '
'; this.type = this.holder.hasClassName('using:news') ? 'news' : 'blog'; this.resultStyle = this.holder.hasClassName('withstyle:expanded') ? GSblogBar.RESULT_STYLE_EXPANDED : GSblogBar.RESULT_STYLE_COMPRESSED; this.orderBy = this.holder.hasClassName('orderby:relevance') ? GSearch.ORDER_BY_RELEVANCE : GSearch.ORDER_BY_DATE; this.term = this.getTerm(); this.action = document.getElementsByClassName('action', this.holder)[0]; this.results = document.getElementsByClassName('results', this.holder)[0]; this.setHandler('show'); }, show: function() { this.load(); this.action.innerHTML = this.hideContent; this.setHandler('hide'); }, hide: function() { this.results.hide(); this.action.innerHTML = this.showContent; this.setHandler('show'); }, load: function() { this.results.show(); // show as soon as possible var options = { largeResultSet: false, resultStyle: this.resultStyle, title: "Related content on " + this.term, orderBy: this.orderBy, autoExecuteList: { executeList: [ this.term ] } }; eval("new GS" + this.type + "Bar(this.results, options);"); var titleClass = (this.type == 'news') ? 'titleBox_gsnb' : 'titleBox_gsblb'; var closeAttach = document.getElementsByClassName(titleClass, this.results)[0]; if (closeAttach) { closeAttach.innerHTML = ' ' + closeAttach.innerHTML; var self = this; var closeImage = $('close' + this.domId).onclick = function() { self.hide(); } } }, setHandler: function(showOrHide) { var self = this; $(this.domId).onclick = function() { eval("self." + showOrHide + "();"); // this is a bit naughty, but who cares. } }, /* * Get the search term and reset the abbr title to degrade a little nicer */ getTerm: function() { var title = this.holder.getAttribute("title"); if (match = title.match(/^search for(:)?\s*(.*)/i)) { title = match[2]; } else { this.holder.setAttribute("title", "search for " + title); } return title; } }; Event.observe(window, 'load', RelatedSearchFinder.find, false);