Skip to content

Commit

Permalink
Add a way to limit which stylesheets are processed
Browse files Browse the repository at this point in the history
Implements LeaVerou#6137.
Adds limit property which is boolean and reflects the existence of a data-prefix attribute on the script tag.
If it is there, it affects the <link> styles. Only those with a data-prefix attribute are processed.
  • Loading branch information
joyously authored Dec 6, 2018
1 parent 1a10246 commit b14f6ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion prefixfree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ if(!window.addEventListener) {
}

var self = window.StyleFix = {
limit: document.currentScript.hasAttribute("data-prefix"),

link: function(link) {
var url = link.href || link.getAttribute('data-href');
try {
// Ignore stylesheets with data-noprefix attribute as well as alternate stylesheets or without (data-)href attribute
if(!url || link.rel !== 'stylesheet' || link.hasAttribute('data-noprefix')) {
if(!url || link.rel !== 'stylesheet' || link.hasAttribute('data-noprefix')
|| (self.limit && !link.hasAttribute('data-prefix')) ) {
return;
}
}
Expand Down

0 comments on commit b14f6ac

Please sign in to comment.