homeland 0.0.9 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +139 -43
- data/Rakefile +23 -0
- data/app/assets/javascripts/homeland/application.coffee +31 -0
- data/app/assets/javascripts/homeland/bootstrap.min.js +7 -0
- data/{lib/generators/homeland/install/templates/javascripts → app/assets/javascripts/homeland}/jquery.timeago.js +13 -13
- data/app/assets/javascripts/homeland/tether.min.js +1 -0
- data/app/assets/stylesheets/homeland/application.scss +114 -0
- data/app/assets/stylesheets/homeland/bootstrap-theme.scss +165 -0
- data/app/assets/stylesheets/homeland/bootstrap.min.css +5 -0
- data/app/assets/stylesheets/homeland/markdown.scss +13 -0
- data/app/assets/stylesheets/homeland/tether.min.css +1 -0
- data/app/controllers/homeland/application_controller.rb +37 -12
- data/app/controllers/homeland/replies_controller.rb +25 -11
- data/app/controllers/homeland/topics_controller.rb +50 -58
- data/app/helpers/homeland/application_helper.rb +45 -13
- data/app/models/homeland/concerns/markdown_body.rb +17 -0
- data/app/models/homeland/concerns/pagination.rb +14 -0
- data/app/models/homeland/concerns/soft_delete.rb +29 -0
- data/app/models/homeland/concerns/user_methods.rb +23 -0
- data/app/models/homeland/node.rb +10 -25
- data/app/models/homeland/reply.rb +16 -17
- data/app/models/homeland/topic.rb +19 -29
- data/app/views/homeland/replies/_reply.html.erb +35 -0
- data/app/views/homeland/replies/edit.html.erb +17 -27
- data/app/views/homeland/shared/_error_messages.html.erb +2 -4
- data/app/views/homeland/topics/_form.html.erb +21 -24
- data/app/views/homeland/topics/_node_info.html.erb +9 -0
- data/app/views/homeland/topics/_reply_form.html.erb +16 -0
- data/app/views/homeland/topics/_topic.html.erb +17 -26
- data/app/views/homeland/topics/edit.html.erb +6 -10
- data/app/views/homeland/topics/index.html.erb +28 -51
- data/app/views/homeland/topics/new.html.erb +5 -10
- data/app/views/homeland/topics/show.html.erb +16 -89
- data/app/views/layouts/homeland/application.html.erb +42 -0
- data/config/locales/homeland.en.yml +40 -0
- data/config/locales/homeland.zh-CN.yml +8 -0
- data/config/routes.rb +6 -8
- data/db/migrate/20160321125035_create_homeland_nodes.rb +15 -0
- data/db/migrate/20160321125610_create_homeland_topics.rb +25 -0
- data/db/migrate/20160321125920_create_homeland_replies.rb +16 -0
- data/db/migrate/20160322062228_add_reply_to_id_to_replies.rb +7 -0
- data/lib/generators/homeland/controllers_generator.rb +14 -0
- data/lib/generators/homeland/i18n_generator.rb +22 -0
- data/lib/generators/homeland/install_generator.rb +8 -54
- data/lib/generators/homeland/templates/config/initializers/homeland.rb +34 -0
- data/lib/generators/homeland/views_generator.rb +3 -10
- data/lib/homeland.rb +29 -3
- data/lib/homeland/action_view/will_paginate.rb +38 -0
- data/lib/homeland/configuration.rb +66 -0
- data/lib/homeland/engine.rb +4 -27
- data/lib/homeland/markup.rb +17 -0
- data/lib/homeland/markup/base.rb +11 -0
- data/lib/homeland/markup/html.rb +12 -0
- data/lib/homeland/markup/markdown.rb +17 -0
- data/lib/homeland/markup/simple.rb +14 -0
- data/lib/homeland/version.rb +3 -0
- data/lib/tasks/homeland_tasks.rake +4 -0
- metadata +119 -38
- data/Changelogs.md +0 -29
- data/app/assets/images/reply.png +0 -0
- data/app/assets/javascripts/homeland.coffee +0 -51
- data/app/assets/stylesheets/homeland.scss +0 -100
- data/app/helpers/homeland/topics_helper.rb +0 -14
- data/app/models/homeland/section.rb +0 -21
- data/app/views/homeland/topics/_base.html.erb +0 -4
- data/app/views/homeland/topics/_sidebar.html.erb +0 -49
- data/app/views/homeland/topics/feed.builder +0 -20
- data/lib/generators/homeland/install/templates/images/jquery.chosen.png +0 -0
- data/lib/generators/homeland/install/templates/initializer.rb +0 -8
- data/lib/generators/homeland/install/templates/javascripts/jquery.chosen.js +0 -898
- data/lib/generators/homeland/install/templates/javascripts/jquery.hotkeys.js +0 -99
- data/lib/generators/homeland/install/templates/locales/homeland.zh-CN.yml +0 -14
- data/lib/generators/homeland/install/templates/stylesheets/jquery.chosen.scss +0 -367
- data/lib/homeland/setting.rb +0 -37
@@ -1,21 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module Homeland
|
3
|
-
class Section
|
4
|
-
include Mongoid::Document
|
5
|
-
include Mongoid::Timestamps
|
6
|
-
|
7
|
-
field :name
|
8
|
-
field :sort, :type => Integer, :default => 0
|
9
|
-
has_many :nodes, :dependent => :destroy, :class_name => "Homeland::Node"
|
10
|
-
|
11
|
-
validates_presence_of :name
|
12
|
-
validates_uniqueness_of :name
|
13
|
-
|
14
|
-
|
15
|
-
default_scope desc(:sort)
|
16
|
-
|
17
|
-
def sorted_nodes
|
18
|
-
self.nodes.sorted
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
<div class="sidebar">
|
2
|
-
|
3
|
-
<% if params[:action] == "index" %>
|
4
|
-
<div class="box">
|
5
|
-
<h2>社区论坛</h2>
|
6
|
-
<div class="content">
|
7
|
-
<a class="btn btn-success" href="<%= new_topic_path %>">发布新帖</a>
|
8
|
-
</div>
|
9
|
-
<div style="text-align:center;">
|
10
|
-
<a href="<%= homeland.feed_topics_url %>" title="用RSS阅读器订阅论坛新贴">
|
11
|
-
<%= image_tag('feed.png', :alt => "订阅论坛新贴") %></a>
|
12
|
-
</div>
|
13
|
-
</div>
|
14
|
-
<% end %>
|
15
|
-
|
16
|
-
<% if ["show","new","edit","node"].index(params[:action]) and !@node.blank? %>
|
17
|
-
<div class="box">
|
18
|
-
<h2><a href="<%= node_topics_path(@node.id) %>"><%= @node.name %></a></h2>
|
19
|
-
<% if ["new"].index params[:action] %>
|
20
|
-
<p class="sumamry">
|
21
|
-
<%= @node.summary %>
|
22
|
-
</p>
|
23
|
-
<% end %>
|
24
|
-
<div class="content">
|
25
|
-
<a class="btn btn-success" href="<%= new_topic_path(:node => @node.id) %>">发布新帖</a>
|
26
|
-
</div>
|
27
|
-
</div>
|
28
|
-
<% end %>
|
29
|
-
|
30
|
-
<% if ["new"].index(params[:action]) %>
|
31
|
-
<div id="topic_new_tip" class="box">
|
32
|
-
<h2>发贴说明</h2>
|
33
|
-
<ol>
|
34
|
-
<li>发布后正文排版会自动安你在文本框里面输入的样子排列.如果里面带有 URL地址,将会自动转变为超级链接。</li>
|
35
|
-
</ol>
|
36
|
-
</div>
|
37
|
-
<% end %>
|
38
|
-
|
39
|
-
<% if params[:action] == "index" %>
|
40
|
-
<div class="totals box">
|
41
|
-
<h2>统计信息</h2>
|
42
|
-
<ul>
|
43
|
-
<li>贴子数: <%= Homeland::Topic.count %> 篇</li>
|
44
|
-
<li>回贴数: <%= Homeland::Reply.count %> 条</li>
|
45
|
-
</ul>
|
46
|
-
</div>
|
47
|
-
<% end %>
|
48
|
-
|
49
|
-
</div>
|
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
xml.instruct! :xml, :version=>"1.0"
|
3
|
-
xml.rss(:version=>"2.0"){
|
4
|
-
xml.channel{
|
5
|
-
xml.title "#{Setting.app_name}"
|
6
|
-
xml.link root_url
|
7
|
-
xml.description("#{Setting.app_name}最新发贴.")
|
8
|
-
xml.language('en-us')
|
9
|
-
for topic in @topics
|
10
|
-
xml.item do
|
11
|
-
xml.title topic.title
|
12
|
-
xml.description format_topic_body(topic.body)
|
13
|
-
xml.author topic.user.name
|
14
|
-
xml.pubDate(topic.created_at.strftime("%a, %d %b %Y %H:%M:%S %z"))
|
15
|
-
xml.link topic_url topic
|
16
|
-
xml.guid topic_url topic
|
17
|
-
end
|
18
|
-
end
|
19
|
-
}
|
20
|
-
}
|
Binary file
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# Homeland.app_name = "<%= Homeland.app_name %>"
|
2
|
-
# Homeland.user_class = "<%= Homeland.user_class %>"
|
3
|
-
# Homeland.current_user_method = :<%= Homeland.current_user_method %>
|
4
|
-
# Homeland.require_user_method = :<%= Homeland.require_user_method %>
|
5
|
-
# Homeland.user_avatar_method = :<%= Homeland.user_avatar_method %>
|
6
|
-
# Homeland.user_path_method = :<%= Homeland.user_path_method %>
|
7
|
-
# Homeland.per_page = <%= Homeland.per_page.inspect %>
|
8
|
-
|
@@ -1,898 +0,0 @@
|
|
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
|
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
|
-
SelectParser = (function() {
|
13
|
-
function SelectParser() {
|
14
|
-
this.options_index = 0;
|
15
|
-
this.parsed = [];
|
16
|
-
}
|
17
|
-
SelectParser.prototype.add_node = function(child) {
|
18
|
-
if (child.nodeName === "OPTGROUP") {
|
19
|
-
return this.add_group(child);
|
20
|
-
} else {
|
21
|
-
return this.add_option(child);
|
22
|
-
}
|
23
|
-
};
|
24
|
-
SelectParser.prototype.add_group = function(group) {
|
25
|
-
var group_position, option, _i, _len, _ref, _results;
|
26
|
-
group_position = this.parsed.length;
|
27
|
-
this.parsed.push({
|
28
|
-
array_index: group_position,
|
29
|
-
group: true,
|
30
|
-
label: group.label,
|
31
|
-
children: 0,
|
32
|
-
disabled: group.disabled
|
33
|
-
});
|
34
|
-
_ref = group.childNodes;
|
35
|
-
_results = [];
|
36
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
37
|
-
option = _ref[_i];
|
38
|
-
_results.push(this.add_option(option, group_position, group.disabled));
|
39
|
-
}
|
40
|
-
return _results;
|
41
|
-
};
|
42
|
-
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
43
|
-
if (option.nodeName === "OPTION") {
|
44
|
-
if (option.text !== "") {
|
45
|
-
if (group_position != null) {
|
46
|
-
this.parsed[group_position].children += 1;
|
47
|
-
}
|
48
|
-
this.parsed.push({
|
49
|
-
array_index: this.parsed.length,
|
50
|
-
options_index: this.options_index,
|
51
|
-
value: option.value,
|
52
|
-
text: option.text,
|
53
|
-
html: option.innerHTML,
|
54
|
-
selected: option.selected,
|
55
|
-
disabled: group_disabled === true ? group_disabled : option.disabled,
|
56
|
-
group_array_index: group_position,
|
57
|
-
classes: option.className,
|
58
|
-
style: option.style.cssText
|
59
|
-
});
|
60
|
-
} else {
|
61
|
-
this.parsed.push({
|
62
|
-
array_index: this.parsed.length,
|
63
|
-
options_index: this.options_index,
|
64
|
-
empty: true
|
65
|
-
});
|
66
|
-
}
|
67
|
-
return this.options_index += 1;
|
68
|
-
}
|
69
|
-
};
|
70
|
-
return SelectParser;
|
71
|
-
})();
|
72
|
-
SelectParser.select_to_array = function(select) {
|
73
|
-
var child, parser, _i, _len, _ref;
|
74
|
-
parser = new SelectParser();
|
75
|
-
_ref = select.childNodes;
|
76
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
77
|
-
child = _ref[_i];
|
78
|
-
parser.add_node(child);
|
79
|
-
}
|
80
|
-
return parser.parsed;
|
81
|
-
};
|
82
|
-
this.SelectParser = SelectParser;
|
83
|
-
}).call(this);
|
84
|
-
(function() {
|
85
|
-
/*
|
86
|
-
Chosen source: generate output using 'cake build'
|
87
|
-
Copyright (c) 2011 by Harvest
|
88
|
-
*/
|
89
|
-
var AbstractChosen, root;
|
90
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
91
|
-
root = this;
|
92
|
-
AbstractChosen = (function() {
|
93
|
-
function AbstractChosen(form_field, options) {
|
94
|
-
this.form_field = form_field;
|
95
|
-
this.options = options != null ? options : {};
|
96
|
-
this.set_default_values();
|
97
|
-
this.is_multiple = this.form_field.multiple;
|
98
|
-
this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
|
99
|
-
this.setup();
|
100
|
-
this.set_up_html();
|
101
|
-
this.register_observers();
|
102
|
-
this.finish_setup();
|
103
|
-
}
|
104
|
-
AbstractChosen.prototype.set_default_values = function() {
|
105
|
-
this.click_test_action = __bind(function(evt) {
|
106
|
-
return this.test_active_click(evt);
|
107
|
-
}, this);
|
108
|
-
this.activate_action = __bind(function(evt) {
|
109
|
-
return this.activate_field(evt);
|
110
|
-
}, this);
|
111
|
-
this.active_field = false;
|
112
|
-
this.mouse_on_container = false;
|
113
|
-
this.results_showing = false;
|
114
|
-
this.result_highlighted = null;
|
115
|
-
this.result_single_selected = null;
|
116
|
-
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;
|
117
|
-
this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
118
|
-
this.choices = 0;
|
119
|
-
return this.results_none_found = this.options.no_results_text || "No results match";
|
120
|
-
};
|
121
|
-
AbstractChosen.prototype.mouse_enter = function() {
|
122
|
-
return this.mouse_on_container = true;
|
123
|
-
};
|
124
|
-
AbstractChosen.prototype.mouse_leave = function() {
|
125
|
-
return this.mouse_on_container = false;
|
126
|
-
};
|
127
|
-
AbstractChosen.prototype.input_focus = function(evt) {
|
128
|
-
if (!this.active_field) {
|
129
|
-
return setTimeout((__bind(function() {
|
130
|
-
return this.container_mousedown();
|
131
|
-
}, this)), 50);
|
132
|
-
}
|
133
|
-
};
|
134
|
-
AbstractChosen.prototype.input_blur = function(evt) {
|
135
|
-
if (!this.mouse_on_container) {
|
136
|
-
this.active_field = false;
|
137
|
-
return setTimeout((__bind(function() {
|
138
|
-
return this.blur_test();
|
139
|
-
}, this)), 100);
|
140
|
-
}
|
141
|
-
};
|
142
|
-
AbstractChosen.prototype.result_add_option = function(option) {
|
143
|
-
var classes, style;
|
144
|
-
if (!option.disabled) {
|
145
|
-
option.dom_id = this.container_id + "_o_" + option.array_index;
|
146
|
-
classes = option.selected && this.is_multiple ? [] : ["active-result"];
|
147
|
-
if (option.selected) {
|
148
|
-
classes.push("result-selected");
|
149
|
-
}
|
150
|
-
if (option.group_array_index != null) {
|
151
|
-
classes.push("group-option");
|
152
|
-
}
|
153
|
-
if (option.classes !== "") {
|
154
|
-
classes.push(option.classes);
|
155
|
-
}
|
156
|
-
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
|
157
|
-
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
|
158
|
-
} else {
|
159
|
-
return "";
|
160
|
-
}
|
161
|
-
};
|
162
|
-
AbstractChosen.prototype.results_update_field = function() {
|
163
|
-
this.result_clear_highlight();
|
164
|
-
this.result_single_selected = null;
|
165
|
-
return this.results_build();
|
166
|
-
};
|
167
|
-
AbstractChosen.prototype.results_toggle = function() {
|
168
|
-
if (this.results_showing) {
|
169
|
-
return this.results_hide();
|
170
|
-
} else {
|
171
|
-
return this.results_show();
|
172
|
-
}
|
173
|
-
};
|
174
|
-
AbstractChosen.prototype.results_search = function(evt) {
|
175
|
-
if (this.results_showing) {
|
176
|
-
return this.winnow_results();
|
177
|
-
} else {
|
178
|
-
return this.results_show();
|
179
|
-
}
|
180
|
-
};
|
181
|
-
AbstractChosen.prototype.keyup_checker = function(evt) {
|
182
|
-
var stroke, _ref;
|
183
|
-
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
184
|
-
this.search_field_scale();
|
185
|
-
switch (stroke) {
|
186
|
-
case 8:
|
187
|
-
if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
|
188
|
-
return this.keydown_backstroke();
|
189
|
-
} else if (!this.pending_backstroke) {
|
190
|
-
this.result_clear_highlight();
|
191
|
-
return this.results_search();
|
192
|
-
}
|
193
|
-
break;
|
194
|
-
case 13:
|
195
|
-
evt.preventDefault();
|
196
|
-
if (this.results_showing) {
|
197
|
-
return this.result_select(evt);
|
198
|
-
}
|
199
|
-
break;
|
200
|
-
case 27:
|
201
|
-
if (this.results_showing) {
|
202
|
-
return this.results_hide();
|
203
|
-
}
|
204
|
-
break;
|
205
|
-
case 9:
|
206
|
-
case 38:
|
207
|
-
case 40:
|
208
|
-
case 16:
|
209
|
-
case 91:
|
210
|
-
case 17:
|
211
|
-
break;
|
212
|
-
default:
|
213
|
-
return this.results_search();
|
214
|
-
}
|
215
|
-
};
|
216
|
-
AbstractChosen.prototype.generate_field_id = function() {
|
217
|
-
var new_id;
|
218
|
-
new_id = this.generate_random_id();
|
219
|
-
this.form_field.id = new_id;
|
220
|
-
return new_id;
|
221
|
-
};
|
222
|
-
AbstractChosen.prototype.generate_random_char = function() {
|
223
|
-
var chars, newchar, rand;
|
224
|
-
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
|
225
|
-
rand = Math.floor(Math.random() * chars.length);
|
226
|
-
return newchar = chars.substring(rand, rand + 1);
|
227
|
-
};
|
228
|
-
return AbstractChosen;
|
229
|
-
})();
|
230
|
-
root.AbstractChosen = AbstractChosen;
|
231
|
-
}).call(this);
|
232
|
-
(function() {
|
233
|
-
/*
|
234
|
-
Chosen source: generate output using 'cake build'
|
235
|
-
Copyright (c) 2011 by Harvest
|
236
|
-
*/
|
237
|
-
var $, Chosen, get_side_border_padding, root;
|
238
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
239
|
-
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
240
|
-
function ctor() { this.constructor = child; }
|
241
|
-
ctor.prototype = parent.prototype;
|
242
|
-
child.prototype = new ctor;
|
243
|
-
child.__super__ = parent.prototype;
|
244
|
-
return child;
|
245
|
-
}, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
246
|
-
root = this;
|
247
|
-
$ = jQuery;
|
248
|
-
$.fn.extend({
|
249
|
-
chosen: function(options) {
|
250
|
-
if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
|
251
|
-
return this;
|
252
|
-
}
|
253
|
-
return $(this).each(function(input_field) {
|
254
|
-
if (!($(this)).hasClass("chzn-done")) {
|
255
|
-
return new Chosen(this, options);
|
256
|
-
}
|
257
|
-
});
|
258
|
-
}
|
259
|
-
});
|
260
|
-
Chosen = (function() {
|
261
|
-
__extends(Chosen, AbstractChosen);
|
262
|
-
function Chosen() {
|
263
|
-
Chosen.__super__.constructor.apply(this, arguments);
|
264
|
-
}
|
265
|
-
Chosen.prototype.setup = function() {
|
266
|
-
this.form_field_jq = $(this.form_field);
|
267
|
-
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
|
268
|
-
};
|
269
|
-
Chosen.prototype.finish_setup = function() {
|
270
|
-
return this.form_field_jq.addClass("chzn-done");
|
271
|
-
};
|
272
|
-
Chosen.prototype.set_up_html = function() {
|
273
|
-
var container_div, dd_top, dd_width, sf_width;
|
274
|
-
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
|
275
|
-
this.container_id += "_chzn";
|
276
|
-
this.f_width = this.form_field_jq.outerWidth();
|
277
|
-
this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
|
278
|
-
container_div = $("<div />", {
|
279
|
-
id: this.container_id,
|
280
|
-
"class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
|
281
|
-
style: 'width: ' + this.f_width + 'px;'
|
282
|
-
});
|
283
|
-
if (this.is_multiple) {
|
284
|
-
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>');
|
285
|
-
} else {
|
286
|
-
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;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
|
287
|
-
}
|
288
|
-
this.form_field_jq.hide().after(container_div);
|
289
|
-
this.container = $('#' + this.container_id);
|
290
|
-
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
|
291
|
-
this.dropdown = this.container.find('div.chzn-drop').first();
|
292
|
-
dd_top = this.container.height();
|
293
|
-
dd_width = this.f_width - get_side_border_padding(this.dropdown);
|
294
|
-
this.dropdown.css({
|
295
|
-
"width": dd_width + "px",
|
296
|
-
"top": dd_top + "px"
|
297
|
-
});
|
298
|
-
this.search_field = this.container.find('input').first();
|
299
|
-
this.search_results = this.container.find('ul.chzn-results').first();
|
300
|
-
this.search_field_scale();
|
301
|
-
this.search_no_results = this.container.find('li.no-results').first();
|
302
|
-
if (this.is_multiple) {
|
303
|
-
this.search_choices = this.container.find('ul.chzn-choices').first();
|
304
|
-
this.search_container = this.container.find('li.search-field').first();
|
305
|
-
} else {
|
306
|
-
this.search_container = this.container.find('div.chzn-search').first();
|
307
|
-
this.selected_item = this.container.find('.chzn-single').first();
|
308
|
-
sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
|
309
|
-
this.search_field.css({
|
310
|
-
"width": sf_width + "px"
|
311
|
-
});
|
312
|
-
}
|
313
|
-
this.results_build();
|
314
|
-
this.set_tab_index();
|
315
|
-
return this.form_field_jq.trigger("liszt:ready", {
|
316
|
-
chosen: this
|
317
|
-
});
|
318
|
-
};
|
319
|
-
Chosen.prototype.register_observers = function() {
|
320
|
-
this.container.mousedown(__bind(function(evt) {
|
321
|
-
return this.container_mousedown(evt);
|
322
|
-
}, this));
|
323
|
-
this.container.mouseup(__bind(function(evt) {
|
324
|
-
return this.container_mouseup(evt);
|
325
|
-
}, this));
|
326
|
-
this.container.mouseenter(__bind(function(evt) {
|
327
|
-
return this.mouse_enter(evt);
|
328
|
-
}, this));
|
329
|
-
this.container.mouseleave(__bind(function(evt) {
|
330
|
-
return this.mouse_leave(evt);
|
331
|
-
}, this));
|
332
|
-
this.search_results.mouseup(__bind(function(evt) {
|
333
|
-
return this.search_results_mouseup(evt);
|
334
|
-
}, this));
|
335
|
-
this.search_results.mouseover(__bind(function(evt) {
|
336
|
-
return this.search_results_mouseover(evt);
|
337
|
-
}, this));
|
338
|
-
this.search_results.mouseout(__bind(function(evt) {
|
339
|
-
return this.search_results_mouseout(evt);
|
340
|
-
}, this));
|
341
|
-
this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
|
342
|
-
return this.results_update_field(evt);
|
343
|
-
}, this));
|
344
|
-
this.search_field.blur(__bind(function(evt) {
|
345
|
-
return this.input_blur(evt);
|
346
|
-
}, this));
|
347
|
-
this.search_field.keyup(__bind(function(evt) {
|
348
|
-
return this.keyup_checker(evt);
|
349
|
-
}, this));
|
350
|
-
this.search_field.keydown(__bind(function(evt) {
|
351
|
-
return this.keydown_checker(evt);
|
352
|
-
}, this));
|
353
|
-
if (this.is_multiple) {
|
354
|
-
this.search_choices.click(__bind(function(evt) {
|
355
|
-
return this.choices_click(evt);
|
356
|
-
}, this));
|
357
|
-
return this.search_field.focus(__bind(function(evt) {
|
358
|
-
return this.input_focus(evt);
|
359
|
-
}, this));
|
360
|
-
}
|
361
|
-
};
|
362
|
-
Chosen.prototype.search_field_disabled = function() {
|
363
|
-
this.is_disabled = this.form_field_jq[0].disabled;
|
364
|
-
if (this.is_disabled) {
|
365
|
-
this.container.addClass('chzn-disabled');
|
366
|
-
this.search_field[0].disabled = true;
|
367
|
-
if (!this.is_multiple) {
|
368
|
-
this.selected_item.unbind("focus", this.activate_action);
|
369
|
-
}
|
370
|
-
return this.close_field();
|
371
|
-
} else {
|
372
|
-
this.container.removeClass('chzn-disabled');
|
373
|
-
this.search_field[0].disabled = false;
|
374
|
-
if (!this.is_multiple) {
|
375
|
-
return this.selected_item.bind("focus", this.activate_action);
|
376
|
-
}
|
377
|
-
}
|
378
|
-
};
|
379
|
-
Chosen.prototype.container_mousedown = function(evt) {
|
380
|
-
var target_closelink;
|
381
|
-
if (!this.is_disabled) {
|
382
|
-
target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
|
383
|
-
if (evt && evt.type === "mousedown") {
|
384
|
-
evt.stopPropagation();
|
385
|
-
}
|
386
|
-
if (!this.pending_destroy_click && !target_closelink) {
|
387
|
-
if (!this.active_field) {
|
388
|
-
if (this.is_multiple) {
|
389
|
-
this.search_field.val("");
|
390
|
-
}
|
391
|
-
$(document).click(this.click_test_action);
|
392
|
-
this.results_show();
|
393
|
-
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
|
394
|
-
evt.preventDefault();
|
395
|
-
this.results_toggle();
|
396
|
-
}
|
397
|
-
return this.activate_field();
|
398
|
-
} else {
|
399
|
-
return this.pending_destroy_click = false;
|
400
|
-
}
|
401
|
-
}
|
402
|
-
};
|
403
|
-
Chosen.prototype.container_mouseup = function(evt) {
|
404
|
-
if (evt.target.nodeName === "ABBR") {
|
405
|
-
return this.results_reset(evt);
|
406
|
-
}
|
407
|
-
};
|
408
|
-
Chosen.prototype.blur_test = function(evt) {
|
409
|
-
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
|
410
|
-
return this.close_field();
|
411
|
-
}
|
412
|
-
};
|
413
|
-
Chosen.prototype.close_field = function() {
|
414
|
-
$(document).unbind("click", this.click_test_action);
|
415
|
-
if (!this.is_multiple) {
|
416
|
-
this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
|
417
|
-
this.search_field.attr("tabindex", -1);
|
418
|
-
}
|
419
|
-
this.active_field = false;
|
420
|
-
this.results_hide();
|
421
|
-
this.container.removeClass("chzn-container-active");
|
422
|
-
this.winnow_results_clear();
|
423
|
-
this.clear_backstroke();
|
424
|
-
this.show_search_field_default();
|
425
|
-
return this.search_field_scale();
|
426
|
-
};
|
427
|
-
Chosen.prototype.activate_field = function() {
|
428
|
-
if (!this.is_multiple && !this.active_field) {
|
429
|
-
this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
|
430
|
-
this.selected_item.attr("tabindex", -1);
|
431
|
-
}
|
432
|
-
this.container.addClass("chzn-container-active");
|
433
|
-
this.active_field = true;
|
434
|
-
this.search_field.val(this.search_field.val());
|
435
|
-
return this.search_field.focus();
|
436
|
-
};
|
437
|
-
Chosen.prototype.test_active_click = function(evt) {
|
438
|
-
if ($(evt.target).parents('#' + this.container_id).length) {
|
439
|
-
return this.active_field = true;
|
440
|
-
} else {
|
441
|
-
return this.close_field();
|
442
|
-
}
|
443
|
-
};
|
444
|
-
Chosen.prototype.results_build = function() {
|
445
|
-
var content, data, _i, _len, _ref;
|
446
|
-
this.parsing = true;
|
447
|
-
this.results_data = root.SelectParser.select_to_array(this.form_field);
|
448
|
-
if (this.is_multiple && this.choices > 0) {
|
449
|
-
this.search_choices.find("li.search-choice").remove();
|
450
|
-
this.choices = 0;
|
451
|
-
} else if (!this.is_multiple) {
|
452
|
-
this.selected_item.find("span").text(this.default_text);
|
453
|
-
if (this.form_field.options.length <= this.disable_search_threshold) {
|
454
|
-
this.container.addClass("chzn-container-single-nosearch");
|
455
|
-
} else {
|
456
|
-
this.container.removeClass("chzn-container-single-nosearch");
|
457
|
-
}
|
458
|
-
}
|
459
|
-
content = '';
|
460
|
-
_ref = this.results_data;
|
461
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
462
|
-
data = _ref[_i];
|
463
|
-
if (data.group) {
|
464
|
-
content += this.result_add_group(data);
|
465
|
-
} else if (!data.empty) {
|
466
|
-
content += this.result_add_option(data);
|
467
|
-
if (data.selected && this.is_multiple) {
|
468
|
-
this.choice_build(data);
|
469
|
-
} else if (data.selected && !this.is_multiple) {
|
470
|
-
this.selected_item.find("span").text(data.text);
|
471
|
-
if (this.allow_single_deselect) {
|
472
|
-
this.single_deselect_control_build();
|
473
|
-
}
|
474
|
-
}
|
475
|
-
}
|
476
|
-
}
|
477
|
-
this.search_field_disabled();
|
478
|
-
this.show_search_field_default();
|
479
|
-
this.search_field_scale();
|
480
|
-
this.search_results.html(content);
|
481
|
-
return this.parsing = false;
|
482
|
-
};
|
483
|
-
Chosen.prototype.result_add_group = function(group) {
|
484
|
-
if (!group.disabled) {
|
485
|
-
group.dom_id = this.container_id + "_g_" + group.array_index;
|
486
|
-
return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
|
487
|
-
} else {
|
488
|
-
return "";
|
489
|
-
}
|
490
|
-
};
|
491
|
-
Chosen.prototype.result_do_highlight = function(el) {
|
492
|
-
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
493
|
-
if (el.length) {
|
494
|
-
this.result_clear_highlight();
|
495
|
-
this.result_highlight = el;
|
496
|
-
this.result_highlight.addClass("highlighted");
|
497
|
-
maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
|
498
|
-
visible_top = this.search_results.scrollTop();
|
499
|
-
visible_bottom = maxHeight + visible_top;
|
500
|
-
high_top = this.result_highlight.position().top + this.search_results.scrollTop();
|
501
|
-
high_bottom = high_top + this.result_highlight.outerHeight();
|
502
|
-
if (high_bottom >= visible_bottom) {
|
503
|
-
return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
|
504
|
-
} else if (high_top < visible_top) {
|
505
|
-
return this.search_results.scrollTop(high_top);
|
506
|
-
}
|
507
|
-
}
|
508
|
-
};
|
509
|
-
Chosen.prototype.result_clear_highlight = function() {
|
510
|
-
if (this.result_highlight) {
|
511
|
-
this.result_highlight.removeClass("highlighted");
|
512
|
-
}
|
513
|
-
return this.result_highlight = null;
|
514
|
-
};
|
515
|
-
Chosen.prototype.results_show = function() {
|
516
|
-
var dd_top;
|
517
|
-
if (!this.is_multiple) {
|
518
|
-
this.selected_item.addClass("chzn-single-with-drop");
|
519
|
-
if (this.result_single_selected) {
|
520
|
-
this.result_do_highlight(this.result_single_selected);
|
521
|
-
}
|
522
|
-
}
|
523
|
-
dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
|
524
|
-
this.dropdown.css({
|
525
|
-
"top": dd_top + "px",
|
526
|
-
"left": 0
|
527
|
-
});
|
528
|
-
this.results_showing = true;
|
529
|
-
this.search_field.focus();
|
530
|
-
this.search_field.val(this.search_field.val());
|
531
|
-
return this.winnow_results();
|
532
|
-
};
|
533
|
-
Chosen.prototype.results_hide = function() {
|
534
|
-
if (!this.is_multiple) {
|
535
|
-
this.selected_item.removeClass("chzn-single-with-drop");
|
536
|
-
}
|
537
|
-
this.result_clear_highlight();
|
538
|
-
this.dropdown.css({
|
539
|
-
"left": "-9000px"
|
540
|
-
});
|
541
|
-
return this.results_showing = false;
|
542
|
-
};
|
543
|
-
Chosen.prototype.set_tab_index = function(el) {
|
544
|
-
var ti;
|
545
|
-
if (this.form_field_jq.attr("tabindex")) {
|
546
|
-
ti = this.form_field_jq.attr("tabindex");
|
547
|
-
this.form_field_jq.attr("tabindex", -1);
|
548
|
-
if (this.is_multiple) {
|
549
|
-
return this.search_field.attr("tabindex", ti);
|
550
|
-
} else {
|
551
|
-
this.selected_item.attr("tabindex", ti);
|
552
|
-
return this.search_field.attr("tabindex", -1);
|
553
|
-
}
|
554
|
-
}
|
555
|
-
};
|
556
|
-
Chosen.prototype.show_search_field_default = function() {
|
557
|
-
if (this.is_multiple && this.choices < 1 && !this.active_field) {
|
558
|
-
this.search_field.val(this.default_text);
|
559
|
-
return this.search_field.addClass("default");
|
560
|
-
} else {
|
561
|
-
this.search_field.val("");
|
562
|
-
return this.search_field.removeClass("default");
|
563
|
-
}
|
564
|
-
};
|
565
|
-
Chosen.prototype.search_results_mouseup = function(evt) {
|
566
|
-
var target;
|
567
|
-
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
568
|
-
if (target.length) {
|
569
|
-
this.result_highlight = target;
|
570
|
-
return this.result_select(evt);
|
571
|
-
}
|
572
|
-
};
|
573
|
-
Chosen.prototype.search_results_mouseover = function(evt) {
|
574
|
-
var target;
|
575
|
-
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
576
|
-
if (target) {
|
577
|
-
return this.result_do_highlight(target);
|
578
|
-
}
|
579
|
-
};
|
580
|
-
Chosen.prototype.search_results_mouseout = function(evt) {
|
581
|
-
if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
|
582
|
-
return this.result_clear_highlight();
|
583
|
-
}
|
584
|
-
};
|
585
|
-
Chosen.prototype.choices_click = function(evt) {
|
586
|
-
evt.preventDefault();
|
587
|
-
if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
|
588
|
-
return this.results_show();
|
589
|
-
}
|
590
|
-
};
|
591
|
-
Chosen.prototype.choice_build = function(item) {
|
592
|
-
var choice_id, link;
|
593
|
-
choice_id = this.container_id + "_c_" + item.array_index;
|
594
|
-
this.choices += 1;
|
595
|
-
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>');
|
596
|
-
link = $('#' + choice_id).find("a").first();
|
597
|
-
return link.click(__bind(function(evt) {
|
598
|
-
return this.choice_destroy_link_click(evt);
|
599
|
-
}, this));
|
600
|
-
};
|
601
|
-
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
602
|
-
evt.preventDefault();
|
603
|
-
if (!this.is_disabled) {
|
604
|
-
this.pending_destroy_click = true;
|
605
|
-
return this.choice_destroy($(evt.target));
|
606
|
-
} else {
|
607
|
-
return evt.stopPropagation;
|
608
|
-
}
|
609
|
-
};
|
610
|
-
Chosen.prototype.choice_destroy = function(link) {
|
611
|
-
this.choices -= 1;
|
612
|
-
this.show_search_field_default();
|
613
|
-
if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
|
614
|
-
this.results_hide();
|
615
|
-
}
|
616
|
-
this.result_deselect(link.attr("rel"));
|
617
|
-
return link.parents('li').first().remove();
|
618
|
-
};
|
619
|
-
Chosen.prototype.results_reset = function(evt) {
|
620
|
-
this.form_field.options[0].selected = true;
|
621
|
-
this.selected_item.find("span").text(this.default_text);
|
622
|
-
this.show_search_field_default();
|
623
|
-
$(evt.target).remove();
|
624
|
-
this.form_field_jq.trigger("change");
|
625
|
-
if (this.active_field) {
|
626
|
-
return this.results_hide();
|
627
|
-
}
|
628
|
-
};
|
629
|
-
Chosen.prototype.result_select = function(evt) {
|
630
|
-
var high, high_id, item, position;
|
631
|
-
if (this.result_highlight) {
|
632
|
-
high = this.result_highlight;
|
633
|
-
high_id = high.attr("id");
|
634
|
-
this.result_clear_highlight();
|
635
|
-
if (this.is_multiple) {
|
636
|
-
this.result_deactivate(high);
|
637
|
-
} else {
|
638
|
-
this.search_results.find(".result-selected").removeClass("result-selected");
|
639
|
-
this.result_single_selected = high;
|
640
|
-
}
|
641
|
-
high.addClass("result-selected");
|
642
|
-
position = high_id.substr(high_id.lastIndexOf("_") + 1);
|
643
|
-
item = this.results_data[position];
|
644
|
-
item.selected = true;
|
645
|
-
this.form_field.options[item.options_index].selected = true;
|
646
|
-
if (this.is_multiple) {
|
647
|
-
this.choice_build(item);
|
648
|
-
} else {
|
649
|
-
this.selected_item.find("span").first().text(item.text);
|
650
|
-
if (this.allow_single_deselect) {
|
651
|
-
this.single_deselect_control_build();
|
652
|
-
}
|
653
|
-
}
|
654
|
-
if (!(evt.metaKey && this.is_multiple)) {
|
655
|
-
this.results_hide();
|
656
|
-
}
|
657
|
-
this.search_field.val("");
|
658
|
-
this.form_field_jq.trigger("change");
|
659
|
-
return this.search_field_scale();
|
660
|
-
}
|
661
|
-
};
|
662
|
-
Chosen.prototype.result_activate = function(el) {
|
663
|
-
return el.addClass("active-result");
|
664
|
-
};
|
665
|
-
Chosen.prototype.result_deactivate = function(el) {
|
666
|
-
return el.removeClass("active-result");
|
667
|
-
};
|
668
|
-
Chosen.prototype.result_deselect = function(pos) {
|
669
|
-
var result, result_data;
|
670
|
-
result_data = this.results_data[pos];
|
671
|
-
result_data.selected = false;
|
672
|
-
this.form_field.options[result_data.options_index].selected = false;
|
673
|
-
result = $("#" + this.container_id + "_o_" + pos);
|
674
|
-
result.removeClass("result-selected").addClass("active-result").show();
|
675
|
-
this.result_clear_highlight();
|
676
|
-
this.winnow_results();
|
677
|
-
this.form_field_jq.trigger("change");
|
678
|
-
return this.search_field_scale();
|
679
|
-
};
|
680
|
-
Chosen.prototype.single_deselect_control_build = function() {
|
681
|
-
if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
|
682
|
-
return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
683
|
-
}
|
684
|
-
};
|
685
|
-
Chosen.prototype.winnow_results = function() {
|
686
|
-
var found, option, part, parts, regex, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
|
687
|
-
this.no_results_clear();
|
688
|
-
results = 0;
|
689
|
-
searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
|
690
|
-
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
691
|
-
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
|
692
|
-
_ref = this.results_data;
|
693
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
694
|
-
option = _ref[_i];
|
695
|
-
if (!option.disabled && !option.empty) {
|
696
|
-
if (option.group) {
|
697
|
-
$('#' + option.dom_id).css('display', 'none');
|
698
|
-
} else if (!(this.is_multiple && option.selected)) {
|
699
|
-
found = false;
|
700
|
-
result_id = option.dom_id;
|
701
|
-
result = $("#" + result_id);
|
702
|
-
if (regex.test(option.html)) {
|
703
|
-
found = true;
|
704
|
-
results += 1;
|
705
|
-
} else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
|
706
|
-
parts = option.html.replace(/\[|\]/g, "").split(" ");
|
707
|
-
if (parts.length) {
|
708
|
-
for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
|
709
|
-
part = parts[_j];
|
710
|
-
if (regex.test(part)) {
|
711
|
-
found = true;
|
712
|
-
results += 1;
|
713
|
-
}
|
714
|
-
}
|
715
|
-
}
|
716
|
-
}
|
717
|
-
if (found) {
|
718
|
-
if (searchText.length) {
|
719
|
-
startpos = option.html.search(zregex);
|
720
|
-
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
|
721
|
-
text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
722
|
-
} else {
|
723
|
-
text = option.html;
|
724
|
-
}
|
725
|
-
result.html(text);
|
726
|
-
this.result_activate(result);
|
727
|
-
if (option.group_array_index != null) {
|
728
|
-
$("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
|
729
|
-
}
|
730
|
-
} else {
|
731
|
-
if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
|
732
|
-
this.result_clear_highlight();
|
733
|
-
}
|
734
|
-
this.result_deactivate(result);
|
735
|
-
}
|
736
|
-
}
|
737
|
-
}
|
738
|
-
}
|
739
|
-
if (results < 1 && searchText.length) {
|
740
|
-
return this.no_results(searchText);
|
741
|
-
} else {
|
742
|
-
return this.winnow_results_set_highlight();
|
743
|
-
}
|
744
|
-
};
|
745
|
-
Chosen.prototype.winnow_results_clear = function() {
|
746
|
-
var li, lis, _i, _len, _results;
|
747
|
-
this.search_field.val("");
|
748
|
-
lis = this.search_results.find("li");
|
749
|
-
_results = [];
|
750
|
-
for (_i = 0, _len = lis.length; _i < _len; _i++) {
|
751
|
-
li = lis[_i];
|
752
|
-
li = $(li);
|
753
|
-
_results.push(li.hasClass("group-result") ? li.css('display', 'auto') : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
|
754
|
-
}
|
755
|
-
return _results;
|
756
|
-
};
|
757
|
-
Chosen.prototype.winnow_results_set_highlight = function() {
|
758
|
-
var do_high, selected_results;
|
759
|
-
if (!this.result_highlight) {
|
760
|
-
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
761
|
-
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
762
|
-
if (do_high != null) {
|
763
|
-
return this.result_do_highlight(do_high);
|
764
|
-
}
|
765
|
-
}
|
766
|
-
};
|
767
|
-
Chosen.prototype.no_results = function(terms) {
|
768
|
-
var no_results_html;
|
769
|
-
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
|
770
|
-
no_results_html.find("span").first().html(terms);
|
771
|
-
return this.search_results.append(no_results_html);
|
772
|
-
};
|
773
|
-
Chosen.prototype.no_results_clear = function() {
|
774
|
-
return this.search_results.find(".no-results").remove();
|
775
|
-
};
|
776
|
-
Chosen.prototype.keydown_arrow = function() {
|
777
|
-
var first_active, next_sib;
|
778
|
-
if (!this.result_highlight) {
|
779
|
-
first_active = this.search_results.find("li.active-result").first();
|
780
|
-
if (first_active) {
|
781
|
-
this.result_do_highlight($(first_active));
|
782
|
-
}
|
783
|
-
} else if (this.results_showing) {
|
784
|
-
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
785
|
-
if (next_sib) {
|
786
|
-
this.result_do_highlight(next_sib);
|
787
|
-
}
|
788
|
-
}
|
789
|
-
if (!this.results_showing) {
|
790
|
-
return this.results_show();
|
791
|
-
}
|
792
|
-
};
|
793
|
-
Chosen.prototype.keyup_arrow = function() {
|
794
|
-
var prev_sibs;
|
795
|
-
if (!this.results_showing && !this.is_multiple) {
|
796
|
-
return this.results_show();
|
797
|
-
} else if (this.result_highlight) {
|
798
|
-
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
799
|
-
if (prev_sibs.length) {
|
800
|
-
return this.result_do_highlight(prev_sibs.first());
|
801
|
-
} else {
|
802
|
-
if (this.choices > 0) {
|
803
|
-
this.results_hide();
|
804
|
-
}
|
805
|
-
return this.result_clear_highlight();
|
806
|
-
}
|
807
|
-
}
|
808
|
-
};
|
809
|
-
Chosen.prototype.keydown_backstroke = function() {
|
810
|
-
if (this.pending_backstroke) {
|
811
|
-
this.choice_destroy(this.pending_backstroke.find("a").first());
|
812
|
-
return this.clear_backstroke();
|
813
|
-
} else {
|
814
|
-
this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
|
815
|
-
return this.pending_backstroke.addClass("search-choice-focus");
|
816
|
-
}
|
817
|
-
};
|
818
|
-
Chosen.prototype.clear_backstroke = function() {
|
819
|
-
if (this.pending_backstroke) {
|
820
|
-
this.pending_backstroke.removeClass("search-choice-focus");
|
821
|
-
}
|
822
|
-
return this.pending_backstroke = null;
|
823
|
-
};
|
824
|
-
Chosen.prototype.keydown_checker = function(evt) {
|
825
|
-
var stroke, _ref;
|
826
|
-
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
827
|
-
this.search_field_scale();
|
828
|
-
if (stroke !== 8 && this.pending_backstroke) {
|
829
|
-
this.clear_backstroke();
|
830
|
-
}
|
831
|
-
switch (stroke) {
|
832
|
-
case 8:
|
833
|
-
this.backstroke_length = this.search_field.val().length;
|
834
|
-
break;
|
835
|
-
case 9:
|
836
|
-
if (this.results_showing && !this.is_multiple) {
|
837
|
-
this.result_select(evt);
|
838
|
-
}
|
839
|
-
this.mouse_on_container = false;
|
840
|
-
break;
|
841
|
-
case 13:
|
842
|
-
evt.preventDefault();
|
843
|
-
break;
|
844
|
-
case 38:
|
845
|
-
evt.preventDefault();
|
846
|
-
this.keyup_arrow();
|
847
|
-
break;
|
848
|
-
case 40:
|
849
|
-
this.keydown_arrow();
|
850
|
-
break;
|
851
|
-
}
|
852
|
-
};
|
853
|
-
Chosen.prototype.search_field_scale = function() {
|
854
|
-
var dd_top, div, h, style, style_block, styles, w, _i, _len;
|
855
|
-
if (this.is_multiple) {
|
856
|
-
h = 0;
|
857
|
-
w = 0;
|
858
|
-
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
|
859
|
-
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
|
860
|
-
for (_i = 0, _len = styles.length; _i < _len; _i++) {
|
861
|
-
style = styles[_i];
|
862
|
-
style_block += style + ":" + this.search_field.css(style) + ";";
|
863
|
-
}
|
864
|
-
div = $('<div />', {
|
865
|
-
'style': style_block
|
866
|
-
});
|
867
|
-
div.text(this.search_field.val());
|
868
|
-
$('body').append(div);
|
869
|
-
w = div.width() + 25;
|
870
|
-
div.remove();
|
871
|
-
if (w > this.f_width - 10) {
|
872
|
-
w = this.f_width - 10;
|
873
|
-
}
|
874
|
-
this.search_field.css({
|
875
|
-
'width': w + 'px'
|
876
|
-
});
|
877
|
-
dd_top = this.container.height();
|
878
|
-
return this.dropdown.css({
|
879
|
-
"top": dd_top + "px"
|
880
|
-
});
|
881
|
-
}
|
882
|
-
};
|
883
|
-
Chosen.prototype.generate_random_id = function() {
|
884
|
-
var string;
|
885
|
-
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
|
886
|
-
while ($("#" + string).length > 0) {
|
887
|
-
string += this.generate_random_char();
|
888
|
-
}
|
889
|
-
return string;
|
890
|
-
};
|
891
|
-
return Chosen;
|
892
|
-
})();
|
893
|
-
get_side_border_padding = function(elmt) {
|
894
|
-
var side_border_padding;
|
895
|
-
return side_border_padding = elmt.outerWidth() - elmt.width();
|
896
|
-
};
|
897
|
-
root.get_side_border_padding = get_side_border_padding;
|
898
|
-
}).call(this);
|