Click to See Complete Forum and Search --> : I need help designing a javascript thumbnail function


ldfedje
12-20-2005, 06:14 PM
Hi

I am new to this forum, so bear with me while I learn your protocol. I am also fairly new to web design and very new to javascript. Just to give you a little background, I have designed a couple of sites using Web Studio which is a WYSIWYG type design program with capbility of alowing the user to go as far as he/she wishes. Adding CSS, Javascript, Tables and much more can be achieved with this tool.

One of the functions I have been working on is the development of a Pop-Up that is controlled from the body by passing variables to a javascript function, but I am not quite sure how to get there.

Here is the code I have been working with. This code was found on this site at http://www.webdeveloper.com/forum/showthread.php?t=88984 , modified a bit:

<head>
<title></title>

<script language="JavaScript">

var aWindow;

function CkImg(img){
var Img=new Image();
Img.onload=function(){ openWin(this); }
Img.src=img;
}


function openWin(URL)
{
CloseWin();
aWindow=window.open (URL.src, "aWindow", "toolbar=no, width="+(URL.width+20)+", height="+(URL.height+20)+", status=no, scrollbars=no, resize=no, menubar=no, left="+(((screen.width-URL.width)/2)-20)+", top="+(((screen.height-URL.height)/2)-20)+"" ) ;
//aWindow.sizeToContent()
}

function CloseWin(){
// Include CloseWin() in body tag to ensure that the pop-up closes when the main window looses focus.
if (aWindow&&!aWindow.closed){ aWindow.close(); }
}

</script>

</head>

<body onunload="CloseWin();" >

<input type="button" name="" value="Img 1" onclick="CkImg('http://www.lumierestandardpoodles.com/LargePhotos/2004-3-L.jpg');">
<input type="button" name="" value="Img 3" onclick="CkImg('http://www.lumierestandardpoodles.com/LargePhotos/2004-5-L.jpg'); ">


</body>

</html>

What I would like to do is pass variables from the body to the script. These variables would be:
URL (which is already there)
Center - true/false
Left Offset from Center (a negative or positive number)
Right Offset from Center (a negative or positive number)
positionLeftX - If not centered X px from left
positionTopY - If not centered Y px from top
bordercolor - self explanitory
borderWidth - a positive number

With this information, I would then like to create the pop-up based on the information provided by the variables.

-If Center (true) and no offset (0), the code would be similar to the quoted code.
-If Center (true) and Offset values either with a negative number or positive number the above code would include the offset values.
-If not center (false), the x and y co-ordinates would be used.
-The way the code stands right now the border around the image is white, however, I would like that to be variable based on the information passed.
-The way the code is structured above, there is a 20 px border around the images. I would like the user to be able to increase that, or if there is a way, reduce it so that there is no border.

The only rule that would have to apply to this structure is that the maximum image height would be 500 px and the maximum width would be 700 px. This would be to allow for viewing at a 800 x 600 resolution. If the user put in a +50 px border and the screen height is 600 px he would have an image overrun on the page, so I guess that would also have to come into the calculations.

The optimal javascript function would be to put it in a .js file at the root, called from a snippit in the head which would of course be called from the body. The reason for this is that the user would only have to install one .js file and the rest would be passed from the page.

I tried another script that I use on these 2 pages, but they don't work as well as the above script.

http://www.lumierestandardpoodles.com/2004.html and http://www.lumierestandardpoodles.com/2005.html

You can view the page source for the code that I used there if you feel it necessary.

Is this overboard for a Pop-up script? :confused:

Any comments, assistance that you might have would be greatly appreciated. If I am going overboard, let me know that as well.

Regards: Loren

