Skip to content

Commit

Permalink
Reformat code and error by wrong selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwind committed May 27, 2024
1 parent 1e50293 commit 9951fb5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 72 deletions.
30 changes: 17 additions & 13 deletions dist/js/avalynx-table.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@
*/

export class AvalynxTable {
constructor(selector, options = {}) {
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
if (this.tables.length === 0) {
console.error("AvalynxTable: Table(s) with selector '" + selector + "' not found");
return;
}
this.tables.forEach(table => this.init(table));
}

init(table) {
this.enhanceTable(table);
}

enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
}
53 changes: 28 additions & 25 deletions dist/js/avalynx-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,35 @@
*/

class AvalynxTable {
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
if (this.tables.length === 0) {
console.error("AvalynxTable: Table(s) with selector '" + selector + "' not found");
return;
}
this.tables.forEach(table => this.init(table));
this.init();
}
}

init(table) {
this.enhanceTable(table);
}
init(table) {
this.enhanceTable(table);
}

enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
}
30 changes: 17 additions & 13 deletions src/js/avalynx-table.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@
*/

export class AvalynxTable {
constructor(selector, options = {}) {
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
if (this.tables.length === 0) {
console.error("AvalynxTable: Table(s) with selector '" + selector + "' not found");
return;
}
this.tables.forEach(table => this.init(table));
}

init(table) {
this.enhanceTable(table);
}

enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
}
46 changes: 25 additions & 21 deletions src/js/avalynx-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@
*/

class AvalynxTable {
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
constructor(selector, options = {}) {
if (!selector) {
selector = '.avalynx-table';
}
if (!selector.startsWith('.') && !selector.startsWith('#')) {
selector = '.' + selector;
}
this.tables = document.querySelectorAll(selector);
if (this.tables.length === 0) {
console.error("AvalynxTable: Table(s) with selector '" + selector + "' not found");
return;
}
this.tables.forEach(table => this.init(table));
}
}

init(table) {
this.enhanceTable(table);
}

enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
enhanceTable(table) {
const headers = table.querySelectorAll('thead th');
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const cells = row.querySelectorAll('td');
cells.forEach((cell, index) => {
if (headers[index]) {
cell.setAttribute('avalynx-td-title', headers[index].textContent);
}
});
});
}
}

0 comments on commit 9951fb5

Please sign in to comment.