Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Renato =)

Formatar texto

Recommended Posts

Então, peguei um addon pra firefox que cria botões que executam comandos em javascript...

Achei um comando já criado na internet que criava um texto onde você estivesse escrevendo, e o código dele é o seguinte:

 

// This is essentially a single item version of deepakjoshi04's Custom forum Tags button
// found at http://custombuttons.phpbbnow.com/viewtopic.php?t=233#659


var open="TEXTO AQUI";


var theBox = document.commandDispatcher.focusedElement;
var startPos = theBox.selectionStart;
var endPos = theBox.selectionEnd;
var selectionLen = endPos - startPos
var oPosition = theBox.scrollTop;
var oHeight = theBox.scrollHeight;
var text=theBox.value.substring(0,startPos);			// This grabs the first portion of the text box.
var nHeight = theBox.scrollHeight - oHeight;
text +=open;							// This inserts the desired string.
text +=theBox.value.substring(endPos, theBox.value.length);	// This appends the remaining text within the text box.
theBox.value = text;						// This places the new text back into the text box.
theBox.selectionStart = endPos + open.length;
theBox.selectionEnd = endPos + open.length - selectionLen;
theBox.scrollTop = oPosition + nHeight;				// These last 3 statments properly place the cursor.

 

Gostaria de saber como eu poderia fazer, nesse addon, para substituir várias tags (por exemplo :) por :D) na caixa de texto selecionada...

 

tentei colocar este código abaixo só que não acontece nada, também nem tinha esperanças de funcionar

 

replace( "{/p}", "</p>" );

Abraços!

Compartilhar este post


Link para o post
Compartilhar em outros sites

bem, pode ser de outra maneira...

 

quero que quando o usuário fazer certa ação, execute o seguinte comando:

 

java script:
var txt=document.getElementsByTagName('textarea')[0];
txt.value=txt.value.replace({/p},</p>);
void(0);

como se ele fosse executado quando se coloca na barra de endereços e aperta enter...

assim funciona perfeitamente

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.