Skip to content

Commit

Permalink
Update easy_row.js
Browse files Browse the repository at this point in the history
allow for other class Names, duh
  • Loading branch information
compmeist authored May 2, 2024
1 parent d5d7836 commit 9722c63
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions easy-row/easy_row.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@


/*
<easy-row> custom Web Component element, no shadow DOM,
by N.E. Frick, 2024
use in HTML document as: <easy-row ratio="1-2" base="16">
ratio = 1-1 or 1-2 or 2-1 or 1-3 or 1-1-1
base = 0 or 16 or 32
base = 0 or 2 or 16 or 32
simply include:
<script src="/js/easy_row.js" type="module"></script>
Expand All @@ -24,6 +25,23 @@ export class EasyRow extends HTMLElement {
this.base0 = '0';
}

replaceEasyClassName(newEasyClass) {
var easy_c_i_c = 0;
this.classList.forEach(className => {
if (className.startsWith('easy')) {
easy_c_i_c++;
}
});
if (easy_c_i_c == 0)
this.classList.add(newEasyClass);
else
this.classList.forEach(className => {
if (className.startsWith('easy')) {
this.classList.replace(className, newEasyClass);
}
});
}

attributeChangedCallback(name, oldValue, newValue) {
if (name === 'ratio') {
var clsName = newValue.trim();
Expand All @@ -36,13 +54,13 @@ export class EasyRow extends HTMLElement {
else
{ this.ratio0 = '1-1';
}
this.className = `easy${this.base0}-row-${this.ratio0}`;
this.replaceEasyClassName(`easy${this.base0}-row-${this.ratio0}`);
}
else if (name === 'base') {
// const clsName = this.getAttribute('base');
const clsName = newValue;
if (clsName) {

switch (`${clsName.trim()}`) {
case '16':
case '32':this.base0 = clsName; break;
Expand All @@ -52,7 +70,7 @@ export class EasyRow extends HTMLElement {
else
{ this.base0 = '0';
}
this.className = `easy${this.base0}-row-${this.ratio0}`;
this.replaceEasyClassName(`easy${this.base0}-row-${this.ratio0}`);

}
}
Expand Down

0 comments on commit 9722c63

Please sign in to comment.