Author Topic: No cleanup js code in VM 3  (Read 2683 times)

2dmaster

  • Jr. Member
  • **
  • Posts: 94
No cleanup js code in VM 3
« on: January 02, 2016, 11:50:02 am »
Virtuemart so have bad js code;  issue with javascript errors when using javascript compressors/combiners/cachers.
tested with jch optimize pro

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8892
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: No cleanup js code in VM 3
« Reply #1 on: January 02, 2016, 11:55:09 am »
Your point is?

Are you going to say what you think is bad about it and suggest improvements?
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10330
  • VirtueMart Version: 3+
Re: No cleanup js code in VM 3
« Reply #2 on: January 02, 2016, 14:15:16 pm »
I use jchoptimize

& exclude these files

jquery.min.js
jquery-noconflict.js
jquery-migrate.min.js
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3839
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: No cleanup js code in VM 3
« Reply #3 on: January 02, 2016, 22:35:56 pm »
Try to check the VM functions, some have no local names(certainly some mistakes), modules\mod_virtuemart_cart\assets\js\update_cart.js
Code: [Select]
if (typeof Virtuemart === "undefined")
Virtuemart = {};

jQuery(function($) {
Virtuemart.customUpdateVirtueMartCartModule = function(el, options){
var base = this;
var $this = $(this);
base.$el = $(".vmCartModule");

base.options = $.extend({}, Virtuemart.customUpdateVirtueMartCartModule.defaults, options);

base.init = function(){
$.ajaxSetup({ cache: false })
$.getJSON(window.vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json" + window.vmLang,
function (datas, textStatus) {
base.$el.each(function( index ,  module ) {
if (datas.totalProduct > 0) {
$(module).find(".vm_cart_products").html("");
$.each(datas.products, function (key, val) {
//jQuery("#hiddencontainer .vmcontainer").clone().appendTo(".vmcontainer .vm_cart_products");
$(module).find(".hiddencontainer .vmcontainer .product_row").clone().appendTo( $(module).find(".vm_cart_products") );
$.each(val, function (key, val) {
$(module).find(".vm_cart_products ." + key).last().html(val);
});
});
}
$(module).find(".show_cart").html( datas.cart_show);
$(module).find(".total_products").html( datas.totalProductTxt);
$(module).find(".total").html( datas.billTotal);
});
}
);
};
base.init();
};
// Definition Of Defaults
Virtuemart.customUpdateVirtueMartCartModule.defaults = {
name1: 'value1'
};

});

jQuery(document).ready(function( $ ) {
jQuery(document).off("updateVirtueMartCartModule","body",Virtuemart.customUpdateVirtueMartCartModule);
jQuery(document).on("updateVirtueMartCartModule","body",Virtuemart.customUpdateVirtueMartCartModule);
});

Ths is only to help the developpers(i don't know what dev do the javascript currently, but review yourself.
Two time same function for nothing and not using same code.
jQuery(function($) {  == jQuery(document).ready(function( $ ) {

Code: [Select]
var base = this;
var $this = $(this);
base.$el = $(".vmCartModule");
Why base=this and $this = $(this) ?
Why base.$el    = $(".vmCartModule");, using $el = $(".vmCartModule"); do the same effect inside the getJSON if you replace base.$el with $el

I have see in other function missing var before some local variables. So if you try to compres it, this fail.

SO the most valid code here is :
Code: [Select]
if (typeof Virtuemart === "undefined")
Virtuemart = {};

jQuery(document).ready(function( $ ) {
Virtuemart.customUpdateVirtueMartCartModule = function(el, options){
var base = this,
$el = $(".vmCartModule");

base.options = $.extend({}, Virtuemart.customUpdateVirtueMartCartModule.defaults, options);

base.init = function(){
$.ajaxSetup({ cache: false })
$.getJSON(vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json" + vmLang,
function (datas, textStatus) {
$el.each(function( index ,  module ) {
var $mod = $(module);
if (datas.totalProduct > 0) {
$mod.find(".vm_cart_products").html("");
$.each(datas.products, function (key, val) {
$mod.find(".hiddencontainer .vmcontainer .product_row").clone().appendTo( $mod.find(".vm_cart_products") );
$.each(val, function (key, val) {
$mod.find(".vm_cart_products ." + key).last().html(val);
});
});
}
$mod.find(".show_cart").html( datas.cart_show);
$mod.find(".total_products").html( datas.totalProductTxt);
$mod.find(".total").html( datas.billTotal);
});
}
);
};
base.init();
};
jQuery(document).off("updateVirtueMartCartModule","body",Virtuemart.customUpdateVirtueMartCartModule)
.on("updateVirtueMartCartModule","body",Virtuemart.customUpdateVirtueMartCartModule);
});

But in all, this is not completly optimise because in case of 2 modules or more, the $el.each loop get called 2 times.
So i only hope a day that someone review a little the javascript code, because many new mistake are in VM 3.0.x

I do not want to denigrate the work of developer, but i think some review is needed in the javascripts, if you paste this code in jslint for eg. all this mistake get immediatly displayed as errors.

Regards,
Patrick

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9839
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: No cleanup js code in VM 3
« Reply #4 on: January 04, 2016, 15:03:52 pm »
2dMaster

you try to minify a minified version. Do you understand your error? and Patrick, the js code basis is yours. lol you talk about your own errors.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3839
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: No cleanup js code in VM 3
« Reply #5 on: January 04, 2016, 22:18:39 pm »
Max, this code is new and don't existed before.
And i'm not anymore in developper team. If i report error, is this so complicate to check.
If you find this is right so, then leave as it is.
All days i find a bug and not only in VM, in other component too.
I have reported 3 or 4 bugs, in onepage checkout, same in Joomla this year. In some plugins and extention my customer paid for.
One of them i had to rewrite most of the code. I had no problem, all developper say me thanks, but you always come for a old code from 2013, this is now 3 year old.
All do errors, you and me too! Simply check the current security fix in Joomla!

Regards,
Patrick