<?xml version="1.0" encoding="ISO-8859-1"?><!-- generator="wordpress/1.5.1.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Desde mi casa Comments</title>
	<link>http://www.ismaelj.com</link>
	<description>Artículos sobre JavaScript / CSS / (X)HTML</description>
	<pubDate>Wed, 08 Feb 2012 02:51:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.1.3</generator>

	<item>
		<title>by: jose</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6914</link>
		<pubDate>Fri, 23 Apr 2010 01:54:11 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6914</guid>
					<description>Gracias por compartirlo, me ha resultado muy útil para aprender algunas cosas que no encontraba por ninguna parte. Gente como tú es la que hace que otros desarrolladores publiquemos nuestros trabajos, mil gracias.</description>
		<content:encoded><![CDATA[	<p>Gracias por compartirlo, me ha resultado muy útil para aprender algunas cosas que no encontraba por ninguna parte. Gente como tú es la que hace que otros desarrolladores publiquemos nuestros trabajos, mil gracias.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Erik Eckhardt</title>
		<link>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-6884</link>
		<pubDate>Fri, 19 Mar 2010 17:16:53 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-6884</guid>
					<description>I bet I can guess the problem Rob was having without even looking at his code.

Ismael, by using sourceIndex you're assuming that the elements of the document are static. But Rob said he has things that are &quot;written out to the DOM.&quot; His WYSIWYG editor is obviously dynamically inserting and removing elements, which destroys the correlation between sourceIndex and the original element.

Instead, I think you need to use either the id of the element (if it already has one) or generate your own id. I know this has its own assumptions, namely 1) there are no duplicate ids in the document and 2) the ids will not be changed dynamically. However, this seems less risky to me than assuming every element in the DOM will always be in the same ordinal position.

Also, I know this stuff is a few years old. Do you have any recommendations for a more current discussion on this topic? Do you think by now we can start forgetting IE5?</description>
		<content:encoded><![CDATA[	<p>I bet I can guess the problem Rob was having without even looking at his code.</p>
	<p>Ismael, by using sourceIndex you&#8217;re assuming that the elements of the document are static. But Rob said he has things that are &#8220;written out to the DOM.&#8221; His WYSIWYG editor is obviously dynamically inserting and removing elements, which destroys the correlation between sourceIndex and the original element.</p>
	<p>Instead, I think you need to use either the id of the element (if it already has one) or generate your own id. I know this has its own assumptions, namely 1) there are no duplicate ids in the document and 2) the ids will not be changed dynamically. However, this seems less risky to me than assuming every element in the DOM will always be in the same ordinal position.</p>
	<p>Also, I know this stuff is a few years old. Do you have any recommendations for a more current discussion on this topic? Do you think by now we can start forgetting IE5?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jose luis lozano</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6261</link>
		<pubDate>Wed, 02 Dec 2009 23:56:57 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6261</guid>
					<description>thank you very much, for you help, my personal opinion is
