summaryrefslogtreecommitdiffstats
path: root/jquery.multiple.select.js
diff options
context:
space:
mode:
authorJona Goldman <jonagoldman@gmail.com>2014-04-02 16:42:02 +0300
committerJona Goldman <jonagoldman@gmail.com>2014-04-02 16:42:02 +0300
commit11bfeb94e4af81bc8bd89d2b37efae828ab65680 (patch)
treefdcf04715ff507fd10d1625090749eb396be85ff /jquery.multiple.select.js
parent3fe8e29e0ac6a0196853f4d7dda726a58b7f5be4 (diff)
downloadmultiple-select-11bfeb94e4af81bc8bd89d2b37efae828ab65680.zip
multiple-select-11bfeb94e4af81bc8bd89d2b37efae828ab65680.tar.gz
multiple-select-11bfeb94e4af81bc8bd89d2b37efae828ab65680.tar.bz2
Added 3 new options: 'allSelected', 'minumimCountSelected' and 'countSelected'
'allSelected' can be used to overwrite the text shown when all the items are selected. 'minumimCountSelected' and 'countSelected' can be used to show a formatted text after X items where selected. For example: '3 of 10 selected' will be shown if 'minumimCountSelected' is set to 3 and 'countSelected' is set to '# of % selected'.
Diffstat (limited to 'jquery.multiple.select.js')
-rw-r--r--jquery.multiple.select.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/jquery.multiple.select.js b/jquery.multiple.select.js
index 456c41f..8522191 100644
--- a/jquery.multiple.select.js
+++ b/jquery.multiple.select.js
@@ -39,12 +39,12 @@
}
if (($(e.target)[0] === that.$drop[0] ||
$(e.target).parents('.ms-drop')[0] !== that.$drop[0]) &&
- that.options.isopen) {
+ that.options.isOpen) {
that.close();
}
});
- if (this.options.isopen) {
+ if (this.options.isOpen) {
this.open();
}
}
@@ -140,7 +140,7 @@
events: function() {
var that = this;
this.$choice.off('click').on('click', function() {
- that[that.options.isopen ? 'close' : 'open']();
+ that[that.options.isOpen ? 'close' : 'open']();
})
.off('focus').on('focus', this.options.onFocus)
.off('blur').on('blur', this.options.onBlur);
@@ -198,7 +198,7 @@
if (this.$choice.hasClass('disabled')) {
return;
}
- this.options.isopen = true;
+ this.options.isOpen = true;
this.$choice.find('>div').addClass('open');
this.$drop.show();
if (this.options.container) {
@@ -214,7 +214,7 @@
},
close: function() {
- this.options.isopen = false;
+ this.options.isOpen = false;
this.$choice.find('>div').removeClass('open');
this.$drop.hide();
if (this.options.container) {
@@ -230,8 +230,10 @@
update: function() {
var selects = this.getSelects('text'),
$span = this.$choice.find('>span');
- if(selects.length == this.$selectItems.length && this.options.overrideButtonText) {
- $span.removeClass('placeholder').html(this.options.selectAllText);
+ if (selects.length == this.$selectItems.length && this.options.allSelected) {
+ $span.removeClass('placeholder').html(this.options.allSelected);
+ } else if (selects.length > this.options.minumimCountSelected && this.options.countSelected) {
+ $span.removeClass('placeholder').html(this.options.countSelected.replace('#', selects.length).replace('%', this.$selectItems.length));
} else if (selects.length) {
$span.removeClass('placeholder').html(selects.join(', '));
} else {
@@ -416,10 +418,13 @@
};
$.fn.multipleSelect.defaults = {
- isopen: false,
+ isOpen: false,
placeholder: '',
selectAll: true,
selectAllText: 'Select all',
+ allSelected: 'All selected', // false or string
+ minumimCountSelected: 3, // int - 'countSelectedText' will be shown only if more than X items where selected
+ countSelected: '# of % selected', // false or string - '#' is replaced with the count of selected items, '%' is replaces with total items
multiple: false,
multipleWidth: 80,
single: false,