This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21407 - [Custom]: Loading resources is inconvenient
Summary: [Custom]: Loading resources is inconvenient
Status: RESOLVED DUPLICATE of bug 19870
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 18511
  Show dependency treegraph
 
Reported: 2013-03-27 01:22 UTC by Steve Orvell
Modified: 2013-05-29 19:17 UTC (History)
0 users

See Also:


Attachments

Description Steve Orvell 2013-03-27 01:22:55 UTC
If a Custom Element is defined via an < element > tag that's loaded via a web component (< link rel="component" >), it's typical to want to treat resource paths as relative to the loading document, the web component. In that case, it's inconvenient for a custom element to load external resources. 

For example:

this.querySelector('img').src = 'images/icon.png';

Here, the 'images' folder is sibling to the web component. If the web component is not sibling to the host document, the image url will be incorrect. It's possible to address this with the following code, but even with URL (https://dvcs.w3.org/hg/url/raw-file/tip/Overview.html), this is inconvenient:

< element ... > 
  < script > 
    var baseUrl = this.ownerDocument.URL;
    // ...
    var prototype = {
      updateImage: function() {
        this.querySelector('img').src = new URL('images/icon.png', baseUrl);
      }
    }
...

Is there an easier way to accomplish the above?

If not, please consider adding a helper api to facilite this relatively common case. Perhaps CustomElements could be given a 'definitionURL' property to avoid the need to capture this information.
Comment 1 Dimitri Glazkov 2013-05-29 19:17:43 UTC

*** This bug has been marked as a duplicate of bug 19870 ***