PDA

View Full Version : 2 Cmotion pop-up window questions



walterG
09-23-2005, 11:42 AM
Script : Cmotion
http://dynamicdrive.com/dynamicindex4/cmotiongallery.htm

Hi,

Cmotion is great but two small issues ..

1. In IE6, the image in the pop-up window is offset by 10 pixels ie there is a 10px white band to the left and top of the image. Consequently, there is 10px missing from right and bottom of image. I have set the image dimension correctly. Works fine in Firefox.

2. Is there anyway to make the pop-up window close when the user clicks back on the page, rather than spawning a new window each time they click a thumbnail (without closing the previous pop-up)?

Thanks.

Walt

jscheuer1
09-23-2005, 06:35 PM
Not exactly. Try replacing this:

function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to default height
var winattributes="width="+actualWidth+",height="+actualHeight+",resizable=yes"
window.open(path,"", winattributes)
}with this:

var win = null;
function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
if(win&&!window.opera)
win.close()
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to default height
var winattributes="width="+actualWidth+",height="+actualHeight+",top=250,left=250,resizable"
win = window.open('','', winattributes)
win.document.write('<title>Close Window to Exit</title>');
win.document.write('<body bgcolor="#dddddd" text="#000000" style="margin:0;padding:0;overflow:hidden;">');
win.document.write('<img width="'+(actualWidth)+'" height="'+(actualHeight)+'" galleryimg="no" src="'+path+'" />');
win.document.close();
win.focus();
}It is now only good for images though. Before, a page could be popped up as well. Refinements are possible.

walterG
09-23-2005, 06:51 PM
Many thanks. :)

This sorts out problem 1 and helps with 2 :)

I've no idea about js but I have a Dreamweaver extension which pops-up open a window (the exact size of any image) but also closes on click back on main page. Here's the head script. Maybe you can understand it and it may help with this query ! :)

---
<script language="JavaScript" type="text/JavaScript">
<!--
function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) { // v4.01
newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
newWindow.document.open();
newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
if (imageType == "swf"){
newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
newWindow.document.write('</embed></object>'); }else{
newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); }
newWindow.document.write('</body></html>');
newWindow.document.close();
newWindow.focus();
}
//-->
</script>
----

Note - grin icon is middle is "colon D" with no space.

Walt.

Twey
09-23-2005, 07:29 PM
Try <body onclick="win.close()"> for the close-on-click thing.

jscheuer1
09-24-2005, 03:44 AM
I had tried that Twey but, the window then closes as it opens (all onclick). I just had another idea though, make the new window itself close onblur(). That would make our enlargeimage function look like this:

function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to default height
var winattributes="width="+actualWidth+",height="+actualHeight+",top=250,left=250,resizable"
var win = window.open('','', winattributes)
win.document.write('<title>Close Window to Exit</title>');
win.document.write('<script>window.onblur=function(){self.close();}<'+'/'+'script>')
win.document.write('<body bgcolor="#dddddd" text="#000000" style="margin:0;padding:0;overflow:hidden;">');
win.document.write('<img width="'+(actualWidth)+'" height="'+(actualHeight)+'" galleryimg="no" src="'+path+'" />');
win.document.close();
}We can also dispense with the line:

var win = null;

walterG
09-24-2005, 09:23 AM
Excellent. Perfect. Thanks!

Walt.