begin process at 2012 05 30 03:42:13
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive Javascript

 > 

Archives

 > 

AU SECOURS !!!

 > 

Rich Text Editor pb modif


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Rich Text Editor pb modif

mardi 24 août 2004 à 11:06:08 | Rich Text Editor pb modif

jotrash

Membre Club
bonjour a tous et merci de lire ce message...
Debutant en js g un pb de modification dun script trouve
//init variables
var isRichText = false;
var rng;
var currentRTE;
var allRTEs = "";

var isIE;
var isGecko;
var isSafari;
var isKonqueror;

var imagesPath;
var includesPath;
var cssFile;


function initRTE(imgPath, incPath, css) {
//set browser vars
var ua = navigator.userAgent.toLowerCase();
isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
isGecko = (ua.indexOf("gecko") != -1);
isSafari = (ua.indexOf("safari") != -1);
isKonqueror = (ua.indexOf("konqueror") != -1);

//check to see if designMode mode is available
if (document.getElementById && document.designMode && !isSafari && !isKonqueror) {
isRichText = true;
}

if (!isIE) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN | Event.MOUSEUP);
//on appelle les fonctions un peux plus loins
document.onmouseover = raiseButton;
document.onmouseout = normalButton;
document.onmousedown = lowerButton;
document.onmouseup = raiseButton;

//set paths vars
imagesPath = imgPath;
includesPath = incPath;
cssFile = css;

if (isRichText) document.writeln('<style type="text/css">@import "' + includesPath + 'rte.css";</style>');

//for testing standard textarea, uncomment the following line
//isRichText = false;
}

function writeRichText(rte, html, width, height, buttons, readOnly) {
if (isRichText) {
if (allRTEs.length > 0) allRTEs += ";";
allRTEs += rte;
writeRTE(rte, html, width, height, buttons, readOnly);
} else {
writeDefault(rte, html, width, height, buttons, readOnly);
}
}



function raiseButton(e) {
if (isIE) {
var el = window.event.srcElement;
} else {
var el= e.target;
}

className = el.className;
if (className == 'rteImage' || className == 'rteImageLowered') {
el.className = 'rteImageRaised';
}
}

function normalButton(e) {
if (isIE) {
var el = window.event.srcElement;
} else {
var el= e.target;
}

className = el.className;
if (className == 'rteImageRaised' || className == 'rteImageLowered') {
el.className = 'rteImage';
}
}

function lowerButton(e) {
if (isIE) {
var el = window.event.srcElement;
} else {
var el= e.target;
}

className = el.className;
if (className == 'rteImage' || className == 'rteImageRaised') {
el.className = 'rteImageLowered';
}
}

