Page 1 of 1

mosaic.js button onclick better IE workaroud

Posted: 29 Mar 2006 19:59
by Albert
Hello,
I found better IE workaround for creating button with onclick function:
Do not call function create_button( caption, action )...
Please test it with Mozilla family browsers.

Original code mosaic.js:

Code: Select all

var id = x+'_'+y; var melt = create_button( cells[id] ? cells[id] : '?', 'mosaic_elt_choose(\"'+id+'\");' ); melt.setAttribute( 'id', id ); melt.setAttribute( 'title', 'Click to choose stream' ); mcell.appendChild( melt ); mrow.appendChild( mcell );
New code:

Code: Select all

var id = x+'_'+y; var melt = document.createElement("input"); melt.setAttribute('type', 'button'); melt.setAttribute( 'id', id ); melt.setAttribute( 'title', 'Click to choose stream' ); melt.setAttribute('value', cells[id] ? cells[id] : '?'); melt.setAttribute("onclick",function(){mosaic_elt_choose(id);}); mcell.appendChild( melt ); mrow.appendChild( mcell );
Albert

Posted: 29 Mar 2006 20:03
by dionoea
does that automatically replace id with it's value ?

:-(

Posted: 29 Mar 2006 20:21
by Albert
Hello,
I am sorry, id for onclick are all the same - the highest values.
Albert

Posted: 29 Mar 2006 21:52
by dionoea
that's why i had to do my ugly hack ... the DOM way of doing it was great ... but IE didn't like it.

Posted: 29 Mar 2006 21:53
by dionoea
By the way, do you want to be added to the THANKS file ? (since you helped me with lots of bug fixes in the http interface you deserve it)

workaround

Posted: 29 Mar 2006 22:18
by Albert
Hello,
I didn´t noticed comments in create_button()...

I found some workarounds, but mostly uglier :)
I suppose there is a bug(s) in IE. elm.setAttribute() is not working in the right way and all attributes set before appendChild() to the root element are lost (=sets the last value to all).
So I see a way to rewrite mosaic table into 2 for cycles: 1st creates the table and appends it to the document element; 2nd cycle sets attributes (id, onclick) to the allready created and affiliated table cells.

I haven´t tested this yet. I can try tomorow. But... it could be longer code than your workaround... is this advisable?


I do not object to be added to thanks file :-)
Albert

Posted: 30 Mar 2006 02:02
by dionoea
I think that i'll keep current code since it works :)

Could you give me your full name for the thanks file ? (and email if you want ... but use a private message if you do to prevent spam)