|
793 | 793 | }
|
794 | 794 | if (module.is.multiple()) {
|
795 | 795 | $.each(preSelected, function (index, value) {
|
796 |
| - $item.filter('[data-value="' + value + '"]') |
| 796 | + $item.filter('[data-' + metadata.value + '="' + value + '"]') |
797 | 797 | .addClass(className.filtered)
|
798 | 798 | ;
|
799 | 799 | });
|
|
4171 | 4171 | descriptionVertical: 'descriptionVertical', // whether description should be vertical
|
4172 | 4172 | value: 'value', // actual dropdown value
|
4173 | 4173 | text: 'text', // displayed text when selected
|
| 4174 | + data: 'data', // custom data attributes |
4174 | 4175 | type: 'type', // type of dropdown element
|
4175 | 4176 | image: 'image', // optional image path
|
4176 | 4177 | imageClass: 'imageClass', // optional individual class for image
|
|
4315 | 4316 | $.each(values, function (index, option) {
|
4316 | 4317 | var
|
4317 | 4318 | itemType = option[fields.type] || 'item',
|
4318 |
| - isMenu = itemType.indexOf('menu') !== -1 |
| 4319 | + isMenu = itemType.indexOf('menu') !== -1, |
| 4320 | + maybeData = '', |
| 4321 | + dataObject = option[fields.data] |
4319 | 4322 | ;
|
4320 |
| - |
| 4323 | + if (dataObject) { |
| 4324 | + var dataKey, |
| 4325 | + dataKeyEscaped |
| 4326 | + ; |
| 4327 | + for (dataKey in dataObject) { |
| 4328 | + dataKeyEscaped = String(dataKey).replace(/\W/g, ''); |
| 4329 | + if (Object.prototype.hasOwnProperty.call(dataObject, dataKey) && ['text', 'value'].indexOf(dataKeyEscaped.toLowerCase()) === -1) { |
| 4330 | + maybeData += ' data-' + dataKeyEscaped + '="' + deQuote(String(dataObject[dataKey])) + '"'; |
| 4331 | + } |
| 4332 | + } |
| 4333 | + } |
4321 | 4334 | if (itemType === 'item' || isMenu) {
|
4322 | 4335 | var
|
4323 | 4336 | maybeText = option[fields.text]
|
|
4334 | 4347 | : '',
|
4335 | 4348 | hasDescription = escape(option[fields.description] || '', preserveHTML) !== ''
|
4336 | 4349 | ;
|
4337 |
| - html += '<div class="' + deQuote(maybeActionable + maybeDisabled + maybeDescriptionVertical + (option[fields.class] || className.item)) + '" data-value="' + deQuote(option[fields.value], true) + '"' + maybeText + '>'; |
| 4350 | + html += '<div class="' + deQuote(maybeActionable + maybeDisabled + maybeDescriptionVertical + (option[fields.class] || className.item)) + '" data-value="' + deQuote(option[fields.value], true) + '"' + maybeText + maybeData + '>'; |
4338 | 4351 | if (isMenu) {
|
4339 | 4352 | html += '<i class="' + (itemType.indexOf('left') !== -1 ? 'left' : '') + ' dropdown icon"></i>';
|
4340 | 4353 | }
|
|
0 commit comments