// javascript document
/**
* png: adds ie6 support: png images for css background-image and html .
* author: drew diller
* email: drew.diller@gmail.com
* url: http://www.dillerdesign.com/experiment/png/
* version: 0.0.7a
* licensed under the mit license: http://dillerdesign.com/experiment/png/#license
*
* example usage:
* png.fix('.png_bg'); // argument is a css selector
* png.fixpng( somenode ); // argument is an htmldomelement
**/
/*
please read:
absolutely everything in this script is silly. i know this. ie's rendering of certain pixels doesn't make sense, so neither does this code!
*/
var png = {
ns: 'png',
imgsize: {},
createvmlnamespace: function() { /* enable vml */
if (document.namespaces && !document.namespaces[this.ns]) {
document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml');
}
if (window.attachevent) {
window.attachevent('onbeforeunload', function() {
png = null;
});
}
},
createvmlstylesheet: function() { /* style vml, enable behaviors */
/*
just in case lots of other developers have added
lots of other stylesheets using document.createstylesheet
and hit the 31-limit mark, let's not use that method!
further reading: http://msdn.microsoft.com/en-us/library/ms531194(vs.85).aspx
*/
var style = document.createelement('style');
document.documentelement.firstchild.insertbefore(style, document.documentelement.firstchild.firstchild);
var stylesheet = style.stylesheet;
stylesheet.addrule(this.ns + '\\:*', '{behavior:url(#default#vml)}');
stylesheet.addrule(this.ns + '\\:shape', 'position:absolute;');
stylesheet.addrule('img.' + this.ns + '_sizefinder', 'behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;'); /* large negative top value for avoiding vertical scrollbars for large images, suggested by james o'brien, http://www.thanatopsic.org/hendrik/ */
this.stylesheet = stylesheet;
},
readpropertychange: function() {
var el = event.srcelement;
if (event.propertyname.search('background') != -1 || event.propertyname.search('border') != -1) {
png.applyvml(el);
}
if (event.propertyname == 'style.display') {
var display = (el.currentstyle.display == 'none') ? 'none' : 'block';
for (var v in el.vml) {
el.vml[v].shape.style.display = display;
}
}
if (event.propertyname.search('filter') != -1) {
png.vmlopacity(el);
}
},
vmlopacity: function(el) {
if (el.currentstyle.filter.search('lpha') != -1) {
var trans = el.currentstyle.filter;
trans = parseint(trans.substring(trans.lastindexof('=')+1, trans.lastindexof(')')), 10)/100;
el.vml.color.shape.style.filter = el.currentstyle.filter; /* complete guesswork */
el.vml.image.fill.opacity = trans; /* complete guesswork */
}
},
handlepseudohover: function(el) {
settimeout(function() { /* wouldn't work as intended without settimeout */
png.applyvml(el);
}, 1);
},
/**
* this is the method to use in a document.
* @param {string} selector - required - a css selector, such as '#doc .container'
**/
fix: function(selector) {
var selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */
for (var i=0; i size.h) {
c.b = size.h;
}
el.vml.image.shape.style.clip = 'rect('+c.t+'px '+(c.r+fudge)+'px '+c.b+'px '+(c.l+fudge)+'px)';
}
else {
el.vml.image.shape.style.clip = 'rect('+dc.t+'px '+dc.r+'px '+dc.b+'px '+dc.l+'px)';
}
},
fixpng: function(el) {
el.style.behavior = 'none';
if (el.nodename == 'body' || el.nodename == 'td' || el.nodename == 'tr') { /* elements not supported yet */
return;
}
el.isimg = false;
if (el.nodename == 'img') {
if(el.src.tolowercase().search(/\.png$/) != -1) {
el.isimg = true;
el.style.visibility = 'hidden';
}
else {
return;
}
}
else if (el.currentstyle.backgroundimage.tolowercase().search('.png') == -1) {
return;
}
var lib = png;
el.vml = {color: {}, image: {}};
var els = {shape: {}, fill: {}};
for (var r in el.vml) {
for (var e in els) {
var nodestr = lib.ns + ':' + e;
el.vml[r][e] = document.createelement(nodestr);
}
el.vml[r].shape.stroked = false;
el.vml[r].shape.appendchild(el.vml[r].fill);
el.parentnode.insertbefore(el.vml[r].shape, el);
}
el.vml.image.shape.fillcolor = 'none'; /* don't show blank white shapeangle when waiting for image to load. */
el.vml.image.fill.type = 'tile'; /* ze magic!! makes image show up. */
el.vml.color.fill.on = false; /* actually going to apply vml element's style.backgroundcolor, so hide the whiteness. */
lib.attachhandlers(el);
lib.givelayout(el);
lib.givelayout(el.offsetparent);
/* set up element */
lib.applyvml(el);
}
};
try {
document.execcommand("backgroundimagecache", false, true); /* tredosoft multiple ie doesn't like this, so try{} it */
} catch(r) {}
png.createvmlnamespace();
png.createvmlstylesheet();