How can I "always" open images in a new window?
asad_wosaibi
Joined: 2005-05-26
Posts: 7 |
![]() |
Hi, |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
See this thread, http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=27255&highlight=open+window. Only you'll be editing albumBody.tpl instead. |
|
Xprcsn7
Joined: 2005-08-01
Posts: 10 |
![]() |
I checked the thread and apparently they hadn't figured it out. Their goal was slightly different: to make a full sized image to appear as a popup, what i'm trying to do is simply click on thumbnail and opens the regular medium sized photo page in a new window this way people can view the thumbnails and picture at the same time, but in G2b4...i think the other guy had b1. |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
I've been talking to bharat on irc on how to do this. It's possible, but not efficient. He started down the path of getting me the answer, but we stopped when he suggested it might be easier to just edit photo.tpl to render only the image. Here's the useful stuff from our conversation: Quote:
<bharat> sure .. if you know the id of the resize you can do That's when I started editing photo.tpl, theme.inc and creating a new "wrapper" for photo.tpl on my site. I'm lazy and didn't put in the extra 5 seconds of work to edit album.tpl to open the link in a new window. ;) Check out my site for an example: removed link, it doesn't contain modifications any longer those changes will be there for a couple of days or at least until I update from CVS again. Here's what I did: 1) created a 'local' directory under /themes/matrix/templates and copied photo.tpl into it. You'll want album.tpl as well 2) edited photo.tpl to look like this {if !empty($theme.imageViews)} {assign var="image" value=$theme.imageViews[$theme.imageViewsIndex]} {/if} {if isset($theme.photoFrame)} {g->container type="imageframe.ImageFrame" frame=$theme.photoFrame} {g->image id="%ID%" item=$theme.item image=$image fallback=$smarty.capture.fallback class="%CLASS%"} {/g->container} {else} {g->image item=$theme.item image=$image fallback=$smarty.capture.fallback} {/if} 3) created a new file imaginatively called 'none.tpl' in the same 'local' directory and copied the contents of theme.tpl into it. Then I cut out the stuff I didn't want, breadcrumb, the image at the top, the images at the bottom, etc 4) edited theme.inc and revised the showPhotoPage() function to return 'none.tpl' instead of 'theme.tpl' That's pretty much it. You'll want to edit album.tpl to open the link in a new window and you may want to use javascript or what ever you want to open the new window. Gotta go the Closer is on ;) Oh and maybe take a look at this, may or may not help: http://wpg2.ozgreg.com/viewtopic.php?t=46 |
|
Xprcsn7
Joined: 2005-08-01
Posts: 10 |
![]() |
Hi, I followed your instructions to the last step...which again, is the final code for creating the new window. I'm sorry but I have no background in PHP or java or whatever the code is for album.tpl. So I went online and looked for new window scripts and tried pasting them but no luck....I also looked at the other link, but they hadn't figured it all the way out yet...and I also checked out your site and navigated all over the test pages, but did not find an example of an album thumbnail opening a new window. we're soo close, all I need is that five seconds you lazed out on! :D |
|
n8jaeger
Joined: 2005-06-20
Posts: 13 |
![]() |
hi all, |
|
n8jaeger
Joined: 2005-06-20
Posts: 13 |
![]() |
self-solved ;) change <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"}"> to <a {if $frameType != "itemFrame"} |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
That works if you're not showing image frames or want to show the original item (downloadItem). Either way, in my gallery I have full size images restricted to logged in users so I got an error if I wasn't logged in because I'm also using image frames... All you really have to change is this: to this: |
|
szac
Joined: 2003-07-08
Posts: 26 |
![]() |
This is SWEET!! Is it possible to get it to work with RC2? Since the theme.inc system is gone, where would I modify theme.tpl to get it to return photo.tpl in a different template other than theme.tpl? |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
Theme.inc is there. \themes\matrix\theme.inc You'd modify theme.inc to refer the to a different template other than theme.tpl for photos. Re-read my previous post, http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&p=157799#157799 Except my site doesn't have that modification in it any longer. |
|
szac
Joined: 2003-07-08
Posts: 26 |
![]() |
WOW. I totally missed it (was looking in /templates!). Thanks so much for this mod. I've been trying to get something likes this working with G1 for quite some time. Now I'll try to throw some js in there for some nice sized popup windows! CHEERS |
|
szac
Joined: 2003-07-08
Posts: 26 |
![]() |
I found a nice javascript that'll resize the window to the image and add some pixels for the nav and what not. The only problem is that it requires the dimensions of the image to set the size. I'm thinking it's in $photoItem-> somewhere but am clueless to pull it off. I know i have to set the width and hieght as variables and then call them in the js function. How do I call the image dimensions and set them as variables? Thanks Alot! With the javascript working properly I should be able to get my gallery to function somewhat like the "Photo of the Moment" at http://tumyeto.com/[/url] |
|
swordfish
![]()
Joined: 2004-10-01
Posts: 388 |
![]() |
I'm using WPG2 plugin with latest G2 and Matrix theme. For my Full Size images to popup in a new window I simply added the below code to photo.tpl just above {* Download link for item in original format *} This is actually the same exact code taken from the photo.tpl file in wordpress theme. {if count($theme.imageViews) > 1} {if !empty($theme.sourceImage)} <p class="gbIBlock"> <A href="javascript:void(0);" onclick="window.open('{g->url arg1="view=core.DownloadItem" arg2="itemId=`$theme.item.id`"}','viewWindow', '{g->text text="width=%d,height=%d" arg1=$theme.sourceImage.width+20 arg2=$theme.sourceImage.height+20}, resizable=yes,scrollbars=yes' );"> {g->text text="View Full Picture"} {if !empty($theme.sourceImage.width)} ({g->text text="%dx%d" arg1=$theme.sourceImage.width arg2=$theme.sourceImage.height}) ({g->text text="Javascript New Window"}) {/if} </a> </p> {/if} {/if} |
|
szac
Joined: 2003-07-08
Posts: 26 |
![]() |
Sweet! Is it possible to get that to link from the album view? |
|
kylemac123
![]()
Joined: 2005-09-14
Posts: 16 |
![]() |
I seem to be missing something... I had it set so that clicking on the resized image would result in the full sized image being opened in a new window back with beta4 and rc2, now it seems that no longer works, and I can't figure out what I did for the life of me. The above posters solution is alright if you want another link below the image, but I want the image itself to be the link. I figured I'd be editing photo.tpl, but now i'm not so sure. Anyone care to point me in the right direction? |
|
Ave
Joined: 2003-05-11
Posts: 19 |
![]() |
When I use <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"}" target="_blank"> I see subalbums in another window too. I want to see only photos in a new window. |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
kylemac123 and Ave take a look at step 4 above Quote:
4) edited theme.inc and revised the showPhotoPage() function to return 'none.tpl' instead of 'theme.tpl' |
|
Ave
Joined: 2003-05-11
Posts: 19 |
![]() |
I do all steps. But I need a popup when I click on a thumbPhoto. For a thumbAlbum (subAlbum) I don't want a popup. |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
You'll need to play around with adding this code to wrap around the part of the code that creates the link and brings in the image with this: {if $child.canContainChildren} ... code here ... {/if} |
|
Ave
Joined: 2003-05-11
Posts: 19 |
![]() |
Hi nivekiam, It works. Many thanks for the help! Here is the code: Quote:
{if $child.canContainChildren} Now I' looking for a javascript. In order to show only the image. |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
I haven't read this thread very very closely but I gather two suggested options for having a certain link open in a new window: My solution involves the attribute rel="external". /* * Function used to get elements which have a certain classname. The classname does not have to be * the only classname an object has. */ document.getElementsWithExternalRel = function () { var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e; var re = new RegExp('^external$'); // '(^|\\s)external(\\s|$)' do { e = s[i]; while (e) { /* Element nodes only */ if (e.nodeType == 1) { if (e.rel && re.test(e.rel)) r[l++] = e; s[i++] = e.firstChild; } e = e.nextSibling; } } while (i--); return r; } /* * Open a certain URL in a new window. If a popup blocker prevents this the link is opened in the * current window. */ function fnDOM1Open( event ) { if ( window.event ) { var shiftKey = window.event.shiftKey; } else { var shiftKey = event.shiftKey; } if ( !shiftKey ) { var strURL = this.href; var oNewWindow = window.open( strURL ); if ( !oNewWindow ) { window.location.href = strURL; } return false; } else { return true; } } /* * Assign an onclick event handler to all links having the classname "newWindow" */ function fnAssignPopupLinks() { var aAnchorList = document.getElementsWithExternalRel(); i = aAnchorList.length; while (i--) { oAnchor = aAnchorList[i]; if ( oAnchor.href ) { oAnchor.onclick = fnDOM1Open; // DOM level 1 approach } } } All you need to do then is to call the function fnAssignPopupLinks() at the end of the page and it runs in less then a second time for all browsers adding the onclick event handlers to all links having rel="external" This way is much cleaner because it validates and does not disable a user from opening a link when javascript is switched off. And when users use the shift key the javascript lets the browser do the default action whatever that might be so it doesn't interfere with intuitive thingies... |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
I have applied RwD's javascript (above) to my g2 and it is opening the images in a new window when I click the thumbnail. Now i want the new window to be sized to the image, maybe a tad bigger to take navigation etc. Any quick answers on how to pass the image dimensions to the script above and output a nice size window? Thanks |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
I got a partial solution by adding this code to the header of theme_photo.tpl which is called in my theme.inc in function showPhotoPage. {literal} <script language="javascript" type="text/javascript"/> <!-- hide script from older browsers var NS = (navigator.appName=="Netscape")?true:false; function FitPic() { iWidth = (NS)?window.innerWidth:document.body.clientWidth; iHeight = (NS)?window.innerHeight:document.body.clientHeight; iWidth = (document.images[0].width - iWidth) + 20; iHeight = (document.images[0].height - iHeight) + 20; window.resizeBy(iWidth, iHeight); self.focus(); }; // end hiding script from older browsers --> </script> {/literal}
4 problems with this: Example at www.longforest.com/g2test/main.php |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
1, Assign a name to the window like window.open( strURL, 'myGallery' ). ______________________ |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
1. Thanks RwD, I will try that |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
2, For some reason or the other IE seems to do blanking out stuff rather often when javascript is involved. If the problem doesn't happen in Firefox then it is probably just that... |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
I assigned a name to the window in fnDOM1Open(event) as in but I have tried a lot of rudimentary hacks to get the new popup to focus, ie. load on top of the album page but ???? |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
3. Actually it is not closing the album page. The slideshow always stops at the current
It does what you ask, but I think this kind of makes it unclear where you are going to when you press 5. The problem is that the onload event fires after all page content has loaded (including images and |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
*accidentally pressed post comment* |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
Thanks RwD, that Slideshow solution works well. I'll keep the sub-album issue in mind. |
|
RwD
![]()
Joined: 2005-01-09
Posts: 383 |
![]() |
norv, |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
lol.. {literal} <script language="javascript" type="text/javascript"/> <!-- hide script from older browsers var NS = (navigator.appName=="Netscape")?true:false; function initFitPic() { // quit if this function has already been called if (arguments.callee.done) return; // flag this function so we don't do the same thing twice arguments.callee.done = true; iWidth = (NS)?window.innerWidth:document.body.clientWidth; iHeight = (NS)?window.innerHeight:document.body.clientHeight; iWidth = (document.images[0].width - iWidth) + 15; iHeight = (document.images[0].height - iHeight) + 20; window.resizeBy(iWidth, iHeight); self.focus(); }; /* for Mozilla */ if (document.addEventListener) { document.addEventListener("DOMContentLoaded", initFitPic, null); } /* for other browsers */ window.onload = initFitPic; // end hiding script from older browsers --> </script> <style type="text/css"> /* for Internet Explorer */ body {behavior: url(loaded.htc);} </style> {/literal} </head> <body class="gallery"> and loaded.htc simply contains <component lightweight="true"> <attach event="ondocumentready" onevent="window.initFitPic()"> </component> but the behaviour is the same as before. Working on it. |
|
norv
Joined: 2004-03-12
Posts: 13 |
![]() |
I've tried testing for focus as in if (self.focus()) { alert("self.focus"); } else { alert("no self.focus"); } if (oNewWindow.focus()) { alert("oNW focus"); } else { alert("no oNW focus"); } if (window.focus('myPopup')) { alert("myPopup focus"); } else { alert("no myPopup focus"); } no matter where i put the alerts I can't seem to get focus anywhere. |
|
Ave
Joined: 2003-05-11
Posts: 19 |
![]() |
After a happy month with my galley showing popups I was asked to install another gallery with same features in another site. Same server, same PHP, same MySQL, of course. But I installed Gallery 2.0.1, the new version. |
|
Darryl Morgan
Joined: 2005-11-10
Posts: 6 |
![]() |
I've been searching the forums and so far I haven't found a workaround/patch/hack that fits my needs. So I think I'm going to take on what I've found from these various posts and make my own. Basically want the album thumbnail to open up the image at smallest resize. Smallest resize should be clickable (eg. a href) to the fullsize image but this is laoded up in another window. Also the drop down and the fullsize link should open up a new window. It'd be also nice to be able to have in this new window a dropdown that allows you to change the popup image size (eg. alla smugmug style). |
|
mstookey
Joined: 2004-10-09
Posts: 4 |
![]() |
hi, |
|
nivekiam
![]()
Joined: 2002-12-10
Posts: 16504 |
![]() |
Any particular reason why this doesn't work http://gallery.menalto.com/node/31184#comment-123929 |
|
markwaldhoff
Joined: 2006-01-26
Posts: 4 |
![]() |
nivekiam wrote:
Any particular reason why this doesn't work http://gallery.menalto.com/node/31184#comment-123929 I tried this, but it doesn't work for me... http://www.toyotayaris.de/cmsmadesimple/index.php?page=Gallerie2 If you go into the Album:Celica you see some thumbnails and if you click on a thumbnail, the image DON'T open in a new window ! Only if you click on this large image (which don't fit into my frame), a new Window will be opened ! The New Windows should appear if i click on the thumbnail ! how do i get that ? |
|
markwaldhoff
Joined: 2006-01-26
Posts: 4 |
![]() |
Ave wrote:
After a happy month with my galley showing popups I was asked to install another gallery with same features in another site. Same server, same PHP, same MySQL, of course. But I installed Gallery 2.0.1, the new version. I want it like you did in the old site ! That's fantastic ! |
|
MichielM
Joined: 2004-08-16
Posts: 15 |
![]() |
Hi! I have the same problem, the javascript does not work anymore with 2.0.2... |
|
MichielM
Joined: 2004-08-16
Posts: 15 |
![]() |
Just found out that you can vote to get this feature: |
|
lampster
Joined: 2006-11-16
Posts: 36 |
![]() |
I'm using the Carbon template. The above doesn't seem to apply. Is there a solution for Carbon? I've looked at the album.tpl and have attempted to change the following with "taget=blank" <div> Gallery version = 2.1.2 core 1.1.0.2 |
|