@@ -6,174 +6,174 @@ define([
6
6
"jquery" ,
7
7
"underscore" ,
8
8
"mage/template" ,
9
- "text!ui/template/popup/popup- modal.html" ,
10
- "text!ui/template/popup/popup -slide.html" ,
9
+ "text!ui/template/modal/ modal-popup .html" ,
10
+ "text!ui/template/modal/modal -slide.html" ,
11
11
"jquery/ui" ,
12
12
"mage/translate"
13
- ] , function ( $ , _ , template , modalTpl , slideTpl ) {
13
+ ] , function ( $ , _ , template , popupTpl , slideTpl ) {
14
14
"use strict" ;
15
15
16
16
/**
17
- * Dialog Widget
17
+ * Modal Window Widget
18
18
*/
19
- $ . widget ( 'mage.popup ' , {
19
+ $ . widget ( 'mage.modal ' , {
20
20
options : {
21
- type : 'modal ' ,
21
+ type : 'popup ' ,
22
22
title : '' ,
23
- dialogClass : '' ,
24
- modalTpl : modalTpl ,
23
+ modalClass : '' ,
24
+ popupTpl : popupTpl ,
25
25
slideTpl : slideTpl ,
26
- dialogVisibleClass : '_show' ,
27
- parentDialogClass : '_has-dialog ' ,
26
+ modalVisibleClass : '_show' ,
27
+ parentModalClass : '_has-modal ' ,
28
28
innerScrollClass : '_inner-scroll' ,
29
29
responsive : false ,
30
30
innerScroll : false ,
31
- dialogBlock : '[data-role="dialog "]' ,
32
- dialogCloseBtn : '[data-role="closeBtn"]' ,
33
- dialogContent : '[data-role="content"]' ,
34
- dialogAction : '[data-role="action"]' ,
31
+ modalBlock : '[data-role="modal "]' ,
32
+ modalCloseBtn : '[data-role="closeBtn"]' ,
33
+ modalContent : '[data-role="content"]' ,
34
+ modalAction : '[data-role="action"]' ,
35
35
appendTo : 'body' ,
36
- wrapperClass : 'dialogs -wrapper' ,
36
+ wrapperClass : 'modals -wrapper' ,
37
37
overlayClass : 'overlay_magento' ,
38
- responsiveClass : 'dialog -slide' ,
39
- dialogLeftMargin : 45 ,
38
+ responsiveClass : 'modal -slide' ,
39
+ modalLeftMargin : 45 ,
40
40
closeText : $ . mage . __ ( 'Close' ) ,
41
41
buttons : [ {
42
42
text : $ . mage . __ ( 'Ok' ) ,
43
43
class : '' ,
44
44
click : function ( ) {
45
- this . closeDialog ( ) ;
45
+ this . closeModal ( ) ;
46
46
}
47
47
} ]
48
48
} ,
49
49
/**
50
- * Creates dialog widget.
50
+ * Creates modal widget.
51
51
*/
52
52
_create : function ( ) {
53
53
this . options . transitionEvent = this . whichTransitionEvent ( ) ;
54
54
this . _createWrapper ( ) ;
55
- this . _renderDialog ( ) ;
55
+ this . _renderModal ( ) ;
56
56
this . _createButtons ( ) ;
57
57
58
- this . dialog . find ( this . options . dialogCloseBtn ) . on ( 'click' , _ . bind ( this . closeDialog , this ) ) ;
59
- this . element . on ( 'openDialog ' , _ . bind ( this . openDialog , this ) ) ;
60
- this . element . on ( 'closeDialog ' , _ . bind ( this . closeDialog , this ) ) ;
58
+ this . modal . find ( this . options . modalCloseBtn ) . on ( 'click' , _ . bind ( this . closeModal , this ) ) ;
59
+ this . element . on ( 'openModal ' , _ . bind ( this . openModal , this ) ) ;
60
+ this . element . on ( 'closeModal ' , _ . bind ( this . closeModal , this ) ) ;
61
61
} ,
62
62
/**
63
- * Returns element from dialog node.
63
+ * Returns element from modal node.
64
64
* @return {Object } - element.
65
65
*/
66
66
_getElem : function ( elem ) {
67
- return this . dialog . find ( elem ) ;
67
+ return this . modal . find ( elem ) ;
68
68
} ,
69
69
/**
70
- * Gets visible dialog count.
71
- * * @return {Number } - visible dialog count.
70
+ * Gets visible modal count.
71
+ * * @return {Number } - visible modal count.
72
72
*/
73
73
_getVisibleCount : function ( ) {
74
- return this . dialogWrapper . find ( '.' + this . options . dialogVisibleClass ) . length ;
74
+ return this . modalWrapper . find ( '.' + this . options . modalVisibleClass ) . length ;
75
75
} ,
76
76
/**
77
- * Gets visible slide type dialog count .
78
- * * @return {Number } - visible dialog count.
77
+ * Gets count of visible modal by slide type .
78
+ * * @return {Number } - visible modal count.
79
79
*/
80
80
_getVisibleSlideCount : function ( ) {
81
- var elems = this . dialogWrapper . find ( '[data-type="slide"]' ) ;
81
+ var elems = this . modalWrapper . find ( '[data-type="slide"]' ) ;
82
82
83
- return elems . filter ( '.' + this . options . dialogVisibleClass ) . length ;
83
+ return elems . filter ( '.' + this . options . modalVisibleClass ) . length ;
84
84
} ,
85
- openDialog : function ( ) {
85
+ openModal : function ( ) {
86
86
var that = this ;
87
87
88
88
this . options . isOpen = true ;
89
89
this . _createOverlay ( ) ;
90
90
this . _setActive ( ) ;
91
- this . dialog . one ( this . options . transitionEvent , function ( ) {
91
+ this . modal . one ( this . options . transitionEvent , function ( ) {
92
92
that . _trigger ( 'opened' ) ;
93
93
} ) ;
94
- this . dialog . addClass ( this . options . dialogVisibleClass ) ;
94
+ this . modal . addClass ( this . options . modalVisibleClass ) ;
95
95
if ( ! this . options . transitionEvent ) {
96
96
that . _trigger ( 'opened' ) ;
97
97
}
98
98
99
99
return this . element ;
100
100
} ,
101
- closeDialog : function ( ) {
101
+ closeModal : function ( ) {
102
102
var that = this ;
103
103
104
104
this . options . isOpen = false ;
105
- this . dialog . one ( this . options . transitionEvent , function ( ) {
105
+ this . modal . one ( this . options . transitionEvent , function ( ) {
106
106
that . _close ( ) ;
107
107
} ) ;
108
- this . dialog . removeClass ( this . options . dialogVisibleClass ) ;
108
+ this . modal . removeClass ( this . options . modalVisibleClass ) ;
109
109
if ( ! this . options . transitionEvent ) {
110
110
that . _close ( ) ;
111
111
}
112
112
113
113
return this . element ;
114
114
} ,
115
115
/**
116
- * Helper for closeDialog function.
116
+ * Helper for closeModal function.
117
117
*/
118
118
_close : function ( ) {
119
- var trigger = _ . bind ( this . _trigger , this , 'closed' , this . dialog ) ;
119
+ var trigger = _ . bind ( this . _trigger , this , 'closed' , this . modal ) ;
120
120
121
121
this . _destroyOverlay ( ) ;
122
122
this . _unsetActive ( ) ;
123
123
_ . defer ( trigger , this ) ;
124
124
} ,
125
125
/**
126
- * Set z-index and margin for dialog and overlay.
126
+ * Set z-index and margin for modal and overlay.
127
127
*/
128
128
_setActive : function ( ) {
129
- var zIndex = this . dialog . zIndex ( ) ;
129
+ var zIndex = this . modal . zIndex ( ) ;
130
130
131
131
this . prevOverlayIndex = this . overlay . zIndex ( ) ;
132
- this . dialog . zIndex ( zIndex + this . _getVisibleCount ( ) ) ;
132
+ this . modal . zIndex ( zIndex + this . _getVisibleCount ( ) ) ;
133
133
this . overlay . zIndex ( zIndex + ( this . _getVisibleCount ( ) - 1 ) ) ;
134
134
if ( this . _getVisibleSlideCount ( ) ) {
135
- this . dialog . css ( 'marginLeft' , this . options . dialogLeftMargin * this . _getVisibleSlideCount ( ) ) ;
135
+ this . modal . css ( 'marginLeft' , this . options . modalLeftMargin * this . _getVisibleSlideCount ( ) ) ;
136
136
}
137
137
} ,
138
138
/**
139
- * Unset styles for dialog and set z-index for previous dialog .
139
+ * Unset styles for modal and set z-index for previous modal .
140
140
*/
141
141
_unsetActive : function ( ) {
142
- this . dialog . removeAttr ( 'style' ) ;
142
+ this . modal . removeAttr ( 'style' ) ;
143
143
if ( this . overlay ) {
144
144
this . overlay . zIndex ( this . prevOverlayIndex ) ;
145
145
}
146
146
} ,
147
147
/**
148
- * Creates wrapper to hold all dialogs .
148
+ * Creates wrapper to hold all modals .
149
149
*/
150
150
_createWrapper : function ( ) {
151
- this . dialogWrapper = $ ( '.' + this . options . wrapperClass ) ;
152
- if ( ! this . dialogWrapper . length ) {
153
- this . dialogWrapper = $ ( '<div></div>' )
151
+ this . modalWrapper = $ ( '.' + this . options . wrapperClass ) ;
152
+ if ( ! this . modalWrapper . length ) {
153
+ this . modalWrapper = $ ( '<div></div>' )
154
154
. addClass ( this . options . wrapperClass )
155
155
. appendTo ( this . options . appendTo ) ;
156
156
}
157
157
} ,
158
158
/**
159
159
* Compile template and append to wrapper.
160
160
*/
161
- _renderDialog : function ( ) {
161
+ _renderModal : function ( ) {
162
162
$ ( template (
163
163
this . options [ this . options . type + 'Tpl' ] ,
164
164
{
165
165
data : this . options
166
- } ) ) . appendTo ( this . dialogWrapper ) ;
167
- this . dialog = this . dialogWrapper . find ( this . options . dialogBlock ) . last ( ) ;
168
- this . element . show ( ) . appendTo ( this . _getElem ( this . options . dialogContent ) ) ;
166
+ } ) ) . appendTo ( this . modalWrapper ) ;
167
+ this . modal = this . modalWrapper . find ( this . options . modalBlock ) . last ( ) ;
168
+ this . element . show ( ) . appendTo ( this . _getElem ( this . options . modalContent ) ) ;
169
169
} ,
170
170
/**
171
171
* Creates buttons pane.
172
172
*/
173
173
_createButtons : function ( ) {
174
174
var that = this ;
175
175
176
- this . buttons = this . _getElem ( this . options . dialogAction ) ;
176
+ this . buttons = this . _getElem ( this . options . modalAction ) ;
177
177
_ . each ( this . options . buttons , function ( btn , key ) {
178
178
var button = that . buttons [ key ] ;
179
179
@@ -189,28 +189,28 @@ define([
189
189
190
190
this . overlay = $ ( '.' + this . options . overlayClass ) ;
191
191
if ( ! this . overlay . length ) {
192
- $ ( this . options . appendTo ) . addClass ( this . options . parentDialogClass ) ;
192
+ $ ( this . options . appendTo ) . addClass ( this . options . parentModalClass ) ;
193
193
this . overlay = $ ( '<div></div>' )
194
194
. addClass ( this . options . overlayClass )
195
- . appendTo ( this . dialogWrapper ) ;
195
+ . appendTo ( this . modalWrapper ) ;
196
196
}
197
197
198
198
events = $ . _data ( this . overlay . get ( 0 ) , 'events' ) ;
199
199
if ( events ) {
200
200
this . prevOverlayHandler = events . click [ 0 ] . handler ;
201
201
}
202
202
this . overlay . unbind ( ) . on ( 'click' , function ( ) {
203
- that . closeDialog ( ) ;
203
+ that . closeModal ( ) ;
204
204
} ) ;
205
205
} ,
206
206
/**
207
207
* Destroy overlay.
208
208
*/
209
209
_destroyOverlay : function ( ) {
210
- var dialogCount = this . dialogWrapper . find ( '.' + this . options . dialogVisibleClass ) . length ;
210
+ var modalCount = this . modalWrapper . find ( '.' + this . options . modalVisibleClass ) . length ;
211
211
212
- if ( ! dialogCount ) {
213
- $ ( this . options . appendTo ) . removeClass ( this . options . parentDialogClass ) ;
212
+ if ( ! modalCount ) {
213
+ $ ( this . options . appendTo ) . removeClass ( this . options . parentModalClass ) ;
214
214
this . overlay . remove ( ) ;
215
215
this . overlay = null ;
216
216
@@ -239,5 +239,5 @@ define([
239
239
}
240
240
} ) ;
241
241
242
- return $ . mage . popup ;
242
+ return $ . mage . modal ;
243
243
} ) ;
0 commit comments