|
35 | 35 | $(self).html(backup.html());
|
36 | 36 |
|
37 | 37 | /* If multiple parents build classname like foo\bar. */
|
38 |
| - var selected = ""; |
| 38 | + var selected = []; |
39 | 39 | $(parent_selector).each(function() {
|
40 |
| - if ($(":selected", this).val()) { |
41 |
| - selected += "\\" + $(":selected", this).val(); |
42 |
| - } |
| 40 | + $(":selected", this).each(function() { |
| 41 | + selected.push($(this).val()); |
| 42 | + }); |
43 | 43 | });
|
44 |
| - selected = selected.substr(1); |
45 | 44 |
|
46 |
| - /* Zepto class regexp dies with classes like foo\bar. */ |
47 |
| - if (window.Zepto) { |
48 |
| - selected = selected.replace("\\", "\\\\"); |
49 |
| - } |
50 | 45 | /* Also check for first parent without subclassing. */
|
51 | 46 | /* TODO: This should be dynamic and check for each parent */
|
52 | 47 | /* without subclassing. */
|
|
59 | 54 | var selected_first = $(":selected", first).val();
|
60 | 55 |
|
61 | 56 | $("option", self).each(function() {
|
62 |
| - /* Remove unneeded items but save the default value. */ |
63 |
| - if (!$(this).hasClass(selected) && |
64 |
| - !$(this).hasClass(selected_first) && $(this).val() !== "") { |
65 |
| - $(this).remove(); |
66 |
| - } |
| 57 | + |
| 58 | + |
| 59 | + var hasSelectedClass = false; |
| 60 | + var classList = ($(this).attr('class') == undefined || "" ) ? [] : $(this).attr('class').split(/\s+/); |
| 61 | + $.each( classList, function(index, item){ |
| 62 | + if (jQuery.inArray(item, selected) >= 0) { |
| 63 | + hasSelectedClass = true; |
| 64 | + return; |
| 65 | + } |
| 66 | + }); |
| 67 | + if (!hasSelectedClass && |
| 68 | + !$(this).hasClass(selected_first) && $(this).val() !== "") { |
| 69 | + $(this).remove(); |
| 70 | + } |
| 71 | + |
67 | 72 | });
|
68 | 73 |
|
69 | 74 | /* If we have only the default value disable select. */
|
|
0 commit comments