Keyword

K2 Images - Opening in window instead of lightbox?

  • James Wiseman
  • James Wiseman's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #127486 by James Wiseman
Hi all,

I have a client who (for reasons best known to themselves!) wants to have their K2 images opening in a new window sized to the image, rather than in a lightbox.

Is there any way I can set this up by default, and where would I look?

I'm struggling to find where I'd find the code for this, or if there's any functionality built in to enable me to set this by default.

Any help with this would be much appreciated, as it's the only thing still to 'fix' on a site that's due to go live ASAP.

Thanks! :)

James

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127487 by Lefteris
Hi. You first need to remove the class "modal" from the images links in K2 item page. Then you can just add custom javascript code on the onclick attribute of the links to open the image. In any case in order to make changes to item.php you need first to read getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates .

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • James Wiseman
  • James Wiseman's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #127488 by James Wiseman
Replied by James Wiseman on topic Re: K2 Images - Opening in window instead of lightbox?
Thank you - I will give it a go! :)

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127489 by Lefteris
You are welcome.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • James Wiseman
  • James Wiseman's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #127490 by James Wiseman
Replied by James Wiseman on topic Re: K2 Images - Opening in window instead of lightbox?
Sorry - Me again! I spoke too soon :(

OK, I've managed to create the duplicate K2 folder, and removed the 'modal' class from image links, but I can't seem to get the javascript code to work properly.

I'm adding the code to the image link (under <span class="itemImage">) but I can't seem to get it to work.

I've added the Javascript link at the beginning of the item.php file, like this:

<?php
$document = JFactory::getDocument();
$document->addScript('/media/system/js/newimg.js');
?>

The 'newimg.js' file is a script to resize the window to the image size.*

Then, under the main image code (around line 210-ish), I've put this:

<span class="itemImage">
<a onclick="newImg(this.href);return false" rel="{handler: 'image'}" href="<?php echo $this->item->imageXLarge; ?>" title="<?php echo JText::_('K2_CLICK_TO_PREVIEW_IMAGE'); ?>">
<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
</a>
</span>

...but it still opens up in a new window without any resizing.

*For info, the content of the javascript file is:

function newImg(which){
var theImg = new Image();
theImg.src = which;
var imgw = theImg.width;
var imgh = theImg.height;

if(imgw<100){imgw = 100};
if(imgh<100){imgh = 100};

var ImgWin = window.open('','imgwin',config='height='+imgh+',width='+imgw+',top=0,left=100')
with(ImgWin.document){
writeln('<html><head><title>Display Image</title></head>');
writeln('<body onload="self.focus()" onblur="self.close()">');
writeln('<div style="text-align:center">');
writeln('<img src='+which+'></div>');
writeln('<div style="text-align:center;font-size:9px">');
writeln('<a href="#" onClick="self.close()">Close Me</a>');
writeln('</div></body></html>');
close();
}
}

Any ideas what I'm doing wrong? I'm a bit rusty on Javascript. Am I editing the correct <div> in item.php?

Thanks,

James

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127491 by Lefteris
To verify that you are editing the correct file you can always view the page source using your browser. You should also check the browser console for any javascript errors. Finally regarding the actual javascript popup code, if it doesn't work, you can use Google to find an alternative. There are several out there.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum