Hey folks,
extraction feature and JsExp expressions that referenced HTML (like, for example,
the JQuery JqAppend helper). Specifically in these cases, the generated code would
run the event handler attachment JavaScript when the HTML was passed to the JS,
which means it was being executed before the HTML was actually attached to the
DOM.
complicated than originally understood. Andreas wanted a particular behavior (event
attachment occurring after the DOM insertion, but before any other chained JQuery
updates were handled), and general reworking would be required no matter what
our updated approach is.
With all that background out of the way, there's a decision facing us now:
- We keep the current behavior, which will try to run event handler attachment before
DOM insertion. This is obviously broken.
- We don't do event handler extraction in JsExps, even if extractInlineJavaScript is
enabled.
- We update event handler extraction for JsExps so that any extracted JS is executed
after the chained JsExps have all been executed.
The last one is a fairly deep change, but should be manageable without regressions.
I don't like the other two much, personally, but wanted to open up the floor to other ideas.
One more tidibt: an example.
JqId(Str("test")) ~>
JqAppend(<button onclick="doSomething();">Test</button>) ~>
JqAppend(<button onclick="doSomethingElse();">Test2</button>)
The goal here is:
<div id="test">
<button>Test</button>
<button>Test2</button>
</div>
Where the buttons do the appropriate thing. Option (a) would produce this JS:
$('#test')
.append((function() {
lift.onEvent("lift-event-js-F397700660826TXLHFS", "click", function (event) {
doSomething();
});
return "<button id=\"lift-event-js-F397700660826TXLHFS\">Test</button>";
})())
.append((function() {
lift.onEvent("lift-event-js-F397700660826TXABCD", "click", function (event) {
doSomething2();
});
return "<button id=\"lift-event-js-F397700660826TXABCD\">Test2</button>";
})())
Note that `onEvent` runs before the HTML is returned, and therefore before the
append is executed. This is what happens today.
Option (b) would produce this JS:
$('#test')
.append("<button onclick=\"doSomething()\;">Test</button>")
.append("<button onclick=\"doSomething2();\">Test2</button>");
Note that it would do this even if extractInlineJavaScript was enabled. So that flag
could not be used to deal with ContentSecurityPolicy issues if you did AJAX interactions
that used JsExps.
Lastly, option (c) would produce this JS:
$('#test')
.append("<button id=\"lift-event-js-F397700660826TXLHFS\">Test</button>")
.append("<button id=\"lift-event-js-F397700660826TXABCD\">Test2</button>");
lift.onEvent("lift-event-js-F397700660826TXLHFS", "click", function (event) {
doSomething();
});
lift.onEvent("lift-event-js-F397700660826TXABCD", "click", function (event) {
doSomething2();
});
Note that here we run the event attachment after all the jQuery work is complete.
So, I vote (c). Other votes and/or ideas for handling the issue?
Thanks,
Antonio