Foros del Web » Programando para Internet » Javascript »

Mis propias Tags en FCKEditor

Estas en el tema de Mis propias Tags en FCKEditor en el foro de Javascript en Foros del Web. Buenas: Alguien sabe como puedo insertar de manera correcta y con FCKEditor mis propias tags? Me explico. Tengo unos plugins especiales que meto en un ...
  #1 (permalink)  
Antiguo 23/06/2008, 08:48
 
Fecha de Ingreso: julio-2005
Mensajes: 217
Antigüedad: 18 años, 9 meses
Puntos: 0
Pregunta Mis propias Tags en FCKEditor

Buenas:
Alguien sabe como puedo insertar de manera correcta y con FCKEditor mis propias tags?
Me explico. Tengo unos plugins especiales que meto en un texto y al salir a la web se interpretan para que hagan cierto tipo de cosas(crearle ejercicios al usuario por ejemplo). Me creo un plugin en el FCKEditor para .net, me cojo las opciones y se las paso con:

plugin = '<myplugin opciones='+opciones+'>'+opcion1+</myplugin>';

Esto lo estoy haciendo asi para que no se vea en el editor todo el texto del plugin que a la persona que lo edita le es muy incomodo.
Al insertar el plugin hago un FCK.InsertHtml(plugin) y en firefox me va bien. Pero en IE tanto 6 como 7 el opcion1 en vez de ponerlo dentro de la etiqueta me lo pone fuera y a continuacion.
¿Alguien sabe que puede pasar?
__________________
Moitas Gracias desde Galiza!!!
  #2 (permalink)  
Antiguo 24/06/2008, 02:50
 
Fecha de Ingreso: julio-2005
Mensajes: 217
Antigüedad: 18 años, 9 meses
Puntos: 0
Pregunta Respuesta: Mis propias Tags en FCKEditor

Alguien sabe por que pasa esto en IE? Es por el explorador que no permita tags que no existe?
__________________
Moitas Gracias desde Galiza!!!
  #3 (permalink)  
Antiguo 24/06/2008, 13:43
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 10 meses
Puntos: 834
Respuesta: Mis propias Tags en FCKEditor

