Hi,
So I'm developing a custom plugin, and I need to disable a button unless ONLY this element is selected (for example a <h1> tag).
I've been looking through the source code and found that there is code such as this:
Now this does work to a certain extent - If I select a h1 tag either by highlighting or just moving the cursor there it works fine - the problem is when I select other elements around it, for example a list or a blockquote.
I've been reading through the API docs for a couple of days now and cannot get exactly what I want to work, so I'm hoping someone on here can point me in the right direction.
I have also tried doing this:
And running a similar if statement (eg):
However it still doesn't do as I thought it would.
To clarify I only want to enable the button when the ONLY element selected is a h1 tag, if there are other selections involved such as lists, paragraphs,blockquotes bla bla (aka selecting a large part of a post) then I want to disable it. Another thing I may add as well is for example if you want to make a heading bold that is allowed, so child-nested tags are ok, but if the selection is more than just the <h1> tag, then disallow it.
Any help much appreciated, it's driving me mental!
So I'm developing a custom plugin, and I need to disable a button unless ONLY this element is selected (for example a <h1> tag).
I've been looking through the source code and found that there is code such as this:
function onSelectionChange(evt) { var listNodeNames = { h1 : 1 }; var editor = evt.editor, elementPath = evt.data.path, list = elementPath && elementPath.contains( listNodeNames ); if ( list ) return this.setState( CKEDITOR.TRISTATE_OFF ); return this.setState( CKEDITOR.TRISTATE_DISABLED ); }
Now this does work to a certain extent - If I select a h1 tag either by highlighting or just moving the cursor there it works fine - the problem is when I select other elements around it, for example a list or a blockquote.
I've been reading through the API docs for a couple of days now and cannot get exactly what I want to work, so I'm hoping someone on here can point me in the right direction.
I have also tried doing this:
var badListNodeNames = { ul : 1, ol : 1, li : 1 }; var badList = elementPath && elementPath.contains( badListNodeNames );
And running a similar if statement (eg):
if ( list && !badList)
However it still doesn't do as I thought it would.
To clarify I only want to enable the button when the ONLY element selected is a h1 tag, if there are other selections involved such as lists, paragraphs,blockquotes bla bla (aka selecting a large part of a post) then I want to disable it. Another thing I may add as well is for example if you want to make a heading bold that is allowed, so child-nested tags are ok, but if the selection is more than just the <h1> tag, then disallow it.
Any help much appreciated, it's driving me mental!