jejacks0n/mercury

Using Javascript to dynamically alter the toolbar (notably, the page history URL)

mpfrenette opened this issue · 2 comments

I have started to implement Mercury in my project and so far, it works incredibly well.

I now want to implement the history tab and I have succeeded provided that I use a static URL.

To use one, I modified the mercury.min.js file, line 109, and modified the line:

historyPanel: ['History', 'Page Version History', { panel: 'MY URL' }],

And it takes my url as the destination.

I am able to read that variable in Javascript, at:

Mercury.config.toolbars.primary.historyPanel[2].panel

Changing it however in javascript post-load has zero effect on the toolbar.

I do realize that the Mercury.config.toolbars variable is most likely only used for the auto-loading of the toolbar and as such, unused once Mercury is loaded.

But how do I do such a manipulation of the toolbar after load or in the

jQuery(window).on('mercury:ready', function()

Event handler.

On a side note, once the history panel is successfully loaded, the history button becomes an on-off toggle and doesn't refresh the panel.

Is there a way to cause a re-load from the toolbar?

Hey, thanks.

I think you can use a function that returns a string -- which allows you to put logic there in the cases where it's different per page.

And second, it only loads it once as an optimization. I don't think there's a way to reload it once it's been loaded, but I'd have to double check.

I'd say you shouldn't reload it on opening anyway, as that doesn't work well if it's already open and changes are made that would cause a reload. I think cmsimple does some stuff with this, but I can't check at the moment. Check github.com/modeset/cmsimple.

Oh, I see what you mean, it's brilliant! Well, you are brilliant... when I saw it was a function, I assumed just something as dummy as urlencode and not a function which generates a custom URL.

I just assumed that because I am not using NODE.js or other non-blocking javascript: I am coding in strict PHP / JS on top of LAMP, any javascript function I write might be cached and as such, it makes it a lot harder to guess the page.

But I never just thought of calling a function NOT in the mercury.min.js file! I guess I was thinking too much like a PHP developer.

Thanks to your hint, I fixed my issue, here is what I did:

I changed the historyPanel line to :

historyPanel: ['History', 'Page Version History', { panel: GetHistoryUrl() }],

And I added in my HTML, before loading my javascript:

<script type="text/javascript">
function GetHistoryUrl(){
return "http://FULLDOMAIN/URL";
}
</script>

This will also take care of a lot of future questions I would have had without this solution.

Mercury rocks! You rock...