Jump to content
php.lv forumi
  • 0

Izveidot textarea editoru


Question

Posted

Vajadzētu uztaisīt custom bbcode paneli.

Uzspied pimēram ikonu <b>, atveras logs, ieraksti tekstu un spied pievienot. Ievadītais teksts parādas textarea.

Zinu ka ir tie editori, bet gribētos kautko tādu kā aprakstiju, jo citreiz ar roku ievadu <b>teksts</b>.

Tādā gadijumā ja nemaldos tie editori vienkārši parāda to "<b>teksts</b>" nevis "teksts" .

6 answers to this question

Recommended Posts

  • 0
Posted

Pasaki cenu, tad pateikšu vai esmu gatavs!

No tevis paris alinji, par to ka samekleju savos arhiivos ;)

<html>
<body>
<script>
 function codeinsert(tag,elementa_id) {
      var elem = document.getElementById(elementa_id);
      elem.focus();

      if (typeof document.selection != "undefined") {
          var range = document.selection.createRange();
          range.text = "[" + tag + "]" + (tag=="URL"||tag=="IMG"?"http://":"") +
                       range.text + "[/" + tag + "]";  
          range.move("character", -tag.length-3);
          range.select();
      } else if (typeof elem.selectionStart != "undefined") {
          var startPos = elem.selectionStart;
          var endPos = elem.selectionEnd;
          var myValue = "[" + tag + "]" + (tag=="URL"||tag=="IMG"?"http://":"") +
                        elem.value.substring(startPos ,endPos) + "[/" + tag + "]";  

          elem.value = elem.value.substring(0, startPos) +
                       myValue +
                       elem.value.substring(endPos, elem.value.length);
          var x = startPos + myValue.length - tag.length - 3;
          elem.setSelectionRange(x, x);
      } else {
          elem.value += "[" + tag + "]" + (tag=="URL"||tag=="IMG"?"http://":"") + "[/" + tag + "]";
      }
  }
  </script>

  <a href="JavaScript:void(0)" onclick="codeinsert('i','apraksts') ;return false;">I</a>  
  <a href="JavaScript:void(0)" onclick="codeinsert('b','apraksts') ;return false;">B</a>  
  <a href="JavaScript:void(0)" onclick="codeinsert('URL','apraksts') ;return false;">URL</a>
  <br>
   <textarea  name="apraksts" id="apraksts"></textarea>

tagus pats sliksi kadus vajadzees ...

P.S. sen atpaklj JS dalju samekleju sheit pat foruma.

  • 0
Posted

paldies tev, parakajos pa googli un atradu šo te

 

<script language="javascript" type="text/javascript"> 

function addText(Text,Message) 
{ 
 var obj = document.form.message; 

 obj.focus(); 

 if (document.selection && document.selection.createRange)  // Internet Explorer 
 { 
sel = document.selection.createRange(); 
if (sel.parentElement() == obj)  sel.text = Text; 
 } 

 else if (typeof(obj) != "undefined")  // Firefox 
 { 
var longueur = parseInt(obj.value.length); 
var selStart = obj.selectionStart; 
var selEnd = obj.selectionEnd; 

obj.value = obj.value.substring(0,selStart) + Text + obj.value.substring(selEnd,longueur); 
 } 

 else obj.value += Text; 

 obj.focus(); 
} 


function addTags(Tag,fTag,Message) 
{ 
 var obj = document.form.message; 

 obj.focus(); 

 if (document.selection && document.selection.createRange)  // Internet Explorer 
 { 
sel = document.selection.createRange(); 
if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag; 
 } 

 else if (typeof(obj) != "undefined")  // Firefox 
 { 
var longueur = parseInt(obj.value.length); 
var selStart = obj.selectionStart; 
var selEnd = obj.selectionEnd; 

obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur); 
 } 

 else obj.value += Tag + fTag; 

 obj.focus(); 
} 

</script>


<form method="post" name="form" action="..."> 

<!-- Bold fonts -->
<a title="Bold : <b></b>" onmousedown="addTags('<b>','</b>')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;"> <b>B</b> </a> 
<a title="Bold : <b></b>" onmousedown="addTags('<a href=','</a>')" style="background-color:#F7F7F7; font-size:10pt; border: outset white 1px;"> <b>Link</b> </a> 
<br>

<!--textarea -->
<textarea wrap="VIRTUAL" name="message" cols="50" rows="10"></textarea> 

</form>

 

Lieta tāda, ka nezinu kā lai ielieku

onmousedown="addTags('<a href=','</a>')"

šo daļu pareizi, ka href="links kad uzmet tagu">NAME</a>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...