selectize-rails 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,6 +41,7 @@ See the [demo page of Brian Reavis](http://brianreavis.github.io/selectize.js/)
41
41
 
42
42
  | Version | Notes |
43
43
  | -------:| ----------------------------------------------------------- |
44
+ | 0.7.2 | Update to v0.7.2 of selectize.js |
44
45
  | 0.7.0 | Update to v0.7.0 of selectize.js |
45
46
  | 0.6.14 | Update to v0.6.14 of selectize.js |
46
47
  | 0.6.4 | Update to v0.6.4 of selectize.js |
@@ -1,5 +1,5 @@
1
1
  module Selectize
2
2
  module Rails
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.2"
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ git clone https://github.com/brianreavis/selectize.js.git tmp_vendor
6
6
 
7
7
  # Copy files
8
8
  echo "Copying selectize.js"
9
- cp tmp_vendor/dist/js/selectize.js vendor/assets/javascripts/selectize.js
9
+ cp tmp_vendor/dist/js/standalone/selectize.js vendor/assets/javascripts/selectize.js
10
10
  echo "Copying css files"
11
11
  cp tmp_vendor/dist/css/*.css vendor/assets/stylesheets/
12
12
 
@@ -1,5 +1,469 @@
1
1
  /**
2
- * selectize.js (v0.7.0)
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
+ a = a && String(self.items[a.id][field] || '').toLowerCase();
262
+ b = b && String(self.items[b.id][field] || '').toLowerCase();
263
+ if (a > b) return 1 * multiplier;
264
+ if (b > a) return -1 * multiplier;
265
+ return 0;
266
+ };
267
+ })());
268
+ }
269
+ }
270
+
271
+ // apply limits
272
+ search.total = search.items.length;
273
+ if (typeof options.limit === 'number') {
274
+ search.items = search.items.slice(0, options.limit);
275
+ }
276
+
277
+ return search;
278
+ };
279
+
280
+ // utilities
281
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282
+
283
+ var extend = function(a, b) {
284
+ var i, n, k, object;
285
+ for (i = 1, n = arguments.length; i < n; i++) {
286
+ object = arguments[i];
287
+ if (!object) continue;
288
+ for (k in object) {
289
+ if (object.hasOwnProperty(k)) {
290
+ a[k] = object[k];
291
+ }
292
+ }
293
+ }
294
+ return a;
295
+ };
296
+
297
+ var trim = function(str) {
298
+ return (str + '').replace(/^\s+|\s+$|/g, '');
299
+ };
300
+
301
+ var escape_regex = function(str) {
302
+ return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
303
+ };
304
+
305
+ var is_array = Array.isArray || ($ && $.isArray) || function(object) {
306
+ return Object.prototype.toString.call(object) === '[object Array]';
307
+ };
308
+
309
+ var DIACRITICS = {
310
+ 'a': '[aÀÁÂÃÄÅàáâãäå]',
311
+ 'c': '[cÇç]',
312
+ 'e': '[eÈÉÊËèéêë]',
313
+ 'i': '[iÌÍÎÏìíîï]',
314
+ 'n': '[nÑñ]',
315
+ 'o': '[oÒÓÔÕÕÖØòóôõöø]',
316
+ 's': '[sŠš]',
317
+ 'u': '[uÙÚÛÜùúûü]',
318
+ 'y': '[yŸÿý]',
319
+ 'z': '[zŽž]'
320
+ };
321
+
322
+ // export
323
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
324
+
325
+ return Sifter;
326
+
327
+ }));
328
+
329
+ /**
330
+ * microplugin.js
331
+ * Copyright (c) 2013 Brian Reavis & contributors
332
+ *
333
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
334
+ * file except in compliance with the License. You may obtain a copy of the License at:
335
+ * http://www.apache.org/licenses/LICENSE-2.0
336
+ *
337
+ * Unless required by applicable law or agreed to in writing, software distributed under
338
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
339
+ * ANY KIND, either express or implied. See the License for the specific language
340
+ * governing permissions and limitations under the License.
341
+ *
342
+ * @author Brian Reavis <brian@thirdroute.com>
343
+ */
344
+
345
+ (function(root, factory) {
346
+ if (typeof define === 'function' && define.amd) {
347
+ define(factory);
348
+ } else if (typeof exports === 'object') {
349
+ module.exports = factory();
350
+ } else {
351
+ root.MicroPlugin = factory();
352
+ }
353
+ }(this, function() {
354
+ var MicroPlugin = {};
355
+
356
+ MicroPlugin.mixin = function(Interface) {
357
+ Interface.plugins = {};
358
+
359
+ /**
360
+ * Initializes the listed plugins (with options).
361
+ * Acceptable formats:
362
+ *
363
+ * List (without options):
364
+ * ['a', 'b', 'c']
365
+ *
366
+ * List (with options):
367
+ * [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
368
+ *
369
+ * Hash (with options):
370
+ * {'a': { ... }, 'b': { ... }, 'c': { ... }}
371
+ *
372
+ * @param {mixed} plugins
373
+ */
374
+ Interface.prototype.initializePlugins = function(plugins) {
375
+ var i, n, key;
376
+ var self = this;
377
+ var queue = [];
378
+
379
+ self.plugins = {
380
+ names : [],
381
+ settings : {},
382
+ requested : {},
383
+ loaded : {}
384
+ };
385
+
386
+ if (utils.isArray(plugins)) {
387
+ for (i = 0, n = plugins.length; i < n; i++) {
388
+ if (typeof plugins[i] === 'string') {
389
+ queue.push(plugins[i]);
390
+ } else {
391
+ self.plugins.settings[plugins[i].name] = plugins[i].options;
392
+ queue.push(plugins[i].name);
393
+ }
394
+ }
395
+ } else if (plugins) {
396
+ for (key in plugins) {
397
+ if (plugins.hasOwnProperty(key)) {
398
+ self.plugins.settings[key] = plugins[key];
399
+ queue.push(key);
400
+ }
401
+ }
402
+ }
403
+
404
+ while (queue.length) {
405
+ self.require(queue.shift());
406
+ }
407
+ };
408
+
409
+ Interface.prototype.loadPlugin = function(name) {
410
+ var self = this;
411
+ var plugins = self.plugins;
412
+ var plugin = Interface.plugins[name];
413
+
414
+ if (!Interface.plugins.hasOwnProperty(name)) {
415
+ throw new Error('Unable to find "' + name + '" plugin');
416
+ }
417
+
418
+ plugins.requested[name] = true;
419
+ plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);
420
+ plugins.names.push(name);
421
+ };
422
+
423
+ /**
424
+ * Initializes a plugin.
425
+ *
426
+ * @param {string} name
427
+ */
428
+ Interface.prototype.require = function(name) {
429
+ var self = this;
430
+ var plugins = self.plugins;
431
+
432
+ if (!self.plugins.loaded.hasOwnProperty(name)) {
433
+ if (plugins.requested[name]) {
434
+ throw new Error('Plugin has circular dependency ("' + name + '")');
435
+ }
436
+ self.loadPlugin(name);
437
+ }
438
+
439
+ return plugins.loaded[name];
440
+ };
441
+
442
+ /**
443
+ * Registers a plugin.
444
+ *
445
+ * @param {string} name
446
+ * @param {function} fn
447
+ */
448
+ Interface.define = function(name, fn) {
449
+ Interface.plugins[name] = {
450
+ 'name' : name,
451
+ 'fn' : fn
452
+ };
453
+ };
454
+ };
455
+
456
+ var utils = {
457
+ isArray: Array.isArray || function() {
458
+ return Object.prototype.toString.call(vArg) === '[object Array]';
459
+ }
460
+ };
461
+
462
+ return MicroPlugin;
463
+ }));
464
+
465
+ /**
466
+ * selectize.js (v0.7.2)
3
467
  * Copyright (c) 2013 Brian Reavis & contributors
4
468
  *
5
469
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -671,6 +1135,7 @@
671
1135
  self.disable();
672
1136
  }
673
1137
 
1138
+ self.on('change', this.onChange);
674
1139
  self.trigger('initialize');
675
1140
 
676
1141
  // preload options
@@ -720,6 +1185,15 @@
720
1185
  }
721
1186
  },
722
1187
 
1188
+ /**
1189
+ * Triggered when the value of the control has been changed.
1190
+ * This should propagate the event to the original DOM
1191
+ * input / select element.
1192
+ */
1193
+ onChange: function() {
1194
+ this.$input.trigger('change');
1195
+ },
1196
+
723
1197
  /**
724
1198
  * Triggered on <input> keypress.
725
1199
  *
@@ -1741,7 +2215,6 @@
1741
2215
  self.$input.val(self.getValue());
1742
2216
  }
1743
2217
 
1744
- self.$input.trigger('change');
1745
2218
  if (self.isSetup) {
1746
2219
  self.trigger('change', self.$input.val());
1747
2220
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * selectize.bootstrap2.css (v0.7.0) - Bootstrap 2 Theme
2
+ * selectize.bootstrap2.css (v0.7.2) - Bootstrap 2 Theme
3
3
  * Copyright (c) 2013 Brian Reavis & contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -246,7 +246,7 @@
246
246
  .selectize-dropdown {
247
247
  position: absolute;
248
248
  z-index: 2;
249
- margin-top: -1px;
249
+ margin: -1px 0 0 0;
250
250
  background: #ffffff;
251
251
  border: 1px solid #d0d0d0;
252
252
  border-top: 0 none;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * selectize.bootstrap3.css (v0.7.0) - Bootstrap 3 Theme
2
+ * selectize.bootstrap3.css (v0.7.2) - Bootstrap 3 Theme
3
3
  * Copyright (c) 2013 Brian Reavis & contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -246,7 +246,7 @@
246
246
  .selectize-dropdown {
247
247
  position: absolute;
248
248
  z-index: 2;
249
- margin-top: -1px;
249
+ margin: -1px 0 0 0;
250
250
  background: #ffffff;
251
251
  border: 1px solid #cccccc;
252
252
  border-top: 0 none;
@@ -341,12 +341,18 @@
341
341
  opacity: 0.5;
342
342
  }
343
343
 
344
- .selectize-dropdown {
344
+ .selectize-dropdown,
345
+ .selectize-dropdown.form-control {
345
346
  z-index: 1000;
347
+ height: auto;
348
+ padding: 0;
346
349
  margin: 2px 0 0 0;
350
+ background: #ffffff;
347
351
  border: 1px solid #cccccc;
348
352
  border: 1px solid rgba(0, 0, 0, 0.15);
349
- border-radius: 4px;
353
+ -webkit-border-radius: 4px;
354
+ -moz-border-radius: 4px;
355
+ border-radius: 4px;
350
356
  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
351
357
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
352
358
  }
@@ -409,4 +415,16 @@
409
415
  -webkit-border-radius: 3px;
410
416
  -moz-border-radius: 3px;
411
417
  border-radius: 3px;
418
+ }
419
+
420
+ .form-control.selectize-control {
421
+ height: auto;
422
+ padding: 0;
423
+ background: none;
424
+ border: none;
425
+ -webkit-border-radius: 0;
426
+ -moz-border-radius: 0;
427
+ border-radius: 0;
428
+ -webkit-box-shadow: none;
429
+ box-shadow: none;
412
430
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * selectize.css (v0.7.0)
2
+ * selectize.css (v0.7.2)
3
3
  * Copyright (c) 2013 Brian Reavis & contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -246,7 +246,7 @@
246
246
  .selectize-dropdown {
247
247
  position: absolute;
248
248
  z-index: 2;
249
- margin-top: -1px;
249
+ margin: -1px 0 0 0;
250
250
  background: #ffffff;
251
251
  border: 1px solid #d0d0d0;
252
252
  border-top: 0 none;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * selectize.default.css (v0.7.0) - Default Theme
2
+ * selectize.default.css (v0.7.2) - Default Theme
3
3
  * Copyright (c) 2013 Brian Reavis & contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -246,7 +246,7 @@
246
246
  .selectize-dropdown {
247
247
  position: absolute;
248
248
  z-index: 2;
249
- margin-top: -1px;
249
+ margin: -1px 0 0 0;
250
250
  background: #ffffff;
251
251
  border: 1px solid #d0d0d0;
252
252
  border-top: 0 none;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * selectize.legacy.css (v0.7.0) - Default Theme
2
+ * selectize.legacy.css (v0.7.2) - Default Theme
3
3
  * Copyright (c) 2013 Brian Reavis & contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -246,7 +246,7 @@
246
246
  .selectize-dropdown {
247
247
  position: absolute;
248
248
  z-index: 2;
249
- margin-top: -1px;
249
+ margin: -1px 0 0 0;
250
250
  background: #ffffff;
251
251
  border: 1px solid #d0d0d0;
252
252
  border-top: 0 none;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectize-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler