I use a bookmarklet that zoom or shrink images on a page.
function zoomImage(image, amt)
{
if (image.initialHeight == null)
{ /* avoid losing height due to integer rounding while zooming out */
image.initialHeight = image.height;
image.initialWidth = image.width;
image.scalingFactor = 1;
}
image.scalingFactor *= amt;
image.width = image.scalingFactor * image.initialWidth;
image.height = image.scalingFactor * image.initialHeight;
}
for (i=0; i<document.images.length; ++i) { zoomImage(document.images[i], .5); }
This bookmarklet uses document.images which only exists for HTML documents and not XML documents. Using these bookmarklets on a page sent with an XML Content-Type such as application/xhtml+xml just gets you an error in Phoenix's Javascript Console that says document.images has no properties. So I set out to rewrite the bookmarklet using the proper W3C DOM.
function zoom(dir)
{
switch(dir)
{
case "in":
amt = 2;
break;
case "out":
amt = .5;
break;
default:
amt = 1;
}
var imgNodeList = document.getElementsByTagName('img');
for (var i=0; i<imgNodeList.length; i++)
{
x = imgNodeList[i].width;
x *= amt;
imgNodeList[i].setAttribute('width',x);
y = imgNodeList[i].height;
y *= amt;
imgNodeList[i].setAttribute('height',y);
}
}
I just use a switch because I never never used one before in JavaScript and wanted to try it out. My first instinct was to use a regular if.
I haven't checked to see if this works on a page where an IMG element does not have WIDTH and HEIGHT attributes already set. Also, I think I would prefer to set the CSS width and height properties instead of the HTML attributes.
You can see this code in action at The_Terror_of_Tim_Boo_Ba.html.
