| Conditions | 1 |
| Paths | 1 |
| Total Lines | 203 |
| 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 ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 341 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 342 | <input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ fieldExtras }}> |
||
| 343 | </label> |
||
| 344 | |||
| 345 | <# } else if ( 'number' === field.type ) { #> |
||
| 346 | |||
| 347 | <label> |
||
| 348 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 349 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 350 | <input type="{{ field.type }}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ numberFieldExtras }}> |
||
| 351 | </label> |
||
| 352 | |||
| 353 | <# } else if ( 'hidden' === field.type ) { #> |
||
| 354 | |||
| 355 | <input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
||
| 356 | |||
| 357 | <# } else if ( 'checkbox' === field.type ) { #> |
||
| 358 | |||
| 359 | <label> |
||
| 360 | <input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
||
| 361 | <# if ( field.description ) { #>{{ field.description }}<# } #> |
||
| 362 | </label> |
||
| 363 | |||
| 364 | <# } else if ( 'select' === field.type ) { #> |
||
| 365 | |||
| 366 | <label> |
||
| 367 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 368 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 369 | <select data-field="{{{ field.id }}}"<# if ( ! _.isUndefined( field.multiple ) && false !== field.multiple ) { #> multiple="multiple" data-multiple="{{ field.multiple }}"<# } #>> |
||
| 370 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 371 | <option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
| 372 | <# }); #> |
||
| 373 | </select> |
||
| 374 | </label> |
||
| 375 | |||
| 376 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
| 377 | |||
| 378 | <label> |
||
| 379 | <# if ( field.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #> |
||
| 380 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 381 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
| 382 | </label> |
||
| 383 | |||
| 384 | <# } else if ( 'radio' === field.type ) { #> |
||
| 385 | |||
| 386 | <label> |
||
| 387 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 388 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 389 | |||
| 390 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 391 | <label><input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/></label> |
||
| 392 | <# }); #> |
||
| 393 | </label> |
||
| 394 | |||
| 395 | <# } else if ( 'radio-image' === field.type ) { #> |
||
| 396 | |||
| 397 | <label> |
||
| 398 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 399 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 400 | |||
| 401 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 402 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
| 403 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"><img src="{{ choice }}"></label> |
||
| 404 | </input> |
||
| 405 | <# }); #> |
||
| 406 | </label> |
||
| 407 | |||
| 408 | <# } else if ( 'color' === field.type ) { #> |
||
| 409 | |||
| 410 | <# var defaultValue = ''; |
||
| 411 | if ( field.default ) { |
||
| 412 | defaultValue = ( '#' !== field.default.substring( 0, 1 ) ) ? '#' + field.default : field.default; |
||
| 413 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
| 414 | } #> |
||
| 415 | <label> |
||
| 416 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 417 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 418 | <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value', 'kirki' ); ?>" value="{{{ field.default }}}" data-field="{{{ field.id }}}" {{ defaultValue }} /> |
||
| 419 | |||
| 420 | </label> |
||
| 421 | |||
| 422 | <# } else if ( 'textarea' === field.type ) { #> |
||
| 423 | |||
| 424 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 425 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 426 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
| 427 | |||
| 428 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
| 429 | |||
| 430 | <label> |
||
| 431 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 432 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 433 | </label> |
||
| 434 | |||
| 435 | <figure class="kirki-image-attachment" data-placeholder="<?php esc_attr_e( 'No Image Selected', 'kirki' ); ?>" > |
||
| 436 | <# if ( field.default ) { #> |
||
| 437 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
| 438 | <img src="{{{ defaultImageURL }}}"> |
||
| 439 | <# } else { #> |
||
| 440 | <?php esc_attr_e( 'No Image Selected', 'kirki' ); ?> |
||
| 441 | <# } #> |
||
| 442 | </figure> |
||
| 443 | |||
| 444 | <div class="actions"> |
||
| 445 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_attr_e( 'Remove', 'kirki' ); ?></button> |
||
| 446 | <button type="button" class="button upload-button" data-label=" <?php esc_attr_e( 'Add Image', 'kirki' ); ?>" data-alt-label="<?php echo esc_attr_e( 'Change Image', 'kirki' ); ?>" > |
||
| 447 | <# if ( field.default ) { #> |
||
| 448 | <?php esc_attr_e( 'Change Image', 'kirki' ); ?> |
||
| 449 | <# } else { #> |
||
| 450 | <?php esc_attr_e( 'Add Image', 'kirki' ); ?> |
||
| 451 | <# } #> |
||
| 452 | </button> |
||
| 453 | <# if ( field.default.id ) { #> |
||
| 454 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
| 455 | <# } else { #> |
||
| 456 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
| 457 | <# } #> |
||
| 458 | </div> |
||
| 459 | |||
| 460 | <# } else if ( field.type === 'upload' ) { #> |
||
| 461 | |||
| 462 | <label> |
||
| 463 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 464 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 465 | </label> |
||
| 466 | |||
| 467 | <figure class="kirki-file-attachment" data-placeholder="<?php esc_attr_e( 'No File Selected', 'kirki' ); ?>" > |
||
| 468 | <# if ( field.default ) { #> |
||
| 469 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
| 470 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
| 471 | <# } else { #> |
||
| 472 | <?php esc_attr_e( 'No File Selected', 'kirki' ); ?> |
||
| 473 | <# } #> |
||
| 474 | </figure> |
||
| 475 | |||
| 476 | <div class="actions"> |
||
| 477 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
||
| 478 | <button type="button" class="button upload-button" data-label="<?php esc_attr_e( 'Add File', 'kirki' ); ?>" data-alt-label="<?php esc_attr_e( 'Change File', 'kirki' ); ?>"> |
||
| 479 | <# if ( field.default ) { #> |
||
| 480 | <?php esc_attr_e( 'Change File', 'kirki' ); ?> |
||
| 481 | <# } else { #> |
||
| 482 | <?php esc_attr_e( 'Add File', 'kirki' ); ?> |
||
| 483 | <# } #> |
||
| 484 | </button> |
||
| 485 | <# if ( field.default.id ) { #> |
||
| 486 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
| 487 | <# } else { #> |
||
| 488 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
| 489 | <# } #> |
||
| 490 | </div> |
||
| 491 | |||
| 492 | <# } else if ( 'custom' === field.type ) { #> |
||
| 493 | |||
| 494 | <# if ( field.label ) { #><span class="customize-control-title">{{ field.label }}</span><# } #> |
||
| 495 | <# if ( field.description ) { #><span class="description customize-control-description">{{ field.description }}</span><# } #> |
||
| 496 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
| 497 | |||
| 498 | <# } #> |
||
| 499 | |||
| 500 | </div> |
||
| 501 | <# }); #> |
||
| 502 | <button type="button" class="button-link repeater-row-remove"><?php esc_attr_e( 'Remove', 'kirki' ); ?></button> |
||
| 503 | </div> |
||
| 504 | </li> |
||
| 505 | </script> |
||
| 506 | <?php |
||
| 507 | } |
||
| 508 | |||
| 541 |