diff options
author | zhixin <wenzhixin2010@gmail.com> | 2015-11-24 15:46:01 +0800 |
---|---|---|
committer | zhixin <wenzhixin2010@gmail.com> | 2015-11-24 15:46:01 +0800 |
commit | bef9c59171937798093f68b1a00f25431d929ed8 (patch) | |
tree | 5ee2623b5eddec466b30ec7ffe63893d2d23beba | |
parent | 7dc847f6e7db35684b9e0b6f7178d8e260caad2f (diff) | |
download | multiple-select-bef9c59171937798093f68b1a00f25431d929ed8.zip multiple-select-bef9c59171937798093f68b1a00f25431d929ed8.tar.gz multiple-select-bef9c59171937798093f68b1a00f25431d929ed8.tar.bz2 |
Update to 1.2.0
-rw-r--r-- | CHANGELOG.md | 28 | ||||
-rw-r--r-- | CONTRIBUTORS.md | 122 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | bower.json | 2 | ||||
-rw-r--r-- | docs/README-ZH-CN.md | 2 | ||||
-rw-r--r-- | docs/README.md | 4 | ||||
-rw-r--r-- | jquery.multiple.select.js | 349 | ||||
-rw-r--r-- | multiple-select.jquery.json | 2 | ||||
-rw-r--r-- | package.json | 2 |
9 files changed, 224 insertions, 291 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9685bc1..9120512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ ## Changelog +### 1.2.0 + +* [bug] Fix #48: auto hide when the single option is set to true. +* [bug] Fix #65: show selectAll and hide noResults when open. +* [bug] Fix #45, #64: update width option to support a percentage setting. +* [bug] Trigger the checkbox on the entire line. +* [bug] Added `noMatchesFound` option. +* [bug] Update `seperator` to `separator`. +* [enh] Allow object of options along with initial method. +* [enh] Add a `filterAcceptOnEnter` option. +* [enh] Put class on ms-parent div instead of ul. +* [bug] Fixed #99: connect select back to its label. +* [enh] Added `hideOptgroupCheckboxes` option to hide optgroup checkboxes. +* [enh] Added `displayValues` and `delimiter` options. +* [enh] Added `textTemplate` option to custom the text. +* [enh] Added `selectAllDelimiter` option. +* [enh] Added `ellipsis` option. +* [enh] Get percentage width, if used. +* [bug] Fix #134: spelling error. +* [bug] Fixed the error when element id's contain colons. +* [bug] Fix current selected element not displayed in newer jquery versions. +* [bug] Fix #148 plain text stored to HTML. +* [bug] Update multiple-select.png. +* [enh] Added 'close' to allowedMethods. +* [bug] Prevent dropdown from closing occasionally when clicking on checkbox. +* [bug] Fixed dropdown not closing when focus was lost. +* [enh] Support for add title (tooltip) on the select list. + ### 1.1.0 * Fix #63: Add ```keepOpen``` option. diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md deleted file mode 100644 index 1a95f34..0000000 --- a/CONTRIBUTORS.md +++ /dev/null @@ -1,122 +0,0 @@ -## Contributors - -multiple-select is due to the excellent work of the following contributors: - -<table> -<tr> -<th>Author</th> -<th>Github</th> -<th>Location</th> -<th>Blog</th> -<th>Commits</th> -</tr> - -<tr> -<td><img src="https://avatars.githubusercontent.com/u/2117018?" width="32" height="32"> <a href="mailto:wenzhixin2010@gmail.com">文翼</a></td> -<td><a href="https://github.com/wenzhixin">wenzhixin</a></td> -<td>Guangzhou, China</td> -<td><a href="http://wenzhixin.net.cn">http://wenzhixin.net.cn</a></td> -<td>127</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/20234?" width="32" height="32"> Brett Zamir</td> -<td><a href="https://github.com/brettz9">brettz9</a></td> -<td>Shenzhen, China</td> -<td><a href="http://brett-zamir.me">http://brett-zamir.me</a></td> -<td>11</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/3852906?" width="32" height="32"> nicolas-joubert</td> -<td><a href="https://github.com/nicolas-joubert">nicolas-joubert</a></td> -<td>Lyon, France</td> -<td></td> -<td>2</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/4736139?" width="32" height="32"> <a href="mailto:e.marguin@agence-codecouleurs.fr">Eric Marguin</a></td> -<td><a href="https://github.com/emarguin">emarguin</a></td> -<td>France</td> -<td><a href="http://www.agence-codecouleurs.fr">http://www.agence-codecouleurs.fr</a></td> -<td>2</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/1726913?" width="32" height="32"> Sergio</td> -<td><a href="https://github.com/sergiomcalzada">sergiomcalzada</a></td> -<td></td> -<td></td> -<td>2</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/5041046?" width="32" height="32"> <a href="mailto:just@tut.by">Andrei</a></td> -<td><a href="https://github.com/JustAndrei">JustAndrei</a></td> -<td>Belarus, Minsk</td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/14005?" width="32" height="32"> <a href="mailto:fedesoria@gmail.com">Federico Soria</a></td> -<td><a href="https://github.com/fedesoria">fedesoria</a></td> -<td>San Francisco</td> -<td><a href="paybygroup.com">paybygroup.com</a></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/2584275?" width="32" height="32"> guli</td> -<td><a href="https://github.com/guli">guli</a></td> -<td></td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/1297559?" width="32" height="32"> Jona Goldman</td> -<td><a href="https://github.com/jonagoldman">jonagoldman</a></td> -<td></td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/7594976?" width="32" height="32"> topas08</td> -<td><a href="https://github.com/topas08">topas08</a></td> -<td></td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/62062?" width="32" height="32"> <a href="mailto:gaurav@jassal.me">Gaurav Jassal</a></td> -<td><a href="https://github.com/creativeaura">creativeaura</a></td> -<td>London</td> -<td><a href="http://gaurav.jassal.me">http://gaurav.jassal.me</a></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/2769778?" width="32" height="32"> jwheadon</td> -<td><a href="https://github.com/jwheadon">jwheadon</a></td> -<td></td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/479088?" width="32" height="32"> <a href="mailto:tmacey@boundlessnotions.com">Tobias Macey</a></td> -<td><a href="https://github.com/blarghmatey">blarghmatey</a></td> -<td>Boston, MA</td> -<td></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/1058901?" width="32" height="32"> <a href="mailto:xavier@dutreilh.com">Xavier Dutreilh</a></td> -<td><a href="https://github.com/xavierdutreilh">xavierdutreilh</a></td> -<td>Paris, France</td> -<td><a href="http://xavier.dutreilh.com/">http://xavier.dutreilh.com/</a></td> -<td>1</td> -<tr> -<tr> -<td><img src="https://avatars.githubusercontent.com/u/1628706?" width="32" height="32"> Alex Jeffrey</td> -<td><a href="https://github.com/ajeffrey">ajeffrey</a></td> -<td></td> -<td></td> -<td>1</td> -<tr> - -</table> - -Update date: 2014-07-13, created with https://github.com/wenzhixin/github-contributors
\ No newline at end of file @@ -4,10 +4,6 @@ Multiple select is a jQuery plugin to select multiple elements with checkboxes : To get started checkout examples and documentation at http://wenzhixin.net.cn/p/multiple-select -## Contributors - -[CONTRIBUTORS](https://github.com/wenzhixin/multiple-select/blob/master/CONTRIBUTORS.md) - ## Changelog [CHANGELOG](https://github.com/wenzhixin/multiple-select/blob/master/CHANGELOG.md) @@ -1,6 +1,6 @@ { "name": "multiple-select", - "version": "1.1.1", + "version": "1.2.0", "homepage": "https://github.com/wenzhixin/multiple-select", "authors": [ "文翼 <wenzhixin2010@gmail.com>" diff --git a/docs/README-ZH-CN.md b/docs/README-ZH-CN.md index 3d14d5c..29d56c4 100644 --- a/docs/README-ZH-CN.md +++ b/docs/README-ZH-CN.md @@ -2,7 +2,7 @@ Multiple select 是一个通过复选框来选择多元素的 jQuery 插件:). -*当前版本: 1.0.9* +*当前版本: 1.2.0* ## Requirements diff --git a/docs/README.md b/docs/README.md index 987c889..9030bd2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ Multiple select is a jQuery plugin to select multiple elements with checkboxes : **Multiple Selected is licensed under the The MIT License. Completely free, you can arbitrarily use and modify this plugin. If this plugin is useful to you, you can give me a <a href="https://github.com/wenzhixin/multiple-select/">star</a>, and I will do better, thanks.** -*Current version: 1.1.0* +*Current version: 1.2.0* ## Requirements @@ -1114,7 +1114,7 @@ Type: false or string By default this option is set to ```# of % selected```. -#### etcaetera +#### ellipsis Type: boolean diff --git a/jquery.multiple.select.js b/jquery.multiple.select.js index 4e34125..2c0a677 100644 --- a/jquery.multiple.select.js +++ b/jquery.multiple.select.js @@ -1,6 +1,6 @@ /** * @author zhixin wen <wenzhixin2010@gmail.com> - * @version 1.1.0 + * @version 1.2.0 * * http://wenzhixin.net.cn/p/multiple-select/ */ @@ -9,26 +9,54 @@ 'use strict'; + // it only does '%s', and return '' when arguments are undefined + var sprintf = function (str) { + var args = arguments, + flag = true, + i = 1; + + str = str.replace(/%s/g, function () { + var arg = args[i++]; + + if (typeof arg === 'undefined') { + flag = false; + return ''; + } + return arg; + }); + return flag ? str : ''; + }; + function MultipleSelect($el, options) { - var that = this, - name = $el.attr('name') || options.name || '' + var name = $el.attr('name') || options.name || ''; - var originalParentStyle = $el.parent().attr('style') || ''; - $el.parent().hide(); - var elWidth = $el.css("width"); - $el.parent().show().attr('style', originalParentStyle); - if (elWidth=="0px") {elWidth = $el.outerWidth()+20} + this.options = options; + // hide select element this.$el = $el.hide(); - this.options = options; - this.$parent = $('<div' + $.map(['class', 'title'],function (att) { - var attValue = that.$el.attr(att) || ''; - attValue = (att === 'class' ? ('ms-parent' + (attValue ? ' ' : '')) : '') + attValue; - return attValue ? (' ' + att + '="' + attValue + '"') : ''; - }).join('') + ' />'); - this.$choice = $('<button type="button" class="ms-choice"><span class="placeholder">' + - options.placeholder + '</span><div></div></button>'); - this.$drop = $('<div class="ms-drop ' + options.position + '"></div>'); + + // label element + this.$label = this.$el.closest('label') || + this.$el.attr('id') && $(sprintf('label[for="%s"]', this.$el.attr('id').replace(/:/g, '\\:'))); + + // restore class and title from select element + this.$parent = $(sprintf( + '<div class="ms-parent %s" %s/>', + $el.attr('class') || '', + sprintf('title="%s"', $el.attr('title')))); + + // add placeholder to choice button + this.$choice = $(sprintf([ + '<button type="button" class="ms-choice">', + '<span class="placeholder">%s</span>', + '<div></div>', + '</button>' + ].join(''), + this.options.placeholder)); + + // default position is bottom + this.$drop = $(sprintf('<div class="ms-drop %s"></div>', this.options.position)); + this.$el.after(this.$parent); this.$parent.append(this.$choice); this.$parent.append(this.$drop); @@ -36,21 +64,10 @@ if (this.$el.prop('disabled')) { this.$choice.addClass('disabled'); } - this.$parent.css('width', options.width || elWidth); - - if (!this.options.keepOpen) { - $('body').click(function (e) { - if ($(e.target)[0] === that.$choice[0] || - $(e.target).parents('.ms-choice')[0] === that.$choice[0]) { - return; - } - if (($(e.target)[0] === that.$drop[0] || - $(e.target).parents('.ms-drop')[0] !== that.$drop[0]) && - that.options.isOpen) { - that.close(); - } - }); - } + this.$parent.css('width', + this.options.width || + this.$el.css('width') || + this.$el.outerWidth() + 20); this.selectAllName = 'name="selectAll' + name + '"'; this.selectGroupName = 'name="selectGroup' + name + '"'; @@ -61,30 +78,35 @@ constructor: MultipleSelect, init: function () { - var that = this; + var that = this, + $ul = $('<ul></ul>'); + if (this.options.filter) { - this.$drop.append( - '<div class="ms-search">' + - '<input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false">' + - '</div>' + this.$drop.append([ + '<div class="ms-search">', + '<input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false">', + '</div>'].join('') ); } - var ul = $('<ul></ul>'); + if (this.options.selectAll && !this.options.single) { - ul.append( - '<li class="ms-select-all">' + - '<label>' + - '<input type="checkbox" ' + this.selectAllName + ' /> ' + - this.options.selectAllDelimiter[0] + this.options.selectAllText + this.options.selectAllDelimiter[1] + - '</label>' + + $ul.append([ + '<li class="ms-select-all">', + '<label>', + sprintf('<input type="checkbox" %s /> ', this.selectAllName), + this.options.selectAllDelimiter[0], + this.options.selectAllText, + this.options.selectAllDelimiter[1], + '</label>', '</li>' - ); + ].join('')); } + $.each(this.$el.children(), function (i, elm) { - ul.append(that.optionToHtml(i, elm)); + $ul.append(that.optionToHtml(i, elm)); }); - ul.append('<li class="ms-no-results">' + this.options.noMatchesFound + '</li>'); - this.$drop.append(ul); + $ul.append(sprintf('<li class="ms-no-results">%s</li>', this.options.noMatchesFound)); + this.$drop.html('').append($ul); this.$drop.find('ul').css('max-height', this.options.maxHeight + 'px'); this.$drop.find('.multiple').css('width', this.options.multipleWidth + 'px'); @@ -95,6 +117,7 @@ this.$selectItems = this.$drop.find('input[' + this.selectItemName + ']:enabled'); this.$disableItems = this.$drop.find('input[' + this.selectItemName + ']:disabled'); this.$noResults = this.$drop.find('.ms-no-results'); + this.events(); this.updateSelectAll(true); this.update(true); @@ -102,20 +125,28 @@ if (this.options.isOpen) { this.open(); } + + if (!this.options.keepOpen) { + $('body').click(function (e) { + if ($(e.target)[0] === that.$choice[0] || + $(e.target).parents('.ms-choice')[0] === that.$choice[0]) { + return; + } + if (($(e.target)[0] === that.$drop[0] || + $(e.target).parents('.ms-drop')[0] !== that.$drop[0]) && + that.options.isOpen) { + that.close(); + } + }); + } }, optionToHtml: function (i, elm, group, groupDisabled) { var that = this, $elm = $(elm), - multiple = this.options.multiple, - optAttributesToCopy = ['class', 'title'], - clss = $.map(optAttributesToCopy, function (att, i) { - var isMultiple = att === 'class' && multiple; - var attValue = $elm.attr(att) || ''; - return (isMultiple || attValue) ? - (' ' + att + '="' + (isMultiple ? ('multiple' + (attValue ? ' ' : '')) : '') + attValue + '"') : - ''; - }).join(''), + classes = $elm.attr('class') || '', + title = sprintf('title="%s"', $elm.attr('title')), + multiple = this.options.multiple ? 'multiple' : '', disabled, type = this.options.single ? 'radio' : 'checkbox'; @@ -123,67 +154,58 @@ var value = $elm.val(), text = that.options.textTemplate($elm), selected = $elm.prop('selected'), - style = this.options.styler(value) ? ' style="' + this.options.styler(value) + '"' : ''; + style = sprintf('style="%s"', this.options.styler(value)); disabled = groupDisabled || $elm.prop('disabled'); - if ((this.options.blockSeparator > "") && (this.options.blockSeparator == $elm.val())) { - var li = $( - '<li' + clss + style + '>', - '<label class="' + this.options.blockSeparator + (disabled ? 'disabled' : '') + '">', - '</label>', - '</li>' - ); - li.find('label').append(document.createTextNode(text)); - return li; - } else { - var li = $( - '<li' + clss + style + '>' + - '<label' + (disabled ? ' class="disabled"' : '') + '>' + - '<input type="' + type + '" ' + this.selectItemName + - (selected ? ' checked="checked"' : '') + - (disabled ? ' disabled="disabled"' : '') + - (group ? ' data-group="' + group + '"' : '') + - '/> ' + - '</label>' + - '</li>'); - li.find('input').val(value); - li.find('label').append(document.createTextNode(text)); - return li; - } - } else if (!group && $elm.is('optgroup')) { - var _group = 'group_' + i, - label = $elm.attr('label'); + + return $([ + sprintf('<li class="%s %s" %s %s>', multiple, classes, title, style), + sprintf('<label class="%s">', disabled ? 'disabled' : ''), + sprintf('<input type="%s" %s%s%s%s value="%s">', + type, this.selectItemName, + selected ? ' checked="checked"' : '', + disabled ? ' disabled="disabled"' : '', + sprintf(' data-group="%s"', group), + value), + text, + '</label>', + '</li>' + ].join('')); + } + if ($elm.is('optgroup')) { + var group = 'group_' + i, + label = $elm.attr('label'), + text = that.options.textTemplate($elm), + $group = $('<div/>'); disabled = $elm.prop('disabled'); - var group = $('<div/>'); - group.append( - '<li class="group">' + - '<label class="optgroup' + (disabled ? ' disabled' : '') + '" data-group="' + _group + '">' + - (this.options.hideOptgroupCheckboxes ? '' : '<input type="checkbox" ' + this.selectGroupName + - (disabled ? ' disabled="disabled"' : '') + ' /> ') + - label + - '</label>' + - '</li>'); - li.find('label').append(document.createTextNode(text)); + + $group.append([ + '<li class="group">', + sprintf('<label class="optgroup %s" data-group="%s">', disabled ? 'disabled' : '', group), + this.options.hideOptgroupCheckboxes ? '' : sprintf('<input type="checkbox" %s %s>', + this.selectGroupName, disabled ? 'disabled="disabled"' : ''), + label, + '</label>', + '</li>' + ].join('')); + $.each($elm.children(), function (i, elm) { - group.append(that.optionToHtml(i, elm, _group, disabled)); + $group.append(that.optionToHtml(i, elm, group, disabled)); }); - return group.html(); + return $group.html(); } }, events: function () { - var that = this; - - function toggleOpen(e) { - e.preventDefault(); - that[that.options.isOpen ? 'close' : 'open'](); - } - - var label = this.$el.parent().closest('label')[0] || $('label[for=' + this.$el.attr('id').split(':').join('\\:') + ']')[0]; + var that = this, + toggleOpen = function (e) { + e.preventDefault(); + that[that.options.isOpen ? 'close' : 'open'](); + }; - if (label) { - $(label).off('click').on('click', function (e) { + if (this.$label) { + this.$label.off('click').on('click', function (e) { if (e.target.nodeName.toLowerCase() !== 'label' || e.target !== this) { return; } @@ -194,6 +216,7 @@ e.stopPropagation(); // Causes lost focus otherwise }); } + this.$choice.off('click').on('click', toggleOpen) .off('focus').on('focus', this.options.onFocus) .off('blur').on('blur', this.options.onBlur); @@ -206,25 +229,28 @@ break; } }); + this.$searchInput.off('keydown').on('keydown',function (e) { - if (e.keyCode === 9 && e.shiftKey) { // Ensure shift-tab causes lost focus from filter as with clicking away + // Ensure shift-tab causes lost focus from filter as with clicking away + if (e.keyCode === 9 && e.shiftKey) { that.close(); } }).off('keyup').on('keyup', function (e) { - if (that.options.filterAcceptOnEnter && - (e.which === 13 || e.which == 32) && // enter or space - that.$searchInput.val() // Avoid selecting/deselecting if no choices made - ) { - that.$selectAll.click(); - that.close(); - that.focus(); - return; - } - that.filter(); - }); + // enter or space + // Avoid selecting/deselecting if no choices made + if (that.options.filterAcceptOnEnter && (e.which === 13 || e.which == 32) && that.$searchInput.val()) { + that.$selectAll.click(); + that.close(); + that.focus(); + return; + } + that.filter(); + }); + this.$selectAll.off('click').on('click', function () { var checked = $(this).prop('checked'), $items = that.$selectItems.filter(':visible'); + if ($items.length === that.$selectItems.length) { that[checked ? 'checkAll' : 'uncheckAll'](); } else { // when the filter option is true @@ -237,8 +263,9 @@ this.$selectGroups.off('click').on('click', function () { var group = $(this).parent().attr('data-group'), $items = that.$selectItems.filter(':visible'), - $children = $items.filter('[data-group="' + group + '"]'), + $children = $items.filter(sprintf('[data-group="%s"]', group)), checked = $children.length !== $children.filter(':checked').length; + $children.prop('checked', checked); that.updateSelectAll(); that.update(); @@ -277,7 +304,7 @@ this.$noResults.hide(); // Fix #77: 'All selected' when no options - if (this.$el.children().length === 0) { + if (!this.$el.children().length) { this.$selectAll.parent().hide(); this.$noResults.show(); } @@ -285,8 +312,12 @@ if (this.options.container) { var offset = this.$drop.offset(); this.$drop.appendTo($(this.options.container)); - this.$drop.offset({ top: offset.top, left: offset.left }); + this.$drop.offset({ + top: offset.top, + left: offset.left + }); } + if (this.options.filter) { this.$searchInput.val(''); this.$searchInput.focus(); @@ -310,41 +341,35 @@ }, update: function (isInit) { - var selects = this.getSelects(), - $span = this.$choice.find('>span'); + var selects = this.options.displayValues ? this.getSelects() : this.getSelects('text'), + $span = this.$choice.find('>span'), + sl = selects.length; - if (selects.length === 0) { + if (sl === 0) { $span.addClass('placeholder').html(this.options.placeholder); - } else if (this.options.countSelected && selects.length < this.options.minimumCountSelected) { - $span.removeClass('placeholder').text( - (this.options.displayValues ? selects : this.getSelects('text')) - .join(this.options.delimiter)); - } else if (this.options.allSelected && - selects.length === this.$selectItems.length + this.$disableItems.length) { + } else if (this.options.allSelected && sl === this.$selectItems.length + this.$disableItems.length) { $span.removeClass('placeholder').html(this.options.allSelected); - } else if ((this.options.countSelected || this.options.etcaetera) && selects.length > this.options.minimumCountSelected) { - if (this.options.etcaetera) { - $span.removeClass('placeholder').text((this.options.displayValues ? selects : this.getSelects('text').slice(0, this.options.minimumCountSelected)).join(this.options.delimiter) + '...'); - } - else { - $span.removeClass('placeholder').html(this.options.countSelected - .replace('#', selects.length) - .replace('%', this.$selectItems.length + this.$disableItems.length)); - } + } else if (this.options.ellipsis && sl > this.options.minimumCountSelected) { + $span.removeClass('placeholder').text(selects.slice(0, this.options.minimumCountSelected) + .join(this.options.delimiter) + '...'); + } else if (this.options.countSelected && sl > this.options.minimumCountSelected) { + $span.removeClass('placeholder').html(this.options.countSelected + .replace('#', selects.length) + .replace('%', this.$selectItems.length + this.$disableItems.length)); } else { - $span.removeClass('placeholder').text( - (this.options.displayValues ? selects : this.getSelects('text')) - .join(this.options.delimiter)); + $span.removeClass('placeholder').text(selects.join(this.options.delimiter)); } - if (this.options.addTitle) + + if (this.options.addTitle) { $span.prop('title', this.getSelects('text')); + } // set selects to select this.$el.val(this.getSelects()); // add selected class to selected li this.$drop.find('li').removeClass('selected'); - this.$drop.find('input[' + this.selectItemName + ']:checked').each(function () { + this.$drop.find(sprintf('input[%s]:checked', this.selectItemName)).each(function () { $(this).parents('li').first().addClass('selected'); }); @@ -354,9 +379,12 @@ } }, - updateSelectAll: function (Init) { + updateSelectAll: function (isInit) { var $items = this.$selectItems; - if (!Init) { $items = $items.filter(':visible'); } + + if (!isInit) { + $items = $items.filter(':visible'); + } this.$selectAll.prop('checked', $items.length && $items.length === $items.filter(':checked').length); if (this.$selectAll.prop('checked')) { @@ -368,7 +396,7 @@ var $items = this.$selectItems.filter(':visible'); $.each(this.$selectGroups, function (i, val) { var group = $(val).parent().attr('data-group'), - $children = $items.filter('[data-group="' + group + '"]'); + $children = $items.filter(sprintf('[data-group="%s"]', group)); $(val).prop('checked', $children.length && $children.length === $children.filter(':checked').length); }); @@ -379,7 +407,7 @@ var that = this, texts = [], values = []; - this.$drop.find('input[' + this.selectItemName + ']:checked').each(function () { + this.$drop.find(sprintf('input[%s]:checked', this.selectItemName)).each(function () { texts.push($(this).parents('li').first().text()); values.push($(this).val()); }); @@ -390,10 +418,10 @@ var html = [], text = $.trim($(this).parent().text()), group = $(this).parent().data('group'), - $children = that.$drop.find('[' + that.selectItemName + '][data-group="' + group + '"]'), + $children = that.$drop.find(sprintf('[%s][data-group="%s"]', that.selectItemName, group)), $selected = $children.filter(':checked'); - if ($selected.length === 0) { + if (!$selected.length) { return; } @@ -417,7 +445,7 @@ var that = this; this.$selectItems.prop('checked', false); $.each(values, function (i, value) { - that.$selectItems.filter('[value="' + value + '"]').prop('checked', true); + that.$selectItems.filter(sprintf('[value="%s"]', value)).prop('checked', true); }); this.$selectAll.prop('checked', this.$selectItems.length === this.$selectItems.filter(':checked').length); @@ -522,7 +550,7 @@ if (typeof option === 'string') { if ($.inArray(option, allowedMethods) < 0) { - throw "Unknown method: " + option; + throw 'Unknown method: ' + option; } value = data[option](args[1]); } else { @@ -533,7 +561,7 @@ } }); - return value ? value : this; + return typeof value !== 'undefined' ? value : this; }; $.fn.multipleSelect.defaults = { @@ -541,12 +569,9 @@ isOpen: false, placeholder: '', selectAll: true, - selectAllText: 'Select all', selectAllDelimiter: ['[', ']'], - allSelected: 'All selected', minimumCountSelected: 3, - countSelected: '# of % selected', - noMatchesFound: 'No matches found', + ellipsis: false, multiple: false, multipleWidth: 80, single: false, @@ -556,10 +581,16 @@ container: null, position: 'bottom', keepOpen: false, - blockSeparator: '', displayValues: false, delimiter: ', ', addTitle: false, + filterAcceptOnEnter: false, + hideOptgroupCheckboxes: false, + + selectAllText: 'Select all', + allSelected: 'All selected', + countSelected: '# of % selected', + noMatchesFound: 'No matches found', styler: function () { return false; diff --git a/multiple-select.jquery.json b/multiple-select.jquery.json index dd636fd..94b4a9f 100644 --- a/multiple-select.jquery.json +++ b/multiple-select.jquery.json @@ -1,6 +1,6 @@ { "name": "multiple-select", - "version": "1.1.0", + "version": "1.2.0", "title": "Multiple Select", "description": "Multiple select is a jQuery plugin to select multiple elements with checkboxes :).", "author": { diff --git a/package.json b/package.json index f258aad..7e72ecd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "multiple-select", "main": "jquery.multiple.select.js", - "version": "1.1.0", + "version": "1.2.0", "title": "Multiple Select", "description": "Multiple select is a jQuery plugin to select multiple elements with checkboxes :).", "author": { |