@@ -24,9 +24,9 @@ class Crops extends Select {
2424 * @var string
2525 */
2626 protected $ demo_files = array (
27- 'leather_bag .jpg ' ,
28- 'lady .jpg ' ,
29- 'horses.jpg ' ,
27+ 'docs/addons/objectdetection/dirt-road-1851258_1280 .jpg ' ,
28+ 'docs/model-993911_640 .jpg ' ,
29+ 'docs/shoppable_bag.png ' ,
3030 );
3131
3232 /**
@@ -96,7 +96,6 @@ protected function info_box( $struct ) {
9696 * @return array
9797 */
9898 protected function input ( $ struct ) {
99-
10099 $ mode = $ this ->setting ->get_param ( 'mode ' , 'demos ' );
101100 $ wrapper = $ this ->get_part ( 'div ' );
102101 $ wrapper ['attributes ' ]['class ' ][] = 'cld-size-items ' ;
@@ -112,89 +111,130 @@ protected function input( $struct ) {
112111 }
113112 $ sizes = Utils::get_registered_sizes ();
114113
115- $ selector = $ this ->make_selector ();
116- $ wrapper ['children ' ]['control-selector ' ] = $ selector ;
114+ // Create size selector (tabs).
115+ $ size_selector = $ this ->make_size_selector ( $ sizes );
116+ $ wrapper ['children ' ]['size-selector ' ] = $ size_selector ;
117+
118+ // Get demo files.
119+ $ mode = $ this ->setting ->get_param ( 'mode ' , 'demos ' );
120+
121+ /**
122+ * Filter the demo files.
123+ *
124+ * @hook cloudinary_registered_sizes
125+ * @since 3.1.3
126+ *
127+ * @param $demo_files {array} array of demo files.
128+ *
129+ * @return {array}
130+ */
131+ $ examples = apply_filters ( 'cloudinary_demo_crop_files ' , $ this ->demo_files );
132+
133+ if ( 'full ' === $ mode ) {
134+ $ public_id = $ this ->setting ->get_root_setting ()->get_param ( 'preview_id ' );
135+ if ( ! empty ( $ public_id ) ) {
136+ $ examples = array ( $ public_id );
137+ }
138+ }
139+
140+ // Create content area for each size.
117141 foreach ( $ sizes as $ size => $ details ) {
118142 if ( empty ( $ details ['crop ' ] ) ) {
119143 continue ;
120144 }
121- $ row = $ this ->get_part ( 'div ' );
122- $ row ['attributes ' ]['class ' ][] = 'cld-size-items-item ' ;
123- $ row ['attributes ' ]['class ' ][] = 'crop-preview ' ;
124- $ row ['content ' ] = $ size ;
125-
126- $ image = $ this ->get_part ( 'img ' );
127- $ image ['content ' ] = $ size ;
128- $ size_array = array ();
145+
146+ $ size_content = $ this ->get_part ( 'div ' );
147+ $ size_content ['attributes ' ]['class ' ][] = 'cld-size-content ' ;
148+ $ size_content ['attributes ' ]['data-size ' ] = $ size ;
149+ $ size_content ['render ' ] = true ;
150+
151+ $ size_array = array ();
129152 if ( ! empty ( $ details ['width ' ] ) ) {
130- $ size_array [] = 'w_ ' . $ details ['width ' ];
131- $ image ['attributes ' ]['width ' ] = $ details ['width ' ];
153+ $ size_array [] = 'w_ ' . $ details ['width ' ];
132154 }
133155 if ( ! empty ( $ details ['height ' ] ) ) {
134- $ size_array [] = 'h_ ' . $ details ['height ' ];
135- $ image ['attributes ' ]['height ' ] = $ details ['height ' ];
156+ $ size_array [] = 'h_ ' . $ details ['height ' ];
157+ }
158+ $ size_dimensions = implode ( ', ' , $ size_array );
159+
160+ // Create image previews container.
161+ $ images_container = $ this ->get_part ( 'div ' );
162+ $ images_container ['attributes ' ]['class ' ][] = 'cld-size-images ' ;
163+ $ images_container ['render ' ] = true ;
164+
165+ foreach ( $ examples as $ index => $ file ) {
166+ $ image_wrapper = $ this ->get_part ( 'div ' );
167+ $ image_wrapper ['attributes ' ]['class ' ][] = 'cld-size-image-wrapper ' ;
168+ $ image_wrapper ['render ' ] = true ;
169+
170+ $ image = $ this ->get_part ( 'img ' );
171+ $ image ['attributes ' ]['data-size ' ] = $ size_dimensions ;
172+ $ image ['attributes ' ]['data-file ' ] = $ file ;
173+ $ image ['render ' ] = true ;
174+ if ( ! empty ( $ details ['width ' ] ) ) {
175+ $ image ['attributes ' ]['width ' ] = $ details ['width ' ];
176+ }
177+ if ( ! empty ( $ details ['height ' ] ) ) {
178+ $ image ['attributes ' ]['height ' ] = $ details ['height ' ];
179+ }
180+
181+ $ image_wrapper ['children ' ]['image ' ] = $ image ;
182+ $ images_container ['children ' ][ 'image- ' . $ index ] = $ image_wrapper ;
136183 }
137- $ image ['attributes ' ]['data-size ' ] = implode ( ', ' , $ size_array );
138- $ size_key = $ details ['width ' ] . 'x ' . $ details ['height ' ];
184+
185+ // Create single input field with disable checkbox.
186+ $ size_key = $ details ['width ' ] . 'x ' . $ details ['height ' ];
139187 if ( empty ( $ value [ $ size_key ] ) ) {
140188 $ value [ $ size_key ] = '' ;
141189 }
142- $ row ['children ' ]['size ' ] = $ image ;
143- $ row ['children ' ]['input ' ] = $ this ->make_input ( $ this ->get_name () . '[ ' . $ size_key . '] ' , $ value [ $ size_key ] );
190+
191+ $ input_wrapper = $ this ->make_input ( $ this ->get_name () . '[ ' . $ size_key . '] ' , $ value [ $ size_key ] );
192+
144193 // Set the placeholder.
145194 $ placeholder = 'c_fill,g_auto ' ;
146-
147195 if ( 'thumbnail ' === $ size ) {
148196 $ placeholder = 'c_thumb,g_auto ' ;
149197 }
150- $ row [ ' children ' ][ ' input ' ] ['children ' ]['input ' ]['attributes ' ]['placeholder ' ] = $ placeholder ;
198+ $ input_wrapper ['children ' ]['input ' ]['attributes ' ]['placeholder ' ] = $ placeholder ;
151199
152- $ wrapper ['children ' ][ $ size ] = $ row ;
200+ $ size_content ['children ' ]['input ' ] = $ input_wrapper ;
201+ $ size_content ['children ' ]['images ' ] = $ images_container ;
153202
203+ $ wrapper ['children ' ][ 'content- ' . $ size ] = $ size_content ;
154204 }
155205
156206 return $ wrapper ;
157207 }
158208
159209 /**
160- * Make an image selector.
210+ * Make a size selector (tabs).
211+ *
212+ * @param array $sizes The registered sizes.
213+ * @return array
161214 */
162- protected function make_selector ( ) {
215+ protected function make_size_selector ( $ sizes ) {
163216 $ selector = $ this ->get_part ( 'div ' );
164- $ selector ['attributes ' ]['class ' ][] = 'cld-image -selector ' ;
165- $ mode = $ this -> setting -> get_param ( ' mode ' , ' demos ' ) ;
217+ $ selector ['attributes ' ]['class ' ][] = 'cld-size -selector ' ;
218+ $ selector [ ' render ' ] = true ;
166219
167- /**
168- * Filter the demo files.
169- *
170- * @hook cloudinary_registered_sizes
171- * @since 3.1.3
172- *
173- * @param $demo_files {array} array of demo files.
174- *
175- * @return {array}
176- */
177- $ examples = apply_filters ( 'cloudinary_demo_crop_files ' , $ this ->demo_files );
178- if ( 'full ' === $ mode ) {
179- $ public_id = $ this ->setting ->get_root_setting ()->get_param ( 'preview_id ' );
180- if ( ! empty ( $ public_id ) ) {
181- $ examples = array (
182- $ public_id ,
183- );
220+ $ index = 0 ;
221+ foreach ( $ sizes as $ size => $ details ) {
222+ if ( empty ( $ details ['crop ' ] ) ) {
223+ continue ;
184224 }
185- }
186- foreach ( $ examples as $ index => $ file ) {
187- $ name = pathinfo ( $ file , PATHINFO_FILENAME );
188- $ item = $ this ->get_part ( 'span ' );
189- $ item ['attributes ' ]['data-image ' ] = $ file ;
225+
226+ $ item = $ this ->get_part ( 'span ' );
227+ $ item ['attributes ' ]['data-size ' ] = $ size ;
228+ $ item ['attributes ' ]['class ' ][] = 'cld-size-selector-item ' ;
229+ $ item ['render ' ] = true ;
230+
190231 if ( 0 === $ index ) {
191232 $ item ['attributes ' ]['data-selected ' ] = true ;
192-
193233 }
194- $ item ['attributes ' ]['class ' ][] = 'cld-image-selector-item ' ;
195234
196- $ item ['content ' ] = $ name ;
197- $ selector ['children ' ][ 'image- ' . $ index ] = $ item ;
235+ $ item ['content ' ] = $ size ;
236+ $ selector ['children ' ][ 'size- ' . $ size ] = $ item ;
237+ ++$ index ;
198238 }
199239
200240 return $ selector ;
@@ -215,9 +255,11 @@ protected function make_input( $name, $value ) {
215255 'crop-size-inputs ' ,
216256 );
217257
218- $ label = $ this ->get_part ( 'label ' );
219- $ label ['attributes ' ]['for ' ] = $ name ;
220- $ label ['content ' ] = __ ( 'Disable ' , 'cloudinary ' );
258+ // Disable toggle control.
259+ $ control = $ this ->get_part ( 'label ' );
260+ $ control ['attributes ' ]['class ' ][] = 'cld-input-on-off-control ' ;
261+ $ control ['attributes ' ]['class ' ][] = 'medium ' ;
262+ $ control ['attributes ' ]['for ' ] = $ name ;
221263
222264 $ check = $ this ->get_part ( 'input ' );
223265 $ check ['attributes ' ]['type ' ] = 'checkbox ' ;
@@ -230,15 +272,34 @@ protected function make_input( $name, $value ) {
230272 $ check ['attributes ' ]['checked ' ] = 'checked ' ;
231273 }
232274
275+ $ slider = $ this ->get_part ( 'span ' );
276+ $ slider ['attributes ' ]['class ' ][] = 'cld-input-on-off-control-slider ' ;
277+ $ slider ['render ' ] = true ;
278+
279+ $ control ['children ' ]['input ' ] = $ check ;
280+ $ control ['children ' ]['slider ' ] = $ slider ;
281+
282+ $ label = $ this ->get_part ( 'span ' );
283+ $ label ['attributes ' ]['class ' ] = 'cld-input-on-off-control-label ' ;
284+ $ label ['content ' ] = __ ( 'Disable ' , 'cloudinary ' );
285+
233286 $ input = $ this ->get_part ( 'input ' );
234287 $ input ['attributes ' ]['type ' ] = 'text ' ;
235288 $ input ['attributes ' ]['name ' ] = $ name ;
236289 $ input ['attributes ' ]['value ' ] = '-- ' !== $ value ? $ value : '' ;
237290 $ input ['attributes ' ]['class ' ][] = 'regular-text ' ;
238291
239- $ wrapper ['children ' ]['input ' ] = $ input ;
240- $ wrapper ['children ' ]['label ' ] = $ label ;
241- $ wrapper ['children ' ]['check ' ] = $ check ;
292+ $ clear_button = $ this ->get_part ( 'button ' );
293+ $ clear_button ['attributes ' ]['type ' ] = 'button ' ;
294+ $ clear_button ['attributes ' ]['class ' ][] = 'button ' ;
295+ $ clear_button ['attributes ' ]['class ' ][] = 'clear-crop-input ' ;
296+ $ clear_button ['attributes ' ]['title ' ] = __ ( 'Reset input ' , 'cloudinary ' );
297+ $ clear_button ['content ' ] = Utils::get_inline_svg ( 'css/images/undo.svg ' , false ) . '<span> ' . __ ( 'Reset ' , 'cloudinary ' ) . '</span> ' ;
298+
299+ $ wrapper ['children ' ]['input ' ] = $ input ;
300+ $ wrapper ['children ' ]['button ' ] = $ clear_button ;
301+ $ wrapper ['children ' ]['control ' ] = $ control ;
302+ $ wrapper ['children ' ]['label ' ] = $ label ;
242303
243304 return $ wrapper ;
244305 }
0 commit comments