nsanden |
09-25-2006 10:00 PM |
Resize large [IMG] images and link them to original
This mod should resize [IMG] images wider than 'max_width' and link them to their original size. Not very well tested, i'm hoping for some feedback/suggestions. I have tested in firefox/IE latest versions and it seems to work fine. Should be a pretty quick install.
INSTALL:
1) Edit /includes/class_bbcode.php around line 1879 for me.
Look for:
Code:
return '<img src="' . $link . '" border="0" alt="" />';
Change to:
Code:
return '<img src="' . $link . '" border="0" alt="" class="img_tag" />';
2) Add the following to the headinclude template.
Code:
<if condition="THIS_SCRIPT == 'showthread'">
<script type="text/javascript">
max_width = 700;
if(document.documentElement.outerHTML == null) {
HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var df = r.createContextualFragment(sHTML);
this.parentNode.replaceChild(df, this);
});
}
function resizeImages() {
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i];
if(img.className == "img_tag") {
if(img.width > max_width) {
var strNewHTML = '<a href="' + img.src + '" target="_blank"><img width = "' + max_width + '" src="' + img.src + '" border=0 alt="" /></a>';
img.outerHTML = strNewHTML;
}
}
}
}
if (window.addEventListener) {
window.addEventListener('load', resizeImages, false);
} else if (window.attachEvent) {
window.attachEvent('onload', resizeImages);
} else {
window.onload = resizeImages;
}
</script>
</if>
|