getkirby-v2 / panel

This is the deprecated admin panel for Kirby v2.
http://getkirby.com
Other
133 stars 71 forks source link

Field javascript initialization callback doesn't run properly #435

Closed JonasDoebertin closed 8 years ago

JonasDoebertin commented 9 years ago

I am working on my Visual Markdown Editor extension right know, and came across a bug (JonasDoebertin/kirby-visual-markdown#19) which prevents the initialization of the editor to run on some panel page loads.

I have implemented my initialization method like @bastianallgeier mentioned in #228.

$.fn.markdownfield = function() {
    return new VisualMarkdownField($, this);
};

However, sometimes when loading a page in the panel directly (eg. by hitting refresh in the browser) without visiting any other panel page first, the panel fails to initialize the editor.

form.find('[data-field]').each(function() {
    var el  = $(this);
    var key = el.data('field');
    if(el[key]) el[key]();
});

After some debugging, it appears that the above code from panel.js (Line 777) that checks for the data-field="markdown" attribute of the input element and calls the initialization callback runs before the above mentioned code that defines the callback has been executed. Thus, the callback isn't been called.

If you visit any other panel page afterwards and then come back to the page you first visited (without leaving the panel), the callback get's called as expected.

Note: Tested with the latest develop version.

JonasDoebertin commented 9 years ago

It should be noted that I have not experienced this issue with any other extension I made before and that I do not experience it when testing on localhost. It only happens when Kirby runs on an external server.

I guess the reason for that is that the Visual Markdown Editor embeds CodeMirror, which is a lot of code that has to be executed before the interpreter even reaches the point where the callback is being defined.

Maybe a possible solution would be to include the panel.js and main.js resources after all the embedded JS code instead of before?

distantnative commented 8 years ago

Is this still present in the 2.2 beta?

JonasDoebertin commented 8 years ago

Haven't experienced the issue in 2.2 so far. I must admit I did not have a look at the new Panels JS code so far, so I can't really tell if this is coincidence or not.

bastianallgeier commented 8 years ago

I will close this for now. The new panel js should handle this more reliably in general. Please let me know if it appears ever again.