Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/LittleBigTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function littleBIGtable(settings) {
meta: {
loading: false,
status: null,
icons_cached: false,
},
// stores the parameters passed in query string
params: {
Expand All @@ -53,6 +54,27 @@ function littleBIGtable(settings) {
this.settings[i] = settings[i];
}
}

//cache icons
fetch(this.settings.icons).then(response => response.text()).then((iconssvgtext) => {

let parser = new DOMParser();
let icons = parser.parseFromString(iconssvgtext, 'image/svg+xml');

let wrapper = document.createElement('div');
wrapper.setAttribute('id', 'iconscache');
wrapper.style.display = 'none';
wrapper.insertAdjacentElement('afterbegin', icons.firstElementChild);

Array.prototype.map.call(wrapper.getElementsByTagName('symbol'),(el) =>{
el.setAttribute('id','cachedicon_'+el.getAttribute('id'))
});

document.body.insertAdjacentElement('beforeend', wrapper);

this.meta.icons_cached = true

});
// fetch data
this.fetch();
},
Expand Down Expand Up @@ -195,7 +217,7 @@ function littleBIGtable(settings) {
if (undefined !== this.sort[col]) {
icon = this.sort[col];
}
return '<svg class="icon"><use xlink:href="' + this.settings.icons + '#sort-' + icon + '"></use></svg>';
return '<svg class="icon"><use xlink:href="' + (this.meta.icons_cached ? '#cachedicon_' : (this.settings.icons+'#')) + 'sort-' + icon + '"></use></svg>';
},
// set the number of rows to show per page and saves preference in localStorage
// tries to keep the current rows on the page
Expand Down