Conditions | 1 |
Paths | 1 |
Total Lines | 257 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
300 | public function repeater_js_template() { |
||
301 | ?> |
||
302 | <script type="text/html" class="customize-control-repeater-content"> |
||
303 | <# var field; var index = data.index; #> |
||
304 | |||
305 | <li class="repeater-row minimized" data-row="{{{ index }}}"> |
||
306 | |||
307 | <div class="repeater-row-header"> |
||
308 | <span class="repeater-row-label"></span> |
||
309 | <i class="dashicons dashicons-arrow-down repeater-minimize"></i> |
||
310 | </div> |
||
311 | <div class="repeater-row-content"> |
||
312 | <# _.each( data, function( field, i ) { #> |
||
313 | |||
314 | <div class="repeater-field repeater-field-{{{ field.type }}}"> |
||
315 | |||
316 | <# if ( 'text' === field.type || 'url' === field.type || 'link' === field.type || 'email' === field.type || 'tel' === field.type || 'date' === field.type || 'number' === field.type ) { #> |
||
317 | <# var fieldExtras = ''; #> |
||
318 | <# if ( 'link' === field.type ) { #> |
||
319 | <# field.type = 'url' #> |
||
320 | <# } #> |
||
321 | |||
322 | <# if ( 'number' === field.type ) { #> |
||
323 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.min ) ) { #> |
||
324 | <# fieldExtras += ' min="' + field.choices.min + '"'; #> |
||
325 | <# } #> |
||
326 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.max ) ) { #> |
||
327 | <# fieldExtras += ' max="' + field.choices.max + '"'; #> |
||
328 | <# } #> |
||
329 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.step ) ) { #> |
||
330 | <# fieldExtras += ' step="' + field.choices.step + '"'; #> |
||
331 | <# } #> |
||
332 | <# } #> |
||
333 | |||
334 | <label> |
||
335 | <# if ( field.label ) { #> |
||
336 | <span class="customize-control-title">{{ field.label }}</span> |
||
337 | <# } #> |
||
338 | <# if ( field.description ) { #> |
||
339 | <span class="description customize-control-description">{{ field.description }}</span> |
||
340 | <# } #> |
||
341 | <input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ fieldExtras }}> |
||
342 | </label> |
||
343 | |||
344 | <# } else if ( 'number' === field.type ) { #> |
||
345 | |||
346 | <label> |
||
347 | <# if ( field.label ) { #> |
||
348 | <span class="customize-control-title">{{ field.label }}</span> |
||
349 | <# } #> |
||
350 | <# if ( field.description ) { #> |
||
351 | <span class="description customize-control-description">{{ field.description }}</span> |
||
352 | <# } #> |
||
353 | <input type="{{ field.type }}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ numberFieldExtras }}> |
||
354 | </label> |
||
355 | |||
356 | <# } else if ( 'hidden' === field.type ) { #> |
||
357 | |||
358 | <input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
||
359 | |||
360 | <# } else if ( 'checkbox' === field.type ) { #> |
||
361 | |||
362 | <label> |
||
363 | <input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
||
364 | <# if ( field.description ) { #> |
||
365 | {{ field.description }} |
||
366 | <# } #> |
||
367 | </label> |
||
368 | |||
369 | <# } else if ( 'select' === field.type ) { #> |
||
370 | |||
371 | <label> |
||
372 | <# if ( field.label ) { #> |
||
373 | <span class="customize-control-title">{{ field.label }}</span> |
||
374 | <# } #> |
||
375 | <# if ( field.description ) { #> |
||
376 | <span class="description customize-control-description">{{ field.description }}</span> |
||
377 | <# } #> |
||
378 | <select data-field="{{{ field.id }}}"<# if ( ! _.isUndefined( field.multiple ) && false !== field.multiple ) { #> multiple="multiple" data-multiple="{{ field.multiple }}"<# } #>> |
||
379 | <# _.each( field.choices, function( choice, i ) { #> |
||
380 | <option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
381 | <# }); #> |
||
382 | </select> |
||
383 | </label> |
||
384 | |||
385 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
386 | |||
387 | <label> |
||
388 | <# if ( field.label ) { #> |
||
389 | <span class="customize-control-title">{{{ data.label }}}</span> |
||
390 | <# } #> |
||
391 | <# if ( field.description ) { #> |
||
392 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
393 | <# } #> |
||
394 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
395 | </label> |
||
396 | |||
397 | <# } else if ( 'radio' === field.type ) { #> |
||
398 | |||
399 | <label> |
||
400 | <# if ( field.label ) { #> |
||
401 | <span class="customize-control-title">{{ field.label }}</span> |
||
402 | <# } #> |
||
403 | <# if ( field.description ) { #> |
||
404 | <span class="description customize-control-description">{{ field.description }}</span> |
||
405 | <# } #> |
||
406 | |||
407 | <# _.each( field.choices, function( choice, i ) { #> |
||
408 | <label> |
||
409 | <input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/> |
||
410 | </label> |
||
411 | <# }); #> |
||
412 | </label> |
||
413 | |||
414 | <# } else if ( 'radio-image' === field.type ) { #> |
||
415 | |||
416 | <label> |
||
417 | <# if ( field.label ) { #> |
||
418 | <span class="customize-control-title">{{ field.label }}</span> |
||
419 | <# } #> |
||
420 | <# if ( field.description ) { #> |
||
421 | <span class="description customize-control-description">{{ field.description }}</span> |
||
422 | <# } #> |
||
423 | |||
424 | <# _.each( field.choices, function( choice, i ) { #> |
||
425 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
426 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"> |
||
427 | <img src="{{ choice }}"> |
||
428 | </label> |
||
429 | </input> |
||
430 | <# }); #> |
||
431 | </label> |
||
432 | |||
433 | <# } else if ( 'color' === field.type ) { #> |
||
434 | |||
435 | <# var defaultValue = ''; |
||
436 | if ( field.default ) { |
||
437 | if ( '#' !== field.default.substring( 0, 1 ) ) { |
||
438 | defaultValue = '#' + field.default; |
||
439 | } else { |
||
440 | defaultValue = field.default; |
||
441 | } |
||
442 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
443 | } #> |
||
444 | <label> |
||
445 | <# if ( field.label ) { #> |
||
446 | <span class="customize-control-title">{{{ field.label }}}</span> |
||
447 | <# } #> |
||
448 | <# if ( field.description ) { #> |
||
449 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
450 | <# } #> |
||
451 | <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php echo esc_attr( $this->l10n( 'hex-value' ) ); ?>" value="{{{ field.default }}}" data-field="{{{ field.id }}}" {{ defaultValue }} /> |
||
452 | |||
453 | </label> |
||
454 | |||
455 | <# } else if ( 'textarea' === field.type ) { #> |
||
456 | |||
457 | <# if ( field.label ) { #> |
||
458 | <span class="customize-control-title">{{ field.label }}</span> |
||
459 | <# } #> |
||
460 | <# if ( field.description ) { #> |
||
461 | <span class="description customize-control-description">{{ field.description }}</span> |
||
462 | <# } #> |
||
463 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
464 | |||
465 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
466 | |||
467 | <label> |
||
468 | <# if ( field.label ) { #> |
||
469 | <span class="customize-control-title">{{ field.label }}</span> |
||
470 | <# } #> |
||
471 | <# if ( field.description ) { #> |
||
472 | <span class="description customize-control-description">{{ field.description }}</span> |
||
473 | <# } #> |
||
474 | </label> |
||
475 | |||
476 | <figure class="kirki-image-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?>" > |
||
477 | <# if ( field.default ) { #> |
||
478 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
479 | <img src="{{{ defaultImageURL }}}"> |
||
480 | <# } else { #> |
||
481 | <?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?> |
||
482 | <# } #> |
||
483 | </figure> |
||
484 | |||
485 | <div class="actions"> |
||
486 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
487 | <button type="button" class="button upload-button" data-label=" <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-image' ) ); ?>" > |
||
488 | <# if ( field.default ) { #> |
||
489 | <?php echo esc_attr( $this->l10n( 'change-image' ) ); ?> |
||
490 | <# } else { #> |
||
491 | <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?> |
||
492 | <# } #> |
||
493 | </button> |
||
494 | <# if ( field.default.id ) { #> |
||
495 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
496 | <# } else { #> |
||
497 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
498 | <# } #> |
||
499 | </div> |
||
500 | |||
501 | <# } else if ( field.type === 'upload' ) { #> |
||
502 | |||
503 | <label> |
||
504 | <# if ( field.label ) { #> |
||
505 | <span class="customize-control-title">{{ field.label }}</span> |
||
506 | <# } #> |
||
507 | <# if ( field.description ) { #> |
||
508 | <span class="description customize-control-description">{{ field.description }}</span> |
||
509 | <# } #> |
||
510 | </label> |
||
511 | |||
512 | <figure class="kirki-file-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?>" > |
||
513 | <# if ( field.default ) { #> |
||
514 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
515 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
516 | <# } else { #> |
||
517 | <?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?> |
||
518 | <# } #> |
||
519 | </figure> |
||
520 | |||
521 | <div class="actions"> |
||
522 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
||
523 | <button type="button" class="button upload-button" data-label="<?php echo esc_attr( $this->l10n( 'add-file' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-file' ) ); ?>" > |
||
524 | <# if ( field.default ) { #> |
||
525 | <?php echo esc_attr( $this->l10n( 'change-file' ) ); ?> |
||
526 | <# } else { #> |
||
527 | <?php echo esc_attr( $this->l10n( 'add-file' ) ); ?> |
||
528 | <# } #> |
||
529 | </button> |
||
530 | <# if ( field.default.id ) { #> |
||
531 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
532 | <# } else { #> |
||
533 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
534 | <# } #> |
||
535 | </div> |
||
536 | |||
537 | <# } else if ( 'custom' === field.type ) { #> |
||
538 | |||
539 | <# if ( field.label ) { #> |
||
540 | <span class="customize-control-title">{{ field.label }}</span> |
||
541 | <# } #> |
||
542 | <# if ( field.description ) { #> |
||
543 | <span class="description customize-control-description">{{ field.description }}</span> |
||
544 | <# } #> |
||
545 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
546 | |||
547 | <# } #> |
||
548 | |||
549 | </div> |
||
550 | <# }); #> |
||
551 | <button type="button" class="button-link repeater-row-remove"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
552 | </div> |
||
553 | </li> |
||
554 | </script> |
||
555 | <?php |
||
556 | } |
||
557 | |||
621 |