document.currentScript.ownerDocument fails with webcomponents-0.5.5.js and FF 36

446 views
Skip to first unread message

nicolas...@logilab.fr

unread,
Mar 16, 2015, 6:12:09 AM3/16/15
to polym...@googlegroups.com
Hi List,

I could not find a mailing list for the webcomponents.js polyfill. Please redirect me to that list if it exists.

I have been experimenting with web components lately. Looks like a great step forward. Thank you to all whom contributed.

Here is my issue:

test.html looks like this

<html>
  <head>
    <script src="webcomponents-0.5.5.js"></script>
    <link rel="import" href="xprogressbar.html"/>
  </head>
  <body>
    <h1>Testing x-progressbar</h1>
    <div class="xprogressbar" data-done="50" data-todo="40" data-budget="100"
         data-width="100" data-height="20" data-fontsize="2em"></div>
  </body>
</html>

and xprogressbar.html like this:

<template id="x-progressbar-template">
  [...]
</template>

<script src="xprogressbar.js"></script>
<script>
(function() {
  var importDoc = document.currentScript.ownerDocument;
  var proto = Object.create(HTMLElement.prototype);
  proto.createdCallback = function() {
    init_xprogressbar(this, importDoc);
  };
  document.registerElement('x-progressbar', {prototype: proto});
})();
</script>

The above works fine in Chromium 37 and in Iceweasel (Firefox) 36 when dom.webcomponents.enabled = true.

But with Firefox 36, document.currentScript.ownerDocument points to test.html instead of xprogressbar.html.

Any help or pointer will be welcome.

Eric Bidelman

unread,
Mar 16, 2015, 12:05:09 PM3/16/15
to nicolas...@logilab.fr, polym...@googlegroups.com
You can use document._currentScript to support polyfill'd environments. 

http://webcomponents.org/polyfills/html-imports/#other-notes

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/4ec7bf70-3eb5-4a0f-860d-3f7442037510%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Chauvat

unread,
Mar 16, 2015, 5:34:40 PM3/16/15
to Eric Bidelman, polym...@googlegroups.com
On Mon, Mar 16, 2015 at 04:05:03PM +0000, Eric Bidelman wrote:
> You can use document._currentScript to support polyfill'd environments.
>
> http://webcomponents.org/polyfills/html-imports/#other-notes

Thank you for pointing me to the right paragraph of the fine manual.

Could you also tell me what is the code one usually writes to use
currentScript or _currentScript depending on the fact that the
polyfill is active or not active (chrome, firefox with or without
webcomponents enabled)?

Should I just use document._currentScript.ownerDocument and let the
polyfill do its job as long as I have it in the head of my document?

--
Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances

Eric Bidelman

unread,
Mar 16, 2015, 8:21:40 PM3/16/15
to Nicolas Chauvat, polym...@googlegroups.com
You can safely use document._currentScript.ownerDocument all the time if you're using webcomponents.js
Reply all
Reply to author
Forward
0 new messages