Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
fix for resolving css urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Z Weinstein authored and Rafael Z Weinstein committed Feb 21, 2014
1 parent 2799341 commit 08008af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@
};

var hasTemplateElement = typeof HTMLTemplateElement !== 'undefined';
if (hasTemplateElement) {
// TODO(rafaelw): Remove when fix for
// https://codereview.chromium.org/164803002/
// makes it to Chrome release.
(function() {
var t = document.createElement('template');
var d = t.content.ownerDocument;
var html = d.appendChild(d.createElement('html'));
var head = html.appendChild(d.createElement('head'));
var base = d.createElement('base');
base.href = document.baseURI;
head.appendChild(base);
})();
}

var allTemplatesSelectors = 'template, ' +
Object.keys(semanticTemplateElements).map(function(tagName) {
Expand Down Expand Up @@ -257,6 +271,14 @@
var owner = template.ownerDocument;
if (!owner.stagingDocument_) {
owner.stagingDocument_ = owner.implementation.createHTMLDocument('');

// TODO(rafaelw): Remove when fix for
// https://codereview.chromium.org/164803002/
// makes it to Chrome release.
var base = owner.stagingDocument_.createElement('base');
base.href = document.baseURI;
owner.stagingDocument_.head.appendChild(base);

owner.stagingDocument_.stagingDocument_ = owner.stagingDocument_;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,19 @@ suite('Template Instantiation', function() {
})
});

test('baseURI', function(done) {
var div = createTestHtml('<template bind><div style="background: url(foo.jpg)"></div></template>');
var local = document.createElement('div');
local.setAttribute('style', 'background: url(foo.jpg)');
div.appendChild(local);
var template = div.firstChild;
template.model = {};
then(function() {
assert.strictEqual(local.style.backgroundImage, div.childNodes[1].style.backgroundImage);
done();
})
});

test('ChangeRefId', function(done) {
var div = createTestHtml(
'<template id="a">a:{{ }}</template>' +
Expand Down

0 comments on commit 08008af

Please sign in to comment.