6
6
define ( [
7
7
'jquery' ,
8
8
'mage/template' ,
9
+ 'mage/utils/misc' ,
10
+ 'mage/translate' ,
9
11
'jquery-ui-modules/dialog' ,
10
- 'mage/translate'
11
- ] , function ( $ , mageTemplate ) {
12
+ ] , function ( $ , mageTemplate , miscUtils ) {
12
13
'use strict' ;
13
14
14
15
$ . widget ( 'mage.translateInline' , $ . ui . dialog , {
@@ -59,11 +60,12 @@ define([
59
60
* Open.
60
61
*/
61
62
open : function ( ) {
62
- var topMargin ;
63
+ var $uiDialog = $ ( this ) . closest ( '.ui-dialog' ) ,
64
+ topMargin = $uiDialog . children ( '.ui-dialog-titlebar' ) . outerHeight ( ) + 45 ;
63
65
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 )
67
69
} ,
68
70
69
71
/**
@@ -79,11 +81,15 @@ define([
79
81
* @protected
80
82
*/
81
83
_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
+
82
91
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
+
87
93
this . _super ( ) ;
88
94
} ,
89
95
@@ -95,7 +101,7 @@ define([
95
101
_prepareContent : function ( templateData ) {
96
102
var data = $ . extend ( {
97
103
items : templateData ,
98
- escape : $ . mage . escapeHTML
104
+ escape : miscUtils . escape ,
99
105
} , this . options . translateForm . data ) ;
100
106
101
107
this . data = data ;
@@ -131,16 +137,14 @@ define([
131
137
* @protected
132
138
*/
133
139
_formSubmit : function ( ) {
134
- var parameters ;
140
+ var parameters = $ . param ( {
141
+ area : this . options . area
142
+ } ) + '&' + $ ( '#' + this . options . translateForm . data . id ) . serialize ( ) ;
135
143
136
144
this . formIsSubmitted = true ;
137
- parameters = $ . param ( {
138
- area : this . options . area
139
- } ) + '&' + $ ( '#' + this . options . translateForm . data . id ) . serialize ( ) ;
140
145
141
- $ . ajax ( {
146
+ $ . post ( {
142
147
url : this . options . ajaxUrl ,
143
- type : 'POST' ,
144
148
data : parameters ,
145
149
loaderContext : this . element ,
146
150
showLoader : true
@@ -162,11 +166,13 @@ define([
162
166
* @private
163
167
*/
164
168
_updatePlaceholder : function ( newValue ) {
165
- var target = jQuery ( this . target ) ;
169
+ var $target = $ ( this . target ) ,
170
+ translateObject = $target . data ( 'translate' ) [ 0 ] ;
171
+
172
+ translateObject . shown = newValue ;
173
+ translateObject . translated = newValue ;
166
174
167
- target . data ( 'translate' ) [ 0 ] . shown = newValue ;
168
- target . data ( 'translate' ) [ 0 ] . translated = newValue ;
169
- target . html ( newValue ) ;
175
+ $target . html ( newValue ) ;
170
176
} ,
171
177
172
178
/**
@@ -177,20 +183,6 @@ define([
177
183
this . _super ( ) ;
178
184
}
179
185
} ) ;
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, '"' ) :
190
- false ;
191
- }
192
- }
193
- } ) ;
194
186
195
187
return $ . mage . translateInline ;
196
188
} ) ;
0 commit comments