Ir para conteúdo

POWERED BY:

Arquivado

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

buh

bbcode para cor da fonte

Recommended Posts

pessoal to fazendu um formula e to montando um bbcode para formatação do texto ja fiz negrito, italico, sublinhado, pra inserir link, pra inserir imagem, pra inserir video do youtube.. agora

 

 

o problema é a cor da font..

 

com o meu codigo nãoestou conseguindo fazer ele passar a cor

 

funfa assim..

 

<script LANGUAGE="JavaScript">
<!--
// Copyright © 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.geocities.com/~yehuda/
// create 6-element array
var hex = new Array(6)
// assign non-dithered descriptors
hex[0] = "FF"
hex[1] = "CC"
hex[2] = "99"
hex[3] = "66"
hex[4] = "33"
hex[5] = "00"
// accept triplet string and display as background color
function display(triplet) {
// set color as background color
document.bgColor = '#' + triplet
// display the color hexadecimal triplet
//alert('O JavaSite Responde: A cor deste background é ' + triplet)
}
// draw a single table cell based on all descriptors
function drawCell(red, green, blue) {
// open cell with specified hexadecimal triplet background color
document.write('<TD BGCOLOR="#' + red + green + blue + '">')
// open a hypertext link with javascript: scheme to call display function
//document.write('<A HREF="javascript:display(\'' + (red + green + blue) + '\')">')
//document.write('<A HREF="javascript:void(0)" onclick="textarea_selecionado(textarea)">')
document.write("<a href=\"javascript:textarea_selecionado(document.getElementById('texto'));\">")
// print transparent image (use any height and width)
document.write('<IMG SRC="place.gif" BORDER=0 HEIGHT=9 WIDTH=9>')
// close link tag
document.write('</A>')
// close table cell
document.write('</TD>')
}
// draw table row based on red and blue descriptors
function drawRow(red, blue) {
// open table row
document.write('<TR>')
// loop through all non-dithered color descripters as green hex
for (var i = 0; i < 6; ++i) {
drawCell(red, hex[i], blue)
}
// close current table row
document.write('</TR>')
}
// draw table for one of six color cube panels
function drawTable(blue) {
// open table (one of six cube panels)
document.write('<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>')
// loop through all non-dithered color descripters as red hex
for (var i = 0; i < 6; ++i) {
drawRow(hex[i], blue)
}
// close current table
document.write('</TABLE>')
}
// draw all cube panels inside table cells
function drawCube() {
// open table
document.write('<TABLE CELLPADDING=5 CELLSPACING=0 BORDER=0><TR>')
// loop through all non-dithered color descripters as blue hex
for (var i = 0; i < 6; ++i) {
// open table cell with white background color
document.write('<TD BGCOLOR="#FFFFFF">')
// call function to create cube panel with hex[i] blue hex
drawTable(hex[i])
// close current table cell
document.write('</TD>')
}
// close table row and table
document.write('</TR></TABLE>')
}
// call function to begin execution
drawCube()
// -->
</script>
com o codigo assima eu gero a paleta de cores...

 

se vcs notarem tem um <a href... ali achem ele

 

document.write("<a href=\"javascript:cor_font(document.getElementById('texto'));\">")

o codigo que vou postar agora ele faz o seguinte quando eu lecionar um texto dentro da textarea ele coloca a tag antes e depois do texto selecionado abrindo e fechando ela

 

 

function cor_font(textarea) {
if(document.selection && document.selection.createRange().text != ""){
document.selection.createRange().text = "[color=]" + document.selection.createRange().text + "[/color]";
}
else if(typeof(textarea.selectionstart) != "undefined") {
var antes, selecionado, depois;

antes = textarea.value.substring(0, textarea.selectionstart);
selecionado = textarea.value.substring(textarea.selectionstart, textarea.selectionend);
depois = textarea.value.substring(textarea.selectionend);

textarea.value = antes + "[color=]" + selecionado + "[/color]" + depois;
 $("#cor").slideUp();
}
if(document.selection.createRange().text == "" || (!document.selection && textarea.selectionstart == "undefined")) {
textarea.value = textarea.value + "[color=][/color]";
 $("#cor").slideUp();
}
}

meu problema é passar cor ja esta inserindo o [.color=.] [./color.] tem que ter a cor depois do igual

 

coloquei uns codigo loko ae heim kkkk galera me ajudem ..

 

vlw

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu fazeria assim:

 

Em vez disso:

document.write("<a href=\"javascript:cor_font(document.getElementById('texto'));\">")

colocaria:

document.write("<a href=\"javascript:cor_font($('#texto'),red+green+blue);void(0)\">")

e na função cor_font colocaria:

 

function cor_font(textarea,cor) {
if(document.selection && document.selection.createRange().text != ""){
document.selection.createRange().text = "[color=#"+cor+"]" + document.selection.createRange().text + "[/color]";
}
else if(typeof(textarea.selectionstart) != "undefined") {
var antes, selecionado, depois;

antes = textarea.value.substring(0, textarea.selectionstart);
selecionado = textarea.value.substring(textarea.selectionstart, textarea.selectionend);
depois = textarea.value.substring(textarea.selectionend);

textarea.value = antes + "[color=#"+cor+"]" + selecionado + "[/color]" + depois;
 $("#cor").slideUp();
}
if(document.selection.createRange().text == "" || (!document.selection && textarea.selectionstart == "undefined")) {
textarea.value = textarea.value + "[color=#"+cor+"][/color]";
 $("#cor").slideUp();
}
}

Dica:

Reparei que você usa jquery(ou outra biblioteca) ($("#cor")), mas no primeiro codigo você usa document.getElementById, coloque $("#id")

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.