bitmask_attributes 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +2 -1
  2. data/CHANGELOG.rdoc +14 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +18 -11
  5. data/{README.md → README.rdoc} +27 -28
  6. data/Rakefile +137 -0
  7. data/bitmask_attributes.gemspec +1 -3
  8. data/doc/apple-touch-icon.png +0 -0
  9. data/doc/classes/BitmaskAttributes.html +114 -0
  10. data/doc/classes/BitmaskAttributes/ClassMethods.html +205 -0
  11. data/doc/classes/BitmaskAttributes/Definition.html +690 -0
  12. data/doc/classes/BitmaskAttributes/ValueProxy.html +468 -0
  13. data/doc/created.rid +7 -0
  14. data/doc/css/github.css +129 -0
  15. data/doc/css/main.css +326 -0
  16. data/doc/css/panel.css +384 -0
  17. data/doc/css/reset.css +48 -0
  18. data/doc/favicon.ico +0 -0
  19. data/doc/files/CHANGELOG_rdoc.html +67 -0
  20. data/doc/files/README_rdoc.html +224 -0
  21. data/doc/files/lib/bitmask_attributes/definition_rb.html +83 -0
  22. data/doc/files/lib/bitmask_attributes/value_proxy_rb.html +83 -0
  23. data/doc/files/lib/bitmask_attributes/version_rb.html +78 -0
  24. data/doc/files/lib/bitmask_attributes_rb.html +93 -0
  25. data/doc/i/arrows.png +0 -0
  26. data/doc/i/results_bg.png +0 -0
  27. data/doc/i/tree_bg.png +0 -0
  28. data/doc/index.html +13 -0
  29. data/doc/js/highlight.pack.js +1 -0
  30. data/doc/js/jquery-1.3.2.min.js +19 -0
  31. data/doc/js/jquery-effect.js +593 -0
  32. data/doc/js/main.js +24 -0
  33. data/doc/js/navigation.js +142 -0
  34. data/doc/js/search_index.js +1 -0
  35. data/doc/js/searchdoc.js +442 -0
  36. data/doc/js/searcher.js +228 -0
  37. data/doc/panel/index.html +73 -0
  38. data/doc/panel/links.html +18 -0
  39. data/doc/panel/tree.js +1 -0
  40. data/lib/bitmask_attributes/definition.rb +4 -4
  41. data/lib/bitmask_attributes/version.rb +1 -1
  42. metadata +39 -6
