Customizing SMF > SMF Coding Discussion
Open resized images in new window
rfirevtre:
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: ---// 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';
};
}
}
--- End code ---
Anyone who can help me?
flapjack:
nope. you should search a place from where this code is being called. there you will be able to do what you want.
Arantor:
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?
rfirevtre:
Yeah, I'm running SMF 2.0 RC3. Not sure where to find the code though
Arantor:
It's in Sources/Subs-Post.php.
All you need to do is modify the bbcode generated which includes the new size.
--- Code: (find) ---$replaces[$matches[0][$match]] = '[img' . (!empty($desired_width) ? ' width=' . $desired_width : '') . (!empty($desired_height) ? ' height=' . $desired_height : '') . ']' . $matches[4][$match] . '[/img]';
--- End code ---
--- Code: (replace) ---$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]';
--- End code ---
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.
Navigation
[0] Message Index
[#] Next page
Go to full version