Jump to content

Prestashop javascript file call into theme [SOLVED]


Recommended Posts

Hi. 

 

edit: solved, posted solution and link reference at final post.

 

I have a stronge problem about a javascript i load from the template.

I used it on a plain html code to check all about their functions. It works.

 

Now, implemented into the 1.4 prestashop, im getting some errors.

 

Im using the following code to get the js files directly to the header.tpl:

<script type="text/javascript" src="{$js_dir}myfile.js"></script>

The load to Js works.

The problem i have is that the loaded content seems to not being executed.

 

Surprisily, i put an alert('wey') on the top of the called scripts, and they work too.

I don't have f*** idea about why the code is not executing.

 

Suggestions?

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

Hi Vekia. 

 

I have load 2 files. One is the common javascript function library, the other is the call to that function, from a .js file to make it easier to put into the header.tpl.

I also try to put that code surrounded with {literal} with no lucky.

 

This is my code: 

$(document).ready(function(){


var cookieScripts = function () {
// Internal javascript called
console.log("OK");


$.cookiesDirective.loadScript({
uri:'external.js',
appendTo: 'head'
});


}

/* Call cookiesDirective, overriding any default params

*** These are the defaults ***
explicitConsent: true,
position: 'top',
duration: 10,
limit: 0,
message: null, 
cookieScripts: null,
privacyPolicyUri: 'privacy.html',
scriptWrapper: function(){}, 
fontFamily: 'helvetica',
fontColor: '#FFFFFF',
fontSize: '13px',
backgroundColor: '#000000',
backgroundOpacity: '80',
linkColor: '#CA0000'

*/

$.cookiesDirective({
privacyPolicyUri: 'declaracion-de-privacidad.html',
explicitConsent: true,
position : 'top',
scriptWrapper: cookieScripts, 
});
});

I have also a call to jquery. I tried with it and without, no lucky again.

PD: Soy Español, por si te parece que nos podamos entender mejor así. Si publico en el foro Inglés es porque me parece que tiene bastante más movimiento :o

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

Prueba:

 

<script type="text/javascript">
var baseDir = '{$content_dir}';
 
</script>
 
;)

 

This doens't do the thing.

 

$content_dir equals to root domain, where the main index and files are. (www, httpdocs, public_html or whatever)

For load content from the current theme location, must use the globals $js_dir or $css_dir.

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

In some of testing step i got some result, but partial.

 

I think the problem is on the jQuery. I see PS loads some minimal version of jQuery, but if if try i got undefined $ function, wich is the same than dont be loaded.

 

When i load the jQuery from google hosted APIs got that problem.

 

  1. Uncaught TypeError: Object function (a,B){return new e.fn.init(a,b,h)} has no method 'cookiesDirective' load.cookiesdirective.js:38
    1. (anonymous function)load.cookiesdirective.js:38
    2. f.resolveWithjquery.min.js:16
    3. d.extend.readyjquery.min.js:16
    4. c.addEventListener.y

 

I'm stucked here.

 

I've tried jQuery.noConflict(), but i think i don't know really how to use, because is not working anyway.

I also renamed the $ to jQuery on the jQuery.noConflict(); calls.

I don't know if i'm doing something wrong or if is another problem not related to noConflict, but the jQuery.

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

As i think, i was wrong on the jQuery.noConflict() function usage.

 

I forgot this example http://www.prestashop.com/forums/topic/107136-jquery-conflictsolved/?view=findpost&p=1354407 and now is working fine.

 

Your func should look like

$.noConflict();
jQuery(document).ready(function($) {

Regards ;)

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...