Both ways are possible but rather hacky from by point of view, especially setTimeout
is popular for doing such things quick’n’dirty (I tend to do those things too often by the way ;)). The best solution (as far as I know) would be to have a separate function which is triggered twice, after the document is ready and after the save was done (= the page was re-rendered). Usually this is done by special events, but as I said, I don’t really know how the panel fields are working, and therefore I also don’t know how to bind the events correctly.
Just as an example from sites using PJAX: here, PJAX triggers the custom event ‘pjax:complete’ after a successful ajax call, so you could bind the function to this event:
var pageReload = function(){
// everything which should run after a new page call – as local bindings in the newly rendered area for example
};
$(document).ready(function(){
// do other things like initializing PJAX
// call pageReload on instant load
pageReload();
});
// call pageReload after every complete ajax call with PJAX
$(document).on('pjax:complete', pageReload);
There should be some kind of similar event in Kirby which is triggered after the re-rendering of a page.