No. Seguramente el problema es que FCK debe usar inserthtml como comando de execCommand, y ese comando no funciona en Explorer.
Podrías intentar modificar la función, basándore en que si es explorer haga algo distinto, ejemplo:
Código PHP:
function inHTML(){
    var 
u,u2;
    if(!(
u=prompt('ingresar html')))return;
    
        try{
            
editor.execCommand("inserthtml",false,u);
        }catch(
e){
            try{
                
u2=editor.selection.createRange();
                
u2.pasteHTML(u);
            }catch(
E){
                
alert('nop');
            }
        }

Quizá este ejemplo de editor te ayude a entender cómo funcionan estos editores:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title></title>
<
style>
input{
border:1px solid #000;
background:#CCCCCC;
font-family:VerdanaArialHelveticasans-serif;
font-size:9px;
margin-bottom:3px;
}
</
style>
<
script>
var 
editor;
function $(
id){
    return 
document.getElementById(id);
}
function 
formato(f){
    
editor.execCommand(ffalsenull);
}
function 
rev(t)    {
    return 
t.split("<").join("&lt;").split(">").join("&gt;").split("\"").join("&quot;");
}
function 
insertarEnlace(){
    var 
u;
    if(!(
u=prompt('ingresar url','http://')))return;
    
editor.execCommand("CreateLink",false,u);
}
function 
insertarImagen(){
    var 
u;
    if(!(
u=prompt('ingresar url','http://')))return;
    
editor.execCommand("InsertImage",false,u);
}
function 
color(c){
    
editor.execCommand("forecolor",false,c);
}

function 
colorFondo(c){
    var 
h=window.ActiveXObject?'backcolor':'hilitecolor';
    
editor.execCommand(h,false,c);
}
function 
inHTML(){
    var 
u,u2;
    if(!(
u=prompt('ingresar html')))return;
    
        try{
            
editor.execCommand("inserthtml",false,u);
        }catch(
e){
            try{
                
u2=editor.selection.createRange();
                
u2.pasteHTML(u);
            }catch(
E){
                
alert('nop');
            }
        }
}

function 
htmlOEditor(e){
e=|| window.event;
ob=e.target || e.srcElement
$('edit').style.display=(ob.value=='html')?'none':'block';
$(
'ht').style.display=(ob.value!='html')?'none':'block';
$(
'ht').innerHTML=rev(editor.body.innerHTML);
ob.value=(ob.value=='html')?'editor':'html';
}
window.onload=function(){
    
    
editor=$('edit').contentDocument || $('edit').contentWindow.document;
    
editor.designMode='on';
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <input type="button" name="Submit" value="N" onclick="formato('bold')" />
  <input type="button" name="Submit2" value="C" onclick="formato('italic')" />
  <input type="button" name="Submit3" value="S" onclick="formato('underline')" />
  <input type="button" name="Submit4" value="remover formato" onclick="formato('RemoveFormat')" />
  <input type="button" name="Submit5" value="link" onclick="insertarEnlace()" />
  <input type="button" name="Submit9" value="quitar link" onclick="formato('Unlink')" />
  <input type="button" name="Submit6" value="imagen" onclick="insertarImagen()" />
  <input type="button" name="Submit7" value="texto rojo" onclick="color('#FF0000')" />
  <input type="button" name="Submit8" value="fondo rojo" onclick="colorFondo('#FF0000')" />
    <input type="button" name="Submit10" value="deshacer" onclick="formato('undo')" />
  <input type="button" name="Submit11" value="rehacer" onclick="formato('redo')" />

  <input type="button" name="Submit12" value="insertar html" onclick="inHTML()" />
  <br />
<iframe id="edit" width="100%" height="300" style=" border:1px solid #000;"></iframe>
<div id="ht" style="width:100%; height:300px; overflow:auto; border:1px solid #000; display:none"></div>
<div style="margin-top:3px;"><input name="ver" type="button" id="ver" onclick="htmlOEditor(event)" value="html" /></div>
</form>
</body>
</html> 
  #4 (permalink)  
Antiguo 24/06/2008, 15:29
 
Fecha de Ingreso: julio-2005
Mensajes: 217
Antigüedad: 18 años, 9 meses
Puntos: 0
Respuesta: Mis propias Tags en FCKEditor

Claro. Es lo primero que pense que esa funcion en IE no funcionara. Pero probe a crearme algun tag que si que existia como un <a href=...></a> y ahi si que me lo hizo bien. Me metio el texto dentro de la etiqueta y no a continuacion como con las etiquetas que me cree. Por eso crei que podia ser del tipo de tags que me invente.

Comentarte tambien que con Firefox he tenido algun otro problema, no con esto en concreto, mas bien despues de insertar, ya que el cursor queda dentro de la etiqueta y queria que se posicionara fuera de ella el foco.

Probare con lo que me comentaste y te digo. Muchas gracias.
__________________
Moitas Gracias desde Galiza!!!
  #5 (permalink)  
Antiguo 23/08/2010, 11:55
 
Fecha de Ingreso: agosto-2010
Mensajes: 3
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Mis propias Tags en FCKEditor

Cita:
Iniciado por Panino5001 Ver Mensaje
No. Seguramente el problema es que FCK debe usar inserthtml como comando de execCommand, y ese comando no funciona en Explorer.
Podrías intentar modificar la función, basándore en que si es explorer haga algo distinto, ejemplo:
Código PHP:
function inHTML(){
    var 
u,u2;
    if(!(
u=prompt('ingresar html')))return;
    
        try{
            
editor.execCommand("inserthtml",false,u);
        }catch(
e){
            try{
                
u2=editor.selection.createRange();
                
u2.pasteHTML(u);
            }catch(
E){
                
alert('nop');
            }
        }

Quizá este ejemplo de editor te ayude a entender cómo funcionan estos editores:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title></title>
<
style>
input{
border:1px solid #000;
background:#CCCCCC;
font-family:VerdanaArialHelveticasans-serif;
font-size:9px;
margin-bottom:3px;
}
</
style>
<
script>
var 
editor;
function $(
id){
    return 
document.getElementById(id);
}
function 
formato(f){
    
editor.execCommand(ffalsenull);
}
function 
rev(t)    {
    return 
t.split("<").join("&lt;").split(">").join("&gt;").split("\"").join("&quot;");
}
function 
insertarEnlace(){
    var 
u;
    if(!(
u=prompt('ingresar url','http://')))return;
    
editor.execCommand("CreateLink",false,u);
}
function 
insertarImagen(){
    var 
u;
    if(!(
u=prompt('ingresar url','http://')))return;
    
editor.execCommand("InsertImage",false,u);
}
function 
color(c){
    
editor.execCommand("forecolor",false,c);
}

function 
colorFondo(c){
    var 
h=window.ActiveXObject?'backcolor':'hilitecolor';
    
editor.execCommand(h,false,c);
}
function 
inHTML(){
    var 
u,u2;
    if(!(
u=prompt('ingresar html')))return;
    
        try{
            
editor.execCommand("inserthtml",false,u);
        }catch(
e){
            try{
                
u2=editor.selection.createRange();
                
u2.pasteHTML(u);
            }catch(
E){
                
alert('nop');
            }
        }
}

function 
htmlOEditor(e){
e=|| window.event;
ob=e.target || e.srcElement
$('edit').style.display=(ob.value=='html')?'none':'block';
$(
'ht').style.display=(ob.value!='html')?'none':'block';
$(
'ht').innerHTML=rev(editor.body.innerHTML);
ob.value=(ob.value=='html')?'editor':'html';
}
window.onload=function(){
    
    
editor=$('edit').contentDocument || $('edit').contentWindow.document;
    
editor.designMode='on';
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <input type="button" name="Submit" value="N" onclick="formato('bold')" />
  <input type="button" name="Submit2" value="C" onclick="formato('italic')" />
  <input type="button" name="Submit3" value="S" onclick="formato('underline')" />
  <input type="button" name="Submit4" value="remover formato" onclick="formato('RemoveFormat')" />
  <input type="button" name="Submit5" value="link" onclick="insertarEnlace()" />
  <input type="button" name="Submit9" value="quitar link" onclick="formato('Unlink')" />
  <input type="button" name="Submit6" value="imagen" onclick="insertarImagen()" />
  <input type="button" name="Submit7" value="texto rojo" onclick="color('#FF0000')" />
  <input type="button" name="Submit8" value="fondo rojo" onclick="colorFondo('#FF0000')" />
    <input type="button" name="Submit10" value="deshacer" onclick="formato('undo')" />
  <input type="button" name="Submit11" value="rehacer" onclick="formato('redo')" />

  <input type="button" name="Submit12" value="insertar html" onclick="inHTML()" />
  <br />
<iframe id="edit" width="100%" height="300" style=" border:1px solid #000;"></iframe>
<div id="ht" style="width:100%; height:300px; overflow:auto; border:1px solid #000; display:none"></div>
<div style="margin-top:3px;"><input name="ver" type="button" id="ver" onclick="htmlOEditor(event)" value="html" /></div>
</form>
</body>
</html> 
Hola me gusto tu aporte, lo estube probando y me parecio muy sencillo y practico, pero paradojicamente no he podido hacer que puede insertar tipos de fuentes y tañanos. No se si tenes alguna idea para hacer esto en este editor. Saludos. Muchas gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:34.