sdoc 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
- function toggleSource(id)
2
- {
1
+ function toggleSource(id) {
3
2
  var src = $('#' + id).toggle();
4
3
  var isVisible = src.is(':visible');
5
4
  $('#l_' + id).html(isVisible ? 'hide' : 'show');
@@ -10,11 +9,11 @@ function toggleSource(id)
10
9
  }
11
10
 
12
11
  window.highlight = function(url) {
13
- var hash = url.match(/#([^#]+)$/)
14
- if(hash) {
15
- $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
12
+ var hash = url.match(/#([^#]+)$/);
13
+ if (hash) {
14
+ $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow');
16
15
  }
17
- }
16
+ };
18
17
 
19
18
  $(function() {
20
19
  highlight('#' + location.hash);
@@ -5,25 +5,25 @@ Searchdoc = {};
5
5
  Searchdoc.Navigation = new function() {
6
6
  this.initNavigation = function() {
7
7
  var _this = this;
8
-
8
+
9
9
  $(document).keydown(function(e) {
10
10
  _this.onkeydown(e);
11
11
  }).keyup(function(e) {
12
12
  _this.onkeyup(e);
13
13
  });
14
-
14
+
15
15
  this.navigationActive = true;
16
- }
17
-
16
+ };
17
+
18
18
  this.setNavigationActive = function(state) {
19
19
  this.navigationActive = state;
20
20
  this.clearMoveTimeout();
21
- }
21
+ };
22
22
 
23
23
 
24
24
  this.onkeyup = function(e) {
25
25
  if (!this.navigationActive) return;
26
- switch(e.keyCode) {
26
+ switch (e.keyCode) {
27
27
  case 37: //Event.KEY_LEFT:
28
28
  case 38: //Event.KEY_UP:
29
29
  case 39: //Event.KEY_RIGHT:
@@ -33,17 +33,17 @@ Searchdoc.Navigation = new function() {
33
33
  case 75: // k
34
34
  case 76: // l
35
35
  case 67: // c - dvorak
36
- case 72: // h
36
+ case 72: // h
37
37
  case 84: // t
38
38
  case 78: // n
39
39
  this.clearMoveTimeout();
40
40
  break;
41
- }
42
- }
41
+ }
42
+ };
43
43
 
44
44
  this.onkeydown = function(e) {
45
45
  if (!this.navigationActive) return;
46
- switch(e.keyCode) {
46
+ switch (e.keyCode) {
47
47
  case 37: //Event.KEY_LEFT:
48
48
  case 74: // j (qwerty)
49
49
  case 72: // h (dvorak)
@@ -83,43 +83,40 @@ Searchdoc.Navigation = new function() {
83
83
  break;
84
84
  }
85
85
  if (e.ctrlKey && e.shiftKey) this.select(this.$current);
86
- }
86
+ };
87
87
 
88
88
  this.clearMoveTimeout = function() {
89
- clearTimeout(this.moveTimeout);
89
+ clearTimeout(this.moveTimeout);
90
90
  this.moveTimeout = null;
91
- }
91
+ };
92
92
 
93
93
  this.startMoveTimeout = function(isDown) {
94
94
  if (!$.browser.mozilla && !$.browser.opera) return;
95
95
  if (this.moveTimeout) this.clearMoveTimeout();
96
96
  var _this = this;
97
-
97
+
98
98
  var go = function() {
99
99
  if (!_this.moveTimeout) return;
100
100
  _this[isDown ? 'moveDown' : 'moveUp']();
101
101
  _this.moveTimout = setTimeout(go, 100);
102
- }
102
+ };
103
103
  this.moveTimeout = setTimeout(go, 200);
104
- }
105
-
106
- this.moveRight = function() {
107
- }
108
-
109
- this.moveLeft = function() {
110
- }
104
+ };
111
105
 
112
- this.move = function(isDown) {
113
- }
106
+ this.moveRight = function() {};
107
+
108
+ this.moveLeft = function() {};
109
+
110
+ this.move = function(isDown) {};
114
111
 
115
112
  this.moveUp = function() {
116
113
  return this.move(false);
117
- }
114
+ };
118
115
 
119
116
  this.moveDown = function() {
120
117
  return this.move(true);
121
- }
122
- }
118
+ };
119
+ };
123
120
 
