I have some HTML and javascipt that is generated automatically through a URL. This html and javascipt is generated using Smarty templates. Unfortunately, this code that is generated uses a bunch of jQuery, but the references to the jQuery libraries aren't included in the code and so generate errors. I can't change this. Below is an example of the first part of that javascript that generates the error 'Uncaught Reference Error: cj is not defined'
<script type="text/javascript">
cj( function() {
var element_date = "#birth_date_display";var element_time = "#birth_date_time";var time_format = cj( element_time ).attr('timeFormat');
cj(element_time).timeEntry({ show24Hours : time_format, spinnerImage: '' });
var currentYear = new Date().getFullYear();var alt_field = '#birth_date';cj( alt_field ).hide();var date_format = cj( alt_field ).attr('format');var altDateFormat = 'mm/dd/yy';
switch ( date_format ) {
case 'dd-mm':
case 'mm/dd':
altDateFormat = 'mm/dd';
break;
}
What I can do though, is add code onto the end of the file. So I am able to load the relevant libraries and simply enter the same javascript code again, and it works fine.
The problem I am running into is that I am trying to do some styling of the page using jQuery also after the fact. The line below is giving me the problem. Everything gets wrapped fine, but my javascript file just exits on this row,
$("#editrow-email-Primary, #editrow-phone-1-1, #editrow-birth_date").wrapAll("<div class='grid-group personal' />");
again with the same error 'Uncaught reference error: cj is not defined. It is the editrow-birth_date div that most of the previous javascript is for as it uses the jQuery UI datepicker. The funny thing is, simply appending the same javascript and jQuery at the end of the file works fine, until I just to .wrapAll. Then it seems to be trying to run something again in the original javascript and generating a new error and exiting.
I'm completely stuck here, and I don't even know how to properly explain what I think is going on. Is there a way that I can remove the original javascript from the code on the fly so that it can't be executed anymore? I don't think so, but I am hoping so as I feel like that would solve my problem.