{"version":3,"file":"multiple-select-WdaWsAb9.js","sources":["../../../vendor/assets/pseudo_plugins/multiple-select.js"],"sourcesContent":["// we tailor make umd pattern for better support\n// http://wenzhixin.net.cn/p/multiple-select/\n(function(root, factory){\n\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(['jquery'], factory);\n } else if (typeof module === 'object' && module.exports) {\n // Node/CommonJS\n var jQuery = require('jquery');\n module.exports = factory(jQuery);\n\n }else{\n // Browser globals\n factory(root.jQuery);\n }\n}(this, function(jQuery){\n\n\n /**\n * Original author: zhixin wen \n * Original project page: http://wenzhixin.net.cn/p/multiple-select/\n * Forked at version: 1.2.1\n *\n * This is a fork of the original project for our particular use case.\n * NOT ALL OPTIONS OF THE ORIGINAL LIBRARY WORK UNDER THIS VERSION.\n * Especially the select-all functionality.\n *\n * I added most notably the pickoutSelected option, which is supposed\n * to be used together with multiple: true, filter: true, selectAll: false,\n * multipleSelectFilteredOnly: false. Other combinations is not guaranteed\n * to be working, as of today.\n *\n * 01 Jun, 2016.\n *\n * Haochi Kiang \n */\n\n (function ($) {\n\n 'use strict';\n\n var mprint = function (obj) {\n console.log(obj);\n return obj;\n }\n\n // it only does '%s', and return '' when arguments are undefined\n var sprintf = function (str) {\n var args = arguments,\n flag = true,\n i = 1;\n\n str = str.replace(/%s/g, function () {\n var arg = args[i++];\n\n if (typeof arg === 'undefined') {\n flag = false;\n return '';\n }\n return arg;\n });\n return flag ? str : '';\n };\n\n var removeDiacritics = function (str) {\n var defaultDiacriticsRemovalMap = [\n {'base':'A', 'letters':/[\\u0041\\u24B6\\uFF21\\u00C0\\u00C1\\u00C2\\u1EA6\\u1EA4\\u1EAA\\u1EA8\\u00C3\\u0100\\u0102\\u1EB0\\u1EAE\\u1EB4\\u1EB2\\u0226\\u01E0\\u00C4\\u01DE\\u1EA2\\u00C5\\u01FA\\u01CD\\u0200\\u0202\\u1EA0\\u1EAC\\u1EB6\\u1E00\\u0104\\u023A\\u2C6F]/g},\n {'base':'AA','letters':/[\\uA732]/g},\n {'base':'AE','letters':/[\\u00C6\\u01FC\\u01E2]/g},\n {'base':'AO','letters':/[\\uA734]/g},\n {'base':'AU','letters':/[\\uA736]/g},\n {'base':'AV','letters':/[\\uA738\\uA73A]/g},\n {'base':'AY','letters':/[\\uA73C]/g},\n {'base':'B', 'letters':/[\\u0042\\u24B7\\uFF22\\u1E02\\u1E04\\u1E06\\u0243\\u0182\\u0181]/g},\n {'base':'C', 'letters':/[\\u0043\\u24B8\\uFF23\\u0106\\u0108\\u010A\\u010C\\u00C7\\u1E08\\u0187\\u023B\\uA73E]/g},\n {'base':'D', 'letters':/[\\u0044\\u24B9\\uFF24\\u1E0A\\u010E\\u1E0C\\u1E10\\u1E12\\u1E0E\\u0110\\u018B\\u018A\\u0189\\uA779]/g},\n {'base':'DZ','letters':/[\\u01F1\\u01C4]/g},\n {'base':'Dz','letters':/[\\u01F2\\u01C5]/g},\n {'base':'E', 'letters':/[\\u0045\\u24BA\\uFF25\\u00C8\\u00C9\\u00CA\\u1EC0\\u1EBE\\u1EC4\\u1EC2\\u1EBC\\u0112\\u1E14\\u1E16\\u0114\\u0116\\u00CB\\u1EBA\\u011A\\u0204\\u0206\\u1EB8\\u1EC6\\u0228\\u1E1C\\u0118\\u1E18\\u1E1A\\u0190\\u018E]/g},\n {'base':'F', 'letters':/[\\u0046\\u24BB\\uFF26\\u1E1E\\u0191\\uA77B]/g},\n {'base':'G', 'letters':/[\\u0047\\u24BC\\uFF27\\u01F4\\u011C\\u1E20\\u011E\\u0120\\u01E6\\u0122\\u01E4\\u0193\\uA7A0\\uA77D\\uA77E]/g},\n {'base':'H', 'letters':/[\\u0048\\u24BD\\uFF28\\u0124\\u1E22\\u1E26\\u021E\\u1E24\\u1E28\\u1E2A\\u0126\\u2C67\\u2C75\\uA78D]/g},\n {'base':'I', 'letters':/[\\u0049\\u24BE\\uFF29\\u00CC\\u00CD\\u00CE\\u0128\\u012A\\u012C\\u0130\\u00CF\\u1E2E\\u1EC8\\u01CF\\u0208\\u020A\\u1ECA\\u012E\\u1E2C\\u0197]/g},\n {'base':'J', 'letters':/[\\u004A\\u24BF\\uFF2A\\u0134\\u0248]/g},\n {'base':'K', 'letters':/[\\u004B\\u24C0\\uFF2B\\u1E30\\u01E8\\u1E32\\u0136\\u1E34\\u0198\\u2C69\\uA740\\uA742\\uA744\\uA7A2]/g},\n {'base':'L', 'letters':/[\\u004C\\u24C1\\uFF2C\\u013F\\u0139\\u013D\\u1E36\\u1E38\\u013B\\u1E3C\\u1E3A\\u0141\\u023D\\u2C62\\u2C60\\uA748\\uA746\\uA780]/g},\n {'base':'LJ','letters':/[\\u01C7]/g},\n {'base':'Lj','letters':/[\\u01C8]/g},\n {'base':'M', 'letters':/[\\u004D\\u24C2\\uFF2D\\u1E3E\\u1E40\\u1E42\\u2C6E\\u019C]/g},\n {'base':'N', 'letters':/[\\u004E\\u24C3\\uFF2E\\u01F8\\u0143\\u00D1\\u1E44\\u0147\\u1E46\\u0145\\u1E4A\\u1E48\\u0220\\u019D\\uA790\\uA7A4]/g},\n {'base':'NJ','letters':/[\\u01CA]/g},\n {'base':'Nj','letters':/[\\u01CB]/g},\n {'base':'O', 'letters':/[\\u004F\\u24C4\\uFF2F\\u00D2\\u00D3\\u00D4\\u1ED2\\u1ED0\\u1ED6\\u1ED4\\u00D5\\u1E4C\\u022C\\u1E4E\\u014C\\u1E50\\u1E52\\u014E\\u022E\\u0230\\u00D6\\u022A\\u1ECE\\u0150\\u01D1\\u020C\\u020E\\u01A0\\u1EDC\\u1EDA\\u1EE0\\u1EDE\\u1EE2\\u1ECC\\u1ED8\\u01EA\\u01EC\\u00D8\\u01FE\\u0186\\u019F\\uA74A\\uA74C]/g},\n {'base':'OI','letters':/[\\u01A2]/g},\n {'base':'OO','letters':/[\\uA74E]/g},\n {'base':'OU','letters':/[\\u0222]/g},\n {'base':'P', 'letters':/[\\u0050\\u24C5\\uFF30\\u1E54\\u1E56\\u01A4\\u2C63\\uA750\\uA752\\uA754]/g},\n {'base':'Q', 'letters':/[\\u0051\\u24C6\\uFF31\\uA756\\uA758\\u024A]/g},\n {'base':'R', 'letters':/[\\u0052\\u24C7\\uFF32\\u0154\\u1E58\\u0158\\u0210\\u0212\\u1E5A\\u1E5C\\u0156\\u1E5E\\u024C\\u2C64\\uA75A\\uA7A6\\uA782]/g},\n {'base':'S', 'letters':/[\\u0053\\u24C8\\uFF33\\u1E9E\\u015A\\u1E64\\u015C\\u1E60\\u0160\\u1E66\\u1E62\\u1E68\\u0218\\u015E\\u2C7E\\uA7A8\\uA784]/g},\n {'base':'T', 'letters':/[\\u0054\\u24C9\\uFF34\\u1E6A\\u0164\\u1E6C\\u021A\\u0162\\u1E70\\u1E6E\\u0166\\u01AC\\u01AE\\u023E\\uA786]/g},\n {'base':'TZ','letters':/[\\uA728]/g},\n {'base':'U', 'letters':/[\\u0055\\u24CA\\uFF35\\u00D9\\u00DA\\u00DB\\u0168\\u1E78\\u016A\\u1E7A\\u016C\\u00DC\\u01DB\\u01D7\\u01D5\\u01D9\\u1EE6\\u016E\\u0170\\u01D3\\u0214\\u0216\\u01AF\\u1EEA\\u1EE8\\u1EEE\\u1EEC\\u1EF0\\u1EE4\\u1E72\\u0172\\u1E76\\u1E74\\u0244]/g},\n {'base':'V', 'letters':/[\\u0056\\u24CB\\uFF36\\u1E7C\\u1E7E\\u01B2\\uA75E\\u0245]/g},\n {'base':'VY','letters':/[\\uA760]/g},\n {'base':'W', 'letters':/[\\u0057\\u24CC\\uFF37\\u1E80\\u1E82\\u0174\\u1E86\\u1E84\\u1E88\\u2C72]/g},\n {'base':'X', 'letters':/[\\u0058\\u24CD\\uFF38\\u1E8A\\u1E8C]/g},\n {'base':'Y', 'letters':/[\\u0059\\u24CE\\uFF39\\u1EF2\\u00DD\\u0176\\u1EF8\\u0232\\u1E8E\\u0178\\u1EF6\\u1EF4\\u01B3\\u024E\\u1EFE]/g},\n {'base':'Z', 'letters':/[\\u005A\\u24CF\\uFF3A\\u0179\\u1E90\\u017B\\u017D\\u1E92\\u1E94\\u01B5\\u0224\\u2C7F\\u2C6B\\uA762]/g},\n {'base':'a', 'letters':/[\\u0061\\u24D0\\uFF41\\u1E9A\\u00E0\\u00E1\\u00E2\\u1EA7\\u1EA5\\u1EAB\\u1EA9\\u00E3\\u0101\\u0103\\u1EB1\\u1EAF\\u1EB5\\u1EB3\\u0227\\u01E1\\u00E4\\u01DF\\u1EA3\\u00E5\\u01FB\\u01CE\\u0201\\u0203\\u1EA1\\u1EAD\\u1EB7\\u1E01\\u0105\\u2C65\\u0250]/g},\n {'base':'aa','letters':/[\\uA733]/g},\n {'base':'ae','letters':/[\\u00E6\\u01FD\\u01E3]/g},\n {'base':'ao','letters':/[\\uA735]/g},\n {'base':'au','letters':/[\\uA737]/g},\n {'base':'av','letters':/[\\uA739\\uA73B]/g},\n {'base':'ay','letters':/[\\uA73D]/g},\n {'base':'b', 'letters':/[\\u0062\\u24D1\\uFF42\\u1E03\\u1E05\\u1E07\\u0180\\u0183\\u0253]/g},\n {'base':'c', 'letters':/[\\u0063\\u24D2\\uFF43\\u0107\\u0109\\u010B\\u010D\\u00E7\\u1E09\\u0188\\u023C\\uA73F\\u2184]/g},\n {'base':'d', 'letters':/[\\u0064\\u24D3\\uFF44\\u1E0B\\u010F\\u1E0D\\u1E11\\u1E13\\u1E0F\\u0111\\u018C\\u0256\\u0257\\uA77A]/g},\n {'base':'dz','letters':/[\\u01F3\\u01C6]/g},\n {'base':'e', 'letters':/[\\u0065\\u24D4\\uFF45\\u00E8\\u00E9\\u00EA\\u1EC1\\u1EBF\\u1EC5\\u1EC3\\u1EBD\\u0113\\u1E15\\u1E17\\u0115\\u0117\\u00EB\\u1EBB\\u011B\\u0205\\u0207\\u1EB9\\u1EC7\\u0229\\u1E1D\\u0119\\u1E19\\u1E1B\\u0247\\u025B\\u01DD]/g},\n {'base':'f', 'letters':/[\\u0066\\u24D5\\uFF46\\u1E1F\\u0192\\uA77C]/g},\n {'base':'g', 'letters':/[\\u0067\\u24D6\\uFF47\\u01F5\\u011D\\u1E21\\u011F\\u0121\\u01E7\\u0123\\u01E5\\u0260\\uA7A1\\u1D79\\uA77F]/g},\n {'base':'h', 'letters':/[\\u0068\\u24D7\\uFF48\\u0125\\u1E23\\u1E27\\u021F\\u1E25\\u1E29\\u1E2B\\u1E96\\u0127\\u2C68\\u2C76\\u0265]/g},\n {'base':'hv','letters':/[\\u0195]/g},\n {'base':'i', 'letters':/[\\u0069\\u24D8\\uFF49\\u00EC\\u00ED\\u00EE\\u0129\\u012B\\u012D\\u00EF\\u1E2F\\u1EC9\\u01D0\\u0209\\u020B\\u1ECB\\u012F\\u1E2D\\u0268\\u0131]/g},\n {'base':'j', 'letters':/[\\u006A\\u24D9\\uFF4A\\u0135\\u01F0\\u0249]/g},\n {'base':'k', 'letters':/[\\u006B\\u24DA\\uFF4B\\u1E31\\u01E9\\u1E33\\u0137\\u1E35\\u0199\\u2C6A\\uA741\\uA743\\uA745\\uA7A3]/g},\n {'base':'l', 'letters':/[\\u006C\\u24DB\\uFF4C\\u0140\\u013A\\u013E\\u1E37\\u1E39\\u013C\\u1E3D\\u1E3B\\u017F\\u0142\\u019A\\u026B\\u2C61\\uA749\\uA781\\uA747]/g},\n {'base':'lj','letters':/[\\u01C9]/g},\n {'base':'m', 'letters':/[\\u006D\\u24DC\\uFF4D\\u1E3F\\u1E41\\u1E43\\u0271\\u026F]/g},\n {'base':'n', 'letters':/[\\u006E\\u24DD\\uFF4E\\u01F9\\u0144\\u00F1\\u1E45\\u0148\\u1E47\\u0146\\u1E4B\\u1E49\\u019E\\u0272\\u0149\\uA791\\uA7A5]/g},\n {'base':'nj','letters':/[\\u01CC]/g},\n {'base':'o', 'letters':/[\\u006F\\u24DE\\uFF4F\\u00F2\\u00F3\\u00F4\\u1ED3\\u1ED1\\u1ED7\\u1ED5\\u00F5\\u1E4D\\u022D\\u1E4F\\u014D\\u1E51\\u1E53\\u014F\\u022F\\u0231\\u00F6\\u022B\\u1ECF\\u0151\\u01D2\\u020D\\u020F\\u01A1\\u1EDD\\u1EDB\\u1EE1\\u1EDF\\u1EE3\\u1ECD\\u1ED9\\u01EB\\u01ED\\u00F8\\u01FF\\u0254\\uA74B\\uA74D\\u0275]/g},\n {'base':'oi','letters':/[\\u01A3]/g},\n {'base':'ou','letters':/[\\u0223]/g},\n {'base':'oo','letters':/[\\uA74F]/g},\n {'base':'p','letters':/[\\u0070\\u24DF\\uFF50\\u1E55\\u1E57\\u01A5\\u1D7D\\uA751\\uA753\\uA755]/g},\n {'base':'q','letters':/[\\u0071\\u24E0\\uFF51\\u024B\\uA757\\uA759]/g},\n {'base':'r','letters':/[\\u0072\\u24E1\\uFF52\\u0155\\u1E59\\u0159\\u0211\\u0213\\u1E5B\\u1E5D\\u0157\\u1E5F\\u024D\\u027D\\uA75B\\uA7A7\\uA783]/g},\n {'base':'s','letters':/[\\u0073\\u24E2\\uFF53\\u00DF\\u015B\\u1E65\\u015D\\u1E61\\u0161\\u1E67\\u1E63\\u1E69\\u0219\\u015F\\u023F\\uA7A9\\uA785\\u1E9B]/g},\n {'base':'t','letters':/[\\u0074\\u24E3\\uFF54\\u1E6B\\u1E97\\u0165\\u1E6D\\u021B\\u0163\\u1E71\\u1E6F\\u0167\\u01AD\\u0288\\u2C66\\uA787]/g},\n {'base':'tz','letters':/[\\uA729]/g},\n {'base':'u','letters':/[\\u0075\\u24E4\\uFF55\\u00F9\\u00FA\\u00FB\\u0169\\u1E79\\u016B\\u1E7B\\u016D\\u00FC\\u01DC\\u01D8\\u01D6\\u01DA\\u1EE7\\u016F\\u0171\\u01D4\\u0215\\u0217\\u01B0\\u1EEB\\u1EE9\\u1EEF\\u1EED\\u1EF1\\u1EE5\\u1E73\\u0173\\u1E77\\u1E75\\u0289]/g},\n {'base':'v','letters':/[\\u0076\\u24E5\\uFF56\\u1E7D\\u1E7F\\u028B\\uA75F\\u028C]/g},\n {'base':'vy','letters':/[\\uA761]/g},\n {'base':'w','letters':/[\\u0077\\u24E6\\uFF57\\u1E81\\u1E83\\u0175\\u1E87\\u1E85\\u1E98\\u1E89\\u2C73]/g},\n {'base':'x','letters':/[\\u0078\\u24E7\\uFF58\\u1E8B\\u1E8D]/g},\n {'base':'y','letters':/[\\u0079\\u24E8\\uFF59\\u1EF3\\u00FD\\u0177\\u1EF9\\u0233\\u1E8F\\u00FF\\u1EF7\\u1E99\\u1EF5\\u01B4\\u024F\\u1EFF]/g},\n {'base':'z','letters':/[\\u007A\\u24E9\\uFF5A\\u017A\\u1E91\\u017C\\u017E\\u1E93\\u1E95\\u01B6\\u0225\\u0240\\u2C6C\\uA763]/g}\n ];\n\n for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {\n str = str.replace(defaultDiacriticsRemovalMap[i].letters, defaultDiacriticsRemovalMap[i].base);\n }\n\n return str;\n\n };\n\n function MultipleSelect($el, options) {\n var that = this,\n name = $el.attr('name') || options.name || '';\n\n this.options = options;\n\n // hide select element\n this.$el = $el.hide();\n\n // label element\n this.$label = this.$el.closest('label');\n if (this.$label.length === 0 && this.$el.attr('id')) {\n this.$label = $(sprintf('label[for=\"%s\"]', this.$el.attr('id').replace(/:/g, '\\\\:')));\n }\n\n // restore class and title from select element\n this.$parent = $(sprintf(\n '
',\n $el.attr('class') || '',\n sprintf('title=\"%s\"', $el.attr('title'))));\n\n // add placeholder to choice button\n this.$choice = $(sprintf([\n ''\n ].join(''),\n this.options.placeholder));\n if (this.options.hasPNGArrow) {\n this.$choice.addClass('ms-has-png-arrow');\n }\n\n // default position is bottom\n this.$drop = $(sprintf('
',\n this.options.position,\n sprintf(' style=\"width: %s\"', this.options.dropWidth)));\n\n this.$el.after(this.$parent);\n this.$parent.append(this.$choice);\n this.$parent.append(this.$drop);\n\n if (this.$el.prop('disabled')) {\n this.$choice.addClass('disabled');\n }\n this.$parent.css('width',\n this.options.width ||\n this.$el.css('width') ||\n (this.$el.outerWidth() || 0) + 20);\n\n this.selectAllName = 'data-name=\"selectAll' + name + '\"';\n this.selectGroupName = 'data-name=\"selectGroup' + name + '\"';\n this.selectItemName = 'data-name=\"selectItem' + name + '\"';\n\n if (!this.options.keepOpen) {\n $(document).on(\"click\", function (e) {\n if ($(e.target)[0] === that.$choice[0] ||\n $(e.target).parents('.ms-choice')[0] === that.$choice[0]) {\n return;\n }\n if (($(e.target)[0] === that.$drop[0] ||\n $(e.target).parents('.ms-drop')[0] !== that.$drop[0] && e.target !== $el[0]) &&\n that.options.isOpen &&\n ! e.isTrigger) {\n that.close();\n }\n });\n }\n }\n\n MultipleSelect.prototype = {\n constructor: MultipleSelect,\n\n init: function () {\n var that = this,\n $ul = $('
    '),\n clear_all_div, clear_all_anchor;\n\n this.$drop.html('');\n\n if (this.options.filter) {\n this.$drop.append([\n '
    ',\n this.options.input_placeholder\n ? sprintf(\n '',\n this.options.input_placeholder )\n : '',\n '
    '].join('')\n );\n }\n\n if (this.options.selectAll && !this.options.single) {\n $ul.append([\n '
  • ',\n '',\n '
  • '\n ].join(''));\n }\n\n\n this.$drop.append('
    ');\n this.$selectedArea = this.$drop.find('.ms-selected');\n\n\n $.each(this.$el.children(), function (i, elm) {\n $ul.append(that.optionToHtml(i, elm));\n });\n $ul.append(sprintf('
  • %s
  • ', this.options.noMatchesFound));\n this.$drop.append($ul);\n\n if (this.options.clearAll && !this.options.single) {\n clear_all_div = document.createElement('div');\n clear_all_div.classList.add('ms-clear-all');\n\n clear_all_anchor = document.createElement('a');\n clear_all_anchor.href = 'javascript:void(0);';\n clear_all_anchor.textContent = this.options.clearAll;\n\n new MutationObserver( function(mutations) {\n that._hide_or_show_clear_all_link();\n }).observe( this.$selectedArea[0], {childList: true} );\n\n if (that.options.pickoutSelected) {\n clear_all_anchor.addEventListener( 'click', function (e) {\n that.$selectedArea.children('label').each( function () {\n this.dispatchEvent( new MouseEvent('click', {\n 'view': window,\n 'bubbles': true,\n 'cancelable': true\n }));\n });\n e.preventDefault();\n return false;\n });\n } else {\n // Do nothing\n }\n\n\n this.$clear_all_div = $(clear_all_div);\n\n clear_all_div.appendChild( clear_all_anchor );\n if (this.options.clearAllPosition === 'bottom')\n this.$clear_all_div.insertAfter($ul);\n else if (this.options.clearAllPosition === 'top')\n this.$clear_all_div.insertBefore(this.$selectedArea);\n else if (this.options.clearAllPosition === 'after_selected_area')\n this.$clear_all_div.insertAfter(this.$selectedArea);\n this._hide_or_show_clear_all_link();\n }\n\n this.$drop.css('max-height', this.options.maxHeight + (typeof this.options.maxHeight === 'number' ? 'px' : ''));\n if (this.options.height)\n this.$drop.css('height', this.options.height + (typeof this.options.height === 'number' ? 'px' : ''));\n\n this.$drop.find('.multiple label')\n .css('width',\n this.options.multipleWidth\n + (typeof this.options.multipleWidth === 'number' ? 'px' : ''));\n\n this.$searchInput = this.$drop.find('.ms-search input');\n this.$selectAll = this.$drop.find('input[' + this.selectAllName + ']');\n this.$selectGroups = this.$drop.find('input[' + this.selectGroupName + ']');\n this.$selectItems = this.$drop.find('input[' + this.selectItemName + ']:enabled');\n this.$disableItems = this.$drop.find('input[' + this.selectItemName + ']:disabled');\n this.$noResults = this.$drop.find('.ms-no-results');\n\n this.events();\n this.updateSelectAll(true);\n this.update(true);\n this.updateOptGroupSelect();\n\n if (this.options.pickoutSelected) {\n this.$selectItems.filter(':checked').each( function () {\n that._pickoutSelectedItems( this );\n });\n }\n\n if (this.options.isOpen) {\n this.open();\n }\n },\n\n optionToHtml: function (i, elm, group, groupDisabled) {\n var that = this,\n $elm = $(elm),\n classes = $elm.attr('class') || '',\n title = sprintf('title=\"%s\"', $elm.attr('title')),\n multiple = this.options.multiple ? 'multiple' : '',\n disabled,\n type = this.options.single ? 'radio' : 'checkbox';\n\n if ($elm.is('option')) {\n var value = $elm.val(),\n text = that.options.textTemplate($elm),\n selected = $elm.prop('selected'),\n style = sprintf('style=\"%s\"', this.options.styler(value)),\n $el;\n\n disabled = groupDisabled || $elm.prop('disabled');\n\n $el = $([\n sprintf('
  • ', multiple, classes, title, style),\n sprintf('',\n '
  • '\n ].join(''));\n $el.find('input').val(value);\n return $el;\n }\n if ($elm.is('optgroup')) {\n var label = that.options.labelTemplate($elm),\n $group = $('
    ');\n\n group = 'group_' + i;\n disabled = $elm.prop('disabled');\n\n $group.append([\n '
  • ',\n sprintf('',\n '
  • '\n ].join(''));\n\n $.each($elm.children(), function (i, elm) {\n $group.append(that.optionToHtml(i, elm, group, disabled));\n });\n return $group.html();\n }\n },\n\n events: function () {\n var that = this,\n toggleOpen = function (e) {\n e.preventDefault();\n that[that.options.isOpen ? 'close' : 'open']();\n };\n\n if (this.$label) {\n this.$label.off('click').on('click', function (e) {\n if (e.target.nodeName.toLowerCase() !== 'label' || e.target !== this) {\n return;\n }\n toggleOpen(e);\n if (!that.options.filter || !that.options.isOpen) {\n that.focus();\n }\n e.stopPropagation(); // Causes lost focus otherwise\n });\n }\n\n this.$choice.off('click').on('click', toggleOpen)\n .off('focus').on('focus', this.options.onFocus)\n .off('blur').on('blur', this.options.onBlur);\n\n this.$parent.off('keydown').on('keydown', function (e) {\n switch (e.which) {\n case 27: // esc key\n that.close();\n that.$choice.trigger(\"focus\");\n break;\n }\n });\n\n this.$searchInput.off('keydown').on('keydown',function (e) {\n // Ensure shift-tab causes lost focus from filter as with clicking away\n if (e.keyCode === 9 && e.shiftKey) {\n that.close();\n }\n }).off('keyup').on('keyup', function (e) {\n // enter or space\n // Avoid selecting/deselecting if no choices made\n if (that.options.filterAcceptOnEnter && (e.which === 13 || e.which == 32) && that.$searchInput.val()) {\n that.$selectAll.click();\n that.close();\n that.focus();\n return;\n }\n that.filter();\n });\n\n this.$selectAll.off('click').on('click', function () {\n var checked = $(this).prop('checked'),\n $items = that.$selectItems.filter(':visible');\n\n if ($items.length === that.$selectItems.length) {\n that[checked ? 'checkAll' : 'uncheckAll']();\n } else { // when the filter option is true\n that.$selectGroups.prop('checked', checked);\n $items.prop('checked', checked);\n that.options[checked ? 'onCheckAll' : 'onUncheckAll']();\n that.update();\n }\n });\n\n this.$selectGroups.off('click').on('click', function () {\n var group = $(this).parent().attr('data-group'),\n $items = that.options.multipleSelectFilteredOnly\n ? that.$selectItems.filter(':visible')\n : that.$selectItems,\n $children = $items.filter(sprintf('[data-group=\"%s\"]', group)),\n checked = $children.length !== $children.filter(':checked').length;\n\n $children.prop('checked', checked);\n that.updateSelectAll();\n that.update();\n\n if (that.options.pickoutSelected) {\n that._pickOutSelectedGroup($(this));\n }\n\n that.options.onOptgroupClick({\n label: $(this).parent().text(),\n checked: checked,\n children: $children.get(),\n instance: that\n });\n });\n\n this.$selectItems.off('click').on('click', function () {\n that.updateSelectAll();\n that.update();\n that.updateOptGroupSelect();\n that.options.onClick({\n label: $(this).parent().text(),\n value: $(this).val(),\n checked: $(this).prop('checked'),\n instance: that\n });\n\n if (that.options.pickoutSelected) {\n if (true) {//($.trim(that.$searchInput.val()).length == 0) {\n that._pickoutSelectedItems(this);\n } else {\n (function () { return })();\n }\n }\n\n if (that.options.single && that.options.isOpen && !that.options.keepOpen) {\n that.close();\n }\n\n if (that.options.single) {\n var clickedVal = $(this).val();\n that.$selectItems.filter(function() {\n return $(this).val() !== clickedVal;\n }).each(function() {\n $(this).prop('checked', false);\n });\n that.update();\n }\n });\n },\n\n _hide_or_show_clear_all_link: function () {\n if (this.$selectedArea.find('input').length === 0)\n this.$clear_all_div.hide();\n else\n this.$clear_all_div.show();\n },\n\n _pickoutSelectedItems: function (item_input) {\n var group_label = this.getGroupLabel( item_input.dataset.group ),\n group_elems = this.getGroupElems( item_input.dataset.group ),\n is_group_all_selected = this.isOptGroupAllSelected( group_label ),\n that = this;\n\n if (is_group_all_selected) {\n // Hide group label in the dropdown area\n $(group_label.parentElement).hide();\n\n // Remove all children at selected area and\n // insert the group instead\n this._pickOutSelectedGroup($(group_label.querySelector('input')));\n } else {\n this.$selectedArea\n .append( $(item_input)\n .parent()\n .clone()\n .off('click')\n .on('click', function (e) {\n var original_checkbox = that\n .getSelectElemByValue( item_input.value );\n\n // $(this.getGroupElem(item_input.querySelector('input').dataset.group)).show();\n $(\n original_checkbox\n .parentElement\n .parentElement\n ).show();\n original_checkbox.checked = false;\n this.parentElement.removeChild(this);\n that.update();\n return false;\n }));\n }\n },\n\n _pickOutSelectedGroup: function ($group_input) {\n var that = this,\n group = $group_input[0]\n .parentElement\n .dataset\n .group,\n $cloned;\n\n if ( this.$selectedArea.find(\n sprintf('label[data-group=\"%s\"] > input[%s]',\n group,\n this.selectGroupName )\n ).length === 0 ) {\n // Bring myself up to the selected area if checked\n this.$selectedArea\n .append( // Shouldn't be append, but let's have it now.\n $cloned = $group_input\n .parent()\n .clone()\n .off('click')\n .on('click', function (e) {\n // Re-show and uncheck all children\n that\n .getGroupElems( group )\n .forEach( function (e) {\n $(e.parentElement.parentElement).show();\n e.checked = false;\n });\n\n // Re-show the group label itself\n // TODO: replace this with getGroupLabel call\n for( var i = 0; i < that.$selectGroups.length; ++i ) {\n var parent_li = that.$selectGroups[i].parentElement\n if( parent_li.dataset.group === group ) {\n $(parent_li.parentElement).show();\n that.$selectGroups[i].checked = false;\n break;\n }\n }\n\n this.parentElement.removeChild(this);\n that.update();\n return false;\n }))\n $cloned\n .find('span')\n .html(that\n .options\n .pickoutSelectedGroupLabel\n .replace('#', $cloned.text())\n .replace('%', that.getGroupElems(group).length));\n }\n\n this.$selectedArea\n // Find and Remove anything in the 'selected area' which belongs to this\n // group.\n .find(\n sprintf('label:not(.optgroup) > input[data-group=\"%s\"]',\n $group_input[0].parentElement.dataset.group) )\n .each( function () {\n this.parentElement.parentElement.removeChild(this.parentElement);\n })\n },\n\n open: function () {\n if (this.$choice.hasClass('disabled')) {\n return;\n }\n this.options.isOpen = true;\n this.$choice.addClass('open')\n this.$choice.find('>div').addClass('open');\n this.$drop[this.animateMethod('show')]();\n\n if (!this.$el.children().length ) {\n this.$selectAll.parent().hide();\n this.$noResults.show();\n } else {\n this.$selectAll.parent().show();\n this.$noResults.hide();\n }\n\n if (this.options.container) {\n var offset = this.$drop.offset();\n this.$drop.appendTo($(this.options.container));\n this.$drop.offset({\n top: offset === undefined ? 0 : offset.top,\n left: offset === undefined ? 0 : offset.left\n });\n }\n\n if (this.options.filter) {\n this.$searchInput.val('');\n this.$searchInput.trigger(\"focus\");\n this.filter();\n }\n this.options.onOpen();\n },\n\n close: function () {\n this.options.isOpen = false;\n this.$choice.removeClass('open')\n this.$choice.find('>div').removeClass('open');\n this.$drop[this.animateMethod('hide')]();\n if (this.options.container) {\n this.$parent.append(this.$drop);\n this.$drop.css({\n 'top': 'auto',\n 'left': 'auto'\n });\n }\n this.options.onClose();\n },\n\n animateMethod: function (method) {\n var methods = {\n show: {\n fade: 'fadeIn',\n slide: 'slideDown'\n },\n hide: {\n fade: 'fadeOut',\n slide: 'slideUp'\n }\n };\n\n return methods[method][this.options.animate] || method;\n },\n\n\n update: function (isInit) {\n var that = this,\n selects = this.options.displayValues ? this.getSelects() : this.getSelects('text'),\n $span = this.$choice.find('>span'),\n select_len,\n total_len;\n\n if (this.$selectGroups.length != 0) {\n var counts =\n this.$selectGroups.get().reduce( function(sums, current) {\n var $current = $(current),\n group = $current.parent().data('group'),\n $children = that.$drop.find(sprintf('ul [%s][data-group=\"%s\"]', that.selectItemName, group)),\n $selected = $children.filter(':checked');\n return [ sums[0] + $selected.length, sums[1] + $children.length ];\n }, [0, 0])\n select_len = counts[0];\n total_len = counts[1];\n } else {\n select_len = selects.length;\n total_len = this.$selectItems.length + this.$disableItems.length;\n }\n\n\n if (select_len === 0) {\n $span.addClass('placeholder').html(this.options.placeholder);\n } else if ( this.options.allSelected\n && select_len === this.$selectItems.length + this.$disableItems.length) {\n $span.removeClass('placeholder').html(this.options.allSelected);\n } else if ( this.options.ellipsis\n && select_len > this.options.minimumCountSelected) {\n $span.removeClass('placeholder').text(selects.slice(0, this.options.minimumCountSelected)\n .join(this.options.delimiter) + '...');\n } else if ( this.options.countSelected\n && select_len > this.options.minimumCountSelected) {\n $span.removeClass('placeholder').html(\n this.options.countSelected\n .replace('#', select_len )\n .replace('%', total_len )\n );\n } else {\n $span.removeClass('placeholder').text(selects.join(this.options.delimiter));\n }\n\n if (this.options.addTitle) {\n $span.prop('title', this.getSelects('text'));\n }\n\n\n // set selects to select\n this.$el.val(this.getSelects()).trigger('change');\n\n // Remove old `selected' class\n this.$drop.find('li').removeClass('selected');\n\n this.$drop.find('input:checked').each(function () {\n var parent_li = $(this).parents('li');\n\n // add selected class to selected li\n parent_li.first().addClass('selected');\n\n if (that.options.pickoutSelected) {\n parent_li.hide();\n }\n });\n\n // trigger