jsxdirect icon indicating copy to clipboard operation
jsxdirect copied to clipboard

How to you load a script with this?

Open vans163 opened this issue 7 years ago • 2 comments

How do you load a script like ?

vans163 avatar Dec 08 '18 00:12 vans163

@vans163 This is not currently possible. Only JSX within the script tags is supported. That being said, it is not impossible to implement. There would just need to be some conditional logic looking for an src attribute and doing fetches to get the strings to process.

if(scripts.length===0) scripts = document.querySelectorAll("[type='text/jsx']");
	scripts.forEach(el => { // change into a for of loop
                        // look for 'src' attribute, if found, fetch text content
                        // otherwise user innerHTML
			const script = JSXTranspile(el.innerHTML,options),
				node = document.createElement("script");
		for(const attr of [].slice.call(el.attributes)) node.setAttribute(attr.name,el.attributes[attr.name]);
		node.type = "text/javascript";
		node.innerHTML = script;
		el.parentElement.replaceChild(node,el);
	});

anywhichway avatar Dec 08 '18 02:12 anywhichway

This is cool yea, good to declutter the code a bit.

vans163 avatar Dec 08 '18 23:12 vans163