Jump to content

[SOLVED] No jQuery included in RC3?


Andrej Stas

Recommended Posts

I can reproduce this. It breaks all my modules in PrestaShop v1.7 RC3. :(

    /**
     * @deprecated 1.7  This function has no effect in PrestaShop 1.7 theme. jQuery2 is register by the core on every theme.
     *                  Have a look at the /themes/_core folder.
     */
    public function addJquery($version = null, $folder = null, $minifier = true)
    {
        /*
        This is deprecated in PrestaShop 1.7 and has no effect in PrestaShop 1.7 theme.
        jQuery2 is register by the core on every theme. Have a look at the /themes/_core folder.
        */
    }

I'm trying to understand what "jQuery2 is register by the core on every theme. Have a look at the /themes/_core folder." means.

Link to comment
Share on other sites

It seems PrestaShop has removed jQuery from inline JavaScript, but it's still available in JavaScript files that import it. I'm going to try to move all my inline JavaScript into a separate file to see if that fixes the JavaScript errors.

  • Like 1
Link to comment
Share on other sites

 

It seems PrestaShop has removed jQuery from inline JavaScript, but it's still available in JavaScript files that import it. I'm going to try to move all my inline JavaScript into a separate file to see if that fixes the JavaScript errors

 

Rocky, please let me know if you manage to solve it. I will do more tests also.

Link to comment
Share on other sites

Ok, mystery solved!

 

- Prestashop now inserts all JS files, including jQuery library, right before </body>

- I use inline JS in my modules, so basically I try to access jQuery function, but the library has not been loaded yet, that's why I get errors

 

SOLUTION:

- I found this JS script: https://github.com/withjam/jqshim-head which might solve the problem.

- Another option is to put all inline JS into JS files

Edited by Andrej Stas (see edit history)
Link to comment
Share on other sites

I found an easier solution (thanks to shokinro) that doesn't require moving the JavaScript to a separate file. Just add the following code around the <script>:

{block name='javascript_bottom'}
    {$smarty.block.parent}
// Script code here
{/block}

EDIT: This only works if you are extending a TPL file.

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

ok, but i have this script code

 

<script type="text/javascript">
 
infinite_scroll = {$options nofilter};
{if isset($pages_nb)}
infinite_scroll.maxPage = {$pages_nb};
{/if}
$( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll, function(newElements, data, url) { eval(infinite_scroll.callback); });
</script>
 
the code loads variables, so cant add into a js file, and prestashop validation dont want html code anymore on the php of the module. The js fie infinitescroll is loaded before that code. Wich is the "official" way to do?
Link to comment
Share on other sites

  • 2 weeks later...

 

ok, but i have this script code

 

<script type="text/javascript">
 
infinite_scroll = {$options nofilter};
{if isset($pages_nb)}
infinite_scroll.maxPage = {$pages_nb};
{/if}
$( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll, function(newElements, data, url) { eval(infinite_scroll.callback); });
</script>
 
the code loads variables, so cant add into a js file, and prestashop validation dont want html code anymore on the php of the module. The js fie infinitescroll is loaded before that code. Wich is the "official" way to do?

 

 

Use the hook "displayBeforeBodyClosingTag" in your module:

 

 

public function hookDisplayBeforeBodyClosingTag($params)
    {
 
...load data...
 
        $this->context->smarty->assign([
            ....set all your javascript variables...
        ]);
 
        return $this->display(__FILE__, 'javascript_footer.tpl');
    }
 
and then insert all your javascript into this TPL file using all variables you need.
Link to comment
Share on other sites

 

Use the hook "displayBeforeBodyClosingTag" in your module:

 

 

public function hookDisplayBeforeBodyClosingTag($params)
    {
 
...load data...
 
        $this->context->smarty->assign([
            ....set all your javascript variables...
        ]);
 
        return $this->display(__FILE__, 'javascript_footer.tpl');
    }
 
and then insert all your javascript into this TPL file using all variables you need.

 

you are the master

Link to comment
Share on other sites

  • 4 years later...
On 10/30/2016 at 9:24 AM, rocky said:

I found an easier solution (thanks to shokinro) that doesn't require moving the JavaScript to a separate file. Just add the following code around the <script>:


{block name='javascript_bottom'}
    {$smarty.block.parent}
// Script code here
{/block}

EDIT: This only works if you are extending a TPL file.

Thank you a thousand times ! This solved my issue, too, I had a module made for Ps 1.6, and in 1.7x I had to add this part to make it work. 
Thank you !!

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
×
×
  • Create New...