124
121
 
125
122
  // scrollIntoView.js --------------------------------------
@@ -149,10 +146,9 @@ Searchdoc.Panel = function(element, data, tree, frame) {
149
146
  this.$view = this.$result.parent();
150
147
  this.data = data;
151
148
  this.searcher = new Searcher(data.index);
152
-
153
149
  this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
154
150
  this.init();
155
- }
151
+ };
156
152
 
157
153
  Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
158
154
  var suid = 1;
@@ -164,21 +160,22 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
164
160
  };
165
161
  this.$input.keyup(observer);
166
162
  this.$input.click(observer); // mac's clear field
167
-
163
+
168
164
  this.searcher.ready(function(results, isLast) {
169
165
  _this.addResults(results, isLast);
170
- })
171
-
166
+ });
167
+
172
168
  this.$result.click(function(e) {
169
+ e.preventDefault();
173
170
  _this.$current.removeClass('current');
174
171
  _this.$current = $(e.target).closest('li').addClass('current');
175
172
  _this.select();
176
173
  _this.$input.focus();
177
174
  });
178
-
175
+
179
176
  this.initNavigation();
180
177
  this.setNavigationActive(false);
181
- }
178
+ };
182
179
 
183
180
  this.search = function(value, selectFirstMatch) {
184
181
  value = jQuery.trim(value).toLowerCase();
@@ -197,7 +194,7 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
197
194
  this.firstRun = true;
198
195
  this.searcher.find(value);
199
196
  }
200
- }
197
+ };
201
198
 
202
199
  this.addResults = function(results, isLast) {
203
200
  var target = this.$result.get(0);
@@ -205,27 +202,27 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
205
202
  this.$current = null;
206
203
  this.$result.empty();
207
204
  }
208
- for (var i=0, l = results.length; i < l; i++) {
205
+ for (var i = 0, l = results.length; i < l; i++) {
209
206
  target.appendChild(renderItem.call(this, results[i]));
210
- };
207
+ }
211
208
  if (this.firstRun && results.length > 0) {
212
209
  this.firstRun = false;
213
210
  this.$current = $(target.firstChild);
214
211
  this.$current.addClass('current');
215
212
  if (this.selectFirstMatch) this.select();
216
- scrollIntoView(this.$current[0], this.$view[0])
213
+ scrollIntoView(this.$current[0], this.$view[0]);
217
214
  }
218
215
  if (jQuery.browser.msie) this.$element[0].className += '';
219
- }
216
+ };
220
217
 
221
218
  this.open = function(src) {
222
219
  this.frame.location.href = '../' + src;
223
220
  if (this.frame.highlight) this.frame.highlight(src);
224
- }
221
+ };
225
222
 
226
223
  this.select = function() {
227
224
  this.open(this.$current.data('path'));
228
- }
225
+ };
229
226
 
230
227
  this.move = function(isDown) {
231
228
  if (!this.$current) return;
@@ -237,14 +234,15 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
237
234
  this.$current = $next;
238
235
  }
239
236
  return true;
240
- }
237
+ };
241
238
 
242
239
  function renderItem(result) {
243
240
  var li = document.createElement('li'),
244
- html = '', badge = result.badge;
245
- html += '<h1>' + hlt(result.title);
241
+ html = '',
242
+ badge = result.badge;
243
+ html += '<a href="../' + result.path + '">' + hlt(result.title);
246
244
  if (result.params) html += '<i>' + result.params + '</i>';
247
- html += '</h1>';
245
+ html += '</a>';
248
246
  html += '<p>';
249
247
  if (typeof badge != 'undefined') {
250
248
  html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
@@ -257,7 +255,7 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
257
255
  }
258
256
 
259
257
  function hlt(html) {
260
- return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
258
+ return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>');
261
259
  }
262
260
 
263
261
  function escapeHTML(html) {
@@ -266,7 +264,7 @@ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
266
264
  });