function writeRTE(rte, html, width, height, buttons, readOnly) {
if (readOnly) buttons = false;

//adjust minimum table widths
if (isIE) {
if (buttons && (width < 600)) width = 600;
var tablewidth = width;
} else {
if (buttons && (width < 500)) width = 500;
var tablewidth = width + 4;
}

if (buttons == true) {
document.writeln('<table class="rteBack" cellpadding=2 cellspacing=0 id="Buttons1_' + rte + '" width="' + tablewidth + '">');
document.writeln(' <tr>');
document.writeln(' <td>');
document.writeln(' <select id="formatblock_' + rte + '" onchange="Select(\'' + rte + '\', this.id);">');
document.writeln(' <option value="">[Style]</option>');
document.writeln(' <option value="<p>">Paragraph</option>');
document.writeln(' <option value="<h1>">Heading 1 <h1></option>');
document.writeln(' <option value="<h2>">Heading 2 <h2></option>');
document.writeln(' <option value="<address>">Address <ADDR></option>');
document.writeln(' <option value="<pre>">Formatted <pre></option>');
document.writeln(' </select>');
document.writeln(' </td>');
document.writeln(' <td>');
document.writeln(' <select id="fontname_' + rte + '" onchange="Select(\'' + rte + '\', this.id)">');
document.writeln(' <option value="Arial, Helvetica, sans-serif">Arial</option>');
document.writeln(' <option value="Courier New, Courier, mono">Courier New</option>');
document.writeln(' <option value="Times New Roman, Times, serif">Times New Roman</option>');
document.writeln(' <option value="Verdana, Arial, Helvetica, sans-serif">Verdana</option>');
document.writeln(' </select>');
document.writeln(' </td>');
document.writeln(' <td>');
document.writeln(' <select unselectable="on" id="fontsize_' + rte + '" onchange="Select(\'' + rte + '\', this.id);">');
document.writeln(' <option value="1">1</option>');
document.writeln(' <option value="2">2</option>');
document.writeln(' <option value="3">3</option>');
document.writeln(' <option value="4">4</option>');
document.writeln(' <option value="5">5</option>');
document.writeln(' <option value="6">6</option>');
document.writeln(' <option value="7">7</option>');
document.writeln(' </select>');
document.writeln(' </td>');
document.writeln(' <td width="100%">');
document.writeln(' </td>');
document.writeln(' </tr>');
document.writeln('</table>');
document.writeln('<table class="rteBack" cellpadding="0" cellspacing="0" id="Buttons2_' + rte + '" width="' + tablewidth + '">');
document.writeln(' <tr>');

document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'bold.gif" width="25" height="24" alt="Bold" title="Bold" onClick="FormatText(\'' + rte + '\', \'bold\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'italic.gif" width="25" height="24" alt="Italic" title="Italic" onClick="FormatText(\'' + rte + '\', \'italic\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'underline.gif" width="25" height="24" alt="Underline" title="Underline" onClick="FormatText(\'' + rte + '\', \'underline\', \'\')"></td>');

document.writeln(' <td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');

document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'left_just.gif" width="25" height="24" alt="Align Left" title="Align Left" onClick="FormatText(\'' + rte + '\', \'justifyleft\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'centre.gif" width="25" height="24" alt="Center" title="Center" onClick="FormatText(\'' + rte + '\', \'justifycenter\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'right_just.gif" width="25" height="24" alt="Align Right" title="Align Right" onClick="FormatText(\'' + rte + '\', \'justifyright\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'justifyfull.gif" width="25" height="24" alt="Justify Full" title="Justify Full" onclick="FormatText(\'' + rte + '\', \'justifyfull\', \'\')"></td>');

document.writeln(' <td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'hr.gif" width="25" height="24" alt="Horizontal Rule" title="Horizontal Rule" onClick="FormatText(\'' + rte + '\', \'inserthorizontalrule\', \'\')"></td>');

document.writeln(' <td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'numbered_list.gif" width="25" height="24" alt="Ordered List" title="Ordered List" onClick="FormatText(\'' + rte + '\', \'insertorderedlist\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'list.gif" width="25" height="24" alt="Unordered List" title="Unordered List" onClick="FormatText(\'' + rte + '\', \'insertunorderedlist\', \'\')"></td>');

document.writeln(' <td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" onClick="FormatText(\'' + rte + '\', \'outdent\', \'\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'indent.gif" width="25" height="24" alt="Indent" title="Indent" onClick="FormatText(\'' + rte + '\', \'indent\', \'\')"></td>');
document.writeln(' <td><div id="forecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'textcolor.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="FormatText(\'' + rte + '\', \'forecolor\', \'\')"></div></td>');
document.writeln(' <td><div id="hilitecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'bgcolor.gif" width="25" height="24" alt="Background Color" title="Background Color" onClick="FormatText(\'' + rte + '\', \'hilitecolor\', \'\')"></div></td>');


document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'undo.gif" width="25" height="24" alt="Undo" title="Undo" onClick="FormatText(\'' + rte + '\', \'undo\')"></td>');
document.writeln(' <td><img class="rteImage" src="' + imagesPath + 'redo.gif" width="25" height="24" alt="Redo" title="Redo" onClick="FormatText(\'' + rte + '\', \'redo\')"></td>');
document.writeln(' <td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
document.writeln(' <td><div id="smiley_' + rte + '"><img class="rteImage" src="' + imagesPath + 'smiley.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="FormatText(\'' + rte + '\', \'smiley\', \'\')"></div></td>');

document.writeln(' </tr>');
document.writeln('</table>');
}
document.writeln('<iframe id="' + rte + '" name="' + rte + '" width="' + width + 'px" height="' + height + 'px"></iframe>');
if (!readOnly)
document.writeln('<iframe width="154" height="104" id="cp' + rte + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; display: none; position: absolute;"></iframe>');
document.writeln('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
document.getElementById('hdn' + rte).value = html;
enableDesignMode(rte, html, readOnly);
}

function enableDesignMode(rte, html, readOnly) {
var frameHtml = "<html id=\"" + rte + "\">\n";
frameHtml += "<head>\n";
//to reference your stylesheet, set href property below to your stylesheet path and uncomment
if (cssFile.length > 0) {
frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + cssFile + "\" rel=\"stylesheet\">\n";
} else {
frameHtml += "<style>\n";
frameHtml += "body {\n";
frameHtml += " background: #FFFFFF;\n";
frameHtml += " margin: 0px;\n";
frameHtml += " padding: 0px;\n";
frameHtml += "}\n";
frameHtml += "</style>\n";
}
frameHtml += "</head>\n";
frameHtml += "<body>\n";
frameHtml += html + "\n";
frameHtml += "</body>\n";
frameHtml += "</html>";

if (document.all) {
var oRTE = frames[rte].document;
oRTE.open();
oRTE.write(frameHtml);
oRTE.close();
if (!readOnly) oRTE.designMode = "On";
} else {
try {
if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
try {
var oRTE = document.getElementById(rte).contentWindow.document;
oRTE.open();
oRTE.write(frameHtml);
oRTE.close();
if (isGecko && !readOnly) {
//attach a keyboard handler for gecko browsers to make keyboard shortcuts work
oRTE.addEventListener("keypress", kb_handler, true);
}
} catch (e) {
alert("Error preloading content.");
}
} catch (e) {
//gecko may take some time to enable design mode.
//Keep looping until able to set.
if (isGecko) {
setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 10);
} else {
return false;
}
}
}
}

//Fonction pour le gras italique souligne de la textbox
function FormatText(rte, command, option) {
var oRTE;
if (document.all) {
oRTE = frames[rte];

} else {
oRTE = document.getElementById(rte).contentWindow;

//get currently selected range
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}

try {
if ((command == "forecolor") || (command == "hilitecolor")) {
//save current values
parent.command = command;
currentRTE = rte;

//position and show color palette
buttonElement = document.getElementById(command + '_' + rte);
// Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
document.getElementById('cp' + rte).style.left = getOffsetLeft(buttonElement, 4) + "px";
document.getElementById('cp' + rte).style.top = (getOffsetTop(buttonElement, 4) + buttonElement.offsetHeight + 4) + "px";
if (document.getElementById('cp' + rte).style.visibility == "hidden") {
document.getElementById('cp' + rte).style.visibility = "visible";
document.getElementById('cp' + rte).style.display = "inline";
} else {
document.getElementById('cp' + rte).style.visibility = "hidden";
document.getElementById('cp' + rte).style.display = "none";
}
} else {
oRTE.focus();
oRTE.document.execCommand(command, false, option);
oRTE.focus();
}
} catch (e) {
alert(e);
}
}

//Function pour la couleur
function setColor(color) {
var rte = currentRTE;
var oRTE;
if (document.all) {
oRTE = frames[rte];
} else {
oRTE = document.getElementById(rte).contentWindow;
}

var parentCommand = parent.command;
if (document.all) {
//retrieve selected range
var sel = oRTE.document.selection;
if (parentCommand == "hilitecolor") parentCommand = "backcolor";
if (sel != null) {
var newRng = sel.createRange();
newRng = rng;
newRng.select();
}
}
oRTE.focus();
oRTE.document.execCommand(parentCommand, false, color);
oRTE.focus();
document.getElementById('cp' + rte).style.visibility = "hidden";
document.getElementById('cp' + rte).style.display = "none";
}



function getOffsetTop(elm, parents_up) {
var mOffsetTop = elm.offsetTop;
var mOffsetParent = elm.offsetParent;

if(!parents_up) {
parents_up = 10000; // arbitrary big number
}
while(parents_up>0 && mOffsetParent) {
mOffsetTop += mOffsetParent.offsetTop;
mOffsetParent = mOffsetParent.offsetParent;
parents_up--;
}

return mOffsetTop;
}

function getOffsetLeft(elm, parents_up) {
var mOffsetLeft = elm.offsetLeft;
var mOffsetParent = elm.offsetParent;

if(!parents_up) {
parents_up = 10000; // arbitrary big number
}
while(parents_up>0 && mOffsetParent) {
mOffsetLeft += mOffsetParent.offsetLeft;
mOffsetParent = mOffsetParent.offsetParent;
parents_up--;
}

return mOffsetLeft;
}

function Select(rte, selectname) {
var oRTE;
if (document.all) {
oRTE = frames[rte];

var selection = oRTE.document.selection;
if (selection != null) {
rng = selection.createRange();
}
} else {
oRTE = document.getElementById(rte).contentWindow;

var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}

var idx = document.getElementById(selectname).selectedIndex;
if (idx != 0) {
var selected = document.getElementById(selectname).options[idx].value;
var cmd = selectname.replace('_' + rte, '');
oRTE.focus();
oRTE.document.execCommand(cmd, false, selected);
oRTE.focus();

}
}
//po sur de lutilite mais sinon ya une erreur
function kb_handler(evt) {
var rte = evt.target.id;

if (evt.ctrlKey) {
var key = String.fromCharCode(evt.charCode).toLowerCase();
var cmd = '';
switch (key) {
case 'b': cmd = "bold"; break;
case 'i': cmd = "italic"; break;
case 'u': cmd = "underline"; break;
};

if (cmd) {
FormatText(rte, cmd, true);
evt.preventDefault();
evt.stopPropagation();
}
}
}




je voudrais ajouter une case pour les smileys.. ce que g fait en ajoutant
document.writeln(' <td><div id="smiley_' + rte + '"><img class="rteImage" src="' + imagesPath + 'smiley.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="FormatText(\'' + rte + '\', \'smiley\', \'\')"></div></td>');


mais je ne trouve po le code pour afficher l'iframe des smileys (smiley.htm) comme pour les couleurs (palette.htm)

comment faire svp

merci davance

@++
JoTrAsH
mardi 24 août 2004 à 13:30:27 | Re : Rich Text Editor pb modif

coucou747

Administrateur CodeS-SourceS
pour commencer, je serais étonné que ça marche avec mozilla (event) et pour finir, expliques pluotto ce que tu veux faire avec ce scritp... En js, on a souvent 2, 3 ou 4 façon d'arriver au même endroit alors expliqie ce quetu veux faire, on poura peut-être passer par un chemin plus portable...
les vars au début ne sercvent a rien.
mardi 24 août 2004 à 14:09:01 | Re : Rich Text Editor pb modif

jotrash

Membre Club
Réponse acceptée !
g trouve la solution michi qd mm

@++
JoTrAsH


Cette discussion est classée dans : var, document, writeln, rte, orte


Répondre à ce message

Sujets en rapport avec ce message

Aide a decrypté [ par Wab ] bonjour, quelqu'un peux m'aider a decrypté ca? :function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == - aide pour un jv-sc qui test des champs [ par Moussetique ] function VerifForm() { adresse = document.krucial.email.value; motdp = document.krucial.mdp.value; var place = adresse.indexOf("@",1); var point = adr pb pour placer les sous-menus [ par annethe ] Bonjour,J'ai créé un menu dynamique. J'ai réussi à placer lemenu où je veux mais je n'arrive pas à bien placer lessous-menus.dans la page ou j'affiche Appel de fonction via un évènement OnClick ? [ par bside8 ] Bonjour,tout commence par un formulaire PHP dans lequel mes utilisateurs doivent saisir une date.Dans le champ concerné se trouve un gestionnaire d'év OnChange=fonction() --> ne MARCHE pas !! [ par bside8 ] Bonjour,j'essaie de mettre au point un script permettant d'afficher un calendrier.J'affiche dans une fenêtre nommée Calendrier le calendrier du mois c forcer les frames [ par jchv ] je voudrais forcer les frames si on ouvre le site sur une autre page que celle d'accueil. j'ai essayé le script suivant : (le script ajouté va de "if" Changer le chemin d'accès d'un cookie [ par Angelucky ] Salut tout le monde !!!Je suis charger de refaire un site en JavaScript dans lequel j'utilise un cookie ! Mon problème est de pouvoir changer l'emplac Diaporama Javascript [ par Dominike ] - Dominike -Bonjour à tous !Je vous soumet un petit problème que je n'arrive pas à résoudre seul.J'ai récupéré un Javascript sympa pour créer un diapo mozilla et les sélections :( [ par randiox ] voila j'ai fait un petit code qui tourne sous IE :function smiley(code) { var chaine = document.selection.createRange().text; document.formulaire.te au secours a tous [ par 999999 ] salut à tous j'ai un petit problème de javascript. Voila j'ai trouvé un script qui permet d'afficher un texte au passage de la souris sur un lien. Voi


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales