JonasDoebertin / kirby-visual-markdown

Visual Markdown Editor for Kirby CMS 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dupolicated VM Editor after click on URL-Appendix on Kirby 2.2.1

isaactopo opened this issue · comments

commented

Hi, I updated to Kirby 2.2.1 and I'm experimenting a “VM top-bar” duplication every time I click on the new link on the bottom of Title to change URL-Appendix:

captura de pantalla 2015-11-18 a la s 10 55 22 2

I tested this on Firefox and Chrome.

image

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;

  1. Create a structure field.
  2. Create a (default) markdown field.
  3. Add a new entry to the structure field.
  4. Click cancel (clicking okay works fine).
  5. You now have a duplicate markdown field (both buttons, and content).
  6. 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.

HI Jonas, I can now see the text and the toolbar, but there are a couple of issues (Firefox Mac)

  1. The help menu disappears behind the text.

screen shot 2015-11-24 at 10 35 56

2. The header toolbar does not seem sticky? e.g. it scrolls off the top of the screen. Let me know if you want any more information.

Thanks for your insights.

  1. I'm able to reproduce that. Will be fixed.
  2. 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?
  1. Cool
  2. Sorry I misunderstood, I can confirm that when focussed it is sticky, nice idea!
    No other problems so far.

Just tried the developers branche in Kirby 2.2.2 - the error is still there.

image

Reproduce

  • Go to a page with the Markdown Field
  • Open a modal (e.g. when changing the URL slug)
  • Press cancel on the modal
  • The content of the Markdown Field is magically doubled

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?

@JonasDoebertin

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!

commented

Working perfect, thanks @JonasDoebertin !