Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-02-07 00:33:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Using flat js for Modules

Hmmm. Trying to incorporate plyr.io into a site. If I upload all the paraphernalia and 3 million support files into my /themes/theme-name/forms/js directory and kick the main script off with this:

<txp:output_form form="plyr.js" format="flat.script" />

I get SyntaxError: import declarations may only appear at top level of a module.

But if I use:

<script type="module" src="/themes/theme-name/forms/js/plyr.js"></script>

Then it loads (albeit that I get warnings in Firefox that it can’t load the modules, which seems to be because the programmer of plyr.io didn’t use imports with full filename including the .js extension so I need to go through and change them all *sigh*).

Is it possible to load modules using the flat.script technique? I’m not sure <txp:yield> variables help me in this situation.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2019-02-07 07:55:08

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Using flat js for Modules

Like this?

<script type="module" src="<txp:output_form form="plyr.js" format="flat.url" />"></script>

I don’t think <txp:yield /> would work here, though we could amend it in a future version.

Offline

#3 2019-02-07 09:23:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Using flat js for Modules

Aye, that would work. Didn’t think of tag-as-attribute, thank you.

The <txp:yield /> thing is probably not so important: I think I can get Txp to parse() the js file so I can inject the tracklist and metadata from the surrounding <txp:file_download_list> tag via vanilla tags embedded in the script that kicks things off.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2019-02-07 12:52:13

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Using flat js for Modules

Here is another option. Just register type attribute for script tag and you should be able to call

<txp:output_form form="plyr.js" format="flat.script" type="module" />

Offline

#5 2019-02-07 13:09:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Using flat js for Modules

Wow, awesome. I’ll give your plugin a whirl too, thank you so much.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB