Commit 842f6c9b authored by Daniel Fuzari's avatar Daniel Fuzari

Adaptaçoes para diretiva de filtros do inGaia Imob

parent 1d17e957
span.hide-native-select{position:relative}span.hide-native-select select{border:0!important;clip:rect(0 0 0 0)!important;height:1px!important;margin:-1px -1px -1px -3px!important;overflow:hidden!important;padding:0!important;position:absolute!important;width:1px!important;left:50%;top:30px}.multiselect-container{position:absolute;list-style-type:none;margin:0;padding:0}.multiselect-container .input-group{margin:5px}.multiselect-container>li{padding:0}.multiselect-container>li>a.multiselect-all label{font-weight:700}.multiselect-container>li.multiselect-group label{margin:0;padding:3px 20px 3px 20px;height:100%;font-weight:700}.multiselect-container>li.multiselect-group-clickable label{cursor:pointer}.multiselect-container>li>a{padding:0}.multiselect-container>li>a>label{margin:0;height:100%;cursor:pointer;font-weight:400;padding:3px 20px 3px 40px}.multiselect-container>li>a>label.radio,.multiselect-container>li>a>label.checkbox{margin:0}.multiselect-container>li>a>label>input[type=checkbox]{margin-bottom:5px}.btn-group>.btn-group:nth-child(2)>.multiselect.btn{border-top-left-radius:4px;border-bottom-left-radius:4px}.form-inline .multiselect-container label.checkbox,.form-inline .multiselect-container label.radio{padding:3px 20px 3px 40px}.form-inline .multiselect-container li a label.checkbox input[type=checkbox],.form-inline .multiselect-container li a label.radio input[type=radio]{margin-left:-20px;margin-right:0} .multiselect-container{position:absolute;list-style-type:none;margin:0;padding:0}.multiselect-container .input-group{margin:5px}.multiselect-container>li{padding:0}.multiselect-container>li>a.multiselect-all label{font-weight:700}.multiselect-container>li.multiselect-group label{margin:0;padding:3px 20px 3px 20px;height:100%;font-weight:700}.multiselect-container>li.multiselect-group-clickable label{cursor:pointer}.multiselect-container>li>a{padding:0}.multiselect-container>li>a>label{margin:0;height:100%;cursor:pointer;font-weight:400;padding:3px 20px 3px 40px}.multiselect-container>li>a>label.radio,.multiselect-container>li>a>label.checkbox{margin:0}.multiselect-container>li>a>label>input[type=checkbox]{margin-bottom:5px}.btn-group>.btn-group:nth-child(2)>.multiselect.btn{border-top-left-radius:4px;border-bottom-left-radius:4px}.form-inline .multiselect-container label.checkbox,.form-inline .multiselect-container label.radio{padding:3px 20px 3px 40px}.form-inline .multiselect-container li a label.checkbox input[type=checkbox],.form-inline .multiselect-container li a label.radio input[type=radio]{margin-left:-20px;margin-right:0}
\ No newline at end of file \ No newline at end of file
...@@ -192,14 +192,11 @@ ...@@ -192,14 +192,11 @@
this.options.multiple = this.$select.attr('multiple') === "multiple"; this.options.multiple = this.$select.attr('multiple') === "multiple";
this.options.onChange = $.proxy(this.options.onChange, this); this.options.onChange = $.proxy(this.options.onChange, this);
this.options.onSelectAll = $.proxy(this.options.onSelectAll, this);
this.options.onDeselectAll = $.proxy(this.options.onDeselectAll, this);
this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this); this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this);
this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this); this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this);
this.options.onDropdownShown = $.proxy(this.options.onDropdownShown, this); this.options.onDropdownShown = $.proxy(this.options.onDropdownShown, this);
this.options.onDropdownHidden = $.proxy(this.options.onDropdownHidden, this); this.options.onDropdownHidden = $.proxy(this.options.onDropdownHidden, this);
this.options.onInitialized = $.proxy(this.options.onInitialized, this); this.options.onInitialized = $.proxy(this.options.onInitialized, this);
this.options.onFiltering = $.proxy(this.options.onFiltering, this);
// Build select all if enabled. // Build select all if enabled.
this.buildContainer(); this.buildContainer();
...@@ -212,15 +209,11 @@ ...@@ -212,15 +209,11 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(true); this.updateSelectAll(true);
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) { if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) {
this.disable(); this.disable();
} }
this.$select.wrap('<span class="hide-native-select">').after(this.$container); this.$select.hide().after(this.$container);
this.options.onInitialized(this.$select, this.$container); this.options.onInitialized(this.$select, this.$container);
} }
...@@ -238,7 +231,8 @@ ...@@ -238,7 +231,8 @@
*/ */
buttonText: function(options, select) { buttonText: function(options, select) {
if (this.disabledText.length > 0 if (this.disabledText.length > 0
&& (select.prop('disabled') || (options.length == 0 && this.disableIfEmpty))) { && (this.disableIfEmpty || select.prop('disabled'))
&& options.length == 0) {
return this.disabledText; return this.disabledText;
} }
...@@ -246,9 +240,9 @@ ...@@ -246,9 +240,9 @@
return this.nonSelectedText; return this.nonSelectedText;
} }
else if (this.allSelectedText else if (this.allSelectedText
&& options.length === $('option', $(select)).length && options.length === $('option', $(select)).length
&& $('option', $(select)).length !== 1 && $('option', $(select)).length !== 1
&& this.multiple) { && this.multiple) {
if (this.selectAllNumber) { if (this.selectAllNumber) {
return this.allSelectedText + ' (' + options.length + ')'; return this.allSelectedText + ' (' + options.length + ')';
...@@ -269,7 +263,7 @@ ...@@ -269,7 +263,7 @@
selected += label + delimiter; selected += label + delimiter;
}); });
return selected.substr(0, selected.length - this.delimiterText.length); return selected.substr(0, selected.length - 2);
} }
}, },
/** /**
...@@ -291,12 +285,9 @@ ...@@ -291,12 +285,9 @@
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text(); var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text();
selected += label + delimiter; selected += label + delimiter;
}); });
return selected.substr(0, selected.length - this.delimiterText.length); return selected.substr(0, selected.length - 2);
} }
}, },
checkboxName: function(option) {
return false; // no checkbox name
},
/** /**
* Create a label. * Create a label.
* *
...@@ -361,13 +352,7 @@ ...@@ -361,13 +352,7 @@
/** /**
* Triggered on select all. * Triggered on select all.
*/ */
onSelectAll: function() { onSelectAll: function(checked) {
},
/**
* Triggered on deselect all.
*/
onDeselectAll: function() {
}, },
/** /**
...@@ -378,14 +363,6 @@ ...@@ -378,14 +363,6 @@
*/ */
onInitialized: function($select, $container) { onInitialized: function($select, $container) {
},
/**
* Triggered on filtering.
*
* @param {jQuery} $filter
*/
onFiltering: function($filter) {
}, },
enableHTML: false, enableHTML: false,
buttonClass: 'btn btn-default', buttonClass: 'btn btn-default',
...@@ -398,9 +375,10 @@ ...@@ -398,9 +375,10 @@
// Maximum height of the dropdown menu. // Maximum height of the dropdown menu.
// If maximum height is exceeded a scrollbar will be displayed. // If maximum height is exceeded a scrollbar will be displayed.
maxHeight: false, maxHeight: false,
checkboxName: false,
includeSelectAllOption: false, includeSelectAllOption: false,
includeSelectAllIfMoreThan: 0, includeSelectAllIfMoreThan: 0,
selectAllText: ' Select all', selectAllText: ' Selecionar todos',
selectAllValue: 'multiselect-all', selectAllValue: 'multiselect-all',
selectAllName: false, selectAllName: false,
selectAllNumber: true, selectAllNumber: true,
...@@ -409,15 +387,15 @@ ...@@ -409,15 +387,15 @@
enableCaseInsensitiveFiltering: false, enableCaseInsensitiveFiltering: false,
enableFullValueFiltering: false, enableFullValueFiltering: false,
enableClickableOptGroups: false, enableClickableOptGroups: false,
enableCollapsibleOptGroups: false, enableCollapsibelOptGroups: false,
filterPlaceholder: 'Search', filterPlaceholder: 'Pesquisar',
// possible options: 'text', 'value', 'both' // possible options: 'text', 'value', 'both'
filterBehavior: 'text', filterBehavior: 'text',
includeFilterClearBtn: true, includeFilterClearBtn: true,
preventInputChangeEvent: false, preventInputChangeEvent: false,
nonSelectedText: 'None selected', nonSelectedText: 'Todos',
nSelectedText: 'selected', nSelectedText: 'selecionado(s)',
allSelectedText: 'All selected', allSelectedText: 'Todos selecionados',
numberDisplayed: 3, numberDisplayed: 3,
disableIfEmpty: false, disableIfEmpty: false,
disabledText: '', disabledText: '',
...@@ -425,7 +403,7 @@ ...@@ -425,7 +403,7 @@
templates: { templates: {
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> <b class="caret"></b></button>', button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> <b class="caret"></b></button>',
ul: '<ul class="multiselect-container dropdown-menu"></ul>', ul: '<ul class="multiselect-container dropdown-menu"></ul>',
filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>', filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>', filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>',
li: '<li><a tabindex="0"><label></label></a></li>', li: '<li><a tabindex="0"><label></label></a></li>',
divider: '<li class="multiselect-item divider"></li>', divider: '<li class="multiselect-item divider"></li>',
...@@ -465,7 +443,7 @@ ...@@ -465,7 +443,7 @@
// Manually add button width if set. // Manually add button width if set.
if (this.options.buttonWidth && this.options.buttonWidth !== 'auto') { if (this.options.buttonWidth && this.options.buttonWidth !== 'auto') {
this.$button.css({ this.$button.css({
'width' : '100%', //this.options.buttonWidth, 'width' : this.options.buttonWidth,
'overflow' : 'hidden', 'overflow' : 'hidden',
'text-overflow' : 'ellipsis' 'text-overflow' : 'ellipsis'
}); });
...@@ -522,7 +500,7 @@ ...@@ -522,7 +500,7 @@
}, },
/** /**
* Build the dropdown options and binds all necessary events. * Build the dropdown options and binds all nessecary events.
* *
* Uses createDivider and createOptionValue to create the necessary options. * Uses createDivider and createOptionValue to create the necessary options.
*/ */
...@@ -557,7 +535,7 @@ ...@@ -557,7 +535,7 @@
}, this)); }, this));
// Bind the change event on the dropdown elements. // Bind the change event on the dropdown elements.
$('li:not(.multiselect-group) input', this.$ul).on('change', $.proxy(function(event) { $('li input', this.$ul).on('change', $.proxy(function(event) {
var $target = $(event.target); var $target = $(event.target);
var checked = $target.prop('checked') || false; var checked = $target.prop('checked') || false;
...@@ -583,7 +561,6 @@ ...@@ -583,7 +561,6 @@
var $checkboxesNotThis = $('input', this.$container).not($target); var $checkboxesNotThis = $('input', this.$container).not($target);
if (isSelectAllOption) { if (isSelectAllOption) {
if (checked) { if (checked) {
this.selectAll(this.options.selectAllJustVisible); this.selectAll(this.options.selectAllJustVisible);
} }
...@@ -623,17 +600,12 @@ ...@@ -623,17 +600,12 @@
// To prevent select all from firing onChange: #575 // To prevent select all from firing onChange: #575
this.options.onChange($option, checked); this.options.onChange($option, checked);
// Do not update select all or optgroups on select all change!
this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
} }
this.$select.change(); this.$select.change();
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll();
if(this.options.preventInputChangeEvent) { if(this.options.preventInputChangeEvent) {
return false; return false;
...@@ -749,77 +721,111 @@ ...@@ -749,77 +721,111 @@
} }
}, this)); }, this));
if (this.options.enableClickableOptGroups && this.options.multiple) { if(this.options.enableClickableOptGroups && this.options.multiple) {
$("li.multiselect-group input", this.$ul).on("change", $.proxy(function(event) { $('li.multiselect-group', this.$ul).on('click', $.proxy(function(event) {
event.stopPropagation(); event.stopPropagation();
console.log('test');
var group = $(event.target).parent();
var $target = $(event.target); // Search all option in optgroup
var checked = $target.prop('checked') || false; var $options = group.nextUntil('li.multiselect-group');
var $visibleOptions = $options.filter(":visible:not(.disabled)");
var $li = $(event.target).closest('li'); // check or uncheck items
var $group = $li.nextUntil("li.multiselect-group") var allChecked = true;
.not('.multiselect-filter-hidden') var optionInputs = $visibleOptions.find('input');
.not('.disabled'); var values = [];
var $inputs = $group.find("input"); optionInputs.each(function() {
allChecked = allChecked && $(this).prop('checked');
values.push($(this).val());
});
var values = []; if (!allChecked) {
var $options = []; this.select(values, false);
}
else {
this.deselect(values, false);
}
$.each($inputs, $.proxy(function(index, input) { this.options.onChange(optionInputs, !allChecked);
var value = $(input).val(); }, this));
var $option = this.getOptionByValue(value); }
if (checked) { if (this.options.enableCollapsibleOptGroups && this.options.multiple) {
$(input).prop('checked', true); $("li.multiselect-group input", this.$ul).off();
$(input).closest('li') $("li.multiselect-group", this.$ul).siblings().not("li.multiselect-group, li.multiselect-all", this.$ul).each( function () {
.addClass(this.options.selectedClass); $(this).toggleClass('hidden', true);
});
$option.prop('selected', true); $("li.multiselect-group", this.$ul).on("click", $.proxy(function(group) {
} group.stopPropagation();
else { }, this));
$(input).prop('checked', false);
$(input).closest('li')
.removeClass(this.options.selectedClass);
$option.prop('selected', false); $("li.multiselect-group > a > b", this.$ul).on("click", $.proxy(function(t) {
} t.stopPropagation();
var n = $(t.target).closest('li');
var r = n.nextUntil("li.multiselect-group");
var i = true;
r.each(function() {
i = i && $(this).hasClass('hidden');
});
$options.push(this.getOptionByValue(value)); r.toggleClass('hidden', !i);
}, this)) }, this));
// Cannot use select or deselect here because it would call updateOptGroups again. $("li.multiselect-group > a > input", this.$ul).on("change", $.proxy(function(t) {
t.stopPropagation();
var n = $(t.target).closest('li');
var r = n.nextUntil("li.multiselect-group", ':not(.disabled)');
var s = r.find("input");
this.options.onChange($options, checked); var i = true;
s.each(function() {
i = i && $(this).prop("checked");
});
this.updateButtonText(); s.prop("checked", !i).trigger("change");
this.updateSelectAll();
}, this)); }, this));
}
if (this.options.enableCollapsibleOptGroups && this.options.multiple) { // Set the initial selection state of the groups.
$("li.multiselect-group .caret-container", this.$ul).on("click", $.proxy(function(event) { $('li.multiselect-group', this.$ul).each(function() {
var $li = $(event.target).closest('li'); var r = $(this).nextUntil("li.multiselect-group", ':not(.disabled)');
var $inputs = $li.nextUntil("li.multiselect-group") var s = r.find("input");
.not('.multiselect-filter-hidden');
var i = true;
var visible = true; s.each(function() {
$inputs.each(function() { i = i && $(this).prop("checked");
visible = visible && $(this).is(':visible');
}); });
if (visible) { $(this).find('input').prop("checked", i);
$inputs.hide() });
.addClass('multiselect-collapsible-hidden');
} // Update the group checkbox based on new selections among the
else { // corresponding children.
$inputs.show() $("li input", this.$ul).on("change", $.proxy(function(t) {
.removeClass('multiselect-collapsible-hidden'); t.stopPropagation();
} var n = $(t.target).closest('li');
var r1 = n.prevUntil("li.multiselect-group", ':not(.disabled)');
var r2 = n.nextUntil("li.multiselect-group", ':not(.disabled)');
var s1 = r1.find("input");
var s2 = r2.find("input");
var i = $(t.target).prop('checked');
s1.each(function() {
i = i && $(this).prop("checked");
});
s2.each(function() {
i = i && $(this).prop("checked");
});
n.prevAll('.multiselect-group').find('input').prop('checked', i);
}, this)); }, this));
$("li.multiselect-all", this.$ul).css('background', '#f3f3f3').css('border-bottom', '1px solid #eaeaea'); $("li.multiselect-all", this.$ul).css('background', '#f3f3f3').css('border-bottom', '1px solid #eaeaea');
$("li.multiselect-all > a > label.checkbox", this.$ul).css('padding', '3px 20px 3px 35px'); $("li.multiselect-group > a, li.multiselect-all > a > label.checkbox", this.$ul).css('padding', '3px 20px 3px 35px');
$("li.multiselect-group > a > input", this.$ul).css('margin', '4px 0px 5px -20px'); $("li.multiselect-group > a > input", this.$ul).css('margin', '4px 0px 5px -20px');
} }
}, },
...@@ -855,11 +861,9 @@ ...@@ -855,11 +861,9 @@
var $checkbox = $('<input/>').attr('type', inputType); var $checkbox = $('<input/>').attr('type', inputType);
var name = this.options.checkboxName($element); if (this.options.checkboxName) {
if (name) { $checkbox.attr('name', this.options.checkboxName);
$checkbox.attr('name', name);
} }
$label.prepend($checkbox); $label.prepend($checkbox);
var selected = $element.prop('selected') || false; var selected = $element.prop('selected') || false;
...@@ -908,37 +912,50 @@ ...@@ -908,37 +912,50 @@
* @param {jQuery} group * @param {jQuery} group
*/ */
createOptgroup: function(group) { createOptgroup: function(group) {
var label = $(group).attr("label"); if (this.options.enableCollapsibleOptGroups && this.options.multiple) {
var value = $(group).attr("value"); var label = $(group).attr("label");
var $li = $('<li class="multiselect-item multiselect-group"><a href="javascript:void(0);"><label><b></b></label></a></li>'); var value = $(group).attr("value");
var r = $('<li class="multiselect-item multiselect-group"><a href="javascript:void(0);"><input type="checkbox" value="' + value + '"/><b> ' + label + '<b class="caret"></b></b></a></li>');
var classes = this.options.optionClass(group);
$li.addClass(classes);
if (this.options.enableHTML) { if (this.options.enableClickableOptGroups) {
$('label b', $li).html(" " + label); r.addClass("multiselect-group-clickable")
}
this.$ul.append(r);
if ($(group).is(":disabled")) {
r.addClass("disabled")
}
$("option", group).each($.proxy(function($, group) {
this.createOptionValue(group)
}, this))
} }
else { else {
$('label b', $li).text(" " + label); var groupName = $(group).prop('label');
}
if (this.options.enableCollapsibleOptGroups && this.options.multiple) { // Add a header for the group.
$('a', $li).append('<span class="caret-container"><b class="caret"></b></span>'); var $li = $(this.options.templates.liGroup);
}
if (this.options.enableClickableOptGroups && this.options.multiple) { if (this.options.enableHTML) {
$('a label', $li).prepend('<input type="checkbox" value="' + value + '"/>'); $('label', $li).html(groupName);
} }
else {
$('label', $li).text(groupName);
}
if ($(group).is(':disabled')) { if (this.options.enableClickableOptGroups) {
$li.addClass('disabled'); $li.addClass('multiselect-group-clickable');
} }
this.$ul.append($li); this.$ul.append($li);
if ($(group).is(':disabled')) {
$li.addClass('disabled');
}
$("option", group).each($.proxy(function($, group) { // Add the options of the group.
this.createOptionValue(group); $('option', group).each($.proxy(function(index, element) {
}, this)) this.createOptionValue(element);
}, this));
}
}, },
/** /**
...@@ -954,7 +971,7 @@ ...@@ -954,7 +971,7 @@
var alreadyHasSelectAll = this.hasSelectAll(); var alreadyHasSelectAll = this.hasSelectAll();
if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple
&& $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) { && $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) {
// Check whether to add a divider after the select all. // Check whether to add a divider after the select all.
if (this.options.includeSelectAllDivider) { if (this.options.includeSelectAllDivider) {
...@@ -1006,20 +1023,13 @@ ...@@ -1006,20 +1023,13 @@
$('input', this.$filter).attr('placeholder', this.options.filterPlaceholder); $('input', this.$filter).attr('placeholder', this.options.filterPlaceholder);
// Adds optional filter clear button // Adds optional filter clear button
if(this.options.includeFilterClearBtn) { if(this.options.includeFilterClearBtn){
var clearBtn = $(this.options.templates.filterClearBtn); var clearBtn = $(this.options.templates.filterClearBtn);
clearBtn.on('click', $.proxy(function(event){ clearBtn.on('click', $.proxy(function(event){
clearTimeout(this.searchTimeout); clearTimeout(this.searchTimeout);
this.$filter.find('.multiselect-search').val(''); this.$filter.find('.multiselect-search').val('');
$('li', this.$ul).show().removeClass('multiselect-filter-hidden'); $('li', this.$ul).show().removeClass("filter-hidden");
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
}, this)); }, this));
this.$filter.find('.input-group').append(clearBtn); this.$filter.find('.input-group').append(clearBtn);
} }
...@@ -1031,8 +1041,8 @@ ...@@ -1031,8 +1041,8 @@
}).on('input keydown', $.proxy(function(event) { }).on('input keydown', $.proxy(function(event) {
// Cancel enter key default behaviour // Cancel enter key default behaviour
if (event.which === 13) { if (event.which === 13) {
event.preventDefault(); event.preventDefault();
} }
// This is useful to catch "keydown" events after the browser has updated the control. // This is useful to catch "keydown" events after the browser has updated the control.
clearTimeout(this.searchTimeout); clearTimeout(this.searchTimeout);
...@@ -1080,8 +1090,7 @@ ...@@ -1080,8 +1090,7 @@
} }
// Toggle current element (group or group item) according to showElement boolean. // Toggle current element (group or group item) according to showElement boolean.
$(element).toggle(showElement) $(element).toggle(showElement).toggleClass('filter-hidden', !showElement);
.toggleClass('multiselect-filter-hidden', !showElement);
// Differentiate groups and group items. // Differentiate groups and group items.
if ($(element).hasClass('multiselect-group')) { if ($(element).hasClass('multiselect-group')) {
...@@ -1092,14 +1101,12 @@ ...@@ -1092,14 +1101,12 @@
else { else {
// Show group name when at least one of its items is visible. // Show group name when at least one of its items is visible.
if (showElement) { if (showElement) {
$(currentGroup).show() $(currentGroup).show().removeClass('filter-hidden');
.removeClass('multiselect-filter-hidden');
} }
// Show all group items when group name satisfies filter. // Show all group items when group name satisfies filter.
if (!showElement && currentGroupVisible) { if (!showElement && currentGroupVisible) {
$(element).show() $(element).show().removeClass('filter-hidden');
.removeClass('multiselect-filter-hidden');
} }
} }
} }
...@@ -1107,13 +1114,6 @@ ...@@ -1107,13 +1114,6 @@
} }
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
this.options.onFiltering(event.target);
}, this), 300, this); }, this), 300, this);
}, this)); }, this));
} }
...@@ -1177,10 +1177,6 @@ ...@@ -1177,10 +1177,6 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
}, },
/** /**
...@@ -1230,10 +1226,6 @@ ...@@ -1230,10 +1226,6 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
}, },
/** /**
...@@ -1243,10 +1235,6 @@ ...@@ -1243,10 +1235,6 @@
this.deselectAll(false); this.deselectAll(false);
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
}, },
/** /**
...@@ -1292,10 +1280,6 @@ ...@@ -1292,10 +1280,6 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(); this.updateSelectAll();
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
}, },
/** /**
...@@ -1307,36 +1291,34 @@ ...@@ -1307,36 +1291,34 @@
* @param {Boolean} triggerOnSelectAll * @param {Boolean} triggerOnSelectAll
*/ */
selectAll: function (justVisible, triggerOnSelectAll) { selectAll: function (justVisible, triggerOnSelectAll) {
justVisible = (this.options.enableCollapsibleOptGroups && this.options.multiple) ? false : justVisible;
var justVisible = typeof justVisible === 'undefined' ? true : justVisible; var justVisible = typeof justVisible === 'undefined' ? true : justVisible;
var allLis = $("li:not(.divider):not(.disabled):not(.multiselect-group)", this.$ul); var allCheckboxes = $("li input[type='checkbox']:enabled", this.$ul);
var visibleLis = $("li:not(.divider):not(.disabled):not(.multiselect-group):not(.multiselect-filter-hidden):not(.multiselect-collapisble-hidden)", this.$ul).filter(':visible'); var visibleCheckboxes = allCheckboxes.filter(":visible");
var allCheckboxesCount = allCheckboxes.length;
var visibleCheckboxesCount = visibleCheckboxes.length;
if(justVisible) { if(justVisible) {
$('input:enabled' , visibleLis).prop('checked', true); visibleCheckboxes.prop('checked', true);
visibleLis.addClass(this.options.selectedClass); $("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").addClass(this.options.selectedClass);
$('input:enabled' , visibleLis).each($.proxy(function(index, element) {
var value = $(element).val();
var option = this.getOptionByValue(value);
$(option).prop('selected', true);
}, this));
} }
else { else {
$('input:enabled' , allLis).prop('checked', true); allCheckboxes.prop('checked', true);
allLis.addClass(this.options.selectedClass); $("li:not(.divider):not(.disabled)", this.$ul).addClass(this.options.selectedClass);
$('input:enabled' , allLis).each($.proxy(function(index, element) {
var value = $(element).val();
var option = this.getOptionByValue(value);
$(option).prop('selected', true);
}, this));
} }
$('li input[value="' + this.options.selectAllValue + '"]').prop('checked', true); if (allCheckboxesCount === visibleCheckboxesCount || justVisible === false) {
$("option:not([data-role='divider']):enabled", this.$select).prop('selected', true);
}
else {
var values = visibleCheckboxes.map(function() {
return $(this).val();
}).get();
if (this.options.enableClickableOptGroups && this.options.multiple) { $("option:enabled", this.$select).filter(function(index) {
this.updateOptGroups(); return $.inArray($(this).val(), values) !== -1;
}).prop('selected', true);
} }
if (triggerOnSelectAll) { if (triggerOnSelectAll) {
...@@ -1351,41 +1333,33 @@ ...@@ -1351,41 +1333,33 @@
* *
* @param {Boolean} justVisible * @param {Boolean} justVisible
*/ */
deselectAll: function (justVisible, triggerOnDeselectAll) { deselectAll: function (justVisible) {
justVisible = (this.options.enableCollapsibleOptGroups && this.options.multiple) ? false : justVisible;
var justVisible = typeof justVisible === 'undefined' ? true : justVisible; justVisible = typeof justVisible === 'undefined' ? true : justVisible;
var allLis = $("li:not(.divider):not(.disabled):not(.multiselect-group)", this.$ul);
var visibleLis = $("li:not(.divider):not(.disabled):not(.multiselect-group):not(.multiselect-filter-hidden):not(.multiselect-collapisble-hidden)", this.$ul).filter(':visible');
if(justVisible) { if(justVisible) {
$('input[type="checkbox"]:enabled' , visibleLis).prop('checked', false); var visibleCheckboxes = $("li input[type='checkbox']:not(:disabled)", this.$ul).filter(":visible");
visibleLis.removeClass(this.options.selectedClass); visibleCheckboxes.prop('checked', false);
$('input[type="checkbox"]:enabled' , visibleLis).each($.proxy(function(index, element) {
var value = $(element).val();
var option = this.getOptionByValue(value);
$(option).prop('selected', false);
}, this));
}
else {
$('input[type="checkbox"]:enabled' , allLis).prop('checked', false);
allLis.removeClass(this.options.selectedClass);
$('input[type="checkbox"]:enabled' , allLis).each($.proxy(function(index, element) { var values = visibleCheckboxes.map(function() {
var value = $(element).val(); return $(this).val();
var option = this.getOptionByValue(value); }).get();
$(option).prop('selected', false);
}, this));
}
$('li input[value="' + this.options.selectAllValue + '"]').prop('checked', false); $("option:enabled", this.$select).filter(function(index) {
return $.inArray($(this).val(), values) !== -1;
}).prop('selected', false);
if (this.options.enableClickableOptGroups && this.options.multiple) { if (this.options.selectedClass) {
this.updateOptGroups(); $("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").removeClass(this.options.selectedClass);
}
} }
else {
$("li input[type='checkbox']:enabled", this.$ul).prop('checked', false);
$("option:enabled", this.$select).prop('selected', false);
if (triggerOnDeselectAll) { if (this.options.selectedClass) {
this.options.onDeselectAll(); $("li:not(.divider):not(.disabled)", this.$ul).removeClass(this.options.selectedClass);
}
} }
}, },
...@@ -1407,10 +1381,6 @@ ...@@ -1407,10 +1381,6 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(true); this.updateSelectAll(true);
if (this.options.enableClickableOptGroups && this.options.multiple) {
this.updateOptGroups();
}
if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) { if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) {
this.disable(); this.disable();
} }
...@@ -1443,39 +1413,24 @@ ...@@ -1443,39 +1413,24 @@
}); });
forEach(option.children, function(subOption) { // add children option tags forEach(option.children, function(subOption) { // add children option tags
var attributes = { $tag.append($('<option/>').attr({
value: subOption.value, value: subOption.value,
label: subOption.label || subOption.value, label: subOption.label || subOption.value,
title: subOption.title, title: subOption.title,
selected: !!subOption.selected, selected: !!subOption.selected,
disabled: !!subOption.disabled disabled: !!subOption.disabled
}; }));
//Loop through attributes object and add key-value for each attribute
for (var key in subOption.attributes) {
attributes['data-' + key] = subOption.attributes[key];
}
//Append original attributes + new data attributes to option
$tag.append($('<option/>').attr(attributes));
}); });
} }
else { else {
$tag = $('<option/>').attr({
var attributes = { value: option.value,
'value': option.value, label: option.label || option.value,
'label': option.label || option.value, title: option.title,
'title': option.title, class: option.class,
'class': option.class, selected: !!option.selected,
'selected': !!option.selected, disabled: !!option.disabled
'disabled': !!option.disabled });
};
//Loop through attributes object and add key-value for each attribute
for (var key in option.attributes) {
attributes['data-' + key] = option.attributes[key];
}
//Append original attributes + new data attributes to option
$tag = $('<option/>').attr(attributes);
$tag.text(option.label || option.value); $tag.text(option.label || option.value);
} }
...@@ -1531,36 +1486,12 @@ ...@@ -1531,36 +1486,12 @@
return $('li.multiselect-all', this.$ul).length > 0; return $('li.multiselect-all', this.$ul).length > 0;
}, },
/**
* Update opt groups.
*/
updateOptGroups: function() {
var $groups = $('li.multiselect-group', this.$ul)
$groups.each(function() {
var $options = $(this).nextUntil('li.multiselect-group')
.not('.multiselect-filter-hidden')
.not('.disabled');
var checked = true;
$options.each(function() {
var $input = $('input', this);
if (!$input.prop('checked')) {
checked = false;
}
});
$('input', this).prop('checked', checked);
});
},
/** /**
* Updates the select all checkbox based on the currently displayed and selected checkboxes. * Updates the select all checkbox based on the currently displayed and selected checkboxes.
*/ */
updateSelectAll: function(notTriggerOnSelectAll) { updateSelectAll: function(notTriggerOnSelectAll) {
if (this.hasSelectAll()) { if (this.hasSelectAll()) {
var allBoxes = $("li:not(.multiselect-item):not(.multiselect-filter-hidden):not(.multiselect-group):not(.disabled) input:enabled", this.$ul); var allBoxes = $("li:not(.multiselect-item):not(.filter-hidden) input:enabled", this.$ul);
var allBoxesLength = allBoxes.length; var allBoxesLength = allBoxes.length;
var checkedBoxesLength = allBoxes.filter(":checked").length; var checkedBoxesLength = allBoxes.filter(":checked").length;
var selectAllLi = $("li.multiselect-all", this.$ul); var selectAllLi = $("li.multiselect-all", this.$ul);
...@@ -1569,14 +1500,14 @@ ...@@ -1569,14 +1500,14 @@
if (checkedBoxesLength > 0 && checkedBoxesLength === allBoxesLength) { if (checkedBoxesLength > 0 && checkedBoxesLength === allBoxesLength) {
selectAllInput.prop("checked", true); selectAllInput.prop("checked", true);
selectAllLi.addClass(this.options.selectedClass); selectAllLi.addClass(this.options.selectedClass);
this.options.onSelectAll(); this.options.onSelectAll(true);
} }
else { else {
selectAllInput.prop("checked", false); selectAllInput.prop("checked", false);
selectAllLi.removeClass(this.options.selectedClass); selectAllLi.removeClass(this.options.selectedClass);
if (checkedBoxesLength === 0) { if (checkedBoxesLength === 0) {
if (!notTriggerOnSelectAll) { if (!notTriggerOnSelectAll) {
this.options.onDeselectAll(); this.options.onSelectAll(false);
} }
} }
} }
...@@ -1696,4 +1627,4 @@ ...@@ -1696,4 +1627,4 @@
$("select[data-role=multiselect]").multiselect(); $("select[data-role=multiselect]").multiselect();
}); });
}(window.jQuery); }(window.jQuery);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment