Closed kevinresol closed 8 years ago
I think there are some glitches for this method. I got some functionalities not (or occasionally) working when the pages are refreshed by the js client. Particularly, I am using UIkit. After refreshing, the nav bar dropdown just won't show (but it sometimes shows again when the page refreshed again).
Need some ways to thoroughly test this. Any ideas?
I've got the same glitches with this method. As a (hacky) workaround I gave the script tag an id attribute in CallJavascriptResult.hx:
public function addInlineJs( js:String ):CallJavascriptResult<T> {
scripts.push( '<script id="ufrontScript" type="text/javascript">$js</script>' );
return this;
}
public function addJsScript( path:String ):CallJavascriptResult<T> {
scripts.push( '<script id="ufrontScript" type="text/javascript" src="$path"></script>' );
return this;
}
and check this attribute in HttpResponse (js):
document.find("script").each(function(node) {
if (node.attr("id") == "ufrontScript") {
...
using it in the controller
var result = new ViewResult(args).addJsScriptToResult("path/to/script");
return result;
Updated. Only script tags with uf-reload
attribute will re-run
Examples:
<script uf-reload>console.log("test");</script>
<script uf-reload src="app.js"></script>
Next: Need to add one more parameter (reload:Bool
) to CallJSResult
public function addInlineJs( js:String, reload:Bool ):CallJavascriptResult<T>;
public function addJsScript( path:String, reload:Bool ):CallJavascriptResult<T>;
+1 looks like a nice solution
23
I only tested it on Chrome and scripts was executed nicely.