VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: andresf on January 06, 2015, 18:16:05 PM

Title: Inline Javascript problem with template overriding on user fields editing
Post by: andresf on January 06, 2015, 18:16:05 PM
Hello, everyone.

First, a background for the issue:

- I'm overriding the views via template /templates/template/html/com_virtuemart On Virtuemart 3.0.2 - Joomla! 3.3.6
- For perfomance purposes, we have a Joomla! plugin that moves all the external and inline Javascript to the bottom of the page


The problem:

I'm current overriding the user fields edit view, which so far includes the scripts: /user/edit_address.php and /user/edit_address_userfields.php. These views include inline scripts which break the page, (because JS libraries aren't loaded yet). The scripts which break the page are:


<script id="vm.countryState_js" defer type="text/javascript"> //<![CDATA[
jQuery( function($) {
$("#virtuemart_country_id").vm2front("list",{dest : "#virtuemart_state_id",ids : "",prefiks : ""});
});
//]]></script>



<script id="datepicker_js" defer type="text/javascript"> //<![CDATA[
jQuery(document).ready( function($) {
$(".datepicker").live( "focus", function() {
$( this ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1915:2015",
dateFormat:"y.mm.dd",
altField: $(this).prev(),
altFormat: "yy-mm-dd"
});
});
$(".js-date-reset").click(function() {
$(this).prev("input").val("-Nunca-").prev("input").val("0");
});
});
//]] </script>



<script id="vm.countryStateshipto__js" defer type="text/javascript"> //<![CDATA[
jQuery( function($) {
$("#shipto_virtuemart_country_id").vm2front("list",{dest : "#shipto_virtuemart_state_id",ids : "",prefiks : "shipto_"});
});
//]]> </script>


What I want to know is where and how are these scripts injected so I can override them, because I've been looking for several hours and haven't found them.

I've already overrided in this specific view the inline JS generated by the function vmValidator() from the file edit/view.html.php by recreating that function within the overriding script and replacing the line

$this->vmValidator(); for JFactory::getDocument()->addScriptDeclaration(vmValidatorOverride());

And I intend to keep like this for every other inline script of the views I have to override.

Thanks in advance for any help with this issue.
Title: Re: Inline Javascript problem with template overriding on user fields editing
Post by: GJC Web Design on January 06, 2015, 19:36:20 PM
does this help?
http://docs.virtuemart.net/tutorials/development/196-the-vm-javascript-handler.html
Title: Re: Inline Javascript problem with template overriding on user fields editing
Post by: andresf on January 06, 2015, 20:11:12 PM
Thanks, for your reply.

It doesn't help that much. Actually that's the class that causes the error. Looks like it doesn't employs the JDocument class, because it outputs the JS script inline.