Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Darker - tammikuu 19, 2014, 06:37:25 AP

Otsikko: Post editor javascript documentation
Kirjoitti: Darker - tammikuu 19, 2014, 06:37:25 AP
Hi,
I'm trying to mod the post editor behavior using client-side user script. Changes I want to do include:

Ask for url when pressing url button.
Automatically generate preview (on client side)
Keyboard shortcuts (i've noticed that editor has some array for this - how to use it?)
Quote selected (highlighted) sentences from previous posts.

I wonder if the editor javascript is documented somewhere, or if I'm to rely on the comments in the .js file.

Please not that I'm not asking for help with my specific ideas, I'm just looking for some docs, before I start figuring it out on my own.

text bellow is probably gonna change often:

I've found this out so far:

Changing the hotkeys:

smc_Editor.prototype.registerShortcut(string shortcutLetter, string funcKeys, string actionCode)

Functional keys must be in format "ctrl, alt". No other keys are supported. At least one should be present.

Overiding the button events?
This is very confusing for me. Every button in the editor is an image, with a onclick event:
function () {
this.instanceRef.handleButtonClick(this);
};

This means that this shoud refer to the image element. However, the handleButtonClick method accepts an options object as 1st argument. How come that this works? Where is the image element converted to the options object?

Otsikko: Re: Post editor javascript documentation
Kirjoitti: Arantor - tammikuu 19, 2014, 11:37:48 AP
Oh you're going to have so much fun with this, and then do it all again when 2.1 comes out with a completely new editor.

Just for fun the behaviour varies between whether WYSIWYG is enabled or not...
Otsikko: Re: Post editor javascript documentation
Kirjoitti: Darker - tammikuu 19, 2014, 01:28:30 IP
In other words there is no proper way to mod the editor?
Otsikko: Re: Post editor javascript documentation
Kirjoitti: Arantor - tammikuu 19, 2014, 01:40:25 IP
Oh, there's ways to do it but it's a mess because it's undocumented and even we felt it wasn't salvageable which is why 2.1 has a totally different editor.
Otsikko: Re: Post editor javascript documentation
Kirjoitti: emanuele - tammikuu 19, 2014, 02:07:27 IP
Actually 2.1 has a completely different editor because someone decided it was worth wasting a bit of time and implement it, otherwise it would still have the old one. :P
Otsikko: Re: Post editor javascript documentation
Kirjoitti: Arantor - tammikuu 19, 2014, 02:09:21 IP
Compared to trying to fix all the bugs in the old one, the time spent integrating SCEditor was definitely smaller.