Skip to content

Commit

Permalink
Merge pull request #3 from kenshoo/feature/add_select_all
Browse files Browse the repository at this point in the history
bug fix of height and title trim
  • Loading branch information
Ido Stern committed Nov 5, 2013
2 parents bab0c50 + 93f656d commit a5b134e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@
//Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled
//Convert all the values into a comma delimited string
var title = !this.multiple ? selectedItems[0] : selectedItems.join(", ");

//If this is multi select, and the selectText type is count, the show 1 of 2 selected etc..
if (this.multiple && this.options.selectedTextFormat.indexOf('count') > -1) {
var max = this.options.selectedTextFormat.split(">");
var notDisabled = this.options.hideDisabled ? ':not([disabled])' : '';
if ( (max.length>1 && selectedItems.length > max[1]) || (max.length==1 && selectedItems.length>=2)) {
if ( (this.options.trimTitle!=null && title.length >= this.options.trimTitle) || (max.length>1 && selectedItems.length > max[1]) || (max.length==1 && selectedItems.length>=2)) {
title = this.options.countSelectedText.replace('{0}', selectedItems.length).replace('{1}', this.$element.find('option:not([data-divider="true"]):not([data-hidden="true"])'+notDisabled).length);
}
}
Expand Down Expand Up @@ -272,8 +271,9 @@
var liHeight = $menuClone.find('li > a').outerHeight();
var headerHeight = this.options.header ? $menuClone.find('.popover-title').outerHeight() : 0;
var searchHeight = this.options.liveSearch ? $menuClone.find('.bootstrap-select-searchbox').outerHeight() : 0;
var selectAllHeight = this.multiple ? $menuClone.find('#selectAll').outerHeight() : 0;
selectClone.remove();
this.$newElement.data('liHeight', liHeight).data('headerHeight', headerHeight).data('searchHeight', searchHeight);
this.$newElement.data('liHeight', liHeight).data('headerHeight', headerHeight).data('searchHeight', searchHeight).data('selectAllHeight',selectAllHeight);
},

setSize: function() {
Expand All @@ -285,6 +285,7 @@
liHeight = this.$newElement.data('liHeight'),
headerHeight = this.$newElement.data('headerHeight'),
searchHeight = this.$newElement.data('searchHeight'),
selectAllHeight = this.$newElement.data('selectAllHeight'),
divHeight = menu.find('li .divider').outerHeight(true),
menuPadding = parseInt(menu.css('padding-top')) +
parseInt(menu.css('padding-bottom')) +
Expand Down Expand Up @@ -318,17 +319,17 @@
minHeight = 0;
}
menu.css({'max-height' : menuHeight + 'px', 'overflow' : 'hidden', 'min-height' : minHeight + 'px'});
menuInner.css({'max-height' : menuHeight - headerHeight - searchHeight- menuPadding + 'px', 'overflow-y' : 'auto', 'min-height' : minHeight - menuPadding + 'px'});
menuInner.css({'max-height' : menuHeight - headerHeight - searchHeight- menuPadding- selectAllHeight + 'px', 'overflow-y' : 'auto', 'min-height' : minHeight - menuPadding + 'px'});
};
getSize();
$(window).resize(getSize);
$(window).scroll(getSize);
} else if (this.options.size && this.options.size != 'auto' && menu.find('li'+notDisabled).length > this.options.size) {
var optIndex = menu.find("li"+notDisabled+" > *").filter(':not(.div-contain)').slice(0,this.options.size).last().parent().index();
var divLength = menu.find("li").slice(0,optIndex + 1).find('.div-contain').length;
menuHeight = liHeight*this.options.size + divLength*divHeight + menuPadding;
menuHeight = liHeight*this.options.size + divLength*divHeight + menuPadding;
this.$newElement.toggleClass('dropup', (selectOffsetTop > selectOffsetBot) && menuHeight < menu.height() && this.options.dropupAuto);
menu.css({'max-height' : menuHeight + headerHeight + searchHeight + 'px', 'overflow' : 'hidden'});
menu.css({'max-height' : menuHeight + headerHeight + searchHeight + selectAllHeight + 'px', 'overflow' : 'hidden'});
menuInner.css({'max-height' : menuHeight - menuPadding + 'px', 'overflow-y' : 'auto'});
}
},
Expand Down Expand Up @@ -765,6 +766,7 @@
size: 'auto',
title: null,
selectedTextFormat : 'values',
trimTitle:30,
noneSelectedText : 'Nothing selected',
countSelectedText: '{0} of {1} selected',
width: false,
Expand Down

0 comments on commit a5b134e

Please sign in to comment.