Jump to content

[1.7] Can't add jquery plugins in the new symfony powered admin pages


Recommended Posts

Hello,

 

I am working on a module and I'm trying to add a small jquery plugin I need for the product page.

 

Using the old method

$this->context->controller->addJs()

the jquery plugins gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded.

 

Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ?

 

 

Otherwise I am forced to inject the file with js which is not cool.

 

 

Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github.

 

 

- mike

Share this post


Link to post
Share on other sites

  • 3 weeks later...

Hello,

 

I am working on a module and I'm trying to add a small jquery plugin I need for the product page.

 

Using the old method

$this->context->controller->addJs()

the jquery plugins gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded.

 

Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ?

 

 

Otherwise I am forced to inject the file with js which is not cool.

 

 

Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github.

 

 

- mike

 

 

Hello,

 

If you try so:

 public function install() {
        parent::install();
        $this->registerHook('actionAdminControllerSetMedia');
        return true;
    }
    public function hookActionAdminControllerSetMedia($params){
        $this->registerStylesheet('module-namemodule-css','modules/namemodule/views/css/namemodule.css');
        $this->registerJavascript('module-namemodule-js','modules/namemodule/views/js/namemodule.js');
    }

Share this post


Link to post
Share on other sites

 

Hello,

 

If you try so:

 public function install() {
        parent::install();
        $this->registerHook('actionAdminControllerSetMedia');
        return true;
    }
    public function hookActionAdminControllerSetMedia($params){
        $this->registerStylesheet('module-namemodule-css','modules/namemodule/views/css/namemodule.css');
        $this->registerJavascript('module-namemodule-js','modules/namemodule/views/js/namemodule.js');
    }

Unfortunately in AdminController there is not registerJavascript. Only in FrontController.

Share this post


Link to post
Share on other sites

Hi everyone:

 

To BackOffice try this:

public function hookBackOfficeHeader(){    if (Tools::getValue('configure') == $this->name || Tools::getValue('module_name') == $this->name) {        $this->context->controller->addJS($this->_path.'views/js/back.js');        $this->context->controller->addCSS($this->_path.'views/css/back.css');    [spam-filter]

To FrontOffice try this:

public function hookDisplayHeader(){    if ('order' === $this->context->controller->php_self) {        $this->context->controller->registerStylesheet('modules-front', 'modules/'.$this->name.'/views/css/front.css', array('media' => 'all', 'priority' => 150));        $this->context->controller->registerJavascript('modules-front', 'modules/'.$this->name.'/views/js/front.js', array('position' => 'bottom', 'priority' => 150));    [spam-filter]

Hope this be usefull and can help you

 

Edit:

Obviously, install the hooks you need

Edited by GKentaurus (see edit history)

Share this post


Link to post
Share on other sites

Hello GKentaurus,

The problem is not that we cannot add any JS in backoffice. The problem is that we cannot add jquery plugins (actually we can add, but won't work). And this is because jQuery is loaded AFTER we add other js files. Of course, we can add it before too with $this->context->controller->addJquery(), but this won't solve the problem because jQuery will be re-initialised (because of the original way the library is loaded) and all the plugins added before that won't work.

Share this post


Link to post
Share on other sites

  • 6 months later...
On 18/09/2017 at 4:59 PM, Geo Burlibasa said:

Hello GKentaurus,

The problem is not that we cannot add any JS in backoffice. The problem is that we cannot add jquery plugins (actually we can add, but won't work). And this is because jQuery is loaded AFTER we add other js files. Of course, we can add it before too with $this->context->controller->addJquery(), but this won't solve the problem because jQuery will be re-initialised (because of the original way the library is loaded) and all the plugins added before that won't work.

Did you find a solution???

Share this post


Link to post
Share on other sites

  • 1 year later...

hello guys,

In your module class,  you must register this hook "actionAdminControllerSetMedia" then use it

public function install() {
	parent::install();
	$this->registerHook('actionAdminControllerSetMedia');
	return true;
}
public function hookActionAdminControllerSetMedia(){
    $this->context->controller->addJquery();
    $this->context->controller->addJS(_MODULE_DIR_.'moduleName/views/js/jsFileName.js');
}

And

On 9/18/2017 at 2:38 PM, Geo Burlibasa said:

Unfortunately in AdminController there is not registerJavascript. Only in FrontController.

Like you said we're in adminController so we must use "addJS" function

  • Like 1

Share this post


Link to post
Share on other sites

  • 6 months later...
On 8/23/2017 at 3:28 PM, mike10101 said:

Hello,

 

I am working on a module and I'm trying to add a small jquery plugin I need for the product page.

 

Using the old method


$this->context->controller->addJs()

the jquery plugins Showbox jiofi.local.html tplinklogin gets added BEFORE bundle.js where jquery is... well... bundled.. and the plugin can't bind to jquery before its loaded.

 

Is there some kind of method I'm not aware to add js files after bundle.js in the new symfony admin pages ?

 

 

Otherwise I am forced to inject the file with js which is not cool.

 

 

Side note: why can't we post issues on the github repo ?? Its such a shame I can't post this on github.

 

 

- mike

bump

Edited by diondlemarcu (see edit history)

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More