/* 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 + '
' + 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);