Conditions | 1 |
Paths | 1 |
Total Lines | 233 |
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 |
||
303 | public function repeater_js_template() { |
||
304 | ?> |
||
305 | <script type="text/html" class="customize-control-repeater-content"> |
||
306 | <# var field; var index = data.index; #> |
||
307 | |||
308 | <li class="repeater-row minimized" data-row="{{{ index }}}"> |
||
309 | |||
310 | <div class="repeater-row-header"> |
||
311 | <span class="repeater-row-label"></span> |
||
312 | <i class="dashicons dashicons-arrow-down repeater-minimize"></i> |
||
313 | </div> |
||
314 | <div class="repeater-row-content"> |
||
315 | <# _.each( data, function( field, i ) { #> |
||
316 | |||
317 | <div class="repeater-field repeater-field-{{{ field.type }}}"> |
||
318 | |||
319 | <# if ( 'text' === field.type || 'url' === field.type || 'link' === field.type || 'email' === field.type || 'tel' === field.type || 'date' === field.type ) { #> |
||
320 | |||
321 | <# if ( 'link' === field.type ) { #> |
||
322 | <# field.type = 'url' #> |
||
323 | <# } #> |
||
324 | |||
325 | <label> |
||
326 | <# if ( field.label ) { #> |
||
327 | <span class="customize-control-title">{{ field.label }}</span> |
||
328 | <# } #> |
||
329 | <# if ( field.description ) { #> |
||
330 | <span class="description customize-control-description">{{ field.description }}</span> |
||
331 | <# } #> |
||
332 | <input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"> |
||
333 | </label> |
||
334 | |||
335 | <# } else if ( 'hidden' === field.type ) { #> |
||
336 | |||
337 | <input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
||
338 | |||
339 | <# } else if ( 'checkbox' === field.type ) { #> |
||
340 | |||
341 | <label> |
||
342 | <input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
||
343 | <# if ( field.description ) { #> |
||
344 | {{ field.description }} |
||
345 | <# } #> |
||
346 | </label> |
||
347 | |||
348 | <# } else if ( 'select' === field.type ) { #> |
||
349 | |||
350 | <label> |
||
351 | <# if ( field.label ) { #> |
||
352 | <span class="customize-control-title">{{ field.label }}</span> |
||
353 | <# } #> |
||
354 | <# if ( field.description ) { #> |
||
355 | <span class="description customize-control-description">{{ field.description }}</span> |
||
356 | <# } #> |
||
357 | <select data-field="{{{ field.id }}}"<# if ( 'undefined' !== field.multiple && false !== field.multiple ) { #> multiple="multiple"<# } #>> |
||
358 | <# _.each( field.choices, function( choice, i ) { #> |
||
359 | <option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
360 | <# }); #> |
||
361 | </select> |
||
362 | </label> |
||
363 | |||
364 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
365 | |||
366 | <label> |
||
367 | <# if ( field.label ) { #> |
||
368 | <span class="customize-control-title">{{{ data.label }}}</span> |
||
369 | <# } #> |
||
370 | <# if ( field.description ) { #> |
||
371 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
372 | <# } #> |
||
373 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
374 | </label> |
||
375 | |||
376 | <# } else if ( 'radio' === field.type ) { #> |
||
377 | |||
378 | <label> |
||
379 | <# if ( field.label ) { #> |
||
380 | <span class="customize-control-title">{{ field.label }}</span> |
||
381 | <# } #> |
||
382 | <# if ( field.description ) { #> |
||
383 | <span class="description customize-control-description">{{ field.description }}</span> |
||
384 | <# } #> |
||
385 | |||
386 | <# _.each( field.choices, function( choice, i ) { #> |
||
387 | <label> |
||
388 | <input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/> |
||
389 | </label> |
||
390 | <# }); #> |
||
391 | </label> |
||
392 | |||
393 | <# } else if ( 'radio-image' === field.type ) { #> |
||
394 | |||
395 | <label> |
||
396 | <# if ( field.label ) { #> |
||
397 | <span class="customize-control-title">{{ field.label }}</span> |
||
398 | <# } #> |
||
399 | <# if ( field.description ) { #> |
||
400 | <span class="description customize-control-description">{{ field.description }}</span> |
||
401 | <# } #> |
||
402 | |||
403 | <# _.each( field.choices, function( choice, i ) { #> |
||
404 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
405 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"> |
||
406 | <img src="{{ choice }}"> |
||
407 | </label> |
||
408 | </input> |
||
409 | <# }); #> |
||
410 | </label> |
||
411 | |||
412 | <# } else if ( 'color' === field.type ) { #> |
||
413 | |||
414 | <# var defaultValue = ''; |
||
415 | if ( field.default ) { |
||
416 | if ( '#' !== field.default.substring( 0, 1 ) ) { |
||
417 | defaultValue = '#' + field.default; |
||
418 | } else { |
||
419 | defaultValue = field.default; |
||
420 | } |
||
421 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
422 | } #> |
||
423 | <label> |
||
424 | <# if ( field.label ) { #> |
||
425 | <span class="customize-control-title">{{{ field.label }}}</span> |
||
426 | <# } #> |
||
427 | <# if ( field.description ) { #> |
||
428 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
429 | <# } #> |
||
430 | <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 }} /> |
||
431 | |||
432 | </label> |
||
433 | |||
434 | <# } else if ( 'textarea' === field.type ) { #> |
||
435 | |||
436 | <# if ( field.label ) { #> |
||
437 | <span class="customize-control-title">{{ field.label }}</span> |
||
438 | <# } #> |
||
439 | <# if ( field.description ) { #> |
||
440 | <span class="description customize-control-description">{{ field.description }}</span> |
||
441 | <# } #> |
||
442 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
443 | |||
444 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
445 | |||
446 | <label> |
||
447 | <# if ( field.label ) { #> |
||
448 | <span class="customize-control-title">{{ field.label }}</span> |
||
449 | <# } #> |
||
450 | <# if ( field.description ) { #> |
||
451 | <span class="description customize-control-description">{{ field.description }}</span> |
||
452 | <# } #> |
||
453 | </label> |
||
454 | |||
455 | <figure class="kirki-image-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?>" > |
||
456 | <# if ( field.default ) { #> |
||
457 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
458 | <img src="{{{ defaultImageURL }}}"> |
||
459 | <# } else { #> |
||
460 | <?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?> |
||
461 | <# } #> |
||
462 | </figure> |
||
463 | |||
464 | <div class="actions"> |
||
465 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
466 | <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' ) ); ?>" > |
||
467 | <# if ( field.default ) { #> |
||
468 | <?php echo esc_attr( $this->l10n( 'change-image' ) ); ?> |
||
469 | <# } else { #> |
||
470 | <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?> |
||
471 | <# } #> |
||
472 | </button> |
||
473 | <# if ( field.default.id ) { #> |
||
474 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
475 | <# } else { #> |
||
476 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
477 | <# } #> |
||
478 | </div> |
||
479 | |||
480 | <# } else if ( field.type === 'upload' ) { #> |
||
481 | |||
482 | <label> |
||
483 | <# if ( field.label ) { #> |
||
484 | <span class="customize-control-title">{{ field.label }}</span> |
||
485 | <# } #> |
||
486 | <# if ( field.description ) { #> |
||
487 | <span class="description customize-control-description">{{ field.description }}</span> |
||
488 | <# } #> |
||
489 | </label> |
||
490 | |||
491 | <figure class="kirki-file-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?>" > |
||
492 | <# if ( field.default ) { #> |
||
493 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
494 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
495 | <# } else { #> |
||
496 | <?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?> |
||
497 | <# } #> |
||
498 | </figure> |
||
499 | |||
500 | <div class="actions"> |
||
501 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
||
502 | <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' ) ); ?>" > |
||
503 | <# if ( field.default ) { #> |
||
504 | <?php echo esc_attr( $this->l10n( 'change-file' ) ); ?> |
||
505 | <# } else { #> |
||
506 | <?php echo esc_attr( $this->l10n( 'add-file' ) ); ?> |
||
507 | <# } #> |
||
508 | </button> |
||
509 | <# if ( field.default.id ) { #> |
||
510 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
511 | <# } else { #> |
||
512 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
513 | <# } #> |
||
514 | </div> |
||
515 | |||
516 | <# } else if ( 'custom' === field.type ) { #> |
||
517 | |||
518 | <# if ( field.label ) { #> |
||
519 | <span class="customize-control-title">{{ field.label }}</span> |
||
520 | <# } #> |
||
521 | <# if ( field.description ) { #> |
||
522 | <span class="description customize-control-description">{{ field.description }}</span> |
||
523 | <# } #> |
||
524 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
525 | |||
526 | <# } #> |
||
527 | |||
528 | </div> |
||
529 | <# }); #> |
||
530 | <button type="button" class="button-link repeater-row-remove"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
531 | </div> |
||
532 | </li> |
||
533 | </script> |
||
534 | <?php |
||
535 | } |
||
536 | |||
600 |