XF 2.1 Template javascript development mode vs production mode

keithg

Member
I am having an issue where some template script code works in development mode but does not work in production mode.

So my base question is: what is the difference between template processing in development mode vs non-development mode?

I am not a front end developer and I guess I am likely doing something (simple?) the wrong way.

I need to be able to submit an additional form to a different website as part of the log in process (in order to create tracking cookies). I added some simple javascript (and jQuery?) code to the login template.

Everything works fine on my local test system in development mode. Both the overylay and normal login page have the <script> code and I get cookies from the external site.

In production mode the overlay is missing the <script> code, the login page has it, but both get an error ($ is undefined).

How should I morph my simple 5 lines of script to make it work in production mode.

If it matters: my code loads a form from a third party site and defines a submit handler to submit the form when the user logs in.
 
If it helps, here is the script entries I added after line 2 of the login template (i have obfuscated any Marketo account details):

Code:
<script src="//app-sj30.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_111" style="display:none"></form>
<script>MktoForms2.loadForm("//app-sj30.marketo.com", "123-abc-123", 1111);</script>
<script>
$('#login_form').submit(function() {
    var login_form = document.forms['login_form'];
    var login = login_form.elements["login"].value;
    var myForm = MktoForms2.allForms()[0];
    myForm.addHiddenFields({
    //These are the values which will be submitted to Marketo
    "Email":login,
    });
    myForm.submit();
    return true;
});

This works in development mode and accomplishes the goal of getting Marketo cookies in place. So I assume I need to be packaging this differently or pre-processing it to get it to work in production mode? I claim $ undefined error I get in the browser console in production mode is related to the .submit function I added to perform the form submit to Marketo.

My Google-foo is lacking and I have been unable to locate the appropriate XF documentation in order to XenForo-ize the code for a production world.

Any pointers would be appreciated.
 
Back
Top Bottom