Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] wstawianie tekstu do textarea z tinymce
dentopolis
post
Post #1





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


mam textarea z tinymce.działa.
drugi skrypt stąd: js bin działa.
ale przestaje działać gdy połączę obydwa czyli gdy <textarea id='textbox'></textarea>

jak mogę to poprawić?

Ten post edytował dentopolis 3.06.2017, 19:40:52
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 12)
Niree
post
Post #2





Grupa: Zarejestrowani
Postów: 220
Pomógł: 18
Dołączył: 5.02.2016
Skąd: Polska

Ostrzeżenie: (0%)
-----


Kliknij sobie prawym na tinyemce i pobierz identyfikator pola, w którym znajduje się tekst. Edytory działają tak, że tworzą nam zamiast textarea jakieś divy i inne cuda. Dlatego jak określiłeś identyfikator "textarea", to nie ma znaczenia, bo tekst musi być wstrzyknięty do kontenera edytora.
Go to the top of the page
+Quote Post
dentopolis
post
Post #3





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


tinymce nadaje polu textarea id="tinymce", jednak gdy zmieniłem w kodzie na takie id to nadal nie działa:

  1. <textarea id='tinymce'></textarea>
  2.  
  3. <script>
  4. var tinymce = document.getElementById('tinymce');
  5. var procedury = document.getElementById('procedury');
  6. // add one event handler to the table
  7. procedury.onclick = function (e) {
  8. // normalize event
  9. e = e || window.event;
  10. // find out which element was clicked
  11. var el = e.target || e.srcElement;
  12. // check if it's a procedury cell
  13. if (el.nodeName.toUpperCase() == "TD") {
  14. // append it's content to the tinymce
  15. tinymce.value += (el.textContent || el.innerText);
  16. }
  17. }
  18. </script>
Go to the top of the page
+Quote Post
Niree
post
Post #4





Grupa: Zarejestrowani
Postów: 220
Pomógł: 18
Dołączył: 5.02.2016
Skąd: Polska

Ostrzeżenie: (0%)
-----


Ty w ogóle nie ogarniasz co się do Ciebie pisze. Kliknij prawym na tinymce i zobacz w kod HTML, tam nie ma tylko textarea. Skrypt tinymce dodał własne iframki i divy.
To czego szukasz to klasa "mce-content-body"

Użyj jquery do wstrzyknięcia tekstu:

  1. var tinymce = $( ".mce-content-body" );
  2. var procedury = document.getElementById('procedury');
  3. // add one event handler to the table
  4. procedury.onclick = function (e) {
  5. // normalize event
  6. e = e || window.event;
  7. // find out which element was clicked
  8. var el = e.target || e.srcElement;
  9. // check if it's a procedury cell
  10. if (el.nodeName.toUpperCase() == "TD") {
  11. // append it's content to the tinymce
  12. //tinymce.value += (el.textContent || el.innerText);
  13. tinymce.append(el.textContent);
  14. }
  15. }


Ten post edytował Niree 3.06.2017, 21:42:47
Go to the top of the page
+Quote Post
dentopolis
post
Post #5





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


sorry za brak zrozumienia, staram się na ile mogę, ale programowanie to nie moja dziedzina. jaką funkcją mam "wstrzyknąć" ten tekst do pola?

Ten post edytował dentopolis 3.06.2017, 21:57:17
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. tinyMCE.activeEditor.execCommand('mceInsertContent', false, "tekst do wstawienia w pozycji kursora");
Go to the top of the page
+Quote Post
dentopolis
post
Post #7





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


super.działa.dzięki.

  1. <script>
  2. var tinymce = $( ".mce-content-body" );
  3. var procedury = document.getElementById('procedury');
  4. // add one event handler to the table
  5. procedury.onclick = function (e) {
  6. // normalize event
  7. e = e || window.event;
  8. // find out which element was clicked
  9. var el = e.target || e.srcElement;
  10. // check if it's a procedury cell
  11. if (el.nodeName.toUpperCase() == "TD") {
  12. // append it's content to the tinymce
  13. //tinymce.value += (el.textContent || el.innerText);
  14. // tinymce.append(el.textContent);
  15. tinyMCE.activeEditor.execCommand('mceInsertContent', false, (el.textContent));
  16. }
  17. }
  18. </script>



ten kod powyżej działa jeśli chcę kliknąć tekst w komórce tabeli, ale jak powinien wyglądać jeśli tekst jest np.w divie po prostu oddzielany przecinkami np. badanie, przegląd, konsultacja?

Ten post edytował dentopolis 18.06.2017, 21:25:59
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Wstaw je do osobnych elementów, np. <span>, albo do <li> (wtedy nie <div> a <ul>). Przecinki ustaw za pomocą pseudoselektora ::after.

Ten post edytował trueblue 18.06.2017, 21:35:07
Go to the top of the page
+Quote Post
dentopolis
post
Post #9





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


a mogę prosić o pomoc w samym kodzie?
rozumiem że sam tekst ma wyglądać tak:<span class="leczenie">test1</span>, <span class="leczenie">test2</span>
Go to the top of the page
+Quote Post
trueblue
post
Post #10





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


https://stackoverflow.com/questions/1763604...s-to-list-items
Go to the top of the page
+Quote Post
dentopolis
post
Post #11





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


próbuję tak:
  1. <div id="leczenie">
  2. <span>Item A</span>
  3. <span>Item B</span>
  4. </div>
  5. <script type="text/javascript">
  6. // locate your element and add the Click Event Listener
  7. document.getElementById("leczenie").addEventListener("click",function(e) {
  8. // e.target is our targetted element.
  9. // try doing console.log(e.target.nodeName), it will result LI
  10. if(e.target && e.target.nodeName == "span") {
  11. console.log(e.target.id + " was clicked");
  12. }
  13. });
  14. </script>


jak dotąd nie działa, ale tak czy inaczej potrzebuję, żeby kliknięty tekst nie wyskakiwał w konsoli ale był dodany do mojego tinymce (kod powyżej)
Go to the top of the page
+Quote Post
trueblue
post
Post #12





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


SPAN nie span.
Go to the top of the page
+Quote Post
dentopolis
post
Post #13





Grupa: Zarejestrowani
Postów: 252
Pomógł: 0
Dołączył: 14.08.2016

Ostrzeżenie: (0%)
-----


<div id="leczenie">
<span>Item A</span>
<span>Item B</span>
</div>
<script type="text/javascript">
// locate your element and add the Click Event Listener
document.getElementById("leczenie").addEventListener("click",function(e) {
// e.target is our targetted element.
// try doing console.log(e.target.nodeName), it will result LI
if(e.target && e.target.nodeName == "SPAN") {
console.log(e.target.id + " was clicked");
}
});
</script>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 19:25