WARNING: This server is unstable and will be retired in the next days.
If you want to keep this forum available, please request immediately a migration
on the
Nabble Support forum.
Forums that don't receive any migration request will be deleted forever.
[CODI] lazy windowId drop script
Hi!
In my project I'm using a small JavaScript which I use to lazily drop the windowId if I detect a new window (by checking for an empty window.name). This of course also has a few side effects, but works well for almost all use cases.
Since CODI is not a component library, we cannot ship this easily.
What is the best way to provide this script to the community?
It's really just quick hack which could/should be improved by the community since I'm a javascript gimp. Just attach it to our CODI Wiki and explain how to use it?
Here's what I have so far:
The javascript file (resources/js/windowId.js)
-------------------------------------------
function urlWithoutWindowId(base) {
var query = base;
var vars = query.split(/&|\?/g);
var newQuery = "";
var iParam = 0;
for (var i=0; vars != null && i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair.length == 1) {
newQuery = pair[0];
}
else {
if (pair[0] != "windowId") {
var amp = iParam++ > 0 ? "&" : "?";
newQuery = newQuery + amp + pair[0] + "=" + pair[1];
}
}
}
return newQuery;
}
function assertWindowId() {
var freshWindow = window.name.length < 1;
if (freshWindow) {
url = urlWithoutWindowId(window.location.href);
window.name = "window";
window.location = url;
}
}
-------------------------------------------
In my layout.xhmtl facelet I use the following :
-------------------------------------------
<f:view locale="#{settings.locale}">
<h:outputScript name="windowId.js" library="js"/>
<script type="text/javascript">
assertWindowId()
</script>
...
-------------------------------------------
which just reloads the window without the windowId= parameter, thus forcing a new windowId from the system.
Just add this to the wiki or can we deliver this script somehow as part of CODi?
LieGrue,
strub