@@ -0,0 +1,24 @@
1
+ function toggleSource(id)
2
+ {
3
+ var src = $('#' + id).toggle();
4
+ var isVisible = src.is(':visible');
5
+ $('#l_' + id).html(isVisible ? 'hide' : 'show');
6
+ if (!src.data('syntax-higlighted')) {
7
+ src.data('syntax-higlighted', 1);
8
+ hljs.highlightBlock(src[0]);
9
+ }
10
+ }
11
+
12
+ window.highlight = function(url) {
13
+ var hash = url.match(/#([^#]+)$/)
14
+ if(hash) {
15
+ $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
16
+ }
17
+ }
18
+
19
+ $(function() {
20
+ highlight('#' + location.hash);
21
+ $('.description pre').each(function() {
22
+ hljs.highlightBlock(this);
23
+ });
24
+ });
@@ -0,0 +1,142 @@
1
+ /*
2
+ * Navigation allows movement using the arrow keys through the search results.
3
+ *
4
+ * When using this library you will need to set scrollIntoView to the
5
+ * appropriate function for your layout. Use scrollInWindow if the container
6
+ * is not scrollable and scrollInElement if the container is a separate
7
+ * scrolling region.
8
+ */
9
+ Navigation = new function() {
10
+ this.initNavigation = function() {
11
+ var _this = this;
12
+
13
+ $(document).keydown(function(e) {
14
+ _this.onkeydown(e);
15
+ }).keyup(function(e) {
16
+ _this.onkeyup(e);
17
+ });
18
+
19
+ this.navigationActive = true;
20
+ }
21
+
22
+ this.setNavigationActive = function(state) {
23
+ this.navigationActive = state;
24
+ this.clearMoveTimeout();
25
+ }
26
+
27
+ this.onkeyup = function(e) {
28
+ if (!this.navigationActive) return;
29
+
30
+ switch(e.keyCode) {
31
+ case 37: //Event.KEY_LEFT:
32
+ case 38: //Event.KEY_UP:
33
+ case 39: //Event.KEY_RIGHT:
34
+ case 40: //Event.KEY_DOWN:
35
+ this.clearMoveTimeout();
36
+ break;
37
+ }
38
+ }
39
+
40
+ this.onkeydown = function(e) {
41
+ if (!this.navigationActive) return;
42
+ switch(e.keyCode) {
43
+ case 37: //Event.KEY_LEFT:
44
+ if (this.moveLeft()) e.preventDefault();
45
+ break;
46
+ case 38: //Event.KEY_UP:
47
+ if (e.keyCode == 38 || e.ctrlKey) {
48
+ if (this.moveUp()) e.preventDefault();
49
+ this.startMoveTimeout(false);
50
+ }
51
+ break;
52
+ case 39: //Event.KEY_RIGHT:
53
+ if (this.moveRight()) e.preventDefault();
54
+ break;
55
+ case 40: //Event.KEY_DOWN:
56
+ if (e.keyCode == 40 || e.ctrlKey) {
57
+ if (this.moveDown()) e.preventDefault();
58
+ this.startMoveTimeout(true);
59
+ }
60
+ break;
61
+ case 13: //Event.KEY_RETURN:
62
+ if (this.$current)
63
+ e.preventDefault();
64
+ this.select(this.$current);
65
+ break;
66
+ }
67
+ if (e.ctrlKey && e.shiftKey) this.select(this.$current);
68
+ }
69
+
70
+ this.clearMoveTimeout = function() {
71
+ clearTimeout(this.moveTimeout);
72
+ this.moveTimeout = null;
73
+ }
74
+
75
+ this.startMoveTimeout = function(isDown) {
76
+ if (!$.browser.mozilla && !$.browser.opera) return;
77
+ if (this.moveTimeout) this.clearMoveTimeout();
78
+ var _this = this;
79
+
80
+ var go = function() {
81
+ if (!_this.moveTimeout) return;
82
+ _this[isDown ? 'moveDown' : 'moveUp']();
83
+ _this.moveTimout = setTimeout(go, 100);
84
+ }
85
+ this.moveTimeout = setTimeout(go, 200);
86
+ }
87
+
88
+ this.moveRight = function() {
89
+ }
90
+
91
+ this.moveLeft = function() {
92
+ }
93
+
94
+ this.move = function(isDown) {
95
+ }
96
+
97
+ this.moveUp = function() {
98
+ return this.move(false);
99
+ }
100
+
101
+ this.moveDown = function() {
102
+ return this.move(true);
103
+ }
104
+
105
+ /*
106
+ * Scrolls to the given element in the scrollable element view.
107
+ */
108
+ this.scrollInElement = function(element, view) {
109
+ var offset, viewHeight, viewScroll, height;
110
+ offset = element.offsetTop;
111
+ height = element.offsetHeight;
112
+ viewHeight = view.offsetHeight;
113
+ viewScroll = view.scrollTop;
114
+
115
+ if (offset - viewScroll + height > viewHeight) {
116
+ view.scrollTop = offset - viewHeight + height;
117
+ }
118
+ if (offset < viewScroll) {
119
+ view.scrollTop = offset;
120
+ }
121
+ }
122
+
123
+ /*
124
+ * Scrolls to the given element in the window. The second argument is
125
+ * ignored
126
+ */
127
+ this.scrollInWindow = function(element, ignored) {
128
+ var offset, viewHeight, viewScroll, height;
129
+ offset = element.offsetTop;
130
+ height = element.offsetHeight;
131
+ viewHeight = window.innerHeight;
132
+ viewScroll = window.scrollY;
133
+
134
+ if (offset - viewScroll + height > viewHeight) {
135
+ window.scrollTo(window.scrollX, offset - viewHeight + height);
136
+ }
137
+ if (offset < viewScroll) {
138
+ window.scrollTo(window.scrollX, offset);
139
+ }
140
+ }
141
+ }
142
+
@@ -0,0 +1 @@
1
+ var search_data = {"index":{"searchIndex":["bitmaskattributes","classmethods","definition","valueproxy","bitmask()","bitmask_definitions()","bitmasks()","create_attribute_methods_on()","create_convenience_class_method_on()","create_convenience_instance_methods_on()","create_scopes_on()","extract_values()","find_mapping()","generate_bitmasks_on()","install_on()","new()","new()","override()","override_getter_on()","override_setter_on()","serialize!()","symbolize!()","to_i()","updated!()","validate!()","validate_for()","changelog","readme"],"longSearchIndex":["bitmaskattributes","bitmaskattributes::classmethods","bitmaskattributes::definition","bitmaskattributes::valueproxy","bitmaskattributes::classmethods#bitmask()","bitmaskattributes::classmethods#bitmask_definitions()","bitmaskattributes::classmethods#bitmasks()","bitmaskattributes::definition#create_attribute_methods_on()","bitmaskattributes::definition#create_convenience_class_method_on()","bitmaskattributes::definition#create_convenience_instance_methods_on()","bitmaskattributes::definition#create_scopes_on()","bitmaskattributes::valueproxy#extract_values()","bitmaskattributes::valueproxy#find_mapping()","bitmaskattributes::definition#generate_bitmasks_on()","bitmaskattributes::definition#install_on()","bitmaskattributes::definition::new()","bitmaskattributes::valueproxy::new()","bitmaskattributes::definition#override()","bitmaskattributes::definition#override_getter_on()","bitmaskattributes::definition#override_setter_on()","bitmaskattributes::valueproxy#serialize!()","bitmaskattributes::valueproxy#symbolize!()","bitmaskattributes::valueproxy#to_i()","bitmaskattributes::valueproxy#updated!()","bitmaskattributes::valueproxy#validate!()","bitmaskattributes::definition#validate_for()","",""],"info":[["BitmaskAttributes","","classes/BitmaskAttributes.html","",""],["BitmaskAttributes::ClassMethods","","classes/BitmaskAttributes/ClassMethods.html","",""],["BitmaskAttributes::Definition","","classes/BitmaskAttributes/Definition.html","",""],["BitmaskAttributes::ValueProxy","","classes/BitmaskAttributes/ValueProxy.html","",""],["bitmask","BitmaskAttributes::ClassMethods","classes/BitmaskAttributes/ClassMethods.html#method-i-bitmask","(attribute, options={}, &extension)",""],["bitmask_definitions","BitmaskAttributes::ClassMethods","classes/BitmaskAttributes/ClassMethods.html#method-i-bitmask_definitions","()",""],["bitmasks","BitmaskAttributes::ClassMethods","classes/BitmaskAttributes/ClassMethods.html#method-i-bitmasks","()",""],["create_attribute_methods_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-create_attribute_methods_on","(model)","<p>Returns the defined values as an Array.\n"],["create_convenience_class_method_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-create_convenience_class_method_on","(model)",""],["create_convenience_instance_methods_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-create_convenience_instance_methods_on","(model)",""],["create_scopes_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-create_scopes_on","(model)",""],["extract_values","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-extract_values","()",""],["find_mapping","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-find_mapping","()",""],["generate_bitmasks_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-generate_bitmasks_on","(model)",""],["install_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-install_on","(model)",""],["new","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-c-new","(attribute, values=[], &extension)",""],["new","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-c-new","(record, attribute, &extension)",""],["override","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-override","(model)",""],["override_getter_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-override_getter_on","(model)",""],["override_setter_on","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-override_setter_on","(model)",""],["serialize!","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-serialize-21","()",""],["symbolize!","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-symbolize-21","()",""],["to_i","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-to_i","()",""],["updated!","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-updated-21","()",""],["validate!","BitmaskAttributes::ValueProxy","classes/BitmaskAttributes/ValueProxy.html#method-i-validate-21","()",""],["validate_for","BitmaskAttributes::Definition","classes/BitmaskAttributes/Definition.html#method-i-validate_for","(model)",""],["CHANGELOG","","files/CHANGELOG_rdoc.html","",""],["README","","files/README_rdoc.html","","<p>BitmaskAttributes\n<p>Transparent manipulation of bitmask attributes for ActiveRecord, based on\nthe bitmask-attribute …\n"]]}}
@@ -0,0 +1,442 @@
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
+ case 73: // i - qwerty
32
+ case 74: // j
33
+ case 75: // k
34
+ case 76: // l
35
+ case 67: // c - dvorak
36
+ case 72: // h
37
+ case 84: // t
38
+ case 78: // n
39
+ this.clearMoveTimeout();
40
+ break;
41
+ }
42
+ }
43
+
44
+ this.onkeydown = function(e) {
45
+ if (!this.navigationActive) return;
46
+ switch(e.keyCode) {
47
+ case 37: //Event.KEY_LEFT:
48
+ case 74: // j (qwerty)
49
+ case 72: // h (dvorak)
50
+ if (this.moveLeft()) e.preventDefault();
51
+ break;
52
+ case 38: //Event.KEY_UP:
53
+ case 73: // i (qwerty)
54
+ case 67: // c (dvorak)
55
+ if (e.keyCode == 38 || e.ctrlKey) {
56
+ if (this.moveUp()) e.preventDefault();
57
+ this.startMoveTimeout(false);
58
+ }
59
+ break;
60
+ case 39: //Event.KEY_RIGHT:
61
+ case 76: // l (qwerty)
62
+ case 78: // n (dvorak)
63
+ if (this.moveRight()) e.preventDefault();
64
+ break;
65
+ case 40: //Event.KEY_DOWN:
66
+ case 75: // k (qwerty)
67
+ case 84: // t (dvorak)
68
+ if (e.keyCode == 40 || e.ctrlKey) {
69
+ if (this.moveDown()) e.preventDefault();
70
+ this.startMoveTimeout(true);
71
+ }
72
+ break;
73
+ case 9: //Event.KEY_TAB:
74
+ case 13: //Event.KEY_RETURN:
75
+ if (this.$current) this.select(this.$current);
76
+ break;
77
+ }
78
+ if (e.ctrlKey && e.shiftKey) this.select(this.$current);
79
+ }
80
+
81
+ this.clearMoveTimeout = function() {
82
+ clearTimeout(this.moveTimeout);
83
+ this.moveTimeout = null;
84
+ }
85
+
86
+ this.startMoveTimeout = function(isDown) {
87
+ if (!$.browser.mozilla && !$.browser.opera) return;
88
+ if (this.moveTimeout) this.clearMoveTimeout();
89
+ var _this = this;
90
+
91
+ var go = function() {
92
+ if (!_this.moveTimeout) return;
93
+ _this[isDown ? 'moveDown' : 'moveUp']();
94
+ _this.moveTimout = setTimeout(go, 100);
95
+ }
96
+ this.moveTimeout = setTimeout(go, 200);
97
+ }
98
+
99
+ this.moveRight = function() {
100
+ }
101
+
102
+ this.moveLeft = function() {
103
+ }
104
+
105
+ this.move = function(isDown) {
106
+ }
107
+
108
+ this.moveUp = function() {
109
+ return this.move(false);
110
+ }
111
+
112
+ this.moveDown = function() {
113
+ return this.move(true);
114
+ }
115
+ }
116
+
117
+
118
+ // scrollIntoView.js --------------------------------------
119
+
120
+ function scrollIntoView(element, view) {
121
+ var offset, viewHeight, viewScroll, height;
122
+ offset = element.offsetTop;
123
+ height = element.offsetHeight;
124
+ viewHeight = view.offsetHeight;
125
+ viewScroll = view.scrollTop;
126
+ if (offset - viewScroll + height > viewHeight) {
127
+ view.scrollTop = offset - viewHeight + height;
128
+ }
129
+ if (offset < viewScroll) {
130
+ view.scrollTop = offset;
131
+ }
132
+ }
133
+
134
+ // panel.js -----------------------------------------------
135
+
136
+ Searchdoc.Panel = function(element, data, tree, frame) {
137
+ this.$element = $(element);
138
+ this.$input = $('input', element).eq(0);
139
+ this.$result = $('.result ul', element).eq(0);
140
+ this.frame = frame;
141
+ this.$current = null;
142
+ this.$view = this.$result.parent();
143
+ this.data = data;
144
+ this.searcher = new Searcher(data.index);
145
+
146
+ this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
147
+ this.init();
148
+ }
149
+
150
+ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
151
+ var suid = 1;
152
+
153
+ this.init = function() {
154
+ var _this = this;
155
+ var observer = function() {
156
+ _this.search(_this.$input[0].value);
157
+ };
158
+ this.$input.keyup(observer);
159
+ this.$input.click(observer); // mac's clear field
160
+
161
+ this.searcher.ready(function(results, isLast) {
162
+ _this.addResults(results, isLast);
163
+ })
164
+
165
+ this.$result.click(function(e) {
166
+ _this.$current.removeClass('current');
167
+ _this.$current = $(e.target).closest('li').addClass('current');
168
+ _this.select();
169
+ _this.$input.focus();
170
+ });
171
+
172
+ this.initNavigation();
173
+ this.setNavigationActive(false);
174
+ }
175
+
176
+ this.search = function(value, selectFirstMatch) {
177
+ value = jQuery.trim(value).toLowerCase();
178
+ this.selectFirstMatch = selectFirstMatch;
179
+ if (value) {
180
+ this.$element.removeClass('panel_tree').addClass('panel_results');
181
+ this.tree.setNavigationActive(false);
182
+ this.setNavigationActive(true);
183
+ } else {
184
+ this.$element.addClass('panel_tree').removeClass('panel_results');
185
+ this.tree.setNavigationActive(true);
186
+ this.setNavigationActive(false);
187
+ }
188
+ if (value != this.lastQuery) {
189
+ this.lastQuery = value;
190
+ this.firstRun = true;
191
+ this.searcher.find(value);
192
+ }
193
+ }
194
+
195
+ this.addResults = function(results, isLast) {
196
+ var target = this.$result.get(0);
197
+ if (this.firstRun && (results.length > 0 || isLast)) {
198
+ this.$current = null;
199
+ this.$result.empty();
200
+ }
201
+ for (var i=0, l = results.length; i < l; i++) {
202
+ target.appendChild(renderItem.call(this, results[i]));
203
+ };
204
+ if (this.firstRun && results.length > 0) {
205
+ this.firstRun = false;
206
+ this.$current = $(target.firstChild);
207
+ this.$current.addClass('current');
208
+ if (this.selectFirstMatch) this.select();
209
+ scrollIntoView(this.$current[0], this.$view[0])
210
+ }
211
+ if (jQuery.browser.msie) this.$element[0].className += '';
212
+ }
213
+
214
+ this.open = function(src) {
215
+ this.frame.location.href = '../' + src;
216
+ if (this.frame.highlight) this.frame.highlight(src);
217
+ }
218
+
219
+ this.select = function() {
220
+ this.open(this.$current.data('path'));
221
+ }
222
+
223
+ this.move = function(isDown) {
224
+ if (!this.$current) return;
225
+ var $next = this.$current[isDown ? 'next' : 'prev']();
226
+ if ($next.length) {
227
+ this.$current.removeClass('current');
228
+ $next.addClass('current');
229
+ scrollIntoView($next[0], this.$view[0]);
230
+ this.$current = $next;
231
+ }
232
+ return true;
233
+ }
234
+
235
+ function renderItem(result) {
236
+ var li = document.createElement('li'),
237
+ html = '', badge = result.badge;
238
+ html += '<h1>' + hlt(result.title);
239
+ if (result.params) html += '<i>' + result.params + '</i>';
240
+ html += '</h1>';
241
+ html += '<p>';
242
+ if (typeof badge != 'undefined') {
243
+ html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
244
+ }
245
+ html += hlt(result.namespace) + '</p>';
246
+ if (result.snippet) html += '<p class="snippet">' + escapeHTML(result.snippet) + '</p>';
247
+ li.innerHTML = html;
248
+ jQuery.data(li, 'path', result.path);
249
+ return li;
250
+ }
251
+
252
+ function hlt(html) {
253
+ return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
254
+ }
255
+
256
+ function escapeHTML(html) {
257
+ return html.replace(/[&<>]/g, function(c) {
258
+ return '&#' + c.charCodeAt(0) + ';';
259
+ });
260
+ }
261
+
262
+ });
263
+
264
+ // tree.js ------------------------------------------------
265
+
266
+ Searchdoc.Tree = function(element, tree, panel) {
267
+ this.$element = $(element);
268
+ this.$list = $('ul', element);
269
+ this.tree = tree;
270
+ this.panel = panel;
271
+ this.init();
272
+ }
273
+
274
+ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
275
+ this.init = function() {
276
+ var stopper = document.createElement('li');
277
+ stopper.className = 'stopper';
278
+ this.$list[0].appendChild(stopper);
279
+ for (var i=0, l = this.tree.length; i < l; i++) {
280
+ buildAndAppendItem.call(this, this.tree[i], 0, stopper);
281
+ };
282
+ var _this = this;
283
+ this.$list.click(function(e) {
284
+ var $target = $(e.target),
285
+ $li = $target.closest('li');
286
+ if ($target.hasClass('icon')) {
287
+ _this.toggle($li);
288
+ } else {
289
+ _this.select($li);
290
+ }
291
+ })
292
+
293
+ this.initNavigation();
294
+ if (jQuery.browser.msie) document.body.className += '';
295
+ }
296
+
297
+ this.select = function($li) {
298
+ this.highlight($li);
299
+ var path = $li[0].searchdoc_tree_data.path;
300
+ if (path) this.panel.open(path);
301
+ }
302
+
303
+ this.highlight = function($li) {
304
+ if (this.$current) this.$current.removeClass('current');
305
+ this.$current = $li.addClass('current');
306
+ }
307
+
308
+ this.toggle = function($li) {
309
+ var closed = !$li.hasClass('closed'),
310
+ children = $li[0].searchdoc_tree_data.children;
311
+ $li.toggleClass('closed');
312
+ for (var i=0, l = children.length; i < l; i++) {
313
+ toggleVis.call(this, $(children[i].li), !closed);
314
+ };
315
+ }
316
+
317
+ this.moveRight = function() {
318
+ if (!this.$current) {
319
+ this.highlight(this.$list.find('li:first'));
320
+ return;
321
+ }
322
+ if (this.$current.hasClass('closed')) {
323
+ this.toggle(this.$current);
324
+ }
325
+ }
326
+
327
+ this.moveLeft = function() {
328
+ if (!this.$current) {
329
+ this.highlight(this.$list.find('li:first'));
330
+ return;
331
+ }
332
+ if (!this.$current.hasClass('closed')) {
333
+ this.toggle(this.$current);
334
+ } else {
335
+ var level = this.$current[0].searchdoc_tree_data.level;
336
+ if (level == 0) return;
337
+ var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
338
+ this.$current.removeClass('current');
339
+ $next.addClass('current');
340
+ scrollIntoView($next[0], this.$element[0]);
341
+ this.$current = $next;
342
+ }
343
+ }
344
+
345
+ this.move = function(isDown) {
346
+ if (!this.$current) {
347
+ this.highlight(this.$list.find('li:first'));
348
+ return true;
349
+ }
350
+ var next = this.$current[0];
351
+ if (isDown) {
352
+ do {
353
+ next = next.nextSibling;
354
+ if (next && next.style && next.style.display != 'none') break;
355
+ } while(next);
356
+ } else {
357
+ do {
358
+ next = next.previousSibling;
359
+ if (next && next.style && next.style.display != 'none') break;
360
+ } while(next);
361
+ }
362
+ if (next && next.className.indexOf('stopper') == -1) {
363
+ this.$current.removeClass('current');
364
+ $(next).addClass('current');
365
+ scrollIntoView(next, this.$element[0]);
366
+ this.$current = $(next);
367
+ }
368
+ return true;
369
+ }
370
+
371
+ function toggleVis($li, show) {
372
+ var closed = $li.hasClass('closed'),
373
+ children = $li[0].searchdoc_tree_data.children;
374
+ $li.css('display', show ? '' : 'none')
375
+ if (!show && this.$current && $li[0] == this.$current[0]) {
376
+ this.$current.removeClass('current');
377
+ this.$current = null;
378
+ }
379
+ for (var i=0, l = children.length; i < l; i++) {
380
+ toggleVis.call(this, $(children[i].li), show && !closed);
381
+ };
382
+ }
383
+
384
+ function buildAndAppendItem(item, level, before) {
385
+ var li = renderItem(item, level),
386
+ list = this.$list[0];
387
+ item.li = li;
388
+ list.insertBefore(li, before);
389
+ for (var i=0, l = item[3].length; i < l; i++) {
390
+ buildAndAppendItem.call(this, item[3][i], level + 1, before);
391
+ };
392
+ return li;
393
+ }
394
+
395
+ function renderItem(item, level) {
396
+ var li = document.createElement('li'),
397
+ cnt = document.createElement('div'),
398
+ h1 = document.createElement('h1'),
399
+ p = document.createElement('p'),
400
+ icon, i;
401
+
402
+ li.appendChild(cnt);
403
+ li.style.paddingLeft = getOffset(level);
404
+ cnt.className = 'content';
405
+ if (!item[1]) li.className = 'empty ';
406
+ cnt.appendChild(h1);
407
+ // cnt.appendChild(p);
408
+ h1.appendChild(document.createTextNode(item[0]));
409
+ // p.appendChild(document.createTextNode(item[4]));
410
+ if (item[2]) {
411
+ i = document.createElement('i');
412
+ i.appendChild(document.createTextNode(item[2]));
413
+ h1.appendChild(i);
414
+ }
415
+ if (item[3].length > 0) {
416
+ icon = document.createElement('div');
417
+ icon.className = 'icon';
418
+ cnt.appendChild(icon);
419
+ }
420
+
421
+ // user direct assignement instead of $()
422
+ // it's 8x faster
423
+ // $(li).data('path', item[1])
424
+ // .data('children', item[3])
425
+ // .data('level', level)
426
+ // .css('display', level == 0 ? '' : 'none')
427
+ // .addClass('level_' + level)
428
+ // .addClass('closed');
429
+ li.searchdoc_tree_data = {
430
+ path: item[1],
431
+ children: item[3],
432
+ level: level
433
+ }
434
+ li.style.display = level == 0 ? '' : 'none';
435
+ li.className += 'level_' + level + ' closed';
436
+ return li;
437
+ }
438
+
439
+ function getOffset(level) {
440
+ return 5 + 18*level + 'px';
441
+ }
442
+ });