Easy all
Since I studied jQuery recently, I decided to write my own modal window for playing videos when a video thumbnail is clicked. Everything works fine, but I'm just wondering how I can turn it into a plugin so that I can use it on different pages with different parameters, etc. I read the documentation and some manuals, but I can't seem to get it to work. My main code is as follows:
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){
$j("a.video_link").click(function (e) {
e.preventDefault();
$j('body').append('<div id="overlay" />');
$j('#overlay').css({"display":"block","opacity":"0"}).animate({"opacity":"0.2"}, 300),
$j('#video').css({"top":"43%"}).css({"opacity":"0"}).show().animate({"top": "50%", "opacity": "1"}, 550),
$j('#video').append('<div id="modal-vid-close" title="Close window" />');
$j('#overlay, #modal-vid-close').click(function () {
$j('#video').animate({"top": "55%", "opacity": "0"}, 350).fadeOut(200),
$j('#overlay').fadeOut(200, function () { $j(this).remove(); $j('#modal-vid-close').remove()} )
});
});
});
I would like to turn this into a plugin so that I can use it on different pages, and just specify the trigger link and div identifier that will be displayed in the window (it will already be loaded on the page, but hidden). Something like this added to the loading of the document on each page:
var trigger = $j('.video_container a');
var modalcontent = $j('#video');
, , !