Lightview was built to change the way you overlay content on a website.
First make sure you have a valid doctype set as the very first line on the page. I recommend using the HTML5 doctype:
<!DOCTYPE html>
Upload all files from the lightview package to your server: Javascript, CSS and the images.
Lightview requires Prototype 1.7.0 and Scriptaculous 1.8.3+. In the example below I'm including both using the Google AJAX Libraries API. As an alternative you could download and host Prototype and Scriptaculous yourself, but by including both using Google's AJAX Libraries API you don't have to worry about caching and bandwidth cost.
Add Lightview below these libraries, the correct order of the javascript files is as in the example below.
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/prototype/1.7.0/prototype.js'></script> <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/scriptaculous/1/scriptaculous.js'></script> <script type='text/javascript' src='/js/lightview.js'></script>
Add lightview.css to your header.
<link rel="stylesheet" type="text/css" href="css/lightview.css" />
Note: The downloads have an example folder demonstrating the installation.
A view is created using a links class attribute. Single images should have the rel attribute set to 'image', but you can also use no rel attribute at all.
<a href='image.jpg' class='lightview'>My image</a>
An image gallery can be created using rel='gallery[galleryname]'
<a href='image1.jpg' class='lightview' rel='gallery[mygallery]'>Image 1</a> <a href='image2.jpg' class='lightview' rel='gallery[mygallery]'>Image 2</a>
A set can contain any type of media, it's syntax is similar to that of a gallery except set is used instead of gallery. The slideshow button will be enabled when a set consists of images only.
<a href='image.jpg' class='lightview' rel='set[myset]'>My image</a> <a href='movie.mov' class='lightview' rel='set[myset]'>A Quicktime movie</a> <a href='flash.swf' class='lightview' rel='set[myset]'>Flash movie</a>
You can set the title and caption using the title attribute. Use the characters :: if you want both title and caption. This character combination can be changed using the titleSplit option.
<a href='leopard.jpg' title='A title' class='lightview'>Leopard</a> <a href='gazelle.jpg' title='This image has a title :: And a caption' class='lightview'>Gazelle</a> <a href='cheetah.jpg' title=":: I don't have a title, just a caption" class='lightview'>Cheetah</a> <a href='rhino.jpg' title="Left in split characters will get stripped :: " class='lightview'>Rhino</a>
Media other then images supports a thirth parameter with options. There are a lot of options you can use, check the documentation for the available options on each type of media.
<a href='http://google.com' rel='iframe' title='Google :: :: fullscreen: true' class='lightview'>Google</a> <a href='http://yahoo.com' rel='iframe' title='Yahoo :: caption :: width: 800, height: 600' class='lightview'>Yahoo</a>
Lightview will automatically try to detect what type of content you are viewing based on the extensions set in lightview.js. When Lightview can't detect your filetype you will have to set the rel attribute to match it. If you want to show flash for example and the filetype isn't automatically detected you'll have to set rel='flash', other options are quicktime, inline, ajax and iframe.
It's also possible to force a filetype on a set using the following syntax rel='set[setname][type]'. It's impossible for Lightview to detect that the videos below are flash videos since there are no file extensions, forcing the filetype solves this problem. See the documentation for more information on filetypes and forcing them onto a view.
<a href='http://www.youtube.com/v/CQzUsTFqtW0' class='lightview' rel='set[myset][flash]'>Youtube</a> <a href='http://vimeo.com/moogaloop.swf?clip_id=2874824&server=vimeo.com&autoplay=1' class='lightview' rel='set[myset][flash]'>Vimeo</a>
Lightview will show inline content if you set the href attribute to '#id'. The autosize option can be used on ajax and inline views, this will automatically resize them to the content recieved. topclose can be used on ajax, iframe and inline content to have the close button that slides out instead of the static one.
<a href='#hiddenform' class='lightview' title=" :: :: topclose: true, autosize: true">Show Form</a>
<a href='/ajax/' class='lightview' rel='ajax' title=" :: :: ajax: { onComplete: callback }">Ajax Form</a>
<a href='#anotherElement' class='lightview' title=" :: :: menubar: false">No menubar</a>
It's possible to show a view using javascript:
document.observe('lightview:loaded', function() {
Lightview.show({
href: '/ajax/',
rel: 'ajax',
title: 'Login',
caption: 'Enter your username and password to login',
options: {
autosize: true,
topclose: true,
ajax: {
method: 'get',
evalScripts: true,
onComplete: function(){ $('name').focus(); }
}
}
});
});
// Here we observe an element and call Lightview.show, the lightview:loaded event
// is used here to make sure Lightview.show is available.
document.observe("lightview:loaded", function() {
$("elementId").observe('click', function() {
Lightview.show({ href: 'anotherElementId', rel: 'inline' });
});
});
// If you have firebug installed you can run this from your console, have fun.
Lightview.show({ href: 'http://www.google.com', rel: 'iframe', options: { width: 800, height: 500 }});
The type of view will be auto-detected using the url you provide. If for some reason you want to force a specific type of view you can overwrite the auto-detection using the rel attribute.
Lightview.show({
href: 'http://www.youtube.com/v/0alNtVUy7YY&autoplay=1',
rel: 'flash'
});
You can set the following options in lightview.js.
You can overwrite the auto detection of the media type. This is useful when Lightview is not detecting your media. For example, when including Youtube or Google video through flash you need to use rel='flash', on a set you will need to use rel='set[setname][flash]'. The following types can be set on the rel attribute.
These options can be used as thirth parameters in the title attribute, seperated by commas. title='title :: caption :: autosize: true, topclose: true'
The following function are available to you.
Lightview comes with a set of useful custom events you can observe to attach your own callback functions.
You can observe the document or individual links for this event. A function can be called when the event fires. Within the function, event.target will refer to the element that was opened, a few examples:
document.observe('lightview:opened', function(event) {
alert('You opened ' + event.target.href);
});
$('myId').observe('lightview:opened', function(event) {
new Effect.Pulsate($('lightview').down('.title'));
});
Fires on the document when Lightview is loaded and ready for a Lightview.show call.
document.observe('lightview:loaded', function() {
Lightview.show('myId');
});Since Lightview uses Prototype you'll have to enable jQuery.noConflict to avoid conflicts between jQuery and Prototype. You can find documentation about it on the jQuery website. Here's an example of a correct use of jQuery.noConflict so it works with third party code like Lightview:
<!-- Include jQuery --> <script type='text/javascript' src='/js/jquery.min.js'></script> <!-- Enable noConflict --> <script type='text/javascript'>jQuery.noConflict();</script> <!-- Other scripts can now safely use their own $ function --> <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js'></script> <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/scriptaculous/1/scriptaculous.js'></script> <script type='text/javascript' src='/js/lightview.js'></script>
Since the point of jQuery.noConflict is to remove the $ function out of the global scope and give it back to its original owner you should always use a closure that turns the jQuery object into the $ function. This makes it possible to use the jQuery object as the $ function within your own scope, making your code work with third party code. Here's an example:
(function($) {
/* The jQuery $ function can be used here without conflict.
* It's recommended to always use a closure like this so your jQuery code will work
* with third party code without having to modify anything later on.
*
* jQuery plugins that are properly coded already use a closure like this.
*/
$(document).ready(function() { alert('this is jQuery'); });
})(jQuery);
$(document).observe('dom:loaded', function() { alert('this is Prototype'); });
Give your page a doctype, I recommend using the HTML5 doctype.
See the solution above.
Lightview will look for links with the class lightview once the DOM is loaded. Even though this only takes a little while for most pages it could be that you've clicked the link before the documented was loaded.
You must have effects.js from the Scriptaculous package. Get the full scriptaculous download at script.aculo.us
This could be because lightview.css is not included or the images are not uploaded. It also happens when your own CSS is conflicting with lightview.css. Make sure you target elements in your CSS without setting things global, code like li { display: inline; } for example is bad practice when you use third party code like Lightview. When your CSS is properly coded and all the required files are uploaded and included you should have no problem implementing Lightview.
Make sure you have the right versions of Prototype and Scriptaculous and validate your website using validator.w3.org before posting for support on the Lightview Forum. I also recommend getting Firefox with the Firebug addon, many problems posted on the forum are quickly solved with the debugging it provides.
Permission to use Lightview on your domain is required and can be obtained by paying a small fee. For non-commercial domains this will allow you to use Lightview under a Creative Commons by-nc-nd License. When you get permission for a commercial domain you may use Lightview under the terms of the Creative Commons by-nd License.
Note: A new jQuery based version of this script is available: Lightview 3
Use the Lightview Forum for support related questions, feedback, feature requests and bug reports. If you are posting for support please read through the Troubleshooting section first.
For anything non-support related you can contact me at nick@nickstakenburg.com or @staaky. Please use the Forum to get support, I don't have the time to answer every support related email individualy.