Salome HOME
It was impossible to edit the body of the knowledge when the ordered or unordered...
[tools/siman.git] / Workspace / Siman / WebContent / rtef / richtext.js
index 1acd7a9fab570613095b7e22995a407b21b53adf..2b09b060b9bdb7861e0004bb986ea2a15efd5807 100644 (file)
@@ -34,7 +34,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 // Constants
-var minWidth = 450;                                    // minumum width
+var ctxpath = "/siman/";
+var minWidth = 400;                                    // minumum width
 var wrapWidth = 1245;                      //width at which all icons will appear on one bar
 var maxchar = 64000;                // maximum number of characters per save
 var lang = "en";                                       //xhtml language
@@ -135,7 +136,7 @@ function initTextInput() {
 
     wrapWidth   = 14 * 24;
     defaultFont = "Arial, Helvetica, sans-serif";
-    initRTE("../rtef/images/", "../rtef/", "", true);
+    initRTE(ctxpath + "rtef/images/", ctxpath + "rtef/", "", true);
 }
 
 function initTextEditor() {
@@ -158,7 +159,7 @@ function initTextEditor() {
 
     wrapWidth   = 15 * 24;
     defaultFont = "Arial, Helvetica, sans-serif";
-    initRTE("../rtef/images/", "../rtef/", "", true);
+    initRTE(ctxpath + "rtef/images/", ctxpath + "rtef/", "", true);
 }
 
 function addCommand(name, action) {
@@ -268,7 +269,7 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr
                  document.writeln('<tbody><tr>');
                  insertBar();
                  if(fullscreen || activeCommand.get("save") != null){
-                         document.writeln('<td><input type="image" class="rteImg" src="'+imagesPath+'save.gif" alt="'+lblSave+'" title="'+lblSave+'" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'" onClick="submitEdit()"></td>');
+                         document.writeln('<td><input type="image" class="rteImg" id="'+rte+'SaveButton" src="'+imagesPath+'save.gif" alt="'+lblSave+'" title="'+lblSave+'" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'" onClick="prepareSubmitEdit(\''+rte+'\')"></td>');
                          nbcommand += 1;
                  }
                  if(!isSafari && !isKonqueror) {
@@ -281,13 +282,11 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr
 //                       insertImg(lblUnformat,"unformat.gif","rteCommand('"+rte+"','removeformat')");
                          insertSep();
                  }
-                 if(isIE || isSafari || isKonqueror) {
+                 if(false) {
                          addCommand("cut","rteCommand('"+rte+"','cut')");
 //                       insertImg(lblCut,"cut.gif","rteCommand('"+rte+"','cut')");
                          addCommand("copy","rteCommand('"+rte+"','copy')");
 //                       insertImg(lblCopy,"copy.gif","rteCommand('"+rte+"','copy')");
-                 }
-                 if(isSafari || isKonqueror) {
                          addCommand("paste","rteCommand('"+rte+"','InsertText')");
 //                       insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','InsertText')");
                  }
@@ -347,16 +346,15 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr
 //               insertImg(lblAlgnRight,"right_just.gif","rteCommand('"+rte+"','justifyright')");
                  addCommand("justifyfull","rteCommand('"+rte+"','justifyfull')");
 //               insertImg(lblJustifyFull,"justifyfull.gif","rteCommand('"+rte+"','justifyfull')");
-                 if(!isSafari && !isKonqueror) {
+          insertSep();
+            addCommand("numbered_list","rteCommand('"+rte+"','insertorderedlist')");
+//          insertImg(lblOL,"numbered_list.gif","rteCommand('"+rte+"','insertorderedlist')");
+            addCommand("list","rteCommand('"+rte+"','insertunorderedlist')");
+//          insertImg(lblUL,"list.gif","rteCommand('"+rte+"','insertunorderedlist')");
+            addCommand("hyperlink","dlgLaunch('"+rte+"','link')");
+//          insertImg(lblInsertLink,"hyperlink.gif","dlgLaunch('"+rte+"','link')");
+                 if(false) {
                        insertSep();
-                         addCommand("numbered_list","rteCommand('"+rte+"','insertorderedlist')");
-//                       insertImg(lblOL,"numbered_list.gif","rteCommand('"+rte+"','insertorderedlist')");
-                         addCommand("list","rteCommand('"+rte+"','insertunorderedlist')");
-//                       insertImg(lblUL,"list.gif","rteCommand('"+rte+"','insertunorderedlist')");
-                         addCommand("outdent","rteCommand('"+rte+"','outdent')");
-//                       insertImg(lblOutdent,"outdent.gif","rteCommand('"+rte+"','outdent')");
-                         addCommand("indent","rteCommand('"+rte+"','indent')");
-//                       insertImg(lblIndent,"indent.gif","rteCommand('"+rte+"','indent')");
                          insertSep();
                          addCommand("textcolor","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
 //                       insertImg(lblTextColor,"textcolor.gif","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
@@ -368,15 +366,17 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr
                          insertSep();
                          addCommand("special_char","dlgLaunch('"+rte+"','char')");
 //                       insertImg(lblInsertChar,"special_char.gif","dlgLaunch('"+rte+"','char')");
-                         addCommand("hyperlink","dlgLaunch('"+rte+"','link')");
-//                       insertImg(lblInsertLink,"hyperlink.gif","dlgLaunch('"+rte+"','link')");
                          addCommand("image","dlgLaunch('"+rte+"','image')");
 //                       insertImg(lblAddImage,"image.gif","dlgLaunch('"+rte+"','image')");
                          addCommand("insert_table","dlgLaunch('"+rte+"','table')");
 //                       insertImg(lblInsertTable,"insert_table.gif","dlgLaunch('"+rte+"','table')");
                  }
+          addCommand("outdent","rteCommand('"+rte+"','outdent')");
+//        insertImg(lblOutdent,"outdent.gif","rteCommand('"+rte+"','outdent')");
+          addCommand("indent","rteCommand('"+rte+"','indent')");
+//        insertImg(lblIndent,"indent.gif","rteCommand('"+rte+"','indent')");
                  insertSep();
-                 if(!isSafari && !isKonqueror) {
+                 if(false) {
                          addCommand("replace","dlgLaunch('"+rte+"','replace')");
 //                       insertImg(lblSearch,"replace.gif","dlgLaunch('"+rte+"','replace')");
                  }
@@ -437,7 +437,7 @@ function insertImg(name, image, command, id){
          if(id!=null){
            td = "<td id='"+id+"'>";
       }
-         document.writeln(td+'<img class="rteImg" src="'+imagesPath+image+'" alt="'+name+'" title="'+name+'" onMouseDown="'+command+';return false" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'"></td>');
+         document.writeln(td+'<img class="rteImg" src="'+imagesPath+image+'" alt="'+name+'" title="'+name+'" onClick="'+command+';return false" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'"></td>');
 }
 
 function enableDesignMode(rte, html, css, readOnly) {
@@ -481,7 +481,6 @@ function enableDesignMode(rte, html, css, readOnly) {
                                if(isGecko && !readOnly) {
                                        //attach a keyboard handler for gecko browsers to make keyboard shortcuts work
                                        oRTE.addEventListener("keypress", geckoKeyPress, true);
-                                       oRTE.addEventListener("focus", function (){dlgCleanUp();}, false);
                                }
                        } catch(e) {
                                alert(lblErrorPreload);
@@ -490,7 +489,12 @@ function enableDesignMode(rte, html, css, readOnly) {
                        //gecko may take some time to enable design mode.
                        //Keep looping until able to set.
                        if(isGecko){
-                               setTimeout("enableDesignMode('"+rte+"', '"+html+"', '"+css+"', "+readOnly+");", 200);
+                       if(!timeLeft) {
+                           timeLeft = 5000;
+                       }
+                if(timeLeft > 0) {
+                                   setTimeout("enableDesignMode('"+rte+"', '"+html+"', '"+css+"', "+readOnly+ "','"+(timeLeft-200)+"');", 200);
+                           }
                        }else{
                                return false;
                        }
@@ -817,7 +821,7 @@ function getText(rte) {
   return rtn;
 }
 
-function setFormText(popup, content){
+function setFormText(popup, content, timeLeft){
        //set link text value in dialog windows
        if(content != "undefined")
        {
@@ -829,8 +833,13 @@ function setFormText(popup, content){
          }catch(e){
                  //may take some time to create dialog window.
                  //Keep looping until able to set.
-                 setTimeout("setFormText('"+popup+"','" + content + "');", 10);
-         }
+                 if(!timeLeft) {
+                     timeLeft = 5000;
+                 }
+                 if(timeLeft > 0) {
+                     setTimeout("setFormText('"+popup+"','" + content + "','"+(timeLeft-200)+"');", 200);
+                 }
+          }
        }
 }
 
@@ -1037,14 +1046,18 @@ function setRange(rte){
        //function to store range of current selection
        var oRTE = returnRTE(rte);
        var selection;
-       if(document.all){
+       if(document.all){  //IE
                selection = oRTE.document.selection;
                if(selection != null){
       rng = selection.createRange();
     }
        }else{
                selection = oRTE.getSelection();
-               rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
+               if(selection.rangeCount > 0) {
+                 rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
+               } else {
+                 rng = oRTE.document.createRange();
+               }
        }
        return rng;
 }
@@ -1318,3 +1331,17 @@ function checkspell() {
                }
        }
 }
+
+//*****************
+//Validation
+//*****************
+function enableRTEvalidation(rteName) {
+    document.getElementById(rteName+'SaveButton').addEventListener("click", function(event){
+        updateRTEs();
+           field = document.getElementById('hdn'+rteName);
+           if(field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
+               event.preventDefault();
+           }
+       });
+}
+    
\ No newline at end of file