diff options
author | zhixin <wenzhixin2010@gmail.com> | 2014-07-13 22:29:10 +0800 |
---|---|---|
committer | zhixin <wenzhixin2010@gmail.com> | 2014-07-13 22:29:10 +0800 |
commit | 1e19de75c83d8f2142613171ef110dbe76d1398c (patch) | |
tree | 0393aeff9c9510ef281772299afc99ee52230a83 | |
parent | c2e788fe99000bac33c8dcd4538a34640028876a (diff) | |
download | multiple-select-1e19de75c83d8f2142613171ef110dbe76d1398c.zip multiple-select-1e19de75c83d8f2142613171ef110dbe76d1398c.tar.gz multiple-select-1e19de75c83d8f2142613171ef110dbe76d1398c.tar.bz2 |
Format code and update contributors.
-rw-r--r-- | CONTRIBUTORS.md | 71 | ||||
-rw-r--r-- | jquery.multiple.select.js | 156 |
2 files changed, 127 insertions, 100 deletions
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index fc32492..1a95f34 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,6 @@ ## Contributors -Multiple select is due to the excellent work of the following contributors: +multiple-select is due to the excellent work of the following contributors: <table> <tr> @@ -16,7 +16,7 @@ Multiple select is due to the excellent work of the following contributors: <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>126</td> +<td>127</td> <tr> <tr> <td><img src="https://avatars.githubusercontent.com/u/20234?" width="32" height="32"> Brett Zamir</td> @@ -26,16 +26,23 @@ Multiple select is due to the excellent work of the following contributors: <td>11</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><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/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><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> @@ -47,41 +54,34 @@ Multiple select is due to the excellent work of the following contributors: <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><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/7594976?" width="32" height="32"> topas08</td> -<td><a href="https://github.com/topas08">topas08</a></td> +<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/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><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/1628706?" width="32" height="32"> Alex Jeffrey</td> -<td><a href="https://github.com/ajeffrey">ajeffrey</a></td> +<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/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/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> @@ -89,9 +89,16 @@ Multiple select is due to the excellent work of the following contributors: <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><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> @@ -99,12 +106,12 @@ Multiple select is due to the excellent work of the following contributors: <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.im/">http://xavier.im/</a></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/2769778?" width="32" height="32"> jwheadon</td> -<td><a href="https://github.com/jwheadon">jwheadon</a></td> +<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> @@ -112,4 +119,4 @@ Multiple select is due to the excellent work of the following contributors: </table> -Update date: 2014-07-03, created width https://github.com/wenzhixin/github-contributors +Update date: 2014-07-13, created with https://github.com/wenzhixin/github-contributors
\ No newline at end of file diff --git a/jquery.multiple.select.js b/jquery.multiple.select.js index bd10f38..de87c65 100644 --- a/jquery.multiple.select.js +++ b/jquery.multiple.select.js @@ -1,7 +1,7 @@ /** * @author zhixin wen <wenzhixin2010@gmail.com> * @version 1.1.0 - * + * * http://wenzhixin.net.cn/p/multiple-select/ */ @@ -16,7 +16,7 @@ this.$el = $el.hide(); this.options = options; - this.$parent = $('<div' + $.map(['class', 'title'], function (att) { + 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 + '"') : ''; @@ -61,7 +61,7 @@ if (this.options.filter) { html.push( '<div class="ms-search">', - '<input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false">', + '<input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false">', '</div>' ); } @@ -69,10 +69,10 @@ if (this.options.selectAll && !this.options.single) { html.push( '<li class="ms-select-all">', - '<label>', - '<input type="checkbox" ' + this.selectAllName + ' /> ', - this.options.selectAllDelimiter[0] + this.options.selectAllText + this.options.selectAllDelimiter[1], - '</label>', + '<label>', + '<input type="checkbox" ' + this.selectAllName + ' /> ', + this.options.selectAllDelimiter[0] + this.options.selectAllText + this.options.selectAllDelimiter[1], + '</label>', '</li>' ); } @@ -125,24 +125,24 @@ disabled = groupDisabled || $elm.prop('disabled'); if ((this.options.blockSeparator > "") && (this.options.blockSeparator == $elm.val())) { html.push( - '<li' + clss + style + '>', - '<label class="' + this.options.blockSeparator + (disabled ? 'disabled' : '') + '">', - text, - '</label>', - '</li>' + '<li' + clss + style + '>', + '<label class="' + this.options.blockSeparator + (disabled ? 'disabled' : '') + '">', + text, + '</label>', + '</li>' ); } else { html.push( - '<li' + clss + style + '>', - '<label' + (disabled ? ' class="disabled"' : '') + '>', - '<input type="' + type + '" ' + this.selectItemName + ' value="' + value + '"' + - (selected ? ' checked="checked"' : '') + - (disabled ? ' disabled="disabled"' : '') + - (group ? ' data-group="' + group + '"' : '') + - '/> ', - text, - '</label>', - '</li>' + '<li' + clss + style + '>', + '<label' + (disabled ? ' class="disabled"' : '') + '>', + '<input type="' + type + '" ' + this.selectItemName + ' value="' + value + '"' + + (selected ? ' checked="checked"' : '') + + (disabled ? ' disabled="disabled"' : '') + + (group ? ' data-group="' + group + '"' : '') + + '/> ', + text, + '</label>', + '</li>' ); } } else if (!group && $elm.is('optgroup')) { @@ -152,11 +152,11 @@ disabled = $elm.prop('disabled'); html.push( '<li class="group">', - '<label class="optgroup' + (disabled ? ' disabled' : '') + '" data-group="' + _group + '">', - (this.options.hideOptgroupCheckboxes ? '' : '<input type="checkbox" ' + this.selectGroupName + - (disabled ? ' disabled="disabled"' : '') + ' /> '), - label, - '</label>', + '<label class="optgroup' + (disabled ? ' disabled' : '') + '" data-group="' + _group + '">', + (this.options.hideOptgroupCheckboxes ? '' : '<input type="checkbox" ' + this.selectGroupName + + (disabled ? ' disabled="disabled"' : '') + ' /> '), + label, + '</label>', '</li>'); $.each($elm.children(), function (i, elm) { html.push(that.optionToHtml(i, elm, _group, disabled)); @@ -167,10 +167,12 @@ 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') + ']')[0]; if (label) { $(label).off('click').on('click', function (e) { @@ -196,22 +198,22 @@ break; } }); - this.$searchInput.off('keydown').on('keydown', function (e) { + 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 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(); - }); + 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(); + }); this.$selectAll.off('click').on('click', function () { var checked = $(this).prop('checked'), $items = that.$selectItems.filter(':visible'); @@ -308,32 +310,30 @@ } else if (this.options.countSelected && selects.length < this.options.minumimCountSelected) { $span.removeClass('placeholder').html( (this.options.displayValues ? selects : this.getSelects('text')) - .join(this.options.delimiter)); + .join(this.options.delimiter)); } else if (this.options.allSelected && - selects.length === this.$selectItems.length + this.$disableItems.length) { + selects.length === 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.minumimCountSelected) { - if(this.options.etcaetera) - { - $span.removeClass('placeholder').html((this.options.displayValues ? selects : this.getSelects('text').slice(0, this.options.minumimCountSelected)).join(this.options.delimiter)+'...'); - } - else - { - $span.removeClass('placeholder').html(this.options.countSelected - .replace('#', selects.length) - .replace('%', this.$selectItems.length + this.$disableItems.length)); - } + if (this.options.etcaetera) { + $span.removeClass('placeholder').html((this.options.displayValues ? selects : this.getSelects('text').slice(0, this.options.minumimCountSelected)).join(this.options.delimiter) + '...'); + } + else { + $span.removeClass('placeholder').html(this.options.countSelected + .replace('#', selects.length) + .replace('%', this.$selectItems.length + this.$disableItems.length)); + } } else { $span.removeClass('placeholder').html( (this.options.displayValues ? selects : this.getSelects('text')) - .join(this.options.delimiter)); + .join(this.options.delimiter)); } // 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 () { + + // add selected class to selected li + this.$drop.find('li').removeClass('selected'); + this.$drop.find('input[' + this.selectItemName + ']:checked').each(function () { $(this).parents('li').first().addClass('selected'); }); @@ -530,7 +530,7 @@ placeholder: '', selectAll: true, selectAllText: 'Select all', - selectAllDelimiter: ['[',']'], + selectAllDelimiter: ['[', ']'], allSelected: 'All selected', minumimCountSelected: 3, countSelected: '# of % selected', @@ -548,16 +548,36 @@ displayValues: false, delimiter: ', ', - styler: function () { return false; }, - textTemplate: function ($elm) { return $elm.text(); }, - - onOpen: function () { return false; }, - onClose: function () { return false; }, - onCheckAll: function () { return false; }, - onUncheckAll: function () { return false; }, - onFocus: function () { return false; }, - onBlur: function () { return false; }, - onOptgroupClick: function () { return false; }, - onClick: function () { return false; } + styler: function () { + return false; + }, + textTemplate: function ($elm) { + return $elm.text(); + }, + + onOpen: function () { + return false; + }, + onClose: function () { + return false; + }, + onCheckAll: function () { + return false; + }, + onUncheckAll: function () { + return false; + }, + onFocus: function () { + return false; + }, + onBlur: function () { + return false; + }, + onOptgroupClick: function () { + return false; + }, + onClick: function () { + return false; + } }; })(jQuery); |