rrd-grapher 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +9 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +11 -0
  4. data/Guardfile +123 -0
  5. data/README.md +91 -0
  6. data/Rakefile +42 -0
  7. data/example_app/Gemfile +9 -0
  8. data/example_app/Guardfile +18 -0
  9. data/example_app/app.rb +38 -0
  10. data/example_app/assets/javascripts/available_rrds.coffee +13 -0
  11. data/example_app/assets/javascripts/collectd.coffee +48 -0
  12. data/example_app/config.ru +9 -0
  13. data/example_app/public/.gitignore +1 -0
  14. data/example_app/public/chosen/chosen-sprite.png +0 -0
  15. data/example_app/public/chosen/chosen.css +340 -0
  16. data/example_app/public/chosen/chosen.jquery.js +786 -0
  17. data/example_app/public/chosen/chosen.jquery.min.js +10 -0
  18. data/example_app/public/javascripts/available_rrds.js +16 -0
  19. data/example_app/public/javascripts/collectd.js +64 -0
  20. data/example_app/public/javascripts/jquery.timeago.js +148 -0
  21. data/example_app/public/stylesheets/Aristo/images/bg_fallback.png +0 -0
  22. data/example_app/public/stylesheets/Aristo/images/icon_sprite.png +0 -0
  23. data/example_app/public/stylesheets/Aristo/images/progress_bar.gif +0 -0
  24. data/example_app/public/stylesheets/Aristo/images/slider_handles.png +0 -0
  25. data/example_app/public/stylesheets/Aristo/images/ui-icons_222222_256x240.png +0 -0
  26. data/example_app/public/stylesheets/Aristo/images/ui-icons_454545_256x240.png +0 -0
  27. data/example_app/public/stylesheets/Aristo/theme.css +738 -0
  28. data/example_app/views/available_rrds.haml +26 -0
  29. data/example_app/views/collectd.haml +30 -0
  30. data/example_app/views/layout.haml +19 -0
  31. data/example_app/views/stylesheets/available_rrds.scss +7 -0
  32. data/example_notifier/Gemfile +2 -0
  33. data/example_notifier/notifier.rb +25 -0
  34. data/lib/rrd-grapher/assets/javascripts/app-dev.js +20 -0
  35. data/lib/rrd-grapher/assets/javascripts/app.js +20 -0
  36. data/lib/rrd-grapher/assets/javascripts/classes/format.coffee +35 -0
  37. data/lib/rrd-grapher/assets/javascripts/classes/graph.coffee +306 -0
  38. data/lib/rrd-grapher/assets/javascripts/classes/graph_definition.coffee +216 -0
  39. data/lib/rrd-grapher/assets/javascripts/classes/serie.coffee +13 -0
  40. data/lib/rrd-grapher/assets/javascripts/classes/size.coffee +5 -0
  41. data/lib/rrd-grapher/assets/javascripts/classes/static_line.coffee +44 -0
  42. data/lib/rrd-grapher/assets/javascripts/classes/time.coffee +17 -0
  43. data/lib/rrd-grapher/notifier/alarm_manager.rb +190 -0
  44. data/lib/rrd-grapher/notifier/alarm_trigger.rb +187 -0
  45. data/lib/rrd-grapher/notifier/alarms.rb +79 -0
  46. data/lib/rrd-grapher/notifier/collectdrb.rb +86 -0
  47. data/lib/rrd-grapher/notifier/data_struct.rb +46 -0
  48. data/lib/rrd-grapher/notifier/default_user_handler.rb +36 -0
  49. data/lib/rrd-grapher/notifier/parsers/bindata_parser.rb +144 -0
  50. data/lib/rrd-grapher/notifier/parsers/ruby_parser.rb +134 -0
  51. data/lib/rrd-grapher/notifier/structures.rb +80 -0
  52. data/lib/rrd-grapher/notifier.rb +87 -0
  53. data/lib/rrd-grapher/public/favicon.ico +0 -0
  54. data/lib/rrd-grapher/public/javascripts/app-dev.js +13709 -0
  55. data/lib/rrd-grapher/public/javascripts/app.js +4057 -0
  56. data/lib/rrd-grapher/public/javascripts/backbone/backbone.js +1155 -0
  57. data/lib/rrd-grapher/public/javascripts/backbone/backbone.min.js +32 -0
  58. data/lib/rrd-grapher/public/javascripts/backbone/underscore.js +841 -0
  59. data/lib/rrd-grapher/public/javascripts/backbone/underscore.min.js +27 -0
  60. data/lib/rrd-grapher/public/javascripts/classes/format.js +42 -0
  61. data/lib/rrd-grapher/public/javascripts/classes/graph.js +360 -0
  62. data/lib/rrd-grapher/public/javascripts/classes/graph_definition.js +298 -0
  63. data/lib/rrd-grapher/public/javascripts/classes/serie.js +32 -0
  64. data/lib/rrd-grapher/public/javascripts/classes/size.js +7 -0
  65. data/lib/rrd-grapher/public/javascripts/classes/static_line.js +48 -0
  66. data/lib/rrd-grapher/public/javascripts/classes/time.js +17 -0
  67. data/lib/rrd-grapher/public/javascripts/flot/.gitignore +4 -0
  68. data/lib/rrd-grapher/public/javascripts/flot/excanvas.min.js +1 -0
  69. data/lib/rrd-grapher/public/javascripts/flot/jquery.colorhelpers.min.js +1 -0
  70. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.crosshair.min.js +1 -0
  71. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.fillbetween.min.js +1 -0
  72. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.image.min.js +1 -0
  73. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.js +2604 -0
  74. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.navigate.min.js +1 -0
  75. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.pie.min.js +1 -0
  76. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.resize.min.js +1 -0
  77. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.selection.js +345 -0
  78. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.selection.min.js +1 -0
  79. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.stack.min.js +1 -0
  80. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.symbol.min.js +1 -0
  81. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.threshold.min.js +1 -0
  82. data/lib/rrd-grapher/public/javascripts/jquery/jquery-1.6.2.js +8981 -0
  83. data/lib/rrd-grapher/public/javascripts/jquery/jquery-1.6.2.min.js +18 -0
  84. data/lib/rrd-grapher/public/javascripts/jquery/jquery-ui-1.8.11.min.js +783 -0
  85. data/lib/rrd-grapher/public/javascripts/jquery/jquery.showtime.js +63 -0
  86. data/lib/rrd-grapher/public/javascripts/jquery/jquery.tpl.min.js +10 -0
  87. data/lib/rrd-grapher/resources.rb +14 -0
  88. data/lib/rrd-grapher/rrd.rb +238 -0
  89. data/lib/rrd-grapher/rrd_server.rb +78 -0
  90. data/lib/rrd-grapher/version.rb +4 -0
  91. data/lib/rrd-grapher/views/stylesheets/app.scss +111 -0
  92. data/lib/rrd-grapher.rb +12 -0
  93. data/rrd-grapher.gemspec +47 -0
  94. data/spec/common.rb +70 -0
  95. data/spec/data/myrouter.rrd +0 -0
  96. data/spec/data/subdata.rrd +0 -0
  97. data/spec/data/test.rrd +0 -0
  98. data/spec/factories.rb +23 -0
  99. data/spec/javascripts/helpers/jasmine-jquery-1.3.0.js +283 -0
  100. data/spec/javascripts/source/format_spec.coffee +18 -0
  101. data/spec/javascripts/source/graph_def_spec.coffee +27 -0
  102. data/spec/javascripts/source/graph_spec.coffee +63 -0
  103. data/spec/javascripts/source/serie_spec.coffee +28 -0
  104. data/spec/javascripts/source/static_line_spec.coffee +13 -0
  105. data/spec/javascripts/source/time_spec.coffee +26 -0
  106. data/spec/javascripts/support/jasmine.yml +78 -0
  107. data/spec/javascripts/support/jasmine_config.rb +23 -0
  108. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  109. data/spec/unit/alarm_manager_spec.rb +252 -0
  110. data/spec/unit/alarm_trigger_spec.rb +26 -0
  111. data/spec/unit/data_struct_spec.rb +55 -0
  112. data/spec/unit/notifier_spec.rb +45 -0
  113. data/spec/unit/parsers/bindata_parser_spec.rb +184 -0
  114. data/spec/unit/parsers/ruby_parser_spec.rb +184 -0
  115. data/spec/unit/rrd_spec.rb +50 -0
  116. data/spec/unit/structures_spec.rb +28 -0
  117. data/tests/4series.rrd +0 -0
  118. data/tests/analyze_rrd.rb +62 -0
  119. data/tests/exact.rrd +0 -0
  120. data/tests/exact2.rrd +0 -0
  121. data/tests/filler.rb +46 -0
  122. metadata +414 -0
