|
51 | 51 | var elem = $(this.element);
|
52 | 52 |
|
53 | 53 | // get the multiselect instance
|
54 |
| - var instance = (this.instance = (elem.data('echMultiselect') || elem.data("multiselect") || elem.data("ech-multiselect"))); |
| 54 | + this.instance = elem.multiselect('instance'); |
55 | 55 |
|
56 | 56 | // store header; add filter class so the close/check all/uncheck all links can be positioned correctly
|
57 |
| - var header = (this.header = instance.menu.find('.ui-multiselect-header').addClass('ui-multiselect-hasfilter')); |
| 57 | + this.header = this.instance.menu.find('.ui-multiselect-header').addClass('ui-multiselect-hasfilter'); |
58 | 58 |
|
59 | 59 | // wrapper elem
|
60 |
| - var wrapper = (this.wrapper = $('<div class="ui-multiselect-filter">' + (opts.label.length ? opts.label : '') + '<input placeholder="'+opts.placeholder+'" type="search"' + (/\d/.test(opts.width) ? 'style="width:'+opts.width+'px"' : '') + ' /></div>').prependTo(this.header)); |
61 |
| - |
62 |
| - // reference to the actual inputs |
63 |
| - this.inputs = instance.menu.find('input[type="checkbox"], input[type="radio"]'); |
64 |
| - |
65 |
| - // build the input box |
66 |
| - this.input = wrapper.find('input').bind({ |
| 60 | + this.input = $("<input/>").attr({ |
| 61 | + placeholder: opts.placeholder, |
| 62 | + type: "search" |
| 63 | + }).css({ |
| 64 | + width: (/\d/.test(opts.width) ? opts.width + 'px' : null) |
| 65 | + }).addClass("ui-front").bind({ |
67 | 66 | keydown: function(e) {
|
68 | 67 | // prevent the enter key from submitting the form / closing the widget
|
69 | 68 | if(e.which === 13) {
|
|
73 | 72 | input: $.proxy(debounce(this._handler, opts.debounceMS), this),
|
74 | 73 | search: $.proxy(this._handler, this)
|
75 | 74 | });
|
| 75 | + this.wrapper = $("<div/>").addClass("ui-multiselect-filter").text(opts.label).append(this.input).prependTo(this.header); |
| 76 | + |
| 77 | + // reference to the actual inputs |
| 78 | + this.inputs = this.instance.menu.find('input[type="checkbox"], input[type="radio"]'); |
76 | 79 |
|
77 | 80 | // cache input values for searching
|
78 | 81 | this.updateCache();
|
79 | 82 |
|
80 | 83 | // rewrite internal _toggleChecked fn so that when checkAll/uncheckAll is fired,
|
81 | 84 | // only the currently filtered elements are checked
|
82 |
| - instance._toggleChecked = function(flag, group) { |
| 85 | + this.instance._toggleChecked = function(flag, group) { |
83 | 86 | var $inputs = (group && group.length) ? group : this.labels.find('input');
|
84 | 87 | var _self = this;
|
85 | 88 |
|
|
113 | 116 | };
|
114 | 117 |
|
115 | 118 | // rebuild cache when multiselect is updated
|
116 |
| - var doc = $(document).bind('multiselectrefresh.'+ instance._namespaceID, $.proxy(function() { |
| 119 | + var doc = $(document).bind('multiselectrefresh.'+ this.instance._namespaceID, $.proxy(function() { |
117 | 120 | this.updateCache();
|
118 | 121 | this._handler();
|
119 | 122 | }, this));
|
120 | 123 |
|
121 | 124 | // automatically reset the widget on close?
|
122 | 125 | if(this.options.autoReset) {
|
123 |
| - doc.bind('multiselectclose.'+ instance._namespaceID, $.proxy(this._reset, this)); |
| 126 | + doc.bind('multiselectclose.'+ this.instance._namespaceID, $.proxy(this._reset, this)); |
124 | 127 | }
|
125 | 128 | },
|
126 | 129 |
|
|
0 commit comments