Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

AJAX page load event for /admin/pages/edit/show/ pages?


Go to End


3 Posts   2133 Views

Avatar
Rory

Community Member, 5 Posts

19 March 2015 at 8:23pm

Edited: 09/04/2015 8:47pm

Hi guys,

I've tried to fire off some JavaScript on edit page load, e.g. http://www.mysite.com/admin/pages/edit/show/123?locale=en_GB, like this:

(function($) {
    $(document).ready(function() {
        alert("I'm ready!!");
    });
})(jQuery);

But this only works when doing a full page load, not with the usual SilverStripe AJAX page loading, i.e. after selecting a page in the site tree view. The reason is documented here:

http://doc.silverstripe.org/en/developer_guides/customising_the_admin_interface/cms_architecture#ajax-loading-and-browser-history

But I was wondering if anyone knew a solution. My SilverStripe installation version is Framework: 3.1.8, CMS: 3.1.8. What is the appropriate event that will work with the AJAX page load?

Thanks,

Avatar
Pyromanik

Community Member, 419 Posts

20 March 2015 at 11:25pm

Avatar
Rory

Community Member, 5 Posts

9 April 2015 at 8:41pm

Edited: 09/04/2015 8:47pm

Wow, thank you, Pyromanik. You helped me find the solution!

Sorry I didn't see your post for a while. I assumed I'd get an email update on this post by default as author - I didn't realise I had to subscribe.

This is the solution that worked for me in the end, in case anyone else finds it useful. Credit to Pyromanik.

(function($) {
    $.entwine(function($) {
        $('.my-custom-class').entwine({
            onmatch: function() {
                alert("I'm ready!!");
            }
        });
    });
})(jQuery);

I found that implementing this somewhat broke the previous full page loading method, however... well not really - you see - the code ran, but the styling on the page needed a refresh for some reason. Additionally adding in the required styling refresh on an ajaxComplete fixed this issue.

// Refresh on full page load to ensure handle displays
$(document).ajaxComplete(function() {
    $('.my-custom-class').css('...');
});