|
66 | 66 | .addClass(o.classes)
|
67 | 67 | .attr({ 'title':el.attr('title'), 'tabIndex':el.attr('tabIndex'), 'id': el.attr('id') ? el.attr('id') + '_ms' : null })
|
68 | 68 | .prop('aria-haspopup', true)
|
69 |
| - .insertAfter(el), |
| 69 | + .insertAfter(el); |
70 | 70 |
|
71 |
| - buttonlabel = (this.buttonlabel = $('<span />')) |
| 71 | + this.buttonlabel = $('<span />') |
72 | 72 | .html(o.noneSelectedText)
|
73 |
| - .appendTo(button), |
| 73 | + .appendTo(button); |
74 | 74 |
|
75 |
| - menu = (this.menu = $('<div />')) |
| 75 | + this.menu = $('<div />') |
76 | 76 | .addClass('ui-multiselect-menu ui-widget ui-widget-content ui-corner-all')
|
77 | 77 | .addClass(o.classes)
|
78 |
| - .appendTo($(o.appendTo)), |
| 78 | + .appendTo($(o.appendTo)); |
79 | 79 |
|
80 |
| - header = (this.header = $('<div />')) |
| 80 | + this.header = $('<div />') |
81 | 81 | .addClass('ui-widget-header ui-corner-all ui-multiselect-header ui-helper-clearfix')
|
82 |
| - .appendTo(menu), |
| 82 | + .appendTo(this.menu); |
83 | 83 |
|
84 |
| - headerLinkContainer = (this.headerLinkContainer = $('<ul />')) |
| 84 | + this.headerLinkContainer = $('<ul />') |
85 | 85 | .addClass('ui-helper-reset')
|
86 | 86 | .html(function() {
|
87 | 87 | if(o.header === true) {
|
|
100 | 100 | }
|
101 | 101 | })
|
102 | 102 | .append('<li class="ui-multiselect-close"><a href="#" class="ui-multiselect-close"><span class="ui-icon '+o.closeIcon+'"></span></a></li>')
|
103 |
| - .appendTo(header), |
| 103 | + .appendTo(this.header); |
104 | 104 |
|
105 |
| - checkboxContainer = (this.checkboxContainer = $('<ul />')) |
| 105 | + var checkboxContainer = (this.checkboxContainer = $('<ul />')) |
106 | 106 | .addClass('ui-multiselect-checkboxes ui-helper-reset')
|
107 |
| - .appendTo(menu); |
| 107 | + .appendTo(this.menu); |
108 | 108 |
|
109 | 109 | // perform event bindings
|
110 | 110 | this._bindEvents();
|
|
114 | 114 |
|
115 | 115 | // some addl. logic for single selects
|
116 | 116 | if(!o.multiple) {
|
117 |
| - menu.addClass('ui-multiselect-single'); |
| 117 | + this.menu.addClass('ui-multiselect-single'); |
118 | 118 | }
|
119 | 119 |
|
120 | 120 | // bump unique ID
|
|
269 | 269 | this.buttonlabel.text(value);
|
270 | 270 | },
|
271 | 271 |
|
272 |
| - // binds events |
273 |
| - _bindEvents: function() { |
| 272 | + _bindButtonEvents: function() { |
274 | 273 | var self = this;
|
275 | 274 | var button = this.button;
|
276 |
| - |
277 | 275 | function clickHandler() {
|
278 | 276 | self[ self._isOpen ? 'close' : 'open' ]();
|
279 | 277 | return false;
|
|
317 | 315 | $(this).removeClass('ui-state-focus');
|
318 | 316 | }
|
319 | 317 | });
|
| 318 | + }, |
320 | 319 |
|
321 |
| - // header links |
322 |
| - this.header.delegate('a', 'click.multiselect', function(e) { |
323 |
| - // close link |
324 |
| - if($(this).hasClass('ui-multiselect-close')) { |
325 |
| - self.close(); |
326 |
| - |
327 |
| - // check all / uncheck all |
328 |
| - } else { |
329 |
| - self[$(this).hasClass('ui-multiselect-all') ? 'checkAll' : 'uncheckAll'](); |
330 |
| - } |
331 |
| - |
332 |
| - e.preventDefault(); |
333 |
| - }); |
334 |
| - |
| 320 | + _bindMenuEvents: function() { |
| 321 | + var self = this; |
335 | 322 | // optgroup label toggle support
|
336 | 323 | this.menu.delegate('li.ui-multiselect-optgroup-label a', 'click.multiselect', function(e) {
|
337 | 324 | e.preventDefault();
|
|
443 | 430 | // http://bugs.jquery.com/ticket/3827
|
444 | 431 | setTimeout($.proxy(self.update, self), 10);
|
445 | 432 | });
|
| 433 | + }, |
| 434 | + |
| 435 | + _bindHeaderEvents: function() { |
| 436 | + var self = this; |
| 437 | + // header links |
| 438 | + this.header.delegate('a', 'click.multiselect', function(e) { |
| 439 | + // close link |
| 440 | + if($(this).hasClass('ui-multiselect-close')) { |
| 441 | + self.close(); |
| 442 | + |
| 443 | + // check all / uncheck all |
| 444 | + } else { |
| 445 | + self[$(this).hasClass('ui-multiselect-all') ? 'checkAll' : 'uncheckAll'](); |
| 446 | + } |
| 447 | + |
| 448 | + e.preventDefault(); |
| 449 | + }); |
| 450 | + }, |
| 451 | + |
| 452 | + // binds events |
| 453 | + _bindEvents: function() { |
| 454 | + var self = this; |
| 455 | + |
| 456 | + this._bindButtonEvents(); |
| 457 | + this._bindMenuEvents(); |
| 458 | + this._bindHeaderEvents(); |
446 | 459 |
|
447 | 460 | // close each widget when clicking on any other element/anywhere else on the page
|
448 | 461 | $doc.bind('mousedown.' + self._namespaceID, function(event) {
|
449 | 462 | var target = event.target;
|
450 | 463 |
|
451 |
| - if(self._isOpen |
452 |
| - && target !== self.button[0] |
453 |
| - && target !== self.menu[0] |
454 |
| - && !$.contains(self.menu[0], target) |
455 |
| - && !$.contains(self.button[0], target) |
| 464 | + if(self._isOpen && |
| 465 | + target !== self.button[0] && |
| 466 | + target !== self.menu[0] && |
| 467 | + !$.contains(self.menu[0], target) && |
| 468 | + !$.contains(self.button[0], target) |
456 | 469 | ) {
|
457 | 470 | self.close();
|
458 | 471 | }
|
|
0 commit comments