0
votes

In another SO question, this was answered for usage within Blocks (Page selector (block development)). However, how do we apply this within the dashboard for example?

Variable "Concrete" and "ConcreteEvent" seem to be undefined within the admin. What would be the best way to approach this issue?

Example code (using 5.7.x):

Concrete.event.bind('ConcreteSitemap', function(e, instance) {
    Concrete.event.bind('SitemapSelectPage', function(e, data) {
        if (data.instance == instance) {
            Concrete.event.unbind(e);
            alert("You've selected a page! " + data.cID);
        }
    });
});
1
That didn't work either, so I went looking (as it worked for you). I register&require my JS asset with AssetList::getInstance()->register() & $this->requireAsset(). For some reason, these get registered ABOVE events.js, app.js etc. etc. So what I need to find out is, how to move these down (or the other ones up). I put a $this->requireAsset('core/app') before my own requireAsset, but that's just ugly and not the way. Is there a possibility to require my assets after others? - Ramon Leenders
That is really strange, cause in my controller I didn't call any assets at all (except my owns) - but it's in a packeage, maybe that is the reason. 1 moment I test that - toesslab
Ok, you're right: In Single Page it doesn't work, but in a package it does.... sry can't help you - toesslab
My assets are in a package too. They still get loaded before core assets though. It works with the code I posted in the original post and adding the $this->requireAsset('core/app') before my assets though. A workaround for now, but would be nice if someone has the obvious solution for me here! - Ramon Leenders
Ok so in a package it works (for me) without $this->requireAsset('core/app') & window.Concrete.... ... really strange - toesslab

1 Answers

1
votes

It looks like Concrete.event is always loaded in dashboard pages. If you're worried about load order you have a few options.

  1. Make an asset group and put the event js asset first. If you then include the group instead of just the asset concrete5 should manage loading event first.
  2. Use an onload event like jquery's $(function() { ... }). This will fire a little later than you expect, but it will always happen after eventing is loaded.
  3. Set the position of the asset to \Concrete\Core\Asset\Asset::ASSET_POSITION_FOOTER. this will cause your JS to be included in the footer instead of the head allowing the event JS to always load in first

Hope that helps ya