@@ -21,6 +21,9 @@ import PreviewCollection from "../preview-collection";
21
21
*/
22
22
export default class Preview extends PreviewCollection {
23
23
public isLiveEditing : KnockoutObservable < boolean > = ko . observable ( false ) ;
24
+ /**
25
+ * Keeps track of number of button item to disable sortable if there is only 1.
26
+ */
24
27
public disableSorting : KnockoutComputed < void > = ko . computed ( ( ) => {
25
28
const sortableElement = $ ( this . wrapperElement ) . find ( ".buttons-container" ) ;
26
29
if ( this . parent . children ( ) . length <= 1 ) {
@@ -93,19 +96,19 @@ export default class Preview extends PreviewCollection {
93
96
console . error ( error ) ;
94
97
} ) ;
95
98
}
96
-
97
99
/**
98
- * Get the sortable options for the tab heading sorting
100
+ * Get the sortable options for the buttons sorting
99
101
*
100
102
* @returns {JQueryUI.SortableOptions }
101
103
*/
102
104
public getSortableOptions ( ) : SortableOptionsInterface {
105
+ let placeholderGhost : JQuery ;
103
106
return {
104
107
handle : ".button-item-drag-handle" ,
105
108
items : ".pagebuilder-content-type-wrapper" ,
106
- containment : "parent" ,
107
- tolerance : "pointer" ,
108
109
cursor : "grabbing" ,
110
+ containment : "parent" ,
111
+ revert : 200 ,
109
112
cursorAt : { left : 25 , top : 25 } ,
110
113
disabled : this . parent . children ( ) . length <= 1 ,
111
114
/**
@@ -133,10 +136,11 @@ export default class Preview extends PreviewCollection {
133
136
element ( item : JQuery ) {
134
137
const placeholder = item
135
138
. clone ( )
136
- . show ( )
137
139
. css ( {
138
140
display : "inline-block" ,
139
- opacity : "0.3" ,
141
+ opacity : 0 ,
142
+ width : item . width ( ) ,
143
+ height : item . height ( ) ,
140
144
} )
141
145
. removeClass ( "focused" )
142
146
. addClass ( "sortable-placeholder" ) ;
@@ -147,6 +151,56 @@ export default class Preview extends PreviewCollection {
147
151
return ;
148
152
} ,
149
153
} ,
154
+ /**
155
+ * Logic for starting the sorting
156
+ * Adding the placeholderGhost
157
+ *
158
+ * @param {Event } event
159
+ * @param {JQueryUI.Sortable } element
160
+ */
161
+ start ( event , element ) {
162
+ placeholderGhost = element . placeholder
163
+ . clone ( )
164
+ . css ( {
165
+ opacity : 0.3 ,
166
+ position : "absolute" ,
167
+ left : element . placeholder . position ( ) . left ,
168
+ top : element . placeholder . position ( ) . top ,
169
+ } ) ;
170
+ element . item . parent ( ) . append ( placeholderGhost ) ;
171
+ events . trigger ( "stage:interactionStart" ) ;
172
+ } ,
173
+ /**
174
+ * Logic for changing element position during the sorting
175
+ * Set the width and height of the moving placeholder animation
176
+ * Add animation of placeholder ghost to the placeholder position
177
+ *
178
+ * @param {Event } event
179
+ * @param {JQueryUI.Sortable } element
180
+ */
181
+ change ( event , element ) {
182
+ element . placeholder . stop ( true , false ) ;
183
+ if ( this . getAttribute ( "data-appearance" ) === "stacked" ) {
184
+ element . placeholder . css ( { height : element . item . height ( ) / 2 } ) ;
185
+ element . placeholder . animate ( { height : element . item . height ( ) } , 200 , "linear" ) ;
186
+ }
187
+ if ( this . getAttribute ( "data-appearance" ) === "inline" ) {
188
+ element . placeholder . css ( { width : element . item . width ( ) / 2 } ) ;
189
+ element . placeholder . animate ( { width : element . item . width ( ) } , 200 , "linear" ) ;
190
+ }
191
+ placeholderGhost . stop ( true , false ) . animate ( {
192
+ left : element . placeholder . position ( ) . left ,
193
+ top : element . placeholder . position ( ) . top ,
194
+ } , 200 ) ;
195
+ } ,
196
+ /**
197
+ * Logic for post sorting
198
+ * Removing the placeholderGhost
199
+ */
200
+ stop ( ) {
201
+ placeholderGhost . remove ( ) ;
202
+ events . trigger ( "stage:interactionStop" ) ;
203
+ } ,
150
204
} ;
151
205
}
152
206
}
0 commit comments