diff --git a/index.html b/index.html index c6030e2..57817f2 100755 --- a/index.html +++ b/index.html @@ -4,6 +4,7 @@ jQuery selectBox (select replacement plugin) + @@ -335,6 +367,46 @@

$('select').selectBox();

+

+
+ +

+ +

+
+ +

+ + +

diff --git a/jquery.selectBox.js b/jquery.selectBox.js index d2f70b9..83d7be1 100755 --- a/jquery.selectBox.js +++ b/jquery.selectBox.js @@ -66,8 +66,14 @@ , tabIndex = parseInt(select.prop('tabindex')) || 0 , self = this; + // Store data for later use and show the control + select + .addClass('selectBox') + .data('selectBox-control', control) + .data('selectBox-settings', settings) + control - .width(select.outerWidth()) + .width(settings.width ? settings.width : select.outerWidth()) .addClass(select.attr('class')) .attr('title', select.attr('title') || '') .attr('tabindex', tabIndex) @@ -158,8 +164,6 @@ var label = $(''), arrow = $(''); - // Update label - label.attr('class', this.getLabelClass()).text(this.getLabelText()); options = this.getOptions('dropdown'); options.appendTo('BODY'); @@ -202,6 +206,10 @@ }) .insertAfter(select); + // Update label, call this only after the label has been added to control + // label.attr('class', this.getLabelClass()).text(this.getLabelText()); + this.setLabel(); + // Set label width var labelWidth = control.width() @@ -209,15 +217,11 @@ - (parseInt(label.css('paddingLeft')) || 0) - (parseInt(label.css('paddingRight')) || 0); - label.width(labelWidth); + label.width(Math.max(labelWidth, 15)); this.disableSelection(control); } // Store data for later use and show the control - select - .addClass('selectBox') - .data('selectBox-control', control) - .data('selectBox-settings', settings) - .hide(); + select.hide(); }; /** @@ -227,6 +231,8 @@ SelectBox.prototype.getOptions = function (type) { var options; var select = $(this.selectElement); + var settings = select.data('selectBox-settings'); + var customGenerateOptions = settings.generateOptions; var self = this; // Private function to handle recursion in the getOptions function. var _getOptions = function (select, options) { @@ -237,7 +243,7 @@ // Check for a value in the option found. if ($(this).length > 0) { // Create an option form the found element. - self.generateOptions($(this), options); + self.generateOptions($(this), options, customGenerateOptions); } else { // No option information found, so add an empty. options.append('

  • \u00A0
  • '); @@ -257,6 +263,7 @@ switch (type) { case 'inline': options = $('