openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

editor.min.js (1873B)


      1 
      2 // Quelle:
      3 // http://aktuell.de.selfhtml.org/tippstricks/javascript/bbcode/
      4 function insert(tagName, aTag, eTag)
      5 {
      6   var input = document.forms[0].elements[tagName];
      7   input.focus();
      8   /* IE */
      9   if(typeof document.selection != 'undefined') {
     10     /* Einfuegen des Formatierungscodes */
     11 //    alert('IE');
     12     var range = document.selection.createRange();
     13     var insText = range.text;
     14     range.text = aTag + insText + eTag;
     15     /* Anpassen der Cursorposition */
     16     range = document.selection.createRange();
     17     if (insText.length == 0) {
     18       range.move('character', -eTag.length);
     19     } else {
     20       range.moveStart('character', aTag.length + insText.length + eTag.length);      
     21     }
     22     range.select();
     23   }
     24   /* Gecko */
     25   else if(typeof input.selectionStart != 'undefined')
     26   {
     27 //    alert('Gecko');
     28     /* Einfuegen des Formatierungscodes */
     29     var start = input.selectionStart;
     30     var end = input.selectionEnd;
     31     var insText = input.value.substring(start, end);
     32     input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
     33     /* Anpassen der Cursorposition */
     34     var pos;
     35     if (insText.length == 0) {
     36       pos = start + aTag.length;
     37     } else {
     38       pos = start + aTag.length + insText.length + eTag.length;
     39     }
     40     input.selectionStart = pos;
     41     input.selectionEnd = pos;
     42   }
     43   /* uebrige Browser */
     44   else
     45   {
     46     /* Abfrage der Einfuegeposition */
     47     
     48     /*
     49     var pos;
     50     var re = new RegExp('^[0-9]{0,3}$');
     51     while(!re.test(pos)) {
     52       pos = prompt("Position (0.." + input.value.length + "):", "0");
     53     }
     54     if(pos > input.value.length) {
     55       pos = input.value.length;
     56     }
     57 	*/
     58     pos = input.value.length;
     59     
     60     /* Einfuegen des Formatierungscodes */
     61     var insText = prompt("Text");
     62     input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
     63   }
     64 }