Expand-Image without JavaScript (Technics)

by Milo ⌂ @, Wednesday, April 18, 2007, 20:06 (4533 days ago) @ Alfie

Hello,

firstly, sorry my english! I hope you understand me ;-)

Just tested the forum without JavaScript.

I think that it would be a good idea to set the expand-image [...] with 'document.write'

That's one way but not the best. I belive it is mutch better to separate the code.

You can do it like this:


function getID(str){
 // new RegExp(/id=(d.+)/g)
 var r = new RegExp(/id=(d+)/g).exec(str);
 return r!=null&&r.length>=2?r[1]:r;
}
  
function createPreviewIcon(id){
 var img = new Image(11,11);
 img.src = "ajax_preview.png";
 try {img.style.cursor = "pointer";} catch(err) {img.style.cursor = "hand";}
 img.title = "Show preview";
 img.alt = "Show preview";
 img.id = id;
 img.onclick = function(e) {
  ajax_preview(this.id,'Post reply')
  return false;
 };
 return img
}

window.onload = function() {
 var l = document.getElementsByTagName("a");
 for (var i=0; i<l.length; i++)
  if (l[i].className == "reply" && getID(l[i].href) != null)
   l[i].parentNode.appendChild( createPreviewIcon(getID(l[i].href)) );
};


It will replace the 2th anchor which show the preview in a small box for example

a href="#" onclick="ajax_preview(219,'Post reply'); return false" title="Show preview"><img src="ajax_preview.png" alt="Show preview" width="11" height="11" /></a>

That's not a final solution but a motivation! :)

Btw: "he posting contains at least one not accepted word" if I don't know the word, it's a bad comment :(

cu
Micha


Complete thread:

 RSS Feed of thread

powered by my little forum