1000ch / syntax-highlight

Code syntax highlight element.
https://1000ch.github.io/syntax-highlight
27 stars 3 forks source link

document.currentScript not supported in IE 11 #3

Open biaggi opened 8 years ago

biaggi commented 8 years ago

Currently this method is not supported in IE11 and the polyfill suggested by canIUse is also not working in such browser.

Where you aware of this issue? Do you have any plan on making this component IE11 compatible?

References: CanIuse link to the method: http://caniuse.com/#search=currentScript Polyfill suggested: https://github.com/JamesMGreene/document.currentScript

1000ch commented 8 years ago

Did you try webcomponents/webcomponentsjs?

biaggi commented 8 years ago

Thank you for your fast reply.

We were already including webcomponents.lite, i've upgraded it to the full version but regretfully does not solve the problem.

I've been reading your code and seems that I can try to workaround the problem. If I find a solution, I'll send you a pull request.

biaggi commented 8 years ago

In order to get it working in IE11 seems that the solution is to include webcomponents and in adition add this lines to the var currentScript initialization

var currentScript = null;
if (document._currentScript) {
        currentScript = document._currentScript;
 } else {
        currentScript = document.currentScript;
}

The error is gone but I cannot see if is working cos I have another issue not related with this one with createShadowRoot method not defined, I hate IE in all of its forms :-P

I've seen that there is an index.html but the linked css are not in this repository, any suggestion on how to test this component isolated?

donick commented 5 years ago

You can get the path from Error stack, using regExp to match the path you needed.

var err = new Error();
var stack = err.stack;

if (!stack) {
    try {
          throw err;
    } catch (e) {
          stack = e.stack;
    }
}