Skip to content

Commit e096c3b

Browse files
author
WebCoder49
committed
Final testing for accessibility �ria- attributes
1 parent 42061e5 commit e096c3b

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

code-input.js

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,16 @@ var codeInput = {
275275
constructor() {
276276
console.log("code-input: plugin: Created plugin");
277277

278-
codeInput.observedAttributes = codeInput.observedAttributes.concat(self.observedAttributes);
278+
codeInput.observedAttributes.forEach((attribute) => {
279+
// Move plugin attribute to codeInput observed attributes
280+
let regexFromWildcard = codeInput.wildcard2regex(attribute);
281+
if(regexFromWildcard == null) {
282+
// Not a wildcard
283+
codeInput.observedAttributes.push(attribute);
284+
} else {
285+
codeInput.observedAttributes.regex.push(regexFromWildcard);
286+
}
287+
});
279288
}
280289

281290
/**
@@ -589,10 +598,9 @@ var codeInput = {
589598
for(let i = 0; i < codeInput.observedAttributes.regexp.length; i++) {
590599
const reg = codeInput.observedAttributes.regexp[i];
591600
if (mutation.attributeName.match(reg)) {
592-
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, mutation.newValue);
601+
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
593602
}
594603
}
595-
596604
}
597605
}
598606

@@ -660,7 +668,7 @@ var codeInput = {
660668

661669
if (newValue != undefined && newValue != "") {
662670
code.classList.add("language-" + newValue);
663-
console.log("code-input: Language:ADD", "language-" + newValue);
671+
console.log("code-input: Language: ADD", "language-" + newValue);
664672
}
665673

666674
if (mainTextarea.placeholder == oldValue) mainTextarea.placeholder = newValue;
@@ -670,15 +678,18 @@ var codeInput = {
670678
break;
671679
default:
672680
if (codeInput.textareaSyncAttributes.includes(name)) {
673-
this.textareaElement.setAttribute(name, newValue);
674-
}
675-
else
676-
{
677-
codeInput.textareaSyncAttributes.regexp.forEach((attribute) =>
678-
{
679-
for(const attr of this.attributes) {
680-
if (attr.nodeName.match(attribute)) {
681-
this.textareaElement.setAttribute(attr.nodeName, attr.nodeValue);
681+
if(newValue == null) {
682+
this.textareaElement.removeAttribute(name);
683+
} else {
684+
this.textareaElement.setAttribute(name, newValue);
685+
}
686+
} else {
687+
codeInput.textareaSyncAttributes.regexp.forEach((attribute) => {
688+
if (name.match(attribute)) {
689+
if(newValue == null) {
690+
this.textareaElement.removeAttribute(name);
691+
} else {
692+
this.textareaElement.setAttribute(name, newValue);
682693
}
683694
}
684695
});
@@ -855,6 +866,30 @@ var codeInput = {
855866
};
856867
},
857868

869+
arrayWildcards2regex(list) {
870+
for(let i = 0; i < list.length; i++) {
871+
const name = list[i];
872+
if (name.indexOf("*") < 0)
873+
continue;
874+
875+
list.regexp.push(new RegExp("^" +
876+
name.replace(/[/\-\\^$+?.()|[\]{}]/g, '\\$&')
877+
.replace("*", ".*")
878+
+ "$", "i"));
879+
list.splice(i--, 1);
880+
};
881+
},
882+
883+
wildcard2regex(wildcard) {
884+
if (wildcard.indexOf("*") < 0)
885+
return null;
886+
887+
return new RegExp("^" +
888+
wildcard.replace(/[/\-\\^$+?.()|[\]{}]/g, '\\$&')
889+
.replace("*", ".*")
890+
+ "$", "i");
891+
}
892+
858893
}
859894
/**
860895
* convert wildcards into regex
@@ -867,28 +902,17 @@ var codeInput = {
867902
enumerable: false,
868903
configurable: false
869904
});
870-
905+
codeInput.observedAttributes = codeInput.observedAttributes.concat(codeInput.textareaSyncAttributes);
906+
871907
Object.defineProperty(codeInput.observedAttributes, 'regexp', {
872908
value: [],
873909
writable: false,
874910
enumerable: false,
875911
configurable: false
876912
});
877-
const wildcard2regex = list => {
878-
for(let i = 0; i < list.length; i++) {
879-
const name = list[i];
880-
if (name.indexOf("*") < 0)
881-
continue;
882-
883-
list.regexp.push(new RegExp("^" +
884-
name.replace(/[/\-\\^$+?.()|[\]{}]/g, '\\$&')
885-
.replace("*", ".*")
886-
+ "$", "i"));
887-
list.splice(i--, 1);
888-
};
889-
}
890-
wildcard2regex(codeInput.textareaSyncAttributes);
891-
wildcard2regex(codeInput.observedAttributes);
913+
914+
codeInput.arrayWildcards2regex(codeInput.textareaSyncAttributes);
915+
codeInput.arrayWildcards2regex(codeInput.observedAttributes);
892916
}
893917

894918
customElements.define("code-input", codeInput.CodeInput);

0 commit comments

Comments
 (0)