that you code is very very good, by jose luis lozano</description>
		<content:encoded><![CDATA[	<p>thank you very much, for you help, my personal opinion is<br />
that you code is very very good, by jose luis lozano
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Cristian</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6243</link>
		<pubDate>Thu, 26 Nov 2009 08:26:41 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-6243</guid>
					<description>¡Hola gracias por el código!

Me podrías decir como podría hacer para que cuando cargue la pagina se abra un submenu en concreto?</description>
		<content:encoded><![CDATA[	<p>¡Hola gracias por el código!</p>
	<p>Me podrías decir como podría hacer para que cuando cargue la pagina se abra un submenu en concreto?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Abraham</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4900</link>
		<pubDate>Sat, 21 Mar 2009 21:51:10 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4900</guid>
					<description>Amigo muchas gracias, aún en estos tiempos tan avanzados, algo que nunca cambiará es que todos necesitamos de todos, bendiciones, hasta pronto</description>
		<content:encoded><![CDATA[	<p>Amigo muchas gracias, aún en estos tiempos tan avanzados, algo que nunca cambiará es que todos necesitamos de todos, bendiciones, hasta pronto
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: CRISTHIAN</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4799</link>
		<pubDate>Thu, 26 Feb 2009 21:57:03 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4799</guid>
					<description>Amigo muchas gracias por tu aporte, peo tengo un problema descargo el archivo que me das, pero cuando abro la pagina web, tengo todo los sub menus abiertos. como hago parta que me aparezcan cerrados apenas abro la pagina. gracias</description>
		<content:encoded><![CDATA[	<p>Amigo muchas gracias por tu aporte, peo tengo un problema descargo el archivo que me das, pero cuando abro la pagina web, tengo todo los sub menus abiertos. como hago parta que me aparezcan cerrados apenas abro la pagina. gracias
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Hugo</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4619</link>
		<pubDate>Fri, 30 Jan 2009 00:02:11 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4619</guid>
					<description>Se podria implemetar algo para que se abra cierta seccion del menu dependiendo una variable mandada ?</description>
		<content:encoded><![CDATA[	<p>Se podria implemetar algo para que se abra cierta seccion del menu dependiendo una variable mandada ?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: hector</title>
		<link>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4209</link>
		<pubDate>Mon, 03 Nov 2008 22:55:50 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/menu-vertical-multinivel/#comment-4209</guid>
					<description>Sencillo pero en verdad util amigo gracias</description>
		<content:encoded><![CDATA[	<p>Sencillo pero en verdad util amigo gracias
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Ismael Jurado</title>
		<link>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-3360</link>
		<pubDate>Mon, 07 Jul 2008 17:00:58 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-3360</guid>
					<description>Rob, I don't have enough information to guess the right answer. 
buttonID is assigned in HTML to the SPAN or the the IMG? 
And the IMG is surrounded by the SPAN?</description>
		<content:encoded><![CDATA[	<p>Rob, I don&#8217;t have enough information to guess the right answer.<br />
buttonID is assigned in HTML to the SPAN or the the IMG?<br />
And the IMG is surrounded by the SPAN?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Rob Reid</title>
		<link>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-3359</link>
		<pubDate>Mon, 07 Jul 2008 13:36:35 +0000</pubDate>
		<guid>http://www.ismaelj.com/articulos/addevent-recoding-contest/#comment-3359</guid>
					<description>I am having problems with your code in Internet Explorer (6-7) which seems to be related to the this keyword.

I used to use the following functions which do not give me the same problems that I am currently having with your functions. I swapped over to use your functions after reading about the problems they fix that the others didn't and they have worked 
elsewhere perfectly until now with this particular issue.

//old functions that work
function addEvent( obj, type, fn ){ 
	if ( obj.attachEvent ) { 
		obj['e'+type+fn] = fn; 
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );} 
		obj.attachEvent( 'on'+type, obj[type+fn] ); 
	}else 
		obj.addEventListener( type, fn, false ); 
}

function removeEvent( obj, type, fn ) {   
	if ( obj.detachEvent ) { 
		obj.detachEvent( 'on'+type, obj[type+fn] ); 
		obj[type+fn] = null; 
	}else 
		obj.removeEventListener( type, fn, false ); 
} 


The problem is with a WYSIWYG HTML editor that is instantiated on an onclick event and written out to the DOM.
I am looping through all my toolbar buttons adding onclick event handlers to each button in turn.
To take one button in particular the HTML format is this (from IE's generated source)


	
		
	


I am looping through an array of all my buttons within an editor method and adding the event handler like so

Editor.prototype.Create = function()
{
	//some other code
	var self = this;
        //loop through all buttons in turn
	elem = document.getElementById(buttonID);
	addEvent( elem, 'click', function(){ShowDebug('Button 2 OnClick');self.FormatText(this.id,n);} ) 				
	
}

// I have also tried this for buttons I know the ID for.

elem = document.getElementById('ViewText');
addEvent( elem, 'click',  function(){ShowDebug('Button 2 OnClick');self.FormatText('ViewText',n);} );

The event handler seems to be added correctly (from firebuglite debug in IE - I have put some debug into your addEvent function handler when
using attachEvent)


function addEvent(obj,evType,func){
	var r = false;
	if(obj.addEventListener){
		obj.addEventListener(evType, func, false);
		r = true;
	}else if (obj.attachEvent) {
		var id = obj.sourceIndex &amp;#166;&amp;#166; -1;
		ShowDebug(&quot;addEvent to &quot; + id);
		if (!func[evType + id]) {
			var f = func[evType + id] = function(e) {
				var o = document.all[id] &amp;#166;&amp;#166; document;
				o._f = func;
				var s = o._f(e);
				o._f = null;
				return s;
				};
			ShowDebug(&quot;obj = &quot; + obj + &quot; typeof = &quot; + typeof(obj) + &quot; obj.id = &quot; + obj.id + &quot; tagName = &quot; + obj.tagName);
			r = obj.attachEvent(&quot;on&quot; + evType, f);
			obj = null;
		}
	}else{ //if there is already a function for this handler call beforehand
		var ev=&quot;on&quot;+evType;
		var oldevent = obj[ev];
		if (typeof oldevent != &quot;function&quot;){			
			obj[ev]=func;
		}else{			
			obj[ev] = function(){ oldevent();func();}
		}
	}
	return r;
};


1: addEvent to 628
2: obj = [object] typeof = object obj.id = ViewText tagName = IMG

The problem comes whenever I try to click on any of the toolbar buttons. Instead of passing through the reference to the actual IMG tag which it should be doing its passing through the reference for the node above which is the SPAN tag.

// INCORRECT!!!
25: Button 2 Onclick
26: IN FormatText HTMLModeCMStextarea ; CMStextarea ;

Whereas it should be passing though (as Firefox correctly does) the ID for the IMG tag.

// CORRECT!!!
11: Button 2 OnClick
12: IN FormatText ViewSource ; CMStextarea ;

If I revert back to the older functions it works fine. Can you give me some guidance on whats gone wrong and if there is a fix about?

Thanks</description>
		<content:encoded><![CDATA[	<p>I am having problems with your code in Internet Explorer (6-7) which seems to be related to the this keyword.</p>
	<p>I used to use the following functions which do not give me the same problems that I am currently having with your functions. I swapped over to use your functions after reading about the problems they fix that the others didn&#8217;t and they have worked<br />
elsewhere perfectly until now with this particular issue.</p>
	<p>//old functions that work<br />
function addEvent( obj, type, fn ){<br />
	if ( obj.attachEvent ) {<br />
		obj[&#8217;e'+type+fn] = fn;<br />
		obj[type+fn] = function(){obj[&#8217;e'+type+fn]( window.event );}<br />
		obj.attachEvent( &#8216;on&#8217;+type, obj[type+fn] );<br />
	}else<br />
		obj.addEventListener( type, fn, false );<br />
}</p>
	<p>function removeEvent( obj, type, fn ) {<br />
	if ( obj.detachEvent ) {<br />
		obj.detachEvent( &#8216;on&#8217;+type, obj[type+fn] );<br />
		obj[type+fn] = null;<br />
	}else<br />
		obj.removeEventListener( type, fn, false );<br />
} </p>
	<p>The problem is with a WYSIWYG HTML editor that is instantiated on an onclick event and written out to the DOM.<br />
I am looping through all my toolbar buttons adding onclick event handlers to each button in turn.<br />
To take one button in particular the HTML format is this (from IE&#8217;s generated source)</p>
	<p>I am looping through an array of all my buttons within an editor method and adding the event handler like so</p>
	<p>Editor.prototype.Create = function()<br />
{<br />
	//some other code<br />
	var self = this;<br />
        //loop through all buttons in turn<br />
	elem = document.getElementById(buttonID);<br />
	addEvent( elem, &#8216;click&#8217;, function(){ShowDebug(&#8217;Button 2 OnClick&#8217;);self.FormatText(this.id,n);} ) 				</p>
	<p>}</p>
	<p>// I have also tried this for buttons I know the ID for.</p>
	<p>elem = document.getElementById(&#8217;ViewText&#8217;);<br />
addEvent( elem, &#8216;click&#8217;,  function(){ShowDebug(&#8217;Button 2 OnClick&#8217;);self.FormatText(&#8217;ViewText&#8217;,n);} );</p>
	<p>The event handler seems to be added correctly (from firebuglite debug in IE - I have put some debug into your addEvent function handler when<br />
using attachEvent)</p>
	<p>function addEvent(obj,evType,func){<br />
	var r = false;<br />
	if(obj.addEventListener){<br />
		obj.addEventListener(evType, func, false);<br />
		r = true;<br />
	}else if (obj.attachEvent) {<br />
		var id = obj.sourceIndex || -1;<br />
		ShowDebug(&#8221;addEvent to &#8221; + id);<br />
		if (!func[evType + id]) {<br />
			var f = func[evType + id] = function(e) {<br />
				var o = document.all[id] || document;<br />
				o._f = func;<br />
				var s = o._f(e);<br />
				o._f = null;<br />
				return s;<br />
				};<br />
			ShowDebug(&#8221;obj = &#8221; + obj + &#8221; typeof = &#8221; + typeof(obj) + &#8221; obj.id = &#8221; + obj.id + &#8221; tagName = &#8221; + obj.tagName);<br />
			r = obj.attachEvent(&#8221;on&#8221; + evType, f);<br />
			obj = null;<br />
		}<br />
	}else{ //if there is already a function for this handler call beforehand<br />
		var ev=&#8221;on&#8221;+evType;<br />
		var oldevent = obj[ev];<br />
		if (typeof oldevent != &#8220;function&#8221;){<br />
			obj[ev]=func;<br />
		}else{<br />
			obj[ev] = function(){ oldevent();func();}<br />
		}<br />
	}<br />
	return r;<br />
};</p>
	<p>1: addEvent to 628<br />
2: obj = [object] typeof = object obj.id = ViewText tagName = IMG</p>
	<p>The problem comes whenever I try to click on any of the toolbar buttons. Instead of passing through the reference to the actual IMG tag which it should be doing its passing through the reference for the node above which is the SPAN tag.</p>
	<p>// INCORRECT!!!<br />
25: Button 2 Onclick<br />
26: IN FormatText HTMLModeCMStextarea ; CMStextarea ;</p>
	<p>Whereas it should be passing though (as Firefox correctly does) the ID for the IMG tag.</p>
	<p>// CORRECT!!!<br />
11: Button 2 OnClick<br />
12: IN FormatText ViewSource ; CMStextarea ;</p>
	<p>If I revert back to the older functions it works fine. Can you give me some guidance on whats gone wrong and if there is a fix about?</p>
	<p>Thanks
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

