Skip to content

Commit

Permalink
Merge pull request #449 from caseyjhol/master
Browse files Browse the repository at this point in the history
v1.4.3 - performance issues
  • Loading branch information
caseyjhol committed Jan 16, 2014
2 parents 822782e + f8deae1 commit 08f3d68
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bootstrap-select.css
@@ -1,5 +1,5 @@
/*!
* bootstrap-select v1.4.2
* bootstrap-select v1.4.3
* http://silviomoreto.github.io/bootstrap-select/
*
* Copyright 2013 bootstrap-select
Expand Down
2 changes: 1 addition & 1 deletion bootstrap-select.jquery.json
Expand Up @@ -8,7 +8,7 @@
"select",
"replacement"
],
"version": "1.4.2",
"version": "1.4.3",
"author": {
"name": "Silvio Moreto",
"url": "https://github.com/silviomoreto/"
Expand Down
51 changes: 28 additions & 23 deletions bootstrap-select.js
@@ -1,5 +1,5 @@
/*!
* bootstrap-select v1.4.2
* bootstrap-select v1.4.3
* http://silviomoreto.github.io/bootstrap-select/
*
* Copyright 2013 bootstrap-select
Expand All @@ -23,6 +23,7 @@
this.$newElement = null;
this.$button = null;
this.$menu = null;
this.$lis = null;

//Merge defaults, options and data-attributes to make our options
this.options = $.extend({}, $.fn.selectpicker.defaults, this.$element.data(), typeof options == 'object' && options);
Expand All @@ -47,18 +48,19 @@
constructor: Selectpicker,

init: function() {
var that = this,
id = this.$element.attr('id');

this.$element.hide();
this.multiple = this.$element.prop('multiple');
this.autofocus = this.$element.prop('autofocus');
var id = this.$element.attr('id');
this.$newElement = this.createView();
this.$element.after(this.$newElement);
this.$menu = this.$newElement.find('> .dropdown-menu');
this.$button = this.$newElement.find('> button');
this.$searchbox = this.$newElement.find('input');

if (id !== undefined) {
var that = this;
this.$button.attr('data-id', id);
$('label[for="' + id + '"]').click(function(e) {
e.preventDefault();
Expand All @@ -68,16 +70,12 @@

this.checkDisabled();
this.clickListener();
if (this.options.liveSearch) {
this.liveSearchListener();
}
if (this.options.liveSearch) this.liveSearchListener();
this.render();
this.liHeight();
this.setStyle();
this.setWidth();
if (this.options.container) {
this.selectPosition();
}
if (this.options.container) this.selectPosition();
this.$menu.data('this', this);
this.$newElement.data('this', this);
},
Expand Down Expand Up @@ -199,14 +197,16 @@
'</a>';
},

render: function() {
render: function(updateLi) {
var that = this;

//Update the LI to match the SELECT
this.$element.find('option').each(function(index) {
that.setDisabled(index, $(this).is(':disabled') || $(this).parent().is(':disabled') );
that.setSelected(index, $(this).is(':selected') );
});
if (updateLi !== false) {
this.$element.find('option').each(function(index) {
that.setDisabled(index, $(this).is(':disabled') || $(this).parent().is(':disabled') );
that.setSelected(index, $(this).is(':selected') );
});
}

this.tabIndex();

Expand Down Expand Up @@ -408,6 +408,7 @@
},

refresh: function() {
this.$lis = null;
this.reloadLi();
this.render();
this.setWidth();
Expand All @@ -425,14 +426,16 @@
},

setSelected: function(index, selected) {
this.$menu.find('li').eq(index).toggleClass('selected', selected);
if (this.$lis == null) this.$lis = this.$menu.find('li');
$(this.$lis[index]).toggleClass('selected', selected);
},

setDisabled: function(index, disabled) {
if (this.$lis == null) this.$lis = this.$menu.find('li');
if (disabled) {
this.$menu.find('li').eq(index).addClass('disabled').find('a').attr('href', '#').attr('tabindex', -1);
$(this.$lis[index]).addClass('disabled').find('a').attr('href', '#').attr('tabindex', -1);
} else {
this.$menu.find('li').eq(index).removeClass('disabled').find('a').removeAttr('href').attr('tabindex', 0);
$(this.$lis[index]).removeClass('disabled').find('a').removeAttr('href').attr('tabindex', 0);
}
},

Expand Down Expand Up @@ -497,19 +500,21 @@

//Dont run if we have been disabled
if (!that.isDisabled() && !$(this).parent().hasClass('disabled')) {
var $options = that.$element.find('option');
var $option = $options.eq(clickedIndex);
var $options = that.$element.find('option'),
$option = $options.eq(clickedIndex),
state = $option.prop('selected');

//Deselect all others if not multi select box
if (!that.multiple) {
$options.prop('selected', false);
$option.prop('selected', true);
that.$menu.find('.selected').removeClass('selected');
that.setSelected(clickedIndex, true);
}
//Else toggle the one we have chosen if we are multi select.
else {
var state = $option.prop('selected');

$option.prop('selected', !state);
that.setSelected(clickedIndex, !state);
}

if (!that.multiple) {
Expand Down Expand Up @@ -546,7 +551,7 @@
});

this.$element.change(function() {
that.render();
that.render(false);
});
},

Expand Down Expand Up @@ -860,4 +865,4 @@
.on('keydown', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bootstrap-select-searchbox input', Selectpicker.prototype.keydown)
.on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bootstrap-select-searchbox input', function (e) { e.stopPropagation(); });

}(window.jQuery);
}(window.jQuery);
2 changes: 1 addition & 1 deletion bootstrap-select.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bootstrap-select.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -4,7 +4,7 @@
"bootstrap-select.css",
"bootstrap-select.js"
],
"version": "1.4.2",
"version": "1.4.3",
"homepage": "https://github.com/silviomoreto/bootstrap-select",
"authors": [
"silviomoreto"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -3,7 +3,7 @@
"description": "A custom <select> for @twitter bootstrap using button dropdown as replacement",
"keywords": ["form", "bootstrap", "select", "replacement"],
"homepage": "https://github.com/silviomoreto/bootstrap-select",
"version": "1.4.2",
"version": "1.4.3",
"authors": [
{
"name": "Silvio Moreto",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"title": "bootstrap-select",
"filename": "bootstrap-select.js",
"description": "A custom <select> for @twitter bootstrap using button dropdown as replacement",
"version": "1.4.2",
"version": "1.4.3",
"homepage": "http://silviomoreto.github.io/bootstrap-select/",
"author": {
"name": "Silvio Moreto",
Expand Down

0 comments on commit 08f3d68

Please sign in to comment.