Dupolicated VM Editor after click on URL-Appendix on Kirby 2.2.1
isaactopo opened this issue · comments
This is also happening when using the default structure field, so it has to do something with the modal (which is triggered by both the url-slug and the structured-field).
Things to reproduce;
- Create a structure field.
- Create a (default) markdown field.
- Add a new entry to the structure field.
- Click cancel (clicking okay works fine).
- You now have a duplicate markdown field (both buttons, and content).
- You can also try to delete a structure field and click cancel - (the button-bar and the text-content will show up as a new duplicate inside the markdown-area).
- update -
I also tried the developers version;
https://github.com/JonasDoebertin/kirby-visual-markdown/tree/develop
But this branche doesn't work at all with Kirby 2.2.1
It does not show any buttons and the height of the text-area is not adjusted.
Also it throws a Javascript-error in the console;
Uncaught ReferenceError: CodeMirror is not defined
So maybe this error causes the plug-in to break it's own functions.
Hi guys,
I'm aware that Visual Markdown Editor isn't working with the panel changes in Kirby 2.2 right now. Unfortunately, it will take me another few days to get to tackle the issues you noticed.
Note: The develop
branch shouldn't be used, especially not in production, as it may contain unstable or partly broken states at any times.
Is there any news on this? I appreciate you are very busy, but I guess lots of people have sites they want to upgrade to Kirby 2.2.2, but cannot because they use this plugin?
Could you give the current version on the develop
branch a spin? It should fix all Kirby 2.2 related issues and introduce some more fixes. Here's what's new.
Thanks for your insights.
- I'm able to reproduce that. Will be fixed.
- The toolbar was changed to be sticky only if the field is focussed. Once you focus the field the toolbar should appear. Can you confirm this? Do you see any JS errors in the console?
- Cool
- Sorry I misunderstood, I can confirm that when focussed it is sticky, nice idea!
No other problems so far.
Okay, maybe a quick fix.
I downloaded the developers-branche
and changed this file;
site/fields/markdown/assets/js/visualmarkdownfield.js
I changed line #290 with the function below. It's quick and dirty - but it works (as a work around).
It simply checks if the Markdown Field already has a toolbar... if not; it fires the field, if it has a toolbar, it skips the function for this field and goes on to the next field.
I debugged and coded it in 5 minutes, so it may be not an official solution - but at least I can update to Kirby 2.2.2
$.fn.markdownfield = function()
{
if(!$(this).parent().find('ul.visualmarkdown-toolbar').length)
{
return new VisualMarkdownField($,this);
}
};
From what I found out this happens when a modal is closed without the panel page being reloaded (eg. you cancel a modal window). It seems as if the panel reruns the field initialization code when this happens were it clearly shouldn't.
I implemented a hotfix with 0def1ae.
@1n3JgKl9pQ6cUMrW @isaactopo Could you checkout if this solves your issue?
I tried the developers-branche and can confirm "canceling" a modal is not affecting the content of the Markdown Field - so the fix works.
It looks like my own fix (see message above) but yours' more elegant :)
It looks like Kirby is (re-)loading / (re-firing) the assets when you cancel a model. It also effects other plugins, so I'm not sure this is done by design or a bug...
I initialize my field the way Bastian recommended;
https://forum.getkirby.com/t/kirby-2-2-how-to-check-if-panel-is-loaded/2530
...but canceling the modal does fire them twice - so I have to check them the same way you did.
Thanks for pointing me in the right direction!
Seems like this issue is fixed now so I'm closing it.
Please let me know if it ever happens again!
Great, thanks for your hard work!
Working perfect, thanks @JonasDoebertin !