Ir para conteúdo
Fórum Script Brasil
  • 0

Bbcode Pular Linha


Jony Walker

Pergunta

Preciso incorporar a tag de [br] para ser substituída dentro desse script de bbcode e não tenho a menor idéia de como capturar que a pessoa pulou linha:

<script>
var BBCode = function(){
window.undefined = window.undefined;
this.initDone = false;
}
BBCode.prototype.init = function(t){
if(this.initDone) return false;
if(t == undefined) return false;
this._target = t ? document.getElementById(t) : t;
this.initDone = true;
return true;
}
BBCode.prototype.noForm = function(){
return this._target == undefined;
}
// insertcode is used for bold, italic, underline and quote and just
// wraps the tags around a selection or prompts the user for some
// text to apply the tag to
BBCode.prototype.insertCode = function (tag, desc, endtag) {
if(this.noForm()) return false;
var isDesc = (desc == undefined || desc == '') ? false : true;
// our textfield
var textarea = this._target;
// our open tag
var open = '['+tag+']';
var close = '[/'+((endtag == undefined) ? tag : endtag)+']';
if (!textarea.setSelectionRange) {
var selected = document.selection.createRange().text;
if (selected.length<=0) {
// no text was selected so prompt the user for some text
textarea.value += open+((isDesc) ? prompt("Please enter the text you'd like to "+desc, "")+close : '');
} else {
// put the code around the selected text
document.selection.createRange().text = open+selected+((isDesc) ? close : '');
}
} else {
// the text before the selection
var pretext = textarea.value.substring(0, textarea.selectionStart);
// the selected text with tags before and after
var codetext = open+textarea.value.substring(textarea.selectionStart, textarea.selectionEnd)+((isDesc) ? close : '');
// the text after the selection
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
// check if there was a selection
if (codetext == open+close) {
//prompt the user
codetext = open+((isDesc) ? prompt("Coloque o texto que gostaria de deixar "+desc, "")+close : '');
}
// update the text field
textarea.value = pretext+codetext+posttext;
}
// set the focus on the text field
textarea.focus();
}
// inserts an image by prompting the user for the url
BBCode.prototype.insertImage = function (html) {
if(this.noForm()) return false;
var src = prompt('Coloque o endereço url', 'http://');
this.insertCode('img='+src);
}

// inserts a link by prompting the user for a url
BBCode.prototype.insertLink = function (html) {
if(this.noForm()) return false;
this.insertCode('url='+prompt("Coloque o endereço url", "http://"), 'como texto do link', 'url')
}
//-->
</script>

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...