bathurst_guy
12-20-2005, 09:45 PM
Seeing as though you are just starting out with things I would like to strongly recommend CSS for this and not javascript. Like would something like this (http://www.cssplay.co.uk/menu/gallery.html) be more suitable? Or this (http://www.cssplay.co.uk/menu/scroll_gallery.html), or maybe this (http://www.cssplay.co.uk/menu/gallery4.html)?

ldfedje
12-21-2005, 06:53 AM
I have already done exactly that in a table and it works quite well. http://www.lumierestandardpoodles.com/SpecialFeature.html

I am simply trying to get a standard Pop-up to work the way I have described. The only thing that I forgot to mention is that there should be a progress bar showing while the image downloads to let dial-up users know something is happening.

I will keep trying.

Thanks for the comments.

Loren

ldfedje
12-21-2005, 04:42 PM
I have now got it working by passing the values from the body to the head. Now I need to install a progress bar and find some way to make the new pop-up a table so that I can change the background color, background width, center image, have no border at all. All of these things are possible, given enough time. Here is the code that I have developed so far. It works in IE, NS and FF. There is a small top alignment problem in Opera.

Give it a try, simply by changing some of the vairables in the call.

<head>
<title></title>

<script language="JavaScript">

var aWindow,leftoffset=0,topoffset=0,leftposition=0,topposition=0,mycenter=true,addtoborder=0;
var mybar='toolbar=no, status=no, scrollbars=no, resize=no, menubar=no';

function CkImg(img,mycenterx,leftoffsetx,topoffsety,leftpositionx,toppositiony,addtoborderx)
{
mycenter=mycenterx
leftoffset=leftoffsetx
topoffset=topoffsety
leftposition=leftpositionx
topposition=toppositiony
addtoborder=addtoborderx
var Img=new Image();
Img.onload=function()
{
openWin(this);
}
Img.src=img;
}


function openWin(URL)

{
if(mycenter){

CloseWin();
aWindow=window.open (URL.src, "aWindow","mybar, width="+(URL.width+20)+", height="+(URL.height+20)+", left="+(((screen.width-URL.width)/2)-20+(leftoffset))+",top="+(((screen.height-URL.height)/2)-20+(topoffset))+"" ) ;
//aWindow.sizeToContent()
}
else
CloseWin();
aWindow=window.open (URL.src, "aWindow","mybar, width="+(URL.width+20)+", height="+(URL.height+20)+", left="+leftposition+", top="+topposition+"" ) ;
}


function CloseWin()
{
// Include CloseWin() in body tag to ensure that the pop-up closes when the main window looses focus.
if (aWindow&&!aWindow.closed)
{
aWindow.close();
}
}

</script>


</head>

<body onunload="CloseWin();" >


<input type="button" name="" value="Img 1" onclick="CkImg('http://www.lumierestandardpoodles.com/LargePhotos/2004-3-L.jpg',false,100,50,20,20,30);">

<input type="button" name="" value="Img 3" onclick="CkImg('http://www.lumierestandardpoodles.com/LargePhotos/2004-5-L.jpg',true,100,50,20,20,0);">


</body>

</html>

Opinions, assistance and comments welcome.

Loren

Ultimater
12-21-2005, 05:16 PM
As a comment, I would suggest another approach.
Pop up blockers will block windows created with window.open. I'd suggest using a FORM with a target="_new" to create the pop ups. Once the popup window is created, the popup can reference the opener directly via window.opener.variableName and can read any variables it wants to. Also you can write to a popup, you know.

ldfedje
12-21-2005, 05:43 PM
Do you know of any examples I can follow?

I appreciate any help I can get.

Loren

ldfedje
12-23-2005, 08:46 AM
Ok, I give up! I have to agree that pop-up windows are not the best way to go!

Does anyone know of a piece of code (not php) that will produce results similar to a popup but on the page.

No preloading of images (could take too long)
onclick download the image and display it on top of the page.
progress bar "Image loading"
click anywhere and it closes.

I use a script on this page http://www.lumierestandardpoodles.com/About.html , however, it requires preloading so if you have lots of large images the page takes forever. It's done in javascript. Put your cursor over "Why is it not just a Poodle". This is great for a tooltip but not for large versions of images.

Something like this would be perfect except for the preloading.

Any help would be appreciated, even if you just pointed me in the right direction.

Loren

Ultimater
12-23-2005, 03:56 PM
Do me a favor and make a new thread and explain everything you need from the beginning -- I'm losing you. You should do everything in your power to get express your situation so we can do everything in our skills to make it possible. One thing that I don't have is time to re-read threads from the very beginning gathering details. I hope you understand, I only want to help you resolve the issue.