267
265
  }
268
266
 
269
- });
267
+ });
270
268
 
271
269
  // tree.js ------------------------------------------------
272
270
 
@@ -276,18 +274,19 @@ Searchdoc.Tree = function(element, tree, panel) {
276
274
  this.tree = tree;
277
275
  this.panel = panel;
278
276
  this.init();
279
- }
277
+ };
280
278
 
281
279
  Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
282
280
  this.init = function() {
283
281
  var stopper = document.createElement('li');
284
282
  stopper.className = 'stopper';
285
283
  this.$list[0].appendChild(stopper);
286
- for (var i=0, l = this.tree.length; i < l; i++) {
284
+ for (var i = 0, l = this.tree.length; i < l; i++) {
287
285
  buildAndAppendItem.call(this, this.tree[i], 0, stopper);
288
- };
286
+ }
289
287
  var _this = this;
290
288
  this.$list.click(function(e) {
289
+ e.preventDefault();
291
290
  var $target = $(e.target),
292
291
  $li = $target.closest('li');
293
292
  if ($target.hasClass('icon')) {
@@ -295,31 +294,31 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
295
294
  } else {
296
295
  _this.select($li);
297
296
  }
298
- })
299
-
297
+ });
298
+
300
299
  this.initNavigation();
301
300
  if (jQuery.browser.msie) document.body.className += '';
302
- }
301
+ };
303
302
 
304
303
  this.select = function($li) {
305
304
  this.highlight($li);
306
305
  var path = $li[0].searchdoc_tree_data.path;
307
306
  if (path) this.panel.open(path);
308
- }
309
-
307
+ };
308
+
310
309
  this.highlight = function($li) {
311
310
  if (this.$current) this.$current.removeClass('current');
312
311
  this.$current = $li.addClass('current');
313
- }
312
+ };
314
313
 
315
314
  this.toggle = function($li) {
316
315
  var closed = !$li.hasClass('closed'),
317
316
  children = $li[0].searchdoc_tree_data.children;
318
317
  $li.toggleClass('closed');
319
- for (var i=0, l = children.length; i < l; i++) {
318
+ for (var i = 0, l = children.length; i < l; i++) {
320
319
  toggleVis.call(this, $(children[i].li), !closed);
321
- };
322
- }
320
+ }
321
+ };
323
322
 
324
323
  this.moveRight = function() {
325
324
  if (!this.$current) {
@@ -329,8 +328,8 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
329
328
  if (this.$current.hasClass('closed')) {
330
329
  this.toggle(this.$current);
331
330
  }
332
- }
333
-
331
+ };
332
+
334
333
  this.moveLeft = function() {
335
334
  if (!this.$current) {
336
335
  this.highlight(this.$list.find('li:first'));
@@ -340,31 +339,31 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
340
339
  this.toggle(this.$current);
341
340
  } else {
342
341
  var level = this.$current[0].searchdoc_tree_data.level;
343
- if (level == 0) return;
342
+ if (level === 0) return;
344
343
  var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
345
344
  this.$current.removeClass('current');
346
345
  $next.addClass('current');
347
346
  scrollIntoView($next[0], this.$element[0]);
348
347
  this.$current = $next;
349
348
  }
350
- }
349
+ };
351
350
 
352
351
  this.move = function(isDown) {
353
352
  if (!this.$current) {
354
353
  this.highlight(this.$list.find('li:first'));
355
354
  return true;
356
- }
355
+ }
357
356
  var next = this.$current[0];
