33 jQuery.urldecode =
function(
x) {
34 return decodeURIComponent(
x).replace(/\+/g,
' ');
40 jQuery.urlencode = encodeURIComponent;
47 jQuery.getQueryParameters =
function(s) {
48 if (typeof s ==
'undefined')
49 s = document.location.search;
50 var parts = s.substr(s.indexOf(
'?') + 1).split(
'&');
52 for (var i = 0; i < parts.length; i++) {
53 var tmp = parts[i].split(
'=', 2);
54 var key = jQuery.urldecode(tmp[0]);
55 var value = jQuery.urldecode(tmp[1]);
57 result[key].push(value);
59 result[key] = [value];
68 jQuery.fn.highlightText =
function(text, className) {
69 function highlight(node) {
70 if (node.nodeType == 3) {
71 var val = node.nodeValue;
72 var pos = val.toLowerCase().indexOf(text);
73 if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
74 var span = document.createElement(
"span");
75 span.className = className;
76 span.appendChild(document.createTextNode(val.substr(pos, text.length)));
77 node.parentNode.insertBefore(span, node.parentNode.insertBefore(
78 document.createTextNode(val.substr(pos + text.length)),
80 node.nodeValue = val.substr(0, pos);
83 else if (!jQuery(node).is(
"button, select, textarea")) {
84 jQuery.each(node.childNodes,
function() {
89 return this.each(
function() {
98 if (!jQuery.browser) {
99 jQuery.uaMatch =
function(ua) {
100 ua = ua.toLowerCase();
102 var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
103 /(webkit)[ \/]([\w.]+)/.exec(ua) ||
104 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
105 /(msie) ([\w.]+)/.exec(ua) ||
106 ua.indexOf(
"compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
110 browser: match[ 1 ] ||
"",
111 version: match[ 2 ] ||
"0" 115 jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] =
true;
121 var Documentation = {
124 this.fixFirefoxAnchorBug();
125 this.highlightSearchWords();
126 this.initIndexTable();
133 PLURAL_EXPR :
function(n) {
return n == 1 ? 0 : 1; },
138 gettext :
function(string) {
139 var translated = Documentation.TRANSLATIONS[string];
140 if (typeof translated ==
'undefined')
142 return (typeof translated ==
'string') ? translated : translated[0];
145 ngettext :
function(singular, plural, n) {
146 var translated = Documentation.TRANSLATIONS[singular];
147 if (typeof translated ==
'undefined')
148 return (n == 1) ? singular : plural;
149 return translated[Documentation.PLURALEXPR(n)];
152 addTranslations :
function(catalog) {
153 for (var key in catalog.messages)
154 this.TRANSLATIONS[key] = catalog.messages[key];
155 this.PLURAL_EXPR =
new Function(
'n',
'return +(' + catalog.plural_expr +
')');
156 this.LOCALE = catalog.locale;
162 addContextElements :
function() {
163 $(
'div[id] > :header:first').each(
function() {
164 $(
'<a class="headerlink">\u00B6</a>').
165 attr(
'href',
'#' + this.
id).
166 attr(
'title', _(
'Permalink to this headline')).
169 $(
'dt[id]').each(
function() {
170 $(
'<a class="headerlink">\u00B6</a>').
171 attr(
'href',
'#' + this.
id).
172 attr(
'title', _(
'Permalink to this definition')).
181 fixFirefoxAnchorBug :
function() {
182 if (document.location.hash)
183 window.setTimeout(
function() {
184 document.location.href +=
'';
191 highlightSearchWords :
function() {
192 var params = $.getQueryParameters();
193 var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
195 var body = $(
'div.body');
199 window.setTimeout(
function() {
200 $.each(terms,
function() {
201 body.highlightText(this.toLowerCase(),
'highlighted');
204 $(
'<p class="highlight-link"><a href="javascript:Documentation.' +
205 'hideSearchWords()">' + _(
'Hide Search Matches') +
'</a></p>')
206 .appendTo($(
'#searchbox'));
213 initIndexTable :
function() {
214 var togglers = $(
'img.toggler').click(
function() {
215 var src = $(
this).attr(
'src');
216 var idnum = $(
this).attr(
'id').substr(7);
217 $(
'tr.cg-' + idnum).toggle();
218 if (src.substr(-9) ==
'minus.png')
219 $(
this).attr(
'src', src.substr(0, src.length-9) +
'plus.png');
221 $(
this).attr(
'src', src.substr(0, src.length-8) +
'minus.png');
222 }).css(
'display',
'');
223 if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
231 hideSearchWords :
function() {
232 $(
'#searchbox .highlight-link').fadeOut(300);
233 $(
'span.highlighted').removeClass(
'highlighted');
239 makeURL :
function(relativeURL) {
240 return DOCUMENTATION_OPTIONS.URL_ROOT +
'/' + relativeURL;
246 getCurrentURL :
function() {
247 var path = document.location.pathname;
248 var parts = path.split(/\
249 $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\
253 var url = parts.join(
'/');
254 return path.substring(url.lastIndexOf(
'/') + 1, path.length - 1);
259 _ = Documentation.gettext;
261 $(document).ready(
function() {
262 Documentation.init();