[pmwiki-devel] Looking for comments on possible standard for dynamic skins
Henrik Bechmann
henrik at bechmann.ca
Tue May 13 22:43:24 CDT 2008
All,
I'm cleaning up the skin I use on my websites, preparing to create more,
and have encountered a simple issue that may have a simple solution. For
dynamic layout websites (ie which use some javascript), there is often a
need for more than one script to run some kind of initialization routine
on load. It can be cumbersome to edit the onload/onunload attributes of
the body element for each initialization, so I thought that the
following (or something like it) might be a useful standard for us to
collectively follow. (There may already be such a thing, and if so I'd
be happy to hear about it.).
The standard would be to offer two simple javascript objects in the head
of each skin. One to take registrations of load and unload javascript
functions; the other to accept parameters for javascript routines. (The
application javascript routines requiring initialization would typically
be loaded through $HTMLHeaderFmt). The registered functions would be run
on load and unload; the parameters could be read by any javascript
routine that knows about them.
Here's the code for the header that I propose:
====================== start ==================
<script type="text/javascript">
var LoadManager = {
loadlist:[],
unloadlist:[],
registerloadfunction: function (theFunctionName) {
LoadManager.loadlist.push(theFunctionName);
},
registerunloadfunction: function (theFunctionName) {
LoadManager.unloadlist.push(theFunctionName);
},
load: function() {
for (var i=0;i<LoadManager.loadlist.length;i++) LoadManager.loadlist[i]();
},
unload: function() {
for (var i=0;i<LoadManager.unloadlist.length;i++) LoadManager.unloadlist[i]();
}
}
var Parameters = {}
</script>
============================== end ==============================
Here is the body element opening tag:
======================== start ==========================
<body onload="LoadManager.load()" onunload="LoadManager.unload()">
======================== end ==========================
If there is any interest or commentary on this, please let me know.
- Henrik
--
Henrik Bechmann
bechmann.ca
Webmaster, celos.ca webhosting services
More information about the pmwiki-devel
mailing list