ulalume3@11: /* ulalume3@11: * doctools.js ulalume3@11: * ~~~~~~~~~~~ ulalume3@11: * ulalume3@11: * Sphinx JavaScript utilities for all documentation. ulalume3@11: * ulalume3@11: * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. ulalume3@11: * :license: BSD, see LICENSE for details. ulalume3@11: * ulalume3@11: */ ulalume3@11: ulalume3@11: /** ulalume3@11: * select a different prefix for underscore ulalume3@11: */ ulalume3@11: $u = _.noConflict(); ulalume3@11: ulalume3@11: /** ulalume3@11: * make the code below compatible with browsers without ulalume3@11: * an installed firebug like debugger ulalume3@11: if (!window.console || !console.firebug) { ulalume3@11: var names = ["log", "debug", "info", "warn", "error", "assert", "dir", ulalume3@11: "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", ulalume3@11: "profile", "profileEnd"]; ulalume3@11: window.console = {}; ulalume3@11: for (var i = 0; i < names.length; ++i) ulalume3@11: window.console[names[i]] = function() {}; ulalume3@11: } ulalume3@11: */ ulalume3@11: ulalume3@11: /** ulalume3@11: * small helper function to urldecode strings ulalume3@11: */ ulalume3@11: jQuery.urldecode = function(x) { ulalume3@11: return decodeURIComponent(x).replace(/\+/g, ' '); ulalume3@11: } ulalume3@11: ulalume3@11: /** ulalume3@11: * small helper function to urlencode strings ulalume3@11: */ ulalume3@11: jQuery.urlencode = encodeURIComponent; ulalume3@11: ulalume3@11: /** ulalume3@11: * This function returns the parsed url parameters of the ulalume3@11: * current request. Multiple values per key are supported, ulalume3@11: * it will always return arrays of strings for the value parts. ulalume3@11: */ ulalume3@11: jQuery.getQueryParameters = function(s) { ulalume3@11: if (typeof s == 'undefined') ulalume3@11: s = document.location.search; ulalume3@11: var parts = s.substr(s.indexOf('?') + 1).split('&'); ulalume3@11: var result = {}; ulalume3@11: for (var i = 0; i < parts.length; i++) { ulalume3@11: var tmp = parts[i].split('=', 2); ulalume3@11: var key = jQuery.urldecode(tmp[0]); ulalume3@11: var value = jQuery.urldecode(tmp[1]); ulalume3@11: if (key in result) ulalume3@11: result[key].push(value); ulalume3@11: else ulalume3@11: result[key] = [value]; ulalume3@11: } ulalume3@11: return result; ulalume3@11: }; ulalume3@11: ulalume3@11: /** ulalume3@11: * small function to check if an array contains ulalume3@11: * a given item. ulalume3@11: */ ulalume3@11: jQuery.contains = function(arr, item) { ulalume3@11: for (var i = 0; i < arr.length; i++) { ulalume3@11: if (arr[i] == item) ulalume3@11: return true; ulalume3@11: } ulalume3@11: return false; ulalume3@11: }; ulalume3@11: ulalume3@11: /** ulalume3@11: * highlight a given string on a jquery object by wrapping it in ulalume3@11: * span elements with the given class name. ulalume3@11: */ ulalume3@11: jQuery.fn.highlightText = function(text, className) { ulalume3@11: function highlight(node) { ulalume3@11: if (node.nodeType == 3) { ulalume3@11: var val = node.nodeValue; ulalume3@11: var pos = val.toLowerCase().indexOf(text); ulalume3@11: if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { ulalume3@11: var span = document.createElement("span"); ulalume3@11: span.className = className; ulalume3@11: span.appendChild(document.createTextNode(val.substr(pos, text.length))); ulalume3@11: node.parentNode.insertBefore(span, node.parentNode.insertBefore( ulalume3@11: document.createTextNode(val.substr(pos + text.length)), ulalume3@11: node.nextSibling)); ulalume3@11: node.nodeValue = val.substr(0, pos); ulalume3@11: } ulalume3@11: } ulalume3@11: else if (!jQuery(node).is("button, select, textarea")) { ulalume3@11: jQuery.each(node.childNodes, function() { ulalume3@11: highlight(this); ulalume3@11: }); ulalume3@11: } ulalume3@11: } ulalume3@11: return this.each(function() { ulalume3@11: highlight(this); ulalume3@11: }); ulalume3@11: }; ulalume3@11: ulalume3@11: /** ulalume3@11: * Small JavaScript module for the documentation. ulalume3@11: */ ulalume3@11: var Documentation = { ulalume3@11: ulalume3@11: init : function() { ulalume3@11: this.fixFirefoxAnchorBug(); ulalume3@11: this.highlightSearchWords(); ulalume3@11: this.initIndexTable(); ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * i18n support ulalume3@11: */ ulalume3@11: TRANSLATIONS : {}, ulalume3@11: PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, ulalume3@11: LOCALE : 'unknown', ulalume3@11: ulalume3@11: // gettext and ngettext don't access this so that the functions ulalume3@11: // can safely bound to a different name (_ = Documentation.gettext) ulalume3@11: gettext : function(string) { ulalume3@11: var translated = Documentation.TRANSLATIONS[string]; ulalume3@11: if (typeof translated == 'undefined') ulalume3@11: return string; ulalume3@11: return (typeof translated == 'string') ? translated : translated[0]; ulalume3@11: }, ulalume3@11: ulalume3@11: ngettext : function(singular, plural, n) { ulalume3@11: var translated = Documentation.TRANSLATIONS[singular]; ulalume3@11: if (typeof translated == 'undefined') ulalume3@11: return (n == 1) ? singular : plural; ulalume3@11: return translated[Documentation.PLURALEXPR(n)]; ulalume3@11: }, ulalume3@11: ulalume3@11: addTranslations : function(catalog) { ulalume3@11: for (var key in catalog.messages) ulalume3@11: this.TRANSLATIONS[key] = catalog.messages[key]; ulalume3@11: this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); ulalume3@11: this.LOCALE = catalog.locale; ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * add context elements like header anchor links ulalume3@11: */ ulalume3@11: addContextElements : function() { ulalume3@11: $('div[id] > :header:first').each(function() { ulalume3@11: $('\u00B6'). ulalume3@11: attr('href', '#' + this.id). ulalume3@11: attr('title', _('Permalink to this headline')). ulalume3@11: appendTo(this); ulalume3@11: }); ulalume3@11: $('dt[id]').each(function() { ulalume3@11: $('\u00B6'). ulalume3@11: attr('href', '#' + this.id). ulalume3@11: attr('title', _('Permalink to this definition')). ulalume3@11: appendTo(this); ulalume3@11: }); ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * workaround a firefox stupidity ulalume3@11: */ ulalume3@11: fixFirefoxAnchorBug : function() { ulalume3@11: if (document.location.hash && $.browser.mozilla) ulalume3@11: window.setTimeout(function() { ulalume3@11: document.location.href += ''; ulalume3@11: }, 10); ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * highlight the search words provided in the url in the text ulalume3@11: */ ulalume3@11: highlightSearchWords : function() { ulalume3@11: var params = $.getQueryParameters(); ulalume3@11: var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; ulalume3@11: if (terms.length) { ulalume3@11: var body = $('div.body'); ulalume3@11: window.setTimeout(function() { ulalume3@11: $.each(terms, function() { ulalume3@11: body.highlightText(this.toLowerCase(), 'highlighted'); ulalume3@11: }); ulalume3@11: }, 10); ulalume3@11: $('
') ulalume3@11: .appendTo($('#searchbox')); ulalume3@11: } ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * init the domain index toggle buttons ulalume3@11: */ ulalume3@11: initIndexTable : function() { ulalume3@11: var togglers = $('img.toggler').click(function() { ulalume3@11: var src = $(this).attr('src'); ulalume3@11: var idnum = $(this).attr('id').substr(7); ulalume3@11: $('tr.cg-' + idnum).toggle(); ulalume3@11: if (src.substr(-9) == 'minus.png') ulalume3@11: $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); ulalume3@11: else ulalume3@11: $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); ulalume3@11: }).css('display', ''); ulalume3@11: if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { ulalume3@11: togglers.click(); ulalume3@11: } ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * helper function to hide the search marks again ulalume3@11: */ ulalume3@11: hideSearchWords : function() { ulalume3@11: $('#searchbox .highlight-link').fadeOut(300); ulalume3@11: $('span.highlighted').removeClass('highlighted'); ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * make the url absolute ulalume3@11: */ ulalume3@11: makeURL : function(relativeURL) { ulalume3@11: return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; ulalume3@11: }, ulalume3@11: ulalume3@11: /** ulalume3@11: * get the current relative url ulalume3@11: */ ulalume3@11: getCurrentURL : function() { ulalume3@11: var path = document.location.pathname; ulalume3@11: var parts = path.split(/\//); ulalume3@11: $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { ulalume3@11: if (this == '..') ulalume3@11: parts.pop(); ulalume3@11: }); ulalume3@11: var url = parts.join('/'); ulalume3@11: return path.substring(url.lastIndexOf('/') + 1, path.length - 1); ulalume3@11: } ulalume3@11: }; ulalume3@11: ulalume3@11: // quick alias for translations ulalume3@11: _ = Documentation.gettext; ulalume3@11: ulalume3@11: $(document).ready(function() { ulalume3@11: Documentation.init(); ulalume3@11: });