1
/// XXX: make it cross browser
4
* make the code below compatible with browsers without
5
* an installed firebug like debugger
7
if (!window.console || !console.firebug) {
8
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
9
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
11
for (var i = 0; i < names.length; ++i)
12
window.console[names[i]] = function() {}
16
* small helper function to urldecode strings
18
jQuery.urldecode = function(x) {
19
return decodeURIComponent(x).replace(/\+/g, ' ');
23
* small helper function to urlencode strings
25
jQuery.urlencode = encodeURIComponent;
28
* This function returns the parsed url parameters of the
29
* current request. Multiple values per key are supported,
30
* it will always return arrays of strings for the value parts.
32
jQuery.getQueryParameters = function(s) {
33
if (typeof s == 'undefined')
34
s = document.location.search;
35
var parts = s.substr(s.indexOf('?') + 1).split('&');
37
for (var i = 0; i < parts.length; i++) {
38
var tmp = parts[i].split('=', 2);
39
var key = jQuery.urldecode(tmp[0]);
40
var value = jQuery.urldecode(tmp[1]);
42
result[key].push(value);
44
result[key] = [value];
50
* small function to check if an array contains
53
jQuery.contains = function(arr, item) {
54
for (var i = 0; i < arr.length; i++) {
62
* highlight a given string on a jquery object by wrapping it in
63
* span elements with the given class name.
65
jQuery.fn.highlightText = function(text, className) {
66
function highlight(node) {
67
if (node.nodeType == 3) {
68
var val = node.nodeValue;
69
var pos = val.toLowerCase().indexOf(text);
70
if (pos >= 0 && !jQuery.className.has(node.parentNode, className)) {
71
var span = document.createElement("span");
72
span.className = className;
73
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
74
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
75
document.createTextNode(val.substr(pos + text.length)),
77
node.nodeValue = val.substr(0, pos);
80
else if (!jQuery(node).is("button, select, textarea")) {
81
jQuery.each(node.childNodes, function() {
86
return this.each(function() {
92
* Small JavaScript module for the documentation.
97
/* this.addContextElements(); -- now done statically */
98
this.fixFirefoxAnchorBug();
99
this.highlightSearchWords();
105
* add context elements like header anchor links
107
addContextElements : function() {
108
for (var i = 1; i <= 6; i++) {
109
$('h' + i + '[@id]').each(function() {
110
$('<a class="headerlink">\u00B6</a>').
111
attr('href', '#' + this.id).
112
attr('title', 'Permalink to this headline').
116
$('dt[@id]').each(function() {
117
$('<a class="headerlink">\u00B6</a>').
118
attr('href', '#' + this.id).
119
attr('title', 'Permalink to this definition').
125
* workaround a firefox stupidity
127
fixFirefoxAnchorBug : function() {
128
if (document.location.hash && $.browser.mozilla)
129
window.setTimeout(function() {
130
document.location.href += '';
135
* highlight the search words provided in the url in the text
137
highlightSearchWords : function() {
138
var params = $.getQueryParameters();
139
var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
141
var body = $('div.body');
142
window.setTimeout(function() {
143
$.each(terms, function() {
144
body.highlightText(this.toLowerCase(), 'highlight');
147
$('<li class="highlight-link"><a href="javascript:Documentation.' +
148
'hideSearchWords()">Hide Search Matches</a></li>')
149
.appendTo($('.sidebar .this-page-menu'));
154
* init the modindex toggle buttons
156
initModIndex : function() {
157
var togglers = $('img.toggler').click(function() {
158
var src = $(this).attr('src');
159
var idnum = $(this).attr('id').substr(7);
160
console.log($('tr.cg-' + idnum).toggle());
161
if (src.substr(-9) == 'minus.png')
162
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
164
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
165
}).css('display', '');
166
if (DOCUMENTATION_OPTIONS.COLLAPSE_MODINDEX) {
172
* init the inline comments
174
initComments : function() {
175
$('.inlinecomments div.actions').each(function() {
176
this.innerHTML += ' | ';
177
$(this).append($('<a href="#">hide comments</a>').click(function() {
178
$(this).parent().parent().toggle();
182
$('.inlinecomments .comments').hide();
183
$('.inlinecomments a.bubble').each(function() {
184
$(this).click($(this).is('.emptybubble') ? function() {
185
var params = $.getQueryParameters(this.href);
186
Documentation.newComment(params.target[0]);
189
$('.comments', $(this).parent().parent()[0]).toggle();
193
$('#comments div.actions a.newcomment').click(function() {
194
Documentation.newComment();
197
if (document.location.hash.match(/^#comment-/))
198
$('.inlinecomments .comments ' + document.location.hash)
203
* helper function to hide the search marks again
205
hideSearchWords : function() {
206
$('.sidebar .this-page-menu li.highlight-link').fadeOut(300);
207
$('span.highlight').removeClass('highlight');
211
* show the comment window for a certain id or the whole page.
213
newComment : function(id) {
214
Documentation.CommentWindow.openFor(id || '');
218
* write a new comment from within a comment view box
220
newCommentFromBox : function(link) {
221
var params = $.getQueryParameters(link.href);
222
$(link).parent().parent().fadeOut('slow');
223
this.newComment(params.target);
227
* make the url absolute
229
makeURL : function(relativeURL) {
230
return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
234
* get the current relative url
236
getCurrentURL : function() {
237
var path = document.location.pathname;
238
var parts = path.split(/\//);
239
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
243
var url = parts.join('/');
244
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
248
* class that represents the comment window
250
CommentWindow : (function() {
251
var openWindows = {};
253
var Window = function(sectionID) {
254
this.url = Documentation.makeURL('@comments/' + Documentation.getCurrentURL()
255
+ '/?target=' + $.urlencode(sectionID) + '&mode=ajax');
256
this.sectionID = sectionID;
258
this.root = $('<div class="commentwindow"></div>');
259
this.root.appendTo($('body'));
260
this.title = $('<h3>New Comment</h3>').appendTo(this.root);
261
this.body = $('<div class="form">please wait...</div>').appendTo(this.root);
262
this.resizeHandle = $('<div class="resizehandle"></div>').appendTo(this.root);
264
this.root.Draggable({
265
handle: this.title[0]
269
left: window.innerWidth / 2 - $(this.root).width() / 2,
270
top: window.scrollY + (window.innerHeight / 2 - 150)
272
this.root.fadeIn('slow');
276
Window.prototype.updateView = function(data) {
278
function update(data) {
280
document.location.hash = '#comment-' + data.commentID;
281
document.location.reload();
284
self.body.html(data.body);
285
$('div.actions', self.body).append($('<input>')
286
.attr('type', 'button')
287
.attr('value', 'Close')
288
.click(function() { self.close(); })
290
$('div.actions input[@name="preview"]')
291
.attr('type', 'button')
292
.click(function() { self.submitForm($('form', self.body)[0], true); });
293
$('form', self.body).bind("submit", function() {
294
self.submitForm(this);
299
self.root.Highlight(1000, '#aadee1');
300
$('div.error', self.root).slideDown(500);
305
if (typeof data == 'undefined')
306
$.getJSON(this.url, function(json) { update(json); });
313
success: function(json) { update(json); }
317
Window.prototype.getFormValue = function(name) {
318
return $('*[@name="' + name + '"]', this.body)[0].value;
321
Window.prototype.submitForm = function(form, previewMode) {
323
author: form.author.value,
324
author_mail: form.author_mail.value,
325
title: form.title.value,
326
comment_body: form.comment_body.value,
327
preview: previewMode ? 'yes' : ''
331
Window.prototype.close = function() {
333
delete openWindows[this.sectionID];
334
this.root.fadeOut('slow', function() {
339
Window.openFor = function(sectionID) {
340
if (sectionID in openWindows)
341
return openWindows[sectionID];
342
return new Window(sectionID);
350
$(document).ready(function() {
351
Documentation.init();