Skip to content

Commit

Permalink
Support for background images.
Browse files Browse the repository at this point in the history
Closes GH-21
  • Loading branch information
hrj committed Jun 26, 2016
1 parent 2ffb77c commit 089cb03
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/flif-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,28 @@ document.addEventListener("DOMContentLoaded", function() {
});
}


function processBg(elem) {
var src = elem.getAttribute("data-polyflif-bg-src");
var cElem = document.createElement("canvas");
load(src, function(content) {
var pf = new PolyFlif({"buf": content, "canvas": cElem});
setTimeout(function() {
pf["begin"](0, 0, 0);
cElem["toBlob"](function(blob) {
elem.style.backgroundImage = "url('" + URL.createObjectURL(blob) + "')";
}, 'image/png');
}, 0);
});
}

var canvasElements = document.querySelectorAll("canvas[data-polyflif-src]");
for (var i = 0; i < canvasElements.length; i++) {
process(canvasElements[i]);
}

var bgElements = document.querySelectorAll("*[data-polyflif-bg-src]");
for (var i = 0; i < bgElements.length; i++) {
processBg(bgElements[i]);
}
});

0 comments on commit 089cb03

Please sign in to comment.