Skip to content

Commit

Permalink
Merge pull request #8494 from Quetzacoalt91/front-end-optis
Browse files Browse the repository at this point in the history
Reduce javascript execution time on product pages
  • Loading branch information
toutantic authored Nov 15, 2017
2 parents 6b577af + 02cd9e5 commit 88405d7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 66 deletions.
16 changes: 7 additions & 9 deletions admin-dev/themes/default/js/bundle/category-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@
if (isMethodCall) {
switch (settings) {
case 'unselect':
$('div.radio > label > input:radio', this).prop('checked', false);
this.find('.radio > label > input:radio').prop('checked', false);
// TODO: add a callback method feature?
break;
case 'unfold':
$('ul', this).show();
$('li', this).has('ul').addClass('less');
this.find('ul').show();
this.find('li').has('ul').addClass('less');
break;
case 'fold':
$('ul ul', this).hide();
$('li', this).has('ul').addClass('more');
this.find('ul ul').hide();
this.find('li').has('ul').addClass('more');
break;
default:
throw 'Unknown method';
}
}
// initialize tree
else {
$('li > ul', this).each(function (i, item) {
var clickHandler = function (event) {

var $ui = $(event.target);
if ($ui.attr('type') === 'radio' || $ui.attr('type') === 'checkbox') {
return;
Expand All @@ -72,8 +70,8 @@
}

return false;
};

};
this.find('li > ul').each(function (i, item) {
var $inputWrapper = $(item).prev('div');
$inputWrapper.on('click', clickHandler);
$inputWrapper.find('label').on('click', clickHandler);
Expand Down
60 changes: 22 additions & 38 deletions admin-dev/themes/default/js/bundle/product/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,64 +133,48 @@ function updateBulkMenu() {

var productCatalogFilterChanged = false;
function updateFilterMenu() {
var count = $('form#product_catalog_list tr.column-filters select option:selected[value!=""]').length;
$('form#product_catalog_list tr.column-filters input[type="text"]:visible').each(function() {
var columnFilters = $('#product_catalog_list').find('tr.column-filters');
var count = columnFilters.find('option:selected[value!=""]').length;
columnFilters.find('input[type="text"][sql!=""][sql], input[type="text"]:visible').each(function() {
if ($(this).val() !== '') {
count ++;
}
});
$('form#product_catalog_list tr.column-filters input[type="text"][sql!=""][sql]').each(function() {
if ($(this).val() !== '') {
count ++;
}
});
$('button[name="products_filter_submit"]').prop('disabled', (count === 0) && productCatalogFilterChanged === false);
if (count === 0 && productCatalogFilterChanged === false) {
$('button[name="products_filter_reset"]').hide();
}else {
$('button[name="products_filter_reset"]').show();
}
var filtersNotUpdatedYet = (count === 0 && productCatalogFilterChanged === false);
$('button[name="products_filter_submit"]').prop('disabled', filtersNotUpdatedYet);
$('button[name="products_filter_reset"]').toggle(!filtersNotUpdatedYet);
}

function productCategoryFilterReset(div) {
$('div#choice_tree').categorytree('unselect');
$('form#product_catalog_list input[name="filter_category"]').val('');
$('form#product_catalog_list').submit();
$('#choice_tree').categorytree('unselect');
$('#product_catalog_list input[name="filter_category"]').val('');
$('#product_catalog_list').submit();
}

function productCategoryFilterExpand(div, btn) {
$('div#choice_tree').categorytree('unfold');
$('#choice_tree').categorytree('unfold');
}

function productCategoryFilterCollapse(div, btn) {
$('div#choice_tree', div).categorytree('fold');
$('#choice_tree').categorytree('fold');
}

function categoryFilterButtons() {
if ($('div#product_catalog_category_tree_filter ul ul:visible').length === 0) {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_collapse"]').hide();
} else {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_collapse"]').show();
}
if ($('div#product_catalog_category_tree_filter ul ul:hidden').length === 0) {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_expand"]').hide();
} else {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_expand"]').show();
}
if ($('div#product_catalog_category_tree_filter ul input:checked').length === 0) {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_reset"]').hide();
} else {
$('div#product_catalog_category_tree_filter ~ div button[name="product_catalog_category_tree_filter_reset"]').show();
}
var catTree = $('#product_catalog_category_tree_filter');
var catTreeSiblingDivs = $('#product_catalog_category_tree_filter ~ div');
var catTreeList = catTree.find('ul ul');
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_collapse"]').toggle(!catTreeList.filter(':visible').length);
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_expand"]').toggle(!catTreeList.filter(':hidden').length);
catTreeSiblingDivs.find('button[name="product_catalog_category_tree_filter_reset"]').toggle(!catTree.find('ul input:checked').length);
}

function productColumnFilterReset(tr) {
$('input:text', tr).val('');
$('select option:selected', tr).prop('selected', false);
$('input#filter_column_price', tr).attr('sql', '');
$('input#filter_column_sav_quantity', tr).attr('sql', '');
$('input#filter_column_id_product', tr).attr('sql', '');
$('form#product_catalog_list').submit();
$('#filter_column_price', tr).attr('sql', '');
$('#filter_column_sav_quantity', tr).attr('sql', '');
$('#filter_column_id_product', tr).attr('sql', '');
$('#product_catalog_list').submit();
}

function bulkModalAction(allItems, postUrl, redirectUrl, action) {
Expand Down Expand Up @@ -256,7 +240,7 @@ function bulkModalAction(allItems, postUrl, redirectUrl, action) {
}

function bulkProductAction(element, action) {
var form = $('form#product_catalog_list');
var form = $('#product_catalog_list');
var postUrl = '';
var redirectUrl = '';
var urlHandler = null;
Expand Down
28 changes: 12 additions & 16 deletions admin-dev/themes/new-theme/js/product-page/combination.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export default function() {
if (idsProductAttribute[0] != '') {
getCombinations(response);
}
$('#create-combinations').click(function(event) {
event.preventDefault();
form.send(false, false, generate);
});
});


$('#create-combinations').click(function(event) {
event.preventDefault();
form.send(false, false, generate);
});

let productDropzone = Dropzone.forElement('#product-images-dropzone');
let updateCombinationImages = function () {
var productAttributeIds = $.map($('.js-combinations-list .combination'), function (combination) {
Expand All @@ -40,12 +41,7 @@ export default function() {
var isChecked = input.prop('checked');
input.prop('checked', isChecked ? false : true);

if (isChecked) {
$(this).removeClass('img-highlight');

} else {
$(this).addClass('img-highlight');
}
$(this).toggleClass('img-highlight', isChecked);
refreshDefaultImage();
});

Expand Down Expand Up @@ -97,15 +93,15 @@ export default function() {
$imagesElem = $('#combination_' + $index + '_id_image_attr');
}

$imagesElem.html('');
var html = '';

$.each(combinationsImages[value], function(key, image) {
$imagesElem.append(`<div class="product-combination-image ${(image.id_image_attr ? 'img-highlight' : '')}">
html += `<div class="product-combination-image ${(image.id_image_attr ? 'img-highlight' : '')}">
<input type="checkbox" name="combination_${$index}[id_image_attr][]" value="${image.id}" ${(image.id_image_attr ? 'checked="checked"' : '')}>
<img src="${image.base_image_url}-small_default.${image.format}" alt="" />
</div>`);
</div>`;
});

$imagesElem.html(html);
$combinationElem.fadeIn(1000);
});

Expand Down Expand Up @@ -141,7 +137,7 @@ export default function() {

if (defaultImageUrl) {
var img = '<img src="' + defaultImageUrl + '" class="img-responsive" />';
$('#accordion_combinations #attribute_' + $(elem).attr('data')).find('td.img').html(img);
$('#attribute_' + $(elem).attr('data')).find('td.img').html(img);
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function() {

$('.js-nav-tabs li').each((index, item) => {
navWidth += $(item).width();
$('.js-nav-tabs').width(navWidth);
});
$('.js-nav-tabs').width(navWidth);

$('.js-nav-tabs [data-toggle="tab"]').on('click', (e) => {
if (!$(e.target).hasClass('active')) {
Expand Down
10 changes: 8 additions & 2 deletions js/cldr.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var cldrLoadedCatalogs = [];
var cldrLoaderError = false;
var cldrCatalogsPath = (typeof baseDir !== 'undefined' ? baseDir : '') + 'translations/cldr/datas/';

/* Variables avoiding several loading of the same file */
var deferreds = [];
var deferredUrls = [];

/**
* Will get list of CLDR catalogs by XHR.
* Please do not call this directly except if you know what you do. Prefer to call the wrapper methods cldrForXXX()
Expand Down Expand Up @@ -77,14 +81,16 @@ function cldrLazyLoadCatalogs(catalogs, callback) {
return new Globalize(culture);
}
} else {
var deferreds = [];
catalogs.forEach(function(catalog) {
var url = cldrCatalogsPath + catalog.replace(/main\/[^\/]+/, 'main/'+culture) + '.json';
if ($.inArray(url, cldrLoadedCatalogs) === -1) {
if ($.inArray(url, cldrLoadedCatalogs) === -1 && $.inArray(url, deferredUrls) === -1) {
deferredUrls.push(url);
this.push($.get(url).done(function() {
cldrLoadedCatalogs.push(url);
}).fail(function() {
cldrLoaderError = true;
}).always(function() {
deferredUrls.splice(deferredUrls.indexOf(url), 1)
}));
}
}, deferreds);
Expand Down

0 comments on commit 88405d7

Please sign in to comment.