Spica Posted March 20, 2015 Share Posted March 20, 2015 I wonder about behavior of module as this: <?php class JqueryFooTable extends ModuleJS { public static function getModuleInfo() { return array( 'title' => 'JqueryFooTable', 'version' => 1, 'summary' => 'jQuery plugin to make HTML tables responsive', 'href' => 'http://fooplugins.com/plugins/footable-jquery/', 'icon' => 'smile-o', 'singular' => true, 'autoload' => false, ); } public function init() { $this->config->scripts->append($this->config->urls->siteModules . "JqueryFooTable/footable.js"); $this->config->scripts->append($this->config->urls->siteModules . "JqueryFooTable/footable.filter.js"); } } I'd expected JqueryFooTable.js to be autoloaded. But with the init function it doesnt, only without init. Is this a proper way to additionaly load js plugins? Link to comment Share on other sites More sharing options...
Wanze Posted March 20, 2015 Share Posted March 20, 2015 The ModuleJS::init() takes care of loading those scripts if they have the same name as your module, so you don't need to overwrite this method. Edit: If you need to append additional JS/CSS, call parent::init() first 4 Link to comment Share on other sites More sharing options...
adrian Posted March 20, 2015 Share Posted March 20, 2015 I don't think it is always that simple - it depends on what your module extends. In your case you are extending ModuleJS so you'll be fine with Wanze's solution, but just wanted to mention it. From Ryan (https://processwire.com/talk/topic/1416-inputfieldmodule-doesnt-autoload-their-jscss/?p=12789) Any modules that extend: Inputfield, Process or ModuleJS will auto-load their CSS/JS files if they have the same name as the module and appear in the same directory. However, in order for that to work, their init() method has to be called. So if your module extends one of those, and has an init() method, then make sure to call the parent init() method: You should also read this blog post by soma: http://soma.urlich.ch/posts/custom-js-in-processwire-admin/ 2 Link to comment Share on other sites More sharing options...
Spica Posted March 20, 2015 Author Share Posted March 20, 2015 Adding a parent::init(); solved it. <?php class JqueryFooTable extends ModuleJS { public static function getModuleInfo() { return array( 'title' => 'JqueryFooTable', 'version' => 1, 'summary' => 'jQuery plugin to make HTML tables responsive', 'href' => 'http://fooplugins.com/plugins/footable-jquery/', 'icon' => 'smile-o', 'singular' => true, 'autoload' => false, ); } public function init() { parent::init(); $this->config->scripts->append($this->config->urls->siteModules . "JqueryFooTable/footable.js"); $this->config->scripts->append($this->config->urls->siteModules . "JqueryFooTable/footable.filter.js"); } } 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now