//****************************************************************************** function filosofo_je_javascript_addEvent(obj, evType, fn){ // from http://www.sitepoint.com/article/structural-markup-javascript //****************************************************************************** if (obj.addEventListener){ obj.addEventListener(evType, fn, false); //false to make sure it happens during event bubbling, not capturing. see http://www.quirksmode.org/js/events_order.html and http://www.quirksmode.org/js/events_advanced.html return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } //****************************************************************************** function filosofo_je_javascript_extractImageTitles() { //****************************************************************************** var images = document.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { if (images[i].getAttribute('title')) { var title = images[i].getAttribute('title'); if (title != '') { var parent = images[i].parentNode; var idname = images[i].getAttribute('id'); var span = document.createElement('span'); span.className = images[i].className; span.className = images[i].getAttribute('align'); span.width = images[i].getAttribute('width'); if (images[i].getAttribute('style')) { span.setAttribute('style', images[i].getAttribute('style')); } span.setAttribute('id',idname); span.setAttribute('style',''); span.setAttribute('style','width:' + span.width + 'px;'); var pic = document.createElement('img'); var imgattribs = new Array('hspace','ismap','longdesc','usemap','vspace','width','height','src','alt'); for (counter = 0;counter < imgattribs.length;counter++) { if (images[i].getAttribute(imgattribs[counter])) { pic.setAttribute(imgattribs[counter],images[i].getAttribute(imgattribs[counter])); } } pic.setAttribute('title', title); pic.setAttribute('style',''); var p = document.createElement('p'); p.appendChild(document.createTextNode('' + title)); p.className = 'caption'; p.setAttribute('style','width:' + span.width + 'px;'); span.appendChild(pic); span.appendChild(p); parent.replaceChild(span,images[i]); } } } } filosofo_je_javascript_addEvent(window, 'load', filosofo_je_javascript_extractImageTitles);