[ 4 posts ]

Aamir Kapasi

  • Username: kapman
  • Joined: Tue Mar 27, 2012 1:44 am
  • Posts: 2
  • GitHub: kapman
  • Gists: kapman
  • Offline
  • Profile

nodeChange event in the text editor

Post Posted: Fri Jun 08, 2012 4:20 am
+0-
I'm trying to use the nodeChange event to keep the toolbar i made for the text editor updated.

The "commands" key in the event object really helps me do this but it's undefined whenever i try to access it even though when you log the event object you can see it.
Example - http://jsfiddle.net/aamirkapasi/eVbKg/8/

I read through the editor-base API docs and it seems that the "commands" key is only attached to the event object whenever a command is executed using execComand and that is the only time i'm supposed to see it. It being undefined makes sense now but how i can see it when i just log the event doesn't make any sense.

So basically TL;DR is there anyway i can get the "commands" key or anything similar to that from the nodeChange event or do i simply have to check the changedNode and figure out what styles have been applied to it to keep my toolbar updated (which seems very messy and does not work in some edge cases).

TL;DR TL;DR What is the best way to keep my text editor toolbar updated?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: nodeChange event in the text editor

Post Posted: Fri Jun 08, 2012 6:10 am
+0-
You want the 'after' nodeChange event, not the on:

http://jsfiddle.net/davglass/tuSBH/

What you are seeing is a side effect of the browser logging an object but preserving it's reference and not cloning it (one of my pet peeves against browser debuggers).

When you logged the object, the key wasn't actually there it was added later. But the browser logged a reference to that object, so it appears that it was there, when in fact it was updated after that point in time.

You can see this if you do a `Y.log(Y.merge(event));`, this will clone the object at that time and allow you to print it.

Make sense?

Aamir Kapasi

  • Username: kapman
  • Joined: Tue Mar 27, 2012 1:44 am
  • Posts: 2
  • GitHub: kapman
  • Gists: kapman
  • Offline
  • Profile

Re: nodeChange event in the text editor

Post Posted: Mon Jun 11, 2012 1:27 am
+0-
Hey dav, thanks for replying.

The after nodeChange completely solved my problem and the disappearing key makes sense now but i think i've come across a bug.
The commands loses both the underline and strikethrough keys if both styles are applied on the same text.

http://jsfiddle.net/aamirkapasi/2nZY2/

Is this a bug or does this happen for a particular reason?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: nodeChange event in the text editor

Post Posted: Mon Jun 11, 2012 5:11 am
+0-
Looks like a bug, you should file it and I'll look into it when I can ;)
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum