Version Description
- Added the option to quick-create group and capability within the access restriction meta-box.
- Added the option to show groups granting access per capability in the access restriction meta-box.
- Added the quick-create field to the access restrictions meta-box which allows to create group & capability on the fly.
- Added Selectize.js and using it in the access restrictions meta-box instead of checkboxes.
- Improved the Groups > Options screen using a Selectize-based selection of capabilities that are enabled for access restriction.
Download this release
Release Info
Developer | itthinx |
Plugin | Groups |
Version | 1.3.14 |
Comparing to | |
See all releases |
Code changes from version 1.3.13 to 1.3.14
- css/chosen/chosen-sprite.png +0 -0
- css/chosen/chosen-sprite@2x.png +0 -0
- css/chosen/chosen.css +430 -0
- css/chosen/chosen.min.css +3 -0
- css/selectize/selectize.bootstrap2.css +532 -0
- css/selectize/selectize.css +343 -0
- css/selectize/selectize.default.css +417 -0
- groups.php +2 -2
- js/chosen/chosen.jquery.js +1166 -0
- js/chosen/chosen.jquery.min.js +2 -0
- js/selectize/selectize.js +3038 -0
- js/selectize/selectize.min.js +3 -0
- lib/access/class-groups-access-meta-boxes.php +408 -86
- lib/admin/class-groups-admin.php +23 -16
- lib/admin/groups-admin-options.php +22 -22
- lib/core/class-groups-capability.php +31 -0
- lib/views/class-groups-uie.php +120 -0
- readme.txt +20 -9
css/chosen/chosen-sprite.png
ADDED
Binary file
|
css/chosen/chosen-sprite@2x.png
ADDED
Binary file
|
css/chosen/chosen.css
ADDED
@@ -0,0 +1,430 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* @group Base */
|
2 |
+
.chosen-container {
|
3 |
+
position: relative;
|
4 |
+
display: inline-block;
|
5 |
+
vertical-align: middle;
|
6 |
+
font-size: 13px;
|
7 |
+
zoom: 1;
|
8 |
+
*display: inline;
|
9 |
+
-webkit-user-select: none;
|
10 |
+
-moz-user-select: none;
|
11 |
+
user-select: none;
|
12 |
+
}
|
13 |
+
.chosen-container .chosen-drop {
|
14 |
+
position: absolute;
|
15 |
+
top: 100%;
|
16 |
+
left: -9999px;
|
17 |
+
z-index: 1010;
|
18 |
+
-webkit-box-sizing: border-box;
|
19 |
+
-moz-box-sizing: border-box;
|
20 |
+
box-sizing: border-box;
|
21 |
+
width: 100%;
|
22 |
+
border: 1px solid #aaa;
|
23 |
+
border-top: 0;
|
24 |
+
background: #fff;
|
25 |
+
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15);
|
26 |
+
}
|
27 |
+
.chosen-container.chosen-with-drop .chosen-drop {
|
28 |
+
left: 0;
|
29 |
+
}
|
30 |
+
.chosen-container a {
|
31 |
+
cursor: pointer;
|
32 |
+
}
|
33 |
+
|
34 |
+
/* @end */
|
35 |
+
/* @group Single Chosen */
|
36 |
+
.chosen-container-single .chosen-single {
|
37 |
+
position: relative;
|
38 |
+
display: block;
|
39 |
+
overflow: hidden;
|
40 |
+
padding: 0 0 0 8px;
|
41 |
+
height: 23px;
|
42 |
+
border: 1px solid #aaa;
|
43 |
+
border-radius: 5px;
|
44 |
+
background-color: #fff;
|
45 |
+
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
|
46 |
+
background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
|
47 |
+
background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
|
48 |
+
background: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
|
49 |
+
background: linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
|
50 |
+
background-clip: padding-box;
|
51 |
+
box-shadow: 0 0 3px white inset, 0 1px 1px rgba(0, 0, 0, 0.1);
|
52 |
+
color: #444;
|
53 |
+
text-decoration: none;
|
54 |
+
white-space: nowrap;
|
55 |
+
line-height: 24px;
|
56 |
+
}
|
57 |
+
.chosen-container-single .chosen-default {
|
58 |
+
color: #999;
|
59 |
+
}
|
60 |
+
.chosen-container-single .chosen-single span {
|
61 |
+
display: block;
|
62 |
+
overflow: hidden;
|
63 |
+
margin-right: 26px;
|
64 |
+
text-overflow: ellipsis;
|
65 |
+
white-space: nowrap;
|
66 |
+
}
|
67 |
+
.chosen-container-single .chosen-single-with-deselect span {
|
68 |
+
margin-right: 38px;
|
69 |
+
}
|
70 |
+
.chosen-container-single .chosen-single abbr {
|
71 |
+
position: absolute;
|
72 |
+
top: 6px;
|
73 |
+
right: 26px;
|
74 |
+
display: block;
|
75 |
+
width: 12px;
|
76 |
+
height: 12px;
|
77 |
+
background: url('chosen-sprite.png') -42px 1px no-repeat;
|
78 |
+
font-size: 1px;
|
79 |
+
}
|
80 |
+
.chosen-container-single .chosen-single abbr:hover {
|
81 |
+
background-position: -42px -10px;
|
82 |
+
}
|
83 |
+
.chosen-container-single.chosen-disabled .chosen-single abbr:hover {
|
84 |
+
background-position: -42px -10px;
|
85 |
+
}
|
86 |
+
.chosen-container-single .chosen-single div {
|
87 |
+
position: absolute;
|
88 |
+
top: 0;
|
89 |
+
right: 0;
|
90 |
+
display: block;
|
91 |
+
width: 18px;
|
92 |
+
height: 100%;
|
93 |
+
}
|
94 |
+
.chosen-container-single .chosen-single div b {
|
95 |
+
display: block;
|
96 |
+
width: 100%;
|
97 |
+
height: 100%;
|
98 |
+
background: url('chosen-sprite.png') no-repeat 0px 2px;
|
99 |
+
}
|
100 |
+
.chosen-container-single .chosen-search {
|
101 |
+
position: relative;
|
102 |
+
z-index: 1010;
|
103 |
+
margin: 0;
|
104 |
+
padding: 3px 4px;
|
105 |
+
white-space: nowrap;
|
106 |
+
}
|
107 |
+
.chosen-container-single .chosen-search input[type="text"] {
|
108 |
+
-webkit-box-sizing: border-box;
|
109 |
+
-moz-box-sizing: border-box;
|
110 |
+
box-sizing: border-box;
|
111 |
+
margin: 1px 0;
|
112 |
+
padding: 4px 20px 4px 5px;
|
113 |
+
width: 100%;
|
114 |
+
height: auto;
|
115 |
+
outline: 0;
|
116 |
+
border: 1px solid #aaa;
|
117 |
+
background: white url('chosen-sprite.png') no-repeat 100% -20px;
|
118 |
+
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
|
119 |
+
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
120 |
+
background: url('chosen-sprite.png') no-repeat 100% -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
121 |
+
background: url('chosen-sprite.png') no-repeat 100% -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
122 |
+
background: url('chosen-sprite.png') no-repeat 100% -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
|
123 |
+
font-size: 1em;
|
124 |
+
font-family: sans-serif;
|
125 |
+
line-height: normal;
|
126 |
+
border-radius: 0;
|
127 |
+
}
|
128 |
+
.chosen-container-single .chosen-drop {
|
129 |
+
margin-top: -1px;
|
130 |
+
border-radius: 0 0 4px 4px;
|
131 |
+
background-clip: padding-box;
|
132 |
+
}
|
133 |
+
.chosen-container-single.chosen-container-single-nosearch .chosen-search {
|
134 |
+
position: absolute;
|
135 |
+
left: -9999px;
|
136 |
+
}
|
137 |
+
|
138 |
+
/* @end */
|
139 |
+
/* @group Results */
|
140 |
+
.chosen-container .chosen-results {
|
141 |
+
position: relative;
|
142 |
+
overflow-x: hidden;
|
143 |
+
overflow-y: auto;
|
144 |
+
margin: 0 4px 4px 0;
|
145 |
+
padding: 0 0 0 4px;
|
146 |
+
max-height: 240px;
|
147 |
+
-webkit-overflow-scrolling: touch;
|
148 |
+
}
|
149 |
+
.chosen-container .chosen-results li {
|
150 |
+
display: none;
|
151 |
+
margin: 0;
|
152 |
+
padding: 5px 6px;
|
153 |
+
list-style: none;
|
154 |
+
line-height: 15px;
|
155 |
+
}
|
156 |
+
.chosen-container .chosen-results li.active-result {
|
157 |
+
display: list-item;
|
158 |
+
cursor: pointer;
|
159 |
+
}
|
160 |
+
.chosen-container .chosen-results li.disabled-result {
|
161 |
+
display: list-item;
|
162 |
+
color: #ccc;
|
163 |
+
cursor: default;
|
164 |
+
}
|
165 |
+
.chosen-container .chosen-results li.highlighted {
|
166 |
+
background-color: #3875d7;
|
167 |
+
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
|
168 |
+
background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
|
169 |
+
background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
|
170 |
+
background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
|
171 |
+
background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
|
172 |
+
color: #fff;
|
173 |
+
}
|
174 |
+
.chosen-container .chosen-results li.no-results {
|
175 |
+
display: list-item;
|
176 |
+
background: #f4f4f4;
|
177 |
+
}
|
178 |
+
.chosen-container .chosen-results li.group-result {
|
179 |
+
display: list-item;
|
180 |
+
font-weight: bold;
|
181 |
+
cursor: default;
|
182 |
+
}
|
183 |
+
.chosen-container .chosen-results li.group-option {
|
184 |
+
padding-left: 15px;
|
185 |
+
}
|
186 |
+
.chosen-container .chosen-results li em {
|
187 |
+
font-style: normal;
|
188 |
+
text-decoration: underline;
|
189 |
+
}
|
190 |
+
|
191 |
+
/* @end */
|
192 |
+
/* @group Multi Chosen */
|
193 |
+
.chosen-container-multi .chosen-choices {
|
194 |
+
position: relative;
|
195 |
+
overflow: hidden;
|
196 |
+
-webkit-box-sizing: border-box;
|
197 |
+
-moz-box-sizing: border-box;
|
198 |
+
box-sizing: border-box;
|
199 |
+
margin: 0;
|
200 |
+
padding: 0;
|
201 |
+
width: 100%;
|
202 |
+
height: auto !important;
|
203 |
+
height: 1%;
|
204 |
+
border: 1px solid #aaa;
|
205 |
+
background-color: #fff;
|
206 |
+
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
|
207 |
+
background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
208 |
+
background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
209 |
+
background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
210 |
+
background-image: linear-gradient(#eeeeee 1%, #ffffff 15%);
|
211 |
+
cursor: text;
|
212 |
+
}
|
213 |
+
.chosen-container-multi .chosen-choices li {
|
214 |
+
float: left;
|
215 |
+
list-style: none;
|
216 |
+
}
|
217 |
+
.chosen-container-multi .chosen-choices li.search-field {
|
218 |
+
margin: 0;
|
219 |
+
padding: 0;
|
220 |
+
white-space: nowrap;
|
221 |
+
}
|
222 |
+
.chosen-container-multi .chosen-choices li.search-field input[type="text"] {
|
223 |
+
margin: 1px 0;
|
224 |
+
padding: 5px;
|
225 |
+
height: 15px;
|
226 |
+
outline: 0;
|
227 |
+
border: 0 !important;
|
228 |
+
background: transparent !important;
|
229 |
+
box-shadow: none;
|
230 |
+
color: #666;
|
231 |
+
font-size: 100%;
|
232 |
+
font-family: sans-serif;
|
233 |
+
line-height: normal;
|
234 |
+
border-radius: 0;
|
235 |
+
}
|
236 |
+
.chosen-container-multi .chosen-choices li.search-field .default {
|
237 |
+
color: #999;
|
238 |
+
}
|
239 |
+
.chosen-container-multi .chosen-choices li.search-choice {
|
240 |
+
position: relative;
|
241 |
+
margin: 3px 0 3px 5px;
|
242 |
+
padding: 3px 20px 3px 5px;
|
243 |
+
border: 1px solid #aaa;
|
244 |
+
border-radius: 3px;
|
245 |
+
background-color: #e4e4e4;
|
246 |
+
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
|
247 |
+
background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
248 |
+
background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
249 |
+
background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
250 |
+
background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
251 |
+
background-clip: padding-box;
|
252 |
+
box-shadow: 0 0 2px white inset, 0 1px 0 rgba(0, 0, 0, 0.05);
|
253 |
+
color: #333;
|
254 |
+
line-height: 13px;
|
255 |
+
cursor: default;
|
256 |
+
}
|
257 |
+
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
|
258 |
+
position: absolute;
|
259 |
+
top: 4px;
|
260 |
+
right: 3px;
|
261 |
+
display: block;
|
262 |
+
width: 12px;
|
263 |
+
height: 12px;
|
264 |
+
background: url('chosen-sprite.png') -42px 1px no-repeat;
|
265 |
+
font-size: 1px;
|
266 |
+
}
|
267 |
+
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover {
|
268 |
+
background-position: -42px -10px;
|
269 |
+
}
|
270 |
+
.chosen-container-multi .chosen-choices li.search-choice-disabled {
|
271 |
+
padding-right: 5px;
|
272 |
+
border: 1px solid #ccc;
|
273 |
+
background-color: #e4e4e4;
|
274 |
+
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
|
275 |
+
background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
276 |
+
background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
277 |
+
background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
278 |
+
background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
|
279 |
+
color: #666;
|
280 |
+
}
|
281 |
+
.chosen-container-multi .chosen-choices li.search-choice-focus {
|
282 |
+
background: #d4d4d4;
|
283 |
+
}
|
284 |
+
.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close {
|
285 |
+
background-position: -42px -10px;
|
286 |
+
}
|
287 |
+
.chosen-container-multi .chosen-results {
|
288 |
+
margin: 0;
|
289 |
+
padding: 0;
|
290 |
+
}
|
291 |
+
.chosen-container-multi .chosen-drop .result-selected {
|
292 |
+
display: list-item;
|
293 |
+
color: #ccc;
|
294 |
+
cursor: default;
|
295 |
+
}
|
296 |
+
|
297 |
+
/* @end */
|
298 |
+
/* @group Active */
|
299 |
+
.chosen-container-active .chosen-single {
|
300 |
+
border: 1px solid #5897fb;
|
301 |
+
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
302 |
+
}
|
303 |
+
.chosen-container-active.chosen-with-drop .chosen-single {
|
304 |
+
border: 1px solid #aaa;
|
305 |
+
-moz-border-radius-bottomright: 0;
|
306 |
+
border-bottom-right-radius: 0;
|
307 |
+
-moz-border-radius-bottomleft: 0;
|
308 |
+
border-bottom-left-radius: 0;
|
309 |
+
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff));
|
310 |
+
background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%);
|
311 |
+
background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%);
|
312 |
+
background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%);
|
313 |
+
background-image: linear-gradient(#eeeeee 20%, #ffffff 80%);
|
314 |
+
box-shadow: 0 1px 0 #fff inset;
|
315 |
+
}
|
316 |
+
.chosen-container-active.chosen-with-drop .chosen-single div {
|
317 |
+
border-left: none;
|
318 |
+
background: transparent;
|
319 |
+
}
|
320 |
+
.chosen-container-active.chosen-with-drop .chosen-single div b {
|
321 |
+
background-position: -18px 2px;
|
322 |
+
}
|
323 |
+
.chosen-container-active .chosen-choices {
|
324 |
+
border: 1px solid #5897fb;
|
325 |
+
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
326 |
+
}
|
327 |
+
.chosen-container-active .chosen-choices li.search-field input[type="text"] {
|
328 |
+
color: #111 !important;
|
329 |
+
}
|
330 |
+
|
331 |
+
/* @end */
|
332 |
+
/* @group Disabled Support */
|
333 |
+
.chosen-disabled {
|
334 |
+
opacity: 0.5 !important;
|
335 |
+
cursor: default;
|
336 |
+
}
|
337 |
+
.chosen-disabled .chosen-single {
|
338 |
+
cursor: default;
|
339 |
+
}
|
340 |
+
.chosen-disabled .chosen-choices .search-choice .search-choice-close {
|
341 |
+
cursor: default;
|
342 |
+
}
|
343 |
+
|
344 |
+
/* @end */
|
345 |
+
/* @group Right to Left */
|
346 |
+
.chosen-rtl {
|
347 |
+
text-align: right;
|
348 |
+
}
|
349 |
+
.chosen-rtl .chosen-single {
|
350 |
+
overflow: visible;
|
351 |
+
padding: 0 8px 0 0;
|
352 |
+
}
|
353 |
+
.chosen-rtl .chosen-single span {
|
354 |
+
margin-right: 0;
|
355 |
+
margin-left: 26px;
|
356 |
+
direction: rtl;
|
357 |
+
}
|
358 |
+
.chosen-rtl .chosen-single-with-deselect span {
|
359 |
+
margin-left: 38px;
|
360 |
+
}
|
361 |
+
.chosen-rtl .chosen-single div {
|
362 |
+
right: auto;
|
363 |
+
left: 3px;
|
364 |
+
}
|
365 |
+
.chosen-rtl .chosen-single abbr {
|
366 |
+
right: auto;
|
367 |
+
left: 26px;
|
368 |
+
}
|
369 |
+
.chosen-rtl .chosen-choices li {
|
370 |
+
float: right;
|
371 |
+
}
|
372 |
+
.chosen-rtl .chosen-choices li.search-field input[type="text"] {
|
373 |
+
direction: rtl;
|
374 |
+
}
|
375 |
+
.chosen-rtl .chosen-choices li.search-choice {
|
376 |
+
margin: 3px 5px 3px 0;
|
377 |
+
padding: 3px 5px 3px 19px;
|
378 |
+
}
|
379 |
+
.chosen-rtl .chosen-choices li.search-choice .search-choice-close {
|
380 |
+
right: auto;
|
381 |
+
left: 4px;
|
382 |
+
}
|
383 |
+
.chosen-rtl.chosen-container-single-nosearch .chosen-search,
|
384 |
+
.chosen-rtl .chosen-drop {
|
385 |
+
left: 9999px;
|
386 |
+
}
|
387 |
+
.chosen-rtl.chosen-container-single .chosen-results {
|
388 |
+
margin: 0 0 4px 4px;
|
389 |
+
padding: 0 4px 0 0;
|
390 |
+
}
|
391 |
+
.chosen-rtl .chosen-results li.group-option {
|
392 |
+
padding-right: 15px;
|
393 |
+
padding-left: 0;
|
394 |
+
}
|
395 |
+
.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div {
|
396 |
+
border-right: none;
|
397 |
+
}
|
398 |
+
.chosen-rtl .chosen-search input[type="text"] {
|
399 |
+
padding: 4px 5px 4px 20px;
|
400 |
+
background: white url('chosen-sprite.png') no-repeat -30px -20px;
|
401 |
+
background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
|
402 |
+
background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
403 |
+
background: url('chosen-sprite.png') no-repeat -30px -20px, -moz-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
404 |
+
background: url('chosen-sprite.png') no-repeat -30px -20px, -o-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
405 |
+
background: url('chosen-sprite.png') no-repeat -30px -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
|
406 |
+
direction: rtl;
|
407 |
+
}
|
408 |
+
.chosen-rtl.chosen-container-single .chosen-single div b {
|
409 |
+
background-position: 6px 2px;
|
410 |
+
}
|
411 |
+
.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b {
|
412 |
+
background-position: -12px 2px;
|
413 |
+
}
|
414 |
+
|
415 |
+
/* @end */
|
416 |
+
/* @group Retina compatibility */
|
417 |
+
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) {
|
418 |
+
.chosen-rtl .chosen-search input[type="text"],
|
419 |
+
.chosen-container-single .chosen-single abbr,
|
420 |
+
.chosen-container-single .chosen-single div b,
|
421 |
+
.chosen-container-single .chosen-search input[type="text"],
|
422 |
+
.chosen-container-multi .chosen-choices .search-choice .search-choice-close,
|
423 |
+
.chosen-container .chosen-results-scroll-down span,
|
424 |
+
.chosen-container .chosen-results-scroll-up span {
|
425 |
+
background-image: url('chosen-sprite@2x.png') !important;
|
426 |
+
background-size: 52px 37px !important;
|
427 |
+
background-repeat: no-repeat !important;
|
428 |
+
}
|
429 |
+
}
|
430 |
+
/* @end */
|
css/chosen/chosen.min.css
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
/* Chosen v1.0.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
|
2 |
+
|
3 |
+
.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;zoom:1;*display:inline;-webkit-user-select:none;-moz-user-select:none;user-select:none}.chosen-container .chosen-drop{position:absolute;top:100%;left:-9999px;z-index:1010;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15)}.chosen-container.chosen-with-drop .chosen-drop{left:0}.chosen-container a{cursor:pointer}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:23px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),color-stop(100%,#f4f4f4));background:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:24px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(chosen-sprite.png) no-repeat 0 2px}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:#fff url(chosen-sprite.png) no-repeat 100% -20px;background:url(chosen-sprite.png) no-repeat 100% -20px,-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background:url(chosen-sprite.png) no-repeat 100% -20px,-webkit-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat 100% -20px,-moz-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat 100% -20px,-o-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat 100% -20px,linear-gradient(#eee 1%,#fff 15%);font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;left:-9999px}.chosen-container .chosen-results{position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#3875d7),color-stop(90%,#2a62bc));background-image:-webkit-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-moz-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-o-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0;width:100%;height:auto!important;height:1%;border:1px solid #aaa;background-color:#fff;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background-image:-webkit-linear-gradient(#eee 1%,#fff 15%);background-image:-moz-linear-gradient(#eee 1%,#fff 15%);background-image:-o-linear-gradient(#eee 1%,#fff 15%);background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:5px;height:15px;outline:0;border:0!important;background:transparent!important;box-shadow:none;color:#666;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-multi .chosen-choices li.search-field .default{color:#999}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 0 3px 5px;padding:3px 20px 3px 5px;border:1px solid #aaa;border-radius:3px;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-clip:padding-box;box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;-moz-border-radius-bottomright:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#eee),color-stop(80%,#fff));background-image:-webkit-linear-gradient(#eee 20%,#fff 80%);background-image:-moz-linear-gradient(#eee 20%,#fff 80%);background-image:-o-linear-gradient(#eee 20%,#fff 80%);background-image:linear-gradient(#eee 20%,#fff 80%);box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:0;background:transparent}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#111!important}.chosen-disabled{opacity:.5!important;cursor:default}.chosen-disabled .chosen-single{cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl.chosen-container-single-nosearch .chosen-search,.chosen-rtl .chosen-drop{left:9999px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:0}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:#fff url(chosen-sprite.png) no-repeat -30px -20px;background:url(chosen-sprite.png) no-repeat -30px -20px,-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background:url(chosen-sprite.png) no-repeat -30px -20px,-webkit-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat -30px -20px,-moz-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat -30px -20px,-o-linear-gradient(#eee 1%,#fff 15%);background:url(chosen-sprite.png) no-repeat -30px -20px,linear-gradient(#eee 1%,#fff 15%);direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min-resolution:144dpi){.chosen-rtl .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-container-single .chosen-search input[type=text],.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span{background-image:url(chosen-sprite@2x.png)!important;background-size:52px 37px!important;background-repeat:no-repeat!important}}
|
css/selectize/selectize.bootstrap2.css
ADDED
@@ -0,0 +1,532 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* selectize.bootstrap2.css (v0.7.7) - Bootstrap 2 Theme
|
3 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
6 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
*
|
9 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
10 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
12 |
+
* governing permissions and limitations under the License.
|
13 |
+
*
|
14 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
15 |
+
*/
|
16 |
+
|
17 |
+
.selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
|
18 |
+
background: #f2f2f2 !important;
|
19 |
+
background: rgba(0, 0, 0, 0.06) !important;
|
20 |
+
border: 0 none !important;
|
21 |
+
visibility: visible !important;
|
22 |
+
-webkit-box-shadow: inset 0 0 12px 4px #ffffff;
|
23 |
+
box-shadow: inset 0 0 12px 4px #ffffff;
|
24 |
+
}
|
25 |
+
|
26 |
+
.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
|
27 |
+
content: '!';
|
28 |
+
visibility: hidden;
|
29 |
+
}
|
30 |
+
|
31 |
+
.selectize-control.plugin-drag_drop .ui-sortable-helper {
|
32 |
+
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
33 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
34 |
+
}
|
35 |
+
|
36 |
+
.selectize-dropdown-header {
|
37 |
+
position: relative;
|
38 |
+
padding: 3px 10px;
|
39 |
+
background: #f8f8f8;
|
40 |
+
border-bottom: 1px solid #d0d0d0;
|
41 |
+
-webkit-border-radius: 4px 4px 0 0;
|
42 |
+
-moz-border-radius: 4px 4px 0 0;
|
43 |
+
border-radius: 4px 4px 0 0;
|
44 |
+
}
|
45 |
+
|
46 |
+
.selectize-dropdown-header-close {
|
47 |
+
position: absolute;
|
48 |
+
top: 50%;
|
49 |
+
right: 10px;
|
50 |
+
margin-top: -12px;
|
51 |
+
font-size: 20px !important;
|
52 |
+
line-height: 20px;
|
53 |
+
color: #333333;
|
54 |
+
opacity: 0.4;
|
55 |
+
}
|
56 |
+
|
57 |
+
.selectize-dropdown-header-close:hover {
|
58 |
+
color: #000000;
|
59 |
+
}
|
60 |
+
|
61 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup {
|
62 |
+
float: left;
|
63 |
+
border-top: 0 none;
|
64 |
+
border-right: 1px solid #f2f2f2;
|
65 |
+
-webkit-box-sizing: border-box;
|
66 |
+
-moz-box-sizing: border-box;
|
67 |
+
box-sizing: border-box;
|
68 |
+
}
|
69 |
+
|
70 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
|
71 |
+
border-right: 0 none;
|
72 |
+
}
|
73 |
+
|
74 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:before {
|
75 |
+
display: none;
|
76 |
+
}
|
77 |
+
|
78 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup-header {
|
79 |
+
border-top: 0 none;
|
80 |
+
}
|
81 |
+
|
82 |
+
.selectize-control.plugin-remove_button [data-value] {
|
83 |
+
position: relative;
|
84 |
+
padding-right: 24px !important;
|
85 |
+
}
|
86 |
+
|
87 |
+
.selectize-control.plugin-remove_button [data-value] .remove {
|
88 |
+
position: absolute;
|
89 |
+
top: 0;
|
90 |
+
right: 0;
|
91 |
+
bottom: 0;
|
92 |
+
display: inline-block;
|
93 |
+
width: 17px;
|
94 |
+
padding: 1px 0 0 0;
|
95 |
+
font-size: 12px;
|
96 |
+
font-weight: bold;
|
97 |
+
color: inherit;
|
98 |
+
text-align: center;
|
99 |
+
text-decoration: none;
|
100 |
+
vertical-align: middle;
|
101 |
+
border-left: 1px solid #cccccc;
|
102 |
+
-webkit-border-radius: 0 2px 2px 0;
|
103 |
+
-moz-border-radius: 0 2px 2px 0;
|
104 |
+
border-radius: 0 2px 2px 0;
|
105 |
+
-webkit-box-sizing: border-box;
|
106 |
+
-moz-box-sizing: border-box;
|
107 |
+
box-sizing: border-box;
|
108 |
+
}
|
109 |
+
|
110 |
+
.selectize-control.plugin-remove_button [data-value] .remove:hover {
|
111 |
+
background: rgba(0, 0, 0, 0.05);
|
112 |
+
}
|
113 |
+
|
114 |
+
.selectize-control.plugin-remove_button [data-value].active .remove {
|
115 |
+
border-left-color: #0077b3;
|
116 |
+
}
|
117 |
+
|
118 |
+
.selectize-control {
|
119 |
+
position: relative;
|
120 |
+
}
|
121 |
+
|
122 |
+
.selectize-dropdown,
|
123 |
+
.selectize-input,
|
124 |
+
.selectize-input input {
|
125 |
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
126 |
+
font-size: 14px;
|
127 |
+
-webkit-font-smoothing: inherit;
|
128 |
+
line-height: 20px;
|
129 |
+
color: #333333;
|
130 |
+
}
|
131 |
+
|
132 |
+
.selectize-input,
|
133 |
+
.selectize-control.single .selectize-input.focus {
|
134 |
+
display: inline-block;
|
135 |
+
cursor: text;
|
136 |
+
background: #ffffff;
|
137 |
+
}
|
138 |
+
|
139 |
+
.selectize-input {
|
140 |
+
position: relative;
|
141 |
+
z-index: 1;
|
142 |
+
display: inline-block;
|
143 |
+
width: 100%;
|
144 |
+
padding: 7px 10px;
|
145 |
+
overflow: hidden;
|
146 |
+
border: 1px solid #d0d0d0;
|
147 |
+
-webkit-border-radius: 4px;
|
148 |
+
-moz-border-radius: 4px;
|
149 |
+
border-radius: 4px;
|
150 |
+
-webkit-box-shadow: none;
|
151 |
+
box-shadow: none;
|
152 |
+
-webkit-box-sizing: border-box;
|
153 |
+
-moz-box-sizing: border-box;
|
154 |
+
box-sizing: border-box;
|
155 |
+
}
|
156 |
+
|
157 |
+
.selectize-control.multi .selectize-input.has-items {
|
158 |
+
padding: 5px 10px 2px;
|
159 |
+
}
|
160 |
+
|
161 |
+
.selectize-input.full {
|
162 |
+
background-color: #ffffff;
|
163 |
+
}
|
164 |
+
|
165 |
+
.selectize-input.disabled,
|
166 |
+
.selectize-input.disabled * {
|
167 |
+
cursor: default !important;
|
168 |
+
}
|
169 |
+
|
170 |
+
.selectize-input.focus {
|
171 |
+
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
172 |
+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
173 |
+
}
|
174 |
+
|
175 |
+
.selectize-input.dropdown-active {
|
176 |
+
-webkit-border-radius: 4px 4px 0 0;
|
177 |
+
-moz-border-radius: 4px 4px 0 0;
|
178 |
+
border-radius: 4px 4px 0 0;
|
179 |
+
}
|
180 |
+
|
181 |
+
.selectize-input > * {
|
182 |
+
display: -moz-inline-stack;
|
183 |
+
display: inline-block;
|
184 |
+
*display: inline;
|
185 |
+
vertical-align: baseline;
|
186 |
+
zoom: 1;
|
187 |
+
}
|
188 |
+
|
189 |
+
.selectize-control.multi .selectize-input > div {
|
190 |
+
padding: 1px 3px;
|
191 |
+
margin: 0 3px 3px 0;
|
192 |
+
color: #333333;
|
193 |
+
cursor: pointer;
|
194 |
+
background: #e6e6e6;
|
195 |
+
border: 1px solid #cccccc;
|
196 |
+
}
|
197 |
+
|
198 |
+
.selectize-control.multi .selectize-input > div.active {
|
199 |
+
color: #ffffff;
|
200 |
+
background: #0088cc;
|
201 |
+
border: 1px solid #0077b3;
|
202 |
+
}
|
203 |
+
|
204 |
+
.selectize-control.multi .selectize-input.disabled > div,
|
205 |
+
.selectize-control.multi .selectize-input.disabled > div.active {
|
206 |
+
color: #474747;
|
207 |
+
background: #fafafa;
|
208 |
+
border: 1px solid #e0e0e0;
|
209 |
+
}
|
210 |
+
|
211 |
+
.selectize-input > input {
|
212 |
+
max-width: 100% !important;
|
213 |
+
max-height: none !important;
|
214 |
+
min-height: 0 !important;
|
215 |
+
padding: 0 !important;
|
216 |
+
margin: 0 !important;
|
217 |
+
line-height: inherit !important;
|
218 |
+
text-indent: 0 !important;
|
219 |
+
background: none !important;
|
220 |
+
border: 0 none !important;
|
221 |
+
-webkit-box-shadow: none !important;
|
222 |
+
box-shadow: none !important;
|
223 |
+
-webkit-user-select: auto !important;
|
224 |
+
}
|
225 |
+
|
226 |
+
.selectize-input > input:focus {
|
227 |
+
outline: none !important;
|
228 |
+
}
|
229 |
+
|
230 |
+
.selectize-input::after {
|
231 |
+
display: block;
|
232 |
+
clear: left;
|
233 |
+
content: ' ';
|
234 |
+
}
|
235 |
+
|
236 |
+
.selectize-input.dropdown-active::before {
|
237 |
+
position: absolute;
|
238 |
+
right: 0;
|
239 |
+
bottom: 0;
|
240 |
+
left: 0;
|
241 |
+
display: block;
|
242 |
+
height: 1px;
|
243 |
+
background: #e5e5e5;
|
244 |
+
content: ' ';
|
245 |
+
}
|
246 |
+
|
247 |
+
.selectize-dropdown {
|
248 |
+
position: absolute;
|
249 |
+
z-index: 10;
|
250 |
+
margin: -1px 0 0 0;
|
251 |
+
background: #ffffff;
|
252 |
+
border: 1px solid #d0d0d0;
|
253 |
+
border-top: 0 none;
|
254 |
+
-webkit-border-radius: 0 0 4px 4px;
|
255 |
+
-moz-border-radius: 0 0 4px 4px;
|
256 |
+
border-radius: 0 0 4px 4px;
|
257 |
+
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
258 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
259 |
+
-webkit-box-sizing: border-box;
|
260 |
+
-moz-box-sizing: border-box;
|
261 |
+
box-sizing: border-box;
|
262 |
+
}
|
263 |
+
|
264 |
+
.selectize-dropdown [data-selectable] {
|
265 |
+
overflow: hidden;
|
266 |
+
cursor: pointer;
|
267 |
+
}
|
268 |
+
|
269 |
+
.selectize-dropdown [data-selectable] .highlight {
|
270 |
+
background: rgba(255, 237, 40, 0.4);
|
271 |
+
-webkit-border-radius: 1px;
|
272 |
+
-moz-border-radius: 1px;
|
273 |
+
border-radius: 1px;
|
274 |
+
}
|
275 |
+
|
276 |
+
.selectize-dropdown [data-selectable],
|
277 |
+
.selectize-dropdown .optgroup-header {
|
278 |
+
padding: 3px 10px;
|
279 |
+
}
|
280 |
+
|
281 |
+
.selectize-dropdown .optgroup:first-child .optgroup-header {
|
282 |
+
border-top: 0 none;
|
283 |
+
}
|
284 |
+
|
285 |
+
.selectize-dropdown .optgroup-header {
|
286 |
+
color: #999999;
|
287 |
+
cursor: default;
|
288 |
+
background: #ffffff;
|
289 |
+
}
|
290 |
+
|
291 |
+
.selectize-dropdown .active {
|
292 |
+
color: #ffffff;
|
293 |
+
background-color: #0088cc;
|
294 |
+
}
|
295 |
+
|
296 |
+
.selectize-dropdown .active.create {
|
297 |
+
color: #ffffff;
|
298 |
+
}
|
299 |
+
|
300 |
+
.selectize-dropdown .create {
|
301 |
+
color: rgba(51, 51, 51, 0.5);
|
302 |
+
}
|
303 |
+
|
304 |
+
.selectize-dropdown-content {
|
305 |
+
max-height: 200px;
|
306 |
+
overflow-x: hidden;
|
307 |
+
overflow-y: auto;
|
308 |
+
}
|
309 |
+
|
310 |
+
.selectize-control.single .selectize-input,
|
311 |
+
.selectize-control.single .selectize-input input {
|
312 |
+
cursor: pointer;
|
313 |
+
}
|
314 |
+
|
315 |
+
.selectize-control.single .selectize-input.focus,
|
316 |
+
.selectize-control.single .selectize-input.focus input {
|
317 |
+
cursor: text;
|
318 |
+
}
|
319 |
+
|
320 |
+
.selectize-control.single .selectize-input:after {
|
321 |
+
position: absolute;
|
322 |
+
top: 50%;
|
323 |
+
right: 15px;
|
324 |
+
display: block;
|
325 |
+
width: 0;
|
326 |
+
height: 0;
|
327 |
+
margin-top: -3px;
|
328 |
+
border-color: #000000 transparent transparent transparent;
|
329 |
+
border-style: solid;
|
330 |
+
border-width: 5px 5px 0 5px;
|
331 |
+
content: ' ';
|
332 |
+
}
|
333 |
+
|
334 |
+
.selectize-control.single .selectize-input.dropdown-active:after {
|
335 |
+
margin-top: -4px;
|
336 |
+
border-color: transparent transparent #000000 transparent;
|
337 |
+
border-width: 0 5px 5px 5px;
|
338 |
+
}
|
339 |
+
|
340 |
+
.selectize-control .selectize-input.disabled {
|
341 |
+
background-color: #ffffff;
|
342 |
+
opacity: 0.5;
|
343 |
+
}
|
344 |
+
|
345 |
+
.selectize-dropdown {
|
346 |
+
z-index: 1000;
|
347 |
+
margin: 2px 0 0 0;
|
348 |
+
border: 1px solid rgba(0, 0, 0, 0.2);
|
349 |
+
border-radius: 4px;
|
350 |
+
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
351 |
+
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
352 |
+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
353 |
+
}
|
354 |
+
|
355 |
+
.selectize-dropdown .optgroup-header {
|
356 |
+
font-size: 11px;
|
357 |
+
font-weight: bold;
|
358 |
+
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
|
359 |
+
text-transform: uppercase;
|
360 |
+
}
|
361 |
+
|
362 |
+
.selectize-dropdown .optgroup:first-child:before {
|
363 |
+
display: none;
|
364 |
+
}
|
365 |
+
|
366 |
+
.selectize-dropdown .optgroup:before {
|
367 |
+
display: block;
|
368 |
+
*width: 100%;
|
369 |
+
height: 1px;
|
370 |
+
margin: 9px 1px;
|
371 |
+
*margin: -5px 0 5px;
|
372 |
+
margin-right: -10px;
|
373 |
+
margin-left: -10px;
|
374 |
+
overflow: hidden;
|
375 |
+
background-color: #e5e5e5;
|
376 |
+
border-bottom: 1px solid #ffffff;
|
377 |
+
content: ' ';
|
378 |
+
}
|
379 |
+
|
380 |
+
.selectize-dropdown [data-selectable].active {
|
381 |
+
background-color: #0081c2;
|
382 |
+
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
|
383 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
|
384 |
+
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
|
385 |
+
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
|
386 |
+
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
|
387 |
+
background-repeat: repeat-x;
|
388 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0);
|
389 |
+
}
|
390 |
+
|
391 |
+
.selectize-dropdown-content {
|
392 |
+
padding: 5px 0;
|
393 |
+
}
|
394 |
+
|
395 |
+
.selectize-dropdown-header {
|
396 |
+
padding: 6px 10px;
|
397 |
+
}
|
398 |
+
|
399 |
+
.selectize-input {
|
400 |
+
-webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
|
401 |
+
-moz-transition: border linear 0.2s, box-shadow linear 0.2s;
|
402 |
+
-o-transition: border linear 0.2s, box-shadow linear 0.2s;
|
403 |
+
transition: border linear 0.2s, box-shadow linear 0.2s;
|
404 |
+
}
|
405 |
+
|
406 |
+
.selectize-input.dropdown-active {
|
407 |
+
-webkit-border-radius: 4px;
|
408 |
+
-moz-border-radius: 4px;
|
409 |
+
border-radius: 4px;
|
410 |
+
}
|
411 |
+
|
412 |
+
.selectize-input.dropdown-active::before {
|
413 |
+
display: none;
|
414 |
+
}
|
415 |
+
|
416 |
+
.selectize-input.focus,
|
417 |
+
.selectize-input.focus:hover {
|
418 |
+
background: #ffffff !important;
|
419 |
+
border-color: rgba(82, 168, 236, 0.8) !important;
|
420 |
+
outline: 0 !important;
|
421 |
+
outline: thin dotted \9 !important;
|
422 |
+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6) !important;
|
423 |
+
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6) !important;
|
424 |
+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6) !important;
|
425 |
+
}
|
426 |
+
|
427 |
+
.selectize-control.single .selectize-input {
|
428 |
+
color: #333333;
|
429 |
+
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
|
430 |
+
background-color: #f5f5f5;
|
431 |
+
*background-color: #e6e6e6;
|
432 |
+
background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
|
433 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
|
434 |
+
background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
|
435 |
+
background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
|
436 |
+
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
|
437 |
+
background-repeat: repeat-x;
|
438 |
+
border-color: #e6e6e6 #e6e6e6 #bfbfbf;
|
439 |
+
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
440 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
|
441 |
+
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
442 |
+
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
443 |
+
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
444 |
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
445 |
+
}
|
446 |
+
|
447 |
+
.selectize-control.single .selectize-input:hover,
|
448 |
+
.selectize-control.single .selectize-input:focus,
|
449 |
+
.selectize-control.single .selectize-input:active,
|
450 |
+
.selectize-control.single .selectize-input.active,
|
451 |
+
.selectize-control.single .selectize-input.disabled,
|
452 |
+
.selectize-control.single .selectize-input[disabled] {
|
453 |
+
color: #333333;
|
454 |
+
background-color: #e6e6e6;
|
455 |
+
*background-color: #d9d9d9;
|
456 |
+
}
|
457 |
+
|
458 |
+
.selectize-control.single .selectize-input:active,
|
459 |
+
.selectize-control.single .selectize-input.active {
|
460 |
+
background-color: #cccccc \9;
|
461 |
+
}
|
462 |
+
|
463 |
+
.selectize-control.single .selectize-input:hover {
|
464 |
+
color: #333333;
|
465 |
+
text-decoration: none;
|
466 |
+
background-position: 0 -15px;
|
467 |
+
-webkit-transition: background-position 0.1s linear;
|
468 |
+
-moz-transition: background-position 0.1s linear;
|
469 |
+
-o-transition: background-position 0.1s linear;
|
470 |
+
transition: background-position 0.1s linear;
|
471 |
+
}
|
472 |
+
|
473 |
+
.selectize-control.single .selectize-input.disabled {
|
474 |
+
background: #e6e6e6 !important;
|
475 |
+
-webkit-box-shadow: none;
|
476 |
+
-moz-box-shadow: none;
|
477 |
+
box-shadow: none;
|
478 |
+
}
|
479 |
+
|
480 |
+
.selectize-control.multi .selectize-input {
|
481 |
+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
482 |
+
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
483 |
+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
484 |
+
}
|
485 |
+
|
486 |
+
.selectize-control.multi .selectize-input.has-items {
|
487 |
+
padding-right: 7px;
|
488 |
+
padding-left: 7px;
|
489 |
+
}
|
490 |
+
|
491 |
+
.selectize-control.multi .selectize-input > div {
|
492 |
+
color: #333333;
|
493 |
+
text-shadow: none;
|
494 |
+
background-color: #f5f5f5;
|
495 |
+
*background-color: #e6e6e6;
|
496 |
+
background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
|
497 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
|
498 |
+
background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
|
499 |
+
background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
|
500 |
+
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
|
501 |
+
background-repeat: repeat-x;
|
502 |
+
border: 1px solid #cccccc;
|
503 |
+
border-color: #e6e6e6 #e6e6e6 #bfbfbf;
|
504 |
+
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
505 |
+
-webkit-border-radius: 4px;
|
506 |
+
-moz-border-radius: 4px;
|
507 |
+
border-radius: 4px;
|
508 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
|
509 |
+
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
510 |
+
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
511 |
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
|
512 |
+
}
|
513 |
+
|
514 |
+
.selectize-control.multi .selectize-input > div.active {
|
515 |
+
color: #ffffff;
|
516 |
+
text-shadow: none;
|
517 |
+
background-color: #0081c2;
|
518 |
+
*background-color: #0088cc;
|
519 |
+
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
|
520 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
|
521 |
+
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
|
522 |
+
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
|
523 |
+
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
|
524 |
+
background-repeat: repeat-x;
|
525 |
+
border: 1px solid #0088cc;
|
526 |
+
border-color: #0077b3 #0077b3 #004466;
|
527 |
+
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
528 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0);
|
529 |
+
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
530 |
+
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
531 |
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
532 |
+
}
|
css/selectize/selectize.css
ADDED
@@ -0,0 +1,343 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* selectize.css (v0.7.7)
|
3 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
6 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
*
|
9 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
10 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
12 |
+
* governing permissions and limitations under the License.
|
13 |
+
*
|
14 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
15 |
+
*/
|
16 |
+
|
17 |
+
.selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
|
18 |
+
background: #f2f2f2 !important;
|
19 |
+
background: rgba(0, 0, 0, 0.06) !important;
|
20 |
+
border: 0 none !important;
|
21 |
+
visibility: visible !important;
|
22 |
+
-webkit-box-shadow: inset 0 0 12px 4px #ffffff;
|
23 |
+
box-shadow: inset 0 0 12px 4px #ffffff;
|
24 |
+
}
|
25 |
+
|
26 |
+
.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
|
27 |
+
content: '!';
|
28 |
+
visibility: hidden;
|
29 |
+
}
|
30 |
+
|
31 |
+
.selectize-control.plugin-drag_drop .ui-sortable-helper {
|
32 |
+
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
33 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
34 |
+
}
|
35 |
+
|
36 |
+
.selectize-dropdown-header {
|
37 |
+
position: relative;
|
38 |
+
padding: 5px 8px;
|
39 |
+
background: #f8f8f8;
|
40 |
+
border-bottom: 1px solid #d0d0d0;
|
41 |
+
-webkit-border-radius: 3px 3px 0 0;
|
42 |
+
-moz-border-radius: 3px 3px 0 0;
|
43 |
+
border-radius: 3px 3px 0 0;
|
44 |
+
}
|
45 |
+
|
46 |
+
.selectize-dropdown-header-close {
|
47 |
+
position: absolute;
|
48 |
+
top: 50%;
|
49 |
+
right: 8px;
|
50 |
+
margin-top: -12px;
|
51 |
+
font-size: 20px !important;
|
52 |
+
line-height: 20px;
|
53 |
+
color: #303030;
|
54 |
+
opacity: 0.4;
|
55 |
+
}
|
56 |
+
|
57 |
+
.selectize-dropdown-header-close:hover {
|
58 |
+
color: #000000;
|
59 |
+
}
|
60 |
+
|
61 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup {
|
62 |
+
float: left;
|
63 |
+
border-top: 0 none;
|
64 |
+
border-right: 1px solid #f2f2f2;
|
65 |
+
-webkit-box-sizing: border-box;
|
66 |
+
-moz-box-sizing: border-box;
|
67 |
+
box-sizing: border-box;
|
68 |
+
}
|
69 |
+
|
70 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
|
71 |
+
border-right: 0 none;
|
72 |
+
}
|
73 |
+
|
74 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:before {
|
75 |
+
display: none;
|
76 |
+
}
|
77 |
+
|
78 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup-header {
|
79 |
+
border-top: 0 none;
|
80 |
+
}
|
81 |
+
|
82 |
+
.selectize-control.plugin-remove_button [data-value] {
|
83 |
+
position: relative;
|
84 |
+
padding-right: 24px !important;
|
85 |
+
}
|
86 |
+
|
87 |
+
.selectize-control.plugin-remove_button [data-value] .remove {
|
88 |
+
position: absolute;
|
89 |
+
top: 0;
|
90 |
+
right: 0;
|
91 |
+
bottom: 0;
|
92 |
+
display: inline-block;
|
93 |
+
width: 17px;
|
94 |
+
padding: 2px 0 0 0;
|
95 |
+
font-size: 12px;
|
96 |
+
font-weight: bold;
|
97 |
+
color: inherit;
|
98 |
+
text-align: center;
|
99 |
+
text-decoration: none;
|
100 |
+
vertical-align: middle;
|
101 |
+
border-left: 1px solid #d0d0d0;
|
102 |
+
-webkit-border-radius: 0 2px 2px 0;
|
103 |
+
-moz-border-radius: 0 2px 2px 0;
|
104 |
+
border-radius: 0 2px 2px 0;
|
105 |
+
-webkit-box-sizing: border-box;
|
106 |
+
-moz-box-sizing: border-box;
|
107 |
+
box-sizing: border-box;
|
108 |
+
}
|
109 |
+
|
110 |
+
.selectize-control.plugin-remove_button [data-value] .remove:hover {
|
111 |
+
background: rgba(0, 0, 0, 0.05);
|
112 |
+
}
|
113 |
+
|
114 |
+
.selectize-control.plugin-remove_button [data-value].active .remove {
|
115 |
+
border-left-color: #cacaca;
|
116 |
+
}
|
117 |
+
|
118 |
+
.selectize-control {
|
119 |
+
position: relative;
|
120 |
+
}
|
121 |
+
|
122 |
+
.selectize-dropdown,
|
123 |
+
.selectize-input,
|
124 |
+
.selectize-input input {
|
125 |
+
font-family: inherit;
|
126 |
+
font-size: 13px;
|
127 |
+
-webkit-font-smoothing: inherit;
|
128 |
+
line-height: 18px;
|
129 |
+
color: #303030;
|
130 |
+
}
|
131 |
+
|
132 |
+
.selectize-input,
|
133 |
+
.selectize-control.single .selectize-input.focus {
|
134 |
+
display: inline-block;
|
135 |
+
cursor: text;
|
136 |
+
background: #ffffff;
|
137 |
+
}
|
138 |
+
|
139 |
+
.selectize-input {
|
140 |
+
position: relative;
|
141 |
+
z-index: 1;
|
142 |
+
display: inline-block;
|
143 |
+
width: 100%;
|
144 |
+
padding: 8px 8px;
|
145 |
+
overflow: hidden;
|
146 |
+
border: 1px solid #d0d0d0;
|
147 |
+
-webkit-border-radius: 3px;
|
148 |
+
-moz-border-radius: 3px;
|
149 |
+
border-radius: 3px;
|
150 |
+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
|
151 |
+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
|
152 |
+
-webkit-box-sizing: border-box;
|
153 |
+
-moz-box-sizing: border-box;
|
154 |
+
box-sizing: border-box;
|
155 |
+
}
|
156 |
+
|
157 |
+
.selectize-control.multi .selectize-input.has-items {
|
158 |
+
padding: 6px 8px 3px;
|
159 |
+
}
|
160 |
+
|
161 |
+
.selectize-input.full {
|
162 |
+
background-color: #ffffff;
|
163 |
+
}
|
164 |
+
|
165 |
+
.selectize-input.disabled,
|
166 |
+
.selectize-input.disabled * {
|
167 |
+
cursor: default !important;
|
168 |
+
}
|
169 |
+
|
170 |
+
.selectize-input.focus {
|
171 |
+
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
172 |
+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
173 |
+
}
|
174 |
+
|
175 |
+
.selectize-input.dropdown-active {
|
176 |
+
-webkit-border-radius: 3px 3px 0 0;
|
177 |
+
-moz-border-radius: 3px 3px 0 0;
|
178 |
+
border-radius: 3px 3px 0 0;
|
179 |
+
}
|
180 |
+
|
181 |
+
.selectize-input > * {
|
182 |
+
display: -moz-inline-stack;
|
183 |
+
display: inline-block;
|
184 |
+
*display: inline;
|
185 |
+
vertical-align: baseline;
|
186 |
+
zoom: 1;
|
187 |
+
}
|
188 |
+
|
189 |
+
.selectize-control.multi .selectize-input > div {
|
190 |
+
padding: 2px 6px;
|
191 |
+
margin: 0 3px 3px 0;
|
192 |
+
color: #303030;
|
193 |
+
cursor: pointer;
|
194 |
+
background: #f2f2f2;
|
195 |
+
border: 0 solid #d0d0d0;
|
196 |
+
}
|
197 |
+
|
198 |
+
.selectize-control.multi .selectize-input > div.active {
|
199 |
+
color: #303030;
|
200 |
+
background: #e8e8e8;
|
201 |
+
border: 0 solid #cacaca;
|
202 |
+
}
|
203 |
+
|
204 |
+
.selectize-control.multi .selectize-input.disabled > div,
|
205 |
+
.selectize-control.multi .selectize-input.disabled > div.active {
|
206 |
+
color: #7d7d7d;
|
207 |
+
background: #ffffff;
|
208 |
+
border: 0 solid #ffffff;
|
209 |
+
}
|
210 |
+
|
211 |
+
.selectize-input > input {
|
212 |
+
max-width: 100% !important;
|
213 |
+
max-height: none !important;
|
214 |
+
min-height: 0 !important;
|
215 |
+
padding: 0 !important;
|
216 |
+
margin: 0 2px 0 0 !important;
|
217 |
+
line-height: inherit !important;
|
218 |
+
text-indent: 0 !important;
|
219 |
+
background: none !important;
|
220 |
+
border: 0 none !important;
|
221 |
+
-webkit-box-shadow: none !important;
|
222 |
+
box-shadow: none !important;
|
223 |
+
-webkit-user-select: auto !important;
|
224 |
+
}
|
225 |
+
|
226 |
+
.selectize-input > input:focus {
|
227 |
+
outline: none !important;
|
228 |
+
}
|
229 |
+
|
230 |
+
.selectize-input::after {
|
231 |
+
display: block;
|
232 |
+
clear: left;
|
233 |
+
content: ' ';
|
234 |
+
}
|
235 |
+
|
236 |
+
.selectize-input.dropdown-active::before {
|
237 |
+
position: absolute;
|
238 |
+
right: 0;
|
239 |
+
bottom: 0;
|
240 |
+
left: 0;
|
241 |
+
display: block;
|
242 |
+
height: 1px;
|
243 |
+
background: #f0f0f0;
|
244 |
+
content: ' ';
|
245 |
+
}
|
246 |
+
|
247 |
+
.selectize-dropdown {
|
248 |
+
position: absolute;
|
249 |
+
z-index: 10;
|
250 |
+
margin: -1px 0 0 0;
|
251 |
+
background: #ffffff;
|
252 |
+
border: 1px solid #d0d0d0;
|
253 |
+
border-top: 0 none;
|
254 |
+
-webkit-border-radius: 0 0 3px 3px;
|
255 |
+
-moz-border-radius: 0 0 3px 3px;
|
256 |
+
border-radius: 0 0 3px 3px;
|
257 |
+
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
258 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
259 |
+
-webkit-box-sizing: border-box;
|
260 |
+
-moz-box-sizing: border-box;
|
261 |
+
box-sizing: border-box;
|
262 |
+
}
|
263 |
+
|
264 |
+
.selectize-dropdown [data-selectable] {
|
265 |
+
overflow: hidden;
|
266 |
+
cursor: pointer;
|
267 |
+
}
|
268 |
+
|
269 |
+
.selectize-dropdown [data-selectable] .highlight {
|
270 |
+
background: rgba(125, 168, 208, 0.2);
|
271 |
+
-webkit-border-radius: 1px;
|
272 |
+
-moz-border-radius: 1px;
|
273 |
+
border-radius: 1px;
|
274 |
+
}
|
275 |
+
|
276 |
+
.selectize-dropdown [data-selectable],
|
277 |
+
.selectize-dropdown .optgroup-header {
|
278 |
+
padding: 5px 8px;
|
279 |
+
}
|
280 |
+
|
281 |
+
.selectize-dropdown .optgroup:first-child .optgroup-header {
|
282 |
+
border-top: 0 none;
|
283 |
+
}
|
284 |
+
|
285 |
+
.selectize-dropdown .optgroup-header {
|
286 |
+
color: #303030;
|
287 |
+
cursor: default;
|
288 |
+
background: #ffffff;
|
289 |
+
}
|
290 |
+
|
291 |
+
.selectize-dropdown .active {
|
292 |
+
color: #495c68;
|
293 |
+
background-color: #f5fafd;
|
294 |
+
}
|
295 |
+
|
296 |
+
.selectize-dropdown .active.create {
|
297 |
+
color: #495c68;
|
298 |
+
}
|
299 |
+
|
300 |
+
.selectize-dropdown .create {
|
301 |
+
color: rgba(48, 48, 48, 0.5);
|
302 |
+
}
|
303 |
+
|
304 |
+
.selectize-dropdown-content {
|
305 |
+
max-height: 200px;
|
306 |
+
overflow-x: hidden;
|
307 |
+
overflow-y: auto;
|
308 |
+
}
|
309 |
+
|
310 |
+
.selectize-control.single .selectize-input,
|
311 |
+
.selectize-control.single .selectize-input input {
|
312 |
+
cursor: pointer;
|
313 |
+
}
|
314 |
+
|
315 |
+
.selectize-control.single .selectize-input.focus,
|
316 |
+
.selectize-control.single .selectize-input.focus input {
|
317 |
+
cursor: text;
|
318 |
+
}
|
319 |
+
|
320 |
+
.selectize-control.single .selectize-input:after {
|
321 |
+
position: absolute;
|
322 |
+
top: 50%;
|
323 |
+
right: 15px;
|
324 |
+
display: block;
|
325 |
+
width: 0;
|
326 |
+
height: 0;
|
327 |
+
margin-top: -3px;
|
328 |
+
border-color: #808080 transparent transparent transparent;
|
329 |
+
border-style: solid;
|
330 |
+
border-width: 5px 5px 0 5px;
|
331 |
+
content: ' ';
|
332 |
+
}
|
333 |
+
|
334 |
+
.selectize-control.single .selectize-input.dropdown-active:after {
|
335 |
+
margin-top: -4px;
|
336 |
+
border-color: transparent transparent #808080 transparent;
|
337 |
+
border-width: 0 5px 5px 5px;
|
338 |
+
}
|
339 |
+
|
340 |
+
.selectize-control .selectize-input.disabled {
|
341 |
+
background-color: #fafafa;
|
342 |
+
opacity: 0.5;
|
343 |
+
}
|
css/selectize/selectize.default.css
ADDED
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* selectize.default.css (v0.7.7) - Default Theme
|
3 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
6 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
*
|
9 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
10 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
12 |
+
* governing permissions and limitations under the License.
|
13 |
+
*
|
14 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
15 |
+
*/
|
16 |
+
|
17 |
+
.selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
|
18 |
+
background: #f2f2f2 !important;
|
19 |
+
background: rgba(0, 0, 0, 0.06) !important;
|
20 |
+
border: 0 none !important;
|
21 |
+
visibility: visible !important;
|
22 |
+
-webkit-box-shadow: inset 0 0 12px 4px #ffffff;
|
23 |
+
box-shadow: inset 0 0 12px 4px #ffffff;
|
24 |
+
}
|
25 |
+
|
26 |
+
.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
|
27 |
+
content: '!';
|
28 |
+
visibility: hidden;
|
29 |
+
}
|
30 |
+
|
31 |
+
.selectize-control.plugin-drag_drop .ui-sortable-helper {
|
32 |
+
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
33 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
34 |
+
}
|
35 |
+
|
36 |
+
.selectize-dropdown-header {
|
37 |
+
position: relative;
|
38 |
+
padding: 5px 8px;
|
39 |
+
background: #f8f8f8;
|
40 |
+
border-bottom: 1px solid #d0d0d0;
|
41 |
+
-webkit-border-radius: 3px 3px 0 0;
|
42 |
+
-moz-border-radius: 3px 3px 0 0;
|
43 |
+
border-radius: 3px 3px 0 0;
|
44 |
+
}
|
45 |
+
|
46 |
+
.selectize-dropdown-header-close {
|
47 |
+
position: absolute;
|
48 |
+
top: 50%;
|
49 |
+
right: 8px;
|
50 |
+
margin-top: -12px;
|
51 |
+
font-size: 20px !important;
|
52 |
+
line-height: 20px;
|
53 |
+
color: #303030;
|
54 |
+
opacity: 0.4;
|
55 |
+
}
|
56 |
+
|
57 |
+
.selectize-dropdown-header-close:hover {
|
58 |
+
color: #000000;
|
59 |
+
}
|
60 |
+
|
61 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup {
|
62 |
+
float: left;
|
63 |
+
border-top: 0 none;
|
64 |
+
border-right: 1px solid #f2f2f2;
|
65 |
+
-webkit-box-sizing: border-box;
|
66 |
+
-moz-box-sizing: border-box;
|
67 |
+
box-sizing: border-box;
|
68 |
+
}
|
69 |
+
|
70 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
|
71 |
+
border-right: 0 none;
|
72 |
+
}
|
73 |
+
|
74 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup:before {
|
75 |
+
display: none;
|
76 |
+
}
|
77 |
+
|
78 |
+
.selectize-dropdown.plugin-optgroup_columns .optgroup-header {
|
79 |
+
border-top: 0 none;
|
80 |
+
}
|
81 |
+
|
82 |
+
.selectize-control.plugin-remove_button [data-value] {
|
83 |
+
position: relative;
|
84 |
+
padding-right: 24px !important;
|
85 |
+
}
|
86 |
+
|
87 |
+
.selectize-control.plugin-remove_button [data-value] .remove {
|
88 |
+
position: absolute;
|
89 |
+
top: 0;
|
90 |
+
right: 0;
|
91 |
+
bottom: 0;
|
92 |
+
display: inline-block;
|
93 |
+
width: 17px;
|
94 |
+
padding: 2px 0 0 0;
|
95 |
+
font-size: 12px;
|
96 |
+
font-weight: bold;
|
97 |
+
color: inherit;
|
98 |
+
text-align: center;
|
99 |
+
text-decoration: none;
|
100 |
+
vertical-align: middle;
|
101 |
+
border-left: 1px solid #0073bb;
|
102 |
+
-webkit-border-radius: 0 2px 2px 0;
|
103 |
+
-moz-border-radius: 0 2px 2px 0;
|
104 |
+
border-radius: 0 2px 2px 0;
|
105 |
+
-webkit-box-sizing: border-box;
|
106 |
+
-moz-box-sizing: border-box;
|
107 |
+
box-sizing: border-box;
|
108 |
+
}
|
109 |
+
|
110 |
+
.selectize-control.plugin-remove_button [data-value] .remove:hover {
|
111 |
+
background: rgba(0, 0, 0, 0.05);
|
112 |
+
}
|
113 |
+
|
114 |
+
.selectize-control.plugin-remove_button [data-value].active .remove {
|
115 |
+
border-left-color: #00578d;
|
116 |
+
}
|
117 |
+
|
118 |
+
.selectize-control {
|
119 |
+
position: relative;
|
120 |
+
}
|
121 |
+
|
122 |
+
.selectize-dropdown,
|
123 |
+
.selectize-input,
|
124 |
+
.selectize-input input {
|
125 |
+
font-family: inherit;
|
126 |
+
font-size: 13px;
|
127 |
+
-webkit-font-smoothing: inherit;
|
128 |
+
line-height: 18px;
|
129 |
+
color: #303030;
|
130 |
+
}
|
131 |
+
|
132 |
+
.selectize-input,
|
133 |
+
.selectize-control.single .selectize-input.focus {
|
134 |
+
display: inline-block;
|
135 |
+
cursor: text;
|
136 |
+
background: #ffffff;
|
137 |
+
}
|
138 |
+
|
139 |
+
.selectize-input {
|
140 |
+
position: relative;
|
141 |
+
z-index: 1;
|
142 |
+
display: inline-block;
|
143 |
+
width: 100%;
|
144 |
+
padding: 8px 8px;
|
145 |
+
overflow: hidden;
|
146 |
+
border: 1px solid #d0d0d0;
|
147 |
+
-webkit-border-radius: 3px;
|
148 |
+
-moz-border-radius: 3px;
|
149 |
+
border-radius: 3px;
|
150 |
+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
|
151 |
+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
|
152 |
+
-webkit-box-sizing: border-box;
|
153 |
+
-moz-box-sizing: border-box;
|
154 |
+
box-sizing: border-box;
|
155 |
+
}
|
156 |
+
|
157 |
+
.selectize-control.multi .selectize-input.has-items {
|
158 |
+
padding: 5px 8px 2px;
|
159 |
+
}
|
160 |
+
|
161 |
+
.selectize-input.full {
|
162 |
+
background-color: #ffffff;
|
163 |
+
}
|
164 |
+
|
165 |
+
.selectize-input.disabled,
|
166 |
+
.selectize-input.disabled * {
|
167 |
+
cursor: default !important;
|
168 |
+
}
|
169 |
+
|
170 |
+
.selectize-input.focus {
|
171 |
+
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
172 |
+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
|
173 |
+
}
|
174 |
+
|
175 |
+
.selectize-input.dropdown-active {
|
176 |
+
-webkit-border-radius: 3px 3px 0 0;
|
177 |
+
-moz-border-radius: 3px 3px 0 0;
|
178 |
+
border-radius: 3px 3px 0 0;
|
179 |
+
}
|
180 |
+
|
181 |
+
.selectize-input > * {
|
182 |
+
display: -moz-inline-stack;
|
183 |
+
display: inline-block;
|
184 |
+
*display: inline;
|
185 |
+
vertical-align: baseline;
|
186 |
+
zoom: 1;
|
187 |
+
}
|
188 |
+
|
189 |
+
.selectize-control.multi .selectize-input > div {
|
190 |
+
padding: 2px 6px;
|
191 |
+
margin: 0 3px 3px 0;
|
192 |
+
color: #ffffff;
|
193 |
+
cursor: pointer;
|
194 |
+
background: #1da7ee;
|
195 |
+
border: 1px solid #0073bb;
|
196 |
+
}
|
197 |
+
|
198 |
+
.selectize-control.multi .selectize-input > div.active {
|
199 |
+
color: #ffffff;
|
200 |
+
background: #92c836;
|
201 |
+
border: 1px solid #00578d;
|
202 |
+
}
|
203 |
+
|
204 |
+
.selectize-control.multi .selectize-input.disabled > div,
|
205 |
+
.selectize-control.multi .selectize-input.disabled > div.active {
|
206 |
+
color: #ffffff;
|
207 |
+
background: #d2d2d2;
|
208 |
+
border: 1px solid #aaaaaa;
|
209 |
+
}
|
210 |
+
|
211 |
+
.selectize-input > input {
|
212 |
+
max-width: 100% !important;
|
213 |
+
max-height: none !important;
|
214 |
+
min-height: 0 !important;
|
215 |
+
padding: 0 !important;
|
216 |
+
margin: 0 1px !important;
|
217 |
+
line-height: inherit !important;
|
218 |
+
text-indent: 0 !important;
|
219 |
+
background: none !important;
|
220 |
+
border: 0 none !important;
|
221 |
+
-webkit-box-shadow: none !important;
|
222 |
+
box-shadow: none !important;
|
223 |
+
-webkit-user-select: auto !important;
|
224 |
+
}
|
225 |
+
|
226 |
+
.selectize-input > input:focus {
|
227 |
+
outline: none !important;
|
228 |
+
}
|
229 |
+
|
230 |
+
.selectize-input::after {
|
231 |
+
display: block;
|
232 |
+
clear: left;
|
233 |
+
content: ' ';
|
234 |
+
}
|
235 |
+
|
236 |
+
.selectize-input.dropdown-active::before {
|
237 |
+
position: absolute;
|
238 |
+
right: 0;
|
239 |
+
bottom: 0;
|
240 |
+
left: 0;
|
241 |
+
display: block;
|
242 |
+
height: 1px;
|
243 |
+
background: #f0f0f0;
|
244 |
+
content: ' ';
|
245 |
+
}
|
246 |
+
|
247 |
+
.selectize-dropdown {
|
248 |
+
position: absolute;
|
249 |
+
z-index: 10;
|
250 |
+
margin: -1px 0 0 0;
|
251 |
+
background: #ffffff;
|
252 |
+
border: 1px solid #d0d0d0;
|
253 |
+
border-top: 0 none;
|
254 |
+
-webkit-border-radius: 0 0 3px 3px;
|
255 |
+
-moz-border-radius: 0 0 3px 3px;
|
256 |
+
border-radius: 0 0 3px 3px;
|
257 |
+
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
258 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
259 |
+
-webkit-box-sizing: border-box;
|
260 |
+
-moz-box-sizing: border-box;
|
261 |
+
box-sizing: border-box;
|
262 |
+
}
|
263 |
+
|
264 |
+
.selectize-dropdown [data-selectable] {
|
265 |
+
overflow: hidden;
|
266 |
+
cursor: pointer;
|
267 |
+
}
|
268 |
+
|
269 |
+
.selectize-dropdown [data-selectable] .highlight {
|
270 |
+
background: rgba(125, 168, 208, 0.2);
|
271 |
+
-webkit-border-radius: 1px;
|
272 |
+
-moz-border-radius: 1px;
|
273 |
+
border-radius: 1px;
|
274 |
+
}
|
275 |
+
|
276 |
+
.selectize-dropdown [data-selectable],
|
277 |
+
.selectize-dropdown .optgroup-header {
|
278 |
+
padding: 5px 8px;
|
279 |
+
}
|
280 |
+
|
281 |
+
.selectize-dropdown .optgroup:first-child .optgroup-header {
|
282 |
+
border-top: 0 none;
|
283 |
+
}
|
284 |
+
|
285 |
+
.selectize-dropdown .optgroup-header {
|
286 |
+
color: #303030;
|
287 |
+
cursor: default;
|
288 |
+
background: #ffffff;
|
289 |
+
}
|
290 |
+
|
291 |
+
.selectize-dropdown .active {
|
292 |
+
color: #495c68;
|
293 |
+
background-color: #f5fafd;
|
294 |
+
}
|
295 |
+
|
296 |
+
.selectize-dropdown .active.create {
|
297 |
+
color: #495c68;
|
298 |
+
}
|
299 |
+
|
300 |
+
.selectize-dropdown .create {
|
301 |
+
color: rgba(48, 48, 48, 0.5);
|
302 |
+
}
|
303 |
+
|
304 |
+
.selectize-dropdown-content {
|
305 |
+
max-height: 200px;
|
306 |
+
overflow-x: hidden;
|
307 |
+
overflow-y: auto;
|
308 |
+
}
|
309 |
+
|
310 |
+
.selectize-control.single .selectize-input,
|
311 |
+
.selectize-control.single .selectize-input input {
|
312 |
+
cursor: pointer;
|
313 |
+
}
|
314 |
+
|
315 |
+
.selectize-control.single .selectize-input.focus,
|
316 |
+
.selectize-control.single .selectize-input.focus input {
|
317 |
+
cursor: text;
|
318 |
+
}
|
319 |
+
|
320 |
+
.selectize-control.single .selectize-input:after {
|
321 |
+
position: absolute;
|
322 |
+
top: 50%;
|
323 |
+
right: 15px;
|
324 |
+
display: block;
|
325 |
+
width: 0;
|
326 |
+
height: 0;
|
327 |
+
margin-top: -3px;
|
328 |
+
border-color: #808080 transparent transparent transparent;
|
329 |
+
border-style: solid;
|
330 |
+
border-width: 5px 5px 0 5px;
|
331 |
+
content: ' ';
|
332 |
+
}
|
333 |
+
|
334 |
+
.selectize-control.single .selectize-input.dropdown-active:after {
|
335 |
+
margin-top: -4px;
|
336 |
+
border-color: transparent transparent #808080 transparent;
|
337 |
+
border-width: 0 5px 5px 5px;
|
338 |
+
}
|
339 |
+
|
340 |
+
.selectize-control .selectize-input.disabled {
|
341 |
+
background-color: #fafafa;
|
342 |
+
opacity: 0.5;
|
343 |
+
}
|
344 |
+
|
345 |
+
.selectize-control.multi .selectize-input.has-items {
|
346 |
+
padding-right: 5px;
|
347 |
+
padding-left: 5px;
|
348 |
+
}
|
349 |
+
|
350 |
+
.selectize-control.multi .selectize-input.disabled [data-value] {
|
351 |
+
color: #999;
|
352 |
+
text-shadow: none;
|
353 |
+
background: none;
|
354 |
+
border-color: #e6e6e6;
|
355 |
+
-webkit-box-shadow: none;
|
356 |
+
box-shadow: none;
|
357 |
+
}
|
358 |
+
|
359 |
+
.selectize-control.multi .selectize-input [data-value] {
|
360 |
+
text-shadow: 0 1px 0 rgba(0, 51, 83, 0.3);
|
361 |
+
background-color: #1b9dec;
|
362 |
+
background-image: -moz-linear-gradient(top, #1da7ee, #178ee9);
|
363 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#1da7ee), to(#178ee9));
|
364 |
+
background-image: -webkit-linear-gradient(top, #1da7ee, #178ee9);
|
365 |
+
background-image: -o-linear-gradient(top, #1da7ee, #178ee9);
|
366 |
+
background-image: linear-gradient(to bottom, #1da7ee, #178ee9);
|
367 |
+
background-repeat: repeat-x;
|
368 |
+
-webkit-border-radius: 3px;
|
369 |
+
-moz-border-radius: 3px;
|
370 |
+
border-radius: 3px;
|
371 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff1da7ee', endColorstr='#ff178ee9', GradientType=0);
|
372 |
+
-webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), inset 0 1px rgba(255, 255, 255, 0.03);
|
373 |
+
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), inset 0 1px rgba(255, 255, 255, 0.03);
|
374 |
+
}
|
375 |
+
|
376 |
+
.selectize-control.multi .selectize-input [data-value].active {
|
377 |
+
background-color: #0085d4;
|
378 |
+
background-image: -moz-linear-gradient(top, #008fd8, #0075cf);
|
379 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#008fd8), to(#0075cf));
|
380 |
+
background-image: -webkit-linear-gradient(top, #008fd8, #0075cf);
|
381 |
+
background-image: -o-linear-gradient(top, #008fd8, #0075cf);
|
382 |
+
background-image: linear-gradient(to bottom, #008fd8, #0075cf);
|
383 |
+
background-repeat: repeat-x;
|
384 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff008fd8', endColorstr='#ff0075cf', GradientType=0);
|
385 |
+
}
|
386 |
+
|
387 |
+
.selectize-control.single .selectize-input {
|
388 |
+
background-color: #f9f9f9;
|
389 |
+
background-image: -moz-linear-gradient(top, #fefefe, #f2f2f2);
|
390 |
+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fefefe), to(#f2f2f2));
|
391 |
+
background-image: -webkit-linear-gradient(top, #fefefe, #f2f2f2);
|
392 |
+
background-image: -o-linear-gradient(top, #fefefe, #f2f2f2);
|
393 |
+
background-image: linear-gradient(to bottom, #fefefe, #f2f2f2);
|
394 |
+
background-repeat: repeat-x;
|
395 |
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffefefe', endColorstr='#fff2f2f2', GradientType=0);
|
396 |
+
-webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
397 |
+
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
398 |
+
}
|
399 |
+
|
400 |
+
.selectize-control.single .selectize-input,
|
401 |
+
.selectize-dropdown.single {
|
402 |
+
border-color: #b8b8b8;
|
403 |
+
}
|
404 |
+
|
405 |
+
.selectize-dropdown .optgroup-header {
|
406 |
+
padding-top: 7px;
|
407 |
+
font-size: 0.85em;
|
408 |
+
font-weight: bold;
|
409 |
+
}
|
410 |
+
|
411 |
+
.selectize-dropdown .optgroup {
|
412 |
+
border-top: 1px solid #f0f0f0;
|
413 |
+
}
|
414 |
+
|
415 |
+
.selectize-dropdown .optgroup:first-child {
|
416 |
+
border-top: 0 none;
|
417 |
+
}
|
groups.php
CHANGED
@@ -21,13 +21,13 @@
|
|
21 |
* Plugin Name: Groups
|
22 |
* Plugin URI: http://www.itthinx.com/plugins/groups
|
23 |
* Description: Groups provides group-based user membership management, group-based capabilities and content access control.
|
24 |
-
* Version: 1.3.
|
25 |
* Author: itthinx
|
26 |
* Author URI: http://www.itthinx.com
|
27 |
* Donate-Link: http://www.itthinx.com
|
28 |
* License: GPLv3
|
29 |
*/
|
30 |
-
define( 'GROUPS_CORE_VERSION', '1.3.
|
31 |
define( 'GROUPS_FILE', __FILE__ );
|
32 |
if ( !defined( 'GROUPS_CORE_DIR' ) ) {
|
33 |
define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
|
21 |
* Plugin Name: Groups
|
22 |
* Plugin URI: http://www.itthinx.com/plugins/groups
|
23 |
* Description: Groups provides group-based user membership management, group-based capabilities and content access control.
|
24 |
+
* Version: 1.3.14
|
25 |
* Author: itthinx
|
26 |
* Author URI: http://www.itthinx.com
|
27 |
* Donate-Link: http://www.itthinx.com
|
28 |
* License: GPLv3
|
29 |
*/
|
30 |
+
define( 'GROUPS_CORE_VERSION', '1.3.14' );
|
31 |
define( 'GROUPS_FILE', __FILE__ );
|
32 |
if ( !defined( 'GROUPS_CORE_DIR' ) ) {
|
33 |
define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
|
js/chosen/chosen.jquery.js
ADDED
@@ -0,0 +1,1166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Chosen, a Select Box Enhancer for jQuery and Prototype
|
2 |
+
// by Patrick Filler for Harvest, http://getharvest.com
|
3 |
+
//
|
4 |
+
// Version 1.0.0
|
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 `grunt build`, do not edit it by hand.
|
10 |
+
(function() {
|
11 |
+
var $, AbstractChosen, Chosen, SelectParser, _ref,
|
12 |
+
__hasProp = {}.hasOwnProperty,
|
13 |
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
14 |
+
|
15 |
+
SelectParser = (function() {
|
16 |
+
function SelectParser() {
|
17 |
+
this.options_index = 0;
|
18 |
+
this.parsed = [];
|
19 |
+
}
|
20 |
+
|
21 |
+
SelectParser.prototype.add_node = function(child) {
|
22 |
+
if (child.nodeName.toUpperCase() === "OPTGROUP") {
|
23 |
+
return this.add_group(child);
|
24 |
+
} else {
|
25 |
+
return this.add_option(child);
|
26 |
+
}
|
27 |
+
};
|
28 |
+
|
29 |
+
SelectParser.prototype.add_group = function(group) {
|
30 |
+
var group_position, option, _i, _len, _ref, _results;
|
31 |
+
|
32 |
+
group_position = this.parsed.length;
|
33 |
+
this.parsed.push({
|
34 |
+
array_index: group_position,
|
35 |
+
group: true,
|
36 |
+
label: this.escapeExpression(group.label),
|
37 |
+
children: 0,
|
38 |
+
disabled: group.disabled
|
39 |
+
});
|
40 |
+
_ref = group.childNodes;
|
41 |
+
_results = [];
|
42 |
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
43 |
+
option = _ref[_i];
|
44 |
+
_results.push(this.add_option(option, group_position, group.disabled));
|
45 |
+
}
|
46 |
+
return _results;
|
47 |
+
};
|
48 |
+
|
49 |
+
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
|
50 |
+
if (option.nodeName.toUpperCase() === "OPTION") {
|
51 |
+
if (option.text !== "") {
|
52 |
+
if (group_position != null) {
|
53 |
+
this.parsed[group_position].children += 1;
|
54 |
+
}
|
55 |
+
this.parsed.push({
|
56 |
+
array_index: this.parsed.length,
|
57 |
+
options_index: this.options_index,
|
58 |
+
value: option.value,
|
59 |
+
text: option.text,
|
60 |
+
html: option.innerHTML,
|
61 |
+
selected: option.selected,
|
62 |
+
disabled: group_disabled === true ? group_disabled : option.disabled,
|
63 |
+
group_array_index: group_position,
|
64 |
+
classes: option.className,
|
65 |
+
style: option.style.cssText
|
66 |
+
});
|
67 |
+
} else {
|
68 |
+
this.parsed.push({
|
69 |
+
array_index: this.parsed.length,
|
70 |
+
options_index: this.options_index,
|
71 |
+
empty: true
|
72 |
+
});
|
73 |
+
}
|
74 |
+
return this.options_index += 1;
|
75 |
+
}
|
76 |
+
};
|
77 |
+
|
78 |
+
SelectParser.prototype.escapeExpression = function(text) {
|
79 |
+
var map, unsafe_chars;
|
80 |
+
|
81 |
+
if ((text == null) || text === false) {
|
82 |
+
return "";
|
83 |
+
}
|
84 |
+
if (!/[\&\<\>\"\'\`]/.test(text)) {
|
85 |
+
return text;
|
86 |
+
}
|
87 |
+
map = {
|
88 |
+
"<": "<",
|
89 |
+
">": ">",
|
90 |
+
'"': """,
|
91 |
+
"'": "'",
|
92 |
+
"`": "`"
|
93 |
+
};
|
94 |
+
unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
|
95 |
+
return text.replace(unsafe_chars, function(chr) {
|
96 |
+
return map[chr] || "&";
|
97 |
+
});
|
98 |
+
};
|
99 |
+
|
100 |
+
return SelectParser;
|
101 |
+
|
102 |
+
})();
|
103 |
+
|
104 |
+
SelectParser.select_to_array = function(select) {
|
105 |
+
var child, parser, _i, _len, _ref;
|
106 |
+
|
107 |
+
parser = new SelectParser();
|
108 |
+
_ref = select.childNodes;
|
109 |
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
110 |
+
child = _ref[_i];
|
111 |
+
parser.add_node(child);
|
112 |
+
}
|
113 |
+
return parser.parsed;
|
114 |
+
};
|
115 |
+
|
116 |
+
AbstractChosen = (function() {
|
117 |
+
function AbstractChosen(form_field, options) {
|
118 |
+
this.form_field = form_field;
|
119 |
+
this.options = options != null ? options : {};
|
120 |
+
if (!AbstractChosen.browser_is_supported()) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
this.is_multiple = this.form_field.multiple;
|
124 |
+
this.set_default_text();
|
125 |
+
this.set_default_values();
|
126 |
+
this.setup();
|
127 |
+
this.set_up_html();
|
128 |
+
this.register_observers();
|
129 |
+
}
|
130 |
+
|
131 |
+
AbstractChosen.prototype.set_default_values = function() {
|
132 |
+
var _this = this;
|
133 |
+
|
134 |
+
this.click_test_action = function(evt) {
|
135 |
+
return _this.test_active_click(evt);
|
136 |
+
};
|
137 |
+
this.activate_action = function(evt) {
|
138 |
+
return _this.activate_field(evt);
|
139 |
+
};
|
140 |
+
this.active_field = false;
|
141 |
+
this.mouse_on_container = false;
|
142 |
+
this.results_showing = false;
|
143 |
+
this.result_highlighted = null;
|
144 |
+
this.result_single_selected = null;
|
145 |
+
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;
|
146 |
+
this.disable_search_threshold = this.options.disable_search_threshold || 0;
|
147 |
+
this.disable_search = this.options.disable_search || false;
|
148 |
+
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
|
149 |
+
this.group_search = this.options.group_search != null ? this.options.group_search : true;
|
150 |
+
this.search_contains = this.options.search_contains || false;
|
151 |
+
this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
|
152 |
+
this.max_selected_options = this.options.max_selected_options || Infinity;
|
153 |
+
this.inherit_select_classes = this.options.inherit_select_classes || false;
|
154 |
+
this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
|
155 |
+
return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
|
156 |
+
};
|
157 |
+
|
158 |
+
AbstractChosen.prototype.set_default_text = function() {
|
159 |
+
if (this.form_field.getAttribute("data-placeholder")) {
|
160 |
+
this.default_text = this.form_field.getAttribute("data-placeholder");
|
161 |
+
} else if (this.is_multiple) {
|
162 |
+
this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
|
163 |
+
} else {
|
164 |
+
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
|
165 |
+
}
|
166 |
+
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
|
167 |
+
};
|
168 |
+
|
169 |
+
AbstractChosen.prototype.mouse_enter = function() {
|
170 |
+
return this.mouse_on_container = true;
|
171 |
+
};
|
172 |
+
|
173 |
+
AbstractChosen.prototype.mouse_leave = function() {
|
174 |
+
return this.mouse_on_container = false;
|
175 |
+
};
|
176 |
+
|
177 |
+
AbstractChosen.prototype.input_focus = function(evt) {
|
178 |
+
var _this = this;
|
179 |
+
|
180 |
+
if (this.is_multiple) {
|
181 |
+
if (!this.active_field) {
|
182 |
+
return setTimeout((function() {
|
183 |
+
return _this.container_mousedown();
|
184 |
+
}), 50);
|
185 |
+
}
|
186 |
+
} else {
|
187 |
+
if (!this.active_field) {
|
188 |
+
return this.activate_field();
|
189 |
+
}
|
190 |
+
}
|
191 |
+
};
|
192 |
+
|
193 |
+
AbstractChosen.prototype.input_blur = function(evt) {
|
194 |
+
var _this = this;
|
195 |
+
|
196 |
+
if (!this.mouse_on_container) {
|
197 |
+
this.active_field = false;
|
198 |
+
return setTimeout((function() {
|
199 |
+
return _this.blur_test();
|
200 |
+
}), 100);
|
201 |
+
}
|
202 |
+
};
|
203 |
+
|
204 |
+
AbstractChosen.prototype.results_option_build = function(options) {
|
205 |
+
var content, data, _i, _len, _ref;
|
206 |
+
|
207 |
+
content = '';
|
208 |
+
_ref = this.results_data;
|
209 |
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
210 |
+
data = _ref[_i];
|
211 |
+
if (data.group) {
|
212 |
+
content += this.result_add_group(data);
|
213 |
+
} else {
|
214 |
+
content += this.result_add_option(data);
|
215 |
+
}
|
216 |
+
if (options != null ? options.first : void 0) {
|
217 |
+
if (data.selected && this.is_multiple) {
|
218 |
+
this.choice_build(data);
|
219 |
+
} else if (data.selected && !this.is_multiple) {
|
220 |
+
this.single_set_selected_text(data.text);
|
221 |
+
}
|
222 |
+
}
|
223 |
+
}
|
224 |
+
return content;
|
225 |
+
};
|
226 |
+
|
227 |
+
AbstractChosen.prototype.result_add_option = function(option) {
|
228 |
+
var classes, style;
|
229 |
+
|
230 |
+
if (!option.search_match) {
|
231 |
+
return '';
|
232 |
+
}
|
233 |
+
if (!this.include_option_in_results(option)) {
|
234 |
+
return '';
|
235 |
+
}
|
236 |
+
classes = [];
|
237 |
+
if (!option.disabled && !(option.selected && this.is_multiple)) {
|
238 |
+
classes.push("active-result");
|
239 |
+
}
|
240 |
+
if (option.disabled && !(option.selected && this.is_multiple)) {
|
241 |
+
classes.push("disabled-result");
|
242 |
+
}
|
243 |
+
if (option.selected) {
|
244 |
+
classes.push("result-selected");
|
245 |
+
}
|
246 |
+
if (option.group_array_index != null) {
|
247 |
+
classes.push("group-option");
|
248 |
+
}
|
249 |
+
if (option.classes !== "") {
|
250 |
+
classes.push(option.classes);
|
251 |
+
}
|
252 |
+
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
|
253 |
+
return "<li class=\"" + (classes.join(' ')) + "\"" + style + " data-option-array-index=\"" + option.array_index + "\">" + option.search_text + "</li>";
|
254 |
+
};
|
255 |
+
|
256 |
+
AbstractChosen.prototype.result_add_group = function(group) {
|
257 |
+
if (!(group.search_match || group.group_match)) {
|
258 |
+
return '';
|
259 |
+
}
|
260 |
+
if (!(group.active_options > 0)) {
|
261 |
+
return '';
|
262 |
+
}
|
263 |
+
return "<li class=\"group-result\">" + group.search_text + "</li>";
|
264 |
+
};
|
265 |
+
|
266 |
+
AbstractChosen.prototype.results_update_field = function() {
|
267 |
+
this.set_default_text();
|
268 |
+
if (!this.is_multiple) {
|
269 |
+
this.results_reset_cleanup();
|
270 |
+
}
|
271 |
+
this.result_clear_highlight();
|
272 |
+
this.result_single_selected = null;
|
273 |
+
this.results_build();
|
274 |
+
if (this.results_showing) {
|
275 |
+
return this.winnow_results();
|
276 |
+
}
|
277 |
+
};
|
278 |
+
|
279 |
+
AbstractChosen.prototype.results_toggle = function() {
|
280 |
+
if (this.results_showing) {
|
281 |
+
return this.results_hide();
|
282 |
+
} else {
|
283 |
+
return this.results_show();
|
284 |
+
}
|
285 |
+
};
|
286 |
+
|
287 |
+
AbstractChosen.prototype.results_search = function(evt) {
|
288 |
+
if (this.results_showing) {
|
289 |
+
return this.winnow_results();
|
290 |
+
} else {
|
291 |
+
return this.results_show();
|
292 |
+
}
|
293 |
+
};
|
294 |
+
|
295 |
+
AbstractChosen.prototype.winnow_results = function() {
|
296 |
+
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
|
297 |
+
|
298 |
+
this.no_results_clear();
|
299 |
+
results = 0;
|
300 |
+
searchText = this.get_search_text();
|
301 |
+
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
302 |
+
regexAnchor = this.search_contains ? "" : "^";
|
303 |
+
regex = new RegExp(regexAnchor + escapedSearchText, 'i');
|
304 |
+
zregex = new RegExp(escapedSearchText, 'i');
|
305 |
+
_ref = this.results_data;
|
306 |
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
307 |
+
option = _ref[_i];
|
308 |
+
option.search_match = false;
|
309 |
+
results_group = null;
|
310 |
+
if (this.include_option_in_results(option)) {
|
311 |
+
if (option.group) {
|
312 |
+
option.group_match = false;
|
313 |
+
option.active_options = 0;
|
314 |
+
}
|
315 |
+
if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
|
316 |
+
results_group = this.results_data[option.group_array_index];
|
317 |
+
if (results_group.active_options === 0 && results_group.search_match) {
|
318 |
+
results += 1;
|
319 |
+
}
|
320 |
+
results_group.active_options += 1;
|
321 |
+
}
|
322 |
+
if (!(option.group && !this.group_search)) {
|
323 |
+
option.search_text = option.group ? option.label : option.html;
|
324 |
+
option.search_match = this.search_string_match(option.search_text, regex);
|
325 |
+
if (option.search_match && !option.group) {
|
326 |
+
results += 1;
|
327 |
+
}
|
328 |
+
if (option.search_match) {
|
329 |
+
if (searchText.length) {
|
330 |
+
startpos = option.search_text.search(zregex);
|
331 |
+
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
|
332 |
+
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
|
333 |
+
}
|
334 |
+
if (results_group != null) {
|
335 |
+
results_group.group_match = true;
|
336 |
+
}
|
337 |
+
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
|
338 |
+
option.search_match = true;
|
339 |
+
}
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
this.result_clear_highlight();
|
344 |
+
if (results < 1 && searchText.length) {
|
345 |
+
this.update_results_content("");
|
346 |
+
return this.no_results(searchText);
|
347 |
+
} else {
|
348 |
+
this.update_results_content(this.results_option_build());
|
349 |
+
return this.winnow_results_set_highlight();
|
350 |
+
}
|
351 |
+
};
|
352 |
+
|
353 |
+
AbstractChosen.prototype.search_string_match = function(search_string, regex) {
|
354 |
+
var part, parts, _i, _len;
|
355 |
+
|
356 |
+
if (regex.test(search_string)) {
|
357 |
+
return true;
|
358 |
+
} else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
|
359 |
+
parts = search_string.replace(/\[|\]/g, "").split(" ");
|
360 |
+
if (parts.length) {
|
361 |
+
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
362 |
+
part = parts[_i];
|
363 |
+
if (regex.test(part)) {
|
364 |
+
return true;
|
365 |
+
}
|
366 |
+
}
|
367 |
+
}
|
368 |
+
}
|
369 |
+
};
|
370 |
+
|
371 |
+
AbstractChosen.prototype.choices_count = function() {
|
372 |
+
var option, _i, _len, _ref;
|
373 |
+
|
374 |
+
if (this.selected_option_count != null) {
|
375 |
+
return this.selected_option_count;
|
376 |
+
}
|
377 |
+
this.selected_option_count = 0;
|
378 |
+
_ref = this.form_field.options;
|
379 |
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
380 |
+
option = _ref[_i];
|
381 |
+
if (option.selected) {
|
382 |
+
this.selected_option_count += 1;
|
383 |
+
}
|
384 |
+
}
|
385 |
+
return this.selected_option_count;
|
386 |
+
};
|
387 |
+
|
388 |
+
AbstractChosen.prototype.choices_click = function(evt) {
|
389 |
+
evt.preventDefault();
|
390 |
+
if (!(this.results_showing || this.is_disabled)) {
|
391 |
+
return this.results_show();
|
392 |
+
}
|
393 |
+
};
|
394 |
+
|
395 |
+
AbstractChosen.prototype.keyup_checker = function(evt) {
|
396 |
+
var stroke, _ref;
|
397 |
+
|
398 |
+
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
|
399 |
+
this.search_field_scale();
|
400 |
+
switch (stroke) {
|
401 |
+
case 8:
|
402 |
+
if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
|
403 |
+
return this.keydown_backstroke();
|
404 |
+
} else if (!this.pending_backstroke) {
|
405 |
+
this.result_clear_highlight();
|
406 |
+
return this.results_search();
|
407 |
+
}
|
408 |
+
break;
|
409 |
+
case 13:
|
410 |
+
evt.preventDefault();
|
411 |
+
if (this.results_showing) {
|
412 |
+
return this.result_select(evt);
|
413 |
+
}
|
414 |
+
break;
|
415 |
+
case 27:
|
416 |
+
if (this.results_showing) {
|
417 |
+
this.results_hide();
|
418 |
+
}
|
419 |
+
return true;
|
420 |
+
case 9:
|
421 |
+
case 38:
|
422 |
+
case 40:
|
423 |
+
case 16:
|
424 |
+
case 91:
|
425 |
+
case 17:
|
426 |
+
break;
|
427 |
+
default:
|
428 |
+
return this.results_search();
|
429 |
+
}
|
430 |
+
};
|
431 |
+
|
432 |
+
AbstractChosen.prototype.container_width = function() {
|
433 |
+
if (this.options.width != null) {
|
434 |
+
return this.options.width;
|
435 |
+
} else {
|
436 |
+
return "" + this.form_field.offsetWidth + "px";
|
437 |
+
}
|
438 |
+
};
|
439 |
+
|
440 |
+
AbstractChosen.prototype.include_option_in_results = function(option) {
|
441 |
+
if (this.is_multiple && (!this.display_selected_options && option.selected)) {
|
442 |
+
return false;
|
443 |
+
}
|
444 |
+
if (!this.display_disabled_options && option.disabled) {
|
445 |
+
return false;
|
446 |
+
}
|
447 |
+
if (option.empty) {
|
448 |
+
return false;
|
449 |
+
}
|
450 |
+
return true;
|
451 |
+
};
|
452 |
+
|
453 |
+
AbstractChosen.browser_is_supported = function() {
|
454 |
+
if (window.navigator.appName === "Microsoft Internet Explorer") {
|
455 |
+
return document.documentMode >= 8;
|
456 |
+
}
|
457 |
+
if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
|
458 |
+
return false;
|
459 |
+
}
|
460 |
+
if (/Android/i.test(window.navigator.userAgent)) {
|
461 |
+
if (/Mobile/i.test(window.navigator.userAgent)) {
|
462 |
+
return false;
|
463 |
+
}
|
464 |
+
}
|
465 |
+
return true;
|
466 |
+
};
|
467 |
+
|
468 |
+
AbstractChosen.default_multiple_text = "Select Some Options";
|
469 |
+
|
470 |
+
AbstractChosen.default_single_text = "Select an Option";
|
471 |
+
|
472 |
+
AbstractChosen.default_no_result_text = "No results match";
|
473 |
+
|
474 |
+
return AbstractChosen;
|
475 |
+
|
476 |
+
})();
|
477 |
+
|
478 |
+
$ = jQuery;
|
479 |
+
|
480 |
+
$.fn.extend({
|
481 |
+
chosen: function(options) {
|
482 |
+
if (!AbstractChosen.browser_is_supported()) {
|
483 |
+
return this;
|
484 |
+
}
|
485 |
+
return this.each(function(input_field) {
|
486 |
+
var $this, chosen;
|
487 |
+
|
488 |
+
$this = $(this);
|
489 |
+
chosen = $this.data('chosen');
|
490 |
+
if (options === 'destroy' && chosen) {
|
491 |
+
chosen.destroy();
|
492 |
+
} else if (!chosen) {
|
493 |
+
$this.data('chosen', new Chosen(this, options));
|
494 |
+
}
|
495 |
+
});
|
496 |
+
}
|
497 |
+
});
|
498 |
+
|
499 |
+
Chosen = (function(_super) {
|
500 |
+
__extends(Chosen, _super);
|
501 |
+
|
502 |
+
function Chosen() {
|
503 |
+
_ref = Chosen.__super__.constructor.apply(this, arguments);
|
504 |
+
return _ref;
|
505 |
+
}
|
506 |
+
|
507 |
+
Chosen.prototype.setup = function() {
|
508 |
+
this.form_field_jq = $(this.form_field);
|
509 |
+
this.current_selectedIndex = this.form_field.selectedIndex;
|
510 |
+
return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
|
511 |
+
};
|
512 |
+
|
513 |
+
Chosen.prototype.set_up_html = function() {
|
514 |
+
var container_classes, container_props;
|
515 |
+
|
516 |
+
container_classes = ["chosen-container"];
|
517 |
+
container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
|
518 |
+
if (this.inherit_select_classes && this.form_field.className) {
|
519 |
+
container_classes.push(this.form_field.className);
|
520 |
+
}
|
521 |
+
if (this.is_rtl) {
|
522 |
+
container_classes.push("chosen-rtl");
|
523 |
+
}
|
524 |
+
container_props = {
|
525 |
+
'class': container_classes.join(' '),
|
526 |
+
'style': "width: " + (this.container_width()) + ";",
|
527 |
+
'title': this.form_field.title
|
528 |
+
};
|
529 |
+
if (this.form_field.id.length) {
|
530 |
+
container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
|
531 |
+
}
|
532 |
+
this.container = $("<div />", container_props);
|
533 |
+
if (this.is_multiple) {
|
534 |
+
this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
|
535 |
+
} else {
|
536 |
+
this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
|
537 |
+
}
|
538 |
+
this.form_field_jq.hide().after(this.container);
|
539 |
+
this.dropdown = this.container.find('div.chosen-drop').first();
|
540 |
+
this.search_field = this.container.find('input').first();
|
541 |
+
this.search_results = this.container.find('ul.chosen-results').first();
|
542 |
+
this.search_field_scale();
|
543 |
+
this.search_no_results = this.container.find('li.no-results').first();
|
544 |
+
if (this.is_multiple) {
|
545 |
+
this.search_choices = this.container.find('ul.chosen-choices').first();
|
546 |
+
this.search_container = this.container.find('li.search-field').first();
|
547 |
+
} else {
|
548 |
+
this.search_container = this.container.find('div.chosen-search').first();
|
549 |
+
this.selected_item = this.container.find('.chosen-single').first();
|
550 |
+
}
|
551 |
+
this.results_build();
|
552 |
+
this.set_tab_index();
|
553 |
+
this.set_label_behavior();
|
554 |
+
return this.form_field_jq.trigger("chosen:ready", {
|
555 |
+
chosen: this
|
556 |
+
});
|
557 |
+
};
|
558 |
+
|
559 |
+
Chosen.prototype.register_observers = function() {
|
560 |
+
var _this = this;
|
561 |
+
|
562 |
+
this.container.bind('mousedown.chosen', function(evt) {
|
563 |
+
_this.container_mousedown(evt);
|
564 |
+
});
|
565 |
+
this.container.bind('mouseup.chosen', function(evt) {
|
566 |
+
_this.container_mouseup(evt);
|
567 |
+
});
|
568 |
+
this.container.bind('mouseenter.chosen', function(evt) {
|
569 |
+
_this.mouse_enter(evt);
|
570 |
+
});
|
571 |
+
this.container.bind('mouseleave.chosen', function(evt) {
|
572 |
+
_this.mouse_leave(evt);
|
573 |
+
});
|
574 |
+
this.search_results.bind('mouseup.chosen', function(evt) {
|
575 |
+
_this.search_results_mouseup(evt);
|
576 |
+
});
|
577 |
+
this.search_results.bind('mouseover.chosen', function(evt) {
|
578 |
+
_this.search_results_mouseover(evt);
|
579 |
+
});
|
580 |
+
this.search_results.bind('mouseout.chosen', function(evt) {
|
581 |
+
_this.search_results_mouseout(evt);
|
582 |
+
});
|
583 |
+
this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
|
584 |
+
_this.search_results_mousewheel(evt);
|
585 |
+
});
|
586 |
+
this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
|
587 |
+
_this.results_update_field(evt);
|
588 |
+
});
|
589 |
+
this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
|
590 |
+
_this.activate_field(evt);
|
591 |
+
});
|
592 |
+
this.form_field_jq.bind("chosen:open.chosen", function(evt) {
|
593 |
+
_this.container_mousedown(evt);
|
594 |
+
});
|
595 |
+
this.search_field.bind('blur.chosen', function(evt) {
|
596 |
+
_this.input_blur(evt);
|
597 |
+
});
|
598 |
+
this.search_field.bind('keyup.chosen', function(evt) {
|
599 |
+
_this.keyup_checker(evt);
|
600 |
+
});
|
601 |
+
this.search_field.bind('keydown.chosen', function(evt) {
|
602 |
+
_this.keydown_checker(evt);
|
603 |
+
});
|
604 |
+
this.search_field.bind('focus.chosen', function(evt) {
|
605 |
+
_this.input_focus(evt);
|
606 |
+
});
|
607 |
+
if (this.is_multiple) {
|
608 |
+
return this.search_choices.bind('click.chosen', function(evt) {
|
609 |
+
_this.choices_click(evt);
|
610 |
+
});
|
611 |
+
} else {
|
612 |
+
return this.container.bind('click.chosen', function(evt) {
|
613 |
+
evt.preventDefault();
|
614 |
+
});
|
615 |
+
}
|
616 |
+
};
|
617 |
+
|
618 |
+
Chosen.prototype.destroy = function() {
|
619 |
+
$(document).unbind("click.chosen", this.click_test_action);
|
620 |
+
if (this.search_field[0].tabIndex) {
|
621 |
+
this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
|
622 |
+
}
|
623 |
+
this.container.remove();
|
624 |
+
this.form_field_jq.removeData('chosen');
|
625 |
+
return this.form_field_jq.show();
|
626 |
+
};
|
627 |
+
|
628 |
+
Chosen.prototype.search_field_disabled = function() {
|
629 |
+
this.is_disabled = this.form_field_jq[0].disabled;
|
630 |
+
if (this.is_disabled) {
|
631 |
+
this.container.addClass('chosen-disabled');
|
632 |
+
this.search_field[0].disabled = true;
|
633 |
+
if (!this.is_multiple) {
|
634 |
+
this.selected_item.unbind("focus.chosen", this.activate_action);
|
635 |
+
}
|
636 |
+
return this.close_field();
|
637 |
+
} else {
|
638 |
+
this.container.removeClass('chosen-disabled');
|
639 |
+
this.search_field[0].disabled = false;
|
640 |
+
if (!this.is_multiple) {
|
641 |
+
return this.selected_item.bind("focus.chosen", this.activate_action);
|
642 |
+
}
|
643 |
+
}
|
644 |
+
};
|
645 |
+
|
646 |
+
Chosen.prototype.container_mousedown = function(evt) {
|
647 |
+
if (!this.is_disabled) {
|
648 |
+
if (evt && evt.type === "mousedown" && !this.results_showing) {
|
649 |
+
evt.preventDefault();
|
650 |
+
}
|
651 |
+
if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
|
652 |
+
if (!this.active_field) {
|
653 |
+
if (this.is_multiple) {
|
654 |
+
this.search_field.val("");
|
655 |
+
}
|
656 |
+
$(document).bind('click.chosen', this.click_test_action);
|
657 |
+
this.results_show();
|
658 |
+
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
|
659 |
+
evt.preventDefault();
|
660 |
+
this.results_toggle();
|
661 |
+
}
|
662 |
+
return this.activate_field();
|
663 |
+
}
|
664 |
+
}
|
665 |
+
};
|
666 |
+
|
667 |
+
Chosen.prototype.container_mouseup = function(evt) {
|
668 |
+
if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
|
669 |
+
return this.results_reset(evt);
|
670 |
+
}
|
671 |
+
};
|
672 |
+
|
673 |
+
Chosen.prototype.search_results_mousewheel = function(evt) {
|
674 |
+
var delta, _ref1, _ref2;
|
675 |
+
|
676 |
+
delta = -((_ref1 = evt.originalEvent) != null ? _ref1.wheelDelta : void 0) || ((_ref2 = evt.originialEvent) != null ? _ref2.detail : void 0);
|
677 |
+
if (delta != null) {
|
678 |
+
evt.preventDefault();
|
679 |
+
if (evt.type === 'DOMMouseScroll') {
|
680 |
+
delta = delta * 40;
|
681 |
+
}
|
682 |
+
return this.search_results.scrollTop(delta + this.search_results.scrollTop());
|
683 |
+
}
|
684 |
+
};
|
685 |
+
|
686 |
+
Chosen.prototype.blur_test = function(evt) {
|
687 |
+
if (!this.active_field && this.container.hasClass("chosen-container-active")) {
|
688 |
+
return this.close_field();
|
689 |
+
}
|
690 |
+
};
|
691 |
+
|
692 |
+
Chosen.prototype.close_field = function() {
|
693 |
+
$(document).unbind("click.chosen", this.click_test_action);
|
694 |
+
this.active_field = false;
|
695 |
+
this.results_hide();
|
696 |
+
this.container.removeClass("chosen-container-active");
|
697 |
+
this.clear_backstroke();
|
698 |
+
this.show_search_field_default();
|
699 |
+
return this.search_field_scale();
|
700 |
+
};
|
701 |
+
|
702 |
+
Chosen.prototype.activate_field = function() {
|
703 |
+
this.container.addClass("chosen-container-active");
|
704 |
+
this.active_field = true;
|
705 |
+
this.search_field.val(this.search_field.val());
|
706 |
+
return this.search_field.focus();
|
707 |
+
};
|
708 |
+
|
709 |
+
Chosen.prototype.test_active_click = function(evt) {
|
710 |
+
if (this.container.is($(evt.target).closest('.chosen-container'))) {
|
711 |
+
return this.active_field = true;
|
712 |
+
} else {
|
713 |
+
return this.close_field();
|
714 |
+
}
|
715 |
+
};
|
716 |
+
|
717 |
+
Chosen.prototype.results_build = function() {
|
718 |
+
this.parsing = true;
|
719 |
+
this.selected_option_count = null;
|
720 |
+
this.results_data = SelectParser.select_to_array(this.form_field);
|
721 |
+
if (this.is_multiple) {
|
722 |
+
this.search_choices.find("li.search-choice").remove();
|
723 |
+
} else if (!this.is_multiple) {
|
724 |
+
this.single_set_selected_text();
|
725 |
+
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
|
726 |
+
this.search_field[0].readOnly = true;
|
727 |
+
this.container.addClass("chosen-container-single-nosearch");
|
728 |
+
} else {
|
729 |
+
this.search_field[0].readOnly = false;
|
730 |
+
this.container.removeClass("chosen-container-single-nosearch");
|
731 |
+
}
|
732 |
+
}
|
733 |
+
this.update_results_content(this.results_option_build({
|
734 |
+
first: true
|
735 |
+
}));
|
736 |
+
this.search_field_disabled();
|
737 |
+
this.show_search_field_default();
|
738 |
+
this.search_field_scale();
|
739 |
+
return this.parsing = false;
|
740 |
+
};
|
741 |
+
|
742 |
+
Chosen.prototype.result_do_highlight = function(el) {
|
743 |
+
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
|
744 |
+
|
745 |
+
if (el.length) {
|
746 |
+
this.result_clear_highlight();
|
747 |
+
this.result_highlight = el;
|
748 |
+
this.result_highlight.addClass("highlighted");
|
749 |
+
maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
|
750 |
+
visible_top = this.search_results.scrollTop();
|
751 |
+
visible_bottom = maxHeight + visible_top;
|
752 |
+
high_top = this.result_highlight.position().top + this.search_results.scrollTop();
|
753 |
+
high_bottom = high_top + this.result_highlight.outerHeight();
|
754 |
+
if (high_bottom >= visible_bottom) {
|
755 |
+
return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
|
756 |
+
} else if (high_top < visible_top) {
|
757 |
+
return this.search_results.scrollTop(high_top);
|
758 |
+
}
|
759 |
+
}
|
760 |
+
};
|
761 |
+
|
762 |
+
Chosen.prototype.result_clear_highlight = function() {
|
763 |
+
if (this.result_highlight) {
|
764 |
+
this.result_highlight.removeClass("highlighted");
|
765 |
+
}
|
766 |
+
return this.result_highlight = null;
|
767 |
+
};
|
768 |
+
|
769 |
+
Chosen.prototype.results_show = function() {
|
770 |
+
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
|
771 |
+
this.form_field_jq.trigger("chosen:maxselected", {
|
772 |
+
chosen: this
|
773 |
+
});
|
774 |
+
return false;
|
775 |
+
}
|
776 |
+
this.container.addClass("chosen-with-drop");
|
777 |
+
this.form_field_jq.trigger("chosen:showing_dropdown", {
|
778 |
+
chosen: this
|
779 |
+
});
|
780 |
+
this.results_showing = true;
|
781 |
+
this.search_field.focus();
|
782 |
+
this.search_field.val(this.search_field.val());
|
783 |
+
return this.winnow_results();
|
784 |
+
};
|
785 |
+
|
786 |
+
Chosen.prototype.update_results_content = function(content) {
|
787 |
+
return this.search_results.html(content);
|
788 |
+
};
|
789 |
+
|
790 |
+
Chosen.prototype.results_hide = function() {
|
791 |
+
if (this.results_showing) {
|
792 |
+
this.result_clear_highlight();
|
793 |
+
this.container.removeClass("chosen-with-drop");
|
794 |
+
this.form_field_jq.trigger("chosen:hiding_dropdown", {
|
795 |
+
chosen: this
|
796 |
+
});
|
797 |
+
}
|
798 |
+
return this.results_showing = false;
|
799 |
+
};
|
800 |
+
|
801 |
+
Chosen.prototype.set_tab_index = function(el) {
|
802 |
+
var ti;
|
803 |
+
|
804 |
+
if (this.form_field.tabIndex) {
|
805 |
+
ti = this.form_field.tabIndex;
|
806 |
+
this.form_field.tabIndex = -1;
|
807 |
+
return this.search_field[0].tabIndex = ti;
|
808 |
+
}
|
809 |
+
};
|
810 |
+
|
811 |
+
Chosen.prototype.set_label_behavior = function() {
|
812 |
+
var _this = this;
|
813 |
+
|
814 |
+
this.form_field_label = this.form_field_jq.parents("label");
|
815 |
+
if (!this.form_field_label.length && this.form_field.id.length) {
|
816 |
+
this.form_field_label = $("label[for='" + this.form_field.id + "']");
|
817 |
+
}
|
818 |
+
if (this.form_field_label.length > 0) {
|
819 |
+
return this.form_field_label.bind('click.chosen', function(evt) {
|
820 |
+
if (_this.is_multiple) {
|
821 |
+
return _this.container_mousedown(evt);
|
822 |
+
} else {
|
823 |
+
return _this.activate_field();
|
824 |
+
}
|
825 |
+
});
|
826 |
+
}
|
827 |
+
};
|
828 |
+
|
829 |
+
Chosen.prototype.show_search_field_default = function() {
|
830 |
+
if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
|
831 |
+
this.search_field.val(this.default_text);
|
832 |
+
return this.search_field.addClass("default");
|
833 |
+
} else {
|
834 |
+
this.search_field.val("");
|
835 |
+
return this.search_field.removeClass("default");
|
836 |
+
}
|
837 |
+
};
|
838 |
+
|
839 |
+
Chosen.prototype.search_results_mouseup = function(evt) {
|
840 |
+
var target;
|
841 |
+
|
842 |
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
843 |
+
if (target.length) {
|
844 |
+
this.result_highlight = target;
|
845 |
+
this.result_select(evt);
|
846 |
+
return this.search_field.focus();
|
847 |
+
}
|
848 |
+
};
|
849 |
+
|
850 |
+
Chosen.prototype.search_results_mouseover = function(evt) {
|
851 |
+
var target;
|
852 |
+
|
853 |
+
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
|
854 |
+
if (target) {
|
855 |
+
return this.result_do_highlight(target);
|
856 |
+
}
|
857 |
+
};
|
858 |
+
|
859 |
+
Chosen.prototype.search_results_mouseout = function(evt) {
|
860 |
+
if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
|
861 |
+
return this.result_clear_highlight();
|
862 |
+
}
|
863 |
+
};
|
864 |
+
|
865 |
+
Chosen.prototype.choice_build = function(item) {
|
866 |
+
var choice, close_link,
|
867 |
+
_this = this;
|
868 |
+
|
869 |
+
choice = $('<li />', {
|
870 |
+
"class": "search-choice"
|
871 |
+
}).html("<span>" + item.html + "</span>");
|
872 |
+
if (item.disabled) {
|
873 |
+
choice.addClass('search-choice-disabled');
|
874 |
+
} else {
|
875 |
+
close_link = $('<a />', {
|
876 |
+
"class": 'search-choice-close',
|
877 |
+
'data-option-array-index': item.array_index
|
878 |
+
});
|
879 |
+
close_link.bind('click.chosen', function(evt) {
|
880 |
+
return _this.choice_destroy_link_click(evt);
|
881 |
+
});
|
882 |
+
choice.append(close_link);
|
883 |
+
}
|
884 |
+
return this.search_container.before(choice);
|
885 |
+
};
|
886 |
+
|
887 |
+
Chosen.prototype.choice_destroy_link_click = function(evt) {
|
888 |
+
evt.preventDefault();
|
889 |
+
evt.stopPropagation();
|
890 |
+
if (!this.is_disabled) {
|
891 |
+
return this.choice_destroy($(evt.target));
|
892 |
+
}
|
893 |
+
};
|
894 |
+
|
895 |
+
Chosen.prototype.choice_destroy = function(link) {
|
896 |
+
if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
|
897 |
+
this.show_search_field_default();
|
898 |
+
if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
|
899 |
+
this.results_hide();
|
900 |
+
}
|
901 |
+
link.parents('li').first().remove();
|
902 |
+
return this.search_field_scale();
|
903 |
+
}
|
904 |
+
};
|
905 |
+
|
906 |
+
Chosen.prototype.results_reset = function() {
|
907 |
+
this.form_field.options[0].selected = true;
|
908 |
+
this.selected_option_count = null;
|
909 |
+
this.single_set_selected_text();
|
910 |
+
this.show_search_field_default();
|
911 |
+
this.results_reset_cleanup();
|
912 |
+
this.form_field_jq.trigger("change");
|
913 |
+
if (this.active_field) {
|
914 |
+
return this.results_hide();
|
915 |
+
}
|
916 |
+
};
|
917 |
+
|
918 |
+
Chosen.prototype.results_reset_cleanup = function() {
|
919 |
+
this.current_selectedIndex = this.form_field.selectedIndex;
|
920 |
+
return this.selected_item.find("abbr").remove();
|
921 |
+
};
|
922 |
+
|
923 |
+
Chosen.prototype.result_select = function(evt) {
|
924 |
+
var high, item, selected_index;
|
925 |
+
|
926 |
+
if (this.result_highlight) {
|
927 |
+
high = this.result_highlight;
|
928 |
+
this.result_clear_highlight();
|
929 |
+
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
|
930 |
+
this.form_field_jq.trigger("chosen:maxselected", {
|
931 |
+
chosen: this
|
932 |
+
});
|
933 |
+
return false;
|
934 |
+
}
|
935 |
+
if (this.is_multiple) {
|
936 |
+
high.removeClass("active-result");
|
937 |
+
} else {
|
938 |
+
if (this.result_single_selected) {
|
939 |
+
this.result_single_selected.removeClass("result-selected");
|
940 |
+
selected_index = this.result_single_selected[0].getAttribute('data-option-array-index');
|
941 |
+
this.results_data[selected_index].selected = false;
|
942 |
+
}
|
943 |
+
this.result_single_selected = high;
|
944 |
+
}
|
945 |
+
high.addClass("result-selected");
|
946 |
+
item = this.results_data[high[0].getAttribute("data-option-array-index")];
|
947 |
+
item.selected = true;
|
948 |
+
this.form_field.options[item.options_index].selected = true;
|
949 |
+
this.selected_option_count = null;
|
950 |
+
if (this.is_multiple) {
|
951 |
+
this.choice_build(item);
|
952 |
+
} else {
|
953 |
+
this.single_set_selected_text(item.text);
|
954 |
+
}
|
955 |
+
if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) {
|
956 |
+
this.results_hide();
|
957 |
+
}
|
958 |
+
this.search_field.val("");
|
959 |
+
if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
|
960 |
+
this.form_field_jq.trigger("change", {
|
961 |
+
'selected': this.form_field.options[item.options_index].value
|
962 |
+
});
|
963 |
+
}
|
964 |
+
this.current_selectedIndex = this.form_field.selectedIndex;
|
965 |
+
return this.search_field_scale();
|
966 |
+
}
|
967 |
+
};
|
968 |
+
|
969 |
+
Chosen.prototype.single_set_selected_text = function(text) {
|
970 |
+
if (text == null) {
|
971 |
+
text = this.default_text;
|
972 |
+
}
|
973 |
+
if (text === this.default_text) {
|
974 |
+
this.selected_item.addClass("chosen-default");
|
975 |
+
} else {
|
976 |
+
this.single_deselect_control_build();
|
977 |
+
this.selected_item.removeClass("chosen-default");
|
978 |
+
}
|
979 |
+
return this.selected_item.find("span").text(text);
|
980 |
+
};
|
981 |
+
|
982 |
+
Chosen.prototype.result_deselect = function(pos) {
|
983 |
+
var result_data;
|
984 |
+
|
985 |
+
result_data = this.results_data[pos];
|
986 |
+
if (!this.form_field.options[result_data.options_index].disabled) {
|
987 |
+
result_data.selected = false;
|
988 |
+
this.form_field.options[result_data.options_index].selected = false;
|
989 |
+
this.selected_option_count = null;
|
990 |
+
this.result_clear_highlight();
|
991 |
+
if (this.results_showing) {
|
992 |
+
this.winnow_results();
|
993 |
+
}
|
994 |
+
this.form_field_jq.trigger("change", {
|
995 |
+
deselected: this.form_field.options[result_data.options_index].value
|
996 |
+
});
|
997 |
+
this.search_field_scale();
|
998 |
+
return true;
|
999 |
+
} else {
|
1000 |
+
return false;
|
1001 |
+
}
|
1002 |
+
};
|
1003 |
+
|
1004 |
+
Chosen.prototype.single_deselect_control_build = function() {
|
1005 |
+
if (!this.allow_single_deselect) {
|
1006 |
+
return;
|
1007 |
+
}
|
1008 |
+
if (!this.selected_item.find("abbr").length) {
|
1009 |
+
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
|
1010 |
+
}
|
1011 |
+
return this.selected_item.addClass("chosen-single-with-deselect");
|
1012 |
+
};
|
1013 |
+
|
1014 |
+
Chosen.prototype.get_search_text = function() {
|
1015 |
+
if (this.search_field.val() === this.default_text) {
|
1016 |
+
return "";
|
1017 |
+
} else {
|
1018 |
+
return $('<div/>').text($.trim(this.search_field.val())).html();
|
1019 |
+
}
|
1020 |
+
};
|
1021 |
+
|
1022 |
+
Chosen.prototype.winnow_results_set_highlight = function() {
|
1023 |
+
var do_high, selected_results;
|
1024 |
+
|
1025 |
+
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
|
1026 |
+
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
|
1027 |
+
if (do_high != null) {
|
1028 |
+
return this.result_do_highlight(do_high);
|
1029 |
+
}
|
1030 |
+
};
|
1031 |
+
|
1032 |
+
Chosen.prototype.no_results = function(terms) {
|
1033 |
+
var no_results_html;
|
1034 |
+
|
1035 |
+
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
|
1036 |
+
no_results_html.find("span").first().html(terms);
|
1037 |
+
return this.search_results.append(no_results_html);
|
1038 |
+
};
|
1039 |
+
|
1040 |
+
Chosen.prototype.no_results_clear = function() {
|
1041 |
+
return this.search_results.find(".no-results").remove();
|
1042 |
+
};
|
1043 |
+
|
1044 |
+
Chosen.prototype.keydown_arrow = function() {
|
1045 |
+
var next_sib;
|
1046 |
+
|
1047 |
+
if (this.results_showing && this.result_highlight) {
|
1048 |
+
next_sib = this.result_highlight.nextAll("li.active-result").first();
|
1049 |
+
if (next_sib) {
|
1050 |
+
return this.result_do_highlight(next_sib);
|
1051 |
+
}
|
1052 |
+
} else {
|
1053 |
+
return this.results_show();
|
1054 |
+
}
|
1055 |
+
};
|
1056 |
+
|
1057 |
+
Chosen.prototype.keyup_arrow = function() {
|
1058 |
+
var prev_sibs;
|
1059 |
+
|
1060 |
+
if (!this.results_showing && !this.is_multiple) {
|
1061 |
+
return this.results_show();
|
1062 |
+
} else if (this.result_highlight) {
|
1063 |
+
prev_sibs = this.result_highlight.prevAll("li.active-result");
|
1064 |
+
if (prev_sibs.length) {
|
1065 |
+
return this.result_do_highlight(prev_sibs.first());
|
1066 |
+
} else {
|
1067 |
+
if (this.choices_count() > 0) {
|
1068 |
+
this.results_hide();
|
1069 |
+
}
|
1070 |
+
return this.result_clear_highlight();
|
1071 |
+
}
|
1072 |
+
}
|
1073 |
+
};
|
1074 |
+
|
1075 |
+
Chosen.prototype.keydown_backstroke = function() {
|
1076 |
+
var next_available_destroy;
|
1077 |
+
|
1078 |
+
if (this.pending_backstroke) {
|
1079 |
+
this.choice_destroy(this.pending_backstroke.find("a").first());
|
1080 |
+
return this.clear_backstroke();
|
1081 |
+
} else {
|
1082 |
+
next_available_destroy = this.search_container.siblings("li.search-choice").last();
|
1083 |
+
if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
|
1084 |
+
this.pending_backstroke = next_available_destroy;
|
1085 |
+
if (this.single_backstroke_delete) {
|
1086 |
+
return this.keydown_backstroke();
|
1087 |
+
} else {
|
1088 |
+
return this.pending_backstroke.addClass("search-choice-focus");
|
1089 |
+
}
|
1090 |
+
}
|
1091 |
+
}
|
1092 |
+
};
|
1093 |
+
|
1094 |
+
Chosen.prototype.clear_backstroke = function() {
|
1095 |
+
if (this.pending_backstroke) {
|
1096 |
+
this.pending_backstroke.removeClass("search-choice-focus");
|
1097 |
+
}
|
1098 |
+
return this.pending_backstroke = null;
|
1099 |
+
};
|
1100 |
+
|
1101 |
+
Chosen.prototype.keydown_checker = function(evt) {
|
1102 |
+
var stroke, _ref1;
|
1103 |
+
|
1104 |
+
stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode;
|
1105 |
+
this.search_field_scale();
|
1106 |
+
if (stroke !== 8 && this.pending_backstroke) {
|
1107 |
+
this.clear_backstroke();
|
1108 |
+
}
|
1109 |
+
switch (stroke) {
|
1110 |
+
case 8:
|
1111 |
+
this.backstroke_length = this.search_field.val().length;
|
1112 |
+
break;
|
1113 |
+
case 9:
|
1114 |
+
if (this.results_showing && !this.is_multiple) {
|
1115 |
+
this.result_select(evt);
|
1116 |
+
}
|
1117 |
+
this.mouse_on_container = false;
|
1118 |
+
break;
|
1119 |
+
case 13:
|
1120 |
+
evt.preventDefault();
|
1121 |
+
break;
|
1122 |
+
case 38:
|
1123 |
+
evt.preventDefault();
|
1124 |
+
this.keyup_arrow();
|
1125 |
+
break;
|
1126 |
+
case 40:
|
1127 |
+
evt.preventDefault();
|
1128 |
+
this.keydown_arrow();
|
1129 |
+
break;
|
1130 |
+
}
|
1131 |
+
};
|
1132 |
+
|
1133 |
+
Chosen.prototype.search_field_scale = function() {
|
1134 |
+
var div, f_width, h, style, style_block, styles, w, _i, _len;
|
1135 |
+
|
1136 |
+
if (this.is_multiple) {
|
1137 |
+
h = 0;
|
1138 |
+
w = 0;
|
1139 |
+
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
|
1140 |
+
styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
|
1141 |
+
for (_i = 0, _len = styles.length; _i < _len; _i++) {
|
1142 |
+
style = styles[_i];
|
1143 |
+
style_block += style + ":" + this.search_field.css(style) + ";";
|
1144 |
+
}
|
1145 |
+
div = $('<div />', {
|
1146 |
+
'style': style_block
|
1147 |
+
});
|
1148 |
+
div.text(this.search_field.val());
|
1149 |
+
$('body').append(div);
|
1150 |
+
w = div.width() + 25;
|
1151 |
+
div.remove();
|
1152 |
+
f_width = this.container.outerWidth();
|
1153 |
+
if (w > f_width - 10) {
|
1154 |
+
w = f_width - 10;
|
1155 |
+
}
|
1156 |
+
return this.search_field.css({
|
1157 |
+
'width': w + 'px'
|
1158 |
+
});
|
1159 |
+
}
|
1160 |
+
};
|
1161 |
+
|
1162 |
+
return Chosen;
|
1163 |
+
|
1164 |
+
})(AbstractChosen);
|
1165 |
+
|
1166 |
+
}).call(this);
|
js/chosen/chosen.jquery.min.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
/* Chosen v1.0.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
|
2 |
+
!function(){var a,AbstractChosen,Chosen,SelectParser,b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),children:0,disabled:a.disabled}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},SelectParser.prototype.escapeExpression=function(a){var b,c;return null==a||a===!1?"":/[\&\<\>\"\'\`]/.test(a)?(b={"<":"<",">":">",'"':""","'":"'","`":"`"},c=/&(?!\w+;)|[\<\>\"\'\`]/g,a.replace(c,function(a){return b[a]||"&"})):a},SelectParser}(),SelectParser.select_to_array=function(a){var b,c,d,e,f;for(c=new SelectParser,f=a.childNodes,d=0,e=f.length;e>d;d++)b=f[d],c.add_node(b);return c.parsed},AbstractChosen=function(){function AbstractChosen(a,b){this.form_field=a,this.options=null!=b?b:{},AbstractChosen.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers())}return AbstractChosen.prototype.set_default_values=function(){var a=this;return this.click_test_action=function(b){return a.test_active_click(b)},this.activate_action=function(b){return a.activate_field(b)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0},AbstractChosen.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||AbstractChosen.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||AbstractChosen.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||AbstractChosen.default_no_result_text},AbstractChosen.prototype.mouse_enter=function(){return this.mouse_on_container=!0},AbstractChosen.prototype.mouse_leave=function(){return this.mouse_on_container=!1},AbstractChosen.prototype.input_focus=function(){var a=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return a.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},AbstractChosen.prototype.input_blur=function(){var a=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return a.blur_test()},100))},AbstractChosen.prototype.results_option_build=function(a){var b,c,d,e,f;for(b="",f=this.results_data,d=0,e=f.length;e>d;d++)c=f[d],b+=c.group?this.result_add_group(c):this.result_add_option(c),(null!=a?a.first:void 0)&&(c.selected&&this.is_multiple?this.choice_build(c):c.selected&&!this.is_multiple&&this.single_set_selected_text(c.text));return b},AbstractChosen.prototype.result_add_option=function(a){var b,c;return a.search_match?this.include_option_in_results(a)?(b=[],a.disabled||a.selected&&this.is_multiple||b.push("active-result"),!a.disabled||a.selected&&this.is_multiple||b.push("disabled-result"),a.selected&&b.push("result-selected"),null!=a.group_array_index&&b.push("group-option"),""!==a.classes&&b.push(a.classes),c=""!==a.style.cssText?' style="'+a.style+'"':"",'<li class="'+b.join(" ")+'"'+c+' data-option-array-index="'+a.array_index+'">'+a.search_text+"</li>"):"":""},AbstractChosen.prototype.result_add_group=function(a){return a.search_match||a.group_match?a.active_options>0?'<li class="group-result">'+a.search_text+"</li>":"":""},AbstractChosen.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.result_single_selected=null,this.results_build(),this.results_showing?this.winnow_results():void 0},AbstractChosen.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},AbstractChosen.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},AbstractChosen.prototype.winnow_results=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m;for(this.no_results_clear(),e=0,g=this.get_search_text(),a=g.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),d=this.search_contains?"":"^",c=new RegExp(d+a,"i"),j=new RegExp(a,"i"),m=this.results_data,k=0,l=m.length;l>k;k++)b=m[k],b.search_match=!1,f=null,this.include_option_in_results(b)&&(b.group&&(b.group_match=!1,b.active_options=0),null!=b.group_array_index&&this.results_data[b.group_array_index]&&(f=this.results_data[b.group_array_index],0===f.active_options&&f.search_match&&(e+=1),f.active_options+=1),(!b.group||this.group_search)&&(b.search_text=b.group?b.label:b.html,b.search_match=this.search_string_match(b.search_text,c),b.search_match&&!b.group&&(e+=1),b.search_match?(g.length&&(h=b.search_text.search(j),i=b.search_text.substr(0,h+g.length)+"</em>"+b.search_text.substr(h+g.length),b.search_text=i.substr(0,h)+"<em>"+i.substr(h)),null!=f&&(f.group_match=!0)):null!=b.group_array_index&&this.results_data[b.group_array_index].search_match&&(b.search_match=!0)));return this.result_clear_highlight(),1>e&&g.length?(this.update_results_content(""),this.no_results(g)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},AbstractChosen.prototype.search_string_match=function(a,b){var c,d,e,f;if(b.test(a))return!0;if(this.enable_split_word_search&&(a.indexOf(" ")>=0||0===a.indexOf("["))&&(d=a.replace(/\[|\]/g,"").split(" "),d.length))for(e=0,f=d.length;f>e;e++)if(c=d[e],b.test(c))return!0},AbstractChosen.prototype.choices_count=function(){var a,b,c,d;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,d=this.form_field.options,b=0,c=d.length;c>b;b++)a=d[b],a.selected&&(this.selected_option_count+=1);return this.selected_option_count},AbstractChosen.prototype.choices_click=function(a){return a.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},AbstractChosen.prototype.keyup_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(a.preventDefault(),this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},AbstractChosen.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},AbstractChosen.prototype.include_option_in_results=function(a){return this.is_multiple&&!this.display_selected_options&&a.selected?!1:!this.display_disabled_options&&a.disabled?!1:a.empty?!1:!0},AbstractChosen.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)?!1:/Android/i.test(window.navigator.userAgent)&&/Mobile/i.test(window.navigator.userAgent)?!1:!0},AbstractChosen.default_multiple_text="Select Some Options",AbstractChosen.default_single_text="Select an Option",AbstractChosen.default_no_result_text="No results match",AbstractChosen}(),a=jQuery,a.fn.extend({chosen:function(b){return AbstractChosen.browser_is_supported()?this.each(function(){var c,d;c=a(this),d=c.data("chosen"),"destroy"===b&&d?d.destroy():d||c.data("chosen",new Chosen(this,b))}):this}}),Chosen=function(c){function Chosen(){return b=Chosen.__super__.constructor.apply(this,arguments)}return d(Chosen,c),Chosen.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},Chosen.prototype.set_up_html=function(){var b,c;return b=["chosen-container"],b.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&b.push(this.form_field.className),this.is_rtl&&b.push("chosen-rtl"),c={"class":b.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(c.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=a("<div />",c),this.is_multiple?this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'):this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("chosen:ready",{chosen:this})},Chosen.prototype.register_observers=function(){var a=this;return this.container.bind("mousedown.chosen",function(b){a.container_mousedown(b)}),this.container.bind("mouseup.chosen",function(b){a.container_mouseup(b)}),this.container.bind("mouseenter.chosen",function(b){a.mouse_enter(b)}),this.container.bind("mouseleave.chosen",function(b){a.mouse_leave(b)}),this.search_results.bind("mouseup.chosen",function(b){a.search_results_mouseup(b)}),this.search_results.bind("mouseover.chosen",function(b){a.search_results_mouseover(b)}),this.search_results.bind("mouseout.chosen",function(b){a.search_results_mouseout(b)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(b){a.search_results_mousewheel(b)}),this.form_field_jq.bind("chosen:updated.chosen",function(b){a.results_update_field(b)}),this.form_field_jq.bind("chosen:activate.chosen",function(b){a.activate_field(b)}),this.form_field_jq.bind("chosen:open.chosen",function(b){a.container_mousedown(b)}),this.search_field.bind("blur.chosen",function(b){a.input_blur(b)}),this.search_field.bind("keyup.chosen",function(b){a.keyup_checker(b)}),this.search_field.bind("keydown.chosen",function(b){a.keydown_checker(b)}),this.search_field.bind("focus.chosen",function(b){a.input_focus(b)}),this.is_multiple?this.search_choices.bind("click.chosen",function(b){a.choices_click(b)}):this.container.bind("click.chosen",function(a){a.preventDefault()})},Chosen.prototype.destroy=function(){return a(document).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},Chosen.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},Chosen.prototype.container_mousedown=function(b){return this.is_disabled||(b&&"mousedown"===b.type&&!this.results_showing&&b.preventDefault(),null!=b&&a(b.target).hasClass("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!b||a(b.target)[0]!==this.selected_item[0]&&!a(b.target).parents("a.chosen-single").length||(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},Chosen.prototype.container_mouseup=function(a){return"ABBR"!==a.target.nodeName||this.is_disabled?void 0:this.results_reset(a)},Chosen.prototype.search_results_mousewheel=function(a){var b,c,d;return b=-(null!=(c=a.originalEvent)?c.wheelDelta:void 0)||(null!=(d=a.originialEvent)?d.detail:void 0),null!=b?(a.preventDefault(),"DOMMouseScroll"===a.type&&(b=40*b),this.search_results.scrollTop(b+this.search_results.scrollTop())):void 0},Chosen.prototype.blur_test=function(){return!this.active_field&&this.container.hasClass("chosen-container-active")?this.close_field():void 0},Chosen.prototype.close_field=function(){return a(document).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},Chosen.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},Chosen.prototype.test_active_click=function(b){return this.container.is(a(b.target).closest(".chosen-container"))?this.active_field=!0:this.close_field()},Chosen.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=SelectParser.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},Chosen.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){if(this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight(),b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(f>c)return this.search_results.scrollTop(c)}},Chosen.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},Chosen.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results())},Chosen.prototype.update_results_content=function(a){return this.search_results.html(a)},Chosen.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},Chosen.prototype.set_tab_index=function(){var a;return this.form_field.tabIndex?(a=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=a):void 0},Chosen.prototype.set_label_behavior=function(){var b=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=a("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(a){return b.is_multiple?b.container_mousedown(a):b.activate_field()}):void 0},Chosen.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},Chosen.prototype.search_results_mouseup=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c.length?(this.result_highlight=c,this.result_select(b),this.search_field.focus()):void 0},Chosen.prototype.search_results_mouseover=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c?this.result_do_highlight(c):void 0},Chosen.prototype.search_results_mouseout=function(b){return a(b.target).hasClass("active-result")?this.result_clear_highlight():void 0},Chosen.prototype.choice_build=function(b){var c,d,e=this;return c=a("<li />",{"class":"search-choice"}).html("<span>"+b.html+"</span>"),b.disabled?c.addClass("search-choice-disabled"):(d=a("<a />",{"class":"search-choice-close","data-option-array-index":b.array_index}),d.bind("click.chosen",function(a){return e.choice_destroy_link_click(a)}),c.append(d)),this.search_container.before(c)},Chosen.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),b.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(a(b.target))},Chosen.prototype.choice_destroy=function(a){return this.result_deselect(a[0].getAttribute("data-option-array-index"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),a.parents("li").first().remove(),this.search_field_scale()):void 0},Chosen.prototype.results_reset=function(){return this.form_field.options[0].selected=!0,this.selected_option_count=null,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},Chosen.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},Chosen.prototype.result_select=function(a){var b,c,d;return this.result_highlight?(b=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?b.removeClass("active-result"):(this.result_single_selected&&(this.result_single_selected.removeClass("result-selected"),d=this.result_single_selected[0].getAttribute("data-option-array-index"),this.results_data[d].selected=!1),this.result_single_selected=b),b.addClass("result-selected"),c=this.results_data[b[0].getAttribute("data-option-array-index")],c.selected=!0,this.form_field.options[c.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(c):this.single_set_selected_text(c.text),(a.metaKey||a.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[c.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())):void 0},Chosen.prototype.single_set_selected_text=function(a){return null==a&&(a=this.default_text),a===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").text(a)},Chosen.prototype.result_deselect=function(a){var b;return b=this.results_data[a],this.form_field.options[b.options_index].disabled?!1:(b.selected=!1,this.form_field.options[b.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[b.options_index].value}),this.search_field_scale(),!0)},Chosen.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>'),this.selected_item.addClass("chosen-single-with-deselect")):void 0},Chosen.prototype.get_search_text=function(){return this.search_field.val()===this.default_text?"":a("<div/>").text(a.trim(this.search_field.val())).html()},Chosen.prototype.winnow_results_set_highlight=function(){var a,b;return b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first(),null!=a?this.result_do_highlight(a):void 0},Chosen.prototype.no_results=function(b){var c;return c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b),this.search_results.append(c)},Chosen.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},Chosen.prototype.keydown_arrow=function(){var a;return this.results_showing&&this.result_highlight?(a=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(a):void 0:this.results_show()},Chosen.prototype.keyup_arrow=function(){var a;return this.results_showing||this.is_multiple?this.result_highlight?(a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},Chosen.prototype.keydown_backstroke=function(){var a;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(a=this.search_container.siblings("li.search-choice").last(),a.length&&!a.hasClass("search-choice-disabled")?(this.pending_backstroke=a,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},Chosen.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},Chosen.prototype.keydown_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),8!==b&&this.pending_backstroke&&this.clear_backstroke(),b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:a.preventDefault(),this.keydown_arrow()}},Chosen.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){for(d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],i=0,j=g.length;j>i;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return b=a("<div />",{style:f}),b.text(this.search_field.val()),a("body").append(b),h=b.width()+25,b.remove(),c=this.container.outerWidth(),h>c-10&&(h=c-10),this.search_field.css({width:h+"px"})}},Chosen}(AbstractChosen)}.call(this);
|
js/selectize/selectize.js
ADDED
@@ -0,0 +1,3038 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* sifter.js
|
3 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
4 |
+
*
|
5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
6 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
7 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
*
|
9 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
10 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
12 |
+
* governing permissions and limitations under the License.
|
13 |
+
*
|
14 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
15 |
+
*/
|
16 |
+
|
17 |
+
(function(root, factory) {
|
18 |
+
if (typeof define === 'function' && define.amd) {
|
19 |
+
define(factory);
|
20 |
+
} else if (typeof exports === 'object') {
|
21 |
+
module.exports = factory();
|
22 |
+
} else {
|
23 |
+
root.Sifter = factory();
|
24 |
+
}
|
25 |
+
}(this, function() {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Textually searches arrays and hashes of objects
|
29 |
+
* by property (or multiple properties). Designed
|
30 |
+
* specifically for autocomplete.
|
31 |
+
*
|
32 |
+
* @constructor
|
33 |
+
* @param {array|object} items
|
34 |
+
* @param {object} items
|
35 |
+
*/
|
36 |
+
var Sifter = function(items, settings) {
|
37 |
+
this.items = items;
|
38 |
+
this.settings = settings || {diacritics: true};
|
39 |
+
};
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Splits a search string into an array of individual
|
43 |
+
* regexps to be used to match results.
|
44 |
+
*
|
45 |
+
* @param {string} query
|
46 |
+
* @returns {array}
|
47 |
+
*/
|
48 |
+
Sifter.prototype.tokenize = function(query) {
|
49 |
+
query = trim(String(query || '').toLowerCase());
|
50 |
+
if (!query || !query.length) return [];
|
51 |
+
|
52 |
+
var i, n, regex, letter;
|
53 |
+
var tokens = [];
|
54 |
+
var words = query.split(/ +/);
|
55 |
+
|
56 |
+
for (i = 0, n = words.length; i < n; i++) {
|
57 |
+
regex = escape_regex(words[i]);
|
58 |
+
if (this.settings.diacritics) {
|
59 |
+
for (letter in DIACRITICS) {
|
60 |
+
if (DIACRITICS.hasOwnProperty(letter)) {
|
61 |
+
regex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]);
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
tokens.push({
|
66 |
+
string : words[i],
|
67 |
+
regex : new RegExp(regex, 'i')
|
68 |
+
});
|
69 |
+
}
|
70 |
+
|
71 |
+
return tokens;
|
72 |
+
};
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Iterates over arrays and hashes.
|
76 |
+
*
|
77 |
+
* ```
|
78 |
+
* this.iterator(this.items, function(item, id) {
|
79 |
+
* // invoked for each item
|
80 |
+
* });
|
81 |
+
* ```
|
82 |
+
*
|
83 |
+
* @param {array|object} object
|
84 |
+
*/
|
85 |
+
Sifter.prototype.iterator = function(object, callback) {
|
86 |
+
var iterator;
|
87 |
+
if (is_array(object)) {
|
88 |
+
iterator = Array.prototype.forEach || function(callback) {
|
89 |
+
for (var i = 0, n = this.length; i < n; i++) {
|
90 |
+
callback(this[i], i, this);
|
91 |
+
}
|
92 |
+
};
|
93 |
+
} else {
|
94 |
+
iterator = function(callback) {
|
95 |
+
for (var key in this) {
|
96 |
+
if (this.hasOwnProperty(key)) {
|
97 |
+
callback(this[key], key, this);
|
98 |
+
}
|
99 |
+
}
|
100 |
+
};
|
101 |
+
}
|
102 |
+
|
103 |
+
iterator.apply(object, [callback]);
|
104 |
+
};
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Returns a function to be used to score individual results.
|
108 |
+
*
|
109 |
+
* Good matches will have a higher score than poor matches.
|
110 |
+
* If an item is not a match, 0 will be returned by the function.
|
111 |
+
*
|
112 |
+
* @param {object|string} search
|
113 |
+
* @param {object} options (optional)
|
114 |
+
* @returns {function}
|
115 |
+
*/
|
116 |
+
Sifter.prototype.getScoreFunction = function(search, options) {
|
117 |
+
var self, fields, tokens, token_count;
|
118 |
+
|
119 |
+
self = this;
|
120 |
+
search = self.prepareSearch(search, options);
|
121 |
+
tokens = search.tokens;
|
122 |
+
fields = search.options.fields;
|
123 |
+
token_count = tokens.length;
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Calculates how close of a match the
|
127 |
+
* given value is against a search token.
|
128 |
+
*
|
129 |
+
* @param {mixed} value
|
130 |
+
* @param {object} token
|
131 |
+
* @return {number}
|
132 |
+
*/
|
133 |
+
var scoreValue = function(value, token) {
|
134 |
+
var score, pos;
|
135 |
+
|
136 |
+
if (!value) return 0;
|
137 |
+
value = String(value || '');
|
138 |
+
pos = value.search(token.regex);
|
139 |
+
if (pos === -1) return 0;
|
140 |
+
score = token.string.length / value.length;
|
141 |
+
if (pos === 0) score += 0.5;
|
142 |
+
return score;
|
143 |
+
};
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Calculates the score of an object
|
147 |
+
* against the search query.
|
148 |
+
*
|
149 |
+
* @param {object} token
|
150 |
+
* @param {object} data
|
151 |
+
* @return {number}
|
152 |
+
*/
|
153 |
+
var scoreObject = (function() {
|
154 |
+
var field_count = fields.length;
|
155 |
+
if (!field_count) {
|
156 |
+
return function() { return 0; };
|
157 |
+
}
|
158 |
+
if (field_count === 1) {
|
159 |
+
return function(token, data) {
|
160 |
+
return scoreValue(data[fields[0]], token);
|
161 |
+
};
|
162 |
+
}
|
163 |
+
return function(token, data) {
|
164 |
+
for (var i = 0, sum = 0; i < field_count; i++) {
|
165 |
+
sum += scoreValue(data[fields[i]], token);
|
166 |
+
}
|
167 |
+
return sum / field_count;
|
168 |
+
};
|
169 |
+
})();
|
170 |
+
|
171 |
+
if (!token_count) {
|
172 |
+
return function() { return 0; };
|
173 |
+
}
|
174 |
+
if (token_count === 1) {
|
175 |
+
return function(data) {
|
176 |
+
return scoreObject(tokens[0], data);
|
177 |
+
};
|
178 |
+
}
|
179 |
+
return function(data) {
|
180 |
+
for (var i = 0, sum = 0; i < token_count; i++) {
|
181 |
+
sum += scoreObject(tokens[i], data);
|
182 |
+
}
|
183 |
+
return sum / token_count;
|
184 |
+
};
|
185 |
+
};
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Parses a search query and returns an object
|
189 |
+
* with tokens and fields ready to be populated
|
190 |
+
* with results.
|
191 |
+
*
|
192 |
+
* @param {string} query
|
193 |
+
* @param {object} options
|
194 |
+
* @returns {object}
|
195 |
+
*/
|
196 |
+
Sifter.prototype.prepareSearch = function(query, options) {
|
197 |
+
if (typeof query === 'object') return query;
|
198 |
+
return {
|
199 |
+
options : extend({}, options),
|
200 |
+
query : String(query || '').toLowerCase(),
|
201 |
+
tokens : this.tokenize(query),
|
202 |
+
total : 0,
|
203 |
+
items : []
|
204 |
+
};
|
205 |
+
};
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Searches through all items and returns a sorted array of matches.
|
209 |
+
*
|
210 |
+
* The `options` parameter can contain:
|
211 |
+
*
|
212 |
+
* - fields {string|array}
|
213 |
+
* - sort {string}
|
214 |
+
* - direction {string}
|
215 |
+
* - score {function}
|
216 |
+
* - limit {integer}
|
217 |
+
*
|
218 |
+
* Returns an object containing:
|
219 |
+
*
|
220 |
+
* - options {object}
|
221 |
+
* - query {string}
|
222 |
+
* - tokens {array}
|
223 |
+
* - total {int}
|
224 |
+
* - items {array}
|
225 |
+
*
|
226 |
+
* @param {string} query
|
227 |
+
* @param {object} options
|
228 |
+
* @returns {object}
|
229 |
+
*/
|
230 |
+
Sifter.prototype.search = function(query, options) {
|
231 |
+
var self = this, value, score, search, calculateScore;
|
232 |
+
|
233 |
+
search = this.prepareSearch(query, options);
|
234 |
+
options = search.options;
|
235 |
+
query = search.query;
|
236 |
+
|
237 |
+
// generate result scoring function
|
238 |
+
if (!is_array(options.fields)) options.fields = [options.fields];
|
239 |
+
calculateScore = options.score || self.getScoreFunction(search);
|
240 |
+
|
241 |
+
// perform search and sort
|
242 |
+
if (query.length) {
|
243 |
+
self.iterator(self.items, function(item, id) {
|
244 |
+
score = calculateScore(item);
|
245 |
+
if (score > 0) {
|
246 |
+
search.items.push({'score': score, 'id': id});
|
247 |
+
}
|
248 |
+
});
|
249 |
+
search.items.sort(function(a, b) {
|
250 |
+
return b.score - a.score;
|
251 |
+
});
|
252 |
+
} else {
|
253 |
+
self.iterator(self.items, function(item, id) {
|
254 |
+
search.items.push({'score': 1, 'id': id});
|
255 |
+
});
|
256 |
+
if (options.sort) {
|
257 |
+
search.items.sort((function() {
|
258 |
+
var field = options.sort;
|
259 |
+
var multiplier = options.direction === 'desc' ? -1 : 1;
|
260 |
+
return function(a, b) {
|
261 |
+
return cmp(self.items[a.id][field], self.items[b.id][field]) * multiplier;
|
262 |
+
};
|
263 |
+
})());
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
// apply limits
|
268 |
+
search.total = search.items.length;
|
269 |
+
if (typeof options.limit === 'number') {
|
270 |
+
search.items = search.items.slice(0, options.limit);
|
271 |
+
}
|
272 |
+
|
273 |
+
return search;
|
274 |
+
};
|
275 |
+
|
276 |
+
// utilities
|
277 |
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
278 |
+
|
279 |
+
var cmp = function(a, b) {
|
280 |
+
if (typeof a === 'number' && typeof b === 'number') {
|
281 |
+
return a > b ? 1 : (a < b ? -1 : 0);
|
282 |
+
}
|
283 |
+
a = String(a || '').toLowerCase();
|
284 |
+
b = String(b || '').toLowerCase();
|
285 |
+
if (a > b) return 1;
|
286 |
+
if (b > a) return -1;
|
287 |
+
return 0;
|
288 |
+
};
|
289 |
+
|
290 |
+
var extend = function(a, b) {
|
291 |
+
var i, n, k, object;
|
292 |
+
for (i = 1, n = arguments.length; i < n; i++) {
|
293 |
+
object = arguments[i];
|
294 |
+
if (!object) continue;
|
295 |
+
for (k in object) {
|
296 |
+
if (object.hasOwnProperty(k)) {
|
297 |
+
a[k] = object[k];
|
298 |
+
}
|
299 |
+
}
|
300 |
+
}
|
301 |
+
return a;
|
302 |
+
};
|
303 |
+
|
304 |
+
var trim = function(str) {
|
305 |
+
return (str + '').replace(/^\s+|\s+$|/g, '');
|
306 |
+
};
|
307 |
+
|
308 |
+
var escape_regex = function(str) {
|
309 |
+
return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
|
310 |
+
};
|
311 |
+
|
312 |
+
var is_array = Array.isArray || ($ && $.isArray) || function(object) {
|
313 |
+
return Object.prototype.toString.call(object) === '[object Array]';
|
314 |
+
};
|
315 |
+
|
316 |
+
var DIACRITICS = {
|
317 |
+
'a': '[aÀÁÂÃÄÅàáâãäå]',
|
318 |
+
'c': '[cÇç]',
|
319 |
+
'e': '[eÈÉÊËèéêë]',
|
320 |
+
'i': '[iÌÍÎÏìíîï]',
|
321 |
+
'n': '[nÑñ]',
|
322 |
+
'o': '[oÒÓÔÕÕÖØòóôõöø]',
|
323 |
+
's': '[sŠš]',
|
324 |
+
'u': '[uÙÚÛÜùúûü]',
|
325 |
+
'y': '[yŸÿý]',
|
326 |
+
'z': '[zŽž]'
|
327 |
+
};
|
328 |
+
|
329 |
+
// export
|
330 |
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
331 |
+
|
332 |
+
return Sifter;
|
333 |
+
|
334 |
+
}));
|
335 |
+
|
336 |
+
/**
|
337 |
+
* microplugin.js
|
338 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
339 |
+
*
|
340 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
341 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
342 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
343 |
+
*
|
344 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
345 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
346 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
347 |
+
* governing permissions and limitations under the License.
|
348 |
+
*
|
349 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
350 |
+
*/
|
351 |
+
|
352 |
+
(function(root, factory) {
|
353 |
+
if (typeof define === 'function' && define.amd) {
|
354 |
+
define(factory);
|
355 |
+
} else if (typeof exports === 'object') {
|
356 |
+
module.exports = factory();
|
357 |
+
} else {
|
358 |
+
root.MicroPlugin = factory();
|
359 |
+
}
|
360 |
+
}(this, function() {
|
361 |
+
var MicroPlugin = {};
|
362 |
+
|
363 |
+
MicroPlugin.mixin = function(Interface) {
|
364 |
+
Interface.plugins = {};
|
365 |
+
|
366 |
+
/**
|
367 |
+
* Initializes the listed plugins (with options).
|
368 |
+
* Acceptable formats:
|
369 |
+
*
|
370 |
+
* List (without options):
|
371 |
+
* ['a', 'b', 'c']
|
372 |
+
*
|
373 |
+
* List (with options):
|
374 |
+
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
|
375 |
+
*
|
376 |
+
* Hash (with options):
|
377 |
+
* {'a': { ... }, 'b': { ... }, 'c': { ... }}
|
378 |
+
*
|
379 |
+
* @param {mixed} plugins
|
380 |
+
*/
|
381 |
+
Interface.prototype.initializePlugins = function(plugins) {
|
382 |
+
var i, n, key;
|
383 |
+
var self = this;
|
384 |
+
var queue = [];
|
385 |
+
|
386 |
+
self.plugins = {
|
387 |
+
names : [],
|
388 |
+
settings : {},
|
389 |
+
requested : {},
|
390 |
+
loaded : {}
|
391 |
+
};
|
392 |
+
|
393 |
+
if (utils.isArray(plugins)) {
|
394 |
+
for (i = 0, n = plugins.length; i < n; i++) {
|
395 |
+
if (typeof plugins[i] === 'string') {
|
396 |
+
queue.push(plugins[i]);
|
397 |
+
} else {
|
398 |
+
self.plugins.settings[plugins[i].name] = plugins[i].options;
|
399 |
+
queue.push(plugins[i].name);
|
400 |
+
}
|
401 |
+
}
|
402 |
+
} else if (plugins) {
|
403 |
+
for (key in plugins) {
|
404 |
+
if (plugins.hasOwnProperty(key)) {
|
405 |
+
self.plugins.settings[key] = plugins[key];
|
406 |
+
queue.push(key);
|
407 |
+
}
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
while (queue.length) {
|
412 |
+
self.require(queue.shift());
|
413 |
+
}
|
414 |
+
};
|
415 |
+
|
416 |
+
Interface.prototype.loadPlugin = function(name) {
|
417 |
+
var self = this;
|
418 |
+
var plugins = self.plugins;
|
419 |
+
var plugin = Interface.plugins[name];
|
420 |
+
|
421 |
+
if (!Interface.plugins.hasOwnProperty(name)) {
|
422 |
+
throw new Error('Unable to find "' + name + '" plugin');
|
423 |
+
}
|
424 |
+
|
425 |
+
plugins.requested[name] = true;
|
426 |
+
plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);
|
427 |
+
plugins.names.push(name);
|
428 |
+
};
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Initializes a plugin.
|
432 |
+
*
|
433 |
+
* @param {string} name
|
434 |
+
*/
|
435 |
+
Interface.prototype.require = function(name) {
|
436 |
+
var self = this;
|
437 |
+
var plugins = self.plugins;
|
438 |
+
|
439 |
+
if (!self.plugins.loaded.hasOwnProperty(name)) {
|
440 |
+
if (plugins.requested[name]) {
|
441 |
+
throw new Error('Plugin has circular dependency ("' + name + '")');
|
442 |
+
}
|
443 |
+
self.loadPlugin(name);
|
444 |
+
}
|
445 |
+
|
446 |
+
return plugins.loaded[name];
|
447 |
+
};
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Registers a plugin.
|
451 |
+
*
|
452 |
+
* @param {string} name
|
453 |
+
* @param {function} fn
|
454 |
+
*/
|
455 |
+
Interface.define = function(name, fn) {
|
456 |
+
Interface.plugins[name] = {
|
457 |
+
'name' : name,
|
458 |
+
'fn' : fn
|
459 |
+
};
|
460 |
+
};
|
461 |
+
};
|
462 |
+
|
463 |
+
var utils = {
|
464 |
+
isArray: Array.isArray || function(vArg) {
|
465 |
+
return Object.prototype.toString.call(vArg) === '[object Array]';
|
466 |
+
}
|
467 |
+
};
|
468 |
+
|
469 |
+
return MicroPlugin;
|
470 |
+
}));
|
471 |
+
|
472 |
+
/**
|
473 |
+
* selectize.js (v0.7.7)
|
474 |
+
* Copyright (c) 2013 Brian Reavis & contributors
|
475 |
+
*
|
476 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
|
477 |
+
* file except in compliance with the License. You may obtain a copy of the License at:
|
478 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
479 |
+
*
|
480 |
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
481 |
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
482 |
+
* ANY KIND, either express or implied. See the License for the specific language
|
483 |
+
* governing permissions and limitations under the License.
|
484 |
+
*
|
485 |
+
* @author Brian Reavis <brian@thirdroute.com>
|
486 |
+
*/
|
487 |
+
|
488 |
+
/*jshint curly:false */
|
489 |
+
/*jshint browser:true */
|
490 |
+
|
491 |
+
(function(root, factory) {
|
492 |
+
if (typeof define === 'function' && define.amd) {
|
493 |
+
define(['jquery','sifter','microplugin'], factory);
|
494 |
+
} else {
|
495 |
+
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
|
496 |
+
}
|
497 |
+
}(this, function($, Sifter, MicroPlugin) {
|
498 |
+
'use strict';
|
499 |
+
|
500 |
+
var highlight = function($element, pattern) {
|
501 |
+
if (typeof pattern === 'string' && !pattern.length) return;
|
502 |
+
var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern;
|
503 |
+
|
504 |
+
var highlight = function(node) {
|
505 |
+
var skip = 0;
|
506 |
+
if (node.nodeType === 3) {
|
507 |
+
var pos = node.data.search(regex);
|
508 |
+
if (pos >= 0 && node.data.length > 0) {
|
509 |
+
var match = node.data.match(regex);
|
510 |
+
var spannode = document.createElement('span');
|
511 |
+
spannode.className = 'highlight';
|
512 |
+
var middlebit = node.splitText(pos);
|
513 |
+
var endbit = middlebit.splitText(match[0].length);
|
514 |
+
var middleclone = middlebit.cloneNode(true);
|
515 |
+
spannode.appendChild(middleclone);
|
516 |
+
middlebit.parentNode.replaceChild(spannode, middlebit);
|
517 |
+
skip = 1;
|
518 |
+
}
|
519 |
+
} else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
|
520 |
+
for (var i = 0; i < node.childNodes.length; ++i) {
|
521 |
+
i += highlight(node.childNodes[i]);
|
522 |
+
}
|
523 |
+
}
|
524 |
+
return skip;
|
525 |
+
};
|
526 |
+
|
527 |
+
return $element.each(function() {
|
528 |
+
highlight(this);
|
529 |
+
});
|
530 |
+
};
|
531 |
+
|
532 |
+
var MicroEvent = function() {};
|
533 |
+
MicroEvent.prototype = {
|
534 |
+
on: function(event, fct){
|
535 |
+
this._events = this._events || {};
|
536 |
+
this._events[event] = this._events[event] || [];
|
537 |
+
this._events[event].push(fct);
|
538 |
+
},
|
539 |
+
off: function(event, fct){
|
540 |
+
var n = arguments.length;
|
541 |
+
if (n === 0) return delete this._events;
|
542 |
+
if (n === 1) return delete this._events[event];
|
543 |
+
|
544 |
+
this._events = this._events || {};
|
545 |
+
if (event in this._events === false) return;
|
546 |
+
this._events[event].splice(this._events[event].indexOf(fct), 1);
|
547 |
+
},
|
548 |
+
trigger: function(event /* , args... */){
|
549 |
+
this._events = this._events || {};
|
550 |
+
if (event in this._events === false) return;
|
551 |
+
for (var i = 0; i < this._events[event].length; i++){
|
552 |
+
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
|
553 |
+
}
|
554 |
+
}
|
555 |
+
};
|
556 |
+
|
557 |
+
/**
|
558 |
+
* Mixin will delegate all MicroEvent.js function in the destination object.
|
559 |
+
*
|
560 |
+
* - MicroEvent.mixin(Foobar) will make Foobar able to use MicroEvent
|
561 |
+
*
|
562 |
+
* @param {object} the object which will support MicroEvent
|
563 |
+
*/
|
564 |
+
MicroEvent.mixin = function(destObject){
|
565 |
+
var props = ['on', 'off', 'trigger'];
|
566 |
+
for (var i = 0; i < props.length; i++){
|
567 |
+
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
|
568 |
+
}
|
569 |
+
};
|
570 |
+
|
571 |
+
var IS_MAC = /Mac/.test(navigator.userAgent);
|
572 |
+
|
573 |
+
var KEY_A = 65;
|
574 |
+
var KEY_COMMA = 188;
|
575 |
+
var KEY_RETURN = 13;
|
576 |
+
var KEY_ESC = 27;
|
577 |
+
var KEY_LEFT = 37;
|
578 |
+
var KEY_UP = 38;
|
579 |
+
var KEY_RIGHT = 39;
|
580 |
+
var KEY_DOWN = 40;
|
581 |
+
var KEY_BACKSPACE = 8;
|
582 |
+
var KEY_DELETE = 46;
|
583 |
+
var KEY_SHIFT = 16;
|
584 |
+
var KEY_CMD = IS_MAC ? 91 : 17;
|
585 |
+
var KEY_CTRL = IS_MAC ? 18 : 17;
|
586 |
+
var KEY_TAB = 9;
|
587 |
+
|
588 |
+
var TAG_SELECT = 1;
|
589 |
+
var TAG_INPUT = 2;
|
590 |
+
|
591 |
+
var isset = function(object) {
|
592 |
+
return typeof object !== 'undefined';
|
593 |
+
};
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Converts a scalar to its best string representation
|
597 |
+
* for hash keys and HTML attribute values.
|
598 |
+
*
|
599 |
+
* Transformations:
|
600 |
+
* 'str' -> 'str'
|
601 |
+
* null -> ''
|
602 |
+
* undefined -> ''
|
603 |
+
* true -> '1'
|
604 |
+
* false -> '0'
|
605 |
+
* 0 -> '0'
|
606 |
+
* 1 -> '1'
|
607 |
+
*
|
608 |
+
* @param {string} value
|
609 |
+
* @returns {string}
|
610 |
+
*/
|
611 |
+
var hash_key = function(value) {
|
612 |
+
if (typeof value === 'undefined' || value === null) return '';
|
613 |
+
if (typeof value === 'boolean') return value ? '1' : '0';
|
614 |
+
return value + '';
|
615 |
+
};
|
616 |
+
|
617 |
+
/**
|
618 |
+
* Escapes a string for use within HTML.
|
619 |
+
*
|
620 |
+
* @param {string} str
|
621 |
+
* @returns {string}
|
622 |
+
*/
|
623 |
+
var escape_html = function(str) {
|
624 |
+
return (str + '')
|
625 |
+
.replace(/&/g, '&')
|
626 |
+
.replace(/</g, '<')
|
627 |
+
.replace(/>/g, '>')
|
628 |
+
.replace(/"/g, '"');
|
629 |
+
};
|
630 |
+
|
631 |
+
var hook = {};
|
632 |
+
|
633 |
+
/**
|
634 |
+
* Wraps `method` on `self` so that `fn`
|
635 |
+
* is invoked before the original method.
|
636 |
+
*
|
637 |
+
* @param {object} self
|
638 |
+
* @param {string} method
|
639 |
+
* @param {function} fn
|
640 |
+
*/
|
641 |
+
hook.before = function(self, method, fn) {
|
642 |
+
var original = self[method];
|
643 |
+
self[method] = function() {
|
644 |
+
fn.apply(self, arguments);
|
645 |
+
return original.apply(self, arguments);
|
646 |
+
};
|
647 |
+
};
|
648 |
+
|
649 |
+
/**
|
650 |
+
* Wraps `method` on `self` so that `fn`
|
651 |
+
* is invoked after the original method.
|
652 |
+
*
|
653 |
+
* @param {object} self
|
654 |
+
* @param {string} method
|
655 |
+
* @param {function} fn
|
656 |
+
*/
|
657 |
+
hook.after = function(self, method, fn) {
|
658 |
+
var original = self[method];
|
659 |
+
self[method] = function() {
|
660 |
+
var result = original.apply(self, arguments);
|
661 |
+
fn.apply(self, arguments);
|
662 |
+
return result;
|
663 |
+
};
|
664 |
+
};
|
665 |
+
|
666 |
+
/**
|
667 |
+
* Builds a hash table out of an array of
|
668 |
+
* objects, using the specified `key` within
|
669 |
+
* each object.
|
670 |
+
*
|
671 |
+
* @param {string} key
|
672 |
+
* @param {mixed} objects
|
673 |
+
*/
|
674 |
+
var build_hash_table = function(key, objects) {
|
675 |
+
if (!$.isArray(objects)) return objects;
|
676 |
+
var i, n, table = {};
|
677 |
+
for (i = 0, n = objects.length; i < n; i++) {
|
678 |
+
if (objects[i].hasOwnProperty(key)) {
|
679 |
+
table[objects[i][key]] = objects[i];
|
680 |
+
}
|
681 |
+
}
|
682 |
+
return table;
|
683 |
+
};
|
684 |
+
|
685 |
+
/**
|
686 |
+
* Wraps `fn` so that it can only be invoked once.
|
687 |
+
*
|
688 |
+
* @param {function} fn
|
689 |
+
* @returns {function}
|
690 |
+
*/
|
691 |
+
var once = function(fn) {
|
692 |
+
var called = false;
|
693 |
+
return function() {
|
694 |
+
if (called) return;
|
695 |
+
called = true;
|
696 |
+
fn.apply(this, arguments);
|
697 |
+
};
|
698 |
+
};
|
699 |
+
|
700 |
+
/**
|
701 |
+
* Wraps `fn` so that it can only be called once
|
702 |
+
* every `delay` milliseconds (invoked on the falling edge).
|
703 |
+
*
|
704 |
+
* @param {function} fn
|
705 |
+
* @param {int} delay
|
706 |
+
* @returns {function}
|
707 |
+
*/
|
708 |
+
var debounce = function(fn, delay) {
|
709 |
+
var timeout;
|
710 |
+
return function() {
|
711 |
+
var self = this;
|
712 |
+
var args = arguments;
|
713 |
+
window.clearTimeout(timeout);
|
714 |
+
timeout = window.setTimeout(function() {
|
715 |
+
fn.apply(self, args);
|
716 |
+
}, delay);
|
717 |
+
};
|
718 |
+
};
|
719 |
+
|
720 |
+
/**
|
721 |
+
* Debounce all fired events types listed in `types`
|
722 |
+
* while executing the provided `fn`.
|
723 |
+
*
|
724 |
+
* @param {object} self
|
725 |
+
* @param {array} types
|
726 |
+
* @param {function} fn
|
727 |
+
*/
|
728 |
+
var debounce_events = function(self, types, fn) {
|
729 |
+
var type;
|
730 |
+
var trigger = self.trigger;
|
731 |
+
var event_args = {};
|
732 |
+
|
733 |
+
// override trigger method
|
734 |
+
self.trigger = function() {
|
735 |
+
var type = arguments[0];
|
736 |
+
if (types.indexOf(type) !== -1) {
|
737 |
+
event_args[type] = arguments;
|
738 |
+
} else {
|
739 |
+
return trigger.apply(self, arguments);
|
740 |
+
}
|
741 |
+
};
|
742 |
+
|
743 |
+
// invoke provided function
|
744 |
+
fn.apply(self, []);
|
745 |
+
self.trigger = trigger;
|
746 |
+
|
747 |
+
// trigger queued events
|
748 |
+
for (type in event_args) {
|
749 |
+
if (event_args.hasOwnProperty(type)) {
|
750 |
+
trigger.apply(self, event_args[type]);
|
751 |
+
}
|
752 |
+
}
|
753 |
+
};
|
754 |
+
|
755 |
+
/**
|
756 |
+
* A workaround for http://bugs.jquery.com/ticket/6696
|
757 |
+
*
|
758 |
+
* @param {object} $parent - Parent element to listen on.
|
759 |
+
* @param {string} event - Event name.
|
760 |
+
* @param {string} selector - Descendant selector to filter by.
|
761 |
+
* @param {function} fn - Event handler.
|
762 |
+
*/
|
763 |
+
var watchChildEvent = function($parent, event, selector, fn) {
|
764 |
+
$parent.on(event, selector, function(e) {
|
765 |
+
var child = e.target;
|
766 |
+
while (child && child.parentNode !== $parent[0]) {
|
767 |
+
child = child.parentNode;
|
768 |
+
}
|
769 |
+
e.currentTarget = child;
|
770 |
+
return fn.apply(this, [e]);
|
771 |
+
});
|
772 |
+
};
|
773 |
+
|
774 |
+
/**
|
775 |
+
* Determines the current selection within a text input control.
|
776 |
+
* Returns an object containing:
|
777 |
+
* - start
|
778 |
+
* - length
|
779 |
+
*
|
780 |
+
* @param {object} input
|
781 |
+
* @returns {object}
|
782 |
+
*/
|
783 |
+
var getSelection = function(input) {
|
784 |
+
var result = {};
|
785 |
+
if ('selectionStart' in input) {
|
786 |
+
result.start = input.selectionStart;
|
787 |
+
result.length = input.selectionEnd - result.start;
|
788 |
+
} else if (document.selection) {
|
789 |
+
input.focus();
|
790 |
+
var sel = document.selection.createRange();
|
791 |
+
var selLen = document.selection.createRange().text.length;
|
792 |
+
sel.moveStart('character', -input.value.length);
|
793 |
+
result.start = sel.text.length - selLen;
|
794 |
+
result.length = selLen;
|
795 |
+
}
|
796 |
+
return result;
|
797 |
+
};
|
798 |
+
|
799 |
+
/**
|
800 |
+
* Copies CSS properties from one element to another.
|
801 |
+
*
|
802 |
+
* @param {object} $from
|
803 |
+
* @param {object} $to
|
804 |
+
* @param {array} properties
|
805 |
+
*/
|
806 |
+
var transferStyles = function($from, $to, properties) {
|
807 |
+
var i, n, styles = {};
|
808 |
+
if (properties) {
|
809 |
+
for (i = 0, n = properties.length; i < n; i++) {
|
810 |
+
styles[properties[i]] = $from.css(properties[i]);
|
811 |
+
}
|
812 |
+
} else {
|
813 |
+
styles = $from.css();
|
814 |
+
}
|
815 |
+
$to.css(styles);
|
816 |
+
};
|
817 |
+
|
818 |
+
/**
|
819 |
+
* Measures the width of a string within a
|
820 |
+
* parent element (in pixels).
|
821 |
+
*
|
822 |
+
* @param {string} str
|
823 |
+
* @param {object} $parent
|
824 |
+
* @returns {int}
|
825 |
+
*/
|
826 |
+
var measureString = function(str, $parent) {
|
827 |
+
var $test = $('<test>').css({
|
828 |
+
position: 'absolute',
|
829 |
+
top: -99999,
|
830 |
+
left: -99999,
|
831 |
+
width: 'auto',
|
832 |
+
padding: 0,
|
833 |
+
whiteSpace: 'nowrap'
|
834 |
+
}).text(str).appendTo('body');
|
835 |
+
|
836 |
+
transferStyles($parent, $test, [
|
837 |
+
'letterSpacing',
|
838 |
+
'fontSize',
|
839 |
+
'fontFamily',
|
840 |
+
'fontWeight',
|
841 |
+
'textTransform'
|
842 |
+
]);
|
843 |
+
|
844 |
+
var width = $test.width();
|
845 |
+
$test.remove();
|
846 |
+
|
847 |
+
return width;
|
848 |
+
};
|
849 |
+
|
850 |
+
/**
|
851 |
+
* Sets up an input to grow horizontally as the user
|
852 |
+
* types. If the value is changed manually, you can
|
853 |
+
* trigger the "update" handler to resize:
|
854 |
+
*
|
855 |
+
* $input.trigger('update');
|
856 |
+
*
|
857 |
+
* @param {object} $input
|
858 |
+
*/
|
859 |
+
var autoGrow = function($input) {
|
860 |
+
var update = function(e) {
|
861 |
+
var value, keyCode, printable, placeholder, width;
|
862 |
+
var shift, character, selection;
|
863 |
+
e = e || window.event || {};
|
864 |
+
|
865 |
+
if (e.metaKey || e.altKey) return;
|
866 |
+
if ($input.data('grow') === false) return;
|
867 |
+
|
868 |
+
value = $input.val();
|
869 |
+
if (e.type && e.type.toLowerCase() === 'keydown') {
|
870 |
+
keyCode = e.keyCode;
|
871 |
+
printable = (
|
872 |
+
(keyCode >= 97 && keyCode <= 122) || // a-z
|
873 |
+
(keyCode >= 65 && keyCode <= 90) || // A-Z
|
874 |
+
(keyCode >= 48 && keyCode <= 57) || // 0-9
|
875 |
+
keyCode === 32 // space
|
876 |
+
);
|
877 |
+
|
878 |
+
if (keyCode === KEY_DELETE || keyCode === KEY_BACKSPACE) {
|
879 |
+
selection = getSelection($input[0]);
|
880 |
+
if (selection.length) {
|
881 |
+
value = value.substring(0, selection.start) + value.substring(selection.start + selection.length);
|
882 |
+
} else if (keyCode === KEY_BACKSPACE && selection.start) {
|
883 |
+
value = value.substring(0, selection.start - 1) + value.substring(selection.start + 1);
|
884 |
+
} else if (keyCode === KEY_DELETE && typeof selection.start !== 'undefined') {
|
885 |
+
value = value.substring(0, selection.start) + value.substring(selection.start + 1);
|
886 |
+
}
|
887 |
+
} else if (printable) {
|
888 |
+
shift = e.shiftKey;
|
889 |
+
character = String.fromCharCode(e.keyCode);
|
890 |
+
if (shift) character = character.toUpperCase();
|
891 |
+
else character = character.toLowerCase();
|
892 |
+
value += character;
|
893 |
+
}
|
894 |
+
}
|
895 |
+
|
896 |
+
placeholder = $input.attr('placeholder') || '';
|
897 |
+
if (!value.length && placeholder.length) {
|
898 |
+
value = placeholder;
|
899 |
+
}
|
900 |
+
|
901 |
+
width = measureString(value, $input) + 4;
|
902 |
+
if (width !== $input.width()) {
|
903 |
+
$input.width(width);
|
904 |
+
$input.triggerHandler('resize');
|
905 |
+
}
|
906 |
+
};
|
907 |
+
|
908 |
+
$input.on('keydown keyup update blur', update);
|
909 |
+
update();
|
910 |
+
};
|
911 |
+
|
912 |
+
var Selectize = function($input, settings) {
|
913 |
+
var key, i, n, self = this;
|
914 |
+
$input[0].selectize = self;
|
915 |
+
|
916 |
+
// setup default state
|
917 |
+
$.extend(self, {
|
918 |
+
settings : settings,
|
919 |
+
$input : $input,
|
920 |
+
tagType : $input[0].tagName.toLowerCase() === 'select' ? TAG_SELECT : TAG_INPUT,
|
921 |
+
|
922 |
+
eventNS : '.selectize' + (++Selectize.count),
|
923 |
+
highlightedValue : null,
|
924 |
+
isOpen : false,
|
925 |
+
isDisabled : false,
|
926 |
+
isLocked : false,
|
927 |
+
isFocused : false,
|
928 |
+
isInputFocused : false,
|
929 |
+
isInputHidden : false,
|
930 |
+
isSetup : false,
|
931 |
+
isShiftDown : false,
|
932 |
+
isCmdDown : false,
|
933 |
+
isCtrlDown : false,
|
934 |
+
ignoreFocus : false,
|
935 |
+
ignoreHover : false,
|
936 |
+
hasOptions : false,
|
937 |
+
currentResults : null,
|
938 |
+
lastValue : '',
|
939 |
+
caretPos : 0,
|
940 |
+
loading : 0,
|
941 |
+
loadedSearches : {},
|
942 |
+
|
943 |
+
$activeOption : null,
|
944 |
+
$activeItems : [],
|
945 |
+
|
946 |
+
optgroups : {},
|
947 |
+
options : {},
|
948 |
+
userOptions : {},
|
949 |
+
items : [],
|
950 |
+
renderCache : {},
|
951 |
+
onSearchChange : debounce(self.onSearchChange, settings.loadThrottle)
|
952 |
+
});
|
953 |
+
|
954 |
+
// search system
|
955 |
+
self.sifter = new Sifter(this.options, {diacritics: settings.diacritics});
|
956 |
+
|
957 |
+
// build options table
|
958 |
+
$.extend(self.options, build_hash_table(settings.valueField, settings.options));
|
959 |
+
delete self.settings.options;
|
960 |
+
|
961 |
+
// build optgroup table
|
962 |
+
$.extend(self.optgroups, build_hash_table(settings.optgroupValueField, settings.optgroups));
|
963 |
+
delete self.settings.optgroups;
|
964 |
+
|
965 |
+
// option-dependent defaults
|
966 |
+
self.settings.mode = self.settings.mode || (self.settings.maxItems === 1 ? 'single' : 'multi');
|
967 |
+
if (typeof self.settings.hideSelected !== 'boolean') {
|
968 |
+
self.settings.hideSelected = self.settings.mode === 'multi';
|
969 |
+
}
|
970 |
+
|
971 |
+
self.initializePlugins(self.settings.plugins);
|
972 |
+
self.setupCallbacks();
|
973 |
+
self.setupTemplates();
|
974 |
+
self.setup();
|
975 |
+
};
|
976 |
+
|
977 |
+
// mixins
|
978 |
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
979 |
+
|
980 |
+
MicroEvent.mixin(Selectize);
|
981 |
+
MicroPlugin.mixin(Selectize);
|
982 |
+
|
983 |
+
// methods
|
984 |
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
985 |
+
|
986 |
+
$.extend(Selectize.prototype, {
|
987 |
+
|
988 |
+
/**
|
989 |
+
* Creates all elements and sets up event bindings.
|
990 |
+
*/
|
991 |
+
setup: function() {
|
992 |
+
var self = this;
|
993 |
+
var settings = self.settings;
|
994 |
+
var eventNS = self.eventNS;
|
995 |
+
var $window = $(window);
|
996 |
+
var $document = $(document);
|
997 |
+
|
998 |
+
var $wrapper;
|
999 |
+
var $control;
|
1000 |
+
var $control_input;
|
1001 |
+
var $dropdown;
|
1002 |
+
var $dropdown_content;
|
1003 |
+
var $dropdown_parent;
|
1004 |
+
var inputMode;
|
1005 |
+
var timeout_blur;
|
1006 |
+
var timeout_focus;
|
1007 |
+
var tab_index;
|
1008 |
+
var classes;
|
1009 |
+
var classes_plugins;
|
1010 |
+
|
1011 |
+
inputMode = self.settings.mode;
|
1012 |
+
tab_index = self.$input.attr('tabindex') || '';
|
1013 |
+
classes = self.$input.attr('class') || '';
|
1014 |
+
|
1015 |
+
$wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);
|
1016 |
+
$control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper);
|
1017 |
+
$control_input = $('<input type="text">').appendTo($control).attr('tabindex', tab_index);
|
1018 |
+
$dropdown_parent = $(settings.dropdownParent || $wrapper);
|
1019 |
+
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(classes).addClass(inputMode).hide().appendTo($dropdown_parent);
|
1020 |
+
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown);
|
1021 |
+
|
1022 |
+
$wrapper.css({
|
1023 |
+
width: self.$input[0].style.width
|
1024 |
+
});
|
1025 |
+
|
1026 |
+
if (self.plugins.names.length) {
|
1027 |
+
classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-');
|
1028 |
+
$wrapper.addClass(classes_plugins);
|
1029 |
+
$dropdown.addClass(classes_plugins);
|
1030 |
+
}
|
1031 |
+
|
1032 |
+
if ((settings.maxItems === null || settings.maxItems > 1) && self.tagType === TAG_SELECT) {
|
1033 |
+
self.$input.attr('multiple', 'multiple');
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
if (self.settings.placeholder) {
|
1037 |
+
$control_input.attr('placeholder', settings.placeholder);
|
1038 |
+
}
|
1039 |
+
|
1040 |
+
self.$wrapper = $wrapper;
|
1041 |
+
self.$control = $control;
|
1042 |
+
self.$control_input = $control_input;
|
1043 |
+
self.$dropdown = $dropdown;
|
1044 |
+
self.$dropdown_content = $dropdown_content;
|
1045 |
+
|
1046 |
+
$control.on('mousedown', function(e) {
|
1047 |
+
if (!e.isDefaultPrevented()) {
|
1048 |
+
window.setTimeout(function() {
|
1049 |
+
self.focus(true);
|
1050 |
+
}, 0);
|
1051 |
+
}
|
1052 |
+
});
|
1053 |
+
|
1054 |
+
// necessary for mobile webkit devices (manual focus triggering
|
1055 |
+
// is ignored unless invoked within a click event)
|
1056 |
+
$control.on('click', function(e) {
|
1057 |
+
if (!self.isInputFocused) {
|
1058 |
+
self.focus(true);
|
1059 |
+
}
|
1060 |
+
});
|
1061 |
+
|
1062 |
+
$dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); });
|
1063 |
+
$dropdown.on('mousedown', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
|
1064 |
+
watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
|
1065 |
+
autoGrow($control_input);
|
1066 |
+
|
1067 |
+
$control_input.on({
|
1068 |
+
mousedown : function(e) { e.stopPropagation(); },
|
1069 |
+
keydown : function() { return self.onKeyDown.apply(self, arguments); },
|
1070 |
+
keyup : function() { return self.onKeyUp.apply(self, arguments); },
|
1071 |
+
keypress : function() { return self.onKeyPress.apply(self, arguments); },
|
1072 |
+
resize : function() { self.positionDropdown.apply(self, []); },
|
1073 |
+
blur : function() { return self.onBlur.apply(self, arguments); },
|
1074 |
+
focus : function() { return self.onFocus.apply(self, arguments); }
|
1075 |
+
});
|
1076 |
+
|
1077 |
+
$document.on('keydown' + eventNS, function(e) {
|
1078 |
+
self.isCmdDown = e[IS_MAC ? 'metaKey' : 'ctrlKey'];
|
1079 |
+
self.isCtrlDown = e[IS_MAC ? 'altKey' : 'ctrlKey'];
|
1080 |
+
self.isShiftDown = e.shiftKey;
|
1081 |
+
});
|
1082 |
+
|
1083 |
+
$document.on('keyup' + eventNS, function(e) {
|
1084 |
+
if (e.keyCode === KEY_CTRL) self.isCtrlDown = false;
|
1085 |
+
if (e.keyCode === KEY_SHIFT) self.isShiftDown = false;
|
1086 |
+
if (e.keyCode === KEY_CMD) self.isCmdDown = false;
|
1087 |
+
});
|
1088 |
+
|
1089 |
+
$document.on('mousedown' + eventNS, function(e) {
|
1090 |
+
if (self.isFocused) {
|
1091 |
+
// prevent events on the dropdown scrollbar from causing the control to blur
|
1092 |
+
if (e.target === self.$dropdown[0] || e.target.parentNode === self.$dropdown[0]) {
|
1093 |
+
var ignoreFocus = self.ignoreFocus;
|
1094 |
+
self.ignoreFocus = true;
|
1095 |
+
window.setTimeout(function() {
|
1096 |
+
self.ignoreFocus = ignoreFocus;
|
1097 |
+
self.focus(false);
|
1098 |
+
}, 0);
|
1099 |
+
return;
|
1100 |
+
}
|
1101 |
+
// blur on click outside
|
1102 |
+
if (!self.$control.has(e.target).length && e.target !== self.$control[0]) {
|
1103 |
+
self.blur();
|
1104 |
+
}
|
1105 |
+
}
|
1106 |
+
});
|
1107 |
+
|
1108 |
+
$window.on(['scroll' + eventNS, 'resize' + eventNS].join(' '), function() {
|
1109 |
+
if (self.isOpen) {
|
1110 |
+
self.positionDropdown.apply(self, arguments);
|
1111 |
+
}
|
1112 |
+
});
|
1113 |
+
$window.on('mousemove' + eventNS, function() {
|
1114 |
+
self.ignoreHover = false;
|
1115 |
+
});
|
1116 |
+
|
1117 |
+
self.$input.attr('tabindex',-1).hide().after(self.$wrapper);
|
1118 |
+
|
1119 |
+
if ($.isArray(settings.items)) {
|
1120 |
+
self.setValue(settings.items);
|
1121 |
+
delete settings.items;
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
self.updateOriginalInput();
|
1125 |
+
self.refreshItems();
|
1126 |
+
self.refreshClasses();
|
1127 |
+
self.updatePlaceholder();
|
1128 |
+
self.isSetup = true;
|
1129 |
+
|
1130 |
+
if (self.$input.is(':disabled')) {
|
1131 |
+
self.disable();
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
self.on('change', this.onChange);
|
1135 |
+
self.trigger('initialize');
|
1136 |
+
|
1137 |
+
// preload options
|
1138 |
+
if (settings.preload) {
|
1139 |
+
self.onSearchChange('');
|
1140 |
+
}
|
1141 |
+
},
|
1142 |
+
|
1143 |
+
/**
|
1144 |
+
* Sets up default rendering functions.
|
1145 |
+
*/
|
1146 |
+
setupTemplates: function() {
|
1147 |
+
var self = this;
|
1148 |
+
var field_label = self.settings.labelField;
|
1149 |
+
var field_optgroup = self.settings.optgroupLabelField;
|
1150 |
+
|
1151 |
+
var templates = {
|
1152 |
+
'optgroup': function(data) {
|
1153 |
+
return '<div class="optgroup">' + data.html + '</div>';
|
1154 |
+
},
|
1155 |
+
'optgroup_header': function(data, escape) {
|
1156 |
+
return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>';
|
1157 |
+
},
|
1158 |
+
'option': function(data, escape) {
|
1159 |
+
return '<div class="option">' + escape(data[field_label]) + '</div>';
|
1160 |
+
},
|
1161 |
+
'item': function(data, escape) {
|
1162 |
+
return '<div class="item">' + escape(data[field_label]) + '</div>';
|
1163 |
+
},
|
1164 |
+
'option_create': function(data, escape) {
|
1165 |
+
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>';
|
1166 |
+
},
|
1167 |
+
};
|
1168 |
+
|
1169 |
+
self.settings.render = $.extend({}, templates, self.settings.render);
|
1170 |
+
},
|
1171 |
+
|
1172 |
+
/**
|
1173 |
+
* Maps fired events to callbacks provided
|
1174 |
+
* in the settings used when creating the control.
|
1175 |
+
*/
|
1176 |
+
setupCallbacks: function() {
|
1177 |
+
var key, fn, callbacks = {
|
1178 |
+
'initialize' : 'onInitialize',
|
1179 |
+
'change' : 'onChange',
|
1180 |
+
'item_add' : 'onItemAdd',
|
1181 |
+
'item_remove' : 'onItemRemove',
|
1182 |
+
'clear' : 'onClear',
|
1183 |
+
'option_add' : 'onOptionAdd',
|
1184 |
+
'option_remove' : 'onOptionRemove',
|
1185 |
+
'option_clear' : 'onOptionClear',
|
1186 |
+
'dropdown_open' : 'onDropdownOpen',
|
1187 |
+
'dropdown_close' : 'onDropdownClose',
|
1188 |
+
'type' : 'onType'
|
1189 |
+
};
|
1190 |
+
|
1191 |
+
for (key in callbacks) {
|
1192 |
+
if (callbacks.hasOwnProperty(key)) {
|
1193 |
+
fn = this.settings[callbacks[key]];
|
1194 |
+
if (fn) this.on(key, fn);
|
1195 |
+
}
|
1196 |
+
}
|
1197 |
+
},
|
1198 |
+
|
1199 |
+
/**
|
1200 |
+
* Triggered when the value of the control has been changed.
|
1201 |
+
* This should propagate the event to the original DOM
|
1202 |
+
* input / select element.
|
1203 |
+
*/
|
1204 |
+
onChange: function() {
|
1205 |
+
this.$input.trigger('change');
|
1206 |
+
},
|
1207 |
+
|
1208 |
+
/**
|
1209 |
+
* Triggered on <input> keypress.
|
1210 |
+
*
|
1211 |
+
* @param {object} e
|
1212 |
+
* @returns {boolean}
|
1213 |
+
*/
|
1214 |
+
onKeyPress: function(e) {
|
1215 |
+
if (this.isLocked) return e && e.preventDefault();
|
1216 |
+
var character = String.fromCharCode(e.keyCode || e.which);
|
1217 |
+
if (this.settings.create && character === this.settings.delimiter) {
|
1218 |
+
this.createItem();
|
1219 |
+
e.preventDefault();
|
1220 |
+
return false;
|
1221 |
+
}
|
1222 |
+
},
|
1223 |
+
|
1224 |
+
/**
|
1225 |
+
* Triggered on <input> keydown.
|
1226 |
+
*
|
1227 |
+
* @param {object} e
|
1228 |
+
* @returns {boolean}
|
1229 |
+
*/
|
1230 |
+
onKeyDown: function(e) {
|
1231 |
+
var isInput = e.target === this.$control_input[0];
|
1232 |
+
var self = this;
|
1233 |
+
|
1234 |
+
if (self.isLocked) {
|
1235 |
+
if (e.keyCode !== KEY_TAB) {
|
1236 |
+
e.preventDefault();
|
1237 |
+
}
|
1238 |
+
return;
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
switch (e.keyCode) {
|
1242 |
+
case KEY_A:
|
1243 |
+
if (self.isCmdDown) {
|
1244 |
+
self.selectAll();
|
1245 |
+
return;
|
1246 |
+
}
|
1247 |
+
break;
|
1248 |
+
case KEY_ESC:
|
1249 |
+
self.blur();
|
1250 |
+
return;
|
1251 |
+
case KEY_DOWN:
|
1252 |
+
if (!self.isOpen && self.hasOptions) {
|
1253 |
+
self.open();
|
1254 |
+
} else if (self.$activeOption) {
|
1255 |
+
self.ignoreHover = true;
|
1256 |
+
var $next = self.getAdjacentOption(self.$activeOption, 1);
|
1257 |
+
if ($next.length) self.setActiveOption($next, true, true);
|
1258 |
+
}
|
1259 |
+
e.preventDefault();
|
1260 |
+
return;
|
1261 |
+
case KEY_UP:
|
1262 |
+
if (self.$activeOption) {
|
1263 |
+
self.ignoreHover = true;
|
1264 |
+
var $prev = self.getAdjacentOption(self.$activeOption, -1);
|
1265 |
+
if ($prev.length) self.setActiveOption($prev, true, true);
|
1266 |
+
}
|
1267 |
+
e.preventDefault();
|
1268 |
+
return;
|
1269 |
+
case KEY_RETURN:
|
1270 |
+
if (self.$activeOption) {
|
1271 |
+
self.onOptionSelect({currentTarget: self.$activeOption});
|
1272 |
+
}
|
1273 |
+
e.preventDefault();
|
1274 |
+
return;
|
1275 |
+
case KEY_LEFT:
|
1276 |
+
self.advanceSelection(-1, e);
|
1277 |
+
return;
|
1278 |
+
case KEY_RIGHT:
|
1279 |
+
self.advanceSelection(1, e);
|
1280 |
+
return;
|
1281 |
+
case KEY_TAB:
|
1282 |
+
if (self.settings.create && $.trim(self.$control_input.val()).length) {
|
1283 |
+
self.createItem();
|
1284 |
+
e.preventDefault();
|
1285 |
+
}
|
1286 |
+
return;
|
1287 |
+
case KEY_BACKSPACE:
|
1288 |
+
case KEY_DELETE:
|
1289 |
+
self.deleteSelection(e);
|
1290 |
+
return;
|
1291 |
+
}
|
1292 |
+
if (self.isFull() || self.isInputHidden) {
|
1293 |
+
e.preventDefault();
|
1294 |
+
return;
|
1295 |
+
}
|
1296 |
+
},
|
1297 |
+
|
1298 |
+
/**
|
1299 |
+
* Triggered on <input> keyup.
|
1300 |
+
*
|
1301 |
+
* @param {object} e
|
1302 |
+
* @returns {boolean}
|
1303 |
+
*/
|
1304 |
+
onKeyUp: function(e) {
|
1305 |
+
var self = this;
|
1306 |
+
|
1307 |
+
if (self.isLocked) return e && e.preventDefault();
|
1308 |
+
var value = self.$control_input.val() || '';
|
1309 |
+
if (self.lastValue !== value) {
|
1310 |
+
self.lastValue = value;
|
1311 |
+
self.onSearchChange(value);
|
1312 |
+
self.refreshOptions();
|
1313 |
+
self.trigger('type', value);
|
1314 |
+
}
|
1315 |
+
},
|
1316 |
+
|
1317 |
+
/**
|
1318 |
+
* Invokes the user-provide option provider / loader.
|
1319 |
+
*
|
1320 |
+
* Note: this function is debounced in the Selectize
|
1321 |
+
* constructor (by `settings.loadDelay` milliseconds)
|
1322 |
+
*
|
1323 |
+
* @param {string} value
|
1324 |
+
*/
|
1325 |
+
onSearchChange: function(value) {
|
1326 |
+
var self = this;
|
1327 |
+
var fn = self.settings.load;
|
1328 |
+
if (!fn) return;
|
1329 |
+
if (self.loadedSearches.hasOwnProperty(value)) return;
|
1330 |
+
self.loadedSearches[value] = true;
|
1331 |
+
self.load(function(callback) {
|
1332 |
+
fn.apply(self, [value, callback]);
|
1333 |
+
});
|
1334 |
+
},
|
1335 |
+
|
1336 |
+
/**
|
1337 |
+
* Triggered on <input> focus.
|
1338 |
+
*
|
1339 |
+
* @param {object} e (optional)
|
1340 |
+
* @returns {boolean}
|
1341 |
+
*/
|
1342 |
+
onFocus: function(e) {
|
1343 |
+
var self = this;
|
1344 |
+
|
1345 |
+
self.isInputFocused = true;
|
1346 |
+
self.isFocused = true;
|
1347 |
+
if (self.isDisabled) {
|
1348 |
+
self.blur();
|
1349 |
+
e.preventDefault();
|
1350 |
+
return false;
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
if (self.ignoreFocus) return;
|
1354 |
+
if (self.settings.preload === 'focus') self.onSearchChange('');
|
1355 |
+
|
1356 |
+
self.showInput();
|
1357 |
+
self.setActiveItem(null);
|
1358 |
+
self.refreshOptions(!!self.settings.openOnFocus);
|
1359 |
+
self.refreshClasses();
|
1360 |
+
},
|
1361 |
+
|
1362 |
+
/**
|
1363 |
+
* Triggered on <input> blur.
|
1364 |
+
*
|
1365 |
+
* @param {object} e
|
1366 |
+
* @returns {boolean}
|
1367 |
+
*/
|
1368 |
+
onBlur: function(e) {
|
1369 |
+
var self = this;
|
1370 |
+
self.isInputFocused = false;
|
1371 |
+
if (self.ignoreFocus) return;
|
1372 |
+
|
1373 |
+
self.close();
|
1374 |
+
self.setTextboxValue('');
|
1375 |
+
self.setActiveItem(null);
|
1376 |
+
self.setActiveOption(null);
|
1377 |
+
self.setCaret(self.items.length);
|
1378 |
+
self.isFocused = false;
|
1379 |
+
self.refreshClasses();
|
1380 |
+
},
|
1381 |
+
|
1382 |
+
/**
|
1383 |
+
* Triggered when the user rolls over
|
1384 |
+
* an option in the autocomplete dropdown menu.
|
1385 |
+
*
|
1386 |
+
* @param {object} e
|
1387 |
+
* @returns {boolean}
|
1388 |
+
*/
|
1389 |
+
onOptionHover: function(e) {
|
1390 |
+
if (this.ignoreHover) return;
|
1391 |
+
this.setActiveOption(e.currentTarget, false);
|
1392 |
+
},
|
1393 |
+
|
1394 |
+
/**
|
1395 |
+
* Triggered when the user clicks on an option
|
1396 |
+
* in the autocomplete dropdown menu.
|
1397 |
+
*
|
1398 |
+
* @param {object} e
|
1399 |
+
* @returns {boolean}
|
1400 |
+
*/
|
1401 |
+
onOptionSelect: function(e) {
|
1402 |
+
var value, $target, $option, self = this;
|
1403 |
+
|
1404 |
+
e.preventDefault && e.preventDefault();
|
1405 |
+
e.stopPropagation && e.stopPropagation();
|
1406 |
+
self.focus(false);
|
1407 |
+
|
1408 |
+
$target = $(e.currentTarget);
|
1409 |
+
if ($target.hasClass('create')) {
|
1410 |
+
self.createItem();
|
1411 |
+
} else {
|
1412 |
+
value = $target.attr('data-value');
|
1413 |
+
if (value) {
|
1414 |
+
self.setTextboxValue('');
|
1415 |
+
self.addItem(value);
|
1416 |
+
if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) {
|
1417 |
+
self.setActiveOption(self.getOption(value));
|
1418 |
+
}
|
1419 |
+
}
|
1420 |
+
}
|
1421 |
+
},
|
1422 |
+
|
1423 |
+
/**
|
1424 |
+
* Triggered when the user clicks on an item
|
1425 |
+
* that has been selected.
|
1426 |
+
*
|
1427 |
+
* @param {object} e
|
1428 |
+
* @returns {boolean}
|
1429 |
+
*/
|
1430 |
+
onItemSelect: function(e) {
|
1431 |
+
var self = this;
|
1432 |
+
|
1433 |
+
if (self.settings.mode === 'multi') {
|
1434 |
+
e.preventDefault();
|
1435 |
+
self.setActiveItem(e.currentTarget, e);
|
1436 |
+
self.focus(false);
|
1437 |
+
self.hideInput();
|
1438 |
+
}
|
1439 |
+
},
|
1440 |
+
|
1441 |
+
/**
|
1442 |
+
* Invokes the provided method that provides
|
1443 |
+
* results to a callback---which are then added
|
1444 |
+
* as options to the control.
|
1445 |
+
*
|
1446 |
+
* @param {function} fn
|
1447 |
+
*/
|
1448 |
+
load: function(fn) {
|
1449 |
+
var self = this;
|
1450 |
+
var $wrapper = self.$wrapper.addClass('loading');
|
1451 |
+
|
1452 |
+
self.loading++;
|
1453 |
+
fn.apply(self, [function(results) {
|
1454 |
+
self.loading = Math.max(self.loading - 1, 0);
|
1455 |
+
if (results && results.length) {
|
1456 |
+
self.addOption(results);
|
1457 |
+
self.refreshOptions(false);
|
1458 |
+
if (self.isInputFocused) self.open();
|
1459 |
+
}
|
1460 |
+
if (!self.loading) {
|
1461 |
+
$wrapper.removeClass('loading');
|
1462 |
+
}
|
1463 |
+
self.trigger('load', results);
|
1464 |
+
}]);
|
1465 |
+
},
|
1466 |
+
|
1467 |
+
/**
|
1468 |
+
* Sets the input field of the control to the specified value.
|
1469 |
+
*
|
1470 |
+
* @param {string} value
|
1471 |
+
*/
|
1472 |
+
setTextboxValue: function(value) {
|
1473 |
+
this.$control_input.val(value).triggerHandler('update');
|
1474 |
+
this.lastValue = value;
|
1475 |
+
},
|
1476 |
+
|
1477 |
+
/**
|
1478 |
+
* Returns the value of the control. If multiple items
|
1479 |
+
* can be selected (e.g. <select multiple>), this returns
|
1480 |
+
* an array. If only one item can be selected, this
|
1481 |
+
* returns a string.
|
1482 |
+
*
|
1483 |
+
* @returns {mixed}
|
1484 |
+
*/
|
1485 |
+
getValue: function() {
|
1486 |
+
if (this.tagType === TAG_SELECT && this.$input.attr('multiple')) {
|
1487 |
+
return this.items;
|
1488 |
+
} else {
|
1489 |
+
return this.items.join(this.settings.delimiter);
|
1490 |
+
}
|
1491 |
+
},
|
1492 |
+
|
1493 |
+
/**
|
1494 |
+
* Resets the selected items to the given value.
|
1495 |
+
*
|
1496 |
+
* @param {mixed} value
|
1497 |
+
*/
|
1498 |
+
setValue: function(value) {
|
1499 |
+
debounce_events(this, ['change'], function() {
|
1500 |
+
this.clear();
|
1501 |
+
var items = $.isArray(value) ? value : [value];
|
1502 |
+
for (var i = 0, n = items.length; i < n; i++) {
|
1503 |
+
this.addItem(items[i]);
|
1504 |
+
}
|
1505 |
+
});
|
1506 |
+
},
|
1507 |
+
|
1508 |
+
/**
|
1509 |
+
* Sets the selected item.
|
1510 |
+
*
|
1511 |
+
* @param {object} $item
|
1512 |
+
* @param {object} e (optional)
|
1513 |
+
*/
|
1514 |
+
setActiveItem: function($item, e) {
|
1515 |
+
var self = this;
|
1516 |
+
var eventName;
|
1517 |
+
var i, idx, begin, end, item, swap;
|
1518 |
+
var $last;
|
1519 |
+
|
1520 |
+
$item = $($item);
|
1521 |
+
|
1522 |
+
// clear the active selection
|
1523 |
+
if (!$item.length) {
|
1524 |
+
$(self.$activeItems).removeClass('active');
|
1525 |
+
self.$activeItems = [];
|
1526 |
+
self.isFocused = self.isInputFocused;
|
1527 |
+
return;
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
// modify selection
|
1531 |
+
eventName = e && e.type.toLowerCase();
|
1532 |
+
|
1533 |
+
if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) {
|
1534 |
+
$last = self.$control.children('.active:last');
|
1535 |
+
begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]);
|
1536 |
+
end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]);
|
1537 |
+
if (begin > end) {
|
1538 |
+
swap = begin;
|
1539 |
+
begin = end;
|
1540 |
+
end = swap;
|
1541 |
+
}
|
1542 |
+
for (i = begin; i <= end; i++) {
|
1543 |
+
item = self.$control[0].childNodes[i];
|
1544 |
+
if (self.$activeItems.indexOf(item) === -1) {
|
1545 |
+
$(item).addClass('active');
|
1546 |
+
self.$activeItems.push(item);
|
1547 |
+
}
|
1548 |
+
}
|
1549 |
+
e.preventDefault();
|
1550 |
+
} else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) {
|
1551 |
+
if ($item.hasClass('active')) {
|
1552 |
+
idx = self.$activeItems.indexOf($item[0]);
|
1553 |
+
self.$activeItems.splice(idx, 1);
|
1554 |
+
$item.removeClass('active');
|
1555 |
+
} else {
|
1556 |
+
self.$activeItems.push($item.addClass('active')[0]);
|
1557 |
+
}
|
1558 |
+
} else {
|
1559 |
+
$(self.$activeItems).removeClass('active');
|
1560 |
+
self.$activeItems = [$item.addClass('active')[0]];
|
1561 |
+
}
|
1562 |
+
|
1563 |
+
self.isFocused = !!self.$activeItems.length || self.isInputFocused;
|
1564 |
+
},
|
1565 |
+
|
1566 |
+
/**
|
1567 |
+
* Sets the selected item in the dropdown menu
|
1568 |
+
* of available options.
|
1569 |
+
*
|
1570 |
+
* @param {object} $object
|
1571 |
+
* @param {boolean} scroll
|
1572 |
+
* @param {boolean} animate
|
1573 |
+
*/
|
1574 |
+
setActiveOption: function($option, scroll, animate) {
|
1575 |
+
var height_menu, height_item, y;
|
1576 |
+
var scroll_top, scroll_bottom;
|
1577 |
+
var self = this;
|
1578 |
+
|
1579 |
+
if (self.$activeOption) self.$activeOption.removeClass('active');
|
1580 |
+
self.$activeOption = null;
|
1581 |
+
|
1582 |
+
$option = $($option);
|
1583 |
+
if (!$option.length) return;
|
1584 |
+
|
1585 |
+
self.$activeOption = $option.addClass('active');
|
1586 |
+
|
1587 |
+
if (scroll || !isset(scroll)) {
|
1588 |
+
|
1589 |
+
height_menu = self.$dropdown_content.height();
|
1590 |
+
height_item = self.$activeOption.outerHeight(true);
|
1591 |
+
scroll = self.$dropdown_content.scrollTop() || 0;
|
1592 |
+
y = self.$activeOption.offset().top - self.$dropdown_content.offset().top + scroll;
|
1593 |
+
scroll_top = y;
|
1594 |
+
scroll_bottom = y - height_menu + height_item;
|
1595 |
+
|
1596 |
+
if (y + height_item > height_menu - scroll) {
|
1597 |
+
self.$dropdown_content.stop().animate({scrollTop: scroll_bottom}, animate ? self.settings.scrollDuration : 0);
|
1598 |
+
} else if (y < scroll) {
|
1599 |
+
self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0);
|
1600 |
+
}
|
1601 |
+
|
1602 |
+
}
|
1603 |
+
},
|
1604 |
+
|
1605 |
+
/**
|
1606 |
+
* Selects all items (CTRL + A).
|
1607 |
+
*/
|
1608 |
+
selectAll: function() {
|
1609 |
+
this.$activeItems = Array.prototype.slice.apply(this.$control.children(':not(input)').addClass('active'));
|
1610 |
+
this.isFocused = true;
|
1611 |
+
if (this.$activeItems.length) this.hideInput();
|
1612 |
+
},
|
1613 |
+
|
1614 |
+
/**
|
1615 |
+
* Hides the input element out of view, while
|
1616 |
+
* retaining its focus.
|
1617 |
+
*/
|
1618 |
+
hideInput: function() {
|
1619 |
+
var self = this;
|
1620 |
+
|
1621 |
+
self.close();
|
1622 |
+
self.setTextboxValue('');
|
1623 |
+
self.$control_input.css({opacity: 0, position: 'absolute', left: -10000});
|
1624 |
+
self.isInputHidden = true;
|
1625 |
+
},
|
1626 |
+
|
1627 |
+
/**
|
1628 |
+
* Restores input visibility.
|
1629 |
+
*/
|
1630 |
+
showInput: function() {
|
1631 |
+
this.$control_input.css({opacity: 1, position: 'relative', left: 0});
|
1632 |
+
this.isInputHidden = false;
|
1633 |
+
},
|
1634 |
+
|
1635 |
+
/**
|
1636 |
+
* Gives the control focus. If "trigger" is falsy,
|
1637 |
+
* focus handlers won't be fired--causing the focus
|
1638 |
+
* to happen silently in the background.
|
1639 |
+
*
|
1640 |
+
* @param {boolean} trigger
|
1641 |
+
*/
|
1642 |
+
focus: function(trigger) {
|
1643 |
+
var self = this;
|
1644 |
+
|
1645 |
+
if (self.isDisabled) return;
|
1646 |
+
self.ignoreFocus = true;
|
1647 |
+
self.$control_input[0].focus();
|
1648 |
+
self.isInputFocused = true;
|
1649 |
+
window.setTimeout(function() {
|
1650 |
+
self.ignoreFocus = false;
|
1651 |
+
if (trigger) self.onFocus();
|
1652 |
+
}, 0);
|
1653 |
+
},
|
1654 |
+
|
1655 |
+
/**
|
1656 |
+
* Forces the control out of focus.
|
1657 |
+
*/
|
1658 |
+
blur: function() {
|
1659 |
+
this.$control_input.trigger('blur');
|
1660 |
+
},
|
1661 |
+
|
1662 |
+
/**
|
1663 |
+
* Returns a function that scores an object
|
1664 |
+
* to show how good of a match it is to the
|
1665 |
+
* provided query.
|
1666 |
+
*
|
1667 |
+
* @param {string} query
|
1668 |
+
* @param {object} options
|
1669 |
+
* @return {function}
|
1670 |
+
*/
|
1671 |
+
getScoreFunction: function(query) {
|
1672 |
+
return this.sifter.getScoreFunction(query, this.getSearchOptions());
|
1673 |
+
},
|
1674 |
+
|
1675 |
+
/**
|
1676 |
+
* Returns search options for sifter (the system
|
1677 |
+
* for scoring and sorting results).
|
1678 |
+
*
|
1679 |
+
* @see https://github.com/brianreavis/sifter.js
|
1680 |
+
* @return {object}
|
1681 |
+
*/
|
1682 |
+
getSearchOptions: function() {
|
1683 |
+
var settings = this.settings;
|
1684 |
+
var fields = settings.searchField;
|
1685 |
+
|
1686 |
+
return {
|
1687 |
+
fields : $.isArray(fields) ? fields : [fields],
|
1688 |
+
sort : settings.sortField,
|
1689 |
+
direction : settings.sortDirection,
|
1690 |
+
};
|
1691 |
+
},
|
1692 |
+
|
1693 |
+
/**
|
1694 |
+
* Searches through available options and returns
|
1695 |
+
* a sorted array of matches.
|
1696 |
+
*
|
1697 |
+
* Returns an object containing:
|
1698 |
+
*
|
1699 |
+
* - query {string}
|
1700 |
+
* - tokens {array}
|
1701 |
+
* - total {int}
|
1702 |
+
* - items {array}
|
1703 |
+
*
|
1704 |
+
* @param {string} query
|
1705 |
+
* @returns {object}
|
1706 |
+
*/
|
1707 |
+
search: function(query) {
|
1708 |
+
var i, value, score, result, calculateScore;
|
1709 |
+
var self = this;
|
1710 |
+
var settings = self.settings;
|
1711 |
+
var options = this.getSearchOptions();
|
1712 |
+
|
1713 |
+
// validate user-provided result scoring function
|
1714 |
+
if (settings.score) {
|
1715 |
+
calculateScore = self.settings.score.apply(this, [query]);
|
1716 |
+
if (typeof calculateScore !== 'function') {
|
1717 |
+
throw new Error('Selectize "score" setting must be a function that returns a function');
|
1718 |
+
}
|
1719 |
+
}
|
1720 |
+
|
1721 |
+
// perform search
|
1722 |
+
if (query !== self.lastQuery) {
|
1723 |
+
self.lastQuery = query;
|
1724 |
+
result = self.sifter.search(query, $.extend(options, {score: calculateScore}));
|
1725 |
+
self.currentResults = result;
|
1726 |
+
} else {
|
1727 |
+
result = $.extend(true, {}, self.currentResults);
|
1728 |
+
}
|
1729 |
+
|
1730 |
+
// filter out selected items
|
1731 |
+
if (settings.hideSelected) {
|
1732 |
+
for (i = result.items.length - 1; i >= 0; i--) {
|
1733 |
+
if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) {
|
1734 |
+
result.items.splice(i, 1);
|
1735 |
+
}
|
1736 |
+
}
|
1737 |
+
}
|
1738 |
+
|
1739 |
+
return result;
|
1740 |
+
},
|
1741 |
+
|
1742 |
+
/**
|
1743 |
+
* Refreshes the list of available options shown
|
1744 |
+
* in the autocomplete dropdown menu.
|
1745 |
+
*
|
1746 |
+
* @param {boolean} triggerDropdown
|
1747 |
+
*/
|
1748 |
+
refreshOptions: function(triggerDropdown) {
|
1749 |
+
if (typeof triggerDropdown === 'undefined') {
|
1750 |
+
triggerDropdown = true;
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
var self = this;
|
1754 |
+
var i, n, groups, groups_order, option, optgroup, html, html_children;
|
1755 |
+
var hasCreateOption;
|
1756 |
+
var query = self.$control_input.val();
|
1757 |
+
var results = self.search(query);
|
1758 |
+
var $active, $create;
|
1759 |
+
var $dropdown_content = self.$dropdown_content;
|
1760 |
+
|
1761 |
+
// build markup
|
1762 |
+
n = results.items.length;
|
1763 |
+
if (typeof self.settings.maxOptions === 'number') {
|
1764 |
+
n = Math.min(n, self.settings.maxOptions);
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
// render and group available options individually
|
1768 |
+
groups = {};
|
1769 |
+
|
1770 |
+
if (self.settings.optgroupOrder) {
|
1771 |
+
groups_order = self.settings.optgroupOrder;
|
1772 |
+
for (i = 0; i < groups_order.length; i++) {
|
1773 |
+
groups[groups_order[i]] = [];
|
1774 |
+
}
|
1775 |
+
} else {
|
1776 |
+
groups_order = [];
|
1777 |
+
}
|
1778 |
+
|
1779 |
+
for (i = 0; i < n; i++) {
|
1780 |
+
option = self.options[results.items[i].id];
|
1781 |
+
optgroup = option[self.settings.optgroupField] || '';
|
1782 |
+
if (!self.optgroups.hasOwnProperty(optgroup)) {
|
1783 |
+
optgroup = '';
|
1784 |
+
}
|
1785 |
+
if (!groups.hasOwnProperty(optgroup)) {
|
1786 |
+
groups[optgroup] = [];
|
1787 |
+
groups_order.push(optgroup);
|
1788 |
+
}
|
1789 |
+
groups[optgroup].push(self.render('option', option));
|
1790 |
+
}
|
1791 |
+
|
1792 |
+
// render optgroup headers & join groups
|
1793 |
+
html = [];
|
1794 |
+
for (i = 0, n = groups_order.length; i < n; i++) {
|
1795 |
+
optgroup = groups_order[i];
|
1796 |
+
if (self.optgroups.hasOwnProperty(optgroup) && groups[optgroup].length) {
|
1797 |
+
// render the optgroup header and options within it,
|
1798 |
+
// then pass it to the wrapper template
|
1799 |
+
html_children = self.render('optgroup_header', self.optgroups[optgroup]) || '';
|
1800 |
+
html_children += groups[optgroup].join('');
|
1801 |
+
html.push(self.render('optgroup', $.extend({}, self.optgroups[optgroup], {
|
1802 |
+
html: html_children
|
1803 |
+
})));
|
1804 |
+
} else {
|
1805 |
+
html.push(groups[optgroup].join(''));
|
1806 |
+
}
|
1807 |
+
}
|
1808 |
+
|
1809 |
+
$dropdown_content.html(html.join(''));
|
1810 |
+
|
1811 |
+
// highlight matching terms inline
|
1812 |
+
if (self.settings.highlight && results.query.length && results.tokens.length) {
|
1813 |
+
for (i = 0, n = results.tokens.length; i < n; i++) {
|
1814 |
+
highlight($dropdown_content, results.tokens[i].regex);
|
1815 |
+
}
|
1816 |
+
}
|
1817 |
+
|
1818 |
+
// add "selected" class to selected options
|
1819 |
+
if (!self.settings.hideSelected) {
|
1820 |
+
for (i = 0, n = self.items.length; i < n; i++) {
|
1821 |
+
self.getOption(self.items[i]).addClass('selected');
|
1822 |
+
}
|
1823 |
+
}
|
1824 |
+
|
1825 |
+
// add create option
|
1826 |
+
hasCreateOption = self.settings.create && results.query.length;
|
1827 |
+
if (hasCreateOption) {
|
1828 |
+
$dropdown_content.prepend(self.render('option_create', {input: query}));
|
1829 |
+
$create = $($dropdown_content[0].childNodes[0]);
|
1830 |
+
}
|
1831 |
+
|
1832 |
+
// activate
|
1833 |
+
self.hasOptions = results.items.length > 0 || hasCreateOption;
|
1834 |
+
if (self.hasOptions) {
|
1835 |
+
if (results.items.length > 0) {
|
1836 |
+
if ($create) {
|
1837 |
+
$active = self.getAdjacentOption($create, 1);
|
1838 |
+
} else {
|
1839 |
+
$active = $dropdown_content.find("[data-selectable]").first();
|
1840 |
+
}
|
1841 |
+
} else {
|
1842 |
+
$active = $create;
|
1843 |
+
}
|
1844 |
+
self.setActiveOption($active);
|
1845 |
+
if (triggerDropdown && !self.isOpen) { self.open(); }
|
1846 |
+
} else {
|
1847 |
+
self.setActiveOption(null);
|
1848 |
+
if (triggerDropdown && self.isOpen) { self.close(); }
|
1849 |
+
}
|
1850 |
+
},
|
1851 |
+
|
1852 |
+
/**
|
1853 |
+
* Adds an available option. If it already exists,
|
1854 |
+
* nothing will happen. Note: this does not refresh
|
1855 |
+
* the options list dropdown (use `refreshOptions`
|
1856 |
+
* for that).
|
1857 |
+
*
|
1858 |
+
* Usage:
|
1859 |
+
*
|
1860 |
+
* this.addOption(data)
|
1861 |
+
*
|
1862 |
+
* @param {object} data
|
1863 |
+
*/
|
1864 |
+
addOption: function(data) {
|
1865 |
+
var i, n, optgroup, value, self = this;
|
1866 |
+
|
1867 |
+
if ($.isArray(data)) {
|
1868 |
+
for (i = 0, n = data.length; i < n; i++) {
|
1869 |
+
self.addOption(data[i]);
|
1870 |
+
}
|
1871 |
+
return;
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
value = hash_key(data[self.settings.valueField]);
|
1875 |
+
if (!value || self.options.hasOwnProperty(value)) return;
|
1876 |
+
|
1877 |
+
self.userOptions[value] = true;
|
1878 |
+
self.options[value] = data;
|
1879 |
+
self.lastQuery = null;
|
1880 |
+
self.trigger('option_add', value, data);
|
1881 |
+
},
|
1882 |
+
|
1883 |
+
/**
|
1884 |
+
* Registers a new optgroup for options
|
1885 |
+
* to be bucketed into.
|
1886 |
+
*
|
1887 |
+
* @param {string} id
|
1888 |
+
* @param {object} data
|
1889 |
+
*/
|
1890 |
+
addOptionGroup: function(id, data) {
|
1891 |
+
this.optgroups[id] = data;
|
1892 |
+
this.trigger('optgroup_add', id, data);
|
1893 |
+
},
|
1894 |
+
|
1895 |
+
/**
|
1896 |
+
* Updates an option available for selection. If
|
1897 |
+
* it is visible in the selected items or options
|
1898 |
+
* dropdown, it will be re-rendered automatically.
|
1899 |
+
*
|
1900 |
+
* @param {string} value
|
1901 |
+
* @param {object} data
|
1902 |
+
*/
|
1903 |
+
updateOption: function(value, data) {
|
1904 |
+
var self = this;
|
1905 |
+
var $item, $item_new;
|
1906 |
+
var value_new, index_item, cache_items, cache_options;
|
1907 |
+
|
1908 |
+
value = hash_key(value);
|
1909 |
+
value_new = hash_key(data[self.settings.valueField]);
|
1910 |
+
|
1911 |
+
// sanity checks
|
1912 |
+
if (!self.options.hasOwnProperty(value)) return;
|
1913 |
+
if (!value_new) throw new Error('Value must be set in option data');
|
1914 |
+
|
1915 |
+
// update references
|
1916 |
+
if (value_new !== value) {
|
1917 |
+
delete self.options[value];
|
1918 |
+
index_item = self.items.indexOf(value);
|
1919 |
+
if (index_item !== -1) {
|
1920 |
+
self.items.splice(index_item, 1, value_new);
|
1921 |
+
}
|
1922 |
+
}
|
1923 |
+
self.options[value_new] = data;
|
1924 |
+
|
1925 |
+
// invalidate render cache
|
1926 |
+
cache_items = self.renderCache['item'];
|
1927 |
+
cache_options = self.renderCache['option'];
|
1928 |
+
|
1929 |
+
if (isset(cache_items)) {
|
1930 |
+
delete cache_items[value];
|
1931 |
+
delete cache_items[value_new];
|
1932 |
+
}
|
1933 |
+
if (isset(cache_options)) {
|
1934 |
+
delete cache_options[value];
|
1935 |
+
delete cache_options[value_new];
|
1936 |
+
}
|
1937 |
+
|
1938 |
+
// update the item if it's selected
|
1939 |
+
if (self.items.indexOf(value_new) !== -1) {
|
1940 |
+
$item = self.getItem(value);
|
1941 |
+
$item_new = $(self.render('item', data));
|
1942 |
+
if ($item.hasClass('active')) $item_new.addClass('active');
|
1943 |
+
$item.replaceWith($item_new);
|
1944 |
+
}
|
1945 |
+
|
1946 |
+
// update dropdown contents
|
1947 |
+
if (self.isOpen) {
|
1948 |
+
self.refreshOptions(false);
|
1949 |
+
}
|
1950 |
+
},
|
1951 |
+
|
1952 |
+
/**
|
1953 |
+
* Removes a single option.
|
1954 |
+
*
|
1955 |
+
* @param {string} value
|
1956 |
+
*/
|
1957 |
+
removeOption: function(value) {
|
1958 |
+
var self = this;
|
1959 |
+
|
1960 |
+
value = hash_key(value);
|
1961 |
+
delete self.userOptions[value];
|
1962 |
+
delete self.options[value];
|
1963 |
+
self.lastQuery = null;
|
1964 |
+
self.trigger('option_remove', value);
|
1965 |
+
self.removeItem(value);
|
1966 |
+
},
|
1967 |
+
|
1968 |
+
/**
|
1969 |
+
* Clears all options.
|
1970 |
+
*/
|
1971 |
+
clearOptions: function() {
|
1972 |
+
var self = this;
|
1973 |
+
|
1974 |
+
self.loadedSearches = {};
|
1975 |
+
self.userOptions = {};
|
1976 |
+
self.options = self.sifter.items = {};
|
1977 |
+
self.lastQuery = null;
|
1978 |
+
self.trigger('option_clear');
|
1979 |
+
self.clear();
|
1980 |
+
},
|
1981 |
+
|
1982 |
+
/**
|
1983 |
+
* Returns the jQuery element of the option
|
1984 |
+
* matching the given value.
|
1985 |
+
*
|
1986 |
+
* @param {string} value
|
1987 |
+
* @returns {object}
|
1988 |
+
*/
|
1989 |
+
getOption: function(value) {
|
1990 |
+
return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]'));
|
1991 |
+
},
|
1992 |
+
|
1993 |
+
/**
|
1994 |
+
* Returns the jQuery element of the next or
|
1995 |
+
* previous selectable option.
|
1996 |
+
*
|
1997 |
+
* @param {object} $option
|
1998 |
+
* @param {int} direction can be 1 for next or -1 for previous
|
1999 |
+
* @return {object}
|
2000 |
+
*/
|
2001 |
+
getAdjacentOption: function($option, direction) {
|
2002 |
+
var $options = this.$dropdown.find('[data-selectable]');
|
2003 |
+
var index = $options.index($option) + direction;
|
2004 |
+
|
2005 |
+
return index >= 0 && index < $options.length ? $options.eq(index) : $();
|
2006 |
+
},
|
2007 |
+
|
2008 |
+
/**
|
2009 |
+
* Finds the first element with a "data-value" attribute
|
2010 |
+
* that matches the given value.
|
2011 |
+
*
|
2012 |
+
* @param {mixed} value
|
2013 |
+
* @param {object} $els
|
2014 |
+
* @return {object}
|
2015 |
+
*/
|
2016 |
+
getElementWithValue: function(value, $els) {
|
2017 |
+
value = hash_key(value);
|
2018 |
+
|
2019 |
+
if (value) {
|
2020 |
+
for (var i = 0, n = $els.length; i < n; i++) {
|
2021 |
+
if ($els[i].getAttribute('data-value') === value) {
|
2022 |
+
return $($els[i]);
|
2023 |
+
}
|
2024 |
+
}
|
2025 |
+
}
|
2026 |
+
|
2027 |
+
return $();
|
2028 |
+
},
|
2029 |
+
|
2030 |
+
/**
|
2031 |
+
* Returns the jQuery element of the item
|
2032 |
+
* matching the given value.
|
2033 |
+
*
|
2034 |
+
* @param {string} value
|
2035 |
+
* @returns {object}
|
2036 |
+
*/
|
2037 |
+
getItem: function(value) {
|
2038 |
+
return this.getElementWithValue(value, this.$control.children());
|
2039 |
+
},
|
2040 |
+
|
2041 |
+
/**
|
2042 |
+
* "Selects" an item. Adds it to the list
|
2043 |
+
* at the current caret position.
|
2044 |
+
*
|
2045 |
+
* @param {string} value
|
2046 |
+
*/
|
2047 |
+
addItem: function(value) {
|
2048 |
+
debounce_events(this, ['change'], function() {
|
2049 |
+
var $item, $option;
|
2050 |
+
var self = this;
|
2051 |
+
var inputMode = self.settings.mode;
|
2052 |
+
var i, active, options, value_next;
|
2053 |
+
value = hash_key(value);
|
2054 |
+
|
2055 |
+
if (inputMode === 'single') self.clear();
|
2056 |
+
if (inputMode === 'multi' && self.isFull()) return;
|
2057 |
+
if (self.items.indexOf(value) !== -1) return;
|
2058 |
+
if (!self.options.hasOwnProperty(value)) return;
|
2059 |
+
|
2060 |
+
$item = $(self.render('item', self.options[value]));
|
2061 |
+
self.items.splice(self.caretPos, 0, value);
|
2062 |
+
self.insertAtCaret($item);
|
2063 |
+
self.refreshClasses();
|
2064 |
+
|
2065 |
+
if (self.isSetup) {
|
2066 |
+
options = self.$dropdown_content.find('[data-selectable]');
|
2067 |
+
|
2068 |
+
// update menu / remove the option
|
2069 |
+
$option = self.getOption(value);
|
2070 |
+
value_next = self.getAdjacentOption($option, 1).attr('data-value');
|
2071 |
+
self.refreshOptions(self.isFocused && inputMode !== 'single');
|
2072 |
+
if (value_next) {
|
2073 |
+
self.setActiveOption(self.getOption(value_next));
|
2074 |
+
}
|
2075 |
+
|
2076 |
+
// hide the menu if the maximum number of items have been selected or no options are left
|
2077 |
+
if (!options.length || (self.settings.maxItems !== null && self.items.length >= self.settings.maxItems)) {
|
2078 |
+
self.close();
|
2079 |
+
} else {
|
2080 |
+
self.positionDropdown();
|
2081 |
+
}
|
2082 |
+
|
2083 |
+
// restore focus to input
|
2084 |
+
if (self.isFocused) {
|
2085 |
+
window.setTimeout(function() {
|
2086 |
+
if (inputMode === 'single') {
|
2087 |
+
self.blur();
|
2088 |
+
self.focus(false);
|
2089 |
+
self.hideInput();
|
2090 |
+
} else {
|
2091 |
+
self.focus(false);
|
2092 |
+
}
|
2093 |
+
}, 0);
|
2094 |
+
}
|
2095 |
+
|
2096 |
+
self.updatePlaceholder();
|
2097 |
+
self.trigger('item_add', value, $item);
|
2098 |
+
self.updateOriginalInput();
|
2099 |
+
}
|
2100 |
+
});
|
2101 |
+
},
|
2102 |
+
|
2103 |
+
/**
|
2104 |
+
* Removes the selected item matching
|
2105 |
+
* the provided value.
|
2106 |
+
*
|
2107 |
+
* @param {string} value
|
2108 |
+
*/
|
2109 |
+
removeItem: function(value) {
|
2110 |
+
var self = this;
|
2111 |
+
var $item, i, idx;
|
2112 |
+
|
2113 |
+
$item = (typeof value === 'object') ? value : self.getItem(value);
|
2114 |
+
value = hash_key($item.attr('data-value'));
|
2115 |
+
i = self.items.indexOf(value);
|
2116 |
+
|
2117 |
+
if (i !== -1) {
|
2118 |
+
$item.remove();
|
2119 |
+
if ($item.hasClass('active')) {
|
2120 |
+
idx = self.$activeItems.indexOf($item[0]);
|
2121 |
+
self.$activeItems.splice(idx, 1);
|
2122 |
+
}
|
2123 |
+
|
2124 |
+
self.items.splice(i, 1);
|
2125 |
+
self.lastQuery = null;
|
2126 |
+
if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) {
|
2127 |
+
self.removeOption(value);
|
2128 |
+
}
|
2129 |
+
|
2130 |
+
if (i < self.caretPos) {
|
2131 |
+
self.setCaret(self.caretPos - 1);
|
2132 |
+
}
|
2133 |
+
|
2134 |
+
self.refreshClasses();
|
2135 |
+
self.updatePlaceholder();
|
2136 |
+
self.updateOriginalInput();
|
2137 |
+
self.positionDropdown();
|
2138 |
+
self.trigger('item_remove', value);
|
2139 |
+
}
|
2140 |
+
},
|
2141 |
+
|
2142 |
+
/**
|
2143 |
+
* Invokes the `create` method provided in the
|
2144 |
+
* selectize options that should provide the data
|
2145 |
+
* for the new item, given the user input.
|
2146 |
+
*
|
2147 |
+
* Once this completes, it will be added
|
2148 |
+
* to the item list.
|
2149 |
+
*/
|
2150 |
+
createItem: function() {
|
2151 |
+
var self = this;
|
2152 |
+
var input = $.trim(self.$control_input.val() || '');
|
2153 |
+
var caret = self.caretPos;
|
2154 |
+
if (!input.length) return;
|
2155 |
+
self.lock();
|
2156 |
+
|
2157 |
+
var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
|
2158 |
+
var data = {};
|
2159 |
+
data[self.settings.labelField] = input;
|
2160 |
+
data[self.settings.valueField] = input;
|
2161 |
+
return data;
|
2162 |
+
};
|
2163 |
+
|
2164 |
+
var create = once(function(data) {
|
2165 |
+
self.unlock();
|
2166 |
+
self.focus(false);
|
2167 |
+
|
2168 |
+
if (!data || typeof data !== 'object') return;
|
2169 |
+
var value = hash_key(data[self.settings.valueField]);
|
2170 |
+
if (!value) return;
|
2171 |
+
|
2172 |
+
self.setTextboxValue('');
|
2173 |
+
self.addOption(data);
|
2174 |
+
self.setCaret(caret);
|
2175 |
+
self.addItem(value);
|
2176 |
+
self.refreshOptions(self.settings.mode !== 'single');
|
2177 |
+
self.focus(false);
|
2178 |
+
});
|
2179 |
+
|
2180 |
+
var output = setup.apply(this, [input, create]);
|
2181 |
+
if (typeof output !== 'undefined') {
|
2182 |
+
create(output);
|
2183 |
+
}
|
2184 |
+
},
|
2185 |
+
|
2186 |
+
/**
|
2187 |
+
* Re-renders the selected item lists.
|
2188 |
+
*/
|
2189 |
+
refreshItems: function() {
|
2190 |
+
this.lastQuery = null;
|
2191 |
+
|
2192 |
+
if (this.isSetup) {
|
2193 |
+
for (var i = 0; i < this.items.length; i++) {
|
2194 |
+
this.addItem(this.items);
|
2195 |
+
}
|
2196 |
+
}
|
2197 |
+
|
2198 |
+
this.refreshClasses();
|
2199 |
+
this.updateOriginalInput();
|
2200 |
+
},
|
2201 |
+
|
2202 |
+
/**
|
2203 |
+
* Updates all state-dependent CSS classes.
|
2204 |
+
*/
|
2205 |
+
refreshClasses: function() {
|
2206 |
+
var self = this;
|
2207 |
+
var isFull = self.isFull();
|
2208 |
+
var isLocked = self.isLocked;
|
2209 |
+
this.$control
|
2210 |
+
.toggleClass('focus', self.isFocused)
|
2211 |
+
.toggleClass('disabled', self.isDisabled)
|
2212 |
+
.toggleClass('locked', isLocked)
|
2213 |
+
.toggleClass('full', isFull).toggleClass('not-full', !isFull)
|
2214 |
+
.toggleClass('dropdown-active', self.isOpen)
|
2215 |
+
.toggleClass('has-options', !$.isEmptyObject(self.options))
|
2216 |
+
.toggleClass('has-items', self.items.length > 0);
|
2217 |
+
this.$control_input.data('grow', !isFull && !isLocked);
|
2218 |
+
},
|
2219 |
+
|
2220 |
+
/**
|
2221 |
+
* Determines whether or not more items can be added
|
2222 |
+
* to the control without exceeding the user-defined maximum.
|
2223 |
+
*
|
2224 |
+
* @returns {boolean}
|
2225 |
+
*/
|
2226 |
+
isFull: function() {
|
2227 |
+
return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems;
|
2228 |
+
},
|
2229 |
+
|
2230 |
+
/**
|
2231 |
+
* Refreshes the original <select> or <input>
|
2232 |
+
* element to reflect the current state.
|
2233 |
+
*/
|
2234 |
+
updateOriginalInput: function() {
|
2235 |
+
var i, n, options, self = this;
|
2236 |
+
|
2237 |
+
if (self.$input[0].tagName.toLowerCase() === 'select') {
|
2238 |
+
options = [];
|
2239 |
+
for (i = 0, n = self.items.length; i < n; i++) {
|
2240 |
+
options.push('<option value="' + escape_html(self.items[i]) + '" selected="selected"></option>');
|
2241 |
+
}
|
2242 |
+
if (!options.length && !this.$input.attr('multiple')) {
|
2243 |
+
options.push('<option value="" selected="selected"></option>');
|
2244 |
+
}
|
2245 |
+
self.$input.html(options.join(''));
|
2246 |
+
} else {
|
2247 |
+
self.$input.val(self.getValue());
|
2248 |
+
}
|
2249 |
+
|
2250 |
+
if (self.isSetup) {
|
2251 |
+
self.trigger('change', self.$input.val());
|
2252 |
+
}
|
2253 |
+
},
|
2254 |
+
|
2255 |
+
/**
|
2256 |
+
* Shows/hide the input placeholder depending
|
2257 |
+
* on if there items in the list already.
|
2258 |
+
*/
|
2259 |
+
updatePlaceholder: function() {
|
2260 |
+
if (!this.settings.placeholder) return;
|
2261 |
+
var $input = this.$control_input;
|
2262 |
+
|
2263 |
+
if (this.items.length) {
|
2264 |
+
$input.removeAttr('placeholder');
|
2265 |
+
} else {
|
2266 |
+
$input.attr('placeholder', this.settings.placeholder);
|
2267 |
+
}
|
2268 |
+
$input.triggerHandler('update');
|
2269 |
+
},
|
2270 |
+
|
2271 |
+
/**
|
2272 |
+
* Shows the autocomplete dropdown containing
|
2273 |
+
* the available options.
|
2274 |
+
*/
|
2275 |
+
open: function() {
|
2276 |
+
var self = this;
|
2277 |
+
|
2278 |
+
if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return;
|
2279 |
+
self.focus(true);
|
2280 |
+
self.isOpen = true;
|
2281 |
+
self.refreshClasses();
|
2282 |
+
self.$dropdown.css({visibility: 'hidden', display: 'block'});
|
2283 |
+
self.positionDropdown();
|
2284 |
+
self.$dropdown.css({visibility: 'visible'});
|
2285 |
+
self.trigger('dropdown_open', this.$dropdown);
|
2286 |
+
},
|
2287 |
+
|
2288 |
+
/**
|
2289 |
+
* Closes the autocomplete dropdown menu.
|
2290 |
+
*/
|
2291 |
+
close: function() {
|
2292 |
+
var self = this;
|
2293 |
+
|
2294 |
+
if (!self.isOpen) return;
|
2295 |
+
self.$dropdown.hide();
|
2296 |
+
self.setActiveOption(null);
|
2297 |
+
self.isOpen = false;
|
2298 |
+
self.refreshClasses();
|
2299 |
+
self.trigger('dropdown_close', self.$dropdown);
|
2300 |
+
},
|
2301 |
+
|
2302 |
+
/**
|
2303 |
+
* Calculates and applies the appropriate
|
2304 |
+
* position of the dropdown.
|
2305 |
+
*/
|
2306 |
+
positionDropdown: function() {
|
2307 |
+
var $control = this.$control;
|
2308 |
+
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
|
2309 |
+
offset.top += $control.outerHeight(true);
|
2310 |
+
|
2311 |
+
this.$dropdown.css({
|
2312 |
+
width : $control.outerWidth(),
|
2313 |
+
top : offset.top,
|
2314 |
+
left : offset.left
|
2315 |
+
});
|
2316 |
+
},
|
2317 |
+
|
2318 |
+
/**
|
2319 |
+
* Resets / clears all selected items
|
2320 |
+
* from the control.
|
2321 |
+
*/
|
2322 |
+
clear: function() {
|
2323 |
+
var self = this;
|
2324 |
+
|
2325 |
+
if (!self.items.length) return;
|
2326 |
+
self.$control.children(':not(input)').remove();
|
2327 |
+
self.items = [];
|
2328 |
+
self.setCaret(0);
|
2329 |
+
self.updatePlaceholder();
|
2330 |
+
self.updateOriginalInput();
|
2331 |
+
self.refreshClasses();
|
2332 |
+
self.showInput();
|
2333 |
+
self.trigger('clear');
|
2334 |
+
},
|
2335 |
+
|
2336 |
+
/**
|
2337 |
+
* A helper method for inserting an element
|
2338 |
+
* at the current caret position.
|
2339 |
+
*
|
2340 |
+
* @param {object} $el
|
2341 |
+
*/
|
2342 |
+
insertAtCaret: function($el) {
|
2343 |
+
var caret = Math.min(this.caretPos, this.items.length);
|
2344 |
+
if (caret === 0) {
|
2345 |
+
this.$control.prepend($el);
|
2346 |
+
} else {
|
2347 |
+
$(this.$control[0].childNodes[caret]).before($el);
|
2348 |
+
}
|
2349 |
+
this.setCaret(caret + 1);
|
2350 |
+
},
|
2351 |
+
|
2352 |
+
/**
|
2353 |
+
* Removes the current selected item(s).
|
2354 |
+
*
|
2355 |
+
* @param {object} e (optional)
|
2356 |
+
* @returns {boolean}
|
2357 |
+
*/
|
2358 |
+
deleteSelection: function(e) {
|
2359 |
+
var i, n, direction, selection, values, caret, option_select, $option_select, $tail;
|
2360 |
+
var self = this;
|
2361 |
+
|
2362 |
+
direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1;
|
2363 |
+
selection = getSelection(self.$control_input[0]);
|
2364 |
+
|
2365 |
+
if (self.$activeOption && !self.settings.hideSelected) {
|
2366 |
+
option_select = self.getAdjacentOption(self.$activeOption, -1).attr('data-value');
|
2367 |
+
}
|
2368 |
+
|
2369 |
+
// determine items that will be removed
|
2370 |
+
values = [];
|
2371 |
+
|
2372 |
+
if (self.$activeItems.length) {
|
2373 |
+
$tail = self.$control.children('.active:' + (direction > 0 ? 'last' : 'first'));
|
2374 |
+
caret = self.$control.children(':not(input)').index($tail);
|
2375 |
+
if (direction > 0) { caret++; }
|
2376 |
+
|
2377 |
+
for (i = 0, n = self.$activeItems.length; i < n; i++) {
|
2378 |
+
values.push($(self.$activeItems[i]).attr('data-value'));
|
2379 |
+
}
|
2380 |
+
if (e) {
|
2381 |
+
e.preventDefault();
|
2382 |
+
e.stopPropagation();
|
2383 |
+
}
|
2384 |
+
} else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) {
|
2385 |
+
if (direction < 0 && selection.start === 0 && selection.length === 0) {
|
2386 |
+
values.push(self.items[self.caretPos - 1]);
|
2387 |
+
} else if (direction > 0 && selection.start === self.$control_input.val().length) {
|
2388 |
+
values.push(self.items[self.caretPos]);
|
2389 |
+
}
|
2390 |
+
}
|
2391 |
+
|
2392 |
+
// allow the callback to abort
|
2393 |
+
if (!values.length || (typeof self.settings.onDelete === 'function' && self.settings.onDelete.apply(self, [values]) === false)) {
|
2394 |
+
return false;
|
2395 |
+
}
|
2396 |
+
|
2397 |
+
// perform removal
|
2398 |
+
if (typeof caret !== 'undefined') {
|
2399 |
+
self.setCaret(caret);
|
2400 |
+
}
|
2401 |
+
while (values.length) {
|
2402 |
+
self.removeItem(values.pop());
|
2403 |
+
}
|
2404 |
+
|
2405 |
+
self.showInput();
|
2406 |
+
self.refreshOptions(true);
|
2407 |
+
|
2408 |
+
// select previous option
|
2409 |
+
if (option_select) {
|
2410 |
+
$option_select = self.getOption(option_select);
|
2411 |
+
if ($option_select.length) {
|
2412 |
+
self.setActiveOption($option_select);
|
2413 |
+
}
|
2414 |
+
}
|
2415 |
+
|
2416 |
+
return true;
|
2417 |
+
},
|
2418 |
+
|
2419 |
+
/**
|
2420 |
+
* Selects the previous / next item (depending
|
2421 |
+
* on the `direction` argument).
|
2422 |
+
*
|
2423 |
+
* > 0 - right
|
2424 |
+
* < 0 - left
|
2425 |
+
*
|
2426 |
+
* @param {int} direction
|
2427 |
+
* @param {object} e (optional)
|
2428 |
+
*/
|
2429 |
+
advanceSelection: function(direction, e) {
|
2430 |
+
var tail, selection, idx, valueLength, cursorAtEdge, $tail;
|
2431 |
+
var self = this;
|
2432 |
+
|
2433 |
+
if (direction === 0) return;
|
2434 |
+
|
2435 |
+
tail = direction > 0 ? 'last' : 'first';
|
2436 |
+
selection = getSelection(self.$control_input[0]);
|
2437 |
+
|
2438 |
+
if (self.isInputFocused && !self.isInputHidden) {
|
2439 |
+
valueLength = self.$control_input.val().length;
|
2440 |
+
cursorAtEdge = direction < 0
|
2441 |
+
? selection.start === 0 && selection.length === 0
|
2442 |
+
: selection.start === valueLength;
|
2443 |
+
|
2444 |
+
if (cursorAtEdge && !valueLength) {
|
2445 |
+
self.advanceCaret(direction, e);
|
2446 |
+
}
|
2447 |
+
} else {
|
2448 |
+
$tail = self.$control.children('.active:' + tail);
|
2449 |
+
if ($tail.length) {
|
2450 |
+
idx = self.$control.children(':not(input)').index($tail);
|
2451 |
+
self.setActiveItem(null);
|
2452 |
+
self.setCaret(direction > 0 ? idx + 1 : idx);
|
2453 |
+
self.showInput();
|
2454 |
+
}
|
2455 |
+
}
|
2456 |
+
},
|
2457 |
+
|
2458 |
+
/**
|
2459 |
+
* Moves the caret left / right.
|
2460 |
+
*
|
2461 |
+
* @param {int} direction
|
2462 |
+
* @param {object} e (optional)
|
2463 |
+
*/
|
2464 |
+
advanceCaret: function(direction, e) {
|
2465 |
+
if (direction === 0) return;
|
2466 |
+
var self = this;
|
2467 |
+
var fn = direction > 0 ? 'next' : 'prev';
|
2468 |
+
if (self.isShiftDown) {
|
2469 |
+
var $adj = self.$control_input[fn]();
|
2470 |
+
if ($adj.length) {
|
2471 |
+
self.hideInput();
|
2472 |
+
self.setActiveItem($adj);
|
2473 |
+
e && e.preventDefault();
|
2474 |
+
}
|
2475 |
+
} else {
|
2476 |
+
self.setCaret(self.caretPos + direction);
|
2477 |
+
}
|
2478 |
+
},
|
2479 |
+
|
2480 |
+
/**
|
2481 |
+
* Moves the caret to the specified index.
|
2482 |
+
*
|
2483 |
+
* @param {int} i
|
2484 |
+
*/
|
2485 |
+
setCaret: function(i) {
|
2486 |
+
var self = this;
|
2487 |
+
|
2488 |
+
if (self.settings.mode === 'single') {
|
2489 |
+
i = self.items.length;
|
2490 |
+
} else {
|
2491 |
+
i = Math.max(0, Math.min(self.items.length, i));
|
2492 |
+
}
|
2493 |
+
|
2494 |
+
// the input must be moved by leaving it in place and moving the
|
2495 |
+
// siblings, due to the fact that focus cannot be restored once lost
|
2496 |
+
// on mobile webkit devices
|
2497 |
+
var j, n, fn, $children, $child;
|
2498 |
+
$children = self.$control.children(':not(input)');
|
2499 |
+
for (j = 0, n = $children.length; j < n; j++) {
|
2500 |
+
$child = $($children[j]).detach();
|
2501 |
+
if (j < i) {
|
2502 |
+
self.$control_input.before($child);
|
2503 |
+
} else {
|
2504 |
+
self.$control.append($child);
|
2505 |
+
}
|
2506 |
+
}
|
2507 |
+
|
2508 |
+
self.caretPos = i;
|
2509 |
+
},
|
2510 |
+
|
2511 |
+
/**
|
2512 |
+
* Disables user input on the control. Used while
|
2513 |
+
* items are being asynchronously created.
|
2514 |
+
*/
|
2515 |
+
lock: function() {
|
2516 |
+
this.close();
|
2517 |
+
this.isLocked = true;
|
2518 |
+
this.refreshClasses();
|
2519 |
+
},
|
2520 |
+
|
2521 |
+
/**
|
2522 |
+
* Re-enables user input on the control.
|
2523 |
+
*/
|
2524 |
+
unlock: function() {
|
2525 |
+
this.isLocked = false;
|
2526 |
+
this.refreshClasses();
|
2527 |
+
},
|
2528 |
+
|
2529 |
+
/**
|
2530 |
+
* Disables user input on the control completely.
|
2531 |
+
* While disabled, it cannot receive focus.
|
2532 |
+
*/
|
2533 |
+
disable: function() {
|
2534 |
+
var self = this;
|
2535 |
+
self.$input.prop('disabled', true);
|
2536 |
+
self.isDisabled = true;
|
2537 |
+
self.lock();
|
2538 |
+
},
|
2539 |
+
|
2540 |
+
/**
|
2541 |
+
* Enables the control so that it can respond
|
2542 |
+
* to focus and user input.
|
2543 |
+
*/
|
2544 |
+
enable: function() {
|
2545 |
+
var self = this;
|
2546 |
+
self.$input.prop('disabled', false);
|
2547 |
+
self.isDisabled = false;
|
2548 |
+
self.unlock();
|
2549 |
+
},
|
2550 |
+
|
2551 |
+
/**
|
2552 |
+
* Completely destroys the control and
|
2553 |
+
* unbinds all event listeners so that it can
|
2554 |
+
* be garbage collected.
|
2555 |
+
*/
|
2556 |
+
destroy: function() {
|
2557 |
+
var self = this;
|
2558 |
+
var eventNS = self.eventNS;
|
2559 |
+
|
2560 |
+
self.trigger('destroy');
|
2561 |
+
self.off();
|
2562 |
+
self.$wrapper.remove();
|
2563 |
+
self.$dropdown.remove();
|
2564 |
+
self.$input.show();
|
2565 |
+
|
2566 |
+
$(window).off(eventNS);
|
2567 |
+
$(document).off(eventNS);
|
2568 |
+
$(document.body).off(eventNS);
|
2569 |
+
|
2570 |
+
delete self.$input[0].selectize;
|
2571 |
+
},
|
2572 |
+
|
2573 |
+
/**
|
2574 |
+
* A helper method for rendering "item" and
|
2575 |
+
* "option" templates, given the data.
|
2576 |
+
*
|
2577 |
+
* @param {string} templateName
|
2578 |
+
* @param {object} data
|
2579 |
+
* @returns {string}
|
2580 |
+
*/
|
2581 |
+
render: function(templateName, data) {
|
2582 |
+
var value, id, label;
|
2583 |
+
var html = '';
|
2584 |
+
var cache = false;
|
2585 |
+
var self = this;
|
2586 |
+
var regex_tag = /^[\t ]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;
|
2587 |
+
|
2588 |
+
if (templateName === 'option' || templateName === 'item') {
|
2589 |
+
value = hash_key(data[self.settings.valueField]);
|
2590 |
+
cache = !!value;
|
2591 |
+
}
|
2592 |
+
|
2593 |
+
// pull markup from cache if it exists
|
2594 |
+
if (cache) {
|
2595 |
+
if (!isset(self.renderCache[templateName])) {
|
2596 |
+
self.renderCache[templateName] = {};
|
2597 |
+
}
|
2598 |
+
if (self.renderCache[templateName].hasOwnProperty(value)) {
|
2599 |
+
return self.renderCache[templateName][value];
|
2600 |
+
}
|
2601 |
+
}
|
2602 |
+
|
2603 |
+
// render markup
|
2604 |
+
html = self.settings.render[templateName].apply(this, [data, escape_html]);
|
2605 |
+
|
2606 |
+
// add mandatory attributes
|
2607 |
+
if (templateName === 'option' || templateName === 'option_create') {
|
2608 |
+
html = html.replace(regex_tag, '<$1 data-selectable');
|
2609 |
+
}
|
2610 |
+
if (templateName === 'optgroup') {
|
2611 |
+
id = data[self.settings.optgroupValueField] || '';
|
2612 |
+
html = html.replace(regex_tag, '<$1 data-group="' + escape_html(id) + '"');
|
2613 |
+
}
|
2614 |
+
if (templateName === 'option' || templateName === 'item') {
|
2615 |
+
html = html.replace(regex_tag, '<$1 data-value="' + escape_html(value || '') + '"');
|
2616 |
+
}
|
2617 |
+
|
2618 |
+
// update cache
|
2619 |
+
if (cache) {
|
2620 |
+
self.renderCache[templateName][value] = html;
|
2621 |
+
}
|
2622 |
+
|
2623 |
+
return html;
|
2624 |
+
}
|
2625 |
+
|
2626 |
+
});
|
2627 |
+
|
2628 |
+
Selectize.count = 0;
|
2629 |
+
Selectize.defaults = {
|
2630 |
+
plugins: [],
|
2631 |
+
delimiter: ',',
|
2632 |
+
persist: true,
|
2633 |
+
diacritics: true,
|
2634 |
+
create: false,
|
2635 |
+
highlight: true,
|
2636 |
+
openOnFocus: true,
|
2637 |
+
maxOptions: 1000,
|
2638 |
+
maxItems: null,
|
2639 |
+
hideSelected: null,
|
2640 |
+
preload: false,
|
2641 |
+
|
2642 |
+
scrollDuration: 60,
|
2643 |
+
loadThrottle: 300,
|
2644 |
+
|
2645 |
+
dataAttr: 'data-data',
|
2646 |
+
optgroupField: 'optgroup',
|
2647 |
+
sortField: '$order',
|
2648 |
+
sortDirection: 'asc',
|
2649 |
+
valueField: 'value',
|
2650 |
+
labelField: 'text',
|
2651 |
+
optgroupLabelField: 'label',
|
2652 |
+
optgroupValueField: 'value',
|
2653 |
+
optgroupOrder: null,
|
2654 |
+
searchField: ['text'],
|
2655 |
+
|
2656 |
+
mode: null,
|
2657 |
+
wrapperClass: 'selectize-control',
|
2658 |
+
inputClass: 'selectize-input',
|
2659 |
+
dropdownClass: 'selectize-dropdown',
|
2660 |
+
dropdownContentClass: 'selectize-dropdown-content',
|
2661 |
+
|
2662 |
+
dropdownParent: null,
|
2663 |
+
|
2664 |
+
/*
|
2665 |
+
load : null, // function(query, callback) { ... }
|
2666 |
+
score : null, // function(search) { ... }
|
2667 |
+
onInitialize : null, // function() { ... }
|
2668 |
+
onChange : null, // function(value) { ... }
|
2669 |
+
onItemAdd : null, // function(value, $item) { ... }
|
2670 |
+
onItemRemove : null, // function(value) { ... }
|
2671 |
+
onClear : null, // function() { ... }
|
2672 |
+
onOptionAdd : null, // function(value, data) { ... }
|
2673 |
+
onOptionRemove : null, // function(value) { ... }
|
2674 |
+
onOptionClear : null, // function() { ... }
|
2675 |
+
onDropdownOpen : null, // function($dropdown) { ... }
|
2676 |
+
onDropdownClose : null, // function($dropdown) { ... }
|
2677 |
+
onType : null, // function(str) { ... }
|
2678 |
+
onDelete : null, // function(values) { ... }
|
2679 |
+
*/
|
2680 |
+
|
2681 |
+
render: {
|
2682 |
+
/*
|
2683 |
+
item: null,
|
2684 |
+
optgroup: null,
|
2685 |
+
optgroup_header: null,
|
2686 |
+
option: null,
|
2687 |
+
option_create: null
|
2688 |
+
*/
|
2689 |
+
}
|
2690 |
+
};
|
2691 |
+
|
2692 |
+
$.fn.selectize = function(settings) {
|
2693 |
+
settings = settings || {};
|
2694 |
+
|
2695 |
+
var defaults = $.fn.selectize.defaults;
|
2696 |
+
var dataAttr = settings.dataAttr || defaults.dataAttr;
|
2697 |
+
|
2698 |
+
/**
|
2699 |
+
* Initializes selectize from a <input type="text"> element.
|
2700 |
+
*
|
2701 |
+
* @param {object} $input
|
2702 |
+
* @param {object} settings
|
2703 |
+
*/
|
2704 |
+
var init_textbox = function($input, settings_element) {
|
2705 |
+
var i, n, values, value = $.trim($input.val() || '');
|
2706 |
+
if (!value.length) return;
|
2707 |
+
|
2708 |
+
values = value.split(settings.delimiter || defaults.delimiter);
|
2709 |
+
for (i = 0, n = values.length; i < n; i++) {
|
2710 |
+
settings_element.options[values[i]] = {
|
2711 |
+
'text' : values[i],
|
2712 |
+
'value' : values[i]
|
2713 |
+
};
|
2714 |
+
}
|
2715 |
+
|
2716 |
+
settings_element.items = values;
|
2717 |
+
};
|
2718 |
+
|
2719 |
+
/**
|
2720 |
+
* Initializes selectize from a <select> element.
|
2721 |
+
*
|
2722 |
+
* @param {object} $input
|
2723 |
+
* @param {object} settings
|
2724 |
+
*/
|
2725 |
+
var init_select = function($input, settings_element) {
|
2726 |
+
var i, n, tagName;
|
2727 |
+
var $children;
|
2728 |
+
var order = 0;
|
2729 |
+
settings_element.maxItems = !!$input.attr('multiple') ? null : 1;
|
2730 |
+
|
2731 |
+
var readData = function($el) {
|
2732 |
+
var data = dataAttr && $el.attr(dataAttr);
|
2733 |
+
if (typeof data === 'string' && data.length) {
|
2734 |
+
return JSON.parse(data);
|
2735 |
+
}
|
2736 |
+
return null;
|
2737 |
+
};
|
2738 |
+
|
2739 |
+
var addOption = function($option, group) {
|
2740 |
+
var value, option;
|
2741 |
+
|
2742 |
+
$option = $($option);
|
2743 |
+
|
2744 |
+
value = $option.attr('value') || '';
|
2745 |
+
if (!value.length) return;
|
2746 |
+
|
2747 |
+
option = readData($option) || {
|
2748 |
+
'text' : $option.text(),
|
2749 |
+
'value' : value,
|
2750 |
+
'optgroup' : group
|
2751 |
+
};
|
2752 |
+
|
2753 |
+
option.$order = ++order;
|
2754 |
+
settings_element.options[value] = option;
|
2755 |
+
|
2756 |
+
if ($option.is(':selected')) {
|
2757 |
+
settings_element.items.push(value);
|
2758 |
+
}
|
2759 |
+
};
|
2760 |
+
|
2761 |
+
var addGroup = function($optgroup) {
|
2762 |
+
var i, n, $options = $('option', $optgroup);
|
2763 |
+
$optgroup = $($optgroup);
|
2764 |
+
|
2765 |
+
var id = $optgroup.attr('label');
|
2766 |
+
if (id && id.length) {
|
2767 |
+
settings_element.optgroups[id] = readData($optgroup) || {
|
2768 |
+
'label': id
|
2769 |
+
};
|
2770 |
+
}
|
2771 |
+
|
2772 |
+
for (i = 0, n = $options.length; i < n; i++) {
|
2773 |
+
addOption($options[i], id);
|
2774 |
+
}
|
2775 |
+
};
|
2776 |
+
|
2777 |
+
$children = $input.children();
|
2778 |
+
for (i = 0, n = $children.length; i < n; i++) {
|
2779 |
+
tagName = $children[i].tagName.toLowerCase();
|
2780 |
+
if (tagName === 'optgroup') {
|
2781 |
+
addGroup($children[i]);
|
2782 |
+
} else if (tagName === 'option') {
|
2783 |
+
addOption($children[i]);
|
2784 |
+
}
|
2785 |
+
}
|
2786 |
+
};
|
2787 |
+
|
2788 |
+
return this.each(function() {
|
2789 |
+
var instance;
|
2790 |
+
var $input = $(this);
|
2791 |
+
var tag_name = $input[0].tagName.toLowerCase();
|
2792 |
+
var settings_element = {
|
2793 |
+
'placeholder' : $input.children('option[value=""]').text() || $input.attr('placeholder'),
|
2794 |
+
'options' : {},
|
2795 |
+
'optgroups' : {},
|
2796 |
+
'items' : []
|
2797 |
+
};
|
2798 |
+
|
2799 |
+
if (tag_name === 'select') {
|
2800 |
+
init_select($input, settings_element);
|
2801 |
+
} else {
|
2802 |
+
init_textbox($input, settings_element);
|
2803 |
+
}
|
2804 |
+
|
2805 |
+
instance = new Selectize($input, $.extend(true, {}, defaults, settings_element, settings));
|
2806 |
+
$input.data('selectize', instance);
|
2807 |
+
$input.addClass('selectized');
|
2808 |
+
});
|
2809 |
+
};
|
2810 |
+
|
2811 |
+
$.fn.selectize.defaults = Selectize.defaults;
|
2812 |
+
|
2813 |
+
Selectize.define('drag_drop', function(options) {
|
2814 |
+
if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');
|
2815 |
+
if (this.settings.mode !== 'multi') return;
|
2816 |
+
var self = this;
|
2817 |
+
|
2818 |
+
this.setup = (function() {
|
2819 |
+
var original = self.setup;
|
2820 |
+
return function() {
|
2821 |
+
original.apply(this, arguments);
|
2822 |
+
|
2823 |
+
var $control = this.$control.sortable({
|
2824 |
+
items: '[data-value]',
|
2825 |
+
forcePlaceholderSize: true,
|
2826 |
+
start: function(e, ui) {
|
2827 |
+
ui.placeholder.css('width', ui.helper.css('width'));
|
2828 |
+
$control.css({overflow: 'visible'});
|
2829 |
+
},
|
2830 |
+
stop: function() {
|
2831 |
+
$control.css({overflow: 'hidden'});
|
2832 |
+
var active = this.$activeItems ? this.$activeItems.slice() : null;
|
2833 |
+
var values = [];
|
2834 |
+
$control.children('[data-value]').each(function() {
|
2835 |
+
values.push($(this).attr('data-value'));
|
2836 |
+
});
|
2837 |
+
self.setValue(values);
|
2838 |
+
self.setActiveItem(active);
|
2839 |
+
}
|
2840 |
+
});
|
2841 |
+
};
|
2842 |
+
})();
|
2843 |
+
|
2844 |
+
});
|
2845 |
+
|
2846 |
+
Selectize.define('dropdown_header', function(options) {
|
2847 |
+
var self = this;
|
2848 |
+
|
2849 |
+
options = $.extend({
|
2850 |
+
title : 'Untitled',
|
2851 |
+
headerClass : 'selectize-dropdown-header',
|
2852 |
+
titleRowClass : 'selectize-dropdown-header-title',
|
2853 |
+
labelClass : 'selectize-dropdown-header-label',
|
2854 |
+
closeClass : 'selectize-dropdown-header-close',
|
2855 |
+
|
2856 |
+
html: function(data) {
|
2857 |
+
return (
|
2858 |
+
'<div class="' + data.headerClass + '">' +
|
2859 |
+
'<div class="' + data.titleRowClass + '">' +
|
2860 |
+
'<span class="' + data.labelClass + '">' + data.title + '</span>' +
|
2861 |
+
'<a href="javascript:void(0)" class="' + data.closeClass + '">×</a>' +
|
2862 |
+
'</div>' +
|
2863 |
+
'</div>'
|
2864 |
+
);
|
2865 |
+
}
|
2866 |
+
}, options);
|
2867 |
+
|
2868 |
+
self.setup = (function() {
|
2869 |
+
var original = self.setup;
|
2870 |
+
return function() {
|
2871 |
+
original.apply(self, arguments);
|
2872 |
+
self.$dropdown_header = $(options.html(options));
|
2873 |
+
self.$dropdown.prepend(self.$dropdown_header);
|
2874 |
+
};
|
2875 |
+
})();
|
2876 |
+
|
2877 |
+
});
|
2878 |
+
|
2879 |
+
Selectize.define('optgroup_columns', function(options) {
|
2880 |
+
var self = this;
|
2881 |
+
|
2882 |
+
options = $.extend({
|
2883 |
+
equalizeWidth : true,
|
2884 |
+
equalizeHeight : true
|
2885 |
+
}, options);
|
2886 |
+
|
2887 |
+
this.getAdjacentOption = function($option, direction) {
|
2888 |
+
var $options = $option.closest('[data-group]').find('[data-selectable]');
|
2889 |
+
var index = $options.index($option) + direction;
|
2890 |
+
|
2891 |
+
return index >= 0 && index < $options.length ? $options.eq(index) : $();
|
2892 |
+
};
|
2893 |
+
|
2894 |
+
this.onKeyDown = (function() {
|
2895 |
+
var original = self.onKeyDown;
|
2896 |
+
return function(e) {
|
2897 |
+
var index, $option, $options, $optgroup;
|
2898 |
+
|
2899 |
+
if (this.isOpen && (e.keyCode === KEY_LEFT || e.keyCode === KEY_RIGHT)) {
|
2900 |
+
self.ignoreHover = true;
|
2901 |
+
$optgroup = this.$activeOption.closest('[data-group]');
|
2902 |
+
index = $optgroup.find('[data-selectable]').index(this.$activeOption);
|
2903 |
+
|
2904 |
+
if(e.keyCode === KEY_LEFT) {
|
2905 |
+
$optgroup = $optgroup.prev('[data-group]');
|
2906 |
+
} else {
|
2907 |
+
$optgroup = $optgroup.next('[data-group]');
|
2908 |
+
}
|
2909 |
+
|
2910 |
+
$options = $optgroup.find('[data-selectable]');
|
2911 |
+
$option = $options.eq(Math.min($options.length - 1, index));
|
2912 |
+
if ($option.length) {
|
2913 |
+
this.setActiveOption($option);
|
2914 |
+
}
|
2915 |
+
return;
|
2916 |
+
}
|
2917 |
+
|
2918 |
+
return original.apply(this, arguments);
|
2919 |
+
};
|
2920 |
+
})();
|
2921 |
+
|
2922 |
+
var equalizeSizes = function() {
|
2923 |
+
var i, n, height_max, width, width_last, width_parent, $optgroups;
|
2924 |
+
|
2925 |
+
$optgroups = $('[data-group]', self.$dropdown_content);
|
2926 |
+
n = $optgroups.length;
|
2927 |
+
if (!n || !self.$dropdown_content.width()) return;
|
2928 |
+
|
2929 |
+
if (options.equalizeHeight) {
|
2930 |
+
height_max = 0;
|
2931 |
+
for (i = 0; i < n; i++) {
|
2932 |
+
height_max = Math.max(height_max, $optgroups.eq(i).height());
|
2933 |
+
}
|
2934 |
+
$optgroups.css({height: height_max});
|
2935 |
+
}
|
2936 |
+
|
2937 |
+
if (options.equalizeWidth) {
|
2938 |
+
width_parent = self.$dropdown_content.innerWidth();
|
2939 |
+
width = Math.round(width_parent / n);
|
2940 |
+
$optgroups.css({width: width});
|
2941 |
+
if (n > 1) {
|
2942 |
+
width_last = width_parent - width * (n - 1);
|
2943 |
+
$optgroups.eq(n - 1).css({width: width_last});
|
2944 |
+
}
|
2945 |
+
}
|
2946 |
+
};
|
2947 |
+
|
2948 |
+
if (options.equalizeHeight || options.equalizeWidth) {
|
2949 |
+
hook.after(this, 'positionDropdown', equalizeSizes);
|
2950 |
+
hook.after(this, 'refreshOptions', equalizeSizes);
|
2951 |
+
}
|
2952 |
+
|
2953 |
+
|
2954 |
+
});
|
2955 |
+
|
2956 |
+
Selectize.define('remove_button', function(options) {
|
2957 |
+
if (this.settings.mode === 'single') return;
|
2958 |
+
|
2959 |
+
options = $.extend({
|
2960 |
+
label : '×',
|
2961 |
+
title : 'Remove',
|
2962 |
+
className : 'remove',
|
2963 |
+
append : true,
|
2964 |
+
}, options);
|
2965 |
+
|
2966 |
+
var self = this;
|
2967 |
+
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
|
2968 |
+
|
2969 |
+
/**
|
2970 |
+
* Appends an element as a child (with raw HTML).
|
2971 |
+
*
|
2972 |
+
* @param {string} html_container
|
2973 |
+
* @param {string} html_element
|
2974 |
+
* @return {string}
|
2975 |
+
*/
|
2976 |
+
var append = function(html_container, html_element) {
|
2977 |
+
var pos = html_container.search(/(<\/[^>]+>\s*)$/);
|
2978 |
+
return html_container.substring(0, pos) + html_element + html_container.substring(pos);
|
2979 |
+
};
|
2980 |
+
|
2981 |
+
this.setup = (function() {
|
2982 |
+
var original = self.setup;
|
2983 |
+
return function() {
|
2984 |
+
// override the item rendering method to add the button to each
|
2985 |
+
if (options.append) {
|
2986 |
+
var render_item = self.settings.render.item;
|
2987 |
+
self.settings.render.item = function(data) {
|
2988 |
+
return append(render_item.apply(this, arguments), html);
|
2989 |
+
};
|
2990 |
+
}
|
2991 |
+
|
2992 |
+
original.apply(this, arguments);
|
2993 |
+
|
2994 |
+
// add event listener
|
2995 |
+
this.$control.on('click', '.' + options.className, function(e) {
|
2996 |
+
e.preventDefault();
|
2997 |
+
var $item = $(e.target).parent();
|
2998 |
+
self.setActiveItem($item);
|
2999 |
+
if (self.deleteSelection()) {
|
3000 |
+
self.setCaret(self.items.length);
|
3001 |
+
}
|
3002 |
+
});
|
3003 |
+
|
3004 |
+
};
|
3005 |
+
})();
|
3006 |
+
|
3007 |
+
});
|
3008 |
+
|
3009 |
+
Selectize.define('restore_on_backspace', function(options) {
|
3010 |
+
var self = this;
|
3011 |
+
|
3012 |
+
options.text = options.text || function(option) {
|
3013 |
+
return option[this.settings.labelField];
|
3014 |
+
};
|
3015 |
+
|
3016 |
+
this.onKeyDown = (function(e) {
|
3017 |
+
var original = self.onKeyDown;
|
3018 |
+
return function(e) {
|
3019 |
+
var index, option;
|
3020 |
+
if (e.keyCode === KEY_BACKSPACE && this.$control_input.val() === '' && !this.$activeItems.length) {
|
3021 |
+
index = this.caretPos - 1;
|
3022 |
+
if (index >= 0 && index < this.items.length) {
|
3023 |
+
option = this.options[this.items[index]];
|
3024 |
+
if (this.deleteSelection(e)) {
|
3025 |
+
this.setTextboxValue(options.text.apply(this, [option]));
|
3026 |
+
this.refreshOptions(true);
|
3027 |
+
}
|
3028 |
+
e.preventDefault();
|
3029 |
+
return;
|
3030 |
+
}
|
3031 |
+
}
|
3032 |
+
return original.apply(this, arguments);
|
3033 |
+
};
|
3034 |
+
})();
|
3035 |
+
});
|
3036 |
+
|
3037 |
+
return Selectize;
|
3038 |
+
}));
|
js/selectize/selectize.min.js
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
/*! selectize.js - v0.7.7 | https://github.com/brianreavis/selectize.js | Apache License (v2) */
|
2 |
+
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=d(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,f,h,i=[],j=a.split(/ +/);for(b=0,c=j.length;c>b;b++){if(f=e(j[b]),this.settings.diacritics)for(h in g)g.hasOwnProperty(h)&&(f=f.replace(new RegExp(h,"g"),g[h]));i.push({string:j[b],regex:new RegExp(f,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=f(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;c>b;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,d,e,f;c=this,a=c.prepareSearch(a,b),e=a.tokens,d=a.options.fields,f=e.length;var g=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),-1===d?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},h=function(){var a=d.length;return a?1===a?function(a,b){return g(b[d[0]],a)}:function(b,c){for(var e=0,f=0;a>e;e++)f+=g(c[d[e]],b);return f/a}:function(){return 0}}();return f?1===f?function(a){return h(e[0],a)}:function(a){for(var b=0,c=0;f>b;b++)c+=h(e[b],a);return c/f}:function(){return 0}},a.prototype.prepareSearch=function(a,b){return"object"==typeof a?a:{options:c({},b),query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,c){var d,e,g,h=this;return e=this.prepareSearch(a,c),c=e.options,a=e.query,f(c.fields)||(c.fields=[c.fields]),g=c.score||h.getScoreFunction(e),a.length?(h.iterator(h.items,function(a,b){d=g(a),d>0&&e.items.push({score:d,id:b})}),e.items.sort(function(a,b){return b.score-a.score})):(h.iterator(h.items,function(a,b){e.items.push({score:1,id:b})}),c.sort&&e.items.sort(function(){var a=c.sort,d="desc"===c.direction?-1:1;return function(c,e){return b(h.items[c.id][a],h.items[e.id][a])*d}}())),e.total=e.items.length,"number"==typeof c.limit&&(e.items=e.items.slice(0,c.limit)),e};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:b>a?-1:0:(a=String(a||"").toLowerCase(),b=String(b||"").toLowerCase(),a>b?1:b>a?-1:0)},c=function(a){var b,c,d,e;for(b=1,c=arguments.length;c>b;b++)if(e=arguments[b])for(d in e)e.hasOwnProperty(d)&&(a[d]=e[d]);return a},d=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},e=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},f=Array.isArray||$&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g={a:"[aÀÁÂÃÄÅàáâãäå]",c:"[cÇç]",e:"[eÈÉÊËèéêë]",i:"[iÌÍÎÏìíîï]",n:"[nÑñ]",o:"[oÒÓÔÕÕÖØòóôõöø]",s:"[sŠš]",u:"[uÙÚÛÜùúûü]",y:"[yŸÿý]",z:"[zŽž]"};return a}),function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.MicroPlugin=b()}(this,function(){var a={};a.mixin=function(a){a.plugins={},a.prototype.initializePlugins=function(a){var c,d,e,f=this,g=[];if(f.plugins={names:[],settings:{},requested:{},loaded:{}},b.isArray(a))for(c=0,d=a.length;d>c;c++)"string"==typeof a[c]?g.push(a[c]):(f.plugins.settings[a[c].name]=a[c].options,g.push(a[c].name));else if(a)for(e in a)a.hasOwnProperty(e)&&(f.plugins.settings[e]=a[e],g.push(e));for(;g.length;)f.require(g.shift())},a.prototype.loadPlugin=function(b){var c=this,d=c.plugins,e=a.plugins[b];if(!a.plugins.hasOwnProperty(b))throw new Error('Unable to find "'+b+'" plugin');d.requested[b]=!0,d.loaded[b]=e.fn.apply(c,[c.plugins.settings[b]||{}]),d.names.push(b)},a.prototype.require=function(a){var b=this,c=b.plugins;if(!b.plugins.loaded.hasOwnProperty(a)){if(c.requested[a])throw new Error('Plugin has circular dependency ("'+a+'")');b.loadPlugin(a)}return c.loaded[a]},a.define=function(b,c){a.plugins[b]={name:b,fn:c}}};var b={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}};return a}),function(a,b){"function"==typeof define&&define.amd?define(["jquery","sifter","microplugin"],b):a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}(this,function(a,b,c){"use strict";var d=function(a,b){if("string"!=typeof b||b.length){var c="string"==typeof b?new RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var e=a.data.search(c);if(e>=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e);h.splitText(f[0].length);var i=h.cloneNode(!0);g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j<a.childNodes.length;++j)j+=d(a.childNodes[j]);return b};return a.each(function(){d(this)})}},e=function(){};e.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){var c=arguments.length;return 0===c?delete this._events:1===c?delete this._events[a]:(this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1),void 0)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},e.mixin=function(a){for(var b=["on","off","trigger"],c=0;c<b.length;c++)a.prototype[b[c]]=e.prototype[b[c]]};var f=/Mac/.test(navigator.userAgent),g=65,h=13,i=27,j=37,k=38,l=39,m=40,n=8,o=46,p=16,q=f?91:17,r=f?18:17,s=9,t=1,u=2,v=function(a){return"undefined"!=typeof a},w=function(a){return"undefined"==typeof a||null===a?"":"boolean"==typeof a?a?"1":"0":a+""},x=function(a){return(a+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},y={};y.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},y.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var z=function(b,c){if(!a.isArray(c))return c;var d,e,f={};for(d=0,e=c.length;e>d;d++)c[d].hasOwnProperty(b)&&(f[c[d][b]]=c[d]);return f},A=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},B=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},C=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return-1===b.indexOf(c)?e.apply(a,arguments):(f[c]=arguments,void 0)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},D=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},E=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},F=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;e>d;d++)f[c[d]]=a.css(c[d]);else f=a.css();b.css(f)},G=function(b,c){var d=a("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"nowrap"}).text(b).appendTo("body");F(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},H=function(a){var b=function(b){var c,d,e,f,g,h,i,j;b=b||window.event||{},b.metaKey||b.altKey||a.data("grow")!==!1&&(c=a.val(),b.type&&"keydown"===b.type.toLowerCase()&&(d=b.keyCode,e=d>=97&&122>=d||d>=65&&90>=d||d>=48&&57>=d||32===d,d===o||d===n?(j=E(a[0]),j.length?c=c.substring(0,j.start)+c.substring(j.start+j.length):d===n&&j.start?c=c.substring(0,j.start-1)+c.substring(j.start+1):d===o&&"undefined"!=typeof j.start&&(c=c.substring(0,j.start)+c.substring(j.start+1))):e&&(h=b.shiftKey,i=String.fromCharCode(b.keyCode),i=h?i.toUpperCase():i.toLowerCase(),c+=i)),f=a.attr("placeholder")||"",!c.length&&f.length&&(c=f),g=G(c,a)+4,g!==a.width()&&(a.width(g),a.triggerHandler("resize")))};a.on("keydown keyup update blur",b),b()},I=function(c,d){var e=this;c[0].selectize=e,a.extend(e,{settings:d,$input:c,tagType:"select"===c[0].tagName.toLowerCase()?t:u,eventNS:".selectize"+ ++I.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isLocked:!1,isFocused:!1,isInputFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:B(e.onSearchChange,d.loadThrottle)}),e.sifter=new b(this.options,{diacritics:d.diacritics}),a.extend(e.options,z(d.valueField,d.options)),delete e.settings.options,a.extend(e.optgroups,z(d.optgroupValueField,d.optgroups)),delete e.settings.optgroups,e.settings.mode=e.settings.mode||(1===e.settings.maxItems?"single":"multi"),"boolean"!=typeof e.settings.hideSelected&&(e.settings.hideSelected="multi"===e.settings.mode),e.initializePlugins(e.settings.plugins),e.setupCallbacks(),e.setupTemplates(),e.setup()};return e.mixin(I),c.mixin(I),a.extend(I.prototype,{setup:function(){var b,c,d,e,g,h,i,j,k,l,m=this,n=m.settings,o=m.eventNS,s=a(window),u=a(document);i=m.settings.mode,j=m.$input.attr("tabindex")||"",k=m.$input.attr("class")||"",b=a("<div>").addClass(n.wrapperClass).addClass(k).addClass(i),c=a("<div>").addClass(n.inputClass).addClass("items").appendTo(b),d=a('<input type="text">').appendTo(c).attr("tabindex",j),h=a(n.dropdownParent||b),e=a("<div>").addClass(n.dropdownClass).addClass(k).addClass(i).hide().appendTo(h),g=a("<div>").addClass(n.dropdownContentClass).appendTo(e),b.css({width:m.$input[0].style.width}),m.plugins.names.length&&(l="plugin-"+m.plugins.names.join(" plugin-"),b.addClass(l),e.addClass(l)),(null===n.maxItems||n.maxItems>1)&&m.tagType===t&&m.$input.attr("multiple","multiple"),m.settings.placeholder&&d.attr("placeholder",n.placeholder),m.$wrapper=b,m.$control=c,m.$control_input=d,m.$dropdown=e,m.$dropdown_content=g,c.on("mousedown",function(a){a.isDefaultPrevented()||window.setTimeout(function(){m.focus(!0)},0)}),c.on("click",function(){m.isInputFocused||m.focus(!0)}),e.on("mouseenter","[data-selectable]",function(){return m.onOptionHover.apply(m,arguments)}),e.on("mousedown","[data-selectable]",function(){return m.onOptionSelect.apply(m,arguments)}),D(c,"mousedown","*:not(input)",function(){return m.onItemSelect.apply(m,arguments)}),H(d),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return m.onKeyDown.apply(m,arguments)},keyup:function(){return m.onKeyUp.apply(m,arguments)},keypress:function(){return m.onKeyPress.apply(m,arguments)},resize:function(){m.positionDropdown.apply(m,[])},blur:function(){return m.onBlur.apply(m,arguments)},focus:function(){return m.onFocus.apply(m,arguments)}}),u.on("keydown"+o,function(a){m.isCmdDown=a[f?"metaKey":"ctrlKey"],m.isCtrlDown=a[f?"altKey":"ctrlKey"],m.isShiftDown=a.shiftKey}),u.on("keyup"+o,function(a){a.keyCode===r&&(m.isCtrlDown=!1),a.keyCode===p&&(m.isShiftDown=!1),a.keyCode===q&&(m.isCmdDown=!1)}),u.on("mousedown"+o,function(a){if(m.isFocused){if(a.target===m.$dropdown[0]||a.target.parentNode===m.$dropdown[0]){var b=m.ignoreFocus;return m.ignoreFocus=!0,window.setTimeout(function(){m.ignoreFocus=b,m.focus(!1)},0),void 0}m.$control.has(a.target).length||a.target===m.$control[0]||m.blur()}}),s.on(["scroll"+o,"resize"+o].join(" "),function(){m.isOpen&&m.positionDropdown.apply(m,arguments)}),s.on("mousemove"+o,function(){m.ignoreHover=!1}),m.$input.attr("tabindex",-1).hide().after(m.$wrapper),a.isArray(n.items)&&(m.setValue(n.items),delete n.items),m.updateOriginalInput(),m.refreshItems(),m.refreshClasses(),m.updatePlaceholder(),m.isSetup=!0,m.$input.is(":disabled")&&m.disable(),m.on("change",this.onChange),m.trigger("initialize"),n.preload&&m.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'<div class="optgroup">'+a.html+"</div>"},optgroup_header:function(a,b){return'<div class="optgroup-header">'+b(a[d])+"</div>"},option:function(a,b){return'<div class="option">'+b(a[c])+"</div>"},item:function(a,b){return'<div class="item">'+b(a[c])+"</div>"},option_create:function(a,b){return'<div class="create">Add <strong>'+b(a.input)+"</strong>…</div>"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onChange:function(){this.$input.trigger("change")},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);return this.settings.create&&b===this.settings.delimiter?(this.createItem(),a.preventDefault(),!1):void 0},onKeyDown:function(b){b.target===this.$control_input[0];var c=this;if(c.isLocked)return b.keyCode!==s&&b.preventDefault(),void 0;switch(b.keyCode){case g:if(c.isCmdDown)return c.selectAll(),void 0;break;case i:return c.blur(),void 0;case m:if(!c.isOpen&&c.hasOptions)c.open();else if(c.$activeOption){c.ignoreHover=!0;var d=c.getAdjacentOption(c.$activeOption,1);d.length&&c.setActiveOption(d,!0,!0)}return b.preventDefault(),void 0;case k:if(c.$activeOption){c.ignoreHover=!0;var e=c.getAdjacentOption(c.$activeOption,-1);e.length&&c.setActiveOption(e,!0,!0)}return b.preventDefault(),void 0;case h:return c.$activeOption&&c.onOptionSelect({currentTarget:c.$activeOption}),b.preventDefault(),void 0;case j:return c.advanceSelection(-1,b),void 0;case l:return c.advanceSelection(1,b),void 0;case s:return c.settings.create&&a.trim(c.$control_input.val()).length&&(c.createItem(),b.preventDefault()),void 0;case n:case o:return c.deleteSelection(b),void 0}return c.isFull()||c.isInputHidden?(b.preventDefault(),void 0):void 0},onKeyUp:function(a){var b=this;if(b.isLocked)return a&&a.preventDefault();var c=b.$control_input.val()||"";b.lastValue!==c&&(b.lastValue=c,b.onSearchChange(c),b.refreshOptions(),b.trigger("type",c))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&(b.loadedSearches.hasOwnProperty(a)||(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])})))},onFocus:function(a){var b=this;return b.isInputFocused=!0,b.isFocused=!0,b.isDisabled?(b.blur(),a.preventDefault(),!1):(b.ignoreFocus||("focus"===b.settings.preload&&b.onSearchChange(""),b.showInput(),b.setActiveItem(null),b.refreshOptions(!!b.settings.openOnFocus),b.refreshClasses()),void 0)},onBlur:function(){var a=this;a.isInputFocused=!1,a.ignoreFocus||(a.close(),a.setTextboxValue(""),a.setActiveItem(null),a.setActiveOption(null),a.setCaret(a.items.length),a.isFocused=!1,a.refreshClasses())},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(b){var c,d,e=this;b.preventDefault&&b.preventDefault(),b.stopPropagation&&b.stopPropagation(),e.focus(!1),d=a(b.currentTarget),d.hasClass("create")?e.createItem():(c=d.attr("data-value"),c&&(e.setTextboxValue(""),e.addItem(c),!e.settings.hideSelected&&b.type&&/mouse/.test(b.type)&&e.setActiveOption(e.getOption(c))))},onItemSelect:function(a){var b=this;"multi"===b.settings.mode&&(a.preventDefault(),b.setActiveItem(a.currentTarget,a),b.focus(!1),b.hideInput())},load:function(a){var b=this,c=b.$wrapper.addClass("loading");b.loading++,a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0),a&&a.length&&(b.addOption(a),b.refreshOptions(!1),b.isInputFocused&&b.open()),b.loading||c.removeClass("loading"),b.trigger("load",a)}])},setTextboxValue:function(a){this.$control_input.val(a).triggerHandler("update"),this.lastValue=a},getValue:function(){return this.tagType===t&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(b){C(this,["change"],function(){this.clear();for(var c=a.isArray(b)?b:[b],d=0,e=c.length;e>d;d++)this.addItem(c[d])})},setActiveItem:function(b,c){var d,e,f,g,h,i,j,k,l=this;if(b=a(b),!b.length)return a(l.$activeItems).removeClass("active"),l.$activeItems=[],l.isFocused=l.isInputFocused,void 0;if(d=c&&c.type.toLowerCase(),"mousedown"===d&&l.isShiftDown&&l.$activeItems.length){for(k=l.$control.children(".active:last"),g=Array.prototype.indexOf.apply(l.$control[0].childNodes,[k[0]]),h=Array.prototype.indexOf.apply(l.$control[0].childNodes,[b[0]]),g>h&&(j=g,g=h,h=j),e=g;h>=e;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.isFocused=!!l.$activeItems.length||l.isInputFocused},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),(c||!v(c))&&(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e-c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):c>g&&j.$dropdown_content.stop().animate({scrollTop:h},d?j.settings.scrollDuration:0)))},selectAll:function(){this.$activeItems=Array.prototype.slice.apply(this.$control.children(":not(input)").addClass("active")),this.isFocused=!0,this.$activeItems.length&&this.hideInput()},hideInput:function(){var a=this;a.close(),a.setTextboxValue(""),a.$control_input.css({opacity:0,position:"absolute",left:-1e4}),a.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(a){var b=this;b.isDisabled||(b.ignoreFocus=!0,b.$control_input[0].focus(),b.isInputFocused=!0,window.setTimeout(function(){b.ignoreFocus=!1,a&&b.onFocus()},0))},blur:function(){this.$control_input.trigger("blur")},getScoreFunction:function(a){return this.sifter.getScoreFunction(a,this.getSearchOptions())},getSearchOptions:function(){var b=this.settings,c=b.searchField;return{fields:a.isArray(c)?c:[c],sort:b.sortField,direction:b.sortDirection}},search:function(b){var c,d,e,f=this,g=f.settings,h=this.getSearchOptions();if(g.score&&(e=f.settings.score.apply(this,[b]),"function"!=typeof e))throw new Error('Selectize "score" setting must be a function that returns a function');if(b!==f.lastQuery?(f.lastQuery=b,d=f.sifter.search(b,a.extend(h,{score:e})),f.currentResults=d):d=a.extend(!0,{},f.currentResults),g.hideSelected)for(c=d.items.length-1;c>=0;c--)-1!==f.items.indexOf(w(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){"undefined"==typeof b&&(b=!0);var c,e,f,g,h,i,j,k,l,m,n,o=this,p=o.$control_input.val(),q=o.search(p),r=o.$dropdown_content;if(e=q.items.length,"number"==typeof o.settings.maxOptions&&(e=Math.min(e,o.settings.maxOptions)),f={},o.settings.optgroupOrder)for(g=o.settings.optgroupOrder,c=0;c<g.length;c++)f[g[c]]=[];else g=[];for(c=0;e>c;c++)h=o.options[q.items[c].id],i=h[o.settings.optgroupField]||"",o.optgroups.hasOwnProperty(i)||(i=""),f.hasOwnProperty(i)||(f[i]=[],g.push(i)),f[i].push(o.render("option",h));for(j=[],c=0,e=g.length;e>c;c++)i=g[c],o.optgroups.hasOwnProperty(i)&&f[i].length?(k=o.render("optgroup_header",o.optgroups[i])||"",k+=f[i].join(""),j.push(o.render("optgroup",a.extend({},o.optgroups[i],{html:k})))):j.push(f[i].join(""));if(r.html(j.join("")),o.settings.highlight&&q.query.length&&q.tokens.length)for(c=0,e=q.tokens.length;e>c;c++)d(r,q.tokens[c].regex);if(!o.settings.hideSelected)for(c=0,e=o.items.length;e>c;c++)o.getOption(o.items[c]).addClass("selected");l=o.settings.create&&q.query.length,l&&(r.prepend(o.render("option_create",{input:p})),n=a(r[0].childNodes[0])),o.hasOptions=q.items.length>0||l,o.hasOptions?(m=q.items.length>0?n?o.getAdjacentOption(n,1):r.find("[data-selectable]").first():n,o.setActiveOption(m),b&&!o.isOpen&&o.open()):(o.setActiveOption(null),b&&o.isOpen&&o.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;d>c;c++)f.addOption(b[c]);else e=w(b[f.settings.valueField]),e&&!f.options.hasOwnProperty(e)&&(f.userOptions[e]=!0,f.options[e]=b,f.lastQuery=null,f.trigger("option_add",e,b))},addOptionGroup:function(a,b){this.optgroups[a]=b,this.trigger("optgroup_add",a,b)},updateOption:function(b,c){var d,e,f,g,h,i,j=this;if(b=w(b),f=w(c[j.settings.valueField]),j.options.hasOwnProperty(b)){if(!f)throw new Error("Value must be set in option data");f!==b&&(delete j.options[b],g=j.items.indexOf(b),-1!==g&&j.items.splice(g,1,f)),j.options[f]=c,h=j.renderCache.item,i=j.renderCache.option,v(h)&&(delete h[b],delete h[f]),v(i)&&(delete i[b],delete i[f]),-1!==j.items.indexOf(f)&&(d=j.getItem(b),e=a(j.render("item",c)),d.hasClass("active")&&e.addClass("active"),d.replaceWith(e)),j.isOpen&&j.refreshOptions(!1)}},removeOption:function(a){var b=this;a=w(a),delete b.userOptions[a],delete b.options[a],b.lastQuery=null,b.trigger("option_remove",a),b.removeItem(a)},clearOptions:function(){var a=this;a.loadedSearches={},a.userOptions={},a.options=a.sifter.items={},a.lastQuery=null,a.trigger("option_clear"),a.clear()},getOption:function(a){return this.getElementWithValue(a,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(b,c){var d=this.$dropdown.find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},getElementWithValue:function(b,c){if(b=w(b))for(var d=0,e=c.length;e>d;d++)if(c[d].getAttribute("data-value")===b)return a(c[d]);return a()},getItem:function(a){return this.getElementWithValue(a,this.$control.children())},addItem:function(b){C(this,["change"],function(){var c,d,e,f,g=this,h=g.settings.mode;b=w(b),"single"===h&&g.clear(),"multi"===h&&g.isFull()||-1===g.items.indexOf(b)&&g.options.hasOwnProperty(b)&&(c=a(g.render("item",g.options[b])),g.items.splice(g.caretPos,0,b),g.insertAtCaret(c),g.refreshClasses(),g.isSetup&&(e=g.$dropdown_content.find("[data-selectable]"),d=g.getOption(b),f=g.getAdjacentOption(d,1).attr("data-value"),g.refreshOptions(g.isFocused&&"single"!==h),f&&g.setActiveOption(g.getOption(f)),!e.length||null!==g.settings.maxItems&&g.items.length>=g.settings.maxItems?g.close():g.positionDropdown(),g.isFocused&&window.setTimeout(function(){"single"===h?(g.blur(),g.focus(!1),g.hideInput()):g.focus(!1)},0),g.updatePlaceholder(),g.trigger("item_add",b,c),g.updateOriginalInput()))})},removeItem:function(a){var b,c,d,e=this;b="object"==typeof a?a:e.getItem(a),a=w(b.attr("data-value")),c=e.items.indexOf(a),-1!==c&&(b.remove(),b.hasClass("active")&&(d=e.$activeItems.indexOf(b[0]),e.$activeItems.splice(d,1)),e.items.splice(c,1),e.lastQuery=null,!e.settings.persist&&e.userOptions.hasOwnProperty(a)&&e.removeOption(a),c<e.caretPos&&e.setCaret(e.caretPos-1),e.refreshClasses(),e.updatePlaceholder(),e.updateOriginalInput(),e.positionDropdown(),e.trigger("item_remove",a))},createItem:function(){var b=this,c=a.trim(b.$control_input.val()||""),d=b.caretPos;if(c.length){b.lock();var e="function"==typeof b.settings.create?this.settings.create:function(a){var c={};return c[b.settings.labelField]=a,c[b.settings.valueField]=a,c},f=A(function(a){if(b.unlock(),b.focus(!1),a&&"object"==typeof a){var c=w(a[b.settings.valueField]);c&&(b.setTextboxValue(""),b.addOption(a),b.setCaret(d),b.addItem(c),b.refreshOptions("single"!==b.settings.mode),b.focus(!1))}}),g=e.apply(this,[c,f]);"undefined"!=typeof g&&f(g)}},refreshItems:function(){if(this.lastQuery=null,this.isSetup)for(var a=0;a<this.items.length;a++)this.addItem(this.items);this.refreshClasses(),this.updateOriginalInput()},refreshClasses:function(){var b=this,c=b.isFull(),d=b.isLocked;this.$control.toggleClass("focus",b.isFocused).toggleClass("disabled",b.isDisabled).toggleClass("locked",d).toggleClass("full",c).toggleClass("not-full",!c).toggleClass("dropdown-active",b.isOpen).toggleClass("has-options",!a.isEmptyObject(b.options)).toggleClass("has-items",b.items.length>0),this.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(){var a,b,c,d=this;if("select"===d.$input[0].tagName.toLowerCase()){for(c=[],a=0,b=d.items.length;b>a;a++)c.push('<option value="'+x(d.items[a])+'" selected="selected"></option>');c.length||this.$input.attr("multiple")||c.push('<option value="" selected="selected"></option>'),d.$input.html(c.join(""))}else d.$input.val(d.getValue());d.isSetup&&d.trigger("change",d.$input.val())},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update")}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(!0),a.isOpen=!0,a.refreshClasses(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",this.$dropdown))},close:function(){var a=this;a.isOpen&&(a.$dropdown.hide(),a.setActiveOption(null),a.isOpen=!1,a.refreshClasses(),a.trigger("dropdown_close",a.$dropdown))},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(){var a=this;a.items.length&&(a.$control.children(":not(input)").remove(),a.items=[],a.setCaret(0),a.updatePlaceholder(),a.updateOriginalInput(),a.refreshClasses(),a.showInput(),a.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===n?-1:1,f=E(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;d>c;c++)g.push(a(l.$activeItems[c]).attr("data-value"));b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(0>e&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(c=a>0?"last":"first",d=E(i.$control_input[0]),i.isInputFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=0>a?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e),i.showInput())))},advanceCaret:function(a,b){if(0!==a){var c=this,d=a>0?"next":"prev";if(c.isShiftDown){var e=c.$control_input[d]();e.length&&(c.hideInput(),c.setActiveItem(e),b&&b.preventDefault())}else c.setCaret(c.caretPos+a)}},setCaret:function(b){var c=this;b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b));var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;e>d;d++)g=a(f[d]).detach(),b>d?c.$control_input.before(g):c.$control.append(g);c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshClasses()},unlock:function(){this.isLocked=!1,this.refreshClasses()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.show(),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(a,b){var c,d,e="",f=!1,g=this,h=/^[\t ]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===a||"item"===a)&&(c=w(b[g.settings.valueField]),f=!!c),f&&(v(g.renderCache[a])||(g.renderCache[a]={}),g.renderCache[a].hasOwnProperty(c))?g.renderCache[a][c]:(e=g.settings.render[a].apply(this,[b,x]),("option"===a||"option_create"===a)&&(e=e.replace(h,"<$1 data-selectable")),"optgroup"===a&&(d=b[g.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+x(d)+'"')),("option"===a||"item"===a)&&(e=e.replace(h,'<$1 data-value="'+x(c||"")+'"')),f&&(g.renderCache[a][c]=e),e)}}),I.count=0,I.defaults={plugins:[],delimiter:",",persist:!0,diacritics:!0,create:!1,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,preload:!1,scrollDuration:60,loadThrottle:300,dataAttr:"data-data",optgroupField:"optgroup",sortField:"$order",sortDirection:"asc",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",optgroupOrder:null,searchField:["text"],mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,render:{}},a.fn.selectize=function(b){b=b||{};var c=a.fn.selectize.defaults,d=b.dataAttr||c.dataAttr,e=function(d,e){var f,g,h,i=a.trim(d.val()||"");if(i.length){for(h=i.split(b.delimiter||c.delimiter),f=0,g=h.length;g>f;f++)e.options[h[f]]={text:h[f],value:h[f]};e.items=h}},f=function(b,c){var e,f,g,h,i=0;c.maxItems=b.attr("multiple")?null:1;var j=function(a){var b=d&&a.attr(d);return"string"==typeof b&&b.length?JSON.parse(b):null},k=function(b,d){var e,f;b=a(b),e=b.attr("value")||"",e.length&&(f=j(b)||{text:b.text(),value:e,optgroup:d},f.$order=++i,c.options[e]=f,b.is(":selected")&&c.items.push(e))},l=function(b){var d,e,f=a("option",b);b=a(b);var g=b.attr("label");for(g&&g.length&&(c.optgroups[g]=j(b)||{label:g}),d=0,e=f.length;e>d;d++)k(f[d],g)};for(h=b.children(),e=0,f=h.length;f>e;e++)g=h[e].tagName.toLowerCase(),"optgroup"===g?l(h[e]):"option"===g&&k(h[e])};return this.each(function(){var d,g=a(this),h=g[0].tagName.toLowerCase(),i={placeholder:g.children('option[value=""]').text()||g.attr("placeholder"),options:{},optgroups:{},items:[]};"select"===h?f(g,i):e(g,i),d=new I(g,a.extend(!0,{},c,i,b)),g.data("selectize",d),g.addClass("selectized")})},a.fn.selectize.defaults=I.defaults,I.define("drag_drop",function(){if(!a.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;this.setup=function(){var c=b.setup;return function(){c.apply(this,arguments);var d=this.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,start:function(a,b){b.placeholder.css("width",b.helper.css("width")),d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var c=this.$activeItems?this.$activeItems.slice():null,e=[];d.children("[data-value]").each(function(){e.push(a(this).attr("data-value"))}),b.setValue(e),b.setActiveItem(c)}})}}()}}),I.define("dropdown_header",function(b){var c=this;b=a.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'<div class="'+a.headerClass+'">'+'<div class="'+a.titleRowClass+'">'+'<span class="'+a.labelClass+'">'+a.title+"</span>"+'<a href="javascript:void(0)" class="'+a.closeClass+'">×</a>'+"</div>"+"</div>"
|
3 |
+
}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),I.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},this.onKeyDown=function(){var a=c.onKeyDown;return function(b){var d,e,f,g;return!this.isOpen||b.keyCode!==j&&b.keyCode!==l?a.apply(this,arguments):(c.ignoreHover=!0,g=this.$activeOption.closest("[data-group]"),d=g.find("[data-selectable]").index(this.$activeOption),g=b.keyCode===j?g.prev("[data-group]"):g.next("[data-group]"),f=g.find("[data-selectable]"),e=f.eq(Math.min(f.length-1,d)),e.length&&this.setActiveOption(e),void 0)}}();var d=function(){var d,e,f,g,h,i,j;if(j=a("[data-group]",c.$dropdown_content),e=j.length,e&&c.$dropdown_content.width()){if(b.equalizeHeight){for(f=0,d=0;e>d;d++)f=Math.max(f,j.eq(d).height());j.css({height:f})}b.equalizeWidth&&(i=c.$dropdown_content.innerWidth(),g=Math.round(i/e),j.css({width:g}),e>1&&(h=i-g*(e-1),j.eq(e-1).css({width:h})))}};(b.equalizeHeight||b.equalizeWidth)&&(y.after(this,"positionDropdown",d),y.after(this,"refreshOptions",d))}),I.define("remove_button",function(b){if("single"!==this.settings.mode){b=a.extend({label:"×",title:"Remove",className:"remove",append:!0},b);var c=this,d='<a href="javascript:void(0)" class="'+b.className+'" tabindex="-1" title="'+x(b.title)+'">'+b.label+"</a>",e=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};this.setup=function(){var f=c.setup;return function(){if(b.append){var g=c.settings.render.item;c.settings.render.item=function(){return e(g.apply(this,arguments),d)}}f.apply(this,arguments),this.$control.on("click","."+b.className,function(b){b.preventDefault();var d=a(b.target).parent();c.setActiveItem(d),c.deleteSelection()&&c.setCaret(c.items.length)})}}()}}),I.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===n&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d<this.items.length)?(e=this.options[this.items[d]],this.deleteSelection(b)&&(this.setTextboxValue(a.text.apply(this,[e])),this.refreshOptions(!0)),b.preventDefault(),void 0):c.apply(this,arguments)}}()}),I});
|
lib/access/class-groups-access-meta-boxes.php
CHANGED
@@ -25,21 +25,27 @@
|
|
25 |
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
|
26 |
*/
|
27 |
class Groups_Access_Meta_Boxes {
|
28 |
-
|
29 |
-
const NONCE
|
30 |
const SET_CAPABILITY = 'set-capability';
|
31 |
-
const READ_ACCESS
|
32 |
-
const CAPABILITY
|
33 |
-
|
|
|
34 |
/**
|
35 |
* Hooks for capabilities meta box and saving options.
|
36 |
*/
|
37 |
public static function init() {
|
|
|
|
|
|
|
38 |
add_action( 'add_meta_boxes', array( __CLASS__, "add_meta_boxes" ), 10, 2 );
|
39 |
-
add_action( 'save_post', array( __CLASS__, "save_post" ) );
|
|
|
40 |
|
41 |
add_action( 'attachment_fields_to_edit', array( __CLASS__, 'attachment_fields_to_edit' ), 10, 2 );
|
42 |
add_action( 'attachment_fields_to_save', array( __CLASS__, 'attachment_fields_to_save' ), 10, 2 );
|
|
|
43 |
}
|
44 |
|
45 |
/**
|
@@ -73,10 +79,65 @@ class Groups_Access_Meta_Boxes {
|
|
73 |
"high"
|
74 |
);
|
75 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
}
|
78 |
}
|
79 |
-
|
80 |
/**
|
81 |
* Render meta box for capabilities.
|
82 |
*
|
@@ -89,6 +150,8 @@ class Groups_Access_Meta_Boxes {
|
|
89 |
|
90 |
$output = "";
|
91 |
|
|
|
|
|
92 |
$post_id = isset( $object->ID ) ? $object->ID : null;
|
93 |
$post_type = isset( $object->post_type ) ? $object->post_type : null;
|
94 |
$post_singular_name = __( "Post", GROUPS_PLUGIN_DOMAIN );
|
@@ -102,35 +165,99 @@ class Groups_Access_Meta_Boxes {
|
|
102 |
}
|
103 |
}
|
104 |
|
|
|
|
|
105 |
if ( self::user_can_restrict() ) {
|
106 |
$user = new Groups_User( get_current_user_id() );
|
107 |
$output .= __( "Enforce read access", GROUPS_PLUGIN_DOMAIN );
|
|
|
108 |
$read_caps = get_post_meta( $post_id, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
|
109 |
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
110 |
-
$output .= '<div
|
111 |
-
$output .=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
foreach( $valid_read_caps as $valid_read_cap ) {
|
113 |
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
114 |
if ( $user->can( $capability->capability ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
$checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : '';
|
116 |
-
$output .= '<
|
117 |
-
$output .= '<label>';
|
118 |
-
$output .= '<input name="' . self::CAPABILITY . '[]" ' . $checked . ' type="checkbox" value="' . esc_attr( $capability->capability_id ) . '" />';
|
119 |
$output .= wp_filter_nohtml_kses( $capability->capability );
|
120 |
-
$
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
}
|
124 |
}
|
125 |
-
$output .= '</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
$output .= '</div>';
|
127 |
-
|
128 |
$output .= '<p class="description">';
|
129 |
$output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
|
130 |
$output .= '</p>';
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
} else {
|
133 |
-
$output .= '<p class="description">';
|
134 |
$output .= sprintf( __( 'You cannot set any access restrictions.', GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
|
135 |
$style = 'cursor:help;vertical-align:middle;';
|
136 |
if ( current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
|
@@ -140,26 +267,76 @@ class Groups_Access_Meta_Boxes {
|
|
140 |
$output .= sprintf( '<img style="%s" alt="?" title="%s" src="%s" />', $style, esc_attr( __( 'You must be in a group that has at least one capability enabled to enforce read access.', GROUPS_PLUGIN_DOMAIN ) ), esc_attr( GROUPS_PLUGIN_URL . 'images/help.png' ) );
|
141 |
if ( current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
|
142 |
$output .= '</a>';
|
143 |
-
}
|
144 |
$output .= '</p>';
|
145 |
}
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
echo $output;
|
148 |
}
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
/**
|
151 |
* Save capability options.
|
152 |
*
|
153 |
* @param int $post_id
|
154 |
-
* @param mixed $post post data
|
155 |
*/
|
156 |
public static function save_post( $post_id = null, $post = null ) {
|
157 |
if ( ( defined( "DOING_AUTOSAVE" ) && DOING_AUTOSAVE ) ) {
|
158 |
} else {
|
159 |
$post_type = get_post_type( $post_id );
|
160 |
-
$post_type_object = get_post_type_object( $post_type );
|
161 |
-
if ( $post_type_object && $post_type != 'attachment' ) {
|
162 |
-
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
163 |
if ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) {
|
164 |
if ( isset( $_POST[self::NONCE] ) && wp_verify_nonce( $_POST[self::NONCE], self::SET_CAPABILITY ) ) {
|
165 |
$post_type = isset( $_POST["post_type"] ) ? $_POST["post_type"] : null;
|
@@ -169,21 +346,80 @@ class Groups_Access_Meta_Boxes {
|
|
169 |
// If the post ID is not provided, it will throw:
|
170 |
// PHP Notice: Undefined offset: 0 in /var/www/groups-forums/wp-includes/capabilities.php on line 1067
|
171 |
if ( current_user_can( 'edit_'.$post_type, $post_id ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
if ( self::user_can_restrict() ) {
|
173 |
-
$valid_read_caps = self::get_valid_read_caps_for_user();
|
174 |
-
foreach( $valid_read_caps as $valid_read_cap ) {
|
175 |
-
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
176 |
-
if ( !empty( $_POST[self::CAPABILITY] ) && is_array( $_POST[self::CAPABILITY] ) && in_array( $capability->capability_id, $_POST[self::CAPABILITY] ) ) {
|
177 |
-
Groups_Post_Access::create( array(
|
178 |
-
'post_id' => $post_id,
|
179 |
-
'capability' => $capability->capability
|
180 |
-
) );
|
181 |
-
} else {
|
182 |
-
Groups_Post_Access::delete( $post_id, $capability->capability );
|
183 |
-
}
|
184 |
-
}
|
185 |
}
|
186 |
}
|
|
|
|
|
187 |
}
|
188 |
}
|
189 |
}
|
@@ -192,6 +428,28 @@ class Groups_Access_Meta_Boxes {
|
|
192 |
}
|
193 |
}
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
/**
|
196 |
* Render capabilities box for attachment post type (Media).
|
197 |
* @param array $form_fields
|
@@ -199,55 +457,119 @@ class Groups_Access_Meta_Boxes {
|
|
199 |
* @return array
|
200 |
*/
|
201 |
public static function attachment_fields_to_edit( $form_fields, $post ) {
|
202 |
-
|
|
|
|
|
|
|
203 |
if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
|
204 |
if ( self::user_can_restrict() ) {
|
205 |
$user = new Groups_User( get_current_user_id() );
|
206 |
-
$output = "";
|
207 |
$post_singular_name = __( 'Media', GROUPS_PLUGIN_DOMAIN );
|
208 |
-
|
209 |
-
$output .= __( "Enforce read access", GROUPS_PLUGIN_DOMAIN );
|
210 |
$read_caps = get_post_meta( $post->ID, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
|
211 |
-
$valid_read_caps = self::get_valid_read_caps_for_user();
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
$output .= '</p>';
|
231 |
-
|
232 |
-
$form_fields['groups_access'] = array(
|
233 |
-
'label' => __( 'Access restrictions', GROUPS_PLUGIN_DOMAIN ),
|
234 |
-
'input' => 'html',
|
235 |
-
'html' => $output
|
236 |
);
|
237 |
}
|
238 |
-
}
|
239 |
-
return $form_fields;
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
* Save capabilities for attachment post type (Media).
|
244 |
-
* When multiple attachments are saved, this is called once for each.
|
245 |
-
* @param array $post post data
|
246 |
* @param array $attachment attachment field data
|
247 |
-
* @return array
|
248 |
-
*/
|
249 |
public static function attachment_fields_to_save( $post, $attachment ) {
|
250 |
-
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
251 |
if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
|
252 |
// if we're here, we assume the user is allowed to edit attachments,
|
253 |
// but we still need to check if the user can restrict access
|
@@ -263,9 +585,9 @@ class Groups_Access_Meta_Boxes {
|
|
263 |
foreach( $valid_read_caps as $valid_read_cap ) {
|
264 |
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
265 |
if ( !empty( $attachment[self::CAPABILITY] ) && is_array( $attachment[self::CAPABILITY] ) && in_array( $capability->capability_id, $attachment[self::CAPABILITY] ) ) {
|
266 |
-
Groups_Post_Access::create( array(
|
267 |
-
'post_id' => $post_id,
|
268 |
-
'capability' => $capability->capability
|
269 |
) );
|
270 |
} else {
|
271 |
Groups_Post_Access::delete( $post_id, $capability->capability );
|
@@ -274,8 +596,8 @@ class Groups_Access_Meta_Boxes {
|
|
274 |
}
|
275 |
}
|
276 |
}
|
277 |
-
}
|
278 |
-
return $post;
|
279 |
}
|
280 |
|
281 |
/**
|
@@ -285,18 +607,18 @@ class Groups_Access_Meta_Boxes {
|
|
285 |
*/
|
286 |
private static function user_can_restrict() {
|
287 |
$has_read_cap = false;
|
288 |
-
$user = new Groups_User( get_current_user_id() );
|
289 |
-
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
290 |
-
foreach( $valid_read_caps as $valid_read_cap ) {
|
291 |
-
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
292 |
if ( $user->can( $capability->capability_id ) ) {
|
293 |
$has_read_cap = true;
|
294 |
break;
|
295 |
-
}
|
296 |
}
|
297 |
}
|
298 |
return $has_read_cap;
|
299 |
-
}
|
300 |
|
301 |
/**
|
302 |
* @return array of valid read capabilities for the current or given user
|
@@ -305,8 +627,8 @@ class Groups_Access_Meta_Boxes {
|
|
305 |
$result = array();
|
306 |
$user = new Groups_User( $user_id === null ? get_current_user_id() : $user_id );
|
307 |
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
308 |
-
foreach( $valid_read_caps as $valid_read_cap ) {
|
309 |
-
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
310 |
if ( $user->can( $capability->capability ) ) {
|
311 |
$result[] = $valid_read_cap;
|
312 |
}
|
25 |
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
|
26 |
*/
|
27 |
class Groups_Access_Meta_Boxes {
|
28 |
+
|
29 |
+
const NONCE = 'groups-meta-box-nonce';
|
30 |
const SET_CAPABILITY = 'set-capability';
|
31 |
+
const READ_ACCESS = 'read-access';
|
32 |
+
const CAPABILITY = 'capability';
|
33 |
+
const SHOW_GROUPS = 'access-meta-box-show-groups';
|
34 |
+
|
35 |
/**
|
36 |
* Hooks for capabilities meta box and saving options.
|
37 |
*/
|
38 |
public static function init() {
|
39 |
+
|
40 |
+
require_once GROUPS_VIEWS_LIB . '/class-groups-uie.php';
|
41 |
+
|
42 |
add_action( 'add_meta_boxes', array( __CLASS__, "add_meta_boxes" ), 10, 2 );
|
43 |
+
add_action( 'save_post', array( __CLASS__, "save_post" ), 10, 2 );
|
44 |
+
add_filter( 'wp_insert_post_empty_content', array( __CLASS__, 'wp_insert_post_empty_content' ), 10, 2 );
|
45 |
|
46 |
add_action( 'attachment_fields_to_edit', array( __CLASS__, 'attachment_fields_to_edit' ), 10, 2 );
|
47 |
add_action( 'attachment_fields_to_save', array( __CLASS__, 'attachment_fields_to_save' ), 10, 2 );
|
48 |
+
|
49 |
}
|
50 |
|
51 |
/**
|
79 |
"high"
|
80 |
);
|
81 |
}
|
82 |
+
|
83 |
+
Groups_UIE::enqueue( 'select' );
|
84 |
+
|
85 |
+
if ( current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
|
86 |
+
if ( $screen = get_current_screen() ) {
|
87 |
+
$screen->add_help_tab( array(
|
88 |
+
'id' => 'groups-access',
|
89 |
+
'title' => __( 'Access restrictions', GROUPS_PLUGIN_DOMAIN ),
|
90 |
+
'content' =>
|
91 |
+
'<p>' .
|
92 |
+
'<strong>' . __( 'Access restrictions', GROUPS_PLUGIN_DOMAIN ) . '</strong>' .
|
93 |
+
'</p>' .
|
94 |
+
'<p>' .
|
95 |
+
__( 'Use the <em>Access restrictions</em> box to limit the visibility of posts, pages and other post types.', GROUPS_PLUGIN_DOMAIN ) .
|
96 |
+
'</p>' .
|
97 |
+
'<p>' .
|
98 |
+
__( 'You can select one or more capabilities that enabled for access restriction.', GROUPS_PLUGIN_DOMAIN ) .
|
99 |
+
' ' .
|
100 |
+
__( 'Note that you must be a member of a group that has such a capability assigned.', GROUPS_PLUGIN_DOMAIN ) .
|
101 |
+
'</p>' .
|
102 |
+
'<p>' .
|
103 |
+
'<strong>' . __( 'Example:', GROUPS_PLUGIN_DOMAIN ) . '</strong>' .
|
104 |
+
'</p>' .
|
105 |
+
__( 'Let\'s assume that you want to limit the visibility of a post to members of the <em>Premium</em> group.', GROUPS_PLUGIN_DOMAIN ) .
|
106 |
+
'<p>' .
|
107 |
+
'<strong>' . __( 'The quick way:', GROUPS_PLUGIN_DOMAIN ) . '</strong>' .
|
108 |
+
' ' .
|
109 |
+
__( 'Using the quick-create field', GROUPS_PLUGIN_DOMAIN ) .
|
110 |
+
'</p>' .
|
111 |
+
__( 'Enter <em>Premium</em> in the quick-create field located in the Access restrictions panel and save or update the post (or hit Enter).', GROUPS_PLUGIN_DOMAIN ) .
|
112 |
+
'<p>' .
|
113 |
+
'<p>' .
|
114 |
+
__( 'Using the quick-create field, you can create a new group and capability. The capability will be assigned to the group and enabled to enforce read access. Group names are case-sensitive, the name of the capability is the lower-case version of the name of the group. If the group already exists, a new capability is created and assigned to the existing group. If the capability already exists, it will be assigned to the group. If both already exist, the capability is enabled to enforce read access. In order to be able to use the capability, your user account will be assigned to the group.', GROUPS_PLUGIN_DOMAIN ) .
|
115 |
+
'</p>' .
|
116 |
+
'<em>' . __( 'The manual way:', GROUPS_PLUGIN_DOMAIN ) . '</em>' .
|
117 |
+
' ' .
|
118 |
+
__( 'Adding the group and capability manually and enabling it for access restriction', GROUPS_PLUGIN_DOMAIN ) .
|
119 |
+
'</p>' .
|
120 |
+
'<p>' .
|
121 |
+
__( 'Try the quick-create field first. Unless you need a more complex setup, there is no reason to go this way instead.', GROUPS_PLUGIN_DOMAIN ) .
|
122 |
+
'</p>' .
|
123 |
+
'<ol>' .
|
124 |
+
'<li>' . __( 'Go to <strong>Groups > Groups</strong> and add the <em>Premium</em> group.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
125 |
+
'<li>' . __( 'Go to <strong>Groups > Capabilities</strong> and add the <em>premium</em> capability.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
126 |
+
'<li>' . __( 'Go to <strong>Groups > Groups</strong> and assign the <em>premium</em> capability to the <em>Premium</em> group.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
127 |
+
'<li>' . __( 'Go to <strong>Groups > Options</strong> and enable the <em>premium</em> capability to restrict access.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
128 |
+
'<li>' . __( 'Become a member of the <em>Premium</em> group - this is required so you can choose the <em>premium</em> capability to restrict access to a post.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
129 |
+
'<li>' . __( 'Edit the post for which you want to restrict access and choose<sup>*</sup> the <em>premium</em> capability.', GROUPS_PLUGIN_DOMAIN ) . '</li>' .
|
130 |
+
'</ol>' .
|
131 |
+
'<p>' .
|
132 |
+
__( '<sup>*</sup> For each capability, the groups that have the capability assigned are shown within parenthesis. You can choose a capability by typing part of the group\'s or the capability\'s name.', GROUPS_PLUGIN_DOMAIN ) .
|
133 |
+
'</p>'
|
134 |
+
) );
|
135 |
+
}
|
136 |
+
}
|
137 |
}
|
138 |
}
|
139 |
}
|
140 |
+
|
141 |
/**
|
142 |
* Render meta box for capabilities.
|
143 |
*
|
150 |
|
151 |
$output = "";
|
152 |
|
153 |
+
$show_groups = Groups_Options::get_user_option( self::SHOW_GROUPS, true );
|
154 |
+
|
155 |
$post_id = isset( $object->ID ) ? $object->ID : null;
|
156 |
$post_type = isset( $object->post_type ) ? $object->post_type : null;
|
157 |
$post_singular_name = __( "Post", GROUPS_PLUGIN_DOMAIN );
|
165 |
}
|
166 |
}
|
167 |
|
168 |
+
$output .= wp_nonce_field( self::SET_CAPABILITY, self::NONCE, true, false );
|
169 |
+
|
170 |
if ( self::user_can_restrict() ) {
|
171 |
$user = new Groups_User( get_current_user_id() );
|
172 |
$output .= __( "Enforce read access", GROUPS_PLUGIN_DOMAIN );
|
173 |
+
|
174 |
$read_caps = get_post_meta( $post_id, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
|
175 |
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
176 |
+
$output .= '<div class="select-capability-container">';
|
177 |
+
$output .= sprintf(
|
178 |
+
'<select class="select capability" name="%s" multiple="multiple" placeholder="%s" data-placeholder="%s" title="%s">',
|
179 |
+
self::CAPABILITY . '[]',
|
180 |
+
__( 'Type and choose …', GROUPS_PLUGIN_DOMAIN),
|
181 |
+
__( 'Type and choose …', GROUPS_PLUGIN_DOMAIN),
|
182 |
+
__( 'Choose one or more capabilities to restrict access. Groups that grant access through the capabilities are shown in parenthesis. If no capabilities are available yet, you can use the quick-create box to create a group and capability enabled for access restriction on the fly.', GROUPS_PLUGIN_DOMAIN )
|
183 |
+
);
|
184 |
+
$output .= '<option value=""></option>';
|
185 |
foreach( $valid_read_caps as $valid_read_cap ) {
|
186 |
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
187 |
if ( $user->can( $capability->capability ) ) {
|
188 |
+
$c = new Groups_Capability( $capability->capability_id );
|
189 |
+
$groups = $c->groups;
|
190 |
+
$group_names = array();
|
191 |
+
if ( !empty( $groups ) ) {
|
192 |
+
foreach( $groups as $group ) {
|
193 |
+
$group_names[] = $group->name;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
if ( count( $group_names ) > 0 ) {
|
197 |
+
$label_title = sprintf(
|
198 |
+
_n(
|
199 |
+
'Members of the %1$s group can access this %2$s through this capability.',
|
200 |
+
'Members of the %1$s groups can access this %2$s through this capability.',
|
201 |
+
count( $group_names ),
|
202 |
+
GROUPS_PLUGIN_DOMAIN
|
203 |
+
),
|
204 |
+
wp_filter_nohtml_kses( implode( ',', $group_names ) ),
|
205 |
+
$post_singular_name
|
206 |
+
);
|
207 |
+
} else {
|
208 |
+
$label_title = __( 'No groups grant access through this capability. To grant access to group members using this capability, you should assign it to a group and enable the capability for access restriction.', GROUPS_PLUGIN_DOMAIN );
|
209 |
+
}
|
210 |
$checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : '';
|
211 |
+
$output .= sprintf( '<option value="%s" %s>', esc_attr( $capability->capability_id ), in_array( $capability->capability, $read_caps ) ? ' selected="selected" ' : '' );
|
|
|
|
|
212 |
$output .= wp_filter_nohtml_kses( $capability->capability );
|
213 |
+
if ( $show_groups ) {
|
214 |
+
if ( count( $group_names ) > 0 ) {
|
215 |
+
$output .= ' ';
|
216 |
+
$output .= '(' . wp_filter_nohtml_kses( implode( ', ', $group_names ) ) . ')';
|
217 |
+
}
|
218 |
+
}
|
219 |
+
$output .= '</option>';
|
220 |
}
|
221 |
}
|
222 |
}
|
223 |
+
$output .= '</select>';
|
224 |
+
|
225 |
+
$output .= Groups_UIE::render_select( '.select.capability' );
|
226 |
+
// $output .= '<script type="text/javascript">';
|
227 |
+
// $output .= 'if (typeof jQuery !== "undefined"){';
|
228 |
+
// if ( self::WHICH_SELECT == 'chosen' ) {
|
229 |
+
// $output .= 'jQuery(".select.capability").chosen({width:"100%",search_contains:true});';
|
230 |
+
// } else {
|
231 |
+
// $output .= 'jQuery(".select.capability").selectize({plugins: ["remove_button"]});';
|
232 |
+
// }
|
233 |
+
// $output .= '}';
|
234 |
+
// $output .= '</script>';
|
235 |
+
// $output .= '<style type="text/css">';
|
236 |
+
// $output .= '.select-capability-container input[type="text"] { min-height: 2em; }';
|
237 |
+
// $output .= '</style>';
|
238 |
$output .= '</div>';
|
239 |
+
|
240 |
$output .= '<p class="description">';
|
241 |
$output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
|
242 |
$output .= '</p>';
|
243 |
+
|
244 |
+
$output .= '<p class="description">';
|
245 |
+
$output .= sprintf( '<label title="%s">', __( 'Click to toggle the display of groups that grant the capabilities.', GROUPS_PLUGIN_DOMAIN ) );
|
246 |
+
$output .= sprintf( '<input id="access-show-groups" type="checkbox" name="%s" %s />', esc_attr( self::SHOW_GROUPS ), $show_groups ? ' checked="checked" ' : '' );
|
247 |
+
$output .= ' ';
|
248 |
+
$output .= __( 'Show groups', GROUPS_PLUGIN_DOMAIN );
|
249 |
+
$output .= '</label>';
|
250 |
+
$output .= '</p>';
|
251 |
+
$output .= '<script type="text/javascript">';
|
252 |
+
$output .= 'if (typeof jQuery !== "undefined"){';
|
253 |
+
$output .= !$show_groups ? 'jQuery("span.groups.description").hide();' : '';
|
254 |
+
$output .= 'jQuery("#access-show-groups").click(function(){';
|
255 |
+
$output .= 'jQuery("span.groups.description").toggle();';
|
256 |
+
$output .= '});';
|
257 |
+
$output .= '}';
|
258 |
+
$output .= '</script>';
|
259 |
} else {
|
260 |
+
$output .= '<p class="description">';
|
261 |
$output .= sprintf( __( 'You cannot set any access restrictions.', GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
|
262 |
$style = 'cursor:help;vertical-align:middle;';
|
263 |
if ( current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
|
267 |
$output .= sprintf( '<img style="%s" alt="?" title="%s" src="%s" />', $style, esc_attr( __( 'You must be in a group that has at least one capability enabled to enforce read access.', GROUPS_PLUGIN_DOMAIN ) ), esc_attr( GROUPS_PLUGIN_URL . 'images/help.png' ) );
|
268 |
if ( current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
|
269 |
$output .= '</a>';
|
270 |
+
}
|
271 |
$output .= '</p>';
|
272 |
}
|
273 |
|
274 |
+
// quick-create
|
275 |
+
if ( current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
|
276 |
+
$style = 'cursor:help;vertical-align:middle;';
|
277 |
+
$output .= '<div class="quick-create-group-capability" style="margin:4px 0">';
|
278 |
+
$output .= '<label>';
|
279 |
+
$output .= sprintf( '<input style="width:100%%;margin-right:-20px;" id="quick-group-capability" name="quick-group-capability" class="quick-group-capability" type="text" value="" placeholder="%s"/>', __( 'Quick-create group & capability', GROUPS_PLUGIN_DOMAIN ) );
|
280 |
+
$output .= sprintf(
|
281 |
+
'<img id="quick-create-help-icon" style="%s" alt="?" title="%s" src="%s" />',
|
282 |
+
$style,
|
283 |
+
esc_attr( __( 'You can create a new group and capability here. The capability will be assigned to the group and enabled to enforce read access. Group names are case-sensitive, the name of the capability is the lower-case version of the name of the group. If the group already exists, a new capability is created and assigned to the existing group. If the capability already exists, it will be assigned to the group. If both already exist, the capability is enabled to enforce read access. In order to be able to use the capability, your user account will be assigned to the group.', GROUPS_PLUGIN_DOMAIN ) ),
|
284 |
+
esc_attr( GROUPS_PLUGIN_URL . 'images/help.png' )
|
285 |
+
);
|
286 |
+
$output .= '</label>';
|
287 |
+
$output .= '</div>';
|
288 |
+
$output .= '<script type="text/javascript">';
|
289 |
+
$output .= 'if (typeof jQuery !== "undefined"){';
|
290 |
+
$output .= 'jQuery("#quick-create-help-icon").click(function(){';
|
291 |
+
$output .= 'jQuery("#contextual-help-link").click();';
|
292 |
+
$output .= '});';
|
293 |
+
$output .= '}';
|
294 |
+
$output .= '</script>';
|
295 |
+
}
|
296 |
+
|
297 |
echo $output;
|
298 |
}
|
299 |
|
300 |
+
/**
|
301 |
+
* Invokes our save_post() if the post content is considered empty.
|
302 |
+
* This is required because even on an empty post, we want to allow to
|
303 |
+
* quick-create group and category as well as assign capabilities.
|
304 |
+
* At WordPress 3.6.1, this is the only way we can achieve that, because
|
305 |
+
* the save_post action is not invoked if the post content is considered
|
306 |
+
* empty.
|
307 |
+
*
|
308 |
+
* @param boolean $maybe_empty
|
309 |
+
* @param array $postarr
|
310 |
+
* @return boolean
|
311 |
+
*/
|
312 |
+
public static function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
|
313 |
+
|
314 |
+
// Only consider invoking save_post() here, if the post content is
|
315 |
+
// considered to be empty at this stage. This is so we don't end up
|
316 |
+
// having save_post() invoked twice when the post is not empty.
|
317 |
+
if ( $maybe_empty ) {
|
318 |
+
$post_id = !empty( $postarr['ID'] ) ? $postarr['ID'] : !empty( $postarr['post_ID'] ) ? $postarr['post_ID'] : null;
|
319 |
+
if ( $post_id ) {
|
320 |
+
self::save_post( $post_id );
|
321 |
+
}
|
322 |
+
}
|
323 |
+
|
324 |
+
return $maybe_empty;
|
325 |
+
}
|
326 |
+
|
327 |
/**
|
328 |
* Save capability options.
|
329 |
*
|
330 |
* @param int $post_id
|
331 |
+
* @param mixed $post post data (not used here)
|
332 |
*/
|
333 |
public static function save_post( $post_id = null, $post = null ) {
|
334 |
if ( ( defined( "DOING_AUTOSAVE" ) && DOING_AUTOSAVE ) ) {
|
335 |
} else {
|
336 |
$post_type = get_post_type( $post_id );
|
337 |
+
$post_type_object = get_post_type_object( $post_type );
|
338 |
+
if ( $post_type_object && $post_type != 'attachment' ) {
|
339 |
+
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
340 |
if ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) {
|
341 |
if ( isset( $_POST[self::NONCE] ) && wp_verify_nonce( $_POST[self::NONCE], self::SET_CAPABILITY ) ) {
|
342 |
$post_type = isset( $_POST["post_type"] ) ? $_POST["post_type"] : null;
|
346 |
// If the post ID is not provided, it will throw:
|
347 |
// PHP Notice: Undefined offset: 0 in /var/www/groups-forums/wp-includes/capabilities.php on line 1067
|
348 |
if ( current_user_can( 'edit_'.$post_type, $post_id ) ) {
|
349 |
+
// quick-create ?
|
350 |
+
if ( current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
|
351 |
+
if ( !empty( $_POST['quick-group-capability'] ) ) {
|
352 |
+
$creator_id = get_current_user_id();
|
353 |
+
$datetime = date( 'Y-m-d H:i:s', time() );
|
354 |
+
$name = ucfirst( strtolower( trim( $_POST['quick-group-capability'] ) ) );
|
355 |
+
if ( strlen( $name ) > 0 ) {
|
356 |
+
// create or obtain the group
|
357 |
+
if ( $group = Groups_Group::read_by_name( $name ) ) {
|
358 |
+
} else {
|
359 |
+
if ( $group_id = Groups_Group::create( compact( 'creator_id', 'datetime', 'name' ) ) ) {
|
360 |
+
$group = Groups_Group::read( $group_id );
|
361 |
+
}
|
362 |
+
}
|
363 |
+
// create or obtain the capability
|
364 |
+
$name = strtolower( $name );
|
365 |
+
if ( $capability = Groups_Capability::read_by_capability( $name ) ) {
|
366 |
+
} else {
|
367 |
+
if ( $capability_id = Groups_Capability::create( array( 'capability' => $name ) ) ) {
|
368 |
+
$capability = Groups_Capability::read( $capability_id );
|
369 |
+
}
|
370 |
+
}
|
371 |
+
if ( $group && $capability ) {
|
372 |
+
// add the capability to the group
|
373 |
+
if ( !Groups_Group_Capability::read( $group->group_id, $capability->capability_id ) ) {
|
374 |
+
Groups_Group_Capability::create(
|
375 |
+
array(
|
376 |
+
'group_id' => $group->group_id,
|
377 |
+
'capability_id' => $capability->capability_id
|
378 |
+
)
|
379 |
+
);
|
380 |
+
}
|
381 |
+
// enable the capability for access restriction
|
382 |
+
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
383 |
+
if ( !in_array( $capability->capability, $valid_read_caps ) ) {
|
384 |
+
$valid_read_caps[] = $capability->capability;
|
385 |
+
}
|
386 |
+
Groups_Options::update_option( Groups_Post_Access::READ_POST_CAPABILITIES, $valid_read_caps );
|
387 |
+
// add the current user to the group
|
388 |
+
Groups_User_Group::create(
|
389 |
+
array(
|
390 |
+
'user_id' => get_current_user_id(),
|
391 |
+
'group_id' => $group->group_id
|
392 |
+
)
|
393 |
+
);
|
394 |
+
// put the capability ID in $_POST[self::CAPABILITY] so it is treated below
|
395 |
+
if ( empty( $_POST[self::CAPABILITY] ) ) {
|
396 |
+
$_POST[self::CAPABILITY] = array();
|
397 |
+
}
|
398 |
+
if ( !in_array( $capability->capability_id, $_POST[self::CAPABILITY] ) ) {
|
399 |
+
$_POST[self::CAPABILITY][] = $capability->capability_id;
|
400 |
+
}
|
401 |
+
}
|
402 |
+
}
|
403 |
+
}
|
404 |
+
}
|
405 |
+
// set
|
406 |
if ( self::user_can_restrict() ) {
|
407 |
+
$valid_read_caps = self::get_valid_read_caps_for_user();
|
408 |
+
foreach( $valid_read_caps as $valid_read_cap ) {
|
409 |
+
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
410 |
+
if ( !empty( $_POST[self::CAPABILITY] ) && is_array( $_POST[self::CAPABILITY] ) && in_array( $capability->capability_id, $_POST[self::CAPABILITY] ) ) {
|
411 |
+
Groups_Post_Access::create( array(
|
412 |
+
'post_id' => $post_id,
|
413 |
+
'capability' => $capability->capability
|
414 |
+
) );
|
415 |
+
} else {
|
416 |
+
Groups_Post_Access::delete( $post_id, $capability->capability );
|
417 |
+
}
|
418 |
+
}
|
419 |
}
|
420 |
}
|
421 |
+
// show groups
|
422 |
+
Groups_Options::update_user_option( self::SHOW_GROUPS, !empty( $_POST[self::SHOW_GROUPS] ) );
|
423 |
}
|
424 |
}
|
425 |
}
|
428 |
}
|
429 |
}
|
430 |
|
431 |
+
/**
|
432 |
+
* Enqueue scripts and styles.
|
433 |
+
*/
|
434 |
+
private static function enqueue() {
|
435 |
+
global $groups_version;
|
436 |
+
if ( self::WHICH_SELECT == 'chosen' ) {
|
437 |
+
if ( !wp_script_is( 'chosen' ) ) {
|
438 |
+
wp_enqueue_script( 'chosen', GROUPS_PLUGIN_URL . 'js/chosen/chosen.jquery.min.js', array( 'jquery' ), $groups_version, false );
|
439 |
+
}
|
440 |
+
if ( !wp_style_is( 'chosen' ) ) {
|
441 |
+
wp_enqueue_style( 'chosen', GROUPS_PLUGIN_URL . 'css/chosen/chosen.min.css', array(), $groups_version );
|
442 |
+
}
|
443 |
+
} else {
|
444 |
+
if ( !wp_script_is( 'selectize' ) ) {
|
445 |
+
wp_enqueue_script( 'selectize', GROUPS_PLUGIN_URL . 'js/selectize/selectize.min.js', array( 'jquery' ), $groups_version, false );
|
446 |
+
}
|
447 |
+
if ( !wp_style_is( 'selectize' ) ) {
|
448 |
+
wp_enqueue_style( 'selectize', GROUPS_PLUGIN_URL . 'css/selectize/selectize.bootstrap2.css', array(), $groups_version );
|
449 |
+
}
|
450 |
+
}
|
451 |
+
}
|
452 |
+
|
453 |
/**
|
454 |
* Render capabilities box for attachment post type (Media).
|
455 |
* @param array $form_fields
|
457 |
* @return array
|
458 |
*/
|
459 |
public static function attachment_fields_to_edit( $form_fields, $post ) {
|
460 |
+
|
461 |
+
Groups_UIE::enqueue( 'select' );
|
462 |
+
|
463 |
+
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
464 |
if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
|
465 |
if ( self::user_can_restrict() ) {
|
466 |
$user = new Groups_User( get_current_user_id() );
|
467 |
+
$output = "";
|
468 |
$post_singular_name = __( 'Media', GROUPS_PLUGIN_DOMAIN );
|
469 |
+
|
470 |
+
$output .= __( "Enforce read access", GROUPS_PLUGIN_DOMAIN );
|
471 |
$read_caps = get_post_meta( $post->ID, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
|
472 |
+
$valid_read_caps = self::get_valid_read_caps_for_user();
|
473 |
+
|
474 |
+
// @todo On attachments edited within the 'Insert Media' popup, the update is triggered too soon and we end up with only the last capability selected.
|
475 |
+
// This occurs when using normal checkboxes as well as the select below (Chosen and Selectize tested).
|
476 |
+
// With checkboxes it's even more confusing, it's actually better to have it using a select as below,
|
477 |
+
// because the visual feedback corresponds with what is assigned.
|
478 |
+
|
479 |
+
// $output .= '<div style="padding:0 1em;margin:1em 0;border:1px solid #ccc;border-radius:4px;">';
|
480 |
+
// $output .= '<ul>';
|
481 |
+
// foreach( $valid_read_caps as $valid_read_cap ) {
|
482 |
+
// if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
483 |
+
// $checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : '';
|
484 |
+
// $output .= '<li>';
|
485 |
+
// $output .= '<label>';
|
486 |
+
// $output .= '<input name="attachments[' . $post->ID . '][' . self::CAPABILITY . '][]" ' . $checked . ' type="checkbox" value="' . esc_attr( $capability->capability_id ) . '" />';
|
487 |
+
// $output .= wp_filter_nohtml_kses( $capability->capability );
|
488 |
+
// $output .= '</label>';
|
489 |
+
// $output .= '</li>';
|
490 |
+
// }
|
491 |
+
// }
|
492 |
+
// $output .= '</ul>';
|
493 |
+
// $output .= '</div>';
|
494 |
+
|
495 |
+
$show_groups = Groups_Options::get_user_option( self::SHOW_GROUPS, true );
|
496 |
+
$output .= '<div class="select-capability-container">';
|
497 |
+
$select_id = 'attachments-' . $post->ID . '-' . self::CAPABILITY;
|
498 |
+
$output .= sprintf(
|
499 |
+
'<select id="%s" class="select capability" name="%s" multiple="multiple" data-placeholder="%s" title="%s">',
|
500 |
+
$select_id,
|
501 |
+
'attachments[' . $post->ID . '][' . self::CAPABILITY . '][]',
|
502 |
+
__( 'Type and choose …', GROUPS_PLUGIN_DOMAIN),
|
503 |
+
__( 'Choose one or more capabilities to restrict access. Groups that grant access through the capabilities are shown in parenthesis. If no capabilities are available yet, you can use the quick-create box to create a group and capability enabled for access restriction on the fly.', GROUPS_PLUGIN_DOMAIN )
|
504 |
+
);
|
505 |
+
$output .= '<option value=""></option>';
|
506 |
+
foreach( $valid_read_caps as $valid_read_cap ) {
|
507 |
+
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
508 |
+
if ( $user->can( $capability->capability ) ) {
|
509 |
+
$c = new Groups_Capability( $capability->capability_id );
|
510 |
+
$groups = $c->groups;
|
511 |
+
$group_names = array();
|
512 |
+
if ( !empty( $groups ) ) {
|
513 |
+
foreach( $groups as $group ) {
|
514 |
+
$group_names[] = $group->name;
|
515 |
+
}
|
516 |
+
}
|
517 |
+
if ( count( $group_names ) > 0 ) {
|
518 |
+
$label_title = sprintf(
|
519 |
+
_n(
|
520 |
+
'Members of the %1$s group can access this %2$s through this capability.',
|
521 |
+
'Members of the %1$s groups can access this %2$s through this capability.',
|
522 |
+
count( $group_names ),
|
523 |
+
GROUPS_PLUGIN_DOMAIN
|
524 |
+
),
|
525 |
+
wp_filter_nohtml_kses( implode( ',', $group_names ) ),
|
526 |
+
$post_singular_name
|
527 |
+
);
|
528 |
+
} else {
|
529 |
+
$label_title = __( 'No groups grant access through this capability. To grant access to group members using this capability, you should assign it to a group and enable the capability for access restriction.', GROUPS_PLUGIN_DOMAIN );
|
530 |
+
}
|
531 |
+
$checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : '';
|
532 |
+
$output .= sprintf( '<option value="%s" %s>', esc_attr( $capability->capability_id ), in_array( $capability->capability, $read_caps ) ? ' selected="selected" ' : '' );
|
533 |
+
$output .= wp_filter_nohtml_kses( $capability->capability );
|
534 |
+
if ( $show_groups ) {
|
535 |
+
if ( count( $group_names ) > 0 ) {
|
536 |
+
$output .= ' ';
|
537 |
+
$output .= '(' . wp_filter_nohtml_kses( implode( ', ', $group_names ) ) . ')';
|
538 |
+
}
|
539 |
+
}
|
540 |
+
$output .= '</option>';
|
541 |
+
}
|
542 |
+
}
|
543 |
+
}
|
544 |
+
$output .= '</select>';
|
545 |
+
|
546 |
+
$output .= Groups_UIE::render_select( '#'.$select_id );
|
547 |
+
|
548 |
+
$output .= '</div>';
|
549 |
+
|
550 |
+
$output .= '<p class="description">';
|
551 |
+
$output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
|
552 |
$output .= '</p>';
|
553 |
+
|
554 |
+
$form_fields['groups_access'] = array(
|
555 |
+
'label' => __( 'Access restrictions', GROUPS_PLUGIN_DOMAIN ),
|
556 |
+
'input' => 'html',
|
557 |
+
'html' => $output
|
558 |
);
|
559 |
}
|
560 |
+
}
|
561 |
+
return $form_fields;
|
562 |
+
}
|
563 |
+
|
564 |
+
/**
|
565 |
* Save capabilities for attachment post type (Media).
|
566 |
+
* When multiple attachments are saved, this is called once for each.
|
567 |
+
* @param array $post post data
|
568 |
* @param array $attachment attachment field data
|
569 |
+
* @return array
|
570 |
+
*/
|
571 |
public static function attachment_fields_to_save( $post, $attachment ) {
|
572 |
+
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
573 |
if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
|
574 |
// if we're here, we assume the user is allowed to edit attachments,
|
575 |
// but we still need to check if the user can restrict access
|
585 |
foreach( $valid_read_caps as $valid_read_cap ) {
|
586 |
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
587 |
if ( !empty( $attachment[self::CAPABILITY] ) && is_array( $attachment[self::CAPABILITY] ) && in_array( $capability->capability_id, $attachment[self::CAPABILITY] ) ) {
|
588 |
+
Groups_Post_Access::create( array(
|
589 |
+
'post_id' => $post_id,
|
590 |
+
'capability' => $capability->capability
|
591 |
) );
|
592 |
} else {
|
593 |
Groups_Post_Access::delete( $post_id, $capability->capability );
|
596 |
}
|
597 |
}
|
598 |
}
|
599 |
+
}
|
600 |
+
return $post;
|
601 |
}
|
602 |
|
603 |
/**
|
607 |
*/
|
608 |
private static function user_can_restrict() {
|
609 |
$has_read_cap = false;
|
610 |
+
$user = new Groups_User( get_current_user_id() );
|
611 |
+
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
612 |
+
foreach( $valid_read_caps as $valid_read_cap ) {
|
613 |
+
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
614 |
if ( $user->can( $capability->capability_id ) ) {
|
615 |
$has_read_cap = true;
|
616 |
break;
|
617 |
+
}
|
618 |
}
|
619 |
}
|
620 |
return $has_read_cap;
|
621 |
+
}
|
622 |
|
623 |
/**
|
624 |
* @return array of valid read capabilities for the current or given user
|
627 |
$result = array();
|
628 |
$user = new Groups_User( $user_id === null ? get_current_user_id() : $user_id );
|
629 |
$valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
630 |
+
foreach( $valid_read_caps as $valid_read_cap ) {
|
631 |
+
if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
|
632 |
if ( $user->can( $capability->capability ) ) {
|
633 |
$result[] = $valid_read_cap;
|
634 |
}
|
lib/admin/class-groups-admin.php
CHANGED
@@ -23,13 +23,17 @@
|
|
23 |
* Groups admin sections initialization.
|
24 |
*/
|
25 |
class Groups_Admin {
|
|
|
|
|
|
|
|
|
26 |
public static function init() {
|
27 |
add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
|
28 |
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
|
29 |
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
|
30 |
add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
|
31 |
}
|
32 |
-
|
33 |
/**
|
34 |
* Hooks into admin_init.
|
35 |
* @see Groups_Admin::admin_menu()
|
@@ -39,8 +43,9 @@ class Groups_Admin {
|
|
39 |
public static function admin_init() {
|
40 |
global $groups_version;
|
41 |
wp_register_style( 'groups_admin', GROUPS_PLUGIN_URL . 'css/groups_admin.css', array(), $groups_version );
|
|
|
42 |
}
|
43 |
-
|
44 |
/**
|
45 |
* Loads styles for the Groups admin section.
|
46 |
*
|
@@ -49,15 +54,17 @@ class Groups_Admin {
|
|
49 |
public static function admin_print_styles() {
|
50 |
wp_enqueue_style( 'groups_admin' );
|
51 |
}
|
52 |
-
|
53 |
/**
|
54 |
* Loads scripts.
|
55 |
*/
|
56 |
public static function admin_print_scripts() {
|
57 |
global $groups_version;
|
58 |
-
|
|
|
|
|
59 |
}
|
60 |
-
|
61 |
/**
|
62 |
* Prints admin notices.
|
63 |
*/
|
@@ -69,18 +76,18 @@ class Groups_Admin {
|
|
69 |
}
|
70 |
}
|
71 |
}
|
72 |
-
|
73 |
/**
|
74 |
* Admin menu.
|
75 |
*/
|
76 |
public static function admin_menu() {
|
77 |
-
|
78 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-groups.php');
|
79 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-capabilities.php');
|
80 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
|
81 |
-
|
82 |
$pages = array();
|
83 |
-
|
84 |
// main
|
85 |
$page = add_menu_page(
|
86 |
__( 'Groups', GROUPS_PLUGIN_DOMAIN ),
|
@@ -109,7 +116,7 @@ class Groups_Admin {
|
|
109 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
110 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
111 |
}
|
112 |
-
|
113 |
// capabilities
|
114 |
$page = add_submenu_page(
|
115 |
'groups-admin',
|
@@ -122,7 +129,7 @@ class Groups_Admin {
|
|
122 |
$pages[] = $page;
|
123 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
124 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
125 |
-
|
126 |
// options
|
127 |
$page = add_submenu_page(
|
128 |
'groups-admin',
|
@@ -135,19 +142,19 @@ class Groups_Admin {
|
|
135 |
$pages[] = $page;
|
136 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
137 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
138 |
-
|
139 |
do_action( 'groups_admin_menu', $pages );
|
140 |
}
|
141 |
-
|
142 |
/**
|
143 |
* Network admin menu.
|
144 |
*/
|
145 |
public static function network_admin_menu() {
|
146 |
-
|
147 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
|
148 |
-
|
149 |
$pages = array();
|
150 |
-
|
151 |
// main
|
152 |
$page = add_menu_page(
|
153 |
__( 'Groups', GROUPS_PLUGIN_DOMAIN ),
|
23 |
* Groups admin sections initialization.
|
24 |
*/
|
25 |
class Groups_Admin {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Sets up action hooks.
|
29 |
+
*/
|
30 |
public static function init() {
|
31 |
add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
|
32 |
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
|
33 |
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
|
34 |
add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
|
35 |
}
|
36 |
+
|
37 |
/**
|
38 |
* Hooks into admin_init.
|
39 |
* @see Groups_Admin::admin_menu()
|
43 |
public static function admin_init() {
|
44 |
global $groups_version;
|
45 |
wp_register_style( 'groups_admin', GROUPS_PLUGIN_URL . 'css/groups_admin.css', array(), $groups_version );
|
46 |
+
require_once GROUPS_VIEWS_LIB . '/class-groups-uie.php';
|
47 |
}
|
48 |
+
|
49 |
/**
|
50 |
* Loads styles for the Groups admin section.
|
51 |
*
|
54 |
public static function admin_print_styles() {
|
55 |
wp_enqueue_style( 'groups_admin' );
|
56 |
}
|
57 |
+
|
58 |
/**
|
59 |
* Loads scripts.
|
60 |
*/
|
61 |
public static function admin_print_scripts() {
|
62 |
global $groups_version;
|
63 |
+
// this one's currently empty
|
64 |
+
//wp_enqueue_script( 'groups_admin', GROUPS_PLUGIN_URL . 'js/groups_admin.js', array( ), $groups_version );
|
65 |
+
Groups_UIE::enqueue( 'select' );
|
66 |
}
|
67 |
+
|
68 |
/**
|
69 |
* Prints admin notices.
|
70 |
*/
|
76 |
}
|
77 |
}
|
78 |
}
|
79 |
+
|
80 |
/**
|
81 |
* Admin menu.
|
82 |
*/
|
83 |
public static function admin_menu() {
|
84 |
+
|
85 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-groups.php');
|
86 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-capabilities.php');
|
87 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
|
88 |
+
|
89 |
$pages = array();
|
90 |
+
|
91 |
// main
|
92 |
$page = add_menu_page(
|
93 |
__( 'Groups', GROUPS_PLUGIN_DOMAIN ),
|
116 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
117 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
118 |
}
|
119 |
+
|
120 |
// capabilities
|
121 |
$page = add_submenu_page(
|
122 |
'groups-admin',
|
129 |
$pages[] = $page;
|
130 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
131 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
132 |
+
|
133 |
// options
|
134 |
$page = add_submenu_page(
|
135 |
'groups-admin',
|
142 |
$pages[] = $page;
|
143 |
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) );
|
144 |
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'admin_print_scripts' ) );
|
145 |
+
|
146 |
do_action( 'groups_admin_menu', $pages );
|
147 |
}
|
148 |
+
|
149 |
/**
|
150 |
* Network admin menu.
|
151 |
*/
|
152 |
public static function network_admin_menu() {
|
153 |
+
|
154 |
include_once( GROUPS_ADMIN_LIB . '/groups-admin-options.php');
|
155 |
+
|
156 |
$pages = array();
|
157 |
+
|
158 |
// main
|
159 |
$page = add_menu_page(
|
160 |
__( 'Groups', GROUPS_PLUGIN_DOMAIN ),
|
lib/admin/groups-admin-options.php
CHANGED
@@ -180,8 +180,8 @@ function groups_admin_options() {
|
|
180 |
echo
|
181 |
'<form action="" name="options" method="post">' .
|
182 |
|
183 |
-
'<p>' .
|
184 |
-
'<input class="button" type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
|
185 |
'</p>' .
|
186 |
|
187 |
'<div>' .
|
@@ -221,9 +221,9 @@ function groups_admin_options() {
|
|
221 |
echo '<ul>';
|
222 |
echo
|
223 |
'<p class="description">' .
|
224 |
-
__( 'This determines for which post types access restriction settings are offered.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
|
225 |
-
__( 'Disabling this setting for a post type does not remove existing access restrictions on individual posts of that type.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
|
226 |
-
'</p>';
|
227 |
|
228 |
|
229 |
echo '<h4>' . __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) . '</h4>';
|
@@ -235,27 +235,27 @@ function groups_admin_options() {
|
|
235 |
$capability_table = _groups_get_tablename( "capability" );
|
236 |
$capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" );
|
237 |
$applicable_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
|
|
|
|
238 |
foreach( $capabilities as $capability ) {
|
239 |
-
$
|
240 |
if ( $capability->capability == Groups_Post_Access::READ_POST_CAPABILITY ) {
|
241 |
-
$
|
242 |
}
|
243 |
-
|
244 |
-
echo '<input name="' . GROUPS_READ_POST_CAPABILITIES . '[]" ' . $checked . ' type="checkbox" value="' . esc_attr( $capability->capability_id ) . '" />';
|
245 |
-
echo wp_filter_nohtml_kses( $capability->capability );
|
246 |
-
echo '</label>';
|
247 |
-
echo ' ';
|
248 |
-
echo '<span class="description">' . wp_filter_nohtml_kses( $capability->description ) . '</span>';
|
249 |
-
echo '<br/>';
|
250 |
}
|
251 |
-
|
252 |
-
echo
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
__( '
|
258 |
-
'
|
|
|
|
|
|
|
|
|
259 |
'</p>';
|
260 |
|
261 |
echo
|
180 |
echo
|
181 |
'<form action="" name="options" method="post">' .
|
182 |
|
183 |
+
'<p>' .
|
184 |
+
'<input class="button" type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
|
185 |
'</p>' .
|
186 |
|
187 |
'<div>' .
|
221 |
echo '<ul>';
|
222 |
echo
|
223 |
'<p class="description">' .
|
224 |
+
__( 'This determines for which post types access restriction settings are offered.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
|
225 |
+
__( 'Disabling this setting for a post type does not remove existing access restrictions on individual posts of that type.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
|
226 |
+
'</p>';
|
227 |
|
228 |
|
229 |
echo '<h4>' . __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) . '</h4>';
|
235 |
$capability_table = _groups_get_tablename( "capability" );
|
236 |
$capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" );
|
237 |
$applicable_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
|
238 |
+
echo '<div class="select-capability-container" style="width:62%;">';
|
239 |
+
printf( '<select class="select capability" name="%s" multiple="multiple">', GROUPS_READ_POST_CAPABILITIES . '[]' );
|
240 |
foreach( $capabilities as $capability ) {
|
241 |
+
$selected = in_array( $capability->capability, $applicable_read_caps ) ? ' selected="selected" ' : '';
|
242 |
if ( $capability->capability == Groups_Post_Access::READ_POST_CAPABILITY ) {
|
243 |
+
$selected .= ' disabled="disabled" ';
|
244 |
}
|
245 |
+
printf( '<option value="%s" %s>%s</option>', esc_attr( $capability->capability_id ), $selected, wp_filter_nohtml_kses( $capability->capability ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
}
|
247 |
+
echo '</select>';
|
248 |
+
echo '</div>';
|
249 |
+
|
250 |
+
echo Groups_UIE::render_select( '.select.capability' );
|
251 |
+
|
252 |
+
echo
|
253 |
+
'<h3>' . __( 'User profiles', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
|
254 |
+
'<p>' .
|
255 |
+
'<label>' .
|
256 |
+
'<input name="' . GROUPS_SHOW_IN_USER_PROFILE . '" type="checkbox" ' . ( $show_in_user_profile ? 'checked="checked"' : '' ) . '/>' .
|
257 |
+
__( 'Show groups in user profiles.', GROUPS_PLUGIN_DOMAIN ) .
|
258 |
+
'</label>' .
|
259 |
'</p>';
|
260 |
|
261 |
echo
|
lib/core/class-groups-capability.php
CHANGED
@@ -49,10 +49,15 @@ class Groups_Capability {
|
|
49 |
* - name
|
50 |
* - description
|
51 |
*
|
|
|
|
|
52 |
* @param string $name property's name
|
53 |
* @return property value, will return null if property does not exist
|
54 |
*/
|
55 |
public function __get( $name ) {
|
|
|
|
|
|
|
56 |
$result = null;
|
57 |
if ( $this->capability !== null ) {
|
58 |
switch( $name ) {
|
@@ -64,6 +69,32 @@ class Groups_Capability {
|
|
64 |
case "description" :
|
65 |
$result = $this->capability->$name;
|
66 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
}
|
69 |
return $result;
|
49 |
* - name
|
50 |
* - description
|
51 |
*
|
52 |
+
* - group_ids groups that have the capability
|
53 |
+
*
|
54 |
* @param string $name property's name
|
55 |
* @return property value, will return null if property does not exist
|
56 |
*/
|
57 |
public function __get( $name ) {
|
58 |
+
|
59 |
+
global $wpdb;
|
60 |
+
|
61 |
$result = null;
|
62 |
if ( $this->capability !== null ) {
|
63 |
switch( $name ) {
|
69 |
case "description" :
|
70 |
$result = $this->capability->$name;
|
71 |
break;
|
72 |
+
case 'group_ids' :
|
73 |
+
$group_capability_table = _groups_get_tablename( "group_capability" );
|
74 |
+
$rows = $wpdb->get_results( $wpdb->prepare(
|
75 |
+
"SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
|
76 |
+
Groups_Utility::id( $this->capability->capability_id )
|
77 |
+
) );
|
78 |
+
if ( $rows ) {
|
79 |
+
$result = array();
|
80 |
+
foreach( $rows as $row ) {
|
81 |
+
$result[] = $row->group_id;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
break;
|
85 |
+
case 'groups' :
|
86 |
+
$group_capability_table = _groups_get_tablename( "group_capability" );
|
87 |
+
$rows = $wpdb->get_results( $wpdb->prepare(
|
88 |
+
"SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
|
89 |
+
Groups_Utility::id( $this->capability->capability_id )
|
90 |
+
) );
|
91 |
+
if ( $rows ) {
|
92 |
+
$result = array();
|
93 |
+
foreach( $rows as $row ) {
|
94 |
+
$result[] = new Groups_Group( $row->group_id );
|
95 |
+
}
|
96 |
+
}
|
97 |
+
break;
|
98 |
}
|
99 |
}
|
100 |
return $result;
|
lib/views/class-groups-uie.php
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* class-groups-uie.php
|
4 |
+
*
|
5 |
+
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com
|
6 |
+
*
|
7 |
+
* This code is released under the GNU General Public License.
|
8 |
+
* See COPYRIGHT.txt and LICENSE.txt.
|
9 |
+
*
|
10 |
+
* This code is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* This header and all notices must be kept intact.
|
16 |
+
*
|
17 |
+
* @author Karim Rahimpur
|
18 |
+
* @package groups
|
19 |
+
* @since groups 1.3.14
|
20 |
+
*/
|
21 |
+
|
22 |
+
/**
|
23 |
+
* User Interface Extensions.
|
24 |
+
*
|
25 |
+
* This class may yet be subject to changes in method signatures. External
|
26 |
+
* dependency is not advised until the private access restriction is removed.
|
27 |
+
*
|
28 |
+
* @access private
|
29 |
+
*/
|
30 |
+
class Groups_UIE {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Extension used for select
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
private static $select = 'selectize';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Setup.
|
40 |
+
*/
|
41 |
+
public static function init() {
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Extension chooser - determines what UI extension is used for an element.
|
46 |
+
*
|
47 |
+
* @param string $element choices: select
|
48 |
+
* @param string $extension choices: chosen, selectize
|
49 |
+
*/
|
50 |
+
public static function set_extension( $element, $extension ) {
|
51 |
+
switch( $element ) {
|
52 |
+
case 'select' :
|
53 |
+
self::$select = $extension;
|
54 |
+
break;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Enqueue scripts and styles.
|
60 |
+
*/
|
61 |
+
public static function enqueue( $element = null ) {
|
62 |
+
global $groups_version;
|
63 |
+
switch( $element ) {
|
64 |
+
case 'select' :
|
65 |
+
switch ( self::$select ) {
|
66 |
+
case 'chosen' :
|
67 |
+
if ( !wp_script_is( 'chosen' ) ) {
|
68 |
+
wp_enqueue_script( 'chosen', GROUPS_PLUGIN_URL . 'js/chosen/chosen.jquery.min.js', array( 'jquery' ), $groups_version, false );
|
69 |
+
}
|
70 |
+
if ( !wp_style_is( 'chosen' ) ) {
|
71 |
+
wp_enqueue_style( 'chosen', GROUPS_PLUGIN_URL . 'css/chosen/chosen.min.css', array(), $groups_version );
|
72 |
+
}
|
73 |
+
break;
|
74 |
+
case 'selectize' :
|
75 |
+
if ( !wp_script_is( 'selectize' ) ) {
|
76 |
+
wp_enqueue_script( 'selectize', GROUPS_PLUGIN_URL . 'js/selectize/selectize.min.js', array( 'jquery' ), $groups_version, false );
|
77 |
+
}
|
78 |
+
if ( !wp_style_is( 'selectize' ) ) {
|
79 |
+
wp_enqueue_style( 'selectize', GROUPS_PLUGIN_URL . 'css/selectize/selectize.bootstrap2.css', array(), $groups_version );
|
80 |
+
}
|
81 |
+
break;
|
82 |
+
}
|
83 |
+
break;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Render select script and style.
|
89 |
+
* @param string $selector identifying the select, default: select.groups-uie
|
90 |
+
* @param boolean $script render the script, default: true
|
91 |
+
* @param boolean $on_document_ready whether to trigger on document ready, default: true
|
92 |
+
* @return string HTML
|
93 |
+
*/
|
94 |
+
public static function render_select( $selector = 'select.groups-uie', $script = true, $on_document_ready = true ) {
|
95 |
+
$output = '';
|
96 |
+
if ( $script ) {
|
97 |
+
$output .= '<script type="text/javascript">';
|
98 |
+
$output .= 'if (typeof jQuery !== "undefined"){';
|
99 |
+
if ( $on_document_ready ) {
|
100 |
+
$output .= 'jQuery("document").ready(function(){';
|
101 |
+
}
|
102 |
+
switch( self::$select ) {
|
103 |
+
case 'chosen' :
|
104 |
+
$output .= sprintf( 'jQuery("%s").chosen({width:"100%%",search_contains:true});', $selector );
|
105 |
+
break;
|
106 |
+
case 'selectize' :
|
107 |
+
$output .= sprintf( 'jQuery("%s").selectize({plugins: ["remove_button"]});', $selector );
|
108 |
+
break;
|
109 |
+
}
|
110 |
+
if ( $on_document_ready ) {
|
111 |
+
$output .= '});';
|
112 |
+
}
|
113 |
+
$output .= '}'; // typeof jQuery
|
114 |
+
$output .= '</script>';
|
115 |
+
}
|
116 |
+
return $output;
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
120 |
+
Groups_UIE::init();
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.itthinx.com/plugins/groups
|
|
4 |
Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, memberships, paypal, permission, permissions, subscription, subscriptions, woocommerce
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.6.1
|
7 |
-
Stable tag: 1.3.
|
8 |
License: GPLv3
|
9 |
|
10 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
@@ -345,6 +345,14 @@ Yes. Access restrictions can be turned on or off for specific CPTs on the *Group
|
|
345 |
|
346 |
Go to *Groups > Options* and enable the option under *User profiles*.
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
== Screenshots ==
|
349 |
|
350 |
See also [Groups](http://www.itthinx.com/plugins/groups/)
|
@@ -360,8 +368,15 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
|
|
360 |
|
361 |
== Changelog ==
|
362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
= 1.3.13 =
|
364 |
-
* Fixed duplicate postmeta
|
365 |
* [groups_can] and [groups_can_not] now accept multiple capabilities separated by comma.
|
366 |
* WordPress 3.6.1 compatibility checked.
|
367 |
|
@@ -502,6 +517,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
|
|
502 |
|
503 |
== Upgrade Notice ==
|
504 |
|
|
|
|
|
|
|
505 |
= 1.3.13 =
|
506 |
* Minor fixes (also tested WordPress 3.6.1 compatibility).
|
507 |
|
@@ -589,10 +607,3 @@ Some installations wouldn't work correctly, showing no capabilities and making i
|
|
589 |
|
590 |
= 1.0.0-beta-1 =
|
591 |
* This is the first public beta release.
|
592 |
-
|
593 |
-
== API ==
|
594 |
-
|
595 |
-
The Groups plugin provides an extensive framework to handle memberships, group-based capabilities and access control.
|
596 |
-
Read more on the official [Groups](http://www.itthinx.com/plugins/groups/) page and the [Groups documentation](http://www.itthinx.com/documentation/groups/) page.
|
597 |
-
|
598 |
-
|
4 |
Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, memberships, paypal, permission, permissions, subscription, subscriptions, woocommerce
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.6.1
|
7 |
+
Stable tag: 1.3.14
|
8 |
License: GPLv3
|
9 |
|
10 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
345 |
|
346 |
Go to *Groups > Options* and enable the option under *User profiles*.
|
347 |
|
348 |
+
= Developers aka What about Groups' API? =
|
349 |
+
|
350 |
+
The Groups plugin provides an extensive framework to handle memberships, group-based capabilities and access control.
|
351 |
+
|
352 |
+
The API documentation is available here: [Groups API](http://api.itthinx.com/groups).
|
353 |
+
|
354 |
+
Also refer to the official [Groups](http://www.itthinx.com/plugins/groups/) plugin page and the [Groups documentation](http://www.itthinx.com/documentation/groups/) pages.
|
355 |
+
|
356 |
== Screenshots ==
|
357 |
|
358 |
See also [Groups](http://www.itthinx.com/plugins/groups/)
|
368 |
|
369 |
== Changelog ==
|
370 |
|
371 |
+
= 1.3.14 =
|
372 |
+
* Added the option to quick-create group and capability within the access restriction meta-box.
|
373 |
+
* Added the option to show groups granting access per capability in the access restriction meta-box.
|
374 |
+
* Added the quick-create field to the access restrictions meta-box which allows to create group & capability on the fly.
|
375 |
+
* Added [Selectize.js](http://brianreavis.github.io/selectize.js/) and using it in the access restrictions meta-box instead of checkboxes.
|
376 |
+
* Improved the Groups > Options screen using a Selectize-based selection of capabilities that are enabled for access restriction.
|
377 |
+
|
378 |
= 1.3.13 =
|
379 |
+
* Fixed duplicate postmeta created when saving access restriction capabilities for a post.
|
380 |
* [groups_can] and [groups_can_not] now accept multiple capabilities separated by comma.
|
381 |
* WordPress 3.6.1 compatibility checked.
|
382 |
|
517 |
|
518 |
== Upgrade Notice ==
|
519 |
|
520 |
+
= 1.3.14 =
|
521 |
+
* New useful features, UI and workflow improvements. Quick-create group and capability directly on posts (access restriction); groups are shown along with access restriction capabilities (can be toggled).
|
522 |
+
|
523 |
= 1.3.13 =
|
524 |
* Minor fixes (also tested WordPress 3.6.1 compatibility).
|
525 |
|
607 |
|
608 |
= 1.0.0-beta-1 =
|
609 |
* This is the first public beta release.
|
|
|
|
|
|
|
|
|
|
|
|
|
|