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