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

Commit

Permalink
Merge branch 'master' into dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 29, 2014
2 parents c43795c + 8703f0f commit c77748d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,16 @@ if (!useNative) {
// both to override and maintain the ability to capture the native value;
// therefore we choose to expose _currentScript both when native imports
// and the polyfill are in use.
Object.defineProperty(mainDoc, '_currentScript', {
var currentScriptDescriptor = {
get: function() {
return HTMLImports.currentScript || mainDoc.currentScript;
return HTMLImports.currentScript || document.currentScript;
},
writeable: true,
configurable: true
});
}

Object.defineProperty(document, '_currentScript', currentScriptDescriptor);
Object.defineProperty(mainDoc, '_currentScript', currentScriptDescriptor);

// TODO(sorvell): multiple calls will install multiple event listeners
// which may not be desireable; calls should resolve in the correct order,
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function cloneStyle(style) {
}

var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
var CSS_IMPORT_REGEXP = /(@import[\s]*)([^;]*)(;)/g;
var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;

var path = {
resolveUrlsInStyle: function(style) {
Expand Down
1 change: 1 addition & 0 deletions test/html/currentScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
function test() {
chai.assert.equal(document._currentScript, document.currentScript, '_currentScript reflects currentScript');
chai.assert.isTrue(window.remoteCurrentScriptExecuted);
done();
}

Expand Down
2 changes: 2 additions & 0 deletions test/html/imports/current-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
window.remoteCurrentScriptExecuted = true;
chai.assert.ok(document._currentScript);
4 changes: 3 additions & 1 deletion test/html/imports/script-1.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div>me</div>
<script>
var d = document._currentScript.ownerDocument.querySelector('div');
chai.assert.ok(document._currentScript);
chai.assert.equal(d.innerHTML, 'me', '_currentScript can locate element in import')
</script>
</script>
<script src="current-script.js"></script>
1 change: 1 addition & 0 deletions test/html/imports/style-paths-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<style>
@import '../stuff/sheet.css';
@import 'sheet1.css';
@import url(//fonts.googleapis.com/css?family=Open+Sans:300,300italic,600,800|Source+Code+Pro);

.image {
background: url(google.png);
Expand Down
10 changes: 10 additions & 0 deletions test/html/style-paths.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<body>
<div class="red">red</div>
<div class="image" style="height: 20px;"></div>
<div style="font-family: 'Source Code Pro'">Source Code Pro</div>
<script>

document.addEventListener('HTMLImportsLoaded', function() {
Expand All @@ -25,6 +26,15 @@
var a = document.createElement('a');
a.href = 'imports/google.png';
chai.assert.match(getComputedStyle(image).backgroundImage, new RegExp(a.href), 'url in style applied');

if (!HTMLImports.useNative) {
var style = document.querySelector('style');
chai.assert.ok(style.sheet);
chai.assert.equal(style.sheet.cssRules[2].href,
'http://fonts.googleapis.com/css?family=Open+Sans:300,300italic,600,800|Source+Code+Pro',
'@import url() form rule has proper url')
}

done();
});
</script>
Expand Down

0 comments on commit c77748d

Please sign in to comment.