Advertisement:

Author Topic: How can I get/write text in textarea of smc editor?  (Read 1382 times)

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 966
  • Gender: Male
How can I get/write text in textarea of smc editor?
« on: December 23, 2017, 07:43:23 AM »
Some of my mods needs
- count characters using javascript when I write something in textarea of smc editor (for example, in post or PM) or
- write one character in textarea of smc editor.

I test with SMF 2.1 Beta 3 with I can not do this.

I add some alert(n) in events of smc editor
Code: (Themes/default/GenericControls.template, line 27) [Select]
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" cols="600" onselect="storeCaret(this); alert(1);" onclick="storeCaret(this); alert(2);" onkeyup="storeCaret(this); alert(3);" onchange="storeCaret(this); alert(4);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], ';', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '"', !empty($context['editor']['required']) ? ' required' : '', '>', $editor_context['value'], '</textarea>
but I do not see any alert. :(

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,497
    • Arantor on GitHub
Re: How can I get/write text in textarea of smc editor?
« Reply #1 on: December 23, 2017, 09:26:22 AM »
Read the editor's documentation: https://www.sceditor.com/api/
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 966
  • Gender: Male
Re: How can I get/write text in textarea of smc editor?
« Reply #2 on: December 23, 2017, 10:01:42 AM »

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 966
  • Gender: Male
Re: How can I get/write text in textarea of smc editor?
« Reply #3 on: December 23, 2017, 03:54:03 PM »
I found methods in order to do this
Code: [Select]
$("#', $editor_id, '").data("sceditor").insertText("Text to insert"); // Insert a text.
$("#', $editor_id, '").data("sceditor").val().length; // Length of text.

Now I want to do this when happend an event (for example, key press) but do not work:
Code: [Select]
// Only one event.
$("#', $editor_id, '").data("sceditor").keyPress(function() {
alert("Key press event fired.");
});

// Various events.
$("#', $editor_id, '").data("sceditor").bind("keyup keydown keypress blur focus valuechange pasteraw paste", function() {
alert("Any event fired.");
});

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 966
  • Gender: Male
Re: How can I get/write text in textarea of smc editor?
« Reply #4 on: December 24, 2017, 12:41:32 PM »
I have another problem with SC Editor of SMF 2.1! This topic should be changed to "Problems with SC Editor WYSIWYG". :(

I do not know if this is a bug.

My mod BBCode with style https://custom.simplemachines.org/mods/index.php?mod=2505 adds the possibility to use CSS styles, CSS classes and some attributes like HTML in BBC tags.

Adds two BBC tags (similar to HTML) with style and class attributes:
Code: [Select]
[div style="" class=""]Paragraph with style[/span]
[span style="" class=""]Characters with style[/span]
Adds an icon for each to SC Editor and works fine (in text mode, of course).

But my mod also adds some attributes to some BBC tags, for example:


If I write this in a new post
Code: [Select]
[list style="color: red; border: 3px inset red;"]
[li style="color: blue; border: 3px inset blue;"]Item 1[/li]
[li]Item 2[/li]
[/list]
I can preview and save, and all is correct. I can use Quick edit button and I see this text, all works.

But... If I use Modify option, I see the original text (textarea of editor contains original text) at begining (a few seconds) and after SC Editor remove all custom attributes and display this:
Code: [Select]
[list]
[li]Item 1[/li]
[li]Item 2[/li]
[/list]
I can not save this because I will loose all style. :(

Offline Steve

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,268
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: How can I get/write text in textarea of smc editor?
« Reply #5 on: December 25, 2017, 02:34:28 PM »
I think that's more of a mod issue than a problem with 2.1 so it should be posted in the mod's support thread. :)
Online Manual

Please do not PM me for support.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,497
    • Arantor on GitHub
Re: How can I get/write text in textarea of smc editor?
« Reply #6 on: December 25, 2017, 02:46:15 PM »
I think that's more of a mod issue than a problem with 2.1 so it should be posted in the mod's support thread. :)

Considering that this thread was opened by the mod author to ask how to make his own mod compatible with 2.1, I doubt the mod thread will be of any use...

I haven't worked with the editor in a while but I think you'd need to specifically tell it to preserve inline styles, it normally strips them out because it itself doesn't use them. Take a look at the bbcode addon that we wrote on top of SCEditor. I also think SCEditir isn't totally up to date in 2.1 and this is one place that targeting anything below beta 3 is a hugely bad idea.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline davidhs

  • Sr. Member
  • ****
  • Posts: 966
  • Gender: Male
Re: How can I get/write text in textarea of smc editor?
« Reply #7 on: December 25, 2017, 04:38:50 PM »
I think that's more of a mod issue than a problem with 2.1 so it should be posted in the mod's support thread. :)

Considering that this thread was opened by the mod author to ask how to make his own mod compatible with 2.1, I doubt the mod thread will be of any use...

I haven't worked with the editor in a while but I think you'd need to specifically tell it to preserve inline styles, it normally strips them out because it itself doesn't use them. Take a look at the bbcode addon that we wrote on top of SCEditor. I also think SCEditir isn't totally up to date in 2.1 and this is one place that targeting anything below beta 3 is a hugely bad idea.
Really I do not want do my mods compatible with SC Editor mod on SMF 2.0.
I want adapt my mods to SC Editor used by SMF 2.1.

Perhaps problem is the SC Editor of SMF 2.1 is not finished... (I do not know!) and then my mods can not support SMF 2.1 yet. :o

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,497
    • Arantor on GitHub
Re: How can I get/write text in textarea of smc editor?
« Reply #8 on: December 25, 2017, 04:42:07 PM »
The SCEditor in 2.1 is taken from SCEditor.com, it's literally not written by the SMF team (the SC stands for Sam Clarke, its author)

The version in 2.1 betas 1 and 2 is older than the one in beta 3, but that's probably not been updated to current SCEditor lately.

Also I wasn't trying to suggest that you support the 2.0 mod, I was just trying to discourage you from trying to support beta 1 or beta 2 since I know you have a habit of trying to support people on older versions rather than trying to do them, you and everyone else a favour by getting them to upgrade already.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Steve

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,268
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: How can I get/write text in textarea of smc editor?
« Reply #9 on: December 25, 2017, 06:15:15 PM »
Considering that this thread was opened by the mod author to ask how to make his own mod compatible with 2.1, I doubt the mod thread will be of any use...

Whoops ... should have read the original post again. Sorry about that.
Online Manual

Please do not PM me for support.