This is how to get Nifty Corners Cube (i.e. v3) to work on PunBB without dropping the form element focusing. (Nifty Corners Cube is an unobtrusive and flexible application for getting rounded corners on your site)
Open "header.php".
After the lines:
<?php
if (defined('PUN_ADMIN_CONSOLE'))
echo '<link rel="stylesheet" type="text/css" href="style/imports/base_admin.css" />'."\n";
And before the lines:
if (isset($required_fields))
{
// Output JavaScript to validate form (make sure required fields are filled out)
?>
<script type="text/javascript">
Add the following:
// Import Nifty Corners Cube for rounded corners
// Import function for handling multiple onload events
// Load such events (form element focusing and Nifty Corners Cube)
?>
<link rel="stylesheet" href="<?php echo PUN_ROOT ?>/...?.../niftyCorners.css" type="text/css" media="screen" />
<script type="text/javascript" src="<?php echo PUN_ROOT ?>/...?.../niftycube.js"></script>
<script type="text/javascript" src="<?php echo PUN_ROOT ?>/...?.../addLoadEvent.js"></script>
<script type="text/javascript">
addLoadEvent(function(){Nifty("xxx","yyy")});
<?php
if (isset($focus_element))
{
?>
addLoadEvent(function(){document.getElementById("<?php echo $focus_element[0] ?>").<?php echo $focus_element[1] ?>.focus()});
<?php
}
?>
</script>
<?php
In the code above, there are three instances of "/...?.../" and the two instances of "xxx" and "yyy".
I am not hear to explain Nifty Corners Cube, so users of the application should recognize the "xxx" and "yyy" as the spots where they would insert the parameters for the application.
The first two "/...?.../" will need to be replaced with the sub-directory (folder) path that you have stored the "Nifty Corners Cube" files in (relative to the directory PunBB is installed in). (Only the files loaded above are actually necessary for the Nifty Corners; the other files included in the Nifty Corners zip file are examples and such.)
The third "/...?.../" will need to be replaced with the sub-directory (folder) path that you have stored the "addLoadEvent.js" javascript file in (relative to the directory PunBB is installed in). This file (addLoadEvent.js) should contain the following code:
/*
* Executing JavaScript on page load
* Author: Simon Willison
* Source: http://simonwillison.net/2004/May/26/addLoadEvent/
*/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load */
});
If you would rather include this tiny function directly within header, it is also acceptable to instead replace the line:
<script type="text/javascript" src="<?php echo PUN_ROOT ?>/...?.../addLoadEvent.js"></script>
...with the javascript function it refers to (i.e. the javascript function I printed above).
And very important! Make sure to delete (or comment out) the code that uses the "body" tag to focus on the form element. (This was done at the beginning of this thread with the effect of making the Nifty Corners application work, and is still required to do so.) In case you missed the discussion above, this is the code you must delete (or comment out):
// START SUBST - <body>
if (isset($focus_element))
{
$tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus();', $tpl_main);
$tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus()">', $tpl_main);
}
// END SUBST - <body>
I have tested this in The following Mac browsers: Firefox 2, Opera 9, Netscape 7, Safari 2. I repeat, those are for Mac. If some kind soul out there tests this on Windows browsers, please tell me the results
The author of addLoadEvent(), Simon Willison, on 26th May 2004 regarding his function wrote:... I?ve tested the above code successfully on IE 5, 5.5 and 6 for Windows; IE 5 and Safari for Mac; Opera 7.5 and FireFox on Mac (which should mean it works with those browsers on Windows as well). Opera 6 for Mac failed the test ...