Diff for /loncom/interface/lonhtmlcommon.pm between versions 1.358 and 1.359

version 1.358, 2014/12/20 15:35:40 version 1.359, 2015/03/31 13:46:01
Line 1306  sub htmlareaselectactive { Line 1306  sub htmlareaselectactive {
     }      }
           
     function startRichEditor(id) {      function startRichEditor(id) {
           // fix character entities inside <m>
           // NOTE: this is not fixing characters inside <parse>
           var ta = document.getElementById(id);
           var value = ta.value;
           var in_m = false; // in the m element
           var in_text = false; // in the text inside the m element
           var im = -1; // position of <m>
           var it = -1; // position of the text inside
           for (var i=0; i<value.length; i++) {
               if (value.substr(i, 2) == "<m") {
                   // ignore previous <m> if found twice
                   in_m = true;
                   in_text = false;
                   im = i;
                   it = -1;
               } else if (in_m) {
                   if (!in_text) {
                       if (value.charAt(i) == ">") {
                           in_text = true;
                           it = i+1;
                       }
                   } else if (value.substr(i, 4) == "</m>") {
                       in_m = false;
                       var text = value.substr(it, i-it);
                       var l1 = text.length;
                       text = text.replace(/</g, "&lt;");
                       text = text.replace(/>/g, "&gt;");
                       var l2 = text.length;
                       value = value.substr(0, it) + text + "</m>" + value.substr(i+4);
                       i = i + (l2-l1);
                   }
               }
           }
           ta.value = value;
     CKEDITOR.replace(id,       CKEDITOR.replace(id, 
     {      {
     customConfig: "/ckeditor/loncapaconfig.js",      customConfig: "/ckeditor/loncapaconfig.js",
Line 1317  sub htmlareaselectactive { Line 1351  sub htmlareaselectactive {
           
     function destroyRichEditor(id) {      function destroyRichEditor(id) {
     CKEDITOR.instances[id].destroy();      CKEDITOR.instances[id].destroy();
           // replace character entities &lt; and &gt; in <m>
           // and "&amp;fctname(" by "&fctname("
           // and the quotes inside functions: "&fct(1, &quot;a&quot;)" -> "&fct(1, "a")"
           var ta = document.getElementById(id);
           var value = ta.value;
           var in_m = false; // in the m element
           var in_text = false; // in the text inside the m element
           var im = -1; // position of <m>
           var it = -1; // position of the text inside
           for (var i=0; i<value.length; i++) {
               if (value.substr(i, 2) == "<m") {
                   // ignore previous <m> if found twice
                   in_m = true;
                   in_text = false;
                   im = i;
                   it = -1;
               } else if (in_m) {
                   if (!in_text) {
                       if (value.charAt(i) == ">") {
                           in_text = true;
                           it = i+1;
                       }
                   } else if (value.substr(i, 4) == "</m>") {
                       in_m = false;
                       var text = value.substr(it, i-it);
                       var l1 = text.length;
                       text = text.replace(/&lt;/g, "<");
                       text = text.replace(/&gt;/g, ">");
                       var l2 = text.length;
                       value = value.substr(0, it) + text + "</m>" + value.substr(i+4);
                       i = i + (l2-l1);
                   }
               }
           }
           // fix function names
           value = value.replace(/&amp;([a-zA-Z_]+)\(/g, "&$1(");
           // fix quotes in functions
           var pos_next_fct = value.search(/&[a-zA-Z_]+\(/);
           var depth = 0;
           for (var i=0; i<value.length; i++) {
               if (i == pos_next_fct) {
                   depth++;
                   var sub = value.substring(i+1);
                   var pos2 = sub.search(/&[a-zA-Z_]+\(/);
                   if (pos2 == -1)
                       pos_next_fct = -1;
                   else
                       pos_next_fct = i + 1 + pos2;
               } else if (depth > 0) {
                   if (value.charAt(i) == ")")
                       depth--;
                   else if (value.substr(i, 6) == "&quot;")
                       value = value.substr(0, i) + "\"" + value.substr(i+6);
               }
           }
           // replace the text value
           ta.value = value;
     }      }
           
     function editorHandler(event) {      function editorHandler(event) {

Removed from v.1.358  
changed lines
  Added in v.1.359


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>