Skip to content

Commit

Permalink
rewrite: fix attr rewrite if no element is available, pass ownerDocum…
Browse files Browse the repository at this point in the history
…ent directly (#174)
  • Loading branch information
ikreymer authored Sep 18, 2024
1 parent 305abfa commit 7dd1f4e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,7 @@ Wombat.prototype.performAttributeRewrite = function(
elem,
name,
value,
ownerDoc,
absUrlOnly
) {
switch (name) {
Expand All @@ -2023,14 +2024,14 @@ Wombat.prototype.performAttributeRewrite = function(
return value;
}
var mod = this.rwModForElement(elem, name);
if (
if (elem &&
this.wbUseAFWorker &&
this.WBAutoFetchWorker &&
this.isSavedDataSrcSrcset(elem)
) {
this.WBAutoFetchWorker.preserveDataSrcset(elem);
}
var result = this.rewriteUrl(value, false, mod, elem.ownerDocument);
var result = this.rewriteUrl(value, false, mod, ownerDoc);
if (mod === 'esm_' && result && result.indexOf('esm_/') < 0) {
// replace current modifier with esm_ if already rewritten
result = result.replace(/(\/[\d]*)([\w]+_)(?=\/)/, '$1esm_');
Expand All @@ -2055,7 +2056,7 @@ Wombat.prototype.rewriteAttr = function(elem, name, absUrlOnly) {

if (!value || this.startsWith(value, 'javascript:')) return changed;

var new_value = this.performAttributeRewrite(elem, name, value, absUrlOnly);
var new_value = this.performAttributeRewrite(elem, name, value, elem.ownerDocument, absUrlOnly);

if (new_value !== value) {
this.removeWBOSRC(elem);
Expand Down Expand Up @@ -2966,6 +2967,7 @@ Wombat.prototype.newAttrObjGetSet = function(attrProto, prop) {
obj.ownerElement,
obj.name,
newValue,
obj.ownerDocument,
false
);
}
Expand Down

0 comments on commit 7dd1f4e

Please sign in to comment.