|
1 | 1 | /**
|
2 |
| - * selectize.js (v0.7.6) |
| 2 | + * selectize.js (v0.7.7) |
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
|
|
157 | 157 | .replace(/"/g, '"');
|
158 | 158 | };
|
159 | 159 |
|
160 |
| - /** |
161 |
| - * Escapes quotation marks with backslashes. Useful |
162 |
| - * for escaping values for use in CSS attribute selectors. |
163 |
| - * |
164 |
| - * @param {string} str |
165 |
| - * @return {string} |
166 |
| - */ |
167 |
| - var escape_quotes = function(str) { |
168 |
| - return str.replace(/(['"])/g, '\\$1'); |
169 |
| - }; |
170 |
| - |
171 | 160 | var hook = {};
|
172 | 161 |
|
173 | 162 | /**
|
|
1429 | 1418 | */
|
1430 | 1419 | addOptionGroup: function(id, data) {
|
1431 | 1420 | this.optgroups[id] = data;
|
1432 |
| - this.trigger('optgroup_add', value, data); |
| 1421 | + this.trigger('optgroup_add', id, data); |
1433 | 1422 | },
|
1434 | 1423 |
|
1435 | 1424 | /**
|
|
1527 | 1516 | * @returns {object}
|
1528 | 1517 | */
|
1529 | 1518 | getOption: function(value) {
|
1530 |
| - value = hash_key(value); |
1531 |
| - return value ? this.$dropdown_content.find('[data-selectable]').filter('[data-value="' + escape_quotes(value) + '"]:first') : $(); |
| 1519 | + return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]')); |
1532 | 1520 | },
|
1533 | 1521 |
|
1534 | 1522 | /**
|
|
1546 | 1534 | return index >= 0 && index < $options.length ? $options.eq(index) : $();
|
1547 | 1535 | },
|
1548 | 1536 |
|
| 1537 | + /** |
| 1538 | + * Finds the first element with a "data-value" attribute |
| 1539 | + * that matches the given value. |
| 1540 | + * |
| 1541 | + * @param {mixed} value |
| 1542 | + * @param {object} $els |
| 1543 | + * @return {object} |
| 1544 | + */ |
| 1545 | + getElementWithValue: function(value, $els) { |
| 1546 | + value = hash_key(value); |
| 1547 | + |
| 1548 | + if (value) { |
| 1549 | + for (var i = 0, n = $els.length; i < n; i++) { |
| 1550 | + if ($els[i].getAttribute('data-value') === value) { |
| 1551 | + return $($els[i]); |
| 1552 | + } |
| 1553 | + } |
| 1554 | + } |
| 1555 | + |
| 1556 | + return $(); |
| 1557 | + }, |
| 1558 | + |
1549 | 1559 | /**
|
1550 | 1560 | * Returns the jQuery element of the item
|
1551 | 1561 | * matching the given value.
|
|
1554 | 1564 | * @returns {object}
|
1555 | 1565 | */
|
1556 | 1566 | getItem: function(value) {
|
1557 |
| - return this.$control.children('[data-value="' + escape_quotes(hash_key(value)) + '"]'); |
| 1567 | + return this.getElementWithValue(value, this.$control.children()); |
1558 | 1568 | },
|
1559 | 1569 |
|
1560 | 1570 | /**
|
|
0 commit comments