Soma

Custom JS in ProcessWire admin

Recommended Posts

Ah, some nice reading to go with my coffee in the morning! Ta, bruv....

  • Like 1

Share this post


Link to post
Share on other sites

...@PapaBear: what the hell is "Ta, bruv...."

@Martijn...your holiday to the UK is long overdue then!!!

  • Like 2

Share this post


Link to post
Share on other sites

"Thankyou Brother"

A bit London, perhaps.....

  • Like 1

Share this post


Link to post
Share on other sites

I had to rewrite some of the tutorial for adding a script in admin.php.

Due to some effect of an installed third party module, the custom script was added after Jquery core js. This usually isn't the case when adding a script via admin.php. I wasn't aware of it at that time and only later remembered that adding a script the way I proposed in admin.php will add our script BEFORE the jquery core script in admin, thus not working when using $ jquery syntax. It's simply because of the order the JS's get added.

After investigating, I found the third party module that was, for some reason, changing this behavior. Reason was: it was loading the JqueryCore in the init() method, thus resulting in my script getting added after JqueryCore. 

I've changed the tutorial to account for this simply by calling the JqueryCore module before adding the custom JS. So instead you would have to do it like this to make sure it gets added after JqueryCore js.

$modules->get('JqueryCore');
$config->scripts->add($config->urls->templates . "scripts/scroll.js");

Sorry for the confusion.

  • Like 2

Share this post


Link to post
Share on other sites

As $config-scripts is a wire array objekt wouldnt it be easier to use :

    WireArray::prepend()
    WireArray::append()

to controll if the new script is loaded first or last ?

Share this post


Link to post
Share on other sites
On 8/24/2018 at 4:07 AM, NorbertH said:

As $config-scripts is a wire array objekt wouldnt it be easier to use :


    WireArray::prepend()
    WireArray::append()

to controll if the new script is loaded first or last ?

I was surprised to find out that these are not WireArray!

https://github.com/processwire/processwire/blob/master/wire/core/FilenameArray.php

Share this post


Link to post
Share on other sites

But still they got an append() and prepend() method ... 

prepend() even seems to remove files that are already in the original array , maybe that would be a nice feature for append () too?

Maybe even an option to add custom keys , not just those md5 strings maybe like add($filename, $customkey).

That would allow to make a method to add after a certain key like addAfter ($filename, $customkey, $afterkey).

That would make it possible to add scripts in an nicely defined order.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.