358
357
  if (isDown) {
359
358
  do {
360
359
  next = next.nextSibling;
361
360
  if (next && next.style && next.style.display != 'none') break;
362
- } while(next);
361
+ } while (next);
363
362
  } else {
364
363
  do {
365
364
  next = next.previousSibling;
366
365
  if (next && next.style && next.style.display != 'none') break;
367
- } while(next);
366
+ } while (next);
368
367
  }
369
368
  if (next && next.className.indexOf('stopper') == -1) {
370
369
  this.$current.removeClass('current');
@@ -373,58 +372,59 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
373
372
  this.$current = $(next);
374
373
  }
375
374
  return true;
376
- }
375
+ };
377
376
 
378
377
  function toggleVis($li, show) {
379
378
  var closed = $li.hasClass('closed'),
380
379
  children = $li[0].searchdoc_tree_data.children;
381
- $li.css('display', show ? '' : 'none')
380
+ $li.css('display', show ? '' : 'none');
382
381
  if (!show && this.$current && $li[0] == this.$current[0]) {
383
382
  this.$current.removeClass('current');
384
383
  this.$current = null;
385
384
  }
386
- for (var i=0, l = children.length; i < l; i++) {
385
+ for (var i = 0, l = children.length; i < l; i++) {
387
386
  toggleVis.call(this, $(children[i].li), show && !closed);
388
- };
387
+ }
389
388
  }
390
389
 
391
390
  function buildAndAppendItem(item, level, before) {
392
- var li = renderItem(item, level),
391
+ var li = renderItem(item, level),
393
392
  list = this.$list[0];
394
393
  item.li = li;
395
394
  list.insertBefore(li, before);
396
- for (var i=0, l = item[3].length; i < l; i++) {
395
+ for (var i = 0, l = item[3].length; i < l; i++) {
397
396
  buildAndAppendItem.call(this, item[3][i], level + 1, before);
398
- };
397
+ }
399
398
  return li;
400
399
  }
401
400
 
402
401
  function renderItem(item, level) {
403
402
  var li = document.createElement('li'),
404
403
  cnt = document.createElement('div'),
405
- h1 = document.createElement('h1'),
404
+ a = document.createElement('a'),
406
405
  p = document.createElement('p'),
407
406
  icon, i;
408
-
407
+
408
+ a.href = '../' + item[1];
409
409
  li.appendChild(cnt);
410
410
  li.style.paddingLeft = getOffset(level);
411
411
  cnt.className = 'content';
412
- if (!item[1]) li.className = 'empty ';
413
- cnt.appendChild(h1);
412
+ if (!item[1]) li.className = 'empty ';
413
+ cnt.appendChild(a);
414
414
  // cnt.appendChild(p);
415
- h1.appendChild(document.createTextNode(item[0]));
415
+ a.appendChild(document.createTextNode(item[0]));
416
416
  // p.appendChild(document.createTextNode(item[4]));
417
417
  if (item[2]) {
418
418
  i = document.createElement('i');
419
419
  i.appendChild(document.createTextNode(item[2]));
420
- h1.appendChild(i);
420
+ a.appendChild(i);
421
421
  }
422
422
  if (item[3].length > 0) {
423
423
  icon = document.createElement('div');
424
424
  icon.className = 'icon';
425
425
  cnt.appendChild(icon);
426
426
  }
427
-
427
+
428
428
  // user direct assignement instead of $()
429
429
  // it's 8x faster
430
430
  // $(li).data('path', item[1])
@@ -437,13 +437,13 @@ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
437
437
  path: item[1],
438
438
  children: item[3],
439
439
  level: level
440
- }
441
- li.style.display = level == 0 ? '' : 'none';
440
+ };
441
+ li.style.display = level === 0 ? '' : 'none';
442
442
  li.className += 'level_' + level + ' closed';
443
443
  return li;
444
444
  }
445
445
 
446
446
  function getOffset(level) {
447
- return 5 + 18*level + 'px';
447
+ return 5 + 18 * level + 'px';
448
448
  }
449
- });
449
+ });