Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/05/2009, 16:43
WebDeveloperZ
 
Fecha de Ingreso: marzo-2007
Mensajes: 340
Antigüedad: 18 años
Puntos: 4
Problema con sistema de tags en IE (estilo foros) ([b][/b])

Que tal gente, tengo un problema en IE, cuando sombreo parte de un texto y aplico un tag utilizando esta funcion no lo encierra, en ves de quedar algo como esto:

[b ]adasd[ /b]

queda asi:

[b ][ /b]adasd

en firefox, opera, etc no sucede.

Alguna idea de como puedo arreglarlo ? gracias.

Llamada:

Código:
<a href="#" onclick="applyDecos('tLongDesc', '', ''); return false;">Bold</a>
JS:

Código:
function applyDecos(eId, decoOpen, decoClose) {
	// Applies decorations brackets to the textbox
	// i.e: applyDecos("tMsg", "", "")
	
	mozWrap(document.getElementById(eId), decoOpen, decoClose); // Adding decos
	document.getElementById(eId).focus(); // Focusing textbox
	
	// If we didnt select but added them, then...
	if (document.getElementById(eId).selectionStart == document.getElementById(eId).selectionEnd) {
		// ... we set the cursor in the middle of both so we can write =)
		document.getElementById(eId).selectionStart = document.getElementById(eId).selectionStart - decoClose.length;
		document.getElementById(eId).selectionEnd = document.getElementById(eId).selectionStart;
	}
	
	return;
//	}
}

/*
* mozWrap From http://www.massless.org/mozedit/
*/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	var scrollTop = txtarea.scrollTop;

	if (selEnd == 1 || selEnd == 2) 
	{
		selEnd = selLength;
	}

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);

	txtarea.value = s1 + open + s2 + close + s3;
	txtarea.selectionStart = selEnd + open.length + close.length;
	txtarea.selectionEnd = txtarea.selectionStart;
	txtarea.focus();
	txtarea.scrollTop = scrollTop;

	return;
}
function insertText(txtarea, data)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	var scrollTop = txtarea.scrollTop;

	if (selEnd == 1 || selEnd == 2) 
	{
		selEnd = selLength;
	}

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);

	txtarea.value = s1 + data + s2 + s3;
	txtarea.selectionStart = selEnd + data.length;
	txtarea.selectionEnd = txtarea.selectionStart;
	txtarea.focus();
	txtarea.scrollTop = scrollTop;

	return;
}

function queryDecoURL(eId) {
	var url = prompt("URL", "http://");
	if (url.length > 0) {
		applyDecos(eId, "", "");
	}
}