Jump to content


Photo

Javascript load order problem


  • Please log in to reply
3 replies to this topic

#1 Rob

Rob

    Sr. Member

  • Members
  • PipPipPipPip
  • 122 posts
  • 34

  • LocationLondon, UK

Posted 02 August 2012 - 06:55 AM

I am having a problem with my module code that seems to be loading my module JS code BEFORE the JQuery libraries and therefore I am getting a '$ is not defined' error.

The weird thing is that I have used the exact same module code in a previous module and it loaded the module JS AFTER the JQuery so it worked fine, but in this case it is not working.

public function init() {
  parent::init();

  // add necessary admin page scripts
  // ---------------------------------------------------------------------------------
  $this->config->styles->append( $this->config->urls->ProcessTestSearch . "css/demo_table.css" );
  $this->config->styles->append( $this->config->urls->ProcessTestSearch . "css/demo_table_jui.css" );
  $this->config->scripts->append( $this->config->urls->ProcessTestSearch . "js/dataTables/jquery.dataTables.min.js");
  //$this->config->scripts->append( $this->config->urls->ProcessTestSearch . "js/dataTables/dataTables.fnSetFilteringDelay.js" );
  $this->config->scripts->append( $this->config->urls->ProcessTestSearch . "ProcessTestSearch.js" );
}

Is there something I am doing wrong? Is there some way to control the order in which modules output the JS script links into the header? I presume this must be happening because, for some reason, the core JQuery module is being loaded after my module, and so therefore the scripts are being added after my module scripts.

#2 Soma

Soma

    Hero Member

  • Moderators
  • 3,186 posts
  • 1743

  • LocationSH, Switzerland

Posted 02 August 2012 - 06:57 AM

No, there's no way to exactly define order, but if done right it should load after jquery core.

Can you show full module code? It depends on more than just the init. What type etc...

Edit:
Also see here : http://processwire.c...ripts#entry5950

And here : http://processwire.c...append +scripts

And here : http://processwire.c...ripts#entry5741

@somartist | modules created | support me, flattr my work flattr.com


#3 Rob

Rob

    Sr. Member

  • Members
  • PipPipPipPip
  • 122 posts
  • 34

  • LocationLondon, UK

Posted 02 August 2012 - 07:10 AM

Thanks Soma.

Turns out it was the autoload status which had originally, by accident, been set to true and despite changing it back to false the code it was saved in the DB. I have changed it in the DB and now it seems to work.

#4 Soma

Soma

    Hero Member

  • Moderators
  • 3,186 posts
  • 1743

  • LocationSH, Switzerland

Posted 02 August 2012 - 07:13 AM

You can also uninstall, change and install to change it. It doesn't change DB when only changing module code "autoload" => false,

@somartist | modules created | support me, flattr my work flattr.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users