Skip to content

Commit c4d2500

Browse files
authored
ENGCOM-8018: Initialize inline translations module only when they are enabled #27696
2 parents b4e13f8 + e5f88ed commit c4d2500

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<element name="collapseAll" type="button" selector=".tree-actions a:first-child"/>
1313
<element name="expandAll" type="button" selector=".tree-actions a:last-child"/>
1414
<element name="categoryHighlighted" type="text" selector="//div[@id='store.menu']//span[contains(text(),'{{name}}')]/ancestor::li" parameterized="true" timeout="30"/>
15-
<element name="categoryNotHighlighted" type="text" selector="ul[id=\'ui-id-2\'] li[class~=\'active\']" timeout="30"/>
15+
<element name="categoryNotHighlighted" type="text" selector="[id=\'store.menu\'] ul li.active" timeout="30"/>
1616
<element name="categoryTreeRoot" type="text" selector="div.x-tree-root-node>li.x-tree-node:first-of-type>div.x-tree-node-el:first-of-type" timeout="30"/>
1717
<element name="categoryInTree" type="text" selector="//a/span[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>
1818
<element name="categoryInTreeUnderRoot" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{name}}')]" parameterized="true"/>

app/code/Magento/Translation/view/frontend/requirejs-config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ var config = {
1010
addClass: 'Magento_Translation/js/add-class',
1111
'Magento_Translation/add-class': 'Magento_Translation/js/add-class'
1212
}
13-
},
14-
deps: [
15-
'mage/translate-inline'
16-
]
13+
}
1714
};

lib/web/mage/translate-inline.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
define([
77
'jquery',
88
'mage/template',
9-
'jquery-ui-modules/dialog',
10-
'mage/translate'
11-
], function ($, mageTemplate) {
9+
'mage/utils/misc',
10+
'mage/translate',
11+
'jquery-ui-modules/dialog'
12+
], function ($, mageTemplate, miscUtils) {
1213
'use strict';
1314

1415
$.widget('mage.translateInline', $.ui.dialog, {
@@ -59,11 +60,12 @@ define([
5960
* Open.
6061
*/
6162
open: function () {
62-
var topMargin;
63+
var $uiDialog = $(this).closest('.ui-dialog'),
64+
topMargin = $uiDialog.children('.ui-dialog-titlebar').outerHeight() + 45;
6365

64-
$(this).closest('.ui-dialog').addClass('ui-dialog-active');
65-
topMargin = jQuery(this).closest('.ui-dialog').children('.ui-dialog-titlebar').outerHeight() + 45;
66-
jQuery(this).closest('.ui-dialog').css('margin-top', topMargin);
66+
$uiDialog
67+
.addClass('ui-dialog-active')
68+
.css('margin-top', topMargin);
6769
},
6870

6971
/**
@@ -79,11 +81,15 @@ define([
7981
* @protected
8082
*/
8183
_create: function () {
84+
var $translateArea = $(this.options.translateArea);
85+
86+
if (!$translateArea.length) {
87+
$translateArea = $('body');
88+
}
89+
$translateArea.on('edit.editTrigger', $.proxy(this._onEdit, this));
90+
8291
this.tmpl = mageTemplate(this.options.translateForm.template);
83-
(this.options.translateArea && $(this.options.translateArea).length ?
84-
$(this.options.translateArea) :
85-
this.element.closest('body'))
86-
.on('edit.editTrigger', $.proxy(this._onEdit, this));
92+
8793
this._super();
8894
},
8995

@@ -95,7 +101,7 @@ define([
95101
_prepareContent: function (templateData) {
96102
var data = $.extend({
97103
items: templateData,
98-
escape: $.mage.escapeHTML
104+
escape: miscUtils.escape
99105
}, this.options.translateForm.data);
100106

101107
this.data = data;
@@ -131,12 +137,11 @@ define([
131137
* @protected
132138
*/
133139
_formSubmit: function () {
134-
var parameters;
140+
var parameters = $.param({
141+
area: this.options.area
142+
}) + '&' + $('#' + this.options.translateForm.data.id).serialize();
135143

136144
this.formIsSubmitted = true;
137-
parameters = $.param({
138-
area: this.options.area
139-
}) + '&' + $('#' + this.options.translateForm.data.id).serialize();
140145

141146
$.ajax({
142147
url: this.options.ajaxUrl,
@@ -162,11 +167,13 @@ define([
162167
* @private
163168
*/
164169
_updatePlaceholder: function (newValue) {
165-
var target = jQuery(this.target);
170+
var $target = $(this.target),
171+
translateObject = $target.data('translate')[0];
172+
173+
translateObject.shown = newValue;
174+
translateObject.translated = newValue;
166175

167-
target.data('translate')[0].shown = newValue;
168-
target.data('translate')[0].translated = newValue;
169-
target.html(newValue);
176+
$target.html(newValue);
170177
},
171178

172179
/**
@@ -177,20 +184,6 @@ define([
177184
this._super();
178185
}
179186
});
180-
// @TODO move the "escapeHTML" method into the file with global utility functions
181-
$.extend(true, $, {
182-
mage: {
183-
/**
184-
* @param {String} str
185-
* @return {Boolean}
186-
*/
187-
escapeHTML: function (str) {
188-
return str ?
189-
jQuery('<div/>').text(str).html().replace(/"/g, '&quot;') :
190-
false;
191-
}
192-
}
193-
});
194187

195188
return $.mage.translateInline;
196189
});

lib/web/mage/utils/misc.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
define([
77
'underscore',
88
'jquery',
9-
'FormData'
10-
], function (_, $) {
9+
'mage/utils/objects'
10+
], function (_, $, utils) {
1111
'use strict';
1212

1313
var defaultAttributes,
@@ -120,7 +120,7 @@ define([
120120
*/
121121
submit: function (options, attrs) {
122122
var form = document.createElement('form'),
123-
data = this.serialize(options.data),
123+
data = utils.serialize(options.data),
124124
attributes = _.extend({}, defaultAttributes, attrs || {});
125125

126126
if (!attributes.action) {
@@ -205,11 +205,11 @@ define([
205205

206206
if (type === 'default') {
207207
formData = new FormData();
208-
_.each(this.serialize(data), function (val, name) {
208+
_.each(utils.serialize(data), function (val, name) {
209209
formData.append(name, val);
210210
});
211211
} else if (type === 'simple') {
212-
formData = this.serialize(data);
212+
formData = utils.serialize(data);
213213
}
214214

215215
return formData;
@@ -242,6 +242,16 @@ define([
242242
return data;
243243
},
244244

245+
/**
246+
* Replaces special characters with their corresponding HTML entities.
247+
*
248+
* @param {String} string - Text to escape.
249+
* @returns {String} Escaped text.
250+
*/
251+
escape: function (string) {
252+
return string ? $('<p/>').text(string).html().replace(/"/g, '&quot;') : string;
253+
},
254+
245255
/**
246256
* Replaces symbol codes with their unescaped counterparts.
247257
*

lib/web/mage/utils/objects.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
define([
66
'ko',
77
'jquery',
8-
'underscore'
9-
], function (ko, $, _) {
8+
'underscore',
9+
'mage/utils/strings'
10+
], function (ko, $, _, stringUtils) {
1011
'use strict';
1112

1213
var primitives = [
@@ -217,7 +218,7 @@ define([
217218
data = this.flatten(data);
218219

219220
_.each(data, function (value, keys) {
220-
keys = this.serializeName(keys);
221+
keys = stringUtils.serializeName(keys);
221222
value = _.isUndefined(value) ? '' : value;
222223

223224
result[keys] = value;

0 commit comments

Comments
 (0)