Skip to content

Commit

Permalink
Merge pull request #5 from kenshoo/feature/trim_text
Browse files Browse the repository at this point in the history
trim text
  • Loading branch information
Ido Stern committed Nov 25, 2013
2 parents f1de229 + 7088d31 commit 7315f6f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
this.registerBlurFocusEvents(that);
if($.fn.tooltip){
this.$newElement.parent().addClass('has-info');
this.$newElement.tooltip({placement:'bottom',html:true})
this.$newElement.tooltip({placement:'bottom',html:true});
this.$newElement.find('[data-original-title]').tooltip({placement:'bottom'})
}
},

Expand Down Expand Up @@ -144,15 +145,21 @@
var optionClass = $this.attr("class") || '';
var inline = $this.attr("style") || '';
var text = $this.data('content') ? $this.data('content') : $this.html();
var origText = "";
if(that.options.trimOption!=null && text.trim().length>=that.options.trimOption){
origText = text;
text = text.substr(0,that.options.trimOption)+"...";
}
var subtext = $this.data('subtext') !== undefined ? '<small class="muted text-muted">' + $this.data('subtext') + '</small>' : '';
var icon = $this.data('icon') !== undefined ? '<i class="glyphicon '+$this.data('icon')+'"></i> ' : '';
if (icon !== '' && ($this.is(':disabled') || $this.parent().is(':disabled'))) {
icon = '<span>'+icon+'</span>';
}

if (!$this.data('content')) {
var tooltip = 'data-original-title=" '+origText.trim()+'"';
//Prepend any icon and append any subtext to the main text.
text = icon + '<span class="text">' + text + subtext + '</span>';
text = icon + '<span class="text" '+(origText.length>0?tooltip:"")+'>' + text + subtext + '</span>';
}

if (that.options.hideDisabled && ($this.is(':disabled') || $this.parent().is(':disabled'))) {
Expand Down Expand Up @@ -827,6 +834,7 @@
title: null,
selectedTextFormat : 'values',
trimTitle:30,
trimOption:20,
noneSelectedText : 'Nothing selected',
countSelectedText: '{0} of {1} selected',
width: false,
Expand Down

0 comments on commit 7315f6f

Please sign in to comment.