erbook 6.1.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/erbook +29 -25
  2. data/doc/HelloWorld.spec +3 -1
  3. data/doc/api/classes/ERBook.html +86 -0
  4. data/doc/api/classes/ERBook/Document.html +399 -0
  5. data/doc/api/classes/ERBook/Document/Node.html +110 -0
  6. data/doc/api/classes/ERBook/Template.html +309 -0
  7. data/doc/api/classes/ERBook/Template/Sandbox.html +134 -0
  8. data/doc/api/classes/RDoc.html +69 -0
  9. data/doc/api/classes/RDoc/AnyMethod.html +249 -0
  10. data/doc/api/classes/RDoc/DummyMarkup.html +60 -0
  11. data/doc/api/classes/RDoc/DummyMixin.html +54 -0
  12. data/doc/api/classes/RDoc/DummyOptions.html +60 -0
  13. data/doc/api/classes/RDoc/TopLevel.html +344 -0
  14. data/doc/api/classes/String.html +212 -0
  15. data/doc/api/created.rid +1 -0
  16. data/doc/api/css/main.css +263 -0
  17. data/doc/api/css/panel.css +383 -0
  18. data/doc/api/css/reset.css +53 -0
  19. data/doc/api/files/ANN_eml.html +276 -0
  20. data/doc/api/files/ANN_html.html +407 -0
  21. data/doc/api/files/ANN_txt.html +271 -0
  22. data/doc/api/files/LICENSE.html +76 -0
  23. data/doc/api/files/lib/erbook/document_rb.html +74 -0
  24. data/doc/api/files/lib/erbook/rdoc_rb.html +77 -0
  25. data/doc/api/files/lib/erbook/template_rb.html +66 -0
  26. data/doc/api/files/lib/erbook/to_xhtml_rb.html +89 -0
  27. data/doc/api/files/lib/erbook_rb.html +70 -0
  28. data/doc/api/i/arrows.png +0 -0
  29. data/doc/api/i/results_bg.png +0 -0
  30. data/doc/api/i/tree_bg.png +0 -0
  31. data/doc/api/index.html +14 -18
  32. data/doc/api/js/jquery-1.3.2.min.js +19 -0
  33. data/doc/api/js/jquery-effect.js +593 -0
  34. data/doc/api/js/main.js +22 -0
  35. data/doc/api/js/searchdoc.js +605 -0
  36. data/doc/api/panel/index.html +63 -0
  37. data/doc/api/panel/search_index.js +1 -0
  38. data/doc/api/panel/tree.js +1 -0
  39. data/doc/formats.erb +63 -115
  40. data/doc/history.erb +125 -92
  41. data/doc/index.erb +12 -7
  42. data/doc/index.xhtml +1020 -1347
  43. data/doc/intro.erb +42 -40
  44. data/doc/setup.erb +18 -18
  45. data/doc/theory.erb +24 -31
  46. data/doc/usage.erb +14 -24
  47. data/fmt/xhtml.icons/index.yaml +16 -14
  48. data/fmt/xhtml.icons/rakefile +33 -0
  49. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/16x16/places/start-here.png +0 -0
  50. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/actions/go-down.png +0 -0
  51. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/actions/go-up.png +0 -0
  52. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/places/start-here.png +0 -0
  53. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/32x32/status/software-update-available.png +0 -0
  54. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/apps/accessories-text-editor.png +0 -0
  55. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/48x48/apps/internet-group-chat.png +0 -0
  56. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/emblems/emblem-important.png +0 -0
  57. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-error.png +0 -0
  58. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-information.png +0 -0
  59. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/48x48/status/dialog-warning.png +0 -0
  60. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/COPYING +1 -0
  61. data/fmt/xhtml.icons/{tango-icon-theme-0.8.1 → tango-icon-theme-0.8.90}/README +0 -0
  62. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/bookmark-new.svg +672 -0
  63. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-down.svg +200 -0
  64. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-home.svg +445 -0
  65. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/go-up.svg +196 -0
  66. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/actions/view-refresh.svg +393 -0
  67. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/apps/accessories-text-editor.svg +554 -0
  68. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/apps/internet-group-chat.svg +312 -0
  69. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/emblems/emblem-favorite.svg +242 -0
  70. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/emblems/emblem-important.svg +164 -0
  71. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/mimetypes/application-certificate.svg +443 -0
  72. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/places/start-here.svg +492 -0
  73. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-error.svg +330 -0
  74. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-information.svg +1159 -0
  75. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/dialog-warning.svg +373 -0
  76. data/fmt/xhtml.icons/tango-icon-theme-0.8.90/scalable/status/software-update-available.svg +209 -0
  77. data/fmt/xhtml.scripts/jquery-1.3.2.min.js +19 -0
  78. data/fmt/xhtml.scripts/jquery.localscroll-1.2.7-min.js +9 -0
  79. data/fmt/xhtml.scripts/jquery.scrollTo-1.4.1-min.js +11 -0
  80. data/fmt/xhtml.yaml +470 -454
  81. data/lang/de.yaml +5 -5
  82. data/lang/el.yaml +4 -4
  83. data/lang/es.yaml +5 -5
  84. data/lang/fr.yaml +5 -5
  85. data/lang/it.yaml +5 -5
  86. data/lang/ja.yaml +4 -4
  87. data/lang/ko.yaml +4 -4
  88. data/lang/nl.yaml +4 -4
  89. data/lang/phrases.yaml +4 -4
  90. data/lang/pt.yaml +5 -5
  91. data/lang/ru.yaml +5 -5
  92. data/lang/zh.yaml +5 -5
  93. data/lang/zt.yaml +5 -5
  94. data/lib/erbook.rb +12 -5
  95. data/lib/erbook/document.rb +127 -107
  96. data/lib/erbook/rdoc.rb +18 -11
  97. data/lib/erbook/template.rb +86 -176
  98. data/lib/erbook/to_xhtml.rb +98 -25
  99. data/{Rakefile → rakefile} +1 -0
  100. metadata +106 -53
  101. data/doc/api/ERBook.html +0 -35
  102. data/doc/api/ERBook/Document.html +0 -669
  103. data/doc/api/ERBook/Document/Node.html +0 -102
  104. data/doc/api/ERBook/Template.html +0 -670
  105. data/doc/api/RDoc.html +0 -23
  106. data/doc/api/RDoc/AnyMethod.html +0 -302
  107. data/doc/api/RDoc/DummyMarkup.html +0 -73
  108. data/doc/api/RDoc/DummyMixin.html +0 -23
  109. data/doc/api/RDoc/DummyOptions.html +0 -140
  110. data/doc/api/RDoc/TopLevel.html +0 -465
  111. data/doc/api/String.html +0 -372
  112. data/doc/api/all-methods.html +0 -253
  113. data/doc/api/all-namespaces.html +0 -42
  114. data/doc/api/app.js +0 -18
  115. data/doc/api/jquery.js +0 -11
  116. data/doc/api/readme.html +0 -38
  117. data/doc/api/style.css +0 -68
  118. data/doc/api/syntax_highlight.css +0 -21
  119. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/48x48/README +0 -2
  120. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/48x48/apps/internet-group-chat.png +0 -0
  121. data/fmt/xhtml.icons/tango-icon-theme-0.8.1/COPYING +0 -67