@@ -0,0 +1,786 @@
1
+ // Chosen, a Select Box Enhancer for jQuery and Protoype
2
+ // by Patrick Filler for Harvest, http://getharvest.com
3
+ //
4
+ // Version 0.9
5
+ // Full source at https://github.com/harvesthq/chosen
6
+ // Copyright (c) 2011 Harvest http://getharvest.com
7
+
8
+ // MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
9
+ // This file is generated by `cake build`, do not edit it by hand.
10
+ (function() {
11
+ /*
12
+ Chosen source: generate output using 'cake build'
13
+ Copyright (c) 2011 by Harvest
14
+ */ var $, Chosen, get_side_border_padding, root;
15
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
16
+ root = this;
17
+ $ = jQuery;
18
+ $.fn.extend({
19
+ chosen: function(data, options) {
20
+ return $(this).each(function(input_field) {
21
+ if (!($(this)).hasClass("chzn-done")) {
22
+ return new Chosen(this, data, options);
23
+ }
24
+ });
25
+ }
26
+ });
27
+ Chosen = (function() {
28
+ function Chosen(elmn) {
29
+ this.set_default_values();
30
+ this.form_field = elmn;
31
+ this.form_field_jq = $(this.form_field);
32
+ this.is_multiple = this.form_field.multiple;
33
+ this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
34
+ this.default_text_default = this.form_field.multiple ? "Select Some Options" : "Select an Option";
35
+ this.set_up_html();
36
+ this.register_observers();
37
+ this.form_field_jq.addClass("chzn-done");
38
+ }
39
+ Chosen.prototype.set_default_values = function() {
40
+ this.click_test_action = __bind(function(evt) {
41
+ return this.test_active_click(evt);
42
+ }, this);
43
+ this.active_field = false;
44
+ this.mouse_on_container = false;
45
+ this.results_showing = false;
46
+ this.result_highlighted = null;
47
+ this.result_single_selected = null;
48
+ return this.choices = 0;
49
+ };
50
+ Chosen.prototype.set_up_html = function() {
51
+ var container_div, dd_top, dd_width, sf_width;
52
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
53
+ this.container_id += "_chzn";
54
+ this.f_width = this.form_field_jq.width();
55
+ this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
56
+ container_div = $("<div />", {
57
+ id: this.container_id,
58
+ "class": "chzn-container " + (this.is_rtl ? ' chzn-rtl' : void 0),
59
+ style: 'width: ' + this.f_width + 'px;'
60
+ });
61
+ if (this.is_multiple) {
62
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
63
+ } else {
64
+ container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
65
+ }
66
+ this.form_field_jq.hide().after(container_div);
67
+ this.container = $('#' + this.container_id);
68
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
69
+ this.dropdown = this.container.find('div.chzn-drop').first();
70
+ dd_top = this.container.height();
71
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
72
+ this.dropdown.css({
73
+ "width": dd_width + "px",
74
+ "top": dd_top + "px"
75
+ });
76
+ this.search_field = this.container.find('input').first();
77
+ this.search_results = this.container.find('ul.chzn-results').first();
78
+ this.search_field_scale();
79
+ this.search_no_results = this.container.find('li.no-results').first();
80
+ if (this.is_multiple) {
81
+ this.search_choices = this.container.find('ul.chzn-choices').first();
82
+ this.search_container = this.container.find('li.search-field').first();
83
+ } else {
84
+ this.search_container = this.container.find('div.chzn-search').first();
85
+ this.selected_item = this.container.find('.chzn-single').first();
86
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
87
+ this.search_field.css({
88
+ "width": sf_width + "px"
89
+ });
90
+ }
91
+ this.results_build();
92
+ return this.set_tab_index();
93
+ };
94
+ Chosen.prototype.register_observers = function() {
95
+ this.container.click(__bind(function(evt) {
96
+ return this.container_click(evt);
97
+ }, this));
98
+ this.container.mouseenter(__bind(function(evt) {
99
+ return this.mouse_enter(evt);
100
+ }, this));
101
+ this.container.mouseleave(__bind(function(evt) {
102
+ return this.mouse_leave(evt);
103
+ }, this));
104
+ this.search_results.click(__bind(function(evt) {
105
+ return this.search_results_click(evt);
106
+ }, this));
107
+ this.search_results.mouseover(__bind(function(evt) {
108
+ return this.search_results_mouseover(evt);
109
+ }, this));
110
+ this.search_results.mouseout(__bind(function(evt) {
111
+ return this.search_results_mouseout(evt);
112
+ }, this));
113
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
114
+ return this.results_update_field(evt);
115
+ }, this));
116
+ this.search_field.blur(__bind(function(evt) {
117
+ return this.input_blur(evt);
118
+ }, this));
119
+ this.search_field.keyup(__bind(function(evt) {
120
+ return this.keyup_checker(evt);
121
+ }, this));
122
+ this.search_field.keydown(__bind(function(evt) {
123
+ return this.keydown_checker(evt);
124
+ }, this));
125
+ if (this.is_multiple) {
126
+ this.search_choices.click(__bind(function(evt) {
127
+ return this.choices_click(evt);
128
+ }, this));
129
+ return this.search_field.focus(__bind(function(evt) {
130
+ return this.input_focus(evt);
131
+ }, this));
132
+ } else {
133
+ return this.selected_item.focus(__bind(function(evt) {
134
+ return this.activate_field(evt);
135
+ }, this));
136
+ }
137
+ };
138
+ Chosen.prototype.container_click = function(evt) {
139
+ if (evt && evt.type === "click") {
140
+ evt.stopPropagation();
141
+ }
142
+ if (!this.pending_destroy_click) {
143
+ if (!this.active_field) {
144
+ if (this.is_multiple) {
145
+ this.search_field.val("");
146
+ }
147
+ $(document).click(this.click_test_action);
148
+ this.results_show();
149
+ } else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
150
+ evt.preventDefault();
151
+ this.results_toggle();
152
+ }
153
+ return this.activate_field();
154
+ } else {
155
+ return this.pending_destroy_click = false;
156
+ }
157
+ };
158
+ Chosen.prototype.mouse_enter = function() {
159
+ return this.mouse_on_container = true;
160
+ };
161
+ Chosen.prototype.mouse_leave = function() {
162
+ return this.mouse_on_container = false;
163
+ };
164
+ Chosen.prototype.input_focus = function(evt) {
165
+ if (!this.active_field) {
166
+ return setTimeout((__bind(function() {
167
+ return this.container_click();
168
+ }, this)), 50);
169
+ }
170
+ };
171
+ Chosen.prototype.input_blur = function(evt) {
172
+ if (!this.mouse_on_container) {
173
+ this.active_field = false;
174
+ return setTimeout((__bind(function() {
175
+ return this.blur_test();
176
+ }, this)), 100);
177
+ }
178
+ };
179
+ Chosen.prototype.blur_test = function(evt) {
180
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
181
+ return this.close_field();
182
+ }
183
+ };
184
+ Chosen.prototype.close_field = function() {
185
+ $(document).unbind("click", this.click_test_action);
186
+ if (!this.is_multiple) {
187
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
188
+ this.search_field.attr("tabindex", -1);
189
+ }
190
+ this.active_field = false;
191
+ this.results_hide();
192
+ this.container.removeClass("chzn-container-active");
193
+ this.winnow_results_clear();
194
+ this.clear_backstroke();
195
+ this.show_search_field_default();
196
+ return this.search_field_scale();
197
+ };
198
+ Chosen.prototype.activate_field = function() {
199
+ if (!this.is_multiple && !this.active_field) {
200
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
201
+ this.selected_item.attr("tabindex", -1);
202
+ }
203
+ this.container.addClass("chzn-container-active");
204
+ this.active_field = true;
205
+ this.search_field.val(this.search_field.val());
206
+ return this.search_field.focus();
207
+ };
208
+ Chosen.prototype.test_active_click = function(evt) {
209
+ if ($(evt.target).parents('#' + this.container_id).length) {
210
+ return this.active_field = true;
211
+ } else {
212
+ return this.close_field();
213
+ }
214
+ };
215
+ Chosen.prototype.results_build = function() {
216
+ var content, data, startTime, _i, _len, _ref;
217
+ startTime = new Date();
218
+ this.parsing = true;
219
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
220
+ if (this.is_multiple && this.choices > 0) {
221
+ this.search_choices.find("li.search-choice").remove();
222
+ this.choices = 0;
223
+ } else if (!this.is_multiple) {
224
+ this.selected_item.find("span").text(this.default_text);
225
+ }
226
+ content = '';
227
+ _ref = this.results_data;
228
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
229
+ data = _ref[_i];
230
+ if (data.group) {
231
+ content += this.result_add_group(data);
232
+ } else if (!data.empty) {
233
+ content += this.result_add_option(data);
234
+ if (data.selected && this.is_multiple) {
235
+ this.choice_build(data);
236
+ } else if (data.selected && !this.is_multiple) {
237
+ this.selected_item.find("span").text(data.text);
238
+ }
239
+ }
240
+ }
241
+ this.show_search_field_default();
242
+ this.search_field_scale();
243
+ this.search_results.html(content);
244
+ return this.parsing = false;
245
+ };
246
+ Chosen.prototype.result_add_group = function(group) {
247
+ if (!group.disabled) {
248
+ group.dom_id = this.container_id + "_g_" + group.array_index;
249
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
250
+ } else {
251
+ return "";
252
+ }
253
+ };
254
+ Chosen.prototype.result_add_option = function(option) {
255
+ var classes;
256
+ if (!option.disabled) {
257
+ option.dom_id = this.container_id + "_o_" + option.array_index;
258
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
259
+ if (option.selected) {
260
+ classes.push("result-selected");
261
+ }
262
+ if (option.group_array_index != null) {
263
+ classes.push("group-option");
264
+ }
265
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>';
266
+ } else {
267
+ return "";
268
+ }
269
+ };
270
+ Chosen.prototype.results_update_field = function() {
271
+ this.result_clear_highlight();
272
+ this.result_single_selected = null;
273
+ return this.results_build();
274
+ };
275
+ Chosen.prototype.result_do_highlight = function(el) {
276
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
277
+ if (el.length) {
278
+ this.result_clear_highlight();
279
+ this.result_highlight = el;
280
+ this.result_highlight.addClass("highlighted");
281
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
282
+ visible_top = this.search_results.scrollTop();
283
+ visible_bottom = maxHeight + visible_top;
284
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
285
+ high_bottom = high_top + this.result_highlight.outerHeight();
286
+ if (high_bottom >= visible_bottom) {
287
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
288
+ } else if (high_top < visible_top) {
289
+ return this.search_results.scrollTop(high_top);
290
+ }
291
+ }
292
+ };
293
+ Chosen.prototype.result_clear_highlight = function() {
294
+ if (this.result_highlight) {
295
+ this.result_highlight.removeClass("highlighted");
296
+ }
297
+ return this.result_highlight = null;
298
+ };
299
+ Chosen.prototype.results_toggle = function() {
300
+ if (this.results_showing) {
301
+ return this.results_hide();
302
+ } else {
303
+ return this.results_show();
304
+ }
305
+ };
306
+ Chosen.prototype.results_show = function() {
307
+ var dd_top;
308
+ if (!this.is_multiple) {
309
+ this.selected_item.addClass("chzn-single-with-drop");
310
+ if (this.result_single_selected) {
311
+ this.result_do_highlight(this.result_single_selected);
312
+ }
313
+ }
314
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
315
+ this.dropdown.css({
316
+ "top": dd_top + "px",
317
+ "left": 0
318
+ });
319
+ this.results_showing = true;
320
+ this.search_field.focus();
321
+ this.search_field.val(this.search_field.val());
322
+ return this.winnow_results();
323
+ };
324
+ Chosen.prototype.results_hide = function() {
325
+ if (!this.is_multiple) {
326
+ this.selected_item.removeClass("chzn-single-with-drop");
327
+ }
328
+ this.result_clear_highlight();
329
+ this.dropdown.css({
330
+ "left": "-9000px"
331
+ });
332
+ return this.results_showing = false;
333
+ };
334
+ Chosen.prototype.set_tab_index = function(el) {
335
+ var ti;
336
+ if (this.form_field_jq.attr("tabindex")) {
337
+ ti = this.form_field_jq.attr("tabindex");
338
+ this.form_field_jq.attr("tabindex", -1);
339
+ if (this.is_multiple) {
340
+ return this.search_field.attr("tabindex", ti);
341
+ } else {
342
+ this.selected_item.attr("tabindex", ti);
343
+ return this.search_field.attr("tabindex", -1);
344
+ }
345
+ }
346
+ };
347
+ Chosen.prototype.show_search_field_default = function() {
348
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
349
+ this.search_field.val(this.default_text);
350
+ return this.search_field.addClass("default");
351
+ } else {
352
+ this.search_field.val("");
353
+ return this.search_field.removeClass("default");
354
+ }
355
+ };
356
+ Chosen.prototype.search_results_click = function(evt) {
357
+ var target;
358
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
359
+ if (target.length) {
360
+ this.result_highlight = target;
361
+ return this.result_select();
362
+ }
363
+ };
364
+ Chosen.prototype.search_results_mouseover = function(evt) {
365
+ var target;
366
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
367
+ if (target) {
368
+ return this.result_do_highlight(target);
369
+ }
370
+ };
371
+ Chosen.prototype.search_results_mouseout = function(evt) {
372
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
373
+ return this.result_clear_highlight();
374
+ }
375
+ };
376
+ Chosen.prototype.choices_click = function(evt) {
377
+ evt.preventDefault();
378
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
379
+ return this.results_show();
380
+ }
381
+ };
382
+ Chosen.prototype.choice_build = function(item) {
383
+ var choice_id, link;
384
+ choice_id = this.container_id + "_c_" + item.array_index;
385
+ this.choices += 1;
386
+ this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
387
+ link = $('#' + choice_id).find("a").first();
388
+ return link.click(__bind(function(evt) {
389
+ return this.choice_destroy_link_click(evt);
390
+ }, this));
391
+ };
392
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
393
+ evt.preventDefault();
394
+ this.pending_destroy_click = true;
395
+ return this.choice_destroy($(evt.target));
396
+ };
397
+ Chosen.prototype.choice_destroy = function(link) {
398
+ this.choices -= 1;
399
+ this.show_search_field_default();
400
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
401
+ this.results_hide();
402
+ }
403
+ this.result_deselect(link.attr("rel"));
404
+ return link.parents('li').first().remove();
405
+ };
406
+ Chosen.prototype.result_select = function() {
407
+ var high, high_id, item, position;
408
+ if (this.result_highlight) {
409
+ high = this.result_highlight;
410
+ high_id = high.attr("id");
411
+ this.result_clear_highlight();
412
+ high.addClass("result-selected");
413
+ if (this.is_multiple) {
414
+ this.result_deactivate(high);
415
+ } else {
416
+ this.result_single_selected = high;
417
+ }
418
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
419
+ item = this.results_data[position];
420
+ item.selected = true;
421
+ this.form_field.options[item.options_index].selected = true;
422
+ if (this.is_multiple) {
423
+ this.choice_build(item);
424
+ } else {
425
+ this.selected_item.find("span").first().text(item.text);
426
+ }
427
+ this.results_hide();
428
+ this.search_field.val("");
429
+ this.form_field_jq.trigger("change");
430
+ return this.search_field_scale();
431
+ }
432
+ };
433
+ Chosen.prototype.result_activate = function(el) {
434
+ return el.addClass("active-result").show();
435
+ };
436
+ Chosen.prototype.result_deactivate = function(el) {
437
+ return el.removeClass("active-result").hide();
438
+ };
439
+ Chosen.prototype.result_deselect = function(pos) {
440
+ var result, result_data;
441
+ result_data = this.results_data[pos];
442
+ result_data.selected = false;
443
+ this.form_field.options[result_data.options_index].selected = false;
444
+ result = $("#" + this.container_id + "_o_" + pos);
445
+ result.removeClass("result-selected").addClass("active-result").show();
446
+ this.result_clear_highlight();
447
+ this.winnow_results();
448
+ this.form_field_jq.trigger("change");
449
+ return this.search_field_scale();
450
+ };
451
+ Chosen.prototype.results_search = function(evt) {
452
+ if (this.results_showing) {
453
+ return this.winnow_results();
454
+ } else {
455
+ return this.results_show();
456
+ }
457
+ };
458
+ Chosen.prototype.winnow_results = function() {
459
+ var found, option, part, parts, regex, result_id, results, searchText, startTime, startpos, text, zregex, _i, _j, _len, _len2, _ref;
460
+ startTime = new Date();
461
+ this.no_results_clear();
462
+ results = 0;
463
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
464
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
465
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
466
+ _ref = this.results_data;
467
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
468
+ option = _ref[_i];
469
+ if (!option.disabled && !option.empty) {
470
+ if (option.group) {
471
+ $('#' + option.dom_id).hide();
472
+ } else if (!(this.is_multiple && option.selected)) {
473
+ found = false;
474
+ result_id = option.dom_id;
475
+ if (regex.test(option.html)) {
476
+ found = true;
477
+ results += 1;
478
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
479
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
480
+ if (parts.length) {
481
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
482
+ part = parts[_j];
483
+ if (regex.test(part)) {
484
+ found = true;
485
+ results += 1;
486
+ }
487
+ }
488
+ }
489
+ }
490
+ if (found) {
491
+ if (searchText.length) {
492
+ startpos = option.html.search(zregex);
493
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
494
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
495
+ } else {
496
+ text = option.html;
497
+ }
498
+ if ($("#" + result_id).html !== text) {
499
+ $("#" + result_id).html(text);
500
+ }
501
+ this.result_activate($("#" + result_id));
502
+ if (option.group_array_index != null) {
503
+ $("#" + this.results_data[option.group_array_index].dom_id).show();
504
+ }
505
+ } else {
506
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
507
+ this.result_clear_highlight();
508
+ }
509
+ this.result_deactivate($("#" + result_id));
510
+ }
511
+ }
512
+ }
513
+ }
514
+ if (results < 1 && searchText.length) {
515
+ return this.no_results(searchText);
516
+ } else {
517
+ return this.winnow_results_set_highlight();
518
+ }
519
+ };
520
+ Chosen.prototype.winnow_results_clear = function() {
521
+ var li, lis, _i, _len, _results;
522
+ this.search_field.val("");
523
+ lis = this.search_results.find("li");
524
+ _results = [];
525
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
526
+ li = lis[_i];
527
+ li = $(li);
528
+ _results.push(li.hasClass("group-result") ? li.show() : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
529
+ }
530
+ return _results;
531
+ };
532
+ Chosen.prototype.winnow_results_set_highlight = function() {
533
+ var do_high;
534
+ if (!this.result_highlight) {
535
+ do_high = this.search_results.find(".active-result").first();
536
+ if (do_high) {
537
+ return this.result_do_highlight(do_high);
538
+ }
539
+ }
540
+ };
541
+ Chosen.prototype.no_results = function(terms) {
542
+ var no_results_html;
543
+ no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
544
+ no_results_html.find("span").first().html(terms);
545
+ return this.search_results.append(no_results_html);
546
+ };
547
+ Chosen.prototype.no_results_clear = function() {
548
+ return this.search_results.find(".no-results").remove();
549
+ };
550
+ Chosen.prototype.keydown_arrow = function() {
551
+ var first_active, next_sib;
552
+ if (!this.result_highlight) {
553
+ first_active = this.search_results.find("li.active-result").first();
554
+ if (first_active) {
555
+ this.result_do_highlight($(first_active));
556
+ }
557
+ } else if (this.results_showing) {
558
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
559
+ if (next_sib) {
560
+ this.result_do_highlight(next_sib);
561
+ }
562
+ }
563
+ if (!this.results_showing) {
564
+ return this.results_show();
565
+ }
566
+ };
567
+ Chosen.prototype.keyup_arrow = function() {
568
+ var prev_sibs;
569
+ if (!this.results_showing && !this.is_multiple) {
570
+ return this.results_show();
571
+ } else if (this.result_highlight) {
572
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
573
+ if (prev_sibs.length) {
574
+ return this.result_do_highlight(prev_sibs.first());
575
+ } else {
576
+ if (this.choices > 0) {
577
+ this.results_hide();
578
+ }
579
+ return this.result_clear_highlight();
580
+ }
581
+ }
582
+ };
583
+ Chosen.prototype.keydown_backstroke = function() {
584
+ if (this.pending_backstroke) {
585
+ this.choice_destroy(this.pending_backstroke.find("a").first());
586
+ return this.clear_backstroke();
587
+ } else {
588
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
589
+ return this.pending_backstroke.addClass("search-choice-focus");
590
+ }
591
+ };
592
+ Chosen.prototype.clear_backstroke = function() {
593
+ if (this.pending_backstroke) {
594
+ this.pending_backstroke.removeClass("search-choice-focus");
595
+ }
596
+ return this.pending_backstroke = null;
597
+ };
598
+ Chosen.prototype.keyup_checker = function(evt) {
599
+ var stroke, _ref;
600
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
601
+ this.search_field_scale();
602
+ switch (stroke) {
603
+ case 8:
604
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
605
+ return this.keydown_backstroke();
606
+ } else if (!this.pending_backstroke) {
607
+ this.result_clear_highlight();
608
+ return this.results_search();
609
+ }
610
+ break;
611
+ case 13:
612
+ evt.preventDefault();
613
+ if (this.results_showing) {
614
+ return this.result_select();
615
+ }
616
+ break;
617
+ case 27:
618
+ if (this.results_showing) {
619
+ return this.results_hide();
620
+ }
621
+ break;
622
+ case 9:
623
+ case 38:
624
+ case 40:
625
+ case 16:
626
+ break;
627
+ default:
628
+ return this.results_search();
629
+ }
630
+ };
631
+ Chosen.prototype.keydown_checker = function(evt) {
632
+ var stroke, _ref;
633
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
634
+ this.search_field_scale();
635
+ if (stroke !== 8 && this.pending_backstroke) {
636
+ this.clear_backstroke();
637
+ }
638
+ switch (stroke) {
639
+ case 8:
640
+ this.backstroke_length = this.search_field.val().length;
641
+ break;
642
+ case 9:
643
+ this.mouse_on_container = false;
644
+ break;
645
+ case 13:
646
+ evt.preventDefault();
647
+ break;
648
+ case 38:
649
+ evt.preventDefault();
650
+ this.keyup_arrow();
651
+ break;
652
+ case 40:
653
+ this.keydown_arrow();
654
+ break;
655
+ }
656
+ };
657
+ Chosen.prototype.search_field_scale = function() {
658
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
659
+ if (this.is_multiple) {
660
+ h = 0;
661
+ w = 0;
662
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
663
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
664
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
665
+ style = styles[_i];
666
+ style_block += style + ":" + this.search_field.css(style) + ";";
667
+ }
668
+ div = $('<div />', {
669
+ 'style': style_block
670
+ });
671
+ div.text(this.search_field.val());
672
+ $('body').append(div);
673
+ w = div.width() + 25;
674
+ div.remove();
675
+ if (w > this.f_width - 10) {
676
+ w = this.f_width - 10;
677
+ }
678
+ this.search_field.css({
679
+ 'width': w + 'px'
680
+ });
681
+ dd_top = this.container.height();
682
+ return this.dropdown.css({
683
+ "top": dd_top + "px"
684
+ });
685
+ }
686
+ };
687
+ Chosen.prototype.generate_field_id = function() {
688
+ var new_id;
689
+ new_id = this.generate_random_id();
690
+ this.form_field.id = new_id;
691
+ return new_id;
692
+ };
693
+ Chosen.prototype.generate_random_id = function() {
694
+ var string;
695
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
696
+ while ($("#" + string).length > 0) {
697
+ string += this.generate_random_char();
698
+ }
699
+ return string;
700
+ };
701
+ Chosen.prototype.generate_random_char = function() {
702
+ var chars, newchar, rand;
703
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
704
+ rand = Math.floor(Math.random() * chars.length);
705
+ return newchar = chars.substring(rand, rand + 1);
706
+ };
707
+ return Chosen;
708
+ })();
709
+ get_side_border_padding = function(elmt) {
710
+ var side_border_padding;
711
+ return side_border_padding = elmt.outerWidth() - elmt.width();
712
+ };
713
+ root.get_side_border_padding = get_side_border_padding;
714
+ }).call(this);
715
+ (function() {
716
+ var SelectParser;
717
+ SelectParser = (function() {
718
+ function SelectParser() {
719
+ this.options_index = 0;
720
+ this.parsed = [];
721
+ }
722
+ SelectParser.prototype.add_node = function(child) {
723
+ if (child.nodeName === "OPTGROUP") {
724
+ return this.add_group(child);
725
+ } else {
726
+ return this.add_option(child);
727
+ }
728
+ };
729
+ SelectParser.prototype.add_group = function(group) {
730
+ var group_position, option, _i, _len, _ref, _results;
731
+ group_position = this.parsed.length;
732
+ this.parsed.push({
733
+ array_index: group_position,
734
+ group: true,
735
+ label: group.label,
736
+ children: 0,
737
+ disabled: group.disabled
738
+ });
739
+ _ref = group.childNodes;
740
+ _results = [];
741
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
742
+ option = _ref[_i];
743
+ _results.push(this.add_option(option, group_position, group.disabled));
744
+ }
745
+ return _results;
746
+ };
747
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
748
+ if (option.nodeName === "OPTION") {
749
+ if (option.text !== "") {
750
+ if (group_position != null) {
751
+ this.parsed[group_position].children += 1;
752
+ }
753
+ this.parsed.push({
754
+ array_index: this.parsed.length,
755
+ options_index: this.options_index,
756
+ value: option.value,
757
+ text: option.text,
758
+ html: option.innerHTML,
759
+ selected: option.selected,
760
+ disabled: group_disabled === true ? group_disabled : option.disabled,
761
+ group_array_index: group_position
762
+ });
763
+ } else {
764
+ this.parsed.push({
765
+ array_index: this.parsed.length,
766
+ options_index: this.options_index,
767
+ empty: true
768
+ });
769
+ }
770
+ return this.options_index += 1;
771
+ }
772
+ };
773
+ return SelectParser;
774
+ })();
775
+ SelectParser.select_to_array = function(select) {
776
+ var child, parser, _i, _len, _ref;
777
+ parser = new SelectParser();
778
+ _ref = select.childNodes;
779
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
780
+ child = _ref[_i];
781
+ parser.add_node(child);
782
+ }
783
+ return parser.parsed;
784
+ };
785
+ this.SelectParser = SelectParser;
786
+ }).call(this);