Using Event.observe is a way of keeping content and function separate. Because I execute it within a function that also contains the function named whatever, it keeps whatever out of the global scope. Both of these are just good practice, and will make it easier to add to or modify this code for use on multiple pages should the need ever arise.
I discovered that if you tell lightwindow 2.0 (which I used in my mock up) what sort of type to expect, it reacts fine without that trailing slash:
Code:
myLightWindow.activateWindow({
href: 'http://www.google.com',
title: 'Melons taste nice raw',
author: 'ThaXhizz',
caption: 'Mmmmmm Margaritas! And yes, this is me...',
height: 650,
width: 850,
type: 'external'
});
I also discovered that lightwindow 2.0 apparently (at least for this code) runs fine under prototype 1.7.0.0 and scriptaculous 1.8.3 (both the latest stable versions I think, and more advanced than those in the lightwindow distro).
This allows us to use the document dom:loaded event (faster than the window load event) and the Event.observe shortcuts:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="javascript/lightwindow.js"></script>
<link rel="stylesheet" href="css/lightwindow.css" type="text/css" media="screen" />
<script type="text/javascript">
(function(){
function whatever(){
myLightWindow.activateWindow({
href: 'http://www.google.com/',
title: 'Melons taste nice raw',
author: 'ThaXhizz',
caption: 'Mmmmmm Margaritas! And yes, this is me...',
height: 650,
width: 850
});
}
document.observe('dom:loaded', function(){
$('clicker').observe('click', whatever);
});
})();
</script>
<style type="text/css">
iframe {
overflow: hidden!important;
}
</style>
</head>
<body>
<form>
<input id="clicker" type="button" value="Click me!" />
</form>
</body>
</html>
This also allows us to change (near the end of lightwindow.js):
Code:
Event.observe(window, 'load', lightwindowInit, false);
to:
Code:
document.observe('dom:loaded', lightwindowInit);
for at least slightly faster response time in initializing lightwindow. On a page with many images, this response time increase will be significant.
Bookmarks