/* The following three functions are taken from http://code.google.com/p/javascript-search-term-highlighter/ Copyright 2004 Dave Lemen 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. */ function parseTerms(query) { var s = query + ''; s = s.replace(/(^|\s)(site|related|link|info|cache):[^\s]*(\s|$)/ig, ' '); s = s.replace(/[^a-z0-9_\-]/ig, ' '); // word chars only. s = s.replace(/(^|\s)-/g, ' '); // +required -excluded ~synonyms s = s.replace(/\b(and|not|or)\b/ig, ' '); s = s.replace(/\b[a-z0-9]\b/ig, ' '); // one char terms return s.split(/\s+/); } function getParamValues(url, parameters) { var params = []; var p = parameters.replace(/,/, ' ').split(/\s+/); if (url.indexOf('?') > 0) { var qs = url.substr(url.indexOf('?') + 1); var qsa = qs.split('&'); for (i = 0; i < qsa.length; i++) { nameValue = qsa[i].split('='); if (nameValue.length != 2) { continue; } for (j = 0; j < p.length; j++) { if (nameValue[0] == p[j]) { params.push(unescape(nameValue[1]).toLowerCase().replace(/\+/g, ' ')); } } } } return params; } function getSearchTerms() { var highlighterParameters = 'q as_q as_epq as_oq query search'; var a = []; var params = getParamValues(document.referrer/*document.location.href*/, highlighterParameters); var terms; for (i = 0; i < params.length; i++) { terms = parseTerms(params[i]); for (j = 0; j < terms.length; j++) { if (terms[j] !== '') { a.push(terms[j].toLowerCase()); } } } return a; } /* The rest of this script is Copyright (c) 2009, Mark Pilgrim, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ var HS = {'visible': 'hide', 'hidden': 'show'}; function hideTOC() { var toc = '‣ show table of contents'; $("#toc").html(toc); } function showTOC() { var toc = ''; var old_level = 1; var level; $('h2,h3').each(function(i, h) { level = parseInt(h.tagName.substring(1), 10); if (level < old_level) { toc += ''; } else if (level > old_level) { toc += '
skip over this code listing'); }); $("pre.screen.cmdline:not(.nd)").each(function(i) { /* add link to command-line help */ this.id = "autopre" + i; }); /* make skip links disappear until you tab to them */ $(".skip a").blur(function() { $(this).css({'position':'absolute','left':'0px','top':'-500px','width':'1px','height':'1px','overflow':'hidden'}); }); $(".skip a").blur(); $(".skip a").focus(function() { $(this).css({'position':'static','width':'auto','height':'auto'}); }); if (!$.browser.msie) { /* synchronized highlighting on callouts and their associated lines within code & screen blocks */ var hip = {'background-color':'#eee','cursor':'default'}; var unhip = {'background-color':'inherit','cursor':'inherit'}; $("pre.code, pre.screen").each(function() { var _this = $(this); window.setTimeout(function() { var s = ''; var ol = _this.next("ol"); var refs = _this.find("a:not([href])"); refs.each(function(i) { var li = ol.find("li:nth-child(" + (i+1) + ")"); s += "
' + clone.html()); win.document.close(); }