diff options
author | Brett Zamir <brettz9@yahoo.com> | 2014-06-20 09:15:48 +0800 |
---|---|---|
committer | Brett Zamir <brettz9@yahoo.com> | 2014-06-20 09:15:48 +0800 |
commit | 06453453632e167803e2534291d5fffd82d83382 (patch) | |
tree | cff5bfee75a67f04c742e7957bcec09f5a87ad13 | |
parent | 6aaeffb3ee9273183c342bd9021a46181b06eeae (diff) | |
parent | bcb85811fee0819e8db6c9f235efcdf3ebbe44a9 (diff) | |
download | multiple-select-06453453632e167803e2534291d5fffd82d83382.zip multiple-select-06453453632e167803e2534291d5fffd82d83382.tar.gz multiple-select-06453453632e167803e2534291d5fffd82d83382.tar.bz2 |
Merge branch 'master' of https://github.com/wenzhixin/multiple-select.git
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGELOG.md | 69 | ||||
-rw-r--r-- | CONTRIBUTORS.md | 108 | ||||
-rw-r--r-- | README.md | 83 | ||||
-rw-r--r-- | jquery.multiple.select.js | 56 |
5 files changed, 224 insertions, 93 deletions
@@ -1 +1,2 @@ /bower_components/ +/tools diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9751780 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,69 @@ +## Changelog + +### 1.1.0 + +* Fix #63: Add ```keepOpen``` option. +* Fix #62: Fix ```isOpen``` and ```filter``` options are both true bug. +* Fix #57: Fire onCheckAll event when literally select. +* Add data attributes for support. +* Fix #55: Add ```name``` option. + +### 1.0.9 + +* Fix #42: Add ```styler``` option to custom item style. +* Fix firefox click bug. +* Add ```allSelected```, ```minumimCountSelected``` and ```countSelected``` options. +* Fix #35: Add ```onFocus``` and ```onBlur``` events. +* Fix #25: Add ```focus``` and ```blur``` methods. +* Fix #31: Trigger the onCheckAll & onUncheckAll events when use filter to select all. + +### 1.0.8 + +* Update the license to The MIT License. +* Fix #47: Add ```No matches found``` message when there are no results found. +* Fix #43: Add ```position``` option. + +### 1.0.7 + +* Fix #44: The filters not working bugs. + +### 1.0.6 + +* Fix #21: Add ```single``` option. +* Add ```override``` option. +* Add ```container``` option. +* Fix #29: Update the optgroups select text. +* Fix #30: Image is not shown in Firefox 25.0.1. +* Fix #22: fix group filter problem. + +### 1.0.5 + +* Update the button text witdh. +* Add keyboard support. + +### 1.0.4 + +* Fix #12: Add ```width``` option. +* Fix #11: Add callback events. +* Add ```maxHeight``` option. + +### 1.0.3 + +* Fix #4: Add ```filter``` option. +* Support mobile devices. +* Fix #6: Add ```refresh``` method. + +### 1.0.2 + +* Fix #7: Add ```selected``` and ```disabled``` options. +* Fix #5: Add ```checkAll``` and ```uncheckAll``` methods. + +### 1.0.1 + +* Fix #3: Add optgroups support. +* Add ```placeholder``` option. +* Fix #2: use prop method instead of attr. + +### 1.0.0 + +* Initial release
\ No newline at end of file diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..82849b3 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,108 @@ +## Contributors + +Multiple select is due to the excellent work of the following contributors: + +<table> +<tr> +<th>Author</th> +<th>Github</th> +<th>Email</th> +<th>Blog</th> +<th>Commits</th> +</tr> + +<tr> +<td>文翼</td> +<td><a href="https://github.com/wenzhixin">wenzhixin</a></td> +<td><a href="mailto:wenzhixin2010@gmail.com">wenzhixin2010@gmail.com</a></td> +<td><a href="http://wenzhixin.net.cn">http://wenzhixin.net.cn</a></td> +<td>119</td> +</tr> +<tr> +<td>Brett Zamir</td> +<td><a href="https://github.com/brettz9">brettz9</a></td> +<td></td> +<td><a href="http://brett-zamir.me">http://brett-zamir.me</a></td> +<td>5</td> +</tr> +<tr> +<td>nicolas-joubert</td> +<td><a href="https://github.com/nicolas-joubert">nicolas-joubert</a></td> +<td></td> +<td></td> +<td>2</td> +</tr> +<tr> +<td>Andrei</td> +<td><a href="https://github.com/JustAndrei">JustAndrei</a></td> +<td><a href="mailto:just@tut.by">just@tut.by</a></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>Federico Soria</td> +<td><a href="https://github.com/fedesoria">fedesoria</a></td> +<td><a href="mailto:fedesoria@gmail.com">fedesoria@gmail.com</a></td> +<td><a href="http://paybygroup.com">paybygroup.com</a></td> +<td>1</td> +</tr> +<tr> +<td>topas08</td> +<td><a href="https://github.com/topas08">topas08</a></td> +<td></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>Xavier Dutreilh</td> +<td><a href="https://github.com/xavierdutreilh">xavierdutreilh</a></td> +<td><a href="mailto:xavier@dutreilh.com">xavier@dutreilh.com</a></td> +<td><a href="http://xavier.im/">http://xavier.im/</a></td> +<td>1</td> +</tr> +<tr> +<td>Alex Jeffrey</td> +<td><a href="https://github.com/ajeffrey">ajeffrey</a></td> +<td></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>Jona Goldman</td> +<td><a href="https://github.com/jonagoldman">jonagoldman</a></td> +<td></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>Tobias Macey</td> +<td><a href="https://github.com/blarghmatey">blarghmatey</a></td> +<td><a href="mailto:tmacey@boundlessnotions.com">tmacey@boundlessnotions.com</a></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>Gaurav Jassal</td> +<td><a href="https://github.com/creativeaura">creativeaura</a></td> +<td><a href="mailto:gaurav@jassal.me">gaurav@jassal.me</a></td> +<td><a href="http://gaurav.jassal.me">http://gaurav.jassal.me</a></td> +<td>1</td> +</tr> +<tr> +<td>guli</td> +<td><a href="https://github.com/guli">guli</a></td> +<td></td> +<td></td> +<td>1</td> +</tr> +<tr> +<td>jwheadon</td> +<td><a href="https://github.com/jwheadon">jwheadon</a></td> +<td></td> +<td></td> +<td>1</td> +</tr> + +</table> + +Update date: 2014-06-13 @@ -6,90 +6,11 @@ To get started checkout examples and documentation at http://wenzhixin.net.cn/p/ ## Contributors -Multiple select is due to the excellent work of the following contributors: - -<table> -<tbody> -<tr><th align="left">文翼</th><td><a href="https://github.com/wenzhixin">GitHub/wenzhixin</a></td></tr> -<tr><th align="left">Gaurav Jassal</th><td><a href="https://github.com/creativeaura">GitHub/creativeaura</a></td><</tr> -<tr><th align="left">guli</th><td><a href="https://github.com/guli">GitHub/guli</a></td></tr> -<tr><th align="left">jwheadon</th><td><a href="https://github.com/jwheadon">GitHub/jwheadon</a></td></tr> -<tr><th align="left">yx</th><td><a href="https://github.com/qqfish">GitHub/qqfish</a></td></tr> -<tr><th align="left">Tobias Macey</th><td><a href="https://github.com/blarghmatey">GitHub/blarghmatey</a></td></tr> -<tr><th align="left">Jona Goldman</th><td><a href="https://github.com/jonagoldman">GitHub/jonagoldman</a></td></tr> -<tr><th align="left">Alex Jeffrey</th><td><a href="https://github.com/ajeffrey">GitHub/ajeffrey</a></td></tr> -</tbody> -</table> +[CONTRIBUTORS](https://github.com/wenzhixin/multiple-select/blob/master/CONTRIBUTORS.md) ## Changelog -### 1.1.0 - -* Fix #63: Add ```keepOpen``` option. -* Fix #62: Fix ```isOpen``` and ```filter``` options are both true bug. -* Fix #57: Fire onCheckAll event when literally select. -* Add data attributes for support. -* Fix #55: Add ```name``` option. - -### 1.0.9 - -* Fix #42: Add ```styler``` option to custom item style. -* Fix firefox click bug. -* Add ```allSelected```, ```minumimCountSelected``` and ```countSelected``` options. -* Fix #35: Add ```onFocus``` and ```onBlur``` events. -* Fix #25: Add ```focus``` and ```blur``` methods. -* Fix #31: Trigger the onCheckAll & onUncheckAll events when use filter to select all. - -### 1.0.8 - -* Update the license to The MIT License. -* Fix #47: Add ```No matches found``` message when there are no results found. -* Fix #43: Add ```position``` option. - -### 1.0.7 - -* Fix #44: The filters not working bugs. - -### 1.0.6 - -* Fix #21: Add ```single``` option. -* Add ```override``` option. -* Add ```container``` option. -* Fix #29: Update the optgroups select text. -* Fix #30: Image is not shown in Firefox 25.0.1. -* Fix #22: fix group filter problem. - -### 1.0.5 - -* Update the button text witdh. -* Add keyboard support. - -### 1.0.4 - -* Fix #12: Add ```width``` option. -* Fix #11: Add callback events. -* Add ```maxHeight``` option. - -### 1.0.3 - -* Fix #4: Add ```filter``` option. -* Support mobile devices. -* Fix #6: Add ```refresh``` method. - -### 1.0.2 - -* Fix #7: Add ```selected``` and ```disabled``` options. -* Fix #5: Add ```checkAll``` and ```uncheckAll``` methods. - -### 1.0.1 - -* Fix #3: Add optgroups support. -* Add ```placeholder``` option. -* Fix #2: use prop method instead of attr. - -### 1.0.0 - -* Initial release +[CHANGELOG](https://github.com/wenzhixin/multiple-select/blob/master/CHANGELOG.md) ## LICENSE diff --git a/jquery.multiple.select.js b/jquery.multiple.select.js index bc20706..f8a1efe 100644 --- a/jquery.multiple.select.js +++ b/jquery.multiple.select.js @@ -16,8 +16,11 @@ this.$el = $el.hide(); this.options = options; - - this.$parent = $('<div class="ms-parent"></div>'); + 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>'); @@ -65,7 +68,7 @@ html.push('<ul>'); if (this.options.selectAll && !this.options.single) { html.push( - '<li>', + '<li class="ms-select-all">', '<label>', '<input type="checkbox" ' + this.selectAllName + ' /> ', '[' + this.options.selectAllText + ']', @@ -102,6 +105,14 @@ $elm = $(elm), html = [], 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(''), disabled, type = this.options.single ? 'radio' : 'checkbox'; @@ -114,7 +125,7 @@ disabled = groupDisabled || $elm.prop('disabled'); if ((this.options.blockSeparator>"") && (this.options.blockSeparator==$elm.val())) { html.push( - '<li' + (multiple ? ' class="multiple"' : '') + style + '>', + '<li' + clss + style + '>', '<label class="' + this.options.blockSeparator + (disabled ? 'disabled' : '') + '">', text, '</label>', @@ -122,7 +133,7 @@ ); } else { html.push( - '<li' + (multiple ? ' class="multiple"' : '') + style + '>', + '<li' + clss + style + '>', '<label' + (disabled ? ' class="disabled"' : '') + '>', '<input type="' + type + '" ' + this.selectItemName + ' value="' + value + '"' + (selected ? ' checked="checked"' : '') + @@ -142,8 +153,8 @@ html.push( '<li class="group">', '<label class="optgroup' + (disabled ? ' disabled' : '') + '" data-group="' + _group + '">', - '<input type="checkbox" ' + this.selectGroupName + - (disabled ? ' disabled="disabled"' : '') + ' /> ', + (this.options.hideOptgroupCheckboxes ? '' : '<input type="checkbox" ' + this.selectGroupName + + (disabled ? ' disabled="disabled"' : '') + ' /> '), label, '</label>', '</li>'); @@ -156,10 +167,24 @@ events: function() { var that = this; - this.$choice.off('click').on('click', function(e) { + 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') + ']')[0]; + if (label) { + $(label).off('click').on('click', function (e) { + if (e.target.nodeName.toLowerCase() !== 'label' || e.target !== this) { + return; + } + toggleOpen(e); + if (!that.options.filter || !that.options.isOpen) { + that.focus(); + } + 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); @@ -281,15 +306,20 @@ if (selects.length === 0) { $span.addClass('placeholder').html(this.options.placeholder); } else if (this.options.countSelected && selects.length < this.options.minumimCountSelected) { - $span.removeClass('placeholder').html(this.getSelects('text').join(', ')); - } else if (this.options.allSelected && selects.length === this.$selectItems.length + this.$disableItems.length) { + $span.removeClass('placeholder').html( + (this.options.displayValues ? selects : this.getSelects('text')) + .join(this.options.delimiter)); + } else if (this.options.allSelected && + selects.length === this.$selectItems.length + this.$disableItems.length) { $span.removeClass('placeholder').html(this.options.allSelected); } else if (this.options.countSelected && selects.length > this.options.minumimCountSelected) { $span.removeClass('placeholder').html(this.options.countSelected .replace('#', selects.length) .replace('%', this.$selectItems.length + this.$disableItems.length)); } else { - $span.removeClass('placeholder').html(this.getSelects('text').join(', ')); + $span.removeClass('placeholder').html( + (this.options.displayValues ? selects : this.getSelects('text')) + .join(this.options.delimiter)); } // set selects to select this.$el.val(this.getSelects()); @@ -501,6 +531,8 @@ position: 'bottom', keepOpen: false, blockSeparator: '', + displayValues: false, + delimiter: ', ', styler: function() {return false;}, |