Skip to content

Commit

Permalink
Re: #209 - Fixing SelectBoxIt width of hidden select box
Browse files Browse the repository at this point in the history
  • Loading branch information
gfranko committed Oct 4, 2013
1 parent 0283d31 commit 8d9c624
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@

//var select = $("select").selectBoxIt({ populate: '<option value="test">test</option>' }).data('selectBox-selectBoxIt').remove(0);

$('select').selectBoxIt({ defaultText: 'Testing' });
$('select').selectBoxIt({ defaultText: 'Testing', autoWidth: false });

$('form').removeClass('hidden');

Expand Down
37 changes: 35 additions & 2 deletions src/javascripts/jquery.selectBoxIt.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
_create: function(internal) {

var self = this,
populateOption = self.options["populate"];
populateOption = self.options["populate"],
userTheme = self.options["theme"];

// If the element calling SelectBoxIt is not a select box or is not visible
if(!self.element.is("select")) {
Expand Down Expand Up @@ -280,7 +281,7 @@
// The html document height
self.documentHeight = $(document).height();

self.theme = self.getThemes()[self.options["theme"]] || self.getThemes()["default"];
self.theme = $.isPlainObject(userTheme) ? $.extend({}, self.getThemes()["default"], userTheme) : self.getThemes()[userTheme] ? self.getThemes()[userTheme] : self.getThemes()["default"];

// The index of the currently selected dropdown list option
self.currentFocus = 0;
Expand Down Expand Up @@ -1740,6 +1741,38 @@

return self;

},

// _realOuterWidth
// ---------------
// Retrieves the true outerWidth dimensions of a hidden DOM element
_realOuterWidth: function(elem) {

if(elem.is(":visible")) {

return elem.outerWidth(true);

}

var self = this,
clonedElem = elem.clone(),
outerWidth;

clonedElem.css({

"visibility": "hidden",

"display": "block",

"position": "absolute"

}).appendTo("body");

outerWidth = clonedElem.outerWidth(true);

clonedElem.remove();

return outerWidth;
}

});
Expand Down
39 changes: 36 additions & 3 deletions src/javascripts/jquery.selectBoxIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
_create: function(internal) {

var self = this,
populateOption = self.options["populate"];
populateOption = self.options["populate"],
userTheme = self.options["theme"];

// If the element calling SelectBoxIt is not a select box or is not visible
if(!self.element.is("select")) {
Expand Down Expand Up @@ -280,7 +281,7 @@
// The html document height
self.documentHeight = $(document).height();

self.theme = self.getThemes()[self.options["theme"]] || self.getThemes()["default"];
self.theme = $.isPlainObject(userTheme) ? $.extend({}, self.getThemes()["default"], userTheme) : self.getThemes()[userTheme] ? self.getThemes()[userTheme] : self.getThemes()["default"];

// The index of the currently selected dropdown list option
self.currentFocus = 0;
Expand Down Expand Up @@ -1740,6 +1741,38 @@

return self;

},

// _realOuterWidth
// ---------------
// Retrieves the true outerWidth dimensions of a hidden DOM element
_realOuterWidth: function(elem) {

if(elem.is(":visible")) {

return elem.outerWidth(true);

}

var self = this,
clonedElem = elem.clone(),
outerWidth;

clonedElem.css({

"visibility": "hidden",

"display": "block",

"position": "absolute"

}).appendTo("body");

outerWidth = clonedElem.outerWidth(true);

clonedElem.remove();

return outerWidth;
}

});
Expand Down Expand Up @@ -2889,7 +2922,7 @@ selectBoxIt._destroySelectBoxIt = function() {

"visibility": "visible",

"width": self.dropdown.outerWidth(),
"width": self._realOuterWidth(self.dropdown),

"height": self.dropdown.outerHeight(),

Expand Down
4 changes: 2 additions & 2 deletions src/javascripts/jquery.selectBoxIt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/javascripts/jquery.selectBoxIt.mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

"visibility": "visible",

"width": self.dropdown.outerWidth(),
"width": self._realOuterWidth(self.dropdown),

"height": self.dropdown.outerHeight(),

Expand Down

0 comments on commit 8d9c624

Please sign in to comment.