Advertisement:

Author Topic: Open resized images in new window  (Read 3791 times)

Offline rfirevtre

  • Semi-Newbie
  • *
  • Posts: 13
Open resized images in new window
« on: April 03, 2010, 08:40:11 PM »
Hi everyone
I was wondering if it's possible to make resized images open in a new window when you click on them.
I found the following script in theme.js and figured that it can probably be edited to open images in a new window on click.

Code: [Select]
// Toggles the element height and width styles of an image.
function smc_toggleImageDimensions()
{
var oImages = document.getElementsByTagName('IMG');
for (oImage in oImages)
{
// Not a resized image? Skip it.
if (oImages[oImage].className == undefined || oImages[oImage].className.indexOf('bbc_img resized') == -1)
continue;

oImages[oImage].style.cursor = 'pointer';
oImages[oImage].onclick = function() {
this.style.width = this.style.height = this.style.width == 'auto' ? null : 'auto';
};
}
}

Anyone who can help me?

Offline flapjack

  • SMF Hero
  • ******
  • Posts: 2,615
  • Gender: Male
  • I pity the fools!
Re: Open resized images in new window
« Reply #1 on: April 03, 2010, 09:51:49 PM »
nope. you should search a place from where this code is being called. there you will be able to do what you want.

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #2 on: April 04, 2010, 05:46:33 AM »
That code is solely for attachments being resized, not for the code you're thinking of.

Looking at that, I'd say SMF 2.0?

Offline rfirevtre

  • Semi-Newbie
  • *
  • Posts: 13
Re: Open resized images in new window
« Reply #3 on: April 04, 2010, 08:43:12 AM »
Yeah, I'm running SMF 2.0 RC3. Not sure where to find the code though

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #4 on: April 04, 2010, 08:45:46 AM »
It's in Sources/Subs-Post.php.

All you need to do is modify the bbcode generated which includes the new size.

Code: (find) [Select]
$replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
Code: (replace) [Select]
$replaces[$matches[0][$match]] = '[url=' . $matches[4][$match] . '][img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img][/url]';
This wraps the code inside a the URL bbcode to force it to open in a new window. Will only apply on newly posted images though.

Offline Yağız...

  • Beta Tester
  • SMF Super Hero
  • *
  • Posts: 10,803
  • Gender: Male
    • MMO Browser
Re: Open resized images in new window
« Reply #5 on: April 04, 2010, 08:57:59 AM »
Or if you want a popup, find this in ./Themes/default/scripts/theme.js:
Code: [Select]
this.style.width = this.style.height = this.style.width == 'auto' ? null : 'auto';Replace with:
Code: [Select]
window.open(this.src, 'image', 'menubar=0,resizable=1,width=' + this.style.width + ',height=' + this.style.height + '');

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #6 on: April 04, 2010, 09:03:48 AM »
Um... Yagiz, that's referring again to the attachments, not to images that are just resized in a post body.

Offline Yağız...

  • Beta Tester
  • SMF Super Hero
  • *
  • Posts: 10,803
  • Gender: Male
    • MMO Browser
Re: Open resized images in new window
« Reply #7 on: April 04, 2010, 09:11:30 AM »
Um... Yagiz, that's referring again to the attachments, not to images that are just resized in a post body.
Sure? I tried on my local, and it worked
 :)

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #8 on: April 04, 2010, 09:13:04 AM »
Looks like the code in the attachments handler to me, unless you've found something else in the code... (or using a non standard theme)

Offline Yağız...

  • Beta Tester
  • SMF Super Hero
  • *
  • Posts: 10,803
  • Gender: Male
    • MMO Browser
Re: Open resized images in new window
« Reply #9 on: April 04, 2010, 09:15:21 AM »
Looks like the code in the attachments handler to me, unless you've found something else in the code... (or using a non standard theme)
Using Curve on a fresh install :)

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #10 on: April 04, 2010, 09:18:15 AM »
Hrm. If it works, great. I just didn't remember seeing that in the code, but I tend to avoid the JS (there's enough in the other thousands upon thousands of lines to remember ;))

Offline Yağız...

  • Beta Tester
  • SMF Super Hero
  • *
  • Posts: 10,803
  • Gender: Male
    • MMO Browser
Re: Open resized images in new window
« Reply #11 on: April 04, 2010, 09:42:43 AM »
Hrm. If it works, great. I just didn't remember seeing that in the code, but I tend to avoid the JS (there's enough in the other thousands upon thousands of lines to remember ;))
Changelog says that they have added this on January:
Quote
+ Allow toggling of full size versions of resized images. (theme.js)
:)

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,062
    • wedgebook on Facebook
Re: Open resized images in new window
« Reply #12 on: April 04, 2010, 09:45:11 AM »
That'd be why; I've not had to go back through the code (nor turned it on in a forum) since before the new year came in... so I'd never have noticed it...

Offline rfirevtre

  • Semi-Newbie
  • *
  • Posts: 13
Re: Open resized images in new window
« Reply #13 on: April 04, 2010, 12:28:38 PM »
I did like Yağız suggested and it worked just like I wanted :)
Thanks for the quick response

Offline Ashelia

  • Semi-Newbie
  • *
  • Posts: 69
  • Gender: Female
Re: Open resized images in new window
« Reply #14 on: April 30, 2012, 10:22:46 AM »
It's in Sources/Subs-Post.php.

All you need to do is modify the bbcode generated which includes the new size.

Code: (find) [Select]
$replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
Code: (replace) [Select]
$replaces[$matches[0][$match]] = '[url=' . $matches[4][$match] . '][img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img][/url]';
This wraps the code inside a the URL bbcode to force it to open in a new window. Will only apply on newly posted images though.

Sorry for bumping an old thread.. but I just tried using this code, and it worked. My problem is that while images do open in new tabs when clicked, they still enlarge inside the post too.

Is there a way for it to only show the full image in a new tab, instead of inside the post?

Offline Ashelia

  • Semi-Newbie
  • *
  • Posts: 69
  • Gender: Female
Re: Open resized images in new window
« Reply #15 on: May 24, 2012, 01:33:09 PM »
Bump! I still haven't found a solution to this ><

Offline Ashelia

  • Semi-Newbie
  • *
  • Posts: 69
  • Gender: Female
Re: Open resized images in new window
« Reply #16 on: May 29, 2012, 03:26:08 PM »
Bumpybump! Still need help

Offline K@

  • Lead Support Specialist
  • SMF Master
  • *
  • Posts: 38,744
  • Gender: Male
  • Nothing (Or nothing you can see)
Re: Open resized images in new window
« Reply #17 on: May 29, 2012, 03:31:27 PM »
Sorry, man!

As this has been marked as being solved, everybody's ignoring this, assuming that everything's been figured-out.

Might be best to start a new topic and refer to your previous posts...?