From da0891d124366cd1d1616e1506145352d0156cd4 Mon Sep 17 00:00:00 2001 From: Josh Schmidt Date: Mon, 9 Nov 2020 20:38:16 -0700 Subject: [PATCH] v1.0.0-rc.3 Release --- dist/css/tom-select.bootstrap3.css | 2 +- dist/css/tom-select.bootstrap4.css | 2 +- dist/css/tom-select.css | 2 +- dist/css/tom-select.default.css | 2 +- dist/js/plugins/change_listener.js | 9 +- dist/js/plugins/change_listener.js.map | 2 +- dist/js/plugins/drag_drop.js | 2 +- dist/js/plugins/dropdown_header.js | 8 +- dist/js/plugins/dropdown_header.js.map | 2 +- dist/js/plugins/input_autogrow.js | 5 +- dist/js/plugins/input_autogrow.js.map | 2 +- dist/js/plugins/no_backspace_delete.js | 2 +- dist/js/plugins/optgroup_columns.js | 6 +- dist/js/plugins/optgroup_columns.js.map | 2 +- dist/js/plugins/remove_button.js | 24 +- dist/js/plugins/remove_button.js.map | 2 +- dist/js/plugins/restore_on_backspace.js | 2 +- dist/js/tom-select.base.js | 540 ++++++++++++----------- dist/js/tom-select.base.js.map | 2 +- dist/js/tom-select.base.min.js | 6 +- dist/js/tom-select.base.min.js.map | 2 +- dist/js/tom-select.complete.js | 543 +++++++++++++----------- dist/js/tom-select.complete.js.map | 2 +- dist/js/tom-select.complete.min.js | 6 +- dist/js/tom-select.complete.min.js.map | 2 +- dist/scss/tom-select.scss | 2 +- package.json | 2 +- 27 files changed, 644 insertions(+), 539 deletions(-) diff --git a/dist/css/tom-select.bootstrap3.css b/dist/css/tom-select.bootstrap3.css index ae6c35ba..3c93d5d4 100644 --- a/dist/css/tom-select.bootstrap3.css +++ b/dist/css/tom-select.bootstrap3.css @@ -1,5 +1,5 @@ /** - * tom-select.css (v1.0.0-rc.2) + * tom-select.css (v1.0.0-rc.3) * Copyright (c) contributors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this diff --git a/dist/css/tom-select.bootstrap4.css b/dist/css/tom-select.bootstrap4.css index 94744b90..b438f4de 100644 --- a/dist/css/tom-select.bootstrap4.css +++ b/dist/css/tom-select.bootstrap4.css @@ -2,7 +2,7 @@ * Tom Select bootstrap 4 */ /** - * tom-select.css (v1.0.0-rc.2) + * tom-select.css (v1.0.0-rc.3) * Copyright (c) contributors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this diff --git a/dist/css/tom-select.css b/dist/css/tom-select.css index 58cd7cb7..df0ec1ab 100644 --- a/dist/css/tom-select.css +++ b/dist/css/tom-select.css @@ -1,5 +1,5 @@ /** - * tom-select.css (v1.0.0-rc.2) + * tom-select.css (v1.0.0-rc.3) * Copyright (c) contributors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this diff --git a/dist/css/tom-select.default.css b/dist/css/tom-select.default.css index 1ea2991a..4a6f859b 100644 --- a/dist/css/tom-select.default.css +++ b/dist/css/tom-select.default.css @@ -1,5 +1,5 @@ /** - * tom-select.css (v1.0.0-rc.2) + * tom-select.css (v1.0.0-rc.3) * Copyright (c) contributors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this diff --git a/dist/js/plugins/change_listener.js b/dist/js/plugins/change_listener.js index e04fa847..e2544ab6 100644 --- a/dist/js/plugins/change_listener.js +++ b/dist/js/plugins/change_listener.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -92,12 +92,6 @@ } }; - /** - * Determines if the provided value has been defined. - * - * @param {mixed} object - * @returns {boolean} - */ /** * Converts a scalar to its best string representation * for hash keys and HTML attribute values. @@ -114,7 +108,6 @@ * @param {string} value * @returns {string|null} */ - function hash_key(value) { if (typeof value === 'undefined' || value === null) return null; if (typeof value === 'boolean') return value ? '1' : '0'; diff --git a/dist/js/plugins/change_listener.js.map b/dist/js/plugins/change_listener.js.map index 12a98196..4c3dbbb0 100644 --- a/dist/js/plugins/change_listener.js.map +++ b/dist/js/plugins/change_listener.js.map @@ -1 +1 @@ -{"version":3,"file":"change_listener.js","sources":["../../../src/defaults.js","../../../src/utils.js","../../../src/settings.js","../../../src/plugins/change_listener/plugin.js"],"sourcesContent":["\nexport default {\n\toptions: [],\n\toptgroups: [],\n\n\tplugins: [],\n\tdelimiter: ',',\n\tsplitOn: null, // regexp or string for splitting up values from a paste command\n\tpersist: true,\n\tdiacritics: true,\n\tcreate: false,\n\tcreateOnBlur: false,\n\tcreateFilter: null,\n\thighlight: true,\n\topenOnFocus: true,\n\tmaxOptions: 50,\n\tmaxItems: null,\n\thideSelected: null,\n\tduplicates: false,\n\taddPrecedence: false,\n\tselectOnTab: false,\n\tpreload: false,\n\tallowEmptyOption: false,\n\tcloseAfterSelect: false,\n\n\tscrollDuration: 60,\n\tloadThrottle: 300,\n\tloadingClass: 'loading',\n\n\tdataAttr: null, //'data-data',\n\toptgroupField: 'optgroup',\n\tvalueField: 'value',\n\tlabelField: 'text',\n\tdisabledField: 'disabled',\n\toptgroupLabelField: 'label',\n\toptgroupValueField: 'value',\n\tlockOptgroupOrder: false,\n\n\tsortField: '$order',\n\tsearchField: ['text'],\n\tsearchConjunction: 'and',\n\n\tmode: null,\n\twrapperClass: 'ts-control',\n\tinputClass: 'ts-input',\n\tdropdownClass: 'ts-dropdown',\n\tdropdownContentClass: 'ts-dropdown-content',\n\titemClass: 'item',\n\toptionClass: 'option',\n\n\tdropdownParent: null,\n\tcontrolInput: null,\n\n\tcopyClassesToDropdown: true,\n\n\t/*\n\tload : null, // function(query, callback) { ... }\n\tscore : null, // function(search) { ... }\n\tonInitialize : null, // function() { ... }\n\tonChange : null, // function(value) { ... }\n\tonItemAdd : null, // function(value, $item) { ... }\n\tonItemRemove : null, // function(value) { ... }\n\tonClear : null, // function() { ... }\n\tonOptionAdd : null, // function(value, data) { ... }\n\tonOptionRemove : null, // function(value) { ... }\n\tonOptionClear : null, // function() { ... }\n\tonOptionGroupAdd : null, // function(id, data) { ... }\n\tonOptionGroupRemove : null, // function(id) { ... }\n\tonOptionGroupClear : null, // function() { ... }\n\tonDropdownOpen : null, // function(dropdown) { ... }\n\tonDropdownClose : null, // function(dropdown) { ... }\n\tonType : null, // function(str) { ... }\n\tonDelete : null, // function(values) { ... }\n\t*/\n\n\trender: {\n\t\t/*\n\t\titem: null,\n\t\toptgroup: null,\n\t\toptgroup_header: null,\n\t\toption: null,\n\t\toption_create: null\n\t\t*/\n\t}\n};\n","/**\n * Determines if the provided value has been defined.\n *\n * @param {mixed} object\n * @returns {boolean}\n */\nexport function isset(object) {\n\treturn typeof object !== 'undefined';\n};\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n * @param {string} value\n * @returns {string|null}\n */\nexport function hash_key(value) {\n\tif (typeof value === 'undefined' || value === null) return null;\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n * @param {string} str\n * @returns {string}\n */\nexport function escape_html(str) {\n\treturn (str + '')\n\t\t.replace(/&/g, '&')\n\t\t.replace(//g, '>')\n\t\t.replace(/\"/g, '"');\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n * @param {object} self\n * @param {array} types\n * @param {function} fn\n */\nexport function debounce_events( self, types, fn) {\n\tvar type;\n\tvar trigger = self.trigger;\n\tvar event_args = {};\n\n\t// override trigger method\n\tself.trigger = function() {\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor (type in event_args) {\n\t\tif (event_args.hasOwnProperty(type)) {\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * @param {object} input\n * @returns {object}\n */\nexport function getSelection(input) {\n\treturn {\n\t\tstart\t: input.selectionStart,\n\t\tlength\t: input.selectionEnd - input.selectionStart,\n\t};\n};\n","import defaults from './defaults.js';\nimport { hash_key } from './utils.js';\n\nexport default function getSettings( input, settings_user){\n\tvar settings\t\t\t\t= Object.assign({}, defaults, settings_user);\n\n\tvar attr_data\t\t\t\t= settings.dataAttr;\n\tvar field_label\t\t\t\t= settings.labelField;\n\tvar field_value\t\t\t\t= settings.valueField;\n\tvar field_disabled\t\t\t= settings.disabledField;\n\tvar field_optgroup\t\t\t= settings.optgroupField;\n\tvar field_optgroup_label\t= settings.optgroupLabelField;\n\tvar field_optgroup_value\t= settings.optgroupValueField;\n\n\tvar tag_name\t\t\t\t= input.tagName.toLowerCase();\n\tvar placeholder\t\t\t\t= input.getAttribute('placeholder') || input.getAttribute('data-placeholder');\n\n\tif (!placeholder && !settings.allowEmptyOption) {\n\t\tlet option\t\t= input.querySelector('option[value=\"\"]');\n\t\tif( option ){\n\t\t\tplaceholder = option.textContent;\n\t\t}\n\n\t}\n\n\tvar settings_element\t\t= {\n\t\t\t\t\t\t\t\t\t\t'placeholder' : placeholder,\n\t\t\t\t\t\t\t\t\t\t'options' : [],\n\t\t\t\t\t\t\t\t\t\t'optgroups' : [],\n\t\t\t\t\t\t\t\t\t\t'items' : []\n\t\t\t\t\t\t\t\t\t};\n\n\n\t/**\n\t * Initialize from a element.\n\t *\n\t */\n\tvar init_textbox = function(){\n\t\tvar i, n, values, option;\n\n\t\tvar data_raw = input.getAttribute(attr_data);\n\n\t\tif (!data_raw) {\n\t\t\tvar value = input.value.trim() || '';\n\t\t\tif (!settings.allowEmptyOption && !value.length) return;\n\t\t\tvalues = value.split(settings.delimiter);\n\t\t\tfor (i = 0, n = values.length; i < n; i++) {\n\t\t\t\toption = {};\n\t\t\t\toption[field_label] = values[i];\n\t\t\t\toption[field_value] = values[i];\n\t\t\t\tsettings_element.options.push(option);\n\t\t\t}\n\t\t\tsettings_element.items = values;\n\t\t} else {\n\t\t\tsettings_element.options = JSON.parse(data_raw);\n\t\t\tfor (i = 0, n = settings_element.options.length; i < n; i++) {\n\t\t\t\tsettings_element.items.push(settings_element.options[i][field_value]);\n\t\t\t}\n\t\t}\n\t};\n\n\n\tif (tag_name === 'select') {\n\t\tinit_select();\n\t} else {\n\t\tinit_textbox();\n\t}\n\n\treturn Object.assign( {}, defaults, settings_element, settings_user);\n};\n","/**\n * Plugin: \"change_listener\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport getSettings from '../../settings.js';\n\nexport default TomSelect.define('change_listener',function(options){\n\tvar self\t\t= this;\n\tvar changed\t\t= false;\n\n\tself.input.addEventListener('change',function(){\n\n\t\t// prevent infinite loops\n\t\tif( changed ){\n\t\t\tchanged = false;\n\t\t\treturn;\n\t\t}\n\n\t\tchanged\t\t\t= true;\n\t\tvar settings\t= getSettings( self.input, {} );\n\n\t\tself.setupOptions(settings.options,settings.optgroups);\n\t\tself.setValue(settings.items);\n\t});\n\n});\n"],"names":["options","optgroups","plugins","delimiter","splitOn","persist","diacritics","create","createOnBlur","createFilter","highlight","openOnFocus","maxOptions","maxItems","hideSelected","duplicates","addPrecedence","selectOnTab","preload","allowEmptyOption","closeAfterSelect","scrollDuration","loadThrottle","loadingClass","dataAttr","optgroupField","valueField","labelField","disabledField","optgroupLabelField","optgroupValueField","lockOptgroupOrder","sortField","searchField","searchConjunction","mode","wrapperClass","inputClass","dropdownClass","dropdownContentClass","itemClass","optionClass","dropdownParent","controlInput","copyClassesToDropdown","render","hash_key","value","getSettings","input","settings_user","settings","Object","assign","defaults","attr_data","field_label","field_value","field_disabled","field_optgroup","field_optgroup_label","field_optgroup_value","tag_name","tagName","toLowerCase","placeholder","getAttribute","option","querySelector","textContent","settings_element","init_select","i","n","children","optionsMap","readData","el","data","dataset","json","length","JSON","parse","addOption","group","hasOwnProperty","arr","Array","isArray","push","option_data","disabled","selected","items","addGroup","optgroup","id","optgroup_data","hasAttribute","init_textbox","values","data_raw","trim","split","TomSelect","define","self","changed","addEventListener","setupOptions","setValue"],"mappings":";;;;;;;;;;;;;;;AACA,gBAAe;CACdA,EAAAA,OAAO,EAAE,EADK;CAEdC,EAAAA,SAAS,EAAE,EAFG;CAIdC,EAAAA,OAAO,EAAE,EAJK;CAKdC,EAAAA,SAAS,EAAE,GALG;CAMdC,EAAAA,OAAO,EAAE,IANK;CAMC;CACfC,EAAAA,OAAO,EAAE,IAPK;CAQdC,EAAAA,UAAU,EAAE,IARE;CASdC,EAAAA,MAAM,EAAE,KATM;CAUdC,EAAAA,YAAY,EAAE,KAVA;CAWdC,EAAAA,YAAY,EAAE,IAXA;CAYdC,EAAAA,SAAS,EAAE,IAZG;CAadC,EAAAA,WAAW,EAAE,IAbC;CAcdC,EAAAA,UAAU,EAAE,EAdE;CAedC,EAAAA,QAAQ,EAAE,IAfI;CAgBdC,EAAAA,YAAY,EAAE,IAhBA;CAiBdC,EAAAA,UAAU,EAAE,KAjBE;CAkBdC,EAAAA,aAAa,EAAE,KAlBD;CAmBdC,EAAAA,WAAW,EAAE,KAnBC;CAoBdC,EAAAA,OAAO,EAAE,KApBK;CAqBdC,EAAAA,gBAAgB,EAAE,KArBJ;CAsBdC,EAAAA,gBAAgB,EAAE,KAtBJ;CAwBdC,EAAAA,cAAc,EAAE,EAxBF;CAyBdC,EAAAA,YAAY,EAAE,GAzBA;CA0BdC,EAAAA,YAAY,EAAE,SA1BA;CA4BdC,EAAAA,QAAQ,EAAE,IA5B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D,gBAAX,CAA4B,QAA5B,EAAqC,YAAU;CAE9C;CACA,QAAID,OAAJ,EAAa;CACZA,MAAAA,OAAO,GAAG,KAAV;CACA;CACA;;CAEDA,IAAAA,OAAO,GAAK,IAAZ;CACA,QAAIzD,QAAQ,GAAGH,WAAW,CAAE2D,IAAI,CAAC1D,KAAP,EAAc,EAAd,CAA1B;CAEA0D,IAAAA,IAAI,CAACG,YAAL,CAAkB3D,QAAQ,CAACnD,OAA3B,EAAmCmD,QAAQ,CAAClD,SAA5C;CACA0G,IAAAA,IAAI,CAACI,QAAL,CAAc5D,QAAQ,CAAC2C,KAAvB;CACA,GAbD;CAeA,CAnBc,CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"change_listener.js","sources":["../../../src/defaults.js","../../../src/utils.js","../../../src/settings.js","../../../src/plugins/change_listener/plugin.js"],"sourcesContent":["\nexport default {\n\toptions: [],\n\toptgroups: [],\n\n\tplugins: [],\n\tdelimiter: ',',\n\tsplitOn: null, // regexp or string for splitting up values from a paste command\n\tpersist: true,\n\tdiacritics: true,\n\tcreate: false,\n\tcreateOnBlur: false,\n\tcreateFilter: null,\n\thighlight: true,\n\topenOnFocus: true,\n\tmaxOptions: 50,\n\tmaxItems: null,\n\thideSelected: null,\n\tduplicates: false,\n\taddPrecedence: false,\n\tselectOnTab: false,\n\tpreload: false,\n\tallowEmptyOption: false,\n\tcloseAfterSelect: false,\n\n\tscrollDuration: 60,\n\tloadThrottle: 300,\n\tloadingClass: 'loading',\n\n\tdataAttr: null, //'data-data',\n\toptgroupField: 'optgroup',\n\tvalueField: 'value',\n\tlabelField: 'text',\n\tdisabledField: 'disabled',\n\toptgroupLabelField: 'label',\n\toptgroupValueField: 'value',\n\tlockOptgroupOrder: false,\n\n\tsortField: '$order',\n\tsearchField: ['text'],\n\tsearchConjunction: 'and',\n\n\tmode: null,\n\twrapperClass: 'ts-control',\n\tinputClass: 'ts-input',\n\tdropdownClass: 'ts-dropdown',\n\tdropdownContentClass: 'ts-dropdown-content',\n\titemClass: 'item',\n\toptionClass: 'option',\n\n\tdropdownParent: null,\n\tcontrolInput: null,\n\n\tcopyClassesToDropdown: true,\n\n\t/*\n\tload : null, // function(query, callback) { ... }\n\tscore : null, // function(search) { ... }\n\tonInitialize : null, // function() { ... }\n\tonChange : null, // function(value) { ... }\n\tonItemAdd : null, // function(value, $item) { ... }\n\tonItemRemove : null, // function(value) { ... }\n\tonClear : null, // function() { ... }\n\tonOptionAdd : null, // function(value, data) { ... }\n\tonOptionRemove : null, // function(value) { ... }\n\tonOptionClear : null, // function() { ... }\n\tonOptionGroupAdd : null, // function(id, data) { ... }\n\tonOptionGroupRemove : null, // function(id) { ... }\n\tonOptionGroupClear : null, // function() { ... }\n\tonDropdownOpen : null, // function(dropdown) { ... }\n\tonDropdownClose : null, // function(dropdown) { ... }\n\tonType : null, // function(str) { ... }\n\tonDelete : null, // function(values) { ... }\n\t*/\n\n\trender: {\n\t\t/*\n\t\titem: null,\n\t\toptgroup: null,\n\t\toptgroup_header: null,\n\t\toption: null,\n\t\toption_create: null\n\t\t*/\n\t}\n};\n","\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n * @param {string} value\n * @returns {string|null}\n */\nexport function hash_key(value) {\n\tif (typeof value === 'undefined' || value === null) return null;\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n * @param {string} str\n * @returns {string}\n */\nexport function escape_html(str) {\n\treturn (str + '')\n\t\t.replace(/&/g, '&')\n\t\t.replace(//g, '>')\n\t\t.replace(/\"/g, '"');\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n * @param {object} self\n * @param {array} types\n * @param {function} fn\n */\nexport function debounce_events( self, types, fn) {\n\tvar type;\n\tvar trigger = self.trigger;\n\tvar event_args = {};\n\n\t// override trigger method\n\tself.trigger = function() {\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor (type in event_args) {\n\t\tif (event_args.hasOwnProperty(type)) {\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * @param {object} input\n * @returns {object}\n */\nexport function getSelection(input) {\n\treturn {\n\t\tstart\t: input.selectionStart,\n\t\tlength\t: input.selectionEnd - input.selectionStart,\n\t};\n};\n","import defaults from './defaults.js';\nimport { hash_key } from './utils.js';\n\nexport default function getSettings( input, settings_user){\n\tvar settings\t\t\t\t= Object.assign({}, defaults, settings_user);\n\n\tvar attr_data\t\t\t\t= settings.dataAttr;\n\tvar field_label\t\t\t\t= settings.labelField;\n\tvar field_value\t\t\t\t= settings.valueField;\n\tvar field_disabled\t\t\t= settings.disabledField;\n\tvar field_optgroup\t\t\t= settings.optgroupField;\n\tvar field_optgroup_label\t= settings.optgroupLabelField;\n\tvar field_optgroup_value\t= settings.optgroupValueField;\n\n\tvar tag_name\t\t\t\t= input.tagName.toLowerCase();\n\tvar placeholder\t\t\t\t= input.getAttribute('placeholder') || input.getAttribute('data-placeholder');\n\n\tif (!placeholder && !settings.allowEmptyOption) {\n\t\tlet option\t\t= input.querySelector('option[value=\"\"]');\n\t\tif( option ){\n\t\t\tplaceholder = option.textContent;\n\t\t}\n\n\t}\n\n\tvar settings_element\t\t= {\n\t\t\t\t\t\t\t\t\t\t'placeholder' : placeholder,\n\t\t\t\t\t\t\t\t\t\t'options' : [],\n\t\t\t\t\t\t\t\t\t\t'optgroups' : [],\n\t\t\t\t\t\t\t\t\t\t'items' : []\n\t\t\t\t\t\t\t\t\t};\n\n\n\t/**\n\t * Initialize from a element.\n\t *\n\t */\n\tvar init_textbox = function(){\n\t\tvar i, n, values, option;\n\n\t\tvar data_raw = input.getAttribute(attr_data);\n\n\t\tif (!data_raw) {\n\t\t\tvar value = input.value.trim() || '';\n\t\t\tif (!settings.allowEmptyOption && !value.length) return;\n\t\t\tvalues = value.split(settings.delimiter);\n\t\t\tfor (i = 0, n = values.length; i < n; i++) {\n\t\t\t\toption = {};\n\t\t\t\toption[field_label] = values[i];\n\t\t\t\toption[field_value] = values[i];\n\t\t\t\tsettings_element.options.push(option);\n\t\t\t}\n\t\t\tsettings_element.items = values;\n\t\t} else {\n\t\t\tsettings_element.options = JSON.parse(data_raw);\n\t\t\tfor (i = 0, n = settings_element.options.length; i < n; i++) {\n\t\t\t\tsettings_element.items.push(settings_element.options[i][field_value]);\n\t\t\t}\n\t\t}\n\t};\n\n\n\tif (tag_name === 'select') {\n\t\tinit_select();\n\t} else {\n\t\tinit_textbox();\n\t}\n\n\treturn Object.assign( {}, defaults, settings_element, settings_user);\n};\n","/**\n * Plugin: \"change_listener\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport getSettings from '../../settings.js';\n\nexport default TomSelect.define('change_listener',function(options){\n\tvar self\t\t= this;\n\tvar changed\t\t= false;\n\n\tself.input.addEventListener('change',function(){\n\n\t\t// prevent infinite loops\n\t\tif( changed ){\n\t\t\tchanged = false;\n\t\t\treturn;\n\t\t}\n\n\t\tchanged\t\t\t= true;\n\t\tvar settings\t= getSettings( self.input, {} );\n\n\t\tself.setupOptions(settings.options,settings.optgroups);\n\t\tself.setValue(settings.items);\n\t});\n\n});\n"],"names":["options","optgroups","plugins","delimiter","splitOn","persist","diacritics","create","createOnBlur","createFilter","highlight","openOnFocus","maxOptions","maxItems","hideSelected","duplicates","addPrecedence","selectOnTab","preload","allowEmptyOption","closeAfterSelect","scrollDuration","loadThrottle","loadingClass","dataAttr","optgroupField","valueField","labelField","disabledField","optgroupLabelField","optgroupValueField","lockOptgroupOrder","sortField","searchField","searchConjunction","mode","wrapperClass","inputClass","dropdownClass","dropdownContentClass","itemClass","optionClass","dropdownParent","controlInput","copyClassesToDropdown","render","hash_key","value","getSettings","input","settings_user","settings","Object","assign","defaults","attr_data","field_label","field_value","field_disabled","field_optgroup","field_optgroup_label","field_optgroup_value","tag_name","tagName","toLowerCase","placeholder","getAttribute","option","querySelector","textContent","settings_element","init_select","i","n","children","optionsMap","readData","el","data","dataset","json","length","JSON","parse","addOption","group","hasOwnProperty","arr","Array","isArray","push","option_data","disabled","selected","items","addGroup","optgroup","id","optgroup_data","hasAttribute","init_textbox","values","data_raw","trim","split","TomSelect","define","self","changed","addEventListener","setupOptions","setValue"],"mappings":";;;;;;;;;;;;;;;AACA,gBAAe;CACdA,EAAAA,OAAO,EAAE,EADK;CAEdC,EAAAA,SAAS,EAAE,EAFG;CAIdC,EAAAA,OAAO,EAAE,EAJK;CAKdC,EAAAA,SAAS,EAAE,GALG;CAMdC,EAAAA,OAAO,EAAE,IANK;CAMC;CACfC,EAAAA,OAAO,EAAE,IAPK;CAQdC,EAAAA,UAAU,EAAE,IARE;CASdC,EAAAA,MAAM,EAAE,KATM;CAUdC,EAAAA,YAAY,EAAE,KAVA;CAWdC,EAAAA,YAAY,EAAE,IAXA;CAYdC,EAAAA,SAAS,EAAE,IAZG;CAadC,EAAAA,WAAW,EAAE,IAbC;CAcdC,EAAAA,UAAU,EAAE,EAdE;CAedC,EAAAA,QAAQ,EAAE,IAfI;CAgBdC,EA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WAAW;CACX,GAFD,MAEO;CACN6B,IAAAA,YAAY;CACZ;;CAED,SAAOhD,MAAM,CAACC,MAAP,CAAe,EAAf,EAAmBC,QAAnB,EAA6BgB,gBAA7B,EAA+CpB,aAA/C,CAAP;CACA;;CChKD;;;;;;;;;;;;;;AAkBA,cAAeuD,6BAAS,CAACC,MAAV,CAAiB,iBAAjB,EAAmC,UAAS1G,OAAT,EAAiB;CAClE,MAAI2G,IAAI,GAAI,IAAZ;CACA,MAAIC,OAAO,GAAI,KAAf;CAEAD,EAAAA,IAAI,CAAC1D,KAAL,CAAW4D,gBAAX,CAA4B,QAA5B,EAAqC,YAAU;CAE9C;CACA,QAAID,OAAJ,EAAa;CACZA,MAAAA,OAAO,GAAG,KAAV;CACA;CACA;;CAEDA,IAAAA,OAAO,GAAK,IAAZ;CACA,QAAIzD,QAAQ,GAAGH,WAAW,CAAE2D,IAAI,CAAC1D,KAAP,EAAc,EAAd,CAA1B;CAEA0D,IAAAA,IAAI,CAACG,YAAL,CAAkB3D,QAAQ,CAACnD,OAA3B,EAAmCmD,QAAQ,CAAClD,SAA5C;CACA0G,IAAAA,IAAI,CAACI,QAAL,CAAc5D,QAAQ,CAAC2C,KAAvB;CACA,GAbD;CAeA,CAnBc,CAAf;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/plugins/drag_drop.js b/dist/js/plugins/drag_drop.js index 33f52162..4b074ce6 100644 --- a/dist/js/plugins/drag_drop.js +++ b/dist/js/plugins/drag_drop.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ diff --git a/dist/js/plugins/dropdown_header.js b/dist/js/plugins/dropdown_header.js index 7f8bca6f..c28812e4 100644 --- a/dist/js/plugins/dropdown_header.js +++ b/dist/js/plugins/dropdown_header.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -17,8 +17,8 @@ * Return a dom element from either a dom query string, jQuery object, a dom element or html string * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 * - * @param {mixed} query - * @return {Element} + * @param {any} query .. should be {HTMLElement|string|JQuery} + * @return {HTMLElement} */ function getDom(query) { if (query.jquery) { @@ -33,7 +33,7 @@ var div = document.createElement('div'); div.innerHTML = query.trim(); // Never return a text node of whitespace as the result - return div.firstChild; + return div.querySelector(':first-child'); } return document.querySelector(query); diff --git a/dist/js/plugins/dropdown_header.js.map b/dist/js/plugins/dropdown_header.js.map index 04c41ddf..7483c4fa 100644 --- a/dist/js/plugins/dropdown_header.js.map +++ b/dist/js/plugins/dropdown_header.js.map @@ -1 +1 @@ -{"version":3,"file":"dropdown_header.js","sources":["../../../src/vanilla.js","../../../src/plugins/dropdown_header/plugin.js"],"sourcesContent":["\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {mixed} query\n * @return {Element}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.firstChild;\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n/**\n * Delegate Event\n *\n */\nexport function onEvent( el, eventName, elementSelector, handler ){\n\n\tlet event_names\t= eventName.split(/\\s/);\n\n\t// create intermediate handler that can be used for all event names\n\t// loop parent nodes from the target to the delegation node\n\tlet _handler = function(e) {\n\t\tvar target_match = parentMatch(e.target, elementSelector, el);\n\t\tif( target_match ){\n\t\t\te.delegateTarget = target_match;\n\t\t\thandler.call(target_match, e);\n\t\t}\n\t};\n\n\tfor( let i = 0; i 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","/**\n * Plugin: \"dropdown_header\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport { getDom } from '../../vanilla.js';\n\n\nexport default TomSelect.define('dropdown_header',function(options) {\n\tvar self = this;\n\n\toptions = Object.assign({\n\t\ttitle : 'Untitled',\n\t\theaderClass : 'dropdown-header',\n\t\ttitleRowClass : 'dropdown-header-title',\n\t\tlabelClass : 'dropdown-header-label',\n\t\tcloseClass : 'dropdown-header-close',\n\n\t\thtml: function(data) {\n\t\t\treturn (\n\t\t\t\t'
' +\n\t\t\t\t\t'
' +\n\t\t\t\t\t\t'' + data.title + '' +\n\t\t\t\t\t\t'×' +\n\t\t\t\t\t'
' +\n\t\t\t\t'
'\n\t\t\t);\n\t\t}\n\t}, options);\n\n\tself.hook('after','setup',function(){\n\t\tvar header = getDom(options.html(options));\n\t\tself.dropdown.insertBefore(header, self.dropdown.firstChild);\n\t});\n\n});\n"],"names":["getDom","query","jquery","HTMLElement","indexOf","div","document","createElement","innerHTML","trim","firstChild","querySelector","TomSelect","define","options","self","Object","assign","title","headerClass","titleRowClass","labelCl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,GAKA,QAND;CAQA;CAhBsB,GAAd,EAiBPR,OAjBO,CAAV;CAmBAC,EAAAA,IAAI,CAACU,IAAL,CAAU,OAAV,EAAkB,OAAlB,EAA0B,YAAU;CACnC,QAAIC,MAAM,GAAG1B,MAAM,CAACc,OAAO,CAACS,IAAR,CAAaT,OAAb,CAAD,CAAnB;CACAC,IAAAA,IAAI,CAACY,QAAL,CAAcC,YAAd,CAA2BF,MAA3B,EAAmCX,IAAI,CAACY,QAAL,CAAcjB,UAAjD;CACA,GAHD;CAKA,CA3Bc,CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"dropdown_header.js","sources":["../../../src/vanilla.js","../../../src/plugins/dropdown_header/plugin.js"],"sourcesContent":["\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {any} query .. should be {HTMLElement|string|JQuery}\n * @return {HTMLElement}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.querySelector(':first-child');\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n\n/**\n * Get the closest node to the evt.target matching the selector\n * Stops at wrapper\n *\n */\nexport function parentMatch(target, selector, wrapper ){\n\n\tif( wrapper && !wrapper.contains(target) ){\n\t\treturn;\n\t}\n\n\twhile( target && target.matches ){\n\n\t\tif( target.matches(selector) ){\n\t\t\treturn target;\n\t\t}\n\n\t\ttarget = target.parentNode;\n\t}\n}\n\n/**\n * Get the first or last item from a querySelectorAll result\n *\n * > 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","/**\n * Plugin: \"dropdown_header\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport { getDom } from '../../vanilla.js';\n\n\nexport default TomSelect.define('dropdown_header',function(options) {\n\tvar self = this;\n\n\toptions = Object.assign({\n\t\ttitle : 'Untitled',\n\t\theaderClass : 'dropdown-header',\n\t\ttitleRowClass : 'dropdown-header-title',\n\t\tlabelClass : 'dropdown-header-label',\n\t\tcloseClass : 'dropdown-header-close',\n\n\t\thtml: function(data) {\n\t\t\treturn (\n\t\t\t\t'
' +\n\t\t\t\t\t'
' +\n\t\t\t\t\t\t'' + data.title + '' +\n\t\t\t\t\t\t'×' +\n\t\t\t\t\t'
' +\n\t\t\t\t'
'\n\t\t\t);\n\t\t}\n\t}, options);\n\n\tself.hook('after','setup',function(){\n\t\tvar header = getDom(options.html(options));\n\t\tself.dropdown.insertBefore(header, self.dropdown.firstChild);\n\t});\n\n});\n"],"names":["getDom","query","jquery","HTMLElement","indexOf","div","document","createElement","innerHTML","trim","querySelector","TomSelect","define","options","self","Object","assign","title","headerClass","titleRowClass","labelClass","closeClass","html","data","hook","header","dropdown","insertBefore","firstChild"],"mappings":";;;;;;;;;;;;;;;CACA;;;;;;;CAOO,SAASA,MAAT,CAAiBC,KAAjB,EAAwB;CAE9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OAAV,EAAkB,OAAlB,EAA0B,YAAU;CACnC,QAAIC,MAAM,GAAGzB,MAAM,CAACa,OAAO,CAACS,IAAR,CAAaT,OAAb,CAAD,CAAnB;CACAC,IAAAA,IAAI,CAACY,QAAL,CAAcC,YAAd,CAA2BF,MAA3B,EAAmCX,IAAI,CAACY,QAAL,CAAcE,UAAjD;CACA,GAHD;CAKA,CA3Bc,CAAf;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/plugins/input_autogrow.js b/dist/js/plugins/input_autogrow.js index 03ac2c18..f8db5f35 100644 --- a/dist/js/plugins/input_autogrow.js +++ b/dist/js/plugins/input_autogrow.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -35,7 +35,7 @@ test_input.style.top = '-99999px'; test_input.style.left = '-99999px'; test_input.style.width = 'auto'; - test_input.style.padding = 0; + test_input.style.padding = '0'; test_input.style.whiteSpace = 'pre'; self.wrapper.appendChild(test_input); var transfer_styles = ['letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform']; @@ -47,7 +47,6 @@ /** * Set the control width * - * @param {string} str */ diff --git a/dist/js/plugins/input_autogrow.js.map b/dist/js/plugins/input_autogrow.js.map index 942396cb..be0ff893 100644 --- a/dist/js/plugins/input_autogrow.js.map +++ b/dist/js/plugins/input_autogrow.js.map @@ -1 +1 @@ -{"version":3,"file":"input_autogrow.js","sources":["../../../src/plugins/input_autogrow/plugin.js"],"sourcesContent":["/**\n * Plugin: \"input_autogrow\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\nimport TomSelect from '../../tom-select.js';\n\nexport default TomSelect.define('input_autogrow', function(options) {\n\n\tvar self\t\t\t\t\t= this;\n\n\tself.hook('after','setup',function(){\n\n\n\t\tvar test_input\t\t\t\t= document.createElement('span');\n\t\tvar control\t\t\t\t\t= this.control_input;\n\t\ttest_input.style.position\t= 'absolute';\n\t\ttest_input.style.top\t\t= '-99999px';\n\t\ttest_input.style.left\t\t= '-99999px';\n\t\ttest_input.style.width\t\t= 'auto';\n\t\ttest_input.style.padding\t= 0;\n\t\ttest_input.style.whiteSpace\t= 'pre';\n\n\t\tself.wrapper.appendChild(test_input);\n\n\n\t\tvar transfer_styles\t\t\t= [ 'letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform' ];\n\n\t\tfor( let i = 0, n = transfer_styles.length; i < n; i++ ){\n\t\t\tlet style_name = transfer_styles[i];\n\t\t\ttest_input.style[style_name] = control.style[style_name];\n\t\t}\n\n\n\t\t/**\n\t\t * Set the control width\n\t\t *\n\t\t * @param {string} str\n\t\t */\n\t\tvar resize = function(){\n\t\t\ttest_input.textContent\t= control.value;\n\t\t\tcontrol.style.width\t\t= test_input.clientWidth+'px';\n\t\t};\n\n\t\tcontrol.addEventListener('input', resize );\n\t\tcontrol.addEventListener('keyup', resize );\n\t\tcontrol.addEventListener('blur', resize );\n\t\tcontrol.addEventListener('update', resize );\n\t});\n\n});\n"],"names":["TomSelect","define","options","self","hook","test_input","document","createElement","control","control_input","style","position","top","left","width","padding","whiteSpace","wrapper","appendChild","transfer_styles","i","n","length","style_name","resize","textContent","value","clientWidth","addEventListener"],"mappings":";;;;;;;;;;;;;;;CAAA;;;;;;;;;;;;;AAeA,cAAeA,6BAAS,CAACC,MAAV,CAAiB,gBAAjB,EAAmC,UAASC,OAAT,EAAkB;CAEnE,MAAIC,IAAI,GAAO,IAAf;CAEAA,EAAAA,IAAI,CAACC,IAAL,CAAU,OAAV,EAAkB,OAAlB,EAA0B,YAAU;CAGnC,QAAIC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R,CAAyB,OAAzB,EAAkCJ,MAAlC;CACAhB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,MAAzB,EAAiCJ,MAAjC;CACAhB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,QAAzB,EAAmCJ,MAAnC;CACA,GArCD;CAuCA,CA3Cc,CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"input_autogrow.js","sources":["../../../src/plugins/input_autogrow/plugin.js"],"sourcesContent":["/**\n * Plugin: \"input_autogrow\" (Tom Select)\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\nimport TomSelect from '../../tom-select.js';\n\nexport default TomSelect.define('input_autogrow', function(options) {\n\n\tvar self\t\t\t\t\t= this;\n\n\tself.hook('after','setup',function(){\n\n\n\t\tvar test_input\t\t\t\t= document.createElement('span');\n\t\tvar control\t\t\t\t\t= this.control_input;\n\t\ttest_input.style.position\t= 'absolute';\n\t\ttest_input.style.top\t\t= '-99999px';\n\t\ttest_input.style.left\t\t= '-99999px';\n\t\ttest_input.style.width\t\t= 'auto';\n\t\ttest_input.style.padding\t= '0';\n\t\ttest_input.style.whiteSpace\t= 'pre';\n\n\t\tself.wrapper.appendChild(test_input);\n\n\n\t\tvar transfer_styles\t\t\t= [ 'letterSpacing', 'fontSize', 'fontFamily', 'fontWeight', 'textTransform' ];\n\n\t\tfor( let i = 0, n = transfer_styles.length; i < n; i++ ){\n\t\t\tlet style_name = transfer_styles[i];\n\t\t\ttest_input.style[style_name] = control.style[style_name];\n\t\t}\n\n\n\t\t/**\n\t\t * Set the control width\n\t\t *\n\t\t */\n\t\tvar resize = function(){\n\t\t\ttest_input.textContent\t= control.value;\n\t\t\tcontrol.style.width\t\t= test_input.clientWidth+'px';\n\t\t};\n\n\t\tcontrol.addEventListener('input', resize );\n\t\tcontrol.addEventListener('keyup', resize );\n\t\tcontrol.addEventListener('blur', resize );\n\t\tcontrol.addEventListener('update', resize );\n\t});\n\n});\n"],"names":["TomSelect","define","options","self","hook","test_input","document","createElement","control","control_input","style","position","top","left","width","padding","whiteSpace","wrapper","appendChild","transfer_styles","i","n","length","style_name","resize","textContent","value","clientWidth","addEventListener"],"mappings":";;;;;;;;;;;;;;;CAAA;;;;;;;;;;;;;AAeA,cAAeA,6BAAS,CAACC,MAAV,CAAiB,gBAAjB,EAAmC,UAASC,OAAT,EAAkB;CAEnE,MAAIC,IAAI,GAAO,IAAf;CAEAA,EAAAA,IAAI,CAACC,IAAL,CAAU,OAAV,EAAkB,OAAlB,EAA0B,YAAU;CAGnC,QAAIC,UAAU,GAAMC,QAAQ,CAACC,aAAT,CAAuB,MAAvB,CAApB;CACA,QAAIC,OAAO,GAAO,KAAKC,aAAvB;CACAJ,IAAAA,UAAU,CAACK,KAAX,CAAiBC,QAAjB,GAA4B,UAA5B;CACAN,IAAAA,UAAU,CAACK,KAAX,CAAiBE,GAAjB,GAAwB,UAAxB;CACAP,IAAAA,UAAU,CAACK,KAAX,CAAiBG,IAAjB,GAAyB,UAAzB;CACAR,IAAAA,UAAU,CAACK,KAAX,CAAiBI,KAAjB,GAA0B,MAA1B;CACAT,IAAAA,UAAU,CAACK,KAAX,CAAiBK,OAAjB,GAA2B,GAA3B;CACAV,IAAAA,UAAU,CAACK,KAAX,CAAiBM,UAAjB,GAA8B,KAA9B;CAEAb,IAAAA,IAAI,CAACc,OAAL,CAAaC,WAAb,CAAyBb,UAAzB;CAGA,QAAIc,eAAe,GAAK,CAAE,eAAF,EAAmB,UAAnB,EAA+B,YAA/B,EAA6C,YAA7C,EAA2D,eAA3D,CAAxB;;CAEA,SAAK,IAAIC,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGF,eAAe,CAACG,MAApC,EAA4CF,CAAC,GAAGC,CAAhD,EAAmDD,CAAC,EAApD,EAAwD;CACvD,UAAIG,UAAU,GAAGJ,eAAe,CAACC,CAAD,CAAhC;CACAf,MAAAA,UAAU,CAACK,KAAX,CAAiBa,UAAjB,IAA+Bf,OAAO,CAACE,KAAR,CAAca,UAAd,CAA/B;CACA;CAGD;;;;;;CAIA,QAAIC,MAAM,GAAG,SAATA,MAAS,GAAU;CACtBnB,MAAAA,UAAU,CAACoB,WAAX,GAAyBjB,OAAO,CAACkB,KAAjC;CACAlB,MAAAA,OAAO,CAACE,KAAR,CAAcI,KAAd,GAAuBT,UAAU,CAACsB,WAAX,GAAuB,IAA9C;CACA,KAHD;;CAKAnB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,OAAzB,EAAkCJ,MAAlC;CACAhB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,OAAzB,EAAkCJ,MAAlC;CACAhB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,MAAzB,EAAiCJ,MAAjC;CACAhB,IAAAA,OAAO,CAACoB,gBAAR,CAAyB,QAAzB,EAAmCJ,MAAnC;CACA,GApCD;CAsCA,CA1Cc,CAAf;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/plugins/no_backspace_delete.js b/dist/js/plugins/no_backspace_delete.js index 480123d5..bd79d283 100644 --- a/dist/js/plugins/no_backspace_delete.js +++ b/dist/js/plugins/no_backspace_delete.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ diff --git a/dist/js/plugins/optgroup_columns.js b/dist/js/plugins/optgroup_columns.js index b70b86d2..3ea1dc67 100644 --- a/dist/js/plugins/optgroup_columns.js +++ b/dist/js/plugins/optgroup_columns.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -20,8 +20,8 @@ * Return a dom element from either a dom query string, jQuery object, a dom element or html string * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 * - * @param {mixed} query - * @return {Element} + * @param {any} query .. should be {HTMLElement|string|JQuery} + * @return {HTMLElement} */ /** * Get the closest node to the evt.target matching the selector diff --git a/dist/js/plugins/optgroup_columns.js.map b/dist/js/plugins/optgroup_columns.js.map index a63114a8..d2a3bd3a 100644 --- a/dist/js/plugins/optgroup_columns.js.map +++ b/dist/js/plugins/optgroup_columns.js.map @@ -1 +1 @@ -{"version":3,"file":"optgroup_columns.js","sources":["../../../src/constants.js","../../../src/vanilla.js","../../../src/plugins/optgroup_columns/plugin.js"],"sourcesContent":["export const KEY_A\t\t\t\t= 65;\nexport const KEY_RETURN\t\t= 13;\nexport const KEY_ESC\t\t\t= 27;\nexport const KEY_LEFT\t\t\t= 37;\nexport const KEY_UP\t\t\t= 38;\nexport const KEY_RIGHT\t\t\t= 39;\nexport const KEY_DOWN\t\t\t= 40;\nexport const KEY_BACKSPACE\t\t= 8;\nexport const KEY_DELETE\t\t= 46;\nexport const KEY_SHIFT\t\t\t= 16;\nexport const KEY_CTRL\t\t\t= 17;\nexport const KEY_TAB\t\t\t= 9;\n","\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {mixed} query\n * @return {Element}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.firstChild;\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n/**\n * Delegate Event\n *\n */\nexport function onEvent( el, eventName, elementSelector, handler ){\n\n\tlet event_names\t= eventName.split(/\\s/);\n\n\t// create intermediate handler that can be used for all event names\n\t// loop parent nodes from the target to the delegation node\n\tlet _handler = function(e) {\n\t\tvar target_match = parentMatch(e.target, elementSelector, el);\n\t\tif( target_match ){\n\t\t\te.delegateTarget = target_match;\n\t\t\thandler.call(target_match, e);\n\t\t}\n\t};\n\n\tfor( let i = 0; i 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","/**\n * Plugin: \"optgroup_columns\" (Tom Select.js)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport * as constants from '../../constants.js';\nimport { parentMatch, nodeIndex } from '../../vanilla.js';\n\nexport default TomSelect.define('optgroup_columns', function(options) {\n\tvar self = this;\n\n\tvar orig_keydown = self.onKeyDown;\n\n\tself.hook('instead','onKeyDown',function( evt ) {\n\t\tvar index, option, options, optgroup;\n\n\t\tif( !self.isOpen || !(evt.keyCode === constants.KEY_LEFT || evt.keyCode === constants.KEY_RIGHT)) {\n\t\t\treturn orig_keydown.apply(self,arguments);\n\t\t}\n\n\t\tself.ignoreHover\t= true;\n\t\toptgroup\t\t\t= parentMatch(self.activeOption,'[data-group]');\n\t\tindex\t\t\t\t= nodeIndex(self.activeOption,'[data-selectable]');\n\n\t\tif( evt.keyCode === constants.KEY_LEFT ){\n\t\t\toptgroup = optgroup.previousSibling;\n\t\t} else {\n\t\t\toptgroup = optgroup.nextSibling;\n\t\t}\n\n\t\tif( !optgroup ){\n\t\t\treturn;\n\t\t}\n\n\t\toptions\t\t\t\t= optgroup.querySelectorAll('[data-selectable]');\n\t\toption\t\t\t\t= options[ Math.min(options.length - 1, index) ];\n\n\t\tif( option ){\n\t\t\tself.setActiveOption(option);\n\t\t}\n\n\t});\n\n});\n"],"names":["KEY_LEFT","KEY_RIGHT","parentMatch","target","selector","wrapper","contains","matches","parentNode","nodeIndex","el","amongst","nodeName","i","previousElementSibling","TomSelect","define","options","self","orig_keydown","onKeyDown","hook","evt","index","option","optgroup","isOpen","keyCode","constants","apply","arguments","ignoreHover","activeOption","previousSibling","nextSibling","querySelectorAll","Math","min","length","setActiveOption"],"mappings":";;;;;;;;;;;;;;;CAGO,IAAMA,QAAQ,GAAK,EAAnB;CAEA,IAAMC,SAAS,GAAK,EAApB;;CCJP;;;;;;;CAmIA;;;;;;CAKO,SAASC,WAAT,CAAqBC,MAArB,EAA6BC,QAA7B,EAAuCC,OAAvC,EAAgD;CAEtD,MAAIA,OAAO,IAAI,CAACA,OAAO,CAACC,QAAR,CAAiBH,MAAjB,CAAhB,EAA0C;CACzC;CACA;;CAED,SAAOA,MAAM,IAAIA,MAAM,CAACI,OAAxB,EAAiC;CAEhC,QAAIJ,MAAM,CAACI,OAAP,CAAeH,QAAf,CAAJ,EAA8B;CAC7B,aAAOD,MAAP;CACA;;CAEDA,IAAAA,MAAM,GAAGA,MAAM,CAACK,UAAhB;CACA;CACD;CAyCD;;;;;CAIO,SAASC,SAAT,CAAoBC,EAApB,EAAwBC,OAAxB,EAAiC;CACvC,MAAI,CAACD,EAAL,EAAS,OAAO,CAAC,CAAR;CAETC,EAAAA,OAAO,GAAGA,OAAO,IAAID,EAAE,CAACE,QAAxB;CAEA,MAAIC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AX,IAAAA,MAAM,GAAMP,OAAO,CAAEmB,IAAI,CAACC,GAAL,CAASpB,OAAO,CAACqB,MAAR,GAAiB,CAA1B,EAA6Bf,KAA7B,CAAF,CAAnB;;CAEA,QAAIC,MAAJ,EAAY;CACXN,MAAAA,IAAI,CAACqB,eAAL,CAAqBf,MAArB;CACA;CAED,GA5BD;CA8BA,CAnCc,CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"optgroup_columns.js","sources":["../../../src/constants.js","../../../src/vanilla.js","../../../src/plugins/optgroup_columns/plugin.js"],"sourcesContent":["export const KEY_A\t\t\t\t= 65;\nexport const KEY_RETURN\t\t= 13;\nexport const KEY_ESC\t\t\t= 27;\nexport const KEY_LEFT\t\t\t= 37;\nexport const KEY_UP\t\t\t= 38;\nexport const KEY_RIGHT\t\t\t= 39;\nexport const KEY_DOWN\t\t\t= 40;\nexport const KEY_BACKSPACE\t\t= 8;\nexport const KEY_DELETE\t\t= 46;\nexport const KEY_SHIFT\t\t\t= 16;\nexport const KEY_CTRL\t\t\t= 17;\nexport const KEY_TAB\t\t\t= 9;\n","\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {any} query .. should be {HTMLElement|string|JQuery}\n * @return {HTMLElement}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.querySelector(':first-child');\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n\n/**\n * Get the closest node to the evt.target matching the selector\n * Stops at wrapper\n *\n */\nexport function parentMatch(target, selector, wrapper ){\n\n\tif( wrapper && !wrapper.contains(target) ){\n\t\treturn;\n\t}\n\n\twhile( target && target.matches ){\n\n\t\tif( target.matches(selector) ){\n\t\t\treturn target;\n\t\t}\n\n\t\ttarget = target.parentNode;\n\t}\n}\n\n/**\n * Get the first or last item from a querySelectorAll result\n *\n * > 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","/**\n * Plugin: \"optgroup_columns\" (Tom Select.js)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\n\nimport TomSelect from '../../tom-select.js';\nimport * as constants from '../../constants.js';\nimport { parentMatch, nodeIndex } from '../../vanilla.js';\n\nexport default TomSelect.define('optgroup_columns', function(options) {\n\tvar self = this;\n\n\tvar orig_keydown = self.onKeyDown;\n\n\tself.hook('instead','onKeyDown',function( evt ) {\n\t\tvar index, option, options, optgroup;\n\n\t\tif( !self.isOpen || !(evt.keyCode === constants.KEY_LEFT || evt.keyCode === constants.KEY_RIGHT)) {\n\t\t\treturn orig_keydown.apply(self,arguments);\n\t\t}\n\n\t\tself.ignoreHover\t= true;\n\t\toptgroup\t\t\t= parentMatch(self.activeOption,'[data-group]');\n\t\tindex\t\t\t\t= nodeIndex(self.activeOption,'[data-selectable]');\n\n\t\tif( evt.keyCode === constants.KEY_LEFT ){\n\t\t\toptgroup = optgroup.previousSibling;\n\t\t} else {\n\t\t\toptgroup = optgroup.nextSibling;\n\t\t}\n\n\t\tif( !optgroup ){\n\t\t\treturn;\n\t\t}\n\n\t\toptions\t\t\t\t= optgroup.querySelectorAll('[data-selectable]');\n\t\toption\t\t\t\t= options[ Math.min(options.length - 1, index) ];\n\n\t\tif( option ){\n\t\t\tself.setActiveOption(option);\n\t\t}\n\n\t});\n\n});\n"],"names":["KEY_LEFT","KEY_RIGHT","parentMatch","target","selector","wrapper","contains","matches","parentNode","nodeIndex","el","amongst","nodeName","i","previousElementSibling","TomSelect","define","options","self","orig_keydown","onKeyDown","hook","evt","index","option","optgroup","isOpen","keyCode","constants","apply","arguments","ignoreHover","activeOption","previousSibling","nextSibling","querySelectorAll","Math","min","length","setActiveOption"],"mappings":";;;;;;;;;;;;;;;CAGO,IAAMA,QAAQ,GAAK,EAAnB;CAEA,IAAMC,SAAS,GAAK,EAApB;;CCJP;;;;;;;CA2GA;;;;;;CAKO,SAASC,WAAT,CAAqBC,MAArB,EAA6BC,QAA7B,EAAuCC,OAAvC,EAAgD;CAEtD,MAAIA,OAAO,IAAI,CAACA,OAAO,CAACC,QAAR,CAAiBH,MAAjB,CAAhB,EAA0C;CACzC;CACA;;CAED,SAAOA,MAAM,IAAIA,MAAM,CAACI,OAAxB,EAAiC;CAEhC,QAAIJ,MAAM,CAACI,OAAP,CAAeH,QAAf,CAAJ,EAA8B;CAC7B,aAAOD,MAAP;CACA;;CAEDA,IAAAA,MAAM,GAAGA,MAAM,CAACK,UAAhB;CACA;CACD;CAyCD;;;;;CAIO,SAASC,SAAT,CAAoBC,EAApB,EAAwBC,OAAxB,EAAiC;CACvC,MAAI,CAACD,EAAL,EAAS,OAAO,CAAC,CAAR;CAETC,EAAAA,OAAO,GAAGA,OAAO,IAAID,EAAE,CAACE,QAAxB;CAEA,MAAIC,CAAC,GAAG,CAAR;;CACA,SAAOH,EAAE,GAAGA,EAAE,CAACI,sBAAf,EAAuC;CAEtC,QAAIJ,EAAE,CAACH,OAA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Bf,KAA7B,CAAF,CAAnB;;CAEA,QAAIC,MAAJ,EAAY;CACXN,MAAAA,IAAI,CAACqB,eAAL,CAAqBf,MAArB;CACA;CAED,GA5BD;CA8BA,CAnCc,CAAf;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/plugins/remove_button.js b/dist/js/plugins/remove_button.js index 289302ad..d5c6bbc9 100644 --- a/dist/js/plugins/remove_button.js +++ b/dist/js/plugins/remove_button.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -17,8 +17,8 @@ * Return a dom element from either a dom query string, jQuery object, a dom element or html string * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 * - * @param {mixed} query - * @return {Element} + * @param {any} query .. should be {HTMLElement|string|JQuery} + * @return {HTMLElement} */ function getDom(query) { if (query.jquery) { @@ -33,17 +33,27 @@ var div = document.createElement('div'); div.innerHTML = query.trim(); // Never return a text node of whitespace as the result - return div.firstChild; + return div.querySelector(':first-child'); } return document.querySelector(query); } /** - * Determines if the provided value has been defined. + * Converts a scalar to its best string representation + * for hash keys and HTML attribute values. * - * @param {mixed} object - * @returns {boolean} + * Transformations: + * 'str' -> 'str' + * null -> '' + * undefined -> '' + * true -> '1' + * false -> '0' + * 0 -> '0' + * 1 -> '1' + * + * @param {string} value + * @returns {string|null} */ /** * Escapes a string for use within HTML. diff --git a/dist/js/plugins/remove_button.js.map b/dist/js/plugins/remove_button.js.map index ecec46d0..ff2805fe 100644 --- a/dist/js/plugins/remove_button.js.map +++ b/dist/js/plugins/remove_button.js.map @@ -1 +1 @@ -{"version":3,"file":"remove_button.js","sources":["../../../src/vanilla.js","../../../src/utils.js","../../../src/plugins/remove_button/plugin.js"],"sourcesContent":["\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {mixed} query\n * @return {Element}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.firstChild;\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n/**\n * Delegate Event\n *\n */\nexport function onEvent( el, eventName, elementSelector, handler ){\n\n\tlet event_names\t= eventName.split(/\\s/);\n\n\t// create intermediate handler that can be used for all event names\n\t// loop parent nodes from the target to the delegation node\n\tlet _handler = function(e) {\n\t\tvar target_match = parentMatch(e.target, elementSelector, el);\n\t\tif( target_match ){\n\t\t\te.delegateTarget = target_match;\n\t\t\thandler.call(target_match, e);\n\t\t}\n\t};\n\n\tfor( let i = 0; i 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","/**\n * Determines if the provided value has been defined.\n *\n * @param {mixed} object\n * @returns {boolean}\n */\nexport function isset(object) {\n\treturn typeof object !== 'undefined';\n};\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n * @param {string} value\n * @returns {string|null}\n */\nexport function hash_key(value) {\n\tif (typeof value === 'undefined' || value === null) return null;\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n * @param {string} str\n * @returns {string}\n */\nexport function escape_html(str) {\n\treturn (str + '')\n\t\t.replace(/&/g, '&')\n\t\t.replace(//g, '>')\n\t\t.replace(/\"/g, '"');\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n * @param {object} self\n * @param {array} types\n * @param {function} fn\n */\nexport function debounce_events( self, types, fn) {\n\tvar type;\n\tvar trigger = self.trigger;\n\tvar event_args = {};\n\n\t// override trigger method\n\tself.trigger = function() {\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor (type in event_args) {\n\t\tif (event_args.hasOwnProperty(type)) {\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * @param {object} input\n * @returns {object}\n */\nexport function getSelection(input) {\n\treturn {\n\t\tstart\t: input.selectionStart,\n\t\tlength\t: input.selectionEnd - input.selectionStart,\n\t};\n};\n","/**\n * Plugin: \"remove_button\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\nimport TomSelect from '../../tom-select.js';\nimport { getDom } from '../../vanilla.js';\nimport { escape_html } from '../../utils.js';\n\nexport default TomSelect.define('remove_button',function(options) {\n\n\toptions = Object.assign({\n\t\t\tlabel : '×',\n\t\t\ttitle : 'Remove',\n\t\t\tclassName : 'remove',\n\t\t\tappend : true\n\t\t}, options);\n\n\n\t//options.className = 'remove-single';\n\tvar self\t\t\t= this;\n\n\t// override the render method to add remove button to each item\n\tif( !options.append ){\n\t\treturn;\n\t}\n\n\tvar html = '' + options.label + '';\n\n\tself.hook('after','setupTemplates',function(){\n\n\t\tvar orig_render_item = self.settings.render.item;\n\n\t\tself.settings.render.item = function(){\n\n\t\t\tvar rendered = getDom(orig_render_item.apply(self, arguments));\n\n\t\t\tvar close_button = getDom(html);\n\t\t\trendered.appendChild(close_button);\n\n\t\t\tclose_button.addEventListener('mousedown',function(evt){\n\t\t\t\tevt.preventDefault();\n\t\t\t\tevt.stopPropagation();\n\t\t\t});\n\n\t\t\tclose_button.addEventListener('click',function(evt){\n\t\t\t\tevt.preventDefault();\n\t\t\t\tevt.stopPropagation();\n\n\t\t\t\t// propagating will trigger the dropdown to show for single mode\n\t\t\t\tif( self.settings.mode !== 'single' ){\n\t\t\t\t\tevt.stopPropagation();\n\t\t\t\t}\n\n\t\t\t\tif (self.isLocked) return;\n\n\t\t\t\tvar value = rendered.dataset.value;\n\t\t\t\tself.removeItem(value);\n\t\t\t\tself.refreshOptions(false);\n\t\t\t});\n\n\t\t\treturn rendered;\n\t\t};\n\n\t});\n\n\n});\n"],"names":["getDom","query","jquery","HTMLElement","indexOf","div","document","createElement","innerHTML","trim","firstChild","querySelector","escape_html","str","replace","TomSelect","define","options","Object","assign","label","title","className","append","self","html","hook","orig_render_item","settings","render","item","rendered","apply","arguments","close_button","appendChild","addEventListener","evt","preventDefault","stopPropagation","mode","isLocked","value","dataset","removeItem","refreshOptions"],"mappings":";;;;;;;;;;;;;;;CACA;;;;;;;CAOO,SAASA,MAAT,CAAiBC,KAAjB,EAAwB;CAE9B,MAAIA,KAAK,CAACC,MAAV,EAAkB;CACjB,WAAOD,KAAK,CAAC,CAAD,CAAZ;CACA;;CAED,MAAIA,KAAK,YAAYE,WAArB,EAAk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AAlB,EAAmC,YAAU;CAE5C,QAAIC,gBAAgB,GAAGH,IAAI,CAACI,QAAL,CAAcC,MAAd,CAAqBC,IAA5C;;CAEAN,IAAAA,IAAI,CAACI,QAAL,CAAcC,MAAd,CAAqBC,IAArB,GAA4B,YAAU;CAErC,UAAIC,QAAQ,GAAG/B,MAAM,CAAC2B,gBAAgB,CAACK,KAAjB,CAAuBR,IAAvB,EAA6BS,SAA7B,CAAD,CAArB;CAEA,UAAIC,YAAY,GAAGlC,MAAM,CAACyB,IAAD,CAAzB;CACAM,MAAAA,QAAQ,CAACI,WAAT,CAAqBD,YAArB;CAEAA,MAAAA,YAAY,CAACE,gBAAb,CAA8B,WAA9B,EAA0C,UAASC,GAAT,EAAa;CACtDA,QAAAA,GAAG,CAACC,cAAJ;CACAD,QAAAA,GAAG,CAACE,eAAJ;CACA,OAHD;CAKAL,MAAAA,YAAY,CAACE,gBAAb,CAA8B,OAA9B,EAAsC,UAASC,GAAT,EAAa;CAClDA,QAAAA,GAAG,CAACC,cAAJ;CACAD,QAAAA,GAAG,CAACE,eAAJ,GAFkD;;CAKlD,YAAIf,IAAI,CAACI,QAAL,CAAcY,IAAd,KAAuB,QAA3B,EAAqC;CACpCH,UAAAA,GAAG,CAACE,eAAJ;CACA;;CAED,YAAIf,IAAI,CAACiB,QAAT,EAAmB;CAEnB,YAAIC,KAAK,GAAGX,QAAQ,CAACY,OAAT,CAAiBD,KAA7B;CACAlB,QAAAA,IAAI,CAACoB,UAAL,CAAgBF,KAAhB;CACAlB,QAAAA,IAAI,CAACqB,cAAL,CAAoB,KAApB;CACA,OAdD;CAgBA,aAAOd,QAAP;CACA,KA7BD;CA+BA,GAnCD;CAsCA,CA1Dc,CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"remove_button.js","sources":["../../../src/vanilla.js","../../../src/utils.js","../../../src/plugins/remove_button/plugin.js"],"sourcesContent":["\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * @param {any} query .. should be {HTMLElement|string|JQuery}\n * @return {HTMLElement}\n */\nexport function getDom( query ){\n\n\tif( query.jquery ){\n\t\treturn query[0];\n\t}\n\n\tif( query instanceof HTMLElement ){\n\t\treturn query;\n\t}\n\n\tif( query.indexOf('<') > -1 ){\n\t\tlet div = document.createElement('div');\n\t\tdiv.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n\t\treturn div.querySelector(':first-child');\n\t}\n\n\treturn document.querySelector(query);\n};\n\n/**\n * Dispatch an event\n *\n */\nexport function triggerEvent( dom_el, event_name ){\n\tvar event = document.createEvent('HTMLEvents');\n\tevent.initEvent(event_name, true, false);\n\tdom_el.dispatchEvent(event)\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nexport function applyCSS( dom_el, css){\n\tObject.keys(css).forEach(function(name){\n\t\tdom_el.style[name] = css[name];\n\t});\n}\n\n\n/**\n * Add css classes\n *\n */\nexport function addClasses( elmts ){\n\n\tvar classes\t\t= classesArray.apply(null,arguments);\n\telmts\t\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map( cls => {\n\t\t\tel.classList.add( cls );\n\t\t});\n\t});\n}\n\n/**\n * Remove css classes\n *\n */\n export function removeClasses( elmts ){\n\n \tvar classes \t= classesArray.apply(null,arguments);\n\telmts\t\t= castAsArray(elmts);\n\n\telmts.map( el => {\n\t\tclasses.map(cls => {\n\t \t\tel.classList.remove( cls );\n\t\t});\n \t});\n }\n\n\n/**\n * Return arguments\n *\n */\nexport function classesArray(){\n\tvar classes = [];\n\tfor( let i = 1; i < arguments.length; i++ ){\n\t\tlet _classes = arguments[i];\n\t\tif( typeof _classes === 'string' ){\n\t\t\t_classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n\t\t}\n\t\tif( Array.isArray(_classes) ){\n\t\t\tclasses = classes.concat(_classes);\n\t\t}\n\t}\n\n\treturn classes.filter(Boolean);\n}\n\nexport function castAsArray(arg){\n\tif( !Array.isArray(arg) ){\n \t\targ = [arg];\n \t}\n\treturn arg;\n}\n\n\n/**\n * Get the closest node to the evt.target matching the selector\n * Stops at wrapper\n *\n */\nexport function parentMatch(target, selector, wrapper ){\n\n\tif( wrapper && !wrapper.contains(target) ){\n\t\treturn;\n\t}\n\n\twhile( target && target.matches ){\n\n\t\tif( target.matches(selector) ){\n\t\t\treturn target;\n\t\t}\n\n\t\ttarget = target.parentNode;\n\t}\n}\n\n/**\n * Get the first or last item from a querySelectorAll result\n *\n * > 0 - right (last)\n * < 0 - left (first)\n *\n */\nexport function querySelectorEnd( el, query, direction){\n\tvar result = el.querySelectorAll(query);\n\tif( !result ){\n\t\treturn;\n\t}\n\n\treturn getTail(result,direction);\n};\n\n\n/**\n * Get the first or last item from an array\n *\n */\nexport function getTail( array, direction ){\n\n\tif( direction > 0 ){\n\t\treturn array[array.length-1];\n\t}\n\n\treturn array[0];\n}\n\n/**\n * Return true if an object is empty\n *\n */\nexport function isEmptyObject(obj){\n\treturn (Object.keys(obj).length === 0);\n}\n\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nexport function nodeIndex( el, amongst ){\n\tif (!el) return -1;\n\n\tamongst = amongst || el.nodeName;\n\n\tvar i = 0;\n\twhile( el = el.previousElementSibling ){\n\n\t\tif( el.matches(amongst) ){\n\t\t\ti++;\n\t\t}\n\t}\n\treturn i;\n}\n","\n\n/**\n * Converts a scalar to its best string representation\n * for hash keys and HTML attribute values.\n *\n * Transformations:\n * 'str' -> 'str'\n * null -> ''\n * undefined -> ''\n * true -> '1'\n * false -> '0'\n * 0 -> '0'\n * 1 -> '1'\n *\n * @param {string} value\n * @returns {string|null}\n */\nexport function hash_key(value) {\n\tif (typeof value === 'undefined' || value === null) return null;\n\tif (typeof value === 'boolean') return value ? '1' : '0';\n\treturn value + '';\n};\n\n/**\n * Escapes a string for use within HTML.\n *\n * @param {string} str\n * @returns {string}\n */\nexport function escape_html(str) {\n\treturn (str + '')\n\t\t.replace(/&/g, '&')\n\t\t.replace(//g, '>')\n\t\t.replace(/\"/g, '"');\n};\n\n\n/**\n * Debounce all fired events types listed in `types`\n * while executing the provided `fn`.\n *\n * @param {object} self\n * @param {array} types\n * @param {function} fn\n */\nexport function debounce_events( self, types, fn) {\n\tvar type;\n\tvar trigger = self.trigger;\n\tvar event_args = {};\n\n\t// override trigger method\n\tself.trigger = function() {\n\t\tvar type = arguments[0];\n\t\tif (types.indexOf(type) !== -1) {\n\t\t\tevent_args[type] = arguments;\n\t\t} else {\n\t\t\treturn trigger.apply(self, arguments);\n\t\t}\n\t};\n\n\t// invoke provided function\n\tfn.apply(self, []);\n\tself.trigger = trigger;\n\n\t// trigger queued events\n\tfor (type in event_args) {\n\t\tif (event_args.hasOwnProperty(type)) {\n\t\t\ttrigger.apply(self, event_args[type]);\n\t\t}\n\t}\n};\n\n\n/**\n * Determines the current selection within a text input control.\n * Returns an object containing:\n * - start\n * - length\n *\n * @param {object} input\n * @returns {object}\n */\nexport function getSelection(input) {\n\treturn {\n\t\tstart\t: input.selectionStart,\n\t\tlength\t: input.selectionEnd - input.selectionStart,\n\t};\n};\n","/**\n * Plugin: \"remove_button\" (Tom Select)\n * Copyright (c) contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n */\nimport TomSelect from '../../tom-select.js';\nimport { getDom } from '../../vanilla.js';\nimport { escape_html } from '../../utils.js';\n\nexport default TomSelect.define('remove_button',function(options) {\n\n\toptions = Object.assign({\n\t\t\tlabel : '×',\n\t\t\ttitle : 'Remove',\n\t\t\tclassName : 'remove',\n\t\t\tappend : true\n\t\t}, options);\n\n\n\t//options.className = 'remove-single';\n\tvar self\t\t\t= this;\n\n\t// override the render method to add remove button to each item\n\tif( !options.append ){\n\t\treturn;\n\t}\n\n\tvar html = '' + options.label + '';\n\n\tself.hook('after','setupTemplates',function(){\n\n\t\tvar orig_render_item = self.settings.render.item;\n\n\t\tself.settings.render.item = function(){\n\n\t\t\tvar rendered = getDom(orig_render_item.apply(self, arguments));\n\n\t\t\tvar close_button = getDom(html);\n\t\t\trendered.appendChild(close_button);\n\n\t\t\tclose_button.addEventListener('mousedown',function(evt){\n\t\t\t\tevt.preventDefault();\n\t\t\t\tevt.stopPropagation();\n\t\t\t});\n\n\t\t\tclose_button.addEventListener('click',function(evt){\n\t\t\t\tevt.preventDefault();\n\t\t\t\tevt.stopPropagation();\n\n\t\t\t\t// propagating will trigger the dropdown to show for single mode\n\t\t\t\tif( self.settings.mode !== 'single' ){\n\t\t\t\t\tevt.stopPropagation();\n\t\t\t\t}\n\n\t\t\t\tif (self.isLocked) return;\n\n\t\t\t\tvar value = rendered.dataset.value;\n\t\t\t\tself.removeItem(value);\n\t\t\t\tself.refreshOptions(false);\n\t\t\t});\n\n\t\t\treturn rendered;\n\t\t};\n\n\t});\n\n\n});\n"],"names":["getDom","query","jquery","HTMLElement","indexOf","div","document","createElement","innerHTML","trim","querySelector","escape_html","str","replace","TomSelect","define","options","Object","assign","label","title","className","append","self","html","hook","orig_render_item","settings","render","item","rendered","apply","arguments","close_button","appendChild","addEventListener","evt","preventDefault","stopPropagation","mode","isLocked","value","dataset","removeItem","refreshOptions"],"mappings":";;;;;;;;;;;;;;;CACA;;;;;;;CAOO,SAASA,MAAT,CAAiBC,KAAjB,EAAwB;CAE9B,MAAIA,KAAK,CAACC,MAAV,EAAkB;CACjB,WAAOD,KAAK,CAAC,CAAD,CAAZ;CACA;;CAED,MAAIA,KAAK,YAAYE,WAArB,EAAkC;CACjC,WAAOF,KAAP;CACA;;CAED,MAAIA,KAAK,CAACG,OAAN,CAAc,GA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,gBAAgB,GAAGH,IAAI,CAACI,QAAL,CAAcC,MAAd,CAAqBC,IAA5C;;CAEAN,IAAAA,IAAI,CAACI,QAAL,CAAcC,MAAd,CAAqBC,IAArB,GAA4B,YAAU;CAErC,UAAIC,QAAQ,GAAG9B,MAAM,CAAC0B,gBAAgB,CAACK,KAAjB,CAAuBR,IAAvB,EAA6BS,SAA7B,CAAD,CAArB;CAEA,UAAIC,YAAY,GAAGjC,MAAM,CAACwB,IAAD,CAAzB;CACAM,MAAAA,QAAQ,CAACI,WAAT,CAAqBD,YAArB;CAEAA,MAAAA,YAAY,CAACE,gBAAb,CAA8B,WAA9B,EAA0C,UAASC,GAAT,EAAa;CACtDA,QAAAA,GAAG,CAACC,cAAJ;CACAD,QAAAA,GAAG,CAACE,eAAJ;CACA,OAHD;CAKAL,MAAAA,YAAY,CAACE,gBAAb,CAA8B,OAA9B,EAAsC,UAASC,GAAT,EAAa;CAClDA,QAAAA,GAAG,CAACC,cAAJ;CACAD,QAAAA,GAAG,CAACE,eAAJ,GAFkD;;CAKlD,YAAIf,IAAI,CAACI,QAAL,CAAcY,IAAd,KAAuB,QAA3B,EAAqC;CACpCH,UAAAA,GAAG,CAACE,eAAJ;CACA;;CAED,YAAIf,IAAI,CAACiB,QAAT,EAAmB;CAEnB,YAAIC,KAAK,GAAGX,QAAQ,CAACY,OAAT,CAAiBD,KAA7B;CACAlB,QAAAA,IAAI,CAACoB,UAAL,CAAgBF,KAAhB;CACAlB,QAAAA,IAAI,CAACqB,cAAL,CAAoB,KAApB;CACA,OAdD;CAgBA,aAAOd,QAAP;CACA,KA7BD;CA+BA,GAnCD;CAsCA,CA1Dc,CAAf;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/plugins/restore_on_backspace.js b/dist/js/plugins/restore_on_backspace.js index b9ada1c3..a6719725 100644 --- a/dist/js/plugins/restore_on_backspace.js +++ b/dist/js/plugins/restore_on_backspace.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ diff --git a/dist/js/tom-select.base.js b/dist/js/tom-select.base.js index d13b0325..963e5bbb 100644 --- a/dist/js/tom-select.base.js +++ b/dist/js/tom-select.base.js @@ -1,5 +1,5 @@ /** -* Tom Select v1.0.0-rc.2 +* Tom Select v1.0.0-rc.3 * Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -86,104 +86,115 @@ */ function MicroPlugin(Interface) { Interface.plugins = {}; - /** - * Initializes the listed plugins (with options). - * Acceptable formats: - * - * List (without options): - * ['a', 'b', 'c'] - * - * List (with options): - * [{'name': 'a', options: {}}, {'name': 'b', options: {}}] - * - * Hash (with options): - * {'a': { ... }, 'b': { ... }, 'c': { ... }} - * - * @param {mixed} plugins - */ - - Interface.prototype.initializePlugins = function (plugins) { - var i, n, key; - var self = this; - var queue = []; - self.plugins = { - names: [], - settings: {}, - requested: {}, - loaded: {} - }; + return /*#__PURE__*/function (_Interface) { + _inheritsLoose(mixin, _Interface); - if (Array.isArray(plugins)) { - for (i = 0, n = plugins.length; i < n; i++) { - if (typeof plugins[i] === 'string') { - queue.push(plugins[i]); - } else { - self.plugins.settings[plugins[i].name] = plugins[i].options; - queue.push(plugins[i].name); - } - } - } else if (plugins) { - for (key in plugins) { - if (plugins.hasOwnProperty(key)) { - self.plugins.settings[key] = plugins[key]; - queue.push(key); - } - } + function mixin() { + return _Interface.apply(this, arguments) || this; } - while (queue.length) { - self.require(queue.shift()); + /** + * Registers a plugin. + * + * @param {string} name + * @param {function} fn + */ + mixin.define = function define(name, fn) { + Interface.plugins[name] = { + 'name': name, + 'fn': fn + }; } - }; + /** + * Initializes the listed plugins (with options). + * Acceptable formats: + * + * List (without options): + * ['a', 'b', 'c'] + * + * List (with options): + * [{'name': 'a', options: {}}, {'name': 'b', options: {}}] + * + * Hash (with options): + * {'a': { ... }, 'b': { ... }, 'c': { ... }} + * + * @param {array|object} plugins + */ + ; - Interface.prototype.loadPlugin = function (name) { - var self = this; - var plugins = self.plugins; - var plugin = Interface.plugins[name]; + var _proto = mixin.prototype; - if (!Interface.plugins.hasOwnProperty(name)) { - throw new Error('Unable to find "' + name + '" plugin'); - } + _proto.initializePlugins = function initializePlugins(plugins) { + var i, n, key; + var self = this; + var queue = []; + self.plugins = { + names: [], + settings: {}, + requested: {}, + loaded: {} + }; - plugins.requested[name] = true; - plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]); - plugins.names.push(name); - }; - /** - * Initializes a plugin. - * - * @param {string} name - */ + if (Array.isArray(plugins)) { + for (i = 0, n = plugins.length; i < n; i++) { + if (typeof plugins[i] === 'string') { + queue.push(plugins[i]); + } else { + self.plugins.settings[plugins[i].name] = plugins[i].options; + queue.push(plugins[i].name); + } + } + } else if (plugins) { + for (key in plugins) { + if (plugins.hasOwnProperty(key)) { + self.plugins.settings[key] = plugins[key]; + queue.push(key); + } + } + } + while (queue.length) { + self.require(queue.shift()); + } + }; - Interface.prototype.require = function (name) { - var self = this; - var plugins = self.plugins; + _proto.loadPlugin = function loadPlugin(name) { + var self = this; + var plugins = self.plugins; + var plugin = Interface.plugins[name]; - if (!self.plugins.loaded.hasOwnProperty(name)) { - if (plugins.requested[name]) { - throw new Error('Plugin has circular dependency ("' + name + '")'); + if (!Interface.plugins.hasOwnProperty(name)) { + throw new Error('Unable to find "' + name + '" plugin'); } - self.loadPlugin(name); + plugins.requested[name] = true; + plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]); + plugins.names.push(name); } + /** + * Initializes a plugin. + * + * @param {string} name + */ + ; - return plugins.loaded[name]; - }; - /** - * Registers a plugin. - * - * @param {string} name - * @param {function} fn - */ + _proto.require = function require(name) { + var self = this; + var plugins = self.plugins; + + if (!self.plugins.loaded.hasOwnProperty(name)) { + if (plugins.requested[name]) { + throw new Error('Plugin has circular dependency ("' + name + '")'); + } + self.loadPlugin(name); + } - Interface.define = function (name, fn) { - Interface.plugins[name] = { - 'name': name, - 'fn': fn + return plugins.loaded[name]; }; - }; + + return mixin; + }(Interface); } /** @@ -384,10 +395,14 @@ * If an item is not a match, 0 will be returned by the function. * * @param {object|string} search - * @param {object} options (optional) + * @param {object} options * @returns {function} */ _proto.getScoreFunction = function getScoreFunction(search, options) { + if (options === void 0) { + options = null; + } + var self, fields, tokens, token_count, nesting; self = this; search = self.prepareSearch(search, options); @@ -399,7 +414,7 @@ * Calculates how close of a match the * given value is against a search token. * - * @param {mixed} value + * @param {string} value * @param {object} token * @return {number} */ @@ -503,7 +518,7 @@ * * @param {string} name * @param {object} result - * @return {mixed} + * @return {string} */ get_field = function get_field(name, result) { @@ -826,15 +841,6 @@ } }; - /** - * Determines if the provided value has been defined. - * - * @param {mixed} object - * @returns {boolean} - */ - function isset(object) { - return typeof object !== 'undefined'; - } /** * Converts a scalar to its best string representation * for hash keys and HTML attribute values. @@ -851,7 +857,6 @@ * @param {string} value * @returns {string|null} */ - function hash_key(value) { if (typeof value === 'undefined' || value === null) return null; if (typeof value === 'boolean') return value ? '1' : '0'; @@ -1079,8 +1084,8 @@ * Return a dom element from either a dom query string, jQuery object, a dom element or html string * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518 * - * @param {mixed} query - * @return {Element} + * @param {any} query .. should be {HTMLElement|string|JQuery} + * @return {HTMLElement} */ function getDom(query) { if (query.jquery) { @@ -1095,7 +1100,7 @@ var div = document.createElement('div'); div.innerHTML = query.trim(); // Never return a text node of whitespace as the result - return div.firstChild; + return div.querySelector(':first-child'); } return document.querySelector(query); @@ -1177,28 +1182,6 @@ return arg; } - /** - * Delegate Event - * - */ - - function onEvent(el, eventName, elementSelector, handler) { - var event_names = eventName.split(/\s/); // create intermediate handler that can be used for all event names - // loop parent nodes from the target to the delegation node - - var _handler = function _handler(e) { - var target_match = parentMatch(e.target, elementSelector, el); - - if (target_match) { - e.delegateTarget = target_match; - handler.call(target_match, e); - } - }; - - for (var i = 0; i < event_names.length; i++) { - el.addEventListener(event_names[i], _handler, true); - } - } /** * Get the closest node to the evt.target matching the selector * Stops at wrapper @@ -1274,13 +1257,13 @@ return i; } - var TomSelect = /*#__PURE__*/function (_MicroEvent) { - _inheritsLoose(TomSelect, _MicroEvent); + var TomSelect = /*#__PURE__*/function (_MicroPlugin) { + _inheritsLoose(TomSelect, _MicroPlugin); function TomSelect(input, settings) { var _this; - _this = _MicroEvent.call(this) || this; + _this = _MicroPlugin.call(this) || this; var dir, self = _assertThisInitialized(_this); @@ -1292,48 +1275,56 @@ } input.tomselect = self; - settings = getSettings(input, settings); // detect rtl environment + /** + * @param {HTMLInputElement} control_input + */ + + _this.control_input = null; + _this.wrapper = null; + _this.dropdown = null; + _this._destroy = null; + _this.control = null; + _this.sifter = null; + _this.dropdown_content = null; // detect rtl environment var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null); dir = computedStyle.getPropertyValue('direction'); // setup default state - Object.assign(self, { - order: 0, - settings: settings, - input: input, - tabIndex: input.getAttribute('tabindex') || '', - is_select_tag: input.tagName.toLowerCase() === 'select', - rtl: /rtl/i.test(dir), - highlightedValue: null, - isBlurring: false, - isOpen: false, - isDisabled: false, - isRequired: input.required, - isInvalid: false, - isLocked: false, - isFocused: false, - isInputHidden: false, - isSetup: false, - ignoreFocus: false, - ignoreBlur: false, - ignoreHover: false, - hasOptions: false, - currentResults: null, - lastValue: '', - caretPos: 0, - loading: 0, - loadedSearches: {}, - activeOption: null, - activeItems: [], - optgroups: {}, - options: {}, - userOptions: {}, - items: [], - renderCache: { - 'item': {}, - 'option': {} - } - }); // debounce user defined load() if loadThrottle > 0 + _this.order = 0; + _this.settings = getSettings(input, settings); + _this.input = input; + _this.tabIndex = input.getAttribute('tabindex') || ''; + _this.is_select_tag = input.tagName.toLowerCase() === 'select'; + _this.rtl = /rtl/i.test(dir); + _this.highlightedValue = null; + _this.isBlurring = false; + _this.isOpen = false; + _this.isDisabled = false; + _this.isRequired = input.required; + _this.isInvalid = false; + _this.isLocked = false; + _this.isFocused = false; + _this.isInputHidden = false; + _this.isSetup = false; + _this.ignoreFocus = false; + _this.ignoreBlur = false; + _this.ignoreHover = false; + _this.hasOptions = false; + _this.currentResults = null; + _this.lastValue = ''; + _this.caretPos = 0; + _this.loading = 0; + _this.loadedSearches = {}; + _this.activeOption = null; + _this.activeItems = []; + _this.optgroups = {}; + _this.options = {}; + _this.userOptions = {}; + _this.items = []; + _this.renderCache = { + 'item': {}, + 'option': {} + }; // debounce user defined load() if loadThrottle > 0 if (self.settings.load && self.settings.loadThrottle) { self.settings.load = self.loadDebounce(self.settings.load, self.settings.loadThrottle); @@ -1341,7 +1332,7 @@ self.sifter = new Sifter(_this.options, { - diacritics: settings.diacritics + diacritics: self.settings.diacritics }); self.setupOptions(self.settings.options, self.settings.optgroups); delete self.settings.optgroups; @@ -1453,27 +1444,30 @@ self.settings.splitOn = new RegExp('\\s*' + delimiterEscaped + '+\\s*'); } - control_input.type = input.type; self.control = control; self.control_input = control_input; self.wrapper = wrapper; self.dropdown = dropdown; self.dropdown_content = dropdown_content; - onEvent(dropdown, 'mouseenter', '[data-selectable]', function () { - return self.onOptionHover.apply(self, arguments); - }); + self.control_input.type = input.type; + dropdown.addEventListener('mouseenter', function (e) { + var target_match = parentMatch(e.target, '[data-selectable]', dropdown); + + if (target_match) { + return self.onOptionHover.call(self, e, target_match); + } + }, true); control.addEventListener('mousedown', function (evt) { var target_match = parentMatch(evt.target, '.' + self.settings.itemClass, control); if (target_match) { - evt.delegateTarget = target_match; - return self.onItemSelect.call(self, evt); + return self.onItemSelect.call(self, evt, target_match); } return self.onMouseDown.call(self, evt); }); control.addEventListener('click', function () { - return self.onClick.apply(self, arguments); + self.onClick.apply(self, arguments); }); control_input.addEventListener('mousedown', function (e) { e.stopPropagation(); @@ -1503,8 +1497,10 @@ // clicking on an option should selectit var doc_mousedown = function doc_mousedown(e) { - // outside of this instance - if (!self.wrapper.contains(e.target)) { + // if dropdownParent is set, options may not be within self.wrapper + var option = parentMatch(e.target, '[data-selectable]', self.dropdown); // outside of this instance + + if (!option && !self.wrapper.contains(e.target)) { if (self.isFocused) { self.blur(e.target); } @@ -1513,12 +1509,10 @@ } e.preventDefault(); - e.stopPropagation(); // option - - var option = parentMatch(e.target, '[data-selectable]', self.wrapper); + e.stopPropagation(); if (option) { - self.onOptionSelect(option, true); + self.onOptionSelect(e, option); } }; @@ -1686,7 +1680,6 @@ * has a click event. * * @param {object} e - * @return {boolean} */ ; @@ -1722,7 +1715,7 @@ // toggle dropdown self.isOpen ? self.close() : self.open(); } else { - self.setActiveItem(null); + self.setActiveItem(); } return false; @@ -1863,7 +1856,7 @@ case KEY_RETURN: if (self.isOpen && self.activeOption) { - self.onOptionSelect(self.activeOption); + self.onOptionSelect(e, self.activeOption); e.preventDefault(); } @@ -1882,7 +1875,7 @@ case KEY_TAB: if (self.settings.selectOnTab && self.isOpen && self.activeOption) { - self.onOptionSelect(self.activeOption); // prevent default [tab] behaviour of jump to the next field + self.onOptionSelect(e, self.activeOption); // prevent default [tab] behaviour of jump to the next field // if select isFull, then the dropdown won't be open and [tab] will work normally e.preventDefault(); @@ -1946,12 +1939,16 @@ /** * Triggered on focus. * - * @param {object} e (optional) + * @param {object} e * @returns {boolean} */ ; _proto.onFocus = function onFocus(e) { + if (e === void 0) { + e = null; + } + var self = this; var wasFocused = self.isFocused; @@ -1968,7 +1965,7 @@ if (!self.activeItems.length) { self.showInput(); - self.setActiveItem(null); + self.setActiveItem(); self.refreshOptions(!!self.settings.openOnFocus); } @@ -1978,7 +1975,7 @@ * Triggered on blur. * * @param {object} e - * @param {Element} dest + * @param {HTMLElement} dest */ ; @@ -1997,8 +1994,8 @@ var deactivate = function deactivate() { self.close(); - self.setActiveItem(null); - self.setActiveOption(null); + self.setActiveItem(); + self.setActiveOption(); self.setCaret(self.items.length); self.refreshState(); // IE11 bug: element still marked as active @@ -2019,46 +2016,47 @@ * Triggered when the user rolls over * an option in the autocomplete dropdown menu. * - * @param {object} e + * @param {object} evt + * @param {HTMLElement} option * @returns {boolean} */ ; - _proto.onOptionHover = function onOptionHover(e) { + _proto.onOptionHover = function onOptionHover(evt, option) { if (this.ignoreHover) return; - this.setActiveOption(e.delegateTarget, false); + this.setActiveOption(option, false); } /** * Triggered when the user clicks on an option * in the autocomplete dropdown menu. * - * @param {Element} target - * @param {boolean} is_mouse_event + * @param {object} evt + * @param {HTMLElement} option * @returns {boolean} */ ; - _proto.onOptionSelect = function onOptionSelect(target, is_mouse_event) { + _proto.onOptionSelect = function onOptionSelect(evt, option) { var value, self = this; - if (!target) { + if (!option) { return; } // should not be possible to trigger a option under a disabled optgroup - if (target.parentNode && target.parentNode.matches('[data-disabled]')) { + if (option.parentElement && option.parentElement.matches('[data-disabled]')) { return; } - if (target.classList.contains('create')) { - self.createItem(null, function () { + if (option.classList.contains('create')) { + self.createItem(null, true, function () { if (self.settings.closeAfterSelect) { self.close(); } }); } else { - value = target.dataset.value; + value = option.dataset.value; if (typeof value !== 'undefined') { self.lastQuery = null; @@ -2066,7 +2064,7 @@ if (self.settings.closeAfterSelect) { self.close(); - } else if (!self.settings.hideSelected && is_mouse_event) { + } else if (!self.settings.hideSelected && evt.type && /mouse/.test(evt.type)) { self.setActiveOption(self.getOption(value)); } } @@ -2076,18 +2074,19 @@ * Triggered when the user clicks on an item * that has been selected. * - * @param {object} e + * @param {object} evt + * @param {HTMLElement} item * @returns {boolean} */ ; - _proto.onItemSelect = function onItemSelect(e) { + _proto.onItemSelect = function onItemSelect(evt, item) { var self = this; if (self.isLocked) return; if (self.settings.mode === 'multi') { - e.preventDefault(); - self.setActiveItem(e.delegateTarget, e); + evt.preventDefault(); + self.setActiveItem(item, evt); } } /** @@ -2162,7 +2161,7 @@ * an array. If only one item can be selected, this * returns a string. * - * @returns {mixed} + * @returns {string|array} */ ; @@ -2176,11 +2175,16 @@ /** * Resets the selected items to the given value. * - * @param {mixed} value + * @param {string|array} value + * @param {boolean} silent */ ; _proto.setValue = function setValue(value, silent) { + if (silent === void 0) { + silent = false; + } + var events = silent ? [] : ['change']; debounce_events(this, events, function () { this.clear(silent); @@ -2190,14 +2194,21 @@ /** * Sets the selected item. * - * @param {object} item - * @param {object} e (optional) + * @param {HTMLElement} item + * @param {object} e */ ; _proto.setActiveItem = function setActiveItem(item, e) { + if (item === void 0) { + item = null; + } + + if (e === void 0) { + e = null; + } var eventName; - var i, begin, end, item, swap; + var i, begin, end, swap; var last; if (this.settings.mode === 'single') return; // clear the active selection @@ -2290,6 +2301,14 @@ ; _proto.setActiveOption = function setActiveOption(option, scroll) { + if (option === void 0) { + option = null; + } + + if (scroll === void 0) { + scroll = false; + } + var height_menu, height_item, y; if (option === this.activeOption) { @@ -2302,15 +2321,15 @@ this.activeOption = option; addClasses(option, 'active'); - if (scroll || !isset(scroll)) { + if (scroll) { height_menu = this.dropdown_content.clientHeight; - scroll = this.dropdown_content.scrollTop || 0; + var scrollTop = this.dropdown_content.scrollTop || 0; height_item = this.activeOption.offsetHeight; - y = this.activeOption.getBoundingClientRect().top - this.dropdown_content.getBoundingClientRect().top + scroll; + y = this.activeOption.getBoundingClientRect().top - this.dropdown_content.getBoundingClientRect().top + scrollTop; - if (y + height_item > height_menu + scroll) { + if (y + height_item > height_menu + scrollTop) { this.dropdown_content.scrollTop = y - height_menu + height_item; - } else if (y < scroll) { + } else if (y < scrollTop) { this.dropdown_content.scrollTop = y; } } @@ -2388,11 +2407,15 @@ /** * Forces the control out of focus. * - * @param {Element} dest + * @param {HTMLElement} dest */ ; _proto.blur = function blur(dest) { + if (dest === void 0) { + dest = null; + } + this.control_input.blur(); this.onBlur(null, dest); } @@ -2402,7 +2425,6 @@ * provided query. * * @param {string} query - * @param {object} options * @return {function} */ ; @@ -2497,13 +2519,12 @@ ; _proto.refreshOptions = function refreshOptions(triggerDropdown) { - var i, j, k, n, groups, groups_order, optgroup, optgroups, html, has_create_option; - var active, active_before, create; - - if (typeof triggerDropdown === 'undefined') { + if (triggerDropdown === void 0) { triggerDropdown = true; } + var i, j, k, n, groups, groups_order, optgroup, optgroups, html, has_create_option; + var active, active_before, create; var self = this; var query = self.inputValue(); var results = self.search(query); @@ -2666,7 +2687,7 @@ self.open(); } } else { - self.setActiveOption(null); + self.setActiveOption(); if (triggerDropdown && self.isOpen) { self.close(); @@ -2756,10 +2777,11 @@ ; _proto.addOptionGroup = function addOptionGroup(id, data) { + var hashed_id; data[this.settings.optgroupValueField] = id; - if (id = this.registerOptionGroup(data)) { - this.trigger('optgroup_add', id, data); + if (hashed_id = this.registerOptionGroup(data)) { + this.trigger('optgroup_add', hashed_id, data); } } /** @@ -2913,7 +2935,7 @@ * Returns the dom element of the next or previous dom element of the same type * * @param {object} option - * @param {int} direction can be 1 for next or -1 for previous + * @param {number} direction can be 1 for next or -1 for previous * @param {string} type * @return {object|undefined} */ @@ -2955,7 +2977,7 @@ * Finds the first element with a "data-value" attribute * that matches the given value. * - * @param {mixed} value + * @param {string} value * @param {object} els * @return {object} */ @@ -2988,12 +3010,16 @@ * "Selects" multiple items at once. Adds them to the list * at the current caret position. * - * @param {string} value + * @param {string|array} values * @param {boolean} silent */ ; _proto.addItems = function addItems(values, silent) { + if (silent === void 0) { + silent = false; + } + this.buffer = document.createDocumentFragment(); var children = this.control.children; @@ -3003,9 +3029,9 @@ var items = Array.isArray(values) ? values : [values]; - for (var i = 0, n = items.length; i < n; i++) { - this.isPending = i < n - 1; - this.addItem(items[i], silent); + for (var _i = 0, n = items.length; _i < n; _i++) { + this.isPending = _i < n - 1; + this.addItem(items[_i], silent); } var control = this.control; @@ -3022,6 +3048,10 @@ ; _proto.addItem = function addItem(value, silent) { + if (silent === void 0) { + silent = false; + } + var events = silent ? [] : ['change']; debounce_events(this, events, function () { var item; @@ -3093,10 +3123,15 @@ * the provided value. * * @param {string} value + * @param {boolean} silent */ ; _proto.removeItem = function removeItem(value, silent) { + if (silent === void 0) { + silent = false; + } + var i, idx; var item = this.getItem(value); if (!item) return; @@ -3139,25 +3174,32 @@ * Once this completes, it will be added * to the item list. * - * @param {string} value - * @param {boolean} [triggerDropdown] - * @param {function} [callback] + * @param {string} input + * @param {boolean} triggerDropdown + * @param {function} callback * @return {boolean} */ ; - _proto.createItem = function createItem(input, triggerDropdown) { + _proto.createItem = function createItem(input, triggerDropdown, callback) { + if (input === void 0) { + input = null; + } + + if (triggerDropdown === void 0) { + triggerDropdown = true; + } + + if (callback === void 0) { + callback = null; + } + var self = this; var caret = self.caretPos; var output; input = input || self.inputValue(); - var callback = arguments[arguments.length - 1]; if (typeof callback !== 'function') callback = function callback() {}; - if (typeof triggerDropdown !== 'boolean') { - triggerDropdown = true; - } - if (!self.canCreate(input)) { callback(); return false; @@ -3207,7 +3249,7 @@ this.lastQuery = null; if (this.isSetup) { - this.addItem(this.items); + this.addItems(this.items); } this.refreshState(); @@ -3353,7 +3395,7 @@ applyCSS(self.dropdown, { display: 'none' }); - self.setActiveOption(null); + self.setActiveOption(); self.refreshState(); if (trigger) self.trigger('dropdown_close', self.dropdown); } @@ -3398,7 +3440,7 @@ this.items = []; this.lastQuery = null; this.setCaret(0); - this.setActiveItem(null); + this.setActiveItem(); this.updateOriginalInput({ silent: silent }); @@ -3491,7 +3533,7 @@ * > 0 - right * < 0 - left * - * @param {int} direction + * @param {number} direction * @param {object} e (optional) */ ; @@ -3524,7 +3566,7 @@ if (last_active) { idx = nodeIndex(last_active); this.setCaret(direction > 0 ? idx + 1 : idx); - this.setActiveItem(null); + this.setActiveItem(); } } } @@ -3546,7 +3588,7 @@ /** * Moves the caret to the specified index. * - * @param {int} i + * @param {number} i */ ; @@ -3676,13 +3718,16 @@ * * @param {string} templateName * @param {object} data - * @returns {Element} + * @returns {HTMLElement} */ ; _proto.render = function render(templateName, data) { - var value, id; - var html = ''; + if (data === void 0) { + data = null; + } + + var value, id, html; var self = this; if (templateName === 'option' || templateName === 'item') { @@ -3734,9 +3779,13 @@ ; _proto.clearCache = function clearCache(templateName) { + if (templateName === void 0) { + templateName = null; + } + var self = this; - if (typeof templateName === 'undefined') { + if (templateName === null) { self.renderCache = { 'item': {}, 'option': {} @@ -3830,8 +3879,7 @@ }; return TomSelect; - }(MicroEvent); - MicroPlugin(TomSelect); + }(MicroPlugin(MicroEvent)); return TomSelect; diff --git a/dist/js/tom-select.base.js.map b/dist/js/tom-select.base.js.map index 397d0d91..6111f9c2 100644 --- a/dist/js/tom-select.base.js.map +++ b/dist/js/tom-select.base.js.map @@ -1 +1 @@ -{"version":3,"file":"tom-select.base.js","sources":["../../src/contrib/microevent.js","../../src/contrib/microplugin.js","../../src/contrib/sifter.js","../../src/contrib/highlight.js","../../src/constants.js","../../src/defaults.js","../../src/utils.js","../../src/settings.js","../../src/vanilla.js","../../src/tom-select.js"],"sourcesContent":["/**\n * MicroEvent - to make any js object an event emitter\n *\n * - pure javascript - server compatible, browser compatible\n * - dont rely on the browser doms\n * - super simple - you get it immediatly, no mistery, no magic involved\n *\n * @author Jerome Etienne (https://github.com/jeromeetienne)\n */\n\nexport default class MicroEvent{\n\tconstructor(){\n\t\tthis._events = {};\n\t}\n\n\ton(event, fct){\n\t\tthis._events[event] = this._events[event] || [];\n\t\tthis._events[event].push(fct);\n\t}\n\n\toff(event, fct){\n\t\tvar n = arguments.length;\n\t\tif (n === 0) return delete this._events;\n\t\tif (n === 1) return delete this._events[event];\n\n\t\tthis._events = this._events || {};\n\t\tif (event in this._events === false) return;\n\t\tthis._events[event].splice(this._events[event].indexOf(fct), 1);\n\t}\n\n\ttrigger(event /* , args... */){\n\t\tthis._events = this._events || {};\n\t\tif (event in this._events === false) return;\n\t\tfor (var i = 0; i < this._events[event].length; i++){\n\t\t\tthis._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));\n\t\t}\n\t}\n};\n","/**\n * microplugin.js\n * Copyright (c) 2013 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis \n */\n\nexport default function MicroPlugin(Interface){\n\n\tInterface.plugins = {};\n\n\t/**\n\t * Initializes the listed plugins (with options).\n\t * Acceptable formats:\n\t *\n\t * List (without options):\n\t * ['a', 'b', 'c']\n\t *\n\t * List (with options):\n\t * [{'name': 'a', options: {}}, {'name': 'b', options: {}}]\n\t *\n\t * Hash (with options):\n\t * {'a': { ... }, 'b': { ... }, 'c': { ... }}\n\t *\n\t * @param {mixed} plugins\n\t */\n\tInterface.prototype.initializePlugins = function(plugins) {\n\t\tvar i, n, key;\n\t\tvar self = this;\n\t\tvar queue = [];\n\n\t\tself.plugins = {\n\t\t\tnames : [],\n\t\t\tsettings : {},\n\t\t\trequested : {},\n\t\t\tloaded : {}\n\t\t};\n\n\t\tif (Array.isArray(plugins)) {\n\t\t\tfor (i = 0, n = plugins.length; i < n; i++) {\n\t\t\t\tif (typeof plugins[i] === 'string') {\n\t\t\t\t\tqueue.push(plugins[i]);\n\t\t\t\t} else {\n\t\t\t\t\tself.plugins.settings[plugins[i].name] = plugins[i].options;\n\t\t\t\t\tqueue.push(plugins[i].name);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (plugins) {\n\t\t\tfor (key in plugins) {\n\t\t\t\tif (plugins.hasOwnProperty(key)) {\n\t\t\t\t\tself.plugins.settings[key] = plugins[key];\n\t\t\t\t\tqueue.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twhile (queue.length) {\n\t\t\tself.require(queue.shift());\n\t\t}\n\t};\n\n\tInterface.prototype.loadPlugin = function(name) {\n\t\tvar self = this;\n\t\tvar plugins = self.plugins;\n\t\tvar plugin = Interface.plugins[name];\n\n\t\tif (!Interface.plugins.hasOwnProperty(name)) {\n\t\t\tthrow new Error('Unable to find \"' + name + '\" plugin');\n\t\t}\n\n\t\tplugins.requested[name] = true;\n\t\tplugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);\n\t\tplugins.names.push(name);\n\t};\n\n\t/**\n\t * Initializes a plugin.\n\t *\n\t * @param {string} name\n\t */\n\tInterface.prototype.require = function(name) {\n\t\tvar self = this;\n\t\tvar plugins = self.plugins;\n\n\t\tif (!self.plugins.loaded.hasOwnProperty(name)) {\n\t\t\tif (plugins.requested[name]) {\n\t\t\t\tthrow new Error('Plugin has circular dependency (\"' + name + '\")');\n\t\t\t}\n\t\t\tself.loadPlugin(name);\n\t\t}\n\n\t\treturn plugins.loaded[name];\n\t};\n\n\t/**\n\t * Registers a plugin.\n\t *\n\t * @param {string} name\n\t * @param {function} fn\n\t */\n\tInterface.define = function(name, fn) {\n\t\tInterface.plugins[name] = {\n\t\t\t'name' : name,\n\t\t\t'fn' : fn\n\t\t};\n\t};\n\n}\n","/**\n * sifter.js\n * Copyright (c) 2013–2020 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis \n */\n\n\n// utilities\n// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\nvar cmp = function(a, b) {\n\tif (typeof a === 'number' && typeof b === 'number') {\n\t\treturn a > b ? 1 : (a < b ? -1 : 0);\n\t}\n\ta = asciifold(String(a || ''));\n\tb = asciifold(String(b || ''));\n\tif (a > b) return 1;\n\tif (b > a) return -1;\n\treturn 0;\n};\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @param {Boolean} nesting Handle nesting or not\n * @return {Object} The resolved property value\n */\nvar getattr = function(obj, name, nesting) {\n if (!obj || !name) return;\n if (!nesting) return obj[name];\n var names = name.split(\".\");\n while(names.length && (obj = obj[names.shift()]));\n return obj;\n};\n\nvar escape_regex = function(str) {\n\treturn (str + '').replace(/([.?*+^$[\\]\\\\(){}|-])/g, '\\\\$1');\n};\n\nvar DIACRITICS = {\n\t'a': '[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]',\n\t'b': '[b␢βΒB฿𐌁ᛒ]',\n\t'c': '[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]',\n\t'd': '[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]',\n\t'e': '[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]',\n\t'f': '[fƑƒḞḟ]',\n\t'g': '[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]',\n\t'h': '[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]',\n\t'i': '[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]',\n\t'j': '[jȷĴĵɈɉʝɟʲ]',\n\t'k': '[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]',\n\t'l': '[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]',\n\t'n': '[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]',\n\t'o': '[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]',\n\t'p': '[pṔṕṖṗⱣᵽƤƥᵱ]',\n\t'q': '[qꝖꝗʠɊɋꝘꝙq̃]',\n\t'r': '[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]',\n\t's': '[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]',\n\t't': '[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]',\n\t'u': '[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]',\n\t'v': '[vṼṽṾṿƲʋꝞꝟⱱʋ]',\n\t'w': '[wẂẃẀẁŴŵẄẅẆẇẈẉ]',\n\t'x': '[xẌẍẊẋχ]',\n\t'y': '[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]',\n\t'z': '[zŹźẐẑŽžŻżẒẓẔẕƵƶ]'\n};\n\nvar asciifold = (function() {\n\tvar i, n, k, chunk;\n\tvar foreignletters = '';\n\tvar lookup = {};\n\tfor (k in DIACRITICS) {\n\t\tif (DIACRITICS.hasOwnProperty(k)) {\n\t\t\tchunk = DIACRITICS[k].substring(2, DIACRITICS[k].length - 1);\n\t\t\tforeignletters += chunk;\n\t\t\tfor (i = 0, n = chunk.length; i < n; i++) {\n\t\t\t\tlookup[chunk.charAt(i)] = k;\n\t\t\t}\n\t\t}\n\t}\n\tvar regexp = new RegExp('[' + foreignletters + ']', 'g');\n\treturn function(str) {\n\t\treturn str.replace(regexp, function(foreignletter) {\n\t\t\treturn lookup[foreignletter];\n\t\t}).toLowerCase();\n\t};\n})();\n\n\nexport default class Sifter{\n\n\t/**\n\t * Textually searches arrays and hashes of objects\n\t * by property (or multiple properties). Designed\n\t * specifically for autocomplete.\n\t *\n\t * @constructor\n\t * @param {array|object} items\n\t * @param {object} items\n\t */\n\tconstructor(items, settings) {\n\t\tthis.items = items;\n\t\tthis.settings = settings || {diacritics: true};\n\t};\n\n\t/**\n\t * Splits a search string into an array of individual\n\t * regexps to be used to match results.\n\t *\n\t * @param {string} query\n\t * @returns {array}\n\t */\n\ttokenize(query, respect_word_boundaries) {\n\t\tquery = String(query || '').toLowerCase().trim();\n\t\tif (!query || !query.length) return [];\n\n\t\tvar i, n, regex, letter;\n\t\tvar tokens = [];\n\t\tvar words = query.split(/ +/);\n\n\t\tfor (i = 0, n = words.length; i < n; i++) {\n\t\t\tregex = escape_regex(words[i]);\n\t\t\tif (this.settings.diacritics) {\n\t\t\t\tfor (letter in DIACRITICS) {\n\t\t\t\t\tif (DIACRITICS.hasOwnProperty(letter)) {\n\t\t\t\t\t\tregex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (respect_word_boundaries) regex = \"\\\\b\"+regex\n\t\t\ttokens.push({\n\t\t\t\tstring : words[i],\n\t\t\t\tregex : new RegExp(regex, 'i')\n\t\t\t});\n\t\t}\n\n\t\treturn tokens;\n\t};\n\n\t/**\n\t * Iterates over arrays and hashes.\n\t *\n\t * ```\n\t * this.iterator(this.items, function(item, id) {\n\t * // invoked for each item\n\t * });\n\t * ```\n\t *\n\t * @param {array|object} object\n\t */\n\titerator(object, callback) {\n\t\tvar iterator;\n\t\tif (Array.isArray(object)) {\n\t\t\titerator = Array.prototype.forEach || function(callback) {\n\t\t\t\tfor (var i = 0, n = this.length; i < n; i++) {\n\t\t\t\t\tcallback(this[i], i, this);\n\t\t\t\t}\n\t\t\t};\n\t\t} else {\n\t\t\titerator = function(callback) {\n\t\t\t\tfor (var key in this) {\n\t\t\t\t\tif (this.hasOwnProperty(key)) {\n\t\t\t\t\t\tcallback(this[key], key, this);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\titerator.apply(object, [callback]);\n\t};\n\n\t/**\n\t * Returns a function to be used to score individual results.\n\t *\n\t * Good matches will have a higher score than poor matches.\n\t * If an item is not a match, 0 will be returned by the function.\n\t *\n\t * @param {object|string} search\n\t * @param {object} options (optional)\n\t * @returns {function}\n\t */\n\tgetScoreFunction(search, options) {\n\t\tvar self, fields, tokens, token_count, nesting;\n\n\t\tself = this;\n\t\tsearch = self.prepareSearch(search, options);\n\t\ttokens = search.tokens;\n\t\tfields = search.options.fields;\n\t\ttoken_count = tokens.length;\n\t\tnesting = search.options.nesting;\n\n\t\t/**\n\t\t * Calculates how close of a match the\n\t\t * given value is against a search token.\n\t\t *\n\t\t * @param {mixed} value\n\t\t * @param {object} token\n\t\t * @return {number}\n\t\t */\n\t\tvar scoreValue = function(value, token) {\n\t\t\tvar score, pos;\n\n\t\t\tif (!value) return 0;\n\t\t\tvalue = String(value || '');\n\t\t\tpos = value.search(token.regex);\n\t\t\tif (pos === -1) return 0;\n\t\t\tscore = token.string.length / value.length;\n\t\t\tif (pos === 0) score += 0.5;\n\t\t\treturn score;\n\t\t};\n\n\t\t/**\n\t\t * Calculates the score of an object\n\t\t * against the search query.\n\t\t *\n\t\t * @param {object} token\n\t\t * @param {object} data\n\t\t * @return {number}\n\t\t */\n\t\tvar scoreObject = (function() {\n\t\t\tvar field_count = fields.length;\n\t\t\tif (!field_count) {\n\t\t\t\treturn function() { return 0; };\n\t\t\t}\n\t\t\tif (field_count === 1) {\n\t\t\t\treturn function(token, data) {\n\t\t\t\t\treturn scoreValue(getattr(data, fields[0], nesting), token);\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn function(token, data) {\n\t\t\t\tfor (var i = 0, sum = 0; i < field_count; i++) {\n\t\t\t\t\tsum += scoreValue(getattr(data, fields[i], nesting), token);\n\t\t\t\t}\n\t\t\t\treturn sum / field_count;\n\t\t\t};\n\t\t})();\n\n\t\tif (!token_count) {\n\t\t\treturn function() { return 0; };\n\t\t}\n\t\tif (token_count === 1) {\n\t\t\treturn function(data) {\n\t\t\t\treturn scoreObject(tokens[0], data);\n\t\t\t};\n\t\t}\n\n\t\tif (search.options.conjunction === 'and') {\n\t\t\treturn function(data) {\n\t\t\t\tvar score;\n\t\t\t\tfor (var i = 0, sum = 0; i < token_count; i++) {\n\t\t\t\t\tscore = scoreObject(tokens[i], data);\n\t\t\t\t\tif (score <= 0) return 0;\n\t\t\t\t\tsum += score;\n\t\t\t\t}\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(data) {\n\t\t\t\tfor (var i = 0, sum = 0; i < token_count; i++) {\n\t\t\t\t\tsum += scoreObject(tokens[i], data);\n\t\t\t\t}\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Returns a function that can be used to compare two\n\t * results, for sorting purposes. If no sorting should\n\t * be performed, `null` will be returned.\n\t *\n\t * @param {string|object} search\n\t * @param {object} options\n\t * @return function(a,b)\n\t */\n\tgetSortFunction(search, options) {\n\t\tvar i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort;\n\n\t\tself = this;\n\t\tsearch = self.prepareSearch(search, options);\n\t\tsort = (!search.query && options.sort_empty) || options.sort;\n\n\t\t/**\n\t\t * Fetches the specified sort field value\n\t\t * from a search result item.\n\t\t *\n\t\t * @param {string} name\n\t\t * @param {object} result\n\t\t * @return {mixed}\n\t\t */\n\t\tget_field = function(name, result) {\n\t\t\tif (name === '$score') return result.score;\n\t\t\treturn getattr(self.items[result.id], name, options.nesting);\n\t\t};\n\n\t\t// parse options\n\t\tfields = [];\n\t\tif (sort) {\n\t\t\tfor (i = 0, n = sort.length; i < n; i++) {\n\t\t\t\tif (search.query || sort[i].field !== '$score') {\n\t\t\t\t\tfields.push(sort[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// the \"$score\" field is implied to be the primary\n\t\t// sort field, unless it's manually specified\n\t\tif (search.query) {\n\t\t\timplicit_score = true;\n\t\t\tfor (i = 0, n = fields.length; i < n; i++) {\n\t\t\t\tif (fields[i].field === '$score') {\n\t\t\t\t\timplicit_score = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (implicit_score) {\n\t\t\t\tfields.unshift({field: '$score', direction: 'desc'});\n\t\t\t}\n\t\t} else {\n\t\t\tfor (i = 0, n = fields.length; i < n; i++) {\n\t\t\t\tif (fields[i].field === '$score') {\n\t\t\t\t\tfields.splice(i, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tmultipliers = [];\n\t\tfor (i = 0, n = fields.length; i < n; i++) {\n\t\t\tmultipliers.push(fields[i].direction === 'desc' ? -1 : 1);\n\t\t}\n\n\t\t// build function\n\t\tfields_count = fields.length;\n\t\tif (!fields_count) {\n\t\t\treturn null;\n\t\t} else if (fields_count === 1) {\n\t\t\tfield = fields[0].field;\n\t\t\tmultiplier = multipliers[0];\n\t\t\treturn function(a, b) {\n\t\t\t\treturn multiplier * cmp(\n\t\t\t\t\tget_field(field, a),\n\t\t\t\t\tget_field(field, b)\n\t\t\t\t);\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(a, b) {\n\t\t\t\tvar i, result, a_value, b_value, field;\n\t\t\t\tfor (i = 0; i < fields_count; i++) {\n\t\t\t\t\tfield = fields[i].field;\n\t\t\t\t\tresult = multipliers[i] * cmp(\n\t\t\t\t\t\tget_field(field, a),\n\t\t\t\t\t\tget_field(field, b)\n\t\t\t\t\t);\n\t\t\t\t\tif (result) return result;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Parses a search query and returns an object\n\t * with tokens and fields ready to be populated\n\t * with results.\n\t *\n\t * @param {string} query\n\t * @param {object} options\n\t * @returns {object}\n\t */\n\tprepareSearch(query, options) {\n\t\tif (typeof query === 'object') return query;\n\n\t\toptions = Object.assign({},options);\n\n\t\tvar option_fields = options.fields;\n\t\tvar option_sort = options.sort;\n\t\tvar option_sort_empty = options.sort_empty;\n\n\t\tif (option_fields && !Array.isArray(option_fields)) options.fields = [option_fields];\n\t\tif (option_sort && !Array.isArray(option_sort)) options.sort = [option_sort];\n\t\tif (option_sort_empty && !Array.isArray(option_sort_empty)) options.sort_empty = [option_sort_empty];\n\n\t\treturn {\n\t\t\toptions : options,\n\t\t\tquery : String(query || '').toLowerCase(),\n\t\t\ttokens : this.tokenize(query, options.respect_word_boundaries),\n\t\t\ttotal : 0,\n\t\t\titems : []\n\t\t};\n\t};\n\n\t/**\n\t * Searches through all items and returns a sorted array of matches.\n\t *\n\t * The `options` parameter can contain:\n\t *\n\t * - fields {string|array}\n\t * - sort {array}\n\t * - score {function}\n\t * - filter {bool}\n\t * - limit {integer}\n\t *\n\t * Returns an object containing:\n\t *\n\t * - options {object}\n\t * - query {string}\n\t * - tokens {array}\n\t * - total {int}\n\t * - items {array}\n\t *\n\t * @param {string} query\n\t * @param {object} options\n\t * @returns {object}\n\t */\n\tsearch(query, options) {\n\t\tvar self = this, value, score, search, calculateScore;\n\t\tvar fn_sort;\n\t\tvar fn_score;\n\n\t\tsearch = this.prepareSearch(query, options);\n\t\toptions = search.options;\n\t\tquery = search.query;\n\n\t\t// generate result scoring function\n\t\tfn_score = options.score || self.getScoreFunction(search);\n\n\t\t// perform search and sort\n\t\tif (query.length) {\n\t\t\tself.iterator(self.items, function(item, id) {\n\t\t\t\tscore = fn_score(item);\n\t\t\t\tif (options.filter === false || score > 0) {\n\t\t\t\t\tsearch.items.push({'score': score, 'id': id});\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tself.iterator(self.items, function(item, id) {\n\t\t\t\tsearch.items.push({'score': 1, 'id': id});\n\t\t\t});\n\t\t}\n\n\t\tfn_sort = self.getSortFunction(search, options);\n\t\tif (fn_sort) search.items.sort(fn_sort);\n\n\t\t// apply limits\n\t\tsearch.total = search.items.length;\n\t\tif (typeof options.limit === 'number') {\n\t\t\tsearch.items = search.items.slice(0, options.limit);\n\t\t}\n\n\t\treturn search;\n\t};\n}\n","/**\n * highlight v3 | MIT license | Johann Burkard \n * Highlights arbitrary terms in a node.\n *\n * - Modified by Marshal 2011-6-24 (added regex)\n * - Modified by Brian Reavis 2012-8-27 (cleanup)\n */\n\nexport function highlight(element, pattern) {\n\tif (typeof pattern === 'string' && !pattern.length) return;\n\tvar regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern;\n\n\tvar highlight = function(node) {\n\t\tvar skip = 0;\n\t\t// Wrap matching part of text node with highlighting , e.g.\n\t\t// Soccer -> Soccer for regex = /soc/i\n\t\tif (node.nodeType === 3) {\n\t\t\tvar pos = node.data.search(regex);\n\t\t\tif (pos >= 0 && node.data.length > 0) {\n\t\t\t\tvar match = node.data.match(regex);\n\t\t\t\tvar spannode = document.createElement('span');\n\t\t\t\tspannode.className = 'highlight';\n\t\t\t\tvar middlebit = node.splitText(pos);\n\t\t\t\tvar endbit = middlebit.splitText(match[0].length);\n\t\t\t\tvar middleclone = middlebit.cloneNode(true);\n\t\t\t\tspannode.appendChild(middleclone);\n\t\t\t\tmiddlebit.parentNode.replaceChild(spannode, middlebit);\n\t\t\t\tskip = 1;\n\t\t\t}\n\t\t}\n\t\t// Recurse element node, looking for child text nodes to highlight, unless element\n\t\t// is childless,