Skip to content

Commit b491424

Browse files
Update aria-fixed semantic-dropdown to fomantic master (#10096)
Co-authored-by: techknowlogick <[email protected]>
1 parent bf1970d commit b491424

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed

web_src/js/semanticDropdown.js

+38-43
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* This is a patched version of semantic.dropdown which includes a11y changes, see
2-
https://github.com/go-gitea/gitea/pull/8638#issuecomment-549175290 */
3-
41
/*!
52
* # Fomantic-UI - Dropdown
63
* http://github.com/fomantic/Fomantic-UI/
@@ -41,6 +38,10 @@ $.fn.dropdown = function(parameters) {
4138
moduleSelector = $allModules.selector || '',
4239

4340
hasTouch = ('ontouchstart' in document.documentElement),
41+
clickEvent = hasTouch
42+
? 'touchstart'
43+
: 'click',
44+
4445
time = new Date().getTime(),
4546
performance = [],
4647

@@ -663,27 +664,10 @@ $.fn.dropdown = function(parameters) {
663664

664665
bind: {
665666
events: function() {
666-
if(hasTouch) {
667-
module.bind.touchEvents();
668-
}
669667
module.bind.keyboardEvents();
670668
module.bind.inputEvents();
671669
module.bind.mouseEvents();
672670
},
673-
touchEvents: function() {
674-
module.debug('Touch device detected binding additional touch events');
675-
if( module.is.searchSelection() ) {
676-
// do nothing special yet
677-
}
678-
else if( module.is.single() ) {
679-
$module
680-
.on('touchstart' + eventNamespace, module.event.test.toggle)
681-
;
682-
}
683-
$menu
684-
.on('touchstart' + eventNamespace, selector.item, module.event.item.mouseenter)
685-
;
686-
},
687671
keyboardEvents: function() {
688672
module.verbose('Binding keyboard events');
689673
$module
@@ -710,8 +694,8 @@ $.fn.dropdown = function(parameters) {
710694
module.verbose('Binding mouse events');
711695
if(module.is.multiple()) {
712696
$module
713-
.on('click' + eventNamespace, selector.label, module.event.label.click)
714-
.on('click' + eventNamespace, selector.remove, module.event.remove.click)
697+
.on(clickEvent + eventNamespace, selector.label, module.event.label.click)
698+
.on(clickEvent + eventNamespace, selector.remove, module.event.remove.click)
715699
;
716700
}
717701
if( module.is.searchSelection() ) {
@@ -720,24 +704,24 @@ $.fn.dropdown = function(parameters) {
720704
.on('mouseup' + eventNamespace, module.event.mouseup)
721705
.on('mousedown' + eventNamespace, selector.menu, module.event.menu.mousedown)
722706
.on('mouseup' + eventNamespace, selector.menu, module.event.menu.mouseup)
723-
.on('click' + eventNamespace, selector.icon, module.event.icon.click)
724-
.on('click' + eventNamespace, selector.clearIcon, module.event.clearIcon.click)
707+
.on(clickEvent + eventNamespace, selector.icon, module.event.icon.click)
708+
.on(clickEvent + eventNamespace, selector.clearIcon, module.event.clearIcon.click)
725709
.on('focus' + eventNamespace, selector.search, module.event.search.focus)
726-
.on('click' + eventNamespace, selector.search, module.event.search.focus)
710+
.on(clickEvent + eventNamespace, selector.search, module.event.search.focus)
727711
.on('blur' + eventNamespace, selector.search, module.event.search.blur)
728-
.on('click' + eventNamespace, selector.text, module.event.text.focus)
712+
.on(clickEvent + eventNamespace, selector.text, module.event.text.focus)
729713
;
730714
if(module.is.multiple()) {
731715
$module
732-
.on('click' + eventNamespace, module.event.click)
716+
.on(clickEvent + eventNamespace, module.event.click)
733717
;
734718
}
735719
}
736720
else {
737721
if(settings.on == 'click') {
738722
$module
739-
.on('click' + eventNamespace, selector.icon, module.event.icon.click)
740-
.on('click' + eventNamespace, module.event.test.toggle)
723+
.on(clickEvent + eventNamespace, selector.icon, module.event.icon.click)
724+
.on(clickEvent + eventNamespace, module.event.test.toggle)
741725
;
742726
}
743727
else if(settings.on == 'hover') {
@@ -755,7 +739,7 @@ $.fn.dropdown = function(parameters) {
755739
.on('mousedown' + eventNamespace, module.event.mousedown)
756740
.on('mouseup' + eventNamespace, module.event.mouseup)
757741
.on('focus' + eventNamespace, module.event.focus)
758-
.on('click' + eventNamespace, selector.clearIcon, module.event.clearIcon.click)
742+
.on(clickEvent + eventNamespace, selector.clearIcon, module.event.clearIcon.click)
759743
;
760744
if(module.has.menuSearch() ) {
761745
$module
@@ -769,7 +753,7 @@ $.fn.dropdown = function(parameters) {
769753
}
770754
}
771755
$menu
772-
.on('mouseenter' + eventNamespace, selector.item, module.event.item.mouseenter)
756+
.on((hasTouch ? 'touchstart' : 'mouseenter') + eventNamespace, selector.item, module.event.item.mouseenter)
773757
.on('mouseleave' + eventNamespace, selector.item, module.event.item.mouseleave)
774758
.on('click' + eventNamespace, selector.item, module.event.item.click)
775759
;
@@ -783,7 +767,7 @@ $.fn.dropdown = function(parameters) {
783767
;
784768
}
785769
$document
786-
.on('click' + elementNamespace, module.event.test.hide)
770+
.on(clickEvent + elementNamespace, module.event.test.hide)
787771
;
788772
}
789773
},
@@ -798,7 +782,7 @@ $.fn.dropdown = function(parameters) {
798782
;
799783
}
800784
$document
801-
.off('click' + elementNamespace)
785+
.off(clickEvent + elementNamespace)
802786
;
803787
}
804788
},
@@ -946,6 +930,10 @@ $.fn.dropdown = function(parameters) {
946930
text,
947931
value
948932
;
933+
if($choice.hasClass(className.unfilterable)) {
934+
results.push(this);
935+
return true;
936+
}
949937
if(settings.match === 'both' || settings.match === 'text') {
950938
text = module.remove.diacritics(String(module.get.choiceText($choice, false)));
951939
if(text.search(beginsWithRegExp) !== -1) {
@@ -1084,6 +1072,7 @@ $.fn.dropdown = function(parameters) {
10841072
if(settings.allowAdditions || (hasSelected && !module.is.multiple())) {
10851073
module.debug('Forcing partial selection to selected item', $selectedItem);
10861074
$selectedItem[0].click();
1075+
return;
10871076
}
10881077
else {
10891078
module.remove.searchTerm();
@@ -1115,7 +1104,7 @@ $.fn.dropdown = function(parameters) {
11151104
var
11161105
value = settings.templates.deQuote(item[fields.value]),
11171106
name = settings.templates.escape(
1118-
item[fields.name] || item[fields.value],
1107+
item[fields.name] || '',
11191108
settings.preserveHTML
11201109
)
11211110
;
@@ -2077,6 +2066,9 @@ $.fn.dropdown = function(parameters) {
20772066
value = ( $option.attr('value') !== undefined )
20782067
? $option.attr('value')
20792068
: name,
2069+
text = ( $option.data(metadata.text) !== undefined )
2070+
? $option.data(metadata.text)
2071+
: name,
20802072
group = $option.parent('optgroup')
20812073
;
20822074
if(settings.placeholder === 'auto' && value === '') {
@@ -2094,6 +2086,7 @@ $.fn.dropdown = function(parameters) {
20942086
select.values.push({
20952087
name : name,
20962088
value : value,
2089+
text : text,
20972090
disabled : disabled
20982091
});
20992092
}
@@ -2182,7 +2175,7 @@ $.fn.dropdown = function(parameters) {
21822175
return;
21832176
}
21842177
if(isMultiple) {
2185-
if($.inArray( String(optionValue), value) !== -1) {
2178+
if($.inArray(module.escape.htmlEntities(String(optionValue)), value) !== -1) {
21862179
$selectedItem = ($selectedItem)
21872180
? $selectedItem.add($choice)
21882181
: $choice
@@ -2201,7 +2194,7 @@ $.fn.dropdown = function(parameters) {
22012194
optionValue = optionValue.toLowerCase();
22022195
value = value.toLowerCase();
22032196
}
2204-
if( String(optionValue) == String(value)) {
2197+
if(module.escape.htmlEntities(String(optionValue)) === module.escape.htmlEntities(String(value))) {
22052198
module.verbose('Found select item by value', optionValue, value);
22062199
$selectedItem = $choice;
22072200
return true;
@@ -3175,6 +3168,7 @@ $.fn.dropdown = function(parameters) {
31753168
values = module.get.values(),
31763169
newValue
31773170
;
3171+
removedValue = module.escape.htmlEntities(removedValue);
31783172
if( module.has.selectInput() ) {
31793173
module.verbose('Input is <select> removing selected option', removedValue);
31803174
newValue = module.remove.arrayValue(removedValue, values);
@@ -3764,10 +3758,9 @@ $.fn.dropdown = function(parameters) {
37643758
},
37653759
htmlEntities: function(string) {
37663760
var
3767-
badChars = /[&<>"'`]/g,
3761+
badChars = /[<>"'`]/g,
37683762
shouldEscape = /[&<>"'`]/,
37693763
escape = {
3770-
"&": "&amp;",
37713764
"<": "&lt;",
37723765
">": "&gt;",
37733766
'"': "&quot;",
@@ -3779,6 +3772,7 @@ $.fn.dropdown = function(parameters) {
37793772
}
37803773
;
37813774
if(shouldEscape.test(string)) {
3775+
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
37823776
return string.replace(badChars, escapedChar);
37833777
}
37843778
return string;
@@ -4175,7 +4169,8 @@ $.fn.dropdown.settings = {
41754169
delete : 'delete',
41764170
header : 'header',
41774171
divider : 'divider',
4178-
groupIcon : ''
4172+
groupIcon : '',
4173+
unfilterable : 'unfilterable'
41794174
}
41804175

41814176
};
@@ -4190,10 +4185,9 @@ $.fn.dropdown.settings.templates = {
41904185
return string;
41914186
}
41924187
var
4193-
badChars = /[&<>"'`]/g,
4188+
badChars = /[<>"'`]/g,
41944189
shouldEscape = /[&<>"'`]/,
41954190
escape = {
4196-
"&": "&amp;",
41974191
"<": "&lt;",
41984192
">": "&gt;",
41994193
'"': "&quot;",
@@ -4205,6 +4199,7 @@ $.fn.dropdown.settings.templates = {
42054199
}
42064200
;
42074201
if(shouldEscape.test(string)) {
4202+
string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
42084203
return string.replace(badChars, escapedChar);
42094204
}
42104205
return string;
@@ -4260,10 +4255,10 @@ $.fn.dropdown.settings.templates = {
42604255
if(option[fields.icon]) {
42614256
html += '<i class="'+deQuote(option[fields.icon])+' '+(option[fields.iconClass] ? deQuote(option[fields.iconClass]) : className.icon)+'"></i>';
42624257
}
4263-
html += escape(option[fields.name] || option[fields.value],preserveHTML);
4258+
html += escape(option[fields.name] || '', preserveHTML);
42644259
html += '</div>';
42654260
} else if (itemType === 'header') {
4266-
var groupName = escape(option[fields.name],preserveHTML),
4261+
var groupName = escape(option[fields.name] || '', preserveHTML),
42674262
groupIcon = option[fields.icon] ? deQuote(option[fields.icon]) : className.groupIcon
42684263
;
42694264
if(groupName !== '' || groupIcon !== '') {

0 commit comments

Comments
 (0)