@@ -0,0 +1,22 @@
1
+ function toggleSource( id )
2
+ {
3
+ var $src = $('#' + id).toggle();
4
+ $('#l_' + id).html($src.css('display') == 'none' ? 'show' : 'hide');
5
+ }
6
+
7
+ function openCode( url )
8
+ {
9
+ window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus();
10
+ }
11
+
12
+
13
+ window.highlight = function(url) {
14
+ var hash = url.match(/#([^#]+)$/)
15
+ if(hash) {
16
+ $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
17
+ }
18
+ }
19
+
20
+ $(function() {
21
+ highlight('#' + location.hash);
22
+ });
@@ -0,0 +1,605 @@
1
+ Searchdoc = {};
2
+
3
+ // navigation.js ------------------------------------------
4
+
5
+ Searchdoc.Navigation = new function() {
6
+ this.initNavigation = function() {
7
+ var _this = this;
8
+
9
+ $(document).keydown(function(e) {
10
+ _this.onkeydown(e);
11
+ }).keyup(function(e) {
12
+ _this.onkeyup(e);
13
+ });
14
+
15
+ this.navigationActive = true;
16
+ }
17
+
18
+ this.setNavigationActive = function(state) {
19
+ this.navigationActive = state;
20
+ this.clearMoveTimeout();
21
+ }
22
+
23
+
24
+ this.onkeyup = function(e) {
25
+ if (!this.navigationActive) return;
26
+ switch(e.keyCode) {
27
+ case 37: //Event.KEY_LEFT:
28
+ case 38: //Event.KEY_UP:
29
+ case 39: //Event.KEY_RIGHT:
30
+ case 40: //Event.KEY_DOWN:
31
+ this.clearMoveTimeout();
32
+ break;
33
+ }
34
+ }
35
+
36
+ this.onkeydown = function(e) {
37
+ if (!this.navigationActive) return;
38
+ switch(e.keyCode) {
39
+ case 37: //Event.KEY_LEFT:
40
+ if (this.moveLeft())
41
+ e.preventDefault();
42
+ break;
43
+ case 38: //Event.KEY_UP:
44
+ if (this.moveUp())
45
+ e.preventDefault();
46
+ this.startMoveTimeout(false);
47
+ break;
48
+ case 39: //Event.KEY_RIGHT:
49
+ if (this.moveRight())
50
+ e.preventDefault();
51
+ break;
52
+ case 40: //Event.KEY_DOWN:
53
+ if (this.moveDown())
54
+ e.preventDefault();
55
+ this.startMoveTimeout(true);
56
+ break;
57
+ case 9: //Event.KEY_TAB:
58
+ case 13: //Event.KEY_RETURN:
59
+ if (this.$current) this.select(this.$current);
60
+ break;
61
+ }
62
+ }
63
+
64
+ this.clearMoveTimeout = function() {
65
+ clearTimeout(this.moveTimeout);
66
+ this.moveTimeout = null;
67
+ }
68
+
69
+ this.startMoveTimeout = function(isDown) {
70
+ if (!$.browser.mozilla && !$.browser.opera) return;
71
+ if (this.moveTimeout) this.clearMoveTimeout();
72
+ var _this = this;
73
+
74
+ var go = function() {
75
+ if (!_this.moveTimeout) return;
76
+ _this[isDown ? 'moveDown' : 'moveUp']();
77
+ _this.moveTimout = setTimeout(go, 100);
78
+ }
79
+ this.moveTimeout = setTimeout(go, 200);
80
+ }
81
+
82
+ this.moveRight = function() {
83
+ }
84
+
85
+ this.moveLeft = function() {
86
+ }
87
+
88
+ this.move = function(isDown) {
89
+ }
90
+
91
+ this.moveUp = function() {
92
+ return this.move(false);
93
+ }
94
+
95
+ this.moveDown = function() {
96
+ return this.move(true);
97
+ }
98
+ }
99
+
100
+
101
+ // scrollIntoView.js --------------------------------------
102
+
103
+ function scrollIntoView(element, view) {
104
+ var offset, viewHeight, viewScroll, height;
105
+ offset = element.offsetTop;
106
+ height = element.offsetHeight;
107
+ viewHeight = view.offsetHeight;
108
+ viewScroll = view.scrollTop;
109
+ if (offset - viewScroll + height > viewHeight) {
110
+ view.scrollTop = offset - viewHeight + height;
111
+ }
112
+ if (offset < viewScroll) {
113
+ view.scrollTop = offset;
114
+ }
115
+ }
116
+
117
+
118
+ // searcher.js --------------------------------------------
119
+
120
+ Searchdoc.Searcher = function(data) {
121
+ this.data = data;
122
+ this.handlers = [];
123
+ }
124
+
125
+ Searchdoc.Searcher.prototype = new function() {
126
+ var CHUNK_SIZE = 1000, // search is performed in chunks of 1000 for non-bloking user input
127
+ MAX_RESULTS = 100, // do not try to find more than 100 results
128
+ huid = 1, suid = 1,
129
+ runs = 0;
130
+
131
+
132
+ this.find = function(query) {
133
+ var queries = splitQuery(query),
134
+ regexps = buildRegexps(queries),
135
+ highlighters = buildHilighters(queries),
136
+ state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++},
137
+ _this = this;
138
+ this.currentSuid = state.n;
139
+
140
+ if (!query) return;
141
+
142
+ var run = function() {
143
+ // stop current search thread if new search started
144
+ if (state.n != _this.currentSuid) return;
145
+
146
+ var results = performSearch(_this.data, regexps, queries, highlighters, state),
147
+ hasMore = (state.limit > 0 && state.pass < 3);
148
+
149
+ triggerResults.call(_this, results, !hasMore);
150
+ if (hasMore) {
151
+ setTimeout(run, 2);
152
+ }
153
+ runs++;
154
+ };
155
+ runs = 0;
156
+
157
+ // start search thread
158
+ run();
159
+ }
160
+
161
+ /* ----- Events ------ */
162
+ this.ready = function(fn) {
163
+ fn.huid = huid;
164
+ this.handlers.push(fn);
165
+ }
166
+
167
+ /* ----- Utilities ------ */
168
+ function splitQuery(query) {
169
+ return jQuery.grep(query.split(/(\s+|\(\)?)/), function(string) { return string.match(/\S/) });
170
+ }
171
+
172
+ function buildRegexps(queries) {
173
+ return jQuery.map(queries, function(query) { return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i') });
174
+ }
175
+
176
+ function buildHilighters(queries) {
177
+ return jQuery.map(queries, function(query) {
178
+ return jQuery.map( query.split(''), function(l, i){ return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2) } ).join('')
179
+ });
180
+ }
181
+
182
+ // function longMatchRegexp(index, longIndex, regexps) {
183
+ // for (var i = regexps.length - 1; i >= 0; i--){
184
+ // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
185
+ // };
186
+ // return true;
187
+ // }
188
+
189
+
190
+ /* ----- Mathchers ------ */
191
+ function matchPass1(index, longIndex, queries, regexps) {
192
+ if (index.indexOf(queries[0]) != 0) return false;
193
+ for (var i=1, l = regexps.length; i < l; i++) {
194
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
195
+ };
196
+ return true;
197
+ }
198
+
199
+ function matchPass2(index, longIndex, queries, regexps) {
200
+ if (index.indexOf(queries[0]) == -1) return false;
201
+ for (var i=1, l = regexps.length; i < l; i++) {
202
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
203
+ };
204
+ return true;
205
+ }
206
+
207
+ function matchPassRegexp(index, longIndex, queries, regexps) {
208
+ if (!index.match(regexps[0])) return false;
209
+ for (var i=1, l = regexps.length; i < l; i++) {
210
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
211
+ };
212
+ return true;
213
+ }
214
+
215
+
216
+ /* ----- Highlighters ------ */
217
+ function highlightRegexp(info, queries, regexps, highlighters) {
218
+ var result = createResult(info);
219
+ for (var i=0, l = regexps.length; i < l; i++) {
220
+ result.title = result.title.replace(regexps[i], highlighters[i]);
221
+ if (i > 0)
222
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
223
+ };
224
+ return result;
225
+ }
226
+
227
+ function hltSubstring(string, pos, length) {
228
+ return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
229
+ }
230
+
231
+ function highlightQuery(info, queries, regexps, highlighters) {
232
+ var result = createResult(info), pos = 0, lcTitle = result.title.toLowerCase();
233
+ pos = lcTitle.indexOf(queries[0]);
234
+ if (pos != -1) {
235
+ result.title = hltSubstring(result.title, pos, queries[0].length);
236
+ }
237
+ for (var i=1, l = regexps.length; i < l; i++) {
238
+ result.title = result.title.replace(regexps[i], highlighters[i]);
239
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
240
+ };
241
+ return result;
242
+ }
243
+
244
+ function createResult(info) {
245
+ var result = {};
246
+ result.title = info[0];
247
+ result.namespace = info[1];
248
+ result.path = info[2];
249
+ result.params = info[3];
250
+ result.snippet = info[4];
251
+ result.badge = info[6];
252
+ return result;
253
+ }
254
+
255
+ /* ----- Searching ------ */
256
+ function performSearch(data, regexps, queries, highlighters, state) {
257
+ var searchIndex = data.searchIndex, // search by title first and then by source
258
+ longSearchIndex = data.longSearchIndex,
259
+ info = data.info,
260
+ result = [],
261
+ i = state.from,
262
+ l = searchIndex.length,
263
+ togo = CHUNK_SIZE,
264
+ matchFunc, hltFunc;
265
+
266
+ while (state.pass < 3 && state.limit > 0 && togo > 0) {
267
+ if (state.pass == 0) {
268
+ matchFunc = matchPass1;
269
+ hltFunc = highlightQuery;
270
+ } else if (state.pass == 1) {
271
+ matchFunc = matchPass2;
272
+ hltFunc = highlightQuery;
273
+ } else if (state.pass == 2) {
274
+ matchFunc = matchPassRegexp;
275
+ hltFunc = highlightRegexp;
276
+ }
277
+
278
+ for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
279
+ if (info[i].n == state.n) continue;
280
+ if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
281
+ info[i].n = state.n;
282
+ result.push(hltFunc(info[i], queries, regexps, highlighters));
283
+ state.limit--;
284
+ }
285
+ };
286
+ if (searchIndex.length <= i) {
287
+ state.pass++;
288
+ i = state.from = 0;
289
+ } else {
290
+ state.from = i;
291
+ }
292
+ }
293
+ return result;
294
+ }
295
+
296
+ function triggerResults(results, isLast) {
297
+ jQuery.each(this.handlers, function(i, fn) { fn.call(this, results, isLast) })
298
+ }
299
+ }
300
+
301
+
302
+
303
+
304
+ // panel.js -----------------------------------------------
305
+
306
+ Searchdoc.Panel = function(element, data, tree, frame) {
307
+ this.$element = $(element);
308
+ this.$input = $('input', element).eq(0);
309
+ this.$result = $('.result ul', element).eq(0);
310
+ this.frame = frame;
311
+ this.$current = null;
312
+ this.$view = this.$result.parent();
313
+ this.data = data;
314
+ this.searcher = new Searchdoc.Searcher(data.index);
315
+ this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
316
+ this.init();
317
+ }
318
+
319
+ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
320
+ var suid = 1;
321
+
322
+ this.init = function() {
323
+ var _this = this;
324
+ var observer = function() {
325
+ _this.search(_this.$input[0].value);
326
+ };
327
+ this.$input.keyup(observer);
328
+ this.$input.click(observer); // mac's clear field
329
+
330
+ this.searcher.ready(function(results, isLast) {
331
+ _this.addResults(results, isLast);
332
+ })
333
+
334
+ this.$result.click(function(e) {
335
+ _this.$current.removeClass('current');
336
+ _this.$current = $(e.target).closest('li').addClass('current');
337
+ _this.select();
338
+ _this.$input.focus();
339
+ });
340
+
341
+ this.initNavigation();
342
+ this.setNavigationActive(false);
343
+ }
344
+
345
+ this.search = function(value) {
346
+ value = jQuery.trim(value).toLowerCase();
347
+ if (value) {
348
+ this.$element.removeClass('panel_tree').addClass('panel_results');
349
+ this.tree.setNavigationActive(false);
350
+ this.setNavigationActive(true);
351
+ } else {
352
+ this.$element.addClass('panel_tree').removeClass('panel_results');
353
+ this.tree.setNavigationActive(true);
354
+ this.setNavigationActive(false);
355
+ }
356
+ if (value != this.lastQuery) {
357
+ this.lastQuery = value;
358
+ this.firstRun = true;
359
+ this.searcher.find(value);
360
+ }
361
+ }
362
+
363
+ this.addResults = function(results, isLast) {
364
+ var target = this.$result.get(0);
365
+ if (this.firstRun && (results.length > 0 || isLast)) {
366
+ this.$current = null;
367
+ this.$result.empty();
368
+ }
369
+ for (var i=0, l = results.length; i < l; i++) {
370
+ target.appendChild(renderItem.call(this, results[i]));
371
+ };
372
+ if (this.firstRun && results.length > 0) {
373
+ this.firstRun = false;
374
+ this.$current = $(target.firstChild);
375
+ this.$current.addClass('current');
376
+ scrollIntoView(this.$current[0], this.$view[0])
377
+ }
378
+ if (jQuery.browser.msie) this.$element[0].className += '';
379
+ }
380
+
381
+ this.open = function(src) {
382
+ this.frame.location.href = '../' + src;
383
+ if (this.frame.highlight) this.frame.highlight(src);
384
+ }
385
+
386
+ this.select = function() {
387
+ this.open(this.$current.data('path'));
388
+ }
389
+
390
+ this.move = function(isDown) {
391
+ if (!this.$current) return;
392
+ var $next = this.$current[isDown ? 'next' : 'prev']();
393
+ if ($next.length) {
394
+ this.$current.removeClass('current');
395
+ $next.addClass('current');
396
+ scrollIntoView($next[0], this.$view[0]);
397
+ this.$current = $next;
398
+ }
399
+ return true;
400
+ }
401
+
402
+ function renderItem(result) {
403
+ var li = document.createElement('li'),
404
+ html = '', badge = result.badge;
405
+ html += '<h1>' + hlt(result.title);
406
+ if (result.params) html += '<i>' + result.params + '</i>';
407
+ html += '</h1>';
408
+ html += '<p>';
409
+ if (typeof badge != 'undefined') {
410
+ html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
411
+ }
412
+ html += hlt(result.namespace) + '</p>';
413
+ if (result.snippet) html += '<p class="snippet">' + escapeHTML(result.snippet) + '</p>';
414
+ li.innerHTML = html;
415
+ jQuery.data(li, 'path', result.path);
416
+ return li;
417
+ }
418
+
419
+ function hlt(html) {
420
+ return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
421
+ }
422
+
423
+ function escapeHTML(html) {
424
+ return html.replace(/[&<>]/g, function(c) {
425
+ return '&#' + c.charCodeAt(0) + ';';
426
+ });
427
+ }
428
+
429
+ });
430
+
431
+ // tree.js ------------------------------------------------
432
+
433
+ Searchdoc.Tree = function(element, tree, panel) {
434
+ this.$element = $(element);
435
+ this.$list = $('ul', element);
436
+ this.tree = tree;
437
+ this.panel = panel;
438
+ this.init();
439
+ }
440
+
441
+ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
442
+ this.init = function() {
443
+ var stopper = document.createElement('li');
444
+ stopper.className = 'stopper';
445
+ this.$list[0].appendChild(stopper);
446
+ for (var i=0, l = this.tree.length; i < l; i++) {
447
+ buildAndAppendItem.call(this, this.tree[i], 0, stopper);
448
+ };
449
+ var _this = this;
450
+ this.$list.click(function(e) {
451
+ var $target = $(e.target),
452
+ $li = $target.closest('li');
453
+ if ($target.hasClass('icon')) {
454
+ _this.toggle($li);
455
+ } else {
456
+ _this.select($li);
457
+ }
458
+ })
459
+
460
+ this.initNavigation();
461
+ if (jQuery.browser.msie) document.body.className += '';
462
+ }
463
+
464
+ this.select = function($li) {
465
+ var path = $li[0].searchdoc_tree_data.path;
466
+ if (this.$current) this.$current.removeClass('current');
467
+ this.$current = $li.addClass('current');
468
+ if (path) this.panel.open(path);
469
+ }
470
+
471
+ this.toggle = function($li) {
472
+ var closed = !$li.hasClass('closed'),
473
+ children = $li[0].searchdoc_tree_data.children;
474
+ $li.toggleClass('closed');
475
+ for (var i=0, l = children.length; i < l; i++) {
476
+ toggleVis.call(this, $(children[i].li), !closed);
477
+ };
478
+ }
479
+
480
+ this.moveRight = function() {
481
+ if (!this.$current) {
482
+ this.select(this.$list.find('li:first'));
483
+ return;
484
+ }
485
+ if (this.$current.hasClass('closed')) {
486
+ this.toggle(this.$current);
487
+ }
488
+ }
489
+
490
+ this.moveLeft = function() {
491
+ if (!this.$current) {
492
+ this.select(this.$list.find('li:first'));
493
+ return;
494
+ }
495
+ if (!this.$current.hasClass('closed')) {
496
+ this.toggle(this.$current);
497
+ } else {
498
+ var level = this.$current[0].searchdoc_tree_data.level;
499
+ if (level == 0) return;
500
+ var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
501
+ this.$current.removeClass('current');
502
+ $next.addClass('current');
503
+ scrollIntoView($next[0], this.$element[0]);
504
+ this.$current = $next;
505
+ }
506
+ }
507
+
508
+ this.move = function(isDown) {
509
+ if (!this.$current) {
510
+ this.select(this.$list.find('li:first'));
511
+ return true;
512
+ }
513
+ var next = this.$current[0];
514
+ if (isDown) {
515
+ do {
516
+ next = next.nextSibling;
517
+ if (next && next.style && next.style.display != 'none') break;
518
+ } while(next);
519
+ } else {
520
+ do {
521
+ next = next.previousSibling;
522
+ if (next && next.style && next.style.display != 'none') break;
523
+ } while(next);
524
+ }
525
+ if (next && next.className.indexOf('stopper') == -1) {
526
+ this.$current.removeClass('current');
527
+ $(next).addClass('current');
528
+ scrollIntoView(next, this.$element[0]);
529
+ this.$current = $(next);
530
+ }
531
+ return true;
532
+ }
533
+
534
+ function toggleVis($li, show) {
535
+ var closed = $li.hasClass('closed'),
536
+ children = $li[0].searchdoc_tree_data.children;
537
+ $li.css('display', show ? '' : 'none')
538
+ if (!show && this.$current && $li[0] == this.$current[0]) {
539
+ this.$current.removeClass('current');
540
+ this.$current = null;
541
+ }
542
+ for (var i=0, l = children.length; i < l; i++) {
543
+ toggleVis.call(this, $(children[i].li), show && !closed);
544
+ };
545
+ }
546
+
547
+ function buildAndAppendItem(item, level, before) {
548
+ var li = renderItem(item, level),
549
+ list = this.$list[0];
550
+ item.li = li;
551
+ list.insertBefore(li, before);
552
+ for (var i=0, l = item[3].length; i < l; i++) {
553
+ buildAndAppendItem.call(this, item[3][i], level + 1, before);
554
+ };
555
+ return li;
556
+ }
557
+
558
+ function renderItem(item, level) {
559
+ var li = document.createElement('li'),
560
+ cnt = document.createElement('div'),
561
+ h1 = document.createElement('h1'),
562
+ p = document.createElement('p'),
563
+ icon, i;
564
+
565
+ li.appendChild(cnt);
566
+ li.style.paddingLeft = getOffset(level);
567
+ cnt.className = 'content';
568
+ if (!item[1]) li.className = 'empty ';
569
+ cnt.appendChild(h1);
570
+ // cnt.appendChild(p);
571
+ h1.appendChild(document.createTextNode(item[0]));
572
+ // p.appendChild(document.createTextNode(item[4]));
573
+ if (item[2]) {
574
+ i = document.createElement('i');
575
+ i.appendChild(document.createTextNode(item[2]));
576
+ h1.appendChild(i);
577
+ }
578
+ if (item[3].length > 0) {
579
+ icon = document.createElement('div');
580
+ icon.className = 'icon';
581
+ cnt.appendChild(icon);
582
+ }
583
+
584
+ // user direct assignement instead of $()
585
+ // it's 8x faster
586
+ // $(li).data('path', item[1])
587
+ // .data('children', item[3])
588
+ // .data('level', level)
589
+ // .css('display', level == 0 ? '' : 'none')
590
+ // .addClass('level_' + level)
591
+ // .addClass('closed');
592
+ li.searchdoc_tree_data = {
593
+ path: item[1],
594
+ children: item[3],
595
+ level: level
596
+ }
597
+ li.style.display = level == 0 ? '' : 'none';
598
+ li.className += 'level_' + level + ' closed';
599
+ return li;
600
+ }
601
+
602
+ function getOffset(level) {
603
+ return 5 + 18*level + 'px';
604
+ }
605
+ });