...

View Full Version : code in external file



roice0
10-30-2010, 11:16 AM
Hello,
I found script for lightbox-
http://www.sohtanaka.com/web-design/examples/modal-window/

I want to take the code that inside the <script type="text/javascript">.....</script> tags (the one that start with "$(document).ready(function(){", and put it inside new file call "lightbox.js", and than call this file with this code:
<script type="text/javascript" src="lightbox/lightbox.js"></script>

I did it but for some reason, when I take the code out of the " <script type="text/javascript">....</script> " tag and put it in other file, the script doesn't work.

Should I change anything in the script for that?

Thank you in advance.

abduraooft
10-30-2010, 11:37 AM
I did it but for some reason, when I take the code out of the " <script type="text/javascript">....</script> " tag and put it in other file, the script doesn't work. Can we have a link to your page?

roice0
10-30-2010, 12:04 PM
Its still under building.
Can you please take a look at the first link that I gave above?
in the source of it you have the JS code:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size

//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value

//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;

//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});

//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer

return false;
});


//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
}); //fade them both out

return false;
});


});

</script>

abduraooft
10-30-2010, 01:07 PM
Are you using the <script> tags inside your external js file?

roice0
10-30-2010, 01:19 PM
No,
the external file start with:
$(document).ready(function(){

glenngv
10-31-2010, 02:51 AM
Make sure you include the jquery js first then the lightbox.js


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="lightbox/lightbox.js"></script>

Also check if the path to the lightbox.js is correct. And check the javascript console or firebug for any errors.

Does the code work before you added lightbox as an external js?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum