homeland 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/app/assets/javascripts/homeland.coffee +3 -0
- data/app/assets/stylesheets/homeland.scss +23 -8
- data/app/controllers/homeland/replies_controller.rb +1 -1
- data/app/controllers/homeland/topics_controller.rb +8 -3
- data/app/helpers/homeland/topics_helper.rb +5 -0
- data/app/models/homeland/node.rb +7 -0
- data/app/models/homeland/section.rb +4 -0
- data/app/views/homeland/topics/_form.html.erb +5 -2
- data/app/views/homeland/topics/_sidebar.html.erb +44 -60
- data/app/views/homeland/topics/_topic.html.erb +1 -1
- data/app/views/homeland/topics/index.html.erb +6 -4
- data/app/views/homeland/topics/show.html.erb +9 -2
- data/lib/generators/homeland/install/templates/images/jquery.chosen.png +0 -0
- data/lib/generators/homeland/install/templates/javascripts/jquery.chosen.js +898 -0
- data/lib/generators/homeland/install/templates/stylesheets/jquery.chosen.scss +367 -0
- data/lib/generators/homeland/install_generator.rb +25 -1
- data/lib/generators/homeland/views_generator.rb +0 -1
- metadata +19 -6
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
A new style forum for
|
1
|
+
A new style forum for tiny community as Rails Engine. You can mount this in you apps.
|
2
2
|
|
3
3
|
## Install
|
4
4
|
|
@@ -8,11 +8,11 @@ A new style forum for small communitys as a Rails Engine. you can mount this in
|
|
8
8
|
|
9
9
|
gem "homeland"
|
10
10
|
|
11
|
-
|
11
|
+
2. Install thought this commands:
|
12
12
|
|
13
13
|
rails g homeland:install
|
14
14
|
|
15
|
-
|
15
|
+
3. change you application.html.erb
|
16
16
|
|
17
17
|
before:
|
18
18
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#= require jquery.hotkeys
|
2
2
|
#= require jquery.timeago
|
3
|
+
#= require jquery.atwho
|
4
|
+
#= require jquery.chosen
|
3
5
|
#= require_self
|
4
6
|
# TopicsController 下所有页面的 JS 功能
|
5
7
|
window.Topics =
|
@@ -42,6 +44,7 @@ window.Topics =
|
|
42
44
|
# Page.ready
|
43
45
|
$(document).ready ->
|
44
46
|
$("abbr.timeago").timeago()
|
47
|
+
$("select").chosen()
|
45
48
|
$("textarea").bind "keydown","ctrl+return",(el) ->
|
46
49
|
if $(el.target).val().trim().length > 0
|
47
50
|
$("#reply form").submit()
|
@@ -1,3 +1,8 @@
|
|
1
|
+
/*
|
2
|
+
*= require jquery.atwho
|
3
|
+
*= require jquery.chosen
|
4
|
+
*/
|
5
|
+
.bbs_name { text-align:right; font-size:18px;}
|
1
6
|
.topics .topic .title a:link,
|
2
7
|
.topics .topic .title a:visited,
|
3
8
|
.node_topics .title a:link,
|
@@ -7,6 +12,21 @@
|
|
7
12
|
|
8
13
|
.sidebar p { margin-bottom:8px;}
|
9
14
|
|
15
|
+
#sections {
|
16
|
+
ul {
|
17
|
+
margin:0; list-style:none;
|
18
|
+
li {
|
19
|
+
margin-bottom:10px;
|
20
|
+
position:relative;
|
21
|
+
min-height:20px;
|
22
|
+
label { display:block; width:80px; text-align:right; color:#999; padding-right:10px; position:absolute; left:0; top:0; }
|
23
|
+
a { display:inline-block; margin-right:8px; }
|
24
|
+
.items { padding-left:90px; }
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
10
30
|
.topics { }
|
11
31
|
.topics .topic { }
|
12
32
|
.topics .topic_line {border-top:1px solid #DDD; padding:10px 0; margin:0 -10px; vertical-align:top; }
|
@@ -24,19 +44,14 @@
|
|
24
44
|
.topics .tools { text-align:right; }
|
25
45
|
.topics .tools a {margin-left:6px;}
|
26
46
|
.topics .topic .replies { width:70px; margin-right:10px; text-align:right; vertical-align:middle; }
|
27
|
-
.topics .topic .replies a.count
|
28
|
-
.topics .topic .replies a.count:visited { line-height: 12px; font-weight: bold; color: white;
|
47
|
+
.topics .topic .replies a.count:link { line-height: 12px; font-weight: bold; color: white;
|
29
48
|
background-color: #1c7fdb; display: inline-block;
|
30
49
|
padding: 2px 10px 2px 10px;
|
31
50
|
-moz-border-radius: 12px; -webkit-border-radius: 12px;
|
32
51
|
margin: 18px 12px 0px 0px; text-decoration: none; }
|
52
|
+
.topics .topic .replies a.count:visited { background:#ddd; color:#aaa;}
|
33
53
|
.topics .topic .replies a.count:hover { color:write; background-color:#1F8AEE; }
|
34
|
-
|
35
|
-
.topics .topic .replies a.state0:visited { background:#DDD; }
|
36
|
-
.topics .topic .replies a.state0:hover { background:#1dc115;}
|
37
|
-
.topics .topic .replies a.state2:link,
|
38
|
-
.topics .topic .replies a.state2:visited { background:#22D419; }
|
39
|
-
.topics .topic .replies a.state2:hover {background:#1dc115; }
|
54
|
+
|
40
55
|
.topics tr.topic td.replies { text-align:right; width:50px; font-size:14px; color:green;font-weight:bold; }
|
41
56
|
.more { padding:8px; border-top:1px solid #DDD; font-size:14px; text-align:right; }
|
42
57
|
|
@@ -11,7 +11,7 @@ module Homeland
|
|
11
11
|
@reply = current_user.replies.find(params[:id])
|
12
12
|
|
13
13
|
if @reply.update_attributes(params[:reply])
|
14
|
-
redirect_to(topic_path(@reply.topic_id), :notice => '
|
14
|
+
redirect_to(topic_path(@reply.topic_id,:anchor => "reply#{@reply.topic.replies_count}"), :notice => '回帖更新成功.')
|
15
15
|
else
|
16
16
|
render :action => "edit"
|
17
17
|
end
|
@@ -60,8 +60,13 @@ module Homeland
|
|
60
60
|
# GET /topics/new.xml
|
61
61
|
def new
|
62
62
|
@topic = Topic.new
|
63
|
-
|
64
|
-
|
63
|
+
if !params[:node].blank?
|
64
|
+
@topic.node_id = params[:node]
|
65
|
+
@node = Node.find_by_id(params[:node])
|
66
|
+
if @node.blank?
|
67
|
+
render_404
|
68
|
+
end
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
def reply
|
@@ -73,7 +78,7 @@ module Homeland
|
|
73
78
|
else
|
74
79
|
flash[:notice] = @reply.errors.full_messages.join("<br />")
|
75
80
|
end
|
76
|
-
redirect_to topic_path(params[:id],:anchor =>
|
81
|
+
redirect_to topic_path(params[:id],:anchor => "reply")
|
77
82
|
end
|
78
83
|
|
79
84
|
# GET /topics/1/edit
|
@@ -4,5 +4,10 @@ module Homeland
|
|
4
4
|
def format_topic_body(text,title = "",allow_image = true)
|
5
5
|
auto_link(simple_format(text),:all, :target => '_blank', :rel => "nofollow")
|
6
6
|
end
|
7
|
+
|
8
|
+
def render_topic_node_select_tag(topic, opts = {})
|
9
|
+
return "" if topic.blank?
|
10
|
+
grouped_collection_select(:topic, :node_id, Section.all,:sorted_nodes, :name, :id, :name, {:value => topic.node_id, :include_blank => false}, opts)
|
11
|
+
end
|
7
12
|
end
|
8
13
|
end
|
data/app/models/homeland/node.rb
CHANGED
@@ -20,5 +20,12 @@ module Homeland
|
|
20
20
|
|
21
21
|
scope :hots, desc(:topics_count)
|
22
22
|
scope :sorted, desc(:sort)
|
23
|
+
|
24
|
+
# 热门节电给 select 用的
|
25
|
+
def self.node_collection
|
26
|
+
Rails.cache.fetch("node:node_collection:#{CacheVersion.section_node_updated_at}") do
|
27
|
+
Node.all.collect { |n| [n.name,n.id] }
|
28
|
+
end
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
@@ -6,7 +6,10 @@
|
|
6
6
|
<div class="clearfix">
|
7
7
|
<%= f.label :title %>
|
8
8
|
<div class="input">
|
9
|
-
|
9
|
+
<span class="span2" style="margin-left:0px;margin-right:10px;">
|
10
|
+
<%= render_topic_node_select_tag(@topic, :style => "width:140px;") %>
|
11
|
+
</span>
|
12
|
+
<%= f.text_field :title, :class => "span6" %>
|
10
13
|
</div>
|
11
14
|
</div>
|
12
15
|
<div class="clearfix">
|
@@ -16,7 +19,7 @@
|
|
16
19
|
</div>
|
17
20
|
</div>
|
18
21
|
<div class="actions">
|
19
|
-
<input type="submit" value="保存" class="btn primary">
|
22
|
+
<input type="submit" value="保存" class="btn btn-primary">
|
20
23
|
<a href="<%= @topic.id.blank? ? topics_path : topic_path(@topic) %>" class="btn">取消</a>
|
21
24
|
</div>
|
22
25
|
</fieldset>
|
@@ -1,65 +1,49 @@
|
|
1
1
|
<div class="sidebar">
|
2
|
-
|
3
|
-
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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阅读器订阅<%= Setting.app_name %>论坛新贴">
|
11
|
+
<%= image_tag('feed.png', :alt => "订阅#{Setting.app_name}论坛新贴") %></a>
|
12
|
+
</div>
|
12
13
|
</div>
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
<
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
<%= image_tag('feed.png', :alt => "订阅#{Setting.app_name}论坛新贴") %></a>
|
23
|
-
</p>
|
24
|
-
</div>
|
25
|
-
<% end %>
|
26
|
-
<%= cache("topic/init_list_sidebar/hot_nodes",:expires_in => 30.minutes) do %>
|
27
|
-
<% if not @hot_nodes.blank? %>
|
28
|
-
<div class="hot_nodes nodes box">
|
29
|
-
<h2>热门节点</h2>
|
30
|
-
<p>
|
31
|
-
<% @hot_nodes.each do |node| %>
|
32
|
-
<a href="<%= node_topics_path(:id => node.id) %>"><%= node.name %></a>
|
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>
|
33
23
|
<% end %>
|
34
|
-
|
35
|
-
|
24
|
+
<div class="content">
|
25
|
+
<a class="btn btn-success" href="<%= new_topic_path(:node => @node.id) %>">发布新帖</a>
|
26
|
+
</div>
|
27
|
+
</div>
|
36
28
|
<% end %>
|
37
|
-
|
38
|
-
<% if
|
39
|
-
<div class="
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
<%
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
<% end %>
|
56
|
-
|
57
|
-
<div class="totals box">
|
58
|
-
<h2>统计信息</h2>
|
59
|
-
<ul>
|
60
|
-
<li>贴子数: <%= Homeland::Topic.count %> 篇</li>
|
61
|
-
<li>回贴数: <%= Homeland::Reply.count %> 条</li>
|
62
|
-
</ul>
|
63
|
-
</div>
|
64
|
-
<% 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
|
+
|
65
49
|
</div>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
</a>
|
10
10
|
</div>
|
11
11
|
<div class="infos">
|
12
|
-
<div class="title"><a href="<%= topic_path(topic) %>" title="<%= topic.title %>"><%= truncate(topic.title, :length => 100) %></a></div>
|
12
|
+
<div class="title"><a href="<%= topic_path(topic) %>#reply<%= topic.replies_count %>" title="<%= topic.title %>"><%= truncate(topic.title, :length => 100) %></a></div>
|
13
13
|
<div class="info leader">
|
14
14
|
由 <%= user_name_tag(topic.user) %>
|
15
15
|
在 <a href="<%= node_topics_path(topic.node_id) %>"><%= topic.node.name %></a> 中发起
|
@@ -18,7 +18,7 @@
|
|
18
18
|
</p>
|
19
19
|
</div>
|
20
20
|
<% else %>
|
21
|
-
<h1><%= Setting.app_name %></h1>
|
21
|
+
<h1 class="bbs_name"><%= Setting.app_name %></h1>
|
22
22
|
<% end %>
|
23
23
|
<div class="topics">
|
24
24
|
<%= render :partial => "topic", :collection => @topics %>
|
@@ -39,9 +39,11 @@
|
|
39
39
|
<% @sections.each do |section| %>
|
40
40
|
<li>
|
41
41
|
<label><%= section.name %></label>
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
<div class="items">
|
43
|
+
<% section.nodes.each do |node| %>
|
44
|
+
<a href="<%= node_topics_path(node.id) %>" title="<%= node.name %>"><%= node.name %></a>
|
45
|
+
<% end %>
|
46
|
+
</div>
|
45
47
|
</li>
|
46
48
|
<% end %>
|
47
49
|
</ul>
|
@@ -62,6 +62,13 @@
|
|
62
62
|
</div>
|
63
63
|
</div>
|
64
64
|
<% end %>
|
65
|
+
<script type="text/javascript">
|
66
|
+
$(document).ready(function(){
|
67
|
+
atDatas = []
|
68
|
+
$(".reply .name a").text(function(idx,text) { atDatas.push(text) });
|
69
|
+
$('#reply_body').atWho("@",{'data':atDatas});
|
70
|
+
})
|
71
|
+
</script>
|
65
72
|
</div>
|
66
73
|
<% end %>
|
67
74
|
<% if current_user %>
|
@@ -69,7 +76,7 @@
|
|
69
76
|
<h4>回复</h4>
|
70
77
|
<%= form_for(Homeland::Reply.new,:url => reply_topic_path(params[:id])) do |f| %>
|
71
78
|
<div class="pull-right">
|
72
|
-
<button type="submit" class="btn primary">提交回复</button><br />
|
79
|
+
<button type="submit" class="btn btn-primary">提交回复</button><br />
|
73
80
|
<span class="help-inline">Ctrl+Enter</span>
|
74
81
|
</div>
|
75
82
|
<div class="clearfix">
|
@@ -81,7 +88,7 @@
|
|
81
88
|
<% else %>
|
82
89
|
<div id="reply" class="form box">
|
83
90
|
<div style="padding:20px;">
|
84
|
-
需要 <a href='/account/sign_in' class="btn primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn
|
91
|
+
需要 <a href='/account/sign_in' class="btn btn-primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn btn-success"> 点击这里注册</a>。
|
85
92
|
</div>
|
86
93
|
</div>
|
87
94
|
<% end %>
|
Binary file
|
@@ -0,0 +1,898 @@
|
|
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);
|