furnace-xray 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/bin/furnace-xray +23 -0
- data/furnace-xray.gemspec +33 -0
- data/lib/furnace-xray.rb +1 -0
- data/lib/furnace-xray/app/app.rb +56 -0
- data/lib/furnace-xray/app/assets/images/chosen-sprite.png +0 -0
- data/lib/furnace-xray/app/assets/images/evil_martians_bw_logo.svg +3 -0
- data/lib/furnace-xray/app/assets/images/evil_martians_logo.svg +3 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_diagonal-maze_20_6e4f1c_10x10.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_diagonal-maze_40_000000_10x10.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_10_eceadf_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_10_f8f7f6_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_eceadf_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_f7f3de_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_ffffff_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_65_654b24_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_68_b83400_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_222222_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_3572ac_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_8c291d_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_b83400_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_fbdb93_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_ffffff_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/javascripts/application.js.coffee +219 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/drawer.js.coffee +206 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/graph.js.coffee +26 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/input.js.coffee +134 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/input_state.js.coffee +8 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/map.js.coffee +45 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/argument.js.coffee +7 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/block.js.coffee +76 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/function.js.coffee +15 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/instruction.js.coffee +33 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/operand.js.coffee +21 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/type.js.coffee +12 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/chosen.jquery.js +1090 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/d3.v3.js +7806 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/dagre.js +4053 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/hotkeys.jquery.js +106 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/jquery.js +9472 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/mustache.js +532 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/stacktrace-0.4.js +424 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/sugar-1.3.8.js +8615 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/ui.jquery.js +14850 -0
- data/lib/furnace-xray/app/assets/stylesheets/app.css.sass +199 -0
- data/lib/furnace-xray/app/assets/stylesheets/chosen.jquery.css +413 -0
- data/lib/furnace-xray/app/assets/stylesheets/elements.css.sass +31 -0
- data/lib/furnace-xray/app/assets/stylesheets/graph.css.sass +29 -0
- data/lib/furnace-xray/app/assets/stylesheets/ui.jquery.css +1174 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.afm +170 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.eot +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.otf +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.svg +553 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.ttf +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.woff +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke_demo.html +1 -0
- data/lib/furnace-xray/app/views/index.haml +52 -0
- data/lib/furnace-xray/app/views/nodes/argument.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/block.jst.mustache +4 -0
- data/lib/furnace-xray/app/views/nodes/diff/added_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/diff/changed_line.jst.mustache +2 -0
- data/lib/furnace-xray/app/views/nodes/diff/removed_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/diff/unchanged_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/function.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/function_removed.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/instruction_typed.jst.mustache +3 -0
- data/lib/furnace-xray/app/views/nodes/instruction_void.jst.mustache +3 -0
- data/lib/furnace-xray/app/views/nodes/operand_argument.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_basic_block.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_constant.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_constant_function.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_instruction.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/type_constant.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/type_parametric.jst.mustache +3 -0
- data/lib/furnace-xray/lib/jst_pages.rb +226 -0
- data/lib/furnace-xray/version.rb +5 -0
- data/sample.json +1 -0
- metadata +251 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
class @FunctionNode
|
2
|
+
constructor: (@name, @present) ->
|
3
|
+
@arguments = []
|
4
|
+
|
5
|
+
setArguments: (@arguments) ->
|
6
|
+
|
7
|
+
setReturnType: (@type) ->
|
8
|
+
|
9
|
+
title: ->
|
10
|
+
template = if @present then 'nodes/function' else 'nodes/function_removed'
|
11
|
+
|
12
|
+
JST[template]
|
13
|
+
type: @type?.title() || '?'
|
14
|
+
name: @name
|
15
|
+
arguments: @arguments.map((x) -> x.title()).join(', ')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class @InstructionNode
|
2
|
+
constructor: ->
|
3
|
+
@blocks = []
|
4
|
+
|
5
|
+
update: (@opcode, @name, @parameters, @operands, @type) ->
|
6
|
+
|
7
|
+
link: (block, index) ->
|
8
|
+
block.addInstruction(@, index)
|
9
|
+
@blocks.add block
|
10
|
+
|
11
|
+
unlink: ->
|
12
|
+
@blocks.each (x) => x.removeInstruction(@)
|
13
|
+
@blocks = []
|
14
|
+
|
15
|
+
title: ->
|
16
|
+
operands = @operands.map (x) ->
|
17
|
+
if x instanceof OperandNode
|
18
|
+
x.title()
|
19
|
+
else
|
20
|
+
"%#{x[0]} => #{x[1].title()}"
|
21
|
+
|
22
|
+
if @type.kind == 'void'
|
23
|
+
JST['nodes/instruction_void']
|
24
|
+
opcode: @opcode
|
25
|
+
parameters: @parameters
|
26
|
+
operands: operands.join(', ')
|
27
|
+
else
|
28
|
+
JST['nodes/instruction_typed']
|
29
|
+
type: @type.title()
|
30
|
+
name: @name
|
31
|
+
opcode: @opcode
|
32
|
+
parameters: @parameters
|
33
|
+
operands: operands.join(', ')
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class @OperandNode
|
2
|
+
|
3
|
+
constructor: (@kind, @type, @name, @value) ->
|
4
|
+
|
5
|
+
title: ->
|
6
|
+
switch @kind
|
7
|
+
when 'argument' then JST['nodes/operand_argument'] name: @name
|
8
|
+
when 'instruction' then JST['nodes/operand_instruction'] name: @name
|
9
|
+
when 'basic_block' then JST['nodes/operand_basic_block'] name: @name
|
10
|
+
when 'constant'
|
11
|
+
data =
|
12
|
+
type: @type.title()
|
13
|
+
value: @value
|
14
|
+
|
15
|
+
if @type.name == 'function'
|
16
|
+
template = 'operand_constant_function'
|
17
|
+
data.parsedValue = JSON.parse(@value)
|
18
|
+
else
|
19
|
+
template = 'operand_constant'
|
20
|
+
|
21
|
+
JST["nodes/#{template}"] data
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class @TypeNode
|
2
|
+
|
3
|
+
constructor: (@kind, @name, @parameters) ->
|
4
|
+
|
5
|
+
title: ->
|
6
|
+
switch @kind
|
7
|
+
when 'void' then JST['nodes/type_constant'](type: 'void')
|
8
|
+
when 'monotype' then JST['nodes/type_constant'](type: @name)
|
9
|
+
when 'parametric'
|
10
|
+
JST['nodes/type_parametric']
|
11
|
+
type: @name
|
12
|
+
parameters: @parameters.map((x) -> x.title()).join(', ')
|
@@ -0,0 +1,1090 @@
|
|
1
|
+
// Chosen, a Select Box Enhancer for jQuery and Protoype
|
2
|
+
// by Patrick Filler for Harvest, http://getharvest.com
|
3
|
+
//
|
4
|
+
// Version 0.9.11
|
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
|
+
var SelectParser;
|
12
|
+
|
13
|
+
SelectParser = (function() {
|
14
|
+
|
15
|
+
function SelectParser() {
|
16
|
+
this.options_index = 0;
|
17
|
+
this.parsed = [];
|
18
|
+
}
|
19
|
+
|
20
|
+
SelectParser.prototype.add_node = function(child) {
|
21
|
+
if (child.nodeName.toUpperCase() === "OPTGROUP") {
|
22
|
+
return this.add_group(child);
|
23
|
+
} else {
|
24
|
+
return this.add_option(child);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
SelectParser.prototype.add_group = function(group) {
|
29
|
+
var group_position, option, _i, _len, _ref, _results;
|
30
|
+
group_position = this.parsed.length;
|
31
|
+
this.parsed.push({
|
32
|
+
array_index: group_position,
|
33
|
+
group: true,
|
34
|
+
label: group.label,
|
35
|
+
children: 0,
|
36
|
+
disabled: group.disabled
|
37
|
+
});
|
38
|
+
_ref = group.childNodes;
|
39
|
+
_results = [];
|
40
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
41
|
+
option = _ref[_i];
|
42
|
+
_results.push(this.add_option(option, group_position, group.disabled));
|
43
|
+
}
|
44
|
+
return _results;
|
45
|
+
};
|
46
|
+
|
47
|
+
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
48
|
+
if (option.nodeName.toUpperCase() === "OPTION") {
|
49
|
+
if (option.text !== "") {
|
50
|
+
if (group_position != null) {
|
51
|
+
this.parsed[group_position].children += 1;
|
52
|
+
}
|
53
|
+
this.parsed.push({
|
54
|
+
array_index: this.parsed.length,
|
55
|
+
options_index: this.options_index,
|
56
|
+
value: option.value,
|
57
|
+
text: option.text,
|
58
|
+
html: option.innerHTML,
|
59
|
+
selected: option.selected,
|
60
|
+
disabled: group_disabled === true ? group_disabled : option.disabled,
|
61
|
+
group_array_index: group_position,
|
62
|
+
classes: option.className,
|
63
|
+
style: option.style.cssText
|
64
|
+
});
|
65
|
+
} else {
|
66
|
+
this.parsed.push({
|
67
|
+
array_index: this.parsed.length,
|
68
|
+
options_index: this.options_index,
|
69
|
+
empty: true
|
70
|
+
});
|
71
|
+
}
|
72
|
+
return this.options_index += 1;
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
return SelectParser;
|
77
|
+
|
78
|
+
})();
|
79
|
+
|
80
|
+
SelectParser.select_to_array = function(select) {
|
81
|
+
var child, parser, _i, _len, _ref;
|
82
|
+
parser = new SelectParser();
|
83
|
+
_ref = select.childNodes;
|
84
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
85
|
+
child = _ref[_i];
|
86
|
+
parser.add_node(child);
|
87
|
+
}
|
88
|
+
return parser.parsed;
|
89
|
+
};
|
90
|
+
|
91
|
+
this.SelectParser = SelectParser;
|
92
|
+
|
93
|
+
}).call(this);
|
94
|
+
|
95
|
+
/*
|
96
|
+
Chosen source: generate output using 'cake build'
|
97
|
+
Copyright (c) 2011 by Harvest
|
98
|
+
*/
|
99
|
+
|
100
|
+
|
101
|
+
(function() {
|
102
|
+
var AbstractChosen, root;
|
103
|
+
|
104
|
+
root = this;
|
105
|
+
|
106
|
+
AbstractChosen = (function() {
|
107
|
+
|
108
|
+
function AbstractChosen(form_field, options) {
|
109
|
+
this.form_field = form_field;
|
110
|
+
this.options = options != null ? options : {};
|
111
|
+
this.is_multiple = this.form_field.multiple;
|
112
|
+
this.set_default_text();
|
113
|
+
this.set_default_values();
|
114
|
+
this.setup();
|
115
|
+
this.set_up_html();
|
116
|
+
this.register_observers();
|
117
|
+
this.finish_setup();
|
118
|
+
}
|
119
|
+
|
120
|
+
AbstractChosen.prototype.set_default_values = function() {
|
121
|
+
var _this = this;
|
122
|
+
this.click_test_action = function(evt) {
|
123
|
+
return _this.test_active_click(evt);
|
124
|
+
};
|
125
|
+
this.activate_action = function(evt) {
|
126
|
+
return _this.activate_field(evt);
|
127
|
+
};
|
128
|
+
this.active_field = false;
|
129
|
+
this.mouse_on_container = false;
|
130
|
+
this.results_showing = false;
|
131
|
+
this.result_highlighted = null;
|
132
|
+
this.result_single_selected = null;
|
133
|
+
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
|
134
|
+
this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
135
|
+
this.disable_search = this.options.disable_search || false;
|
136
|
+
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
|
137
|
+
this.search_contains = this.options.search_contains || false;
|
138
|
+
this.choices = 0;
|
139
|
+
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
|
140
|
+
this.max_selected_options = this.options.max_selected_options || Infinity;
|
141
|
+
return this.inherit_select_classes = this.options.inherit_select_classes || false;
|
142
|
+
};
|
143
|
+
|
144
|
+
AbstractChosen.prototype.set_default_text = function() {
|
145
|
+
if (this.form_field.getAttribute("data-placeholder")) {
|
146
|
+
this.default_text = this.form_field.getAttribute("data-placeholder");
|
147
|
+
} else if (this.is_multiple) {
|
148
|
+
this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
|
149
|
+
} else {
|
150
|
+
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option";
|
151
|
+
}
|
152
|
+
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
|
153
|
+
};
|
154
|
+
|
155
|
+
AbstractChosen.prototype.mouse_enter = function() {
|
156
|
+
return this.mouse_on_container = true;
|
157
|
+
};
|
158
|
+
|
159
|
+
AbstractChosen.prototype.mouse_leave = function() {
|
160
|
+
return this.mouse_on_container = false;
|
161
|
+
};
|
162
|
+
|
163
|
+
AbstractChosen.prototype.input_focus = function(evt) {
|
164
|
+
var _this = this;
|
165
|
+
if (this.is_multiple) {
|
166
|
+
if (!this.active_field) {
|
167
|
+
return setTimeout((function() {
|
168
|
+
return _this.container_mousedown();
|
169
|
+
}), 50);
|
170
|
+
}
|
171
|
+
} else {
|
172
|
+
if (!this.active_field) {
|
173
|
+
return this.activate_field();
|
174
|
+
}
|
175
|
+
}
|
176
|
+
};
|
177
|
+
|
178
|
+
AbstractChosen.prototype.input_blur = function(evt) {
|
179
|
+
var _this = this;
|
180
|
+
if (!this.mouse_on_container) {
|
181
|
+
this.active_field = false;
|
182
|
+
return setTimeout((function() {
|
183
|
+
return _this.blur_test();
|
184
|
+
}), 100);
|
185
|
+
}
|
186
|
+
};
|
187
|
+
|
188
|
+
AbstractChosen.prototype.result_add_option = function(option) {
|
189
|
+
var classes, style;
|
190
|
+
if (!option.disabled) {
|
191
|
+
option.dom_id = this.container_id + "_o_" + option.array_index;
|
192
|
+
classes = option.selected && this.is_multiple ? [] : ["active-result"];
|
193
|
+
if (option.selected) {
|
194
|
+
classes.push("result-selected");
|
195
|
+
}
|
196
|
+
if (option.group_array_index != null) {
|
197
|
+
classes.push("group-option");
|
198
|
+
}
|
199
|
+
if (option.classes !== "") {
|
200
|
+
classes.push(option.classes);
|
201
|
+
}
|
202
|
+
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
|
203
|
+
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
|
204
|
+
} else {
|
205
|
+
return "";
|
206
|
+
}
|
207
|
+
};
|
208
|
+
|
209
|
+
AbstractChosen.prototype.results_update_field = function() {
|
210
|
+
if (!this.is_multiple) {
|
211
|
+
this.results_reset_cleanup();
|
212
|
+
}
|
213
|
+
this.result_clear_highlight();
|
214
|
+
this.result_single_selected = null;
|
215
|
+
return this.results_build();
|
216
|
+
};
|
217
|
+
|
218
|
+
AbstractChosen.prototype.results_toggle = function() {
|
219
|
+
if (this.results_showing) {
|
220
|
+
return this.results_hide();
|
221
|
+
} else {
|
222
|
+
return this.results_show();
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
AbstractChosen.prototype.results_search = function(evt) {
|
227
|
+
if (this.results_showing) {
|
228
|
+
return this.winnow_results();
|
229
|
+
} else {
|
230
|
+
return this.results_show();
|
231
|
+
}
|
232
|
+
};
|
233
|
+
|
234
|
+
AbstractChosen.prototype.keyup_checker = function(evt) {
|
235
|
+
var stroke, _ref;
|
236
|
+
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
237
|
+
|
238
|
+
if (!this.results_showing) {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
|
242
|
+
this.search_field_scale();
|
243
|
+
switch (stroke) {
|
244
|
+
case 8:
|
245
|
+
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
246
|
+
return this.keydown_backstroke();
|
247
|
+
} else if (!this.pending_backstroke) {
|
248
|
+
this.result_clear_highlight();
|
249
|
+
return this.results_search();
|
250
|
+
}
|
251
|
+
break;
|
252
|
+
case 13:
|
253
|
+
evt.preventDefault();
|
254
|
+
if (this.results_showing) {
|
255
|
+
return this.result_select(evt);
|
256
|
+
}
|
257
|
+
break;
|
258
|
+
case 27:
|
259
|
+
if (this.results_showing) {
|
260
|
+
this.results_hide();
|
261
|
+
}
|
262
|
+
return true;
|
263
|
+
case 9:
|
264
|
+
case 38:
|
265
|
+
case 40:
|
266
|
+
case 16:
|
267
|
+
case 91:
|
268
|
+
case 17:
|
269
|
+
break;
|
270
|
+
default:
|
271
|
+
return this.results_search();
|
272
|
+
}
|
273
|
+
};
|
274
|
+
|
275
|
+
AbstractChosen.prototype.generate_field_id = function() {
|
276
|
+
var new_id;
|
277
|
+
new_id = this.generate_random_id();
|
278
|
+
this.form_field.id = new_id;
|
279
|
+
return new_id;
|
280
|
+
};
|
281
|
+
|
282
|
+
AbstractChosen.prototype.generate_random_char = function() {
|
283
|
+
var chars, newchar, rand;
|
284
|
+
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
285
|
+
rand = Math.floor(Math.random() * chars.length);
|
286
|
+
return newchar = chars.substring(rand, rand + 1);
|
287
|
+
};
|
288
|
+
|
289
|
+
return AbstractChosen;
|
290
|
+
|
291
|
+
})();
|
292
|
+
|
293
|
+
root.AbstractChosen = AbstractChosen;
|
294
|
+
|
295
|
+
}).call(this);
|
296
|
+
|
297
|
+
/*
|
298
|
+
Chosen source: generate output using 'cake build'
|
299
|
+
Copyright (c) 2011 by Harvest
|
300
|
+
*/
|
301
|
+
|
302
|
+
|
303
|
+
(function() {
|
304
|
+
var $, Chosen, get_side_border_padding, root,
|
305
|
+
__hasProp = {}.hasOwnProperty,
|
306
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
307
|
+
|
308
|
+
root = this;
|
309
|
+
|
310
|
+
$ = jQuery;
|
311
|
+
|
312
|
+
$.fn.extend({
|
313
|
+
chosen: function(options) {
|
314
|
+
var browser, match, ua;
|
315
|
+
ua = navigator.userAgent.toLowerCase();
|
316
|
+
match = /(msie) ([\w.]+)/.exec(ua) || [];
|
317
|
+
browser = {
|
318
|
+
name: match[1] || "",
|
319
|
+
version: match[2] || "0"
|
320
|
+
};
|
321
|
+
if (browser.name === "msie" && (browser.version === "6.0" || (browser.version === "7.0" && document.documentMode === 7))) {
|
322
|
+
return this;
|
323
|
+
}
|
324
|
+
return this.each(function(input_field) {
|
325
|
+
var $this;
|
326
|
+
$this = $(this);
|
327
|
+
if (!$this.hasClass("chzn-done")) {
|
328
|
+
return $this.data('chosen', new Chosen(this, options));
|
329
|
+
}
|
330
|
+
});
|
331
|
+
}
|
332
|
+
});
|
333
|
+
|
334
|
+
Chosen = (function(_super) {
|
335
|
+
|
336
|
+
__extends(Chosen, _super);
|
337
|
+
|
338
|
+
function Chosen() {
|
339
|
+
return Chosen.__super__.constructor.apply(this, arguments);
|
340
|
+
}
|
341
|
+
|
342
|
+
Chosen.prototype.setup = function() {
|
343
|
+
this.form_field_jq = $(this.form_field);
|
344
|
+
this.current_value = this.form_field_jq.val();
|
345
|
+
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
|
346
|
+
};
|
347
|
+
|
348
|
+
Chosen.prototype.finish_setup = function() {
|
349
|
+
return this.form_field_jq.addClass("chzn-done");
|
350
|
+
};
|
351
|
+
|
352
|
+
Chosen.prototype.set_up_html = function() {
|
353
|
+
var container_classes, container_div, container_props, dd_top, dd_width, sf_width;
|
354
|
+
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
|
355
|
+
this.container_id += "_chzn";
|
356
|
+
container_classes = ["chzn-container"];
|
357
|
+
container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
358
|
+
if (this.inherit_select_classes && this.form_field.className) {
|
359
|
+
container_classes.push(this.form_field.className);
|
360
|
+
}
|
361
|
+
if (this.is_rtl) {
|
362
|
+
container_classes.push("chzn-rtl");
|
363
|
+
}
|
364
|
+
this.f_width = this.form_field_jq.outerWidth();
|
365
|
+
container_props = {
|
366
|
+
id: this.container_id,
|
367
|
+
"class": container_classes.join(' '),
|
368
|
+
style: 'width: ' + this.f_width + 'px;',
|
369
|
+
title: this.form_field.title
|
370
|
+
};
|
371
|
+
container_div = $("<div />", container_props);
|
372
|
+
if (this.is_multiple) {
|
373
|
+
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>');
|
374
|
+
} else {
|
375
|
+
container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
|
376
|
+
}
|
377
|
+
this.form_field_jq.hide().after(container_div);
|
378
|
+
this.container = $('#' + this.container_id);
|
379
|
+
this.dropdown = this.container.find('div.chzn-drop').first();
|
380
|
+
dd_top = this.container.height();
|
381
|
+
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
382
|
+
this.dropdown.css({
|
383
|
+
"width": dd_width + "px",
|
384
|
+
"top": dd_top + "px"
|
385
|
+
});
|
386
|
+
this.search_field = this.container.find('input').first();
|
387
|
+
this.search_results = this.container.find('ul.chzn-results').first();
|
388
|
+
this.search_field_scale();
|
389
|
+
this.search_no_results = this.container.find('li.no-results').first();
|
390
|
+
if (this.is_multiple) {
|
391
|
+
this.search_choices = this.container.find('ul.chzn-choices').first();
|
392
|
+
this.search_container = this.container.find('li.search-field').first();
|
393
|
+
} else {
|
394
|
+
this.search_container = this.container.find('div.chzn-search').first();
|
395
|
+
this.selected_item = this.container.find('.chzn-single').first();
|
396
|
+
sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
|
397
|
+
this.search_field.css({
|
398
|
+
"width": sf_width + "px"
|
399
|
+
});
|
400
|
+
}
|
401
|
+
this.results_build();
|
402
|
+
this.set_tab_index();
|
403
|
+
return this.form_field_jq.trigger("liszt:ready", {
|
404
|
+
chosen: this
|
405
|
+
});
|
406
|
+
};
|
407
|
+
|
408
|
+
Chosen.prototype.register_observers = function() {
|
409
|
+
var _this = this;
|
410
|
+
this.container.mousedown(function(evt) {
|
411
|
+
return _this.container_mousedown(evt);
|
412
|
+
});
|
413
|
+
this.container.mouseup(function(evt) {
|
414
|
+
return _this.container_mouseup(evt);
|
415
|
+
});
|
416
|
+
this.container.mouseenter(function(evt) {
|
417
|
+
return _this.mouse_enter(evt);
|
418
|
+
});
|
419
|
+
this.container.mouseleave(function(evt) {
|
420
|
+
return _this.mouse_leave(evt);
|
421
|
+
});
|
422
|
+
this.search_results.mouseup(function(evt) {
|
423
|
+
return _this.search_results_mouseup(evt);
|
424
|
+
});
|
425
|
+
this.search_results.mouseover(function(evt) {
|
426
|
+
return _this.search_results_mouseover(evt);
|
427
|
+
});
|
428
|
+
this.search_results.mouseout(function(evt) {
|
429
|
+
return _this.search_results_mouseout(evt);
|
430
|
+
});
|
431
|
+
this.form_field_jq.bind("liszt:updated", function(evt) {
|
432
|
+
return _this.results_update_field(evt);
|
433
|
+
});
|
434
|
+
this.form_field_jq.bind("liszt:activate", function(evt) {
|
435
|
+
return _this.activate_field(evt);
|
436
|
+
});
|
437
|
+
this.form_field_jq.bind("liszt:open", function(evt) {
|
438
|
+
return _this.container_mousedown(evt);
|
439
|
+
});
|
440
|
+
this.search_field.blur(function(evt) {
|
441
|
+
return _this.input_blur(evt);
|
442
|
+
});
|
443
|
+
this.search_field.keyup(function(evt) {
|
444
|
+
return _this.keyup_checker(evt);
|
445
|
+
});
|
446
|
+
this.search_field.keydown(function(evt) {
|
447
|
+
return _this.keydown_checker(evt);
|
448
|
+
});
|
449
|
+
this.search_field.keypress(function(evt) {
|
450
|
+
return _this.results_showing;
|
451
|
+
});
|
452
|
+
this.search_field.focus(function(evt) {
|
453
|
+
return _this.input_focus(evt);
|
454
|
+
});
|
455
|
+
if (this.is_multiple) {
|
456
|
+
return this.search_choices.click(function(evt) {
|
457
|
+
return _this.choices_click(evt);
|
458
|
+
});
|
459
|
+
} else {
|
460
|
+
return this.container.click(function(evt) {
|
461
|
+
return evt.preventDefault();
|
462
|
+
});
|
463
|
+
}
|
464
|
+
};
|
465
|
+
|
466
|
+
Chosen.prototype.search_field_disabled = function() {
|
467
|
+
this.is_disabled = this.form_field_jq[0].disabled;
|
468
|
+
if (this.is_disabled) {
|
469
|
+
this.container.addClass('chzn-disabled');
|
470
|
+
this.search_field[0].disabled = true;
|
471
|
+
if (!this.is_multiple) {
|
472
|
+
this.selected_item.unbind("focus", this.activate_action);
|
473
|
+
}
|
474
|
+
return this.close_field();
|
475
|
+
} else {
|
476
|
+
this.container.removeClass('chzn-disabled');
|
477
|
+
this.search_field[0].disabled = false;
|
478
|
+
if (!this.is_multiple) {
|
479
|
+
return this.selected_item.bind("focus", this.activate_action);
|
480
|
+
}
|
481
|
+
}
|
482
|
+
};
|
483
|
+
|
484
|
+
Chosen.prototype.container_mousedown = function(evt) {
|
485
|
+
var target_closelink;
|
486
|
+
if (!this.is_disabled) {
|
487
|
+
target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
|
488
|
+
if (evt && evt.type === "mousedown" && !this.results_showing) {
|
489
|
+
evt.preventDefault();
|
490
|
+
}
|
491
|
+
if (!this.pending_destroy_click && !target_closelink) {
|
492
|
+
if (!this.active_field) {
|
493
|
+
if (this.is_multiple) {
|
494
|
+
this.search_field.val("");
|
495
|
+
}
|
496
|
+
$(document).click(this.click_test_action);
|
497
|
+
this.results_show();
|
498
|
+
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
|
499
|
+
evt.preventDefault();
|
500
|
+
this.results_toggle();
|
501
|
+
}
|
502
|
+
return this.activate_field();
|
503
|
+
} else {
|
504
|
+
return this.pending_destroy_click = false;
|
505
|
+
}
|
506
|
+
}
|
507
|
+
};
|
508
|
+
|
509
|
+
Chosen.prototype.container_mouseup = function(evt) {
|
510
|
+
if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
|
511
|
+
return this.results_reset(evt);
|
512
|
+
}
|
513
|
+
};
|
514
|
+
|
515
|
+
Chosen.prototype.blur_test = function(evt) {
|
516
|
+
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
|
517
|
+
return this.close_field();
|
518
|
+
}
|
519
|
+
};
|
520
|
+
|
521
|
+
Chosen.prototype.close_field = function() {
|
522
|
+
$(document).unbind("click", this.click_test_action);
|
523
|
+
this.active_field = false;
|
524
|
+
this.results_hide();
|
525
|
+
this.container.removeClass("chzn-container-active");
|
526
|
+
this.winnow_results_clear();
|
527
|
+
this.clear_backstroke();
|
528
|
+
this.show_search_field_default();
|
529
|
+
return this.search_field_scale();
|
530
|
+
};
|
531
|
+
|
532
|
+
Chosen.prototype.activate_field = function() {
|
533
|
+
this.container.addClass("chzn-container-active");
|
534
|
+
this.active_field = true;
|
535
|
+
this.search_field.val(this.search_field.val());
|
536
|
+
return this.search_field.focus();
|
537
|
+
};
|
538
|
+
|
539
|
+
Chosen.prototype.test_active_click = function(evt) {
|
540
|
+
if ($(evt.target).parents('#' + this.container_id).length) {
|
541
|
+
return this.active_field = true;
|
542
|
+
} else {
|
543
|
+
return this.close_field();
|
544
|
+
}
|
545
|
+
};
|
546
|
+
|
547
|
+
Chosen.prototype.results_build = function() {
|
548
|
+
var content, data, _i, _len, _ref;
|
549
|
+
this.parsing = true;
|
550
|
+
this.results_data = root.SelectParser.select_to_array(this.form_field);
|
551
|
+
if (this.is_multiple && this.choices > 0) {
|
552
|
+
this.search_choices.find("li.search-choice").remove();
|
553
|
+
this.choices = 0;
|
554
|
+
} else if (!this.is_multiple) {
|
555
|
+
this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
|
556
|
+
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
|
557
|
+
this.container.addClass("chzn-container-single-nosearch");
|
558
|
+
} else {
|
559
|
+
this.container.removeClass("chzn-container-single-nosearch");
|
560
|
+
}
|
561
|
+
}
|
562
|
+
content = '';
|
563
|
+
_ref = this.results_data;
|
564
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
565
|
+
data = _ref[_i];
|
566
|
+
if (data.group) {
|
567
|
+
content += this.result_add_group(data);
|
568
|
+
} else if (!data.empty) {
|
569
|
+
content += this.result_add_option(data);
|
570
|
+
if (data.selected && this.is_multiple) {
|
571
|
+
this.choice_build(data);
|
572
|
+
} else if (data.selected && !this.is_multiple) {
|
573
|
+
this.selected_item.removeClass("chzn-default").find("span").text(data.text);
|
574
|
+
if (this.allow_single_deselect) {
|
575
|
+
this.single_deselect_control_build();
|
576
|
+
}
|
577
|
+
}
|
578
|
+
}
|
579
|
+
}
|
580
|
+
this.search_field_disabled();
|
581
|
+
this.show_search_field_default();
|
582
|
+
this.search_field_scale();
|
583
|
+
this.search_results.html(content);
|
584
|
+
return this.parsing = false;
|
585
|
+
};
|
586
|
+
|
587
|
+
Chosen.prototype.result_add_group = function(group) {
|
588
|
+
if (!group.disabled) {
|
589
|
+
group.dom_id = this.container_id + "_g_" + group.array_index;
|
590
|
+
return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
|
591
|
+
} else {
|
592
|
+
return "";
|
593
|
+
}
|
594
|
+
};
|
595
|
+
|
596
|
+
Chosen.prototype.result_do_highlight = function(el) {
|
597
|
+
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
598
|
+
if (el.length) {
|
599
|
+
this.result_clear_highlight();
|
600
|
+
this.result_highlight = el;
|
601
|
+
this.result_highlight.addClass("highlighted");
|
602
|
+
maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
|
603
|
+
visible_top = this.search_results.scrollTop();
|
604
|
+
visible_bottom = maxHeight + visible_top;
|
605
|
+
high_top = this.result_highlight.position().top + this.search_results.scrollTop();
|
606
|
+
high_bottom = high_top + this.result_highlight.outerHeight();
|
607
|
+
if (high_bottom >= visible_bottom) {
|
608
|
+
return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
|
609
|
+
} else if (high_top < visible_top) {
|
610
|
+
return this.search_results.scrollTop(high_top);
|
611
|
+
}
|
612
|
+
}
|
613
|
+
};
|
614
|
+
|
615
|
+
Chosen.prototype.result_clear_highlight = function() {
|
616
|
+
if (this.result_highlight) {
|
617
|
+
this.result_highlight.removeClass("highlighted");
|
618
|
+
}
|
619
|
+
return this.result_highlight = null;
|
620
|
+
};
|
621
|
+
|
622
|
+
Chosen.prototype.results_show = function() {
|
623
|
+
var dd_top;
|
624
|
+
if (!this.is_multiple) {
|
625
|
+
this.selected_item.addClass("chzn-single-with-drop");
|
626
|
+
if (this.result_single_selected) {
|
627
|
+
this.result_do_highlight(this.result_single_selected);
|
628
|
+
}
|
629
|
+
} else if (this.max_selected_options <= this.choices) {
|
630
|
+
this.form_field_jq.trigger("liszt:maxselected", {
|
631
|
+
chosen: this
|
632
|
+
});
|
633
|
+
return false;
|
634
|
+
}
|
635
|
+
dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
|
636
|
+
this.form_field_jq.trigger("liszt:showing_dropdown", {
|
637
|
+
chosen: this
|
638
|
+
});
|
639
|
+
this.dropdown.css({
|
640
|
+
"top": dd_top + "px",
|
641
|
+
"left": 0
|
642
|
+
});
|
643
|
+
this.results_showing = true;
|
644
|
+
this.search_field.focus();
|
645
|
+
this.search_field.val(this.search_field.val());
|
646
|
+
return this.winnow_results();
|
647
|
+
};
|
648
|
+
|
649
|
+
Chosen.prototype.results_hide = function() {
|
650
|
+
if (!this.is_multiple) {
|
651
|
+
this.selected_item.removeClass("chzn-single-with-drop");
|
652
|
+
}
|
653
|
+
this.result_clear_highlight();
|
654
|
+
this.form_field_jq.trigger("liszt:hiding_dropdown", {
|
655
|
+
chosen: this
|
656
|
+
});
|
657
|
+
this.dropdown.css({
|
658
|
+
"left": "-9000px"
|
659
|
+
});
|
660
|
+
return this.results_showing = false;
|
661
|
+
};
|
662
|
+
|
663
|
+
Chosen.prototype.set_tab_index = function(el) {
|
664
|
+
var ti;
|
665
|
+
if (this.form_field_jq.attr("tabindex")) {
|
666
|
+
ti = this.form_field_jq.attr("tabindex");
|
667
|
+
this.form_field_jq.attr("tabindex", -1);
|
668
|
+
return this.search_field.attr("tabindex", ti);
|
669
|
+
}
|
670
|
+
};
|
671
|
+
|
672
|
+
Chosen.prototype.show_search_field_default = function() {
|
673
|
+
if (this.is_multiple && this.choices < 1 && !this.active_field) {
|
674
|
+
this.search_field.val(this.default_text);
|
675
|
+
return this.search_field.addClass("default");
|
676
|
+
} else {
|
677
|
+
this.search_field.val("");
|
678
|
+
return this.search_field.removeClass("default");
|
679
|
+
}
|
680
|
+
};
|
681
|
+
|
682
|
+
Chosen.prototype.search_results_mouseup = function(evt) {
|
683
|
+
var target;
|
684
|
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
685
|
+
if (target.length) {
|
686
|
+
this.result_highlight = target;
|
687
|
+
this.result_select(evt);
|
688
|
+
return this.search_field.focus();
|
689
|
+
}
|
690
|
+
};
|
691
|
+
|
692
|
+
Chosen.prototype.search_results_mouseover = function(evt) {
|
693
|
+
var target;
|
694
|
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
695
|
+
if (target) {
|
696
|
+
return this.result_do_highlight(target);
|
697
|
+
}
|
698
|
+
};
|
699
|
+
|
700
|
+
Chosen.prototype.search_results_mouseout = function(evt) {
|
701
|
+
if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
|
702
|
+
return this.result_clear_highlight();
|
703
|
+
}
|
704
|
+
};
|
705
|
+
|
706
|
+
Chosen.prototype.choices_click = function(evt) {
|
707
|
+
evt.preventDefault();
|
708
|
+
if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
|
709
|
+
return this.results_show();
|
710
|
+
}
|
711
|
+
};
|
712
|
+
|
713
|
+
Chosen.prototype.choice_build = function(item) {
|
714
|
+
var choice_id, html, link,
|
715
|
+
_this = this;
|
716
|
+
if (this.is_multiple && this.max_selected_options <= this.choices) {
|
717
|
+
this.form_field_jq.trigger("liszt:maxselected", {
|
718
|
+
chosen: this
|
719
|
+
});
|
720
|
+
return false;
|
721
|
+
}
|
722
|
+
choice_id = this.container_id + "_c_" + item.array_index;
|
723
|
+
this.choices += 1;
|
724
|
+
if (item.disabled) {
|
725
|
+
html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>';
|
726
|
+
} else {
|
727
|
+
html = '<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>';
|
728
|
+
}
|
729
|
+
this.search_container.before(html);
|
730
|
+
link = $('#' + choice_id).find("a").first();
|
731
|
+
return link.click(function(evt) {
|
732
|
+
return _this.choice_destroy_link_click(evt);
|
733
|
+
});
|
734
|
+
};
|
735
|
+
|
736
|
+
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
737
|
+
evt.preventDefault();
|
738
|
+
if (!this.is_disabled) {
|
739
|
+
this.pending_destroy_click = true;
|
740
|
+
return this.choice_destroy($(evt.target));
|
741
|
+
} else {
|
742
|
+
return evt.stopPropagation;
|
743
|
+
}
|
744
|
+
};
|
745
|
+
|
746
|
+
Chosen.prototype.choice_destroy = function(link) {
|
747
|
+
if (this.result_deselect(link.attr("rel"))) {
|
748
|
+
this.choices -= 1;
|
749
|
+
this.show_search_field_default();
|
750
|
+
if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
|
751
|
+
this.results_hide();
|
752
|
+
}
|
753
|
+
link.parents('li').first().remove();
|
754
|
+
return this.search_field_scale();
|
755
|
+
}
|
756
|
+
};
|
757
|
+
|
758
|
+
Chosen.prototype.results_reset = function() {
|
759
|
+
this.form_field.options[0].selected = true;
|
760
|
+
this.selected_item.find("span").text(this.default_text);
|
761
|
+
if (!this.is_multiple) {
|
762
|
+
this.selected_item.addClass("chzn-default");
|
763
|
+
}
|
764
|
+
this.show_search_field_default();
|
765
|
+
this.results_reset_cleanup();
|
766
|
+
this.form_field_jq.trigger("change");
|
767
|
+
if (this.active_field) {
|
768
|
+
return this.results_hide();
|
769
|
+
}
|
770
|
+
};
|
771
|
+
|
772
|
+
Chosen.prototype.results_reset_cleanup = function() {
|
773
|
+
this.current_value = this.form_field_jq.val();
|
774
|
+
return this.selected_item.find("abbr").remove();
|
775
|
+
};
|
776
|
+
|
777
|
+
Chosen.prototype.result_select = function(evt) {
|
778
|
+
var high, high_id, item, position;
|
779
|
+
if (this.result_highlight) {
|
780
|
+
high = this.result_highlight;
|
781
|
+
high_id = high.attr("id");
|
782
|
+
this.result_clear_highlight();
|
783
|
+
if (this.is_multiple) {
|
784
|
+
this.result_deactivate(high);
|
785
|
+
} else {
|
786
|
+
this.search_results.find(".result-selected").removeClass("result-selected");
|
787
|
+
this.result_single_selected = high;
|
788
|
+
this.selected_item.removeClass("chzn-default");
|
789
|
+
}
|
790
|
+
high.addClass("result-selected");
|
791
|
+
position = high_id.substr(high_id.lastIndexOf("_") + 1);
|
792
|
+
item = this.results_data[position];
|
793
|
+
item.selected = true;
|
794
|
+
this.form_field.options[item.options_index].selected = true;
|
795
|
+
if (this.is_multiple) {
|
796
|
+
this.choice_build(item);
|
797
|
+
} else {
|
798
|
+
this.selected_item.find("span").first().text(item.text);
|
799
|
+
if (this.allow_single_deselect) {
|
800
|
+
this.single_deselect_control_build();
|
801
|
+
}
|
802
|
+
}
|
803
|
+
if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
|
804
|
+
this.results_hide();
|
805
|
+
}
|
806
|
+
this.search_field.val("");
|
807
|
+
if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
|
808
|
+
this.form_field_jq.trigger("change", {
|
809
|
+
'selected': this.form_field.options[item.options_index].value
|
810
|
+
});
|
811
|
+
}
|
812
|
+
this.current_value = this.form_field_jq.val();
|
813
|
+
return this.search_field_scale();
|
814
|
+
}
|
815
|
+
};
|
816
|
+
|
817
|
+
Chosen.prototype.result_activate = function(el) {
|
818
|
+
return el.addClass("active-result");
|
819
|
+
};
|
820
|
+
|
821
|
+
Chosen.prototype.result_deactivate = function(el) {
|
822
|
+
return el.removeClass("active-result");
|
823
|
+
};
|
824
|
+
|
825
|
+
Chosen.prototype.result_deselect = function(pos) {
|
826
|
+
var result, result_data;
|
827
|
+
result_data = this.results_data[pos];
|
828
|
+
if (!this.form_field.options[result_data.options_index].disabled) {
|
829
|
+
result_data.selected = false;
|
830
|
+
this.form_field.options[result_data.options_index].selected = false;
|
831
|
+
result = $("#" + this.container_id + "_o_" + pos);
|
832
|
+
result.removeClass("result-selected").addClass("active-result").show();
|
833
|
+
this.result_clear_highlight();
|
834
|
+
this.winnow_results();
|
835
|
+
this.form_field_jq.trigger("change", {
|
836
|
+
deselected: this.form_field.options[result_data.options_index].value
|
837
|
+
});
|
838
|
+
this.search_field_scale();
|
839
|
+
return true;
|
840
|
+
} else {
|
841
|
+
return false;
|
842
|
+
}
|
843
|
+
};
|
844
|
+
|
845
|
+
Chosen.prototype.single_deselect_control_build = function() {
|
846
|
+
if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
|
847
|
+
return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
848
|
+
}
|
849
|
+
};
|
850
|
+
|
851
|
+
Chosen.prototype.winnow_results = function() {
|
852
|
+
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
|
853
|
+
this.no_results_clear();
|
854
|
+
results = 0;
|
855
|
+
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
|
856
|
+
var words = searchText.toLowerCase().split(":");
|
857
|
+
regexAnchor = this.search_contains ? "" : "^";
|
858
|
+
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
859
|
+
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
860
|
+
_ref = this.results_data;
|
861
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
862
|
+
option = _ref[_i];
|
863
|
+
if (!option.disabled && !option.empty) {
|
864
|
+
if (option.group) {
|
865
|
+
$('#' + option.dom_id).css('display', 'none');
|
866
|
+
} else if (!(this.is_multiple && option.selected)) {
|
867
|
+
result_id = option.dom_id;
|
868
|
+
result = $("#" + result_id);
|
869
|
+
found = true;
|
870
|
+
for (var i_word = 0; i_word < words.length; ++i_word) {
|
871
|
+
if (option.html.toLowerCase().indexOf(words[i_word]) < 0) {
|
872
|
+
found = false;
|
873
|
+
break;
|
874
|
+
}
|
875
|
+
}
|
876
|
+
if (found) {
|
877
|
+
results += 1;
|
878
|
+
result.html(text);
|
879
|
+
this.result_activate(result);
|
880
|
+
if (option.group_array_index != null) {
|
881
|
+
$("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
|
882
|
+
}
|
883
|
+
} else {
|
884
|
+
if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
|
885
|
+
this.result_clear_highlight();
|
886
|
+
}
|
887
|
+
this.result_deactivate(result);
|
888
|
+
}
|
889
|
+
}
|
890
|
+
}
|
891
|
+
}
|
892
|
+
if (results < 1 && searchText.length) {
|
893
|
+
return this.no_results(searchText);
|
894
|
+
} else {
|
895
|
+
return this.winnow_results_set_highlight();
|
896
|
+
}
|
897
|
+
};
|
898
|
+
|
899
|
+
Chosen.prototype.winnow_results_clear = function() {
|
900
|
+
var li, lis, _i, _len, _results;
|
901
|
+
this.search_field.val("");
|
902
|
+
lis = this.search_results.find("li");
|
903
|
+
_results = [];
|
904
|
+
for (_i = 0, _len = lis.length; _i < _len; _i++) {
|
905
|
+
li = lis[_i];
|
906
|
+
li = $(li);
|
907
|
+
if (li.hasClass("group-result")) {
|
908
|
+
_results.push(li.css('display', 'auto'));
|
909
|
+
} else if (!this.is_multiple || !li.hasClass("result-selected")) {
|
910
|
+
_results.push(this.result_activate(li));
|
911
|
+
} else {
|
912
|
+
_results.push(void 0);
|
913
|
+
}
|
914
|
+
}
|
915
|
+
return _results;
|
916
|
+
};
|
917
|
+
|
918
|
+
Chosen.prototype.winnow_results_set_highlight = function() {
|
919
|
+
var do_high, selected_results;
|
920
|
+
if (!this.result_highlight) {
|
921
|
+
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
922
|
+
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
923
|
+
if (do_high != null) {
|
924
|
+
return this.result_do_highlight(do_high);
|
925
|
+
}
|
926
|
+
}
|
927
|
+
};
|
928
|
+
|
929
|
+
Chosen.prototype.no_results = function(terms) {
|
930
|
+
var no_results_html;
|
931
|
+
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
|
932
|
+
no_results_html.find("span").first().html(terms);
|
933
|
+
return this.search_results.append(no_results_html);
|
934
|
+
};
|
935
|
+
|
936
|
+
Chosen.prototype.no_results_clear = function() {
|
937
|
+
return this.search_results.find(".no-results").remove();
|
938
|
+
};
|
939
|
+
|
940
|
+
Chosen.prototype.keydown_arrow = function() {
|
941
|
+
var first_active, next_sib;
|
942
|
+
if (!this.result_highlight) {
|
943
|
+
first_active = this.search_results.find("li.active-result").first();
|
944
|
+
if (first_active) {
|
945
|
+
this.result_do_highlight($(first_active));
|
946
|
+
}
|
947
|
+
} else if (this.results_showing) {
|
948
|
+
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
949
|
+
if (next_sib) {
|
950
|
+
this.result_do_highlight(next_sib);
|
951
|
+
}
|
952
|
+
}
|
953
|
+
if (!this.results_showing) {
|
954
|
+
return this.results_show();
|
955
|
+
}
|
956
|
+
};
|
957
|
+
|
958
|
+
Chosen.prototype.keyup_arrow = function() {
|
959
|
+
var prev_sibs;
|
960
|
+
if (!this.results_showing && !this.is_multiple) {
|
961
|
+
return this.results_show();
|
962
|
+
} else if (this.result_highlight) {
|
963
|
+
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
964
|
+
if (prev_sibs.length) {
|
965
|
+
return this.result_do_highlight(prev_sibs.first());
|
966
|
+
} else {
|
967
|
+
if (this.choices > 0) {
|
968
|
+
this.results_hide();
|
969
|
+
}
|
970
|
+
return this.result_clear_highlight();
|
971
|
+
}
|
972
|
+
}
|
973
|
+
};
|
974
|
+
|
975
|
+
Chosen.prototype.keydown_backstroke = function() {
|
976
|
+
var next_available_destroy;
|
977
|
+
if (this.pending_backstroke) {
|
978
|
+
this.choice_destroy(this.pending_backstroke.find("a").first());
|
979
|
+
return this.clear_backstroke();
|
980
|
+
} else {
|
981
|
+
next_available_destroy = this.search_container.siblings("li.search-choice").last();
|
982
|
+
if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
|
983
|
+
this.pending_backstroke = next_available_destroy;
|
984
|
+
if (this.single_backstroke_delete) {
|
985
|
+
return this.keydown_backstroke();
|
986
|
+
} else {
|
987
|
+
return this.pending_backstroke.addClass("search-choice-focus");
|
988
|
+
}
|
989
|
+
}
|
990
|
+
}
|
991
|
+
};
|
992
|
+
|
993
|
+
Chosen.prototype.clear_backstroke = function() {
|
994
|
+
if (this.pending_backstroke) {
|
995
|
+
this.pending_backstroke.removeClass("search-choice-focus");
|
996
|
+
}
|
997
|
+
return this.pending_backstroke = null;
|
998
|
+
};
|
999
|
+
|
1000
|
+
Chosen.prototype.keydown_checker = function(evt) {
|
1001
|
+
var stroke, _ref;
|
1002
|
+
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
1003
|
+
this.search_field_scale();
|
1004
|
+
|
1005
|
+
if (this.results_showing) {
|
1006
|
+
if (stroke !== 8 && this.pending_backstroke) {
|
1007
|
+
this.clear_backstroke();
|
1008
|
+
}
|
1009
|
+
switch (stroke) {
|
1010
|
+
case 8:
|
1011
|
+
this.backstroke_length = this.search_field.val().length;
|
1012
|
+
break;
|
1013
|
+
case 9:
|
1014
|
+
if (this.results_showing && !this.is_multiple) {
|
1015
|
+
this.result_select(evt);
|
1016
|
+
}
|
1017
|
+
this.mouse_on_container = false;
|
1018
|
+
break;
|
1019
|
+
case 13:
|
1020
|
+
evt.preventDefault();
|
1021
|
+
break;
|
1022
|
+
case 38:
|
1023
|
+
evt.preventDefault();
|
1024
|
+
this.keyup_arrow();
|
1025
|
+
break;
|
1026
|
+
case 40:
|
1027
|
+
this.keydown_arrow();
|
1028
|
+
break;
|
1029
|
+
}
|
1030
|
+
}
|
1031
|
+
else {
|
1032
|
+
evt.target = document;
|
1033
|
+
$(document).trigger(evt);
|
1034
|
+
}
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
Chosen.prototype.search_field_scale = function() {
|
1038
|
+
var dd_top, div, h, style, style_block, styles, w, _i, _len;
|
1039
|
+
if (this.is_multiple) {
|
1040
|
+
h = 0;
|
1041
|
+
w = 0;
|
1042
|
+
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
|
1043
|
+
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
|
1044
|
+
for (_i = 0, _len = styles.length; _i < _len; _i++) {
|
1045
|
+
style = styles[_i];
|
1046
|
+
style_block += style + ":" + this.search_field.css(style) + ";";
|
1047
|
+
}
|
1048
|
+
div = $('<div />', {
|
1049
|
+
'style': style_block
|
1050
|
+
});
|
1051
|
+
div.text(this.search_field.val());
|
1052
|
+
$('body').append(div);
|
1053
|
+
w = div.width() + 25;
|
1054
|
+
div.remove();
|
1055
|
+
if (w > this.f_width - 10) {
|
1056
|
+
w = this.f_width - 10;
|
1057
|
+
}
|
1058
|
+
this.search_field.css({
|
1059
|
+
'width': w + 'px'
|
1060
|
+
});
|
1061
|
+
dd_top = this.container.height();
|
1062
|
+
return this.dropdown.css({
|
1063
|
+
"top": dd_top + "px"
|
1064
|
+
});
|
1065
|
+
}
|
1066
|
+
};
|
1067
|
+
|
1068
|
+
Chosen.prototype.generate_random_id = function() {
|
1069
|
+
var string;
|
1070
|
+
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
|
1071
|
+
while ($("#" + string).length > 0) {
|
1072
|
+
string += this.generate_random_char();
|
1073
|
+
}
|
1074
|
+
return string;
|
1075
|
+
};
|
1076
|
+
|
1077
|
+
return Chosen;
|
1078
|
+
|
1079
|
+
})(AbstractChosen);
|
1080
|
+
|
1081
|
+
root.Chosen = Chosen;
|
1082
|
+
|
1083
|
+
get_side_border_padding = function(elmt) {
|
1084
|
+
var side_border_padding;
|
1085
|
+
return side_border_padding = elmt.outerWidth() - elmt.width();
|
1086
|
+
};
|
1087
|
+
|
1088
|
+
root.get_side_border_padding = get_side_border_padding;
|
1089
|
+
|
1090
|
+
}).call(this);
|