Skip to content

Commit b6f91fa

Browse files
authored
Merge pull request #4 from tobscure/setattribute-fix
Remove setAttribute calls from constructors to comply with Custom Elements spec
2 parents c3cf96c + bd145df commit b6f91fa

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ if (!window.customElements.get('md-header')) {
5555
class MarkdownBoldButtonElement extends MarkdownButtonElement {
5656
constructor() {
5757
super()
58-
this.setAttribute('hotkey', 'b')
5958
styles.set(this, {prefix: '**', suffix: '**', trimFirst: true})
6059
}
60+
61+
connectedCallback() {
62+
super.connectedCallback()
63+
this.setAttribute('hotkey', 'b')
64+
}
6165
}
6266

6367
if (!window.customElements.get('md-bold')) {
@@ -68,9 +72,13 @@ if (!window.customElements.get('md-bold')) {
6872
class MarkdownItalicButtonElement extends MarkdownButtonElement {
6973
constructor() {
7074
super()
71-
this.setAttribute('hotkey', 'i')
7275
styles.set(this, {prefix: '_', suffix: '_', trimFirst: true})
7376
}
77+
78+
connectedCallback() {
79+
super.connectedCallback()
80+
this.setAttribute('hotkey', 'i')
81+
}
7482
}
7583

7684
if (!window.customElements.get('md-italic')) {
@@ -105,9 +113,13 @@ if (!window.customElements.get('md-code')) {
105113
class MarkdownLinkButtonElement extends MarkdownButtonElement {
106114
constructor() {
107115
super()
108-
this.setAttribute('hotkey', 'k')
109116
styles.set(this, {prefix: '[', suffix: '](url)', replaceNext: 'url', scanFor: 'https?://'})
110117
}
118+
119+
connectedCallback() {
120+
super.connectedCallback()
121+
this.setAttribute('hotkey', 'k')
122+
}
111123
}
112124

113125
if (!window.customElements.get('md-link')) {
@@ -142,9 +154,13 @@ if (!window.customElements.get('md-ordered-list')) {
142154
class MarkdownTaskListButtonElement extends MarkdownButtonElement {
143155
constructor() {
144156
super()
145-
this.setAttribute('hotkey', 'L')
146157
styles.set(this, {prefix: '- [ ] ', multiline: true, surroundWithNewlines: true})
147158
}
159+
160+
connectedCallback() {
161+
super.connectedCallback()
162+
this.setAttribute('hotkey', 'L')
163+
}
148164
}
149165

150166
if (!window.customElements.get('md-task-list')) {

0 commit comments

Comments
 (0)