Jump to content

Custom JS in ProcessWire admin


Soma
 Share

Recommended Posts

  • 2 weeks later...

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
Link to comment
Share on other sites

  • 1 month later...
  • 4 years later...
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

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...