Skip to content

Commit d177c92

Browse files
committed
Compile JS files
1 parent aa3bb05 commit d177c92

16 files changed

Lines changed: 438 additions & 392 deletions

public/assets/scripts/choices.js

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@
217217
return firstChild;
218218
};
219219
})();
220-
var resolveNoticeFunction = function (fn, value) {
221-
return typeof fn === 'function' ? fn(sanitise(value), value) : fn;
222-
};
223220
var resolveStringFunction = function (fn) {
224221
return typeof fn === 'function' ? fn() : fn;
225222
};
@@ -251,6 +248,26 @@
251248
}
252249
return '';
253250
};
251+
var getChoiceForOutput = function (choice, keyCode) {
252+
return {
253+
id: choice.id,
254+
highlighted: choice.highlighted,
255+
labelClass: choice.labelClass,
256+
labelDescription: choice.labelDescription,
257+
customProperties: choice.customProperties,
258+
disabled: choice.disabled,
259+
active: choice.active,
260+
label: choice.label,
261+
placeholder: choice.placeholder,
262+
value: choice.value,
263+
groupValue: choice.group ? choice.group.label : undefined,
264+
element: choice.element,
265+
keyCode: keyCode,
266+
};
267+
};
268+
var resolveNoticeFunction = function (fn, value, item) {
269+
return typeof fn === 'function' ? fn(sanitise(value), unwrapStringForRaw(value), item) : fn;
270+
};
254271
var escapeForTemplate = function (allowHTML, s) {
255272
return allowHTML ? unwrapStringForEscaped(s) : sanitise(s);
256273
};
@@ -979,7 +996,9 @@
979996
customAddItemText: 'Only values matching specific conditions can be added',
980997
addItemText: function (value) { return "Press Enter to add <b>\"".concat(value, "\"</b>"); },
981998
removeItemIconText: function () { return "Remove item"; },
982-
removeItemLabelText: function (value) { return "Remove item: ".concat(value); },
999+
removeItemLabelText: function (value, _valueRaw, i) {
1000+
return "Remove item: ".concat(i ? sanitise(i.label) : value);
1001+
},
9831002
maxItemText: function (maxItemCount) { return "Only ".concat(maxItemCount, " values can be added"); },
9841003
valueComparer: function (value1, value2) { return value1 === value2; },
9851004
fuseOptions: {
@@ -3125,8 +3144,9 @@
31253144
var removeButton = document.createElement('button');
31263145
removeButton.type = 'button';
31273146
addClassesToElement(removeButton, button);
3128-
setElementHtml(removeButton, true, resolveNoticeFunction(removeItemIconText, choice.value));
3129-
var REMOVE_ITEM_LABEL = resolveNoticeFunction(removeItemLabelText, choice.value);
3147+
var eventChoice = getChoiceForOutput(choice);
3148+
setElementHtml(removeButton, true, resolveNoticeFunction(removeItemIconText, choice.value, eventChoice));
3149+
var REMOVE_ITEM_LABEL = resolveNoticeFunction(removeItemLabelText, choice.value, eventChoice);
31303150
if (REMOVE_ITEM_LABEL) {
31313151
removeButton.setAttribute('aria-label', REMOVE_ITEM_LABEL);
31323152
}
@@ -3546,7 +3566,7 @@
35463566
}
35473567
this._store.dispatch(highlightItem(choice, true));
35483568
if (runEvent) {
3549-
this.passedElement.triggerEvent(EventType.highlightItem, this._getChoiceForOutput(choice));
3569+
this.passedElement.triggerEvent(EventType.highlightItem, getChoiceForOutput(choice));
35503570
}
35513571
return this;
35523572
};
@@ -3561,7 +3581,7 @@
35613581
}
35623582
this._store.dispatch(highlightItem(choice, false));
35633583
if (runEvent) {
3564-
this.passedElement.triggerEvent(EventType.unhighlightItem, this._getChoiceForOutput(choice));
3584+
this.passedElement.triggerEvent(EventType.unhighlightItem, getChoiceForOutput(choice));
35653585
}
35663586
return this;
35673587
};
@@ -3571,7 +3591,7 @@
35713591
_this._store.items.forEach(function (item) {
35723592
if (!item.highlighted) {
35733593
_this._store.dispatch(highlightItem(item, true));
3574-
_this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item));
3594+
_this.passedElement.triggerEvent(EventType.highlightItem, getChoiceForOutput(item));
35753595
}
35763596
});
35773597
});
@@ -3583,7 +3603,7 @@
35833603
_this._store.items.forEach(function (item) {
35843604
if (item.highlighted) {
35853605
_this._store.dispatch(highlightItem(item, false));
3586-
_this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item));
3606+
_this.passedElement.triggerEvent(EventType.highlightItem, getChoiceForOutput(item));
35873607
}
35883608
});
35893609
});
@@ -3658,9 +3678,8 @@
36583678
return this;
36593679
};
36603680
Choices.prototype.getValue = function (valueOnly) {
3661-
var _this = this;
36623681
var values = this._store.items.map(function (item) {
3663-
return (valueOnly ? item.value : _this._getChoiceForOutput(item));
3682+
return (valueOnly ? item.value : getChoiceForOutput(item));
36643683
});
36653684
return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values;
36663685
};
@@ -3918,7 +3937,7 @@
39183937
// @todo integrate with Store
39193938
this._searcher.reset();
39203939
if (choice.selected) {
3921-
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(choice));
3940+
this.passedElement.triggerEvent(EventType.removeItem, getChoiceForOutput(choice));
39223941
}
39233942
return this;
39243943
};
@@ -4001,13 +4020,7 @@
40014020
}
40024021
var _a = this, config = _a.config, isSearching = _a._isSearching;
40034022
var _b = this._store, activeGroups = _b.activeGroups, activeChoices = _b.activeChoices;
4004-
var renderLimit = 0;
4005-
if (isSearching && config.searchResultLimit > 0) {
4006-
renderLimit = config.searchResultLimit;
4007-
}
4008-
else if (config.renderChoiceLimit > 0) {
4009-
renderLimit = config.renderChoiceLimit;
4010-
}
4023+
var renderLimit = isSearching ? config.searchResultLimit : config.renderChoiceLimit;
40114024
if (this._isSelectElement) {
40124025
var backingOptions = activeChoices.filter(function (choice) { return !choice.element; });
40134026
if (backingOptions.length) {
@@ -4020,8 +4033,9 @@
40204033
return !choice.placeholder && (isSearching ? !!choice.rank : config.renderSelectedChoices || !choice.selected);
40214034
});
40224035
};
4036+
var showLabel = config.appendGroupInSearch && isSearching;
40234037
var selectableChoices = false;
4024-
var renderChoices = function (choices, withinGroup, groupLabel) {
4038+
var renderChoices = function (choices, withinGroup) {
40254039
if (isSearching) {
40264040
// sortByRank is used to ensure stable sorting, as scores are non-unique
40274041
// this additionally ensures fuseOptions.sortFn is not ignored
@@ -4031,11 +4045,12 @@
40314045
choices.sort(config.sorter);
40324046
}
40334047
var choiceLimit = choices.length;
4034-
choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit;
4048+
choiceLimit = !withinGroup && renderLimit > 0 && choiceLimit > renderLimit ? renderLimit : choiceLimit;
40354049
choiceLimit--;
40364050
choices.every(function (choice, index) {
40374051
// choiceEl being empty signals the contents has probably significantly changed
4038-
var dropdownItem = choice.choiceEl || _this._templates.choice(config, choice, config.itemSelectText, groupLabel);
4052+
var dropdownItem = choice.choiceEl ||
4053+
_this._templates.choice(config, choice, config.itemSelectText, showLabel && choice.group ? choice.group.label : undefined);
40394054
choice.choiceEl = dropdownItem;
40404055
fragment.appendChild(dropdownItem);
40414056
if (isSearching || !choice.selected) {
@@ -4050,7 +4065,7 @@
40504065
}
40514066
if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) {
40524067
// If we have a placeholder choice along with groups
4053-
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined);
4068+
renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false);
40544069
}
40554070
// If we have grouped options
40564071
if (activeGroups.length && !isSearching) {
@@ -4059,7 +4074,7 @@
40594074
}
40604075
// render Choices without group first, regardless of sort, otherwise they won't be distinguishable
40614076
// from the last group
4062-
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined);
4077+
renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false);
40634078
activeGroups.forEach(function (group) {
40644079
var groupChoices = renderableChoices(group.choices);
40654080
if (groupChoices.length) {
@@ -4069,12 +4084,12 @@
40694084
dropdownGroup.remove();
40704085
fragment.appendChild(dropdownGroup);
40714086
}
4072-
renderChoices(groupChoices, true, config.appendGroupInSearch && isSearching ? group.label : undefined);
4087+
renderChoices(groupChoices, true);
40734088
}
40744089
});
40754090
}
40764091
else {
4077-
renderChoices(renderableChoices(activeChoices), false, undefined);
4092+
renderChoices(renderableChoices(activeChoices), false);
40784093
}
40794094
}
40804095
if (!selectableChoices && (isSearching || !fragment.children.length || !config.renderSelectedChoices)) {
@@ -4200,23 +4215,12 @@
42004215
}
42014216
}
42024217
};
4218+
/**
4219+
* @deprecated Use utils.getChoiceForOutput
4220+
*/
42034221
// eslint-disable-next-line class-methods-use-this
42044222
Choices.prototype._getChoiceForOutput = function (choice, keyCode) {
4205-
return {
4206-
id: choice.id,
4207-
highlighted: choice.highlighted,
4208-
labelClass: choice.labelClass,
4209-
labelDescription: choice.labelDescription,
4210-
customProperties: choice.customProperties,
4211-
disabled: choice.disabled,
4212-
active: choice.active,
4213-
label: choice.label,
4214-
placeholder: choice.placeholder,
4215-
value: choice.value,
4216-
groupValue: choice.group ? choice.group.label : undefined,
4217-
element: choice.element,
4218-
keyCode: keyCode,
4219-
};
4223+
return getChoiceForOutput(choice, keyCode);
42204224
};
42214225
Choices.prototype._triggerChange = function (value) {
42224226
if (value === undefined || value === null) {
@@ -4421,7 +4425,7 @@
44214425
var notice = '';
44224426
if (canAddItem && typeof config.addItemFilter === 'function' && !config.addItemFilter(value)) {
44234427
canAddItem = false;
4424-
notice = resolveNoticeFunction(config.customAddItemText, value);
4428+
notice = resolveNoticeFunction(config.customAddItemText, value, undefined);
44254429
}
44264430
if (canAddItem) {
44274431
var foundChoice = this._store.choices.find(function (choice) { return config.valueComparer(choice.value, value); });
@@ -4433,12 +4437,12 @@
44334437
}
44344438
if (!config.duplicateItemsAllowed) {
44354439
canAddItem = false;
4436-
notice = resolveNoticeFunction(config.uniqueItemText, value);
4440+
notice = resolveNoticeFunction(config.uniqueItemText, value, undefined);
44374441
}
44384442
}
44394443
}
44404444
if (canAddItem) {
4441-
notice = resolveNoticeFunction(config.addItemText, value);
4445+
notice = resolveNoticeFunction(config.addItemText, value, undefined);
44424446
}
44434447
if (notice) {
44444448
this._displayNotice(notice, NoticeTypes.addChoice);
@@ -4985,9 +4989,10 @@
49854989
}
49864990
this._store.dispatch(addItem(item));
49874991
if (withEvents) {
4988-
this.passedElement.triggerEvent(EventType.addItem, this._getChoiceForOutput(item));
4992+
var eventChoice = getChoiceForOutput(item);
4993+
this.passedElement.triggerEvent(EventType.addItem, eventChoice);
49894994
if (userTriggered) {
4990-
this.passedElement.triggerEvent(EventType.choice, this._getChoiceForOutput(item));
4995+
this.passedElement.triggerEvent(EventType.choice, eventChoice);
49914996
}
49924997
}
49934998
};
@@ -5000,7 +5005,7 @@
50005005
if (notice && notice.type === NoticeTypes.noChoices) {
50015006
this._clearNotice();
50025007
}
5003-
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
5008+
this.passedElement.triggerEvent(EventType.removeItem, getChoiceForOutput(item));
50045009
};
50055010
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
50065011
if (withEvents === void 0) { withEvents = true; }

public/assets/scripts/choices.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)