Changeset 20295
- Timestamp:
- 03/28/2012 04:14:09 AM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-customize-section.php
r20260 r20295 16 16 public $title = ''; 17 17 public $description = ''; 18 public $ settings;18 public $controls; 19 19 20 20 /** … … 36 36 $this->id = $id; 37 37 38 $this-> settings = array(); // Users cannot customize the $settings array.38 $this->controls = array(); // Users cannot customize the $controls array. 39 39 40 40 return $this; … … 85 85 <ul class="customize-section-content"> 86 86 <?php 87 foreach ( $this-> settings as $setting)88 $ setting->maybe_render();87 foreach ( $this->controls as $control ) 88 $control->maybe_render(); 89 89 ?> 90 90 </ul> -
trunk/wp-includes/class-wp-customize-setting.php
r20290 r20295 11 11 public $manager; 12 12 public $id; 13 public $priority = 10; 14 public $section = ''; 15 public $label = ''; 16 public $control = 'text'; 17 public $control_params = array(); 13 18 14 public $type = 'theme_mod'; 19 public $choices = array();20 15 public $capability = 'edit_theme_options'; 21 16 public $theme_supports = ''; 22 17 public $default = ''; 23 18 public $sanitize_callback = ''; 24 public $visibility;25 19 26 20 protected $id_data = array(); … … 65 59 66 60 /** 67 * Enqueue setting related scripts/styles.68 *69 * @since 3.4.070 */71 public function enqueue() {72 switch( $this->control ) {73 case 'color':74 wp_enqueue_script( 'farbtastic' );75 wp_enqueue_style( 'farbtastic' );76 break;77 case 'upload':78 wp_enqueue_script( 'wp-plupload' );79 break;80 }81 }82 83 /**84 61 * Handle previewing the setting. 85 62 * … … 276 253 return false; 277 254 278 $section = $this->manager->get_section( $this->section );279 if ( isset( $section ) && ! $section->check_capabilities() )280 return false;281 282 255 return true; 283 }284 285 /**286 * Check capabiliites and render the control.287 *288 * @since 3.4.0289 */290 public final function maybe_render() {291 if ( ! $this->check_capabilities() )292 return;293 294 do_action( 'customize_render_setting', $this );295 do_action( 'customize_render_setting_' . $this->id, $this );296 297 $this->render();298 }299 300 /**301 * Render the control. Renders the control wrapper, then calls $this->render_content().302 *303 * @since 3.4.0304 */305 protected function render() {306 307 $id = 'customize-control-' . $this->id;308 $class = 'customize-control customize-control-' . $this->control;309 310 $style = '';311 if ( $this->visibility ) {312 if ( is_string( $this->visibility ) ) {313 $visibility_id = $this->visibility;314 $visibility_value = true;315 } else {316 $visibility_id = $this->visibility[0];317 $visibility_value = $this->visibility[1];318 }319 $visibility_setting = $this->manager->get_setting( $visibility_id );320 321 if ( $visibility_setting && $visibility_value != $visibility_setting->value() )322 $style = 'style="display:none;"';323 }324 325 ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo $style; ?>>326 <?php $this->render_content(); ?>327 </li><?php328 }329 330 /**331 * Render the control's content.332 *333 * Allows the content to be overriden without having to rewrite the wrapper.334 *335 * @since 3.4.0336 */337 protected function render_content() {338 switch( $this->control ) {339 case 'text':340 ?>341 <label>342 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>343 <input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />344 </label>345 <?php346 break;347 case 'color':348 ?>349 <label>350 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>351 <div class="color-picker">352 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />353 <a href="#"></a>354 <div class="color-picker-controls">355 <div class="farbtastic-placeholder"></div>356 <div class="color-picker-details">357 <div class="color-picker-hex">358 <span>#</span>359 <input type="text" />360 </div>361 </div>362 </div>363 </div>364 </label>365 <?php366 break;367 case 'checkbox':368 ?>369 <label>370 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>371 <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); checked( $this->value() ); ?> class="customize-control-content" />372 </label>373 <?php374 break;375 case 'radio':376 if ( empty( $this->choices ) )377 return;378 379 ?>380 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>381 <?php382 foreach ( $this->choices as $value => $label ) :383 ?>384 <label>385 <input type="radio" value="<?php echo esc_attr( $value ); ?>" <?php $this->name(); checked( $this->value(), $value ); ?> />386 <?php echo esc_html( $label ); ?><br/>387 </label>388 <?php389 endforeach;390 break;391 case 'select':392 if ( empty( $this->choices ) )393 return;394 395 ?>396 <label>397 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>398 <select <?php $this->name(); ?> class="customize-control-content">399 <?php400 foreach ( $this->choices as $value => $label )401 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';402 ?>403 </select>404 </label>405 <?php406 break;407 case 'upload':408 ?>409 <label>410 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>411 <div>412 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />413 <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>414 <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>415 </div>416 </label>417 <?php418 break;419 case 'image':420 $value = $this->value();421 422 $image = $value;423 if ( isset( $this->control_params['get_url'] ) )424 $image = call_user_func( $this->control_params['get_url'], $image );425 426 ?>427 <label>428 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>429 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />430 <div class="customize-image-picker">431 <div class="thumbnail">432 <?php if ( empty( $image ) ): ?>433 <img style="display:none;" />434 <?php else: ?>435 <img src="<?php echo esc_url( $image ); ?>" />436 <?php endif; ?>437 </div>438 <div class="actions">439 <a href="#" class="upload"><?php _e( 'Upload New' ); ?></a>440 <a href="#" class="change"><?php _e( 'Change Image' ); ?></a>441 <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>442 </div>443 <div class="library">444 <ul>445 <?php foreach ( $this->control_params['tabs'] as $tab ): ?>446 <li data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>447 <?php echo esc_html( $tab[1] ); ?>448 </li>449 <?php endforeach; ?>450 </ul>451 <?php foreach ( $this->control_params['tabs'] as $tab ): ?>452 <div class="library-content" data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>453 <?php call_user_func( $tab[2] ); ?>454 </div>455 <?php endforeach; ?>456 </div>457 </div>458 </label>459 <?php460 break;461 case 'dropdown-pages':462 printf(463 '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',464 $this->label,465 wp_dropdown_pages(466 array(467 'name' => $this->get_name(),468 'echo' => 0,469 'show_option_none' => __( '— Select —' ),470 'option_none_value' => '0',471 'selected' => get_option( $this->id )472 )473 )474 );475 break;476 }477 }478 479 /**480 * Retrieve the name attribute for an input.481 *482 * @since 3.4.0483 *484 * @return string The name.485 */486 public final function get_name() {487 return self::name_prefix . esc_attr( $this->id );488 }489 490 /**491 * Echo the HTML name attribute for an input.492 *493 * @since 3.4.0494 *495 * @return string The HTML name attribute.496 */497 public final function name() {498 echo 'name="' . $this->get_name() . '"';499 256 } 500 257 -
trunk/wp-includes/class-wp-customize.php
r20290 r20295 15 15 protected $settings = array(); 16 16 protected $sections = array(); 17 protected $controls = array(); 17 18 18 19 /** … … 24 25 require( ABSPATH . WPINC . '/class-wp-customize-setting.php' ); 25 26 require( ABSPATH . WPINC . '/class-wp-customize-section.php' ); 27 require( ABSPATH . WPINC . '/class-wp-customize-control.php' ); 26 28 27 29 add_action( 'setup_theme', array( $this, 'setup_theme' ) ); … … 358 360 * @since 3.4.0 359 361 * 360 * @param string $id A nspecific ID of the setting. Can be a362 * @param string $id A specific ID of the setting. Can be a 361 363 * theme mod or option name. 362 364 * @param array $args Setting arguments. 363 365 */ 364 366 public function add_setting( $id, $args = array() ) { 365 $setting = new WP_Customize_Setting( $this, $id, $args ); 367 if ( is_a( $id, 'WP_Customize_Setting' ) ) 368 $setting = $id; 369 else 370 $setting = new WP_Customize_Setting( $this, $id, $args ); 366 371 367 372 $this->settings[ $setting->id ] = $setting; … … 373 378 * @since 3.4.0 374 379 * 375 * @param string $id A nspecific ID of the setting.380 * @param string $id A specific ID of the setting. 376 381 * @return object The settings object. 377 382 */ … … 386 391 * @since 3.4.0 387 392 * 388 * @param string $id A nspecific ID of the setting.393 * @param string $id A specific ID of the setting. 389 394 */ 390 395 public function remove_setting( $id ) { … … 397 402 * @since 3.4.0 398 403 * 399 * @param string $id A nspecific ID of the section.404 * @param string $id A specific ID of the section. 400 405 * @param array $args Section arguments. 401 406 */ 402 407 public function add_section( $id, $args = array() ) { 403 $section = new WP_Customize_Section( $this, $id, $args ); 408 if ( is_a( $id, 'WP_Customize_Section' ) ) 409 $section = $id; 410 else 411 $section = new WP_Customize_Section( $this, $id, $args ); 404 412 405 413 $this->sections[ $section->id ] = $section; … … 411 419 * @since 3.4.0 412 420 * 413 * @param string $id A nspecific ID of the section.421 * @param string $id A specific ID of the section. 414 422 * @return object The section object. 415 423 */ … … 424 432 * @since 3.4.0 425 433 * 426 * @param string $id A nspecific ID of the section.434 * @param string $id A specific ID of the section. 427 435 */ 428 436 public function remove_section( $id ) { 429 437 unset( $this->sections[ $id ] ); 438 } 439 440 /** 441 * Add a customize control. 442 * 443 * @since 3.4.0 444 * 445 * @param string $id A specific ID of the control. 446 * @param array $args Setting arguments. 447 */ 448 public function add_control( $id, $args = array() ) { 449 if ( is_a( $id, 'WP_Customize_Control' ) ) 450 $control = $id; 451 else 452 $control = new WP_Customize_Control( $this, $id, $args ); 453 454 $this->controls[ $control->id ] = $control; 455 } 456 457 /** 458 * Retrieve a customize control. 459 * 460 * @since 3.4.0 461 * 462 * @param string $id A specific ID of the control. 463 * @return object The settings object. 464 */ 465 public function get_control( $id ) { 466 if ( isset( $this->controls[ $id ] ) ) 467 return $this->controls[ $id ]; 468 } 469 470 /** 471 * Remove a customize setting. 472 * 473 * @since 3.4.0 474 * 475 * @param string $id A specific ID of the control. 476 */ 477 public function remove_control( $id ) { 478 unset( $this->controls[ $id ] ); 430 479 } 431 480 … … 453 502 */ 454 503 public function prepare_controls() { 455 // Prepare settings504 // Prepare controls 456 505 // Reversing makes uasort sort by time added when conflicts occur. 457 506 458 $this-> settings = array_reverse( $this->settings );459 $ settings = array();460 461 foreach ( $this-> settings as $id => $setting) {462 if ( ! isset( $this->sections[ $ setting->section ] ) || ! $setting->check_capabilities() )507 $this->controls = array_reverse( $this->controls ); 508 $controls = array(); 509 510 foreach ( $this->controls as $id => $control ) { 511 if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) 463 512 continue; 464 513 465 $this->sections[ $ setting->section ]->settings[] = $setting;466 $ settings[ $id ] = $setting;467 } 468 $this-> settings = $settings;514 $this->sections[ $control->section ]->controls[] = $control; 515 $controls[ $id ] = $control; 516 } 517 $this->controls = $controls; 469 518 470 519 // Prepare sections … … 474 523 475 524 foreach ( $this->sections as $section ) { 476 if ( ! $section->check_capabilities() || ! $section-> settings )525 if ( ! $section->check_capabilities() || ! $section->controls ) 477 526 continue; 478 527 479 usort( $section-> settings, array( $this, '_cmp_priority' ) );528 usort( $section->controls, array( $this, '_cmp_priority' ) ); 480 529 $sections[] = $section; 481 530 } … … 489 538 */ 490 539 public function enqueue_control_scripts() { 491 foreach ( $this-> settings as $setting) {492 $ setting->enqueue();540 foreach ( $this->controls as $control ) { 541 $control->enqueue(); 493 542 } 494 543 } … … 509 558 510 559 $this->add_setting( 'header_textcolor', array( 511 'label' => 'Text Color', 512 'section' => 'header', 513 'sanitize_callback' => 'sanitize_hexcolor', 514 'control' => 'color', 515 'theme_supports' => array( 'custom-header', 'header-text' ), 516 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 517 ) ); 518 519 /* 520 $this->add_setting( 'display_header', array( 521 'label' => 'Display Text', 560 // @todo: replace with a new accept() setting method 561 // 'sanitize_callback' => 'sanitize_hexcolor', 562 'control' => 'color', 563 'theme_supports' => array( 'custom-header', 'header-text' ), 564 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 565 ) ); 566 567 $this->add_control( 'display_header_text', array( 568 'settings' => 'header_textcolor', 569 'label' => __( 'Display Header Text' ), 570 'section' => 'header', 571 'type' => 'checkbox', 572 ) ); 573 574 $this->add_control( 'header_textcolor', array( 575 'label' => __( 'Text Color' ), 522 576 'section' => 'header', 523 'type' => 'radio', 524 'choices' => array( 525 'show' => 'Yes', 526 'hide' => 'No' 527 ), 528 // Showing header text is actually done by setting header_textcolor to 'blank'. 529 // @todo: Do some JS magic to make this work (since we'll be hiding the textcolor input). 530 'theme_mod' => false, 531 ) ); 532 */ 577 'type' => 'color', 578 ) ); 533 579 534 580 // Input type: checkbox 535 581 // With custom value 536 582 $this->add_setting( 'header_image', array( 583 'default' => get_theme_support( 'custom-header', 'default-image' ), 584 'theme_supports' => 'custom-header', 585 ) ); 586 587 $this->add_control( 'header_image', array( 537 588 'label' => 'Header Image', 538 589 'section' => 'header', 539 'control' => 'image', 540 'default' => get_theme_support( 'custom-header', 'default-image' ), 590 'type' => 'image', 541 591 'control_params' => array( 542 592 'context' => 'custom-header', … … 560 610 // With sanitize_callback 561 611 $this->add_setting( 'background_color', array( 562 'label' => 'Background Color',563 'section' => 'background',564 'control' => 'color',565 612 'default' => get_theme_support( 'custom-background', 'default-color' ), 566 613 'sanitize_callback' => 'sanitize_hexcolor', 614 'theme_supports' => 'custom-background', 615 ) ); 616 617 $this->add_control( 'background_color', array( 618 'label' => __( 'Background Color' ), 619 'section' => 'background', 620 'type' => 'color', 567 621 ) ); 568 622 569 623 $this->add_setting( 'background_image', array( 570 'label' => 'Background Image', 624 'default' => get_theme_support( 'custom-background', 'default-image' ), 625 'theme_supports' => 'custom-background', 626 ) ); 627 628 $this->add_control( 'background_image', array( 629 'label' => __( 'Background Image' ), 571 630 'section' => 'background', 572 'control' => 'upload', 573 'default' => get_theme_support( 'custom-background', 'default-image' ), 631 'type' => 'upload', 574 632 'control_params' => array( 575 633 'context' => 'custom-background', … … 578 636 579 637 $this->add_setting( 'background_repeat', array( 580 'label' => 'Background Repeat', 638 'default' => 'repeat', 639 'theme_supports' => 'custom-background', 640 ) ); 641 642 $this->add_control( 'background_repeat', array( 643 'label' => __( 'Background Repeat' ), 581 644 'section' => 'background', 582 645 'visibility' => 'background_image', 583 ' control'=> 'radio',646 'type' => 'radio', 584 647 'choices' => array( 585 648 'no-repeat' => __('No Repeat'), … … 588 651 'repeat-y' => __('Tile Vertically'), 589 652 ), 590 'default' => 'repeat',591 653 ) ); 592 654 593 655 $this->add_setting( 'background_position_x', array( 594 'label' => 'Background Position', 656 'default' => 'left', 657 'theme_supports' => 'custom-background', 658 ) ); 659 660 $this->add_control( 'background_position_x', array( 661 'label' => __( 'Background Position' ), 595 662 'section' => 'background', 596 663 'visibility' => 'background_image', 597 ' control'=> 'radio',664 'type' => 'radio', 598 665 'choices' => array( 599 666 'left' => __('Left'), … … 601 668 'right' => __('Right'), 602 669 ), 603 'default' => 'left',604 670 ) ); 605 671 606 672 $this->add_setting( 'background_attachment', array( 607 'label' => 'Background Attachment', 673 'default' => 'fixed', 674 'theme_supports' => 'custom-background', 675 ) ); 676 677 $this->add_control( 'background_attachment', array( 678 'label' => __( 'Background Attachment' ), 608 679 'section' => 'background', 609 680 'visibility' => 'background_image', 610 ' control'=> 'radio',681 'type' => 'radio', 611 682 'choices' => array( 612 683 'fixed' => __('Fixed'), 613 684 'scroll' => __('Scroll'), 614 685 ), 615 'default' => 'fixed',616 686 ) ); 617 687 … … 637 707 } 638 708 639 $this->add_setting( "nav_menu_locations[{$location}]", array( 640 'label' => $description, 641 'theme_supports' => 'menus', // Todo: Needs also widgets -- array( 'menus', 'widgets' ) 642 'section' => 'nav', 643 'control' => 'select', 644 'choices' => $choices, 709 $menu_setting_id = "nav_menu_locations[{$location}]"; 710 711 $this->add_setting( $menu_setting_id, array( 645 712 'sanitize_callback' => 'absint', 713 'theme_supports' => 'menus', 714 ) ); 715 716 $this->add_control( $menu_setting_id, array( 717 'label' => $description, 718 'section' => 'nav', 719 'type' => 'select', 720 'choices' => $choices, 646 721 ) ); 647 722 } … … 661 736 662 737 $this->add_setting( 'show_on_front', array( 663 'label' => __( 'Front page displays' ), 738 'default' => get_option( 'show_on_front' ), 739 'capability' => 'manage_options', 740 'type' => 'option', 664 741 // 'theme_supports' => 'static-front-page', 665 'section' => 'static_front_page', 666 'control' => 'radio', 667 'choices' => $choices, 668 'default' => get_option( 'show_on_front' ), 742 ) ); 743 744 $this->add_control( 'show_on_front', array( 745 'label' => __( 'Front page displays' ), 746 'section' => 'static_front_page', 747 'type' => 'radio', 748 'choices' => $choices, 749 ) ); 750 751 $this->add_setting( 'page_on_front', array( 752 'type' => 'option', 753 'capability' => 'manage_options', 754 // 'theme_supports' => 'static-front-page', 755 ) ); 756 757 $this->add_control( 'page_on_front', array( 758 'label' => __( 'Front page' ), 759 'section' => 'static_front_page', 760 'type' => 'dropdown-pages', 761 'visibility' => array( 'show_on_front', 'page' ), 762 ) ); 763 764 $this->add_setting( 'page_for_posts', array( 669 765 'type' => 'option', 670 766 'capability' => 'manage_options', 671 ) );672 673 $this->add_setting( 'page_on_front', array(674 'label' => __( 'Front page' ),675 767 // 'theme_supports' => 'static-front-page', 676 'section' => 'static_front_page', 677 'control' => 'dropdown-pages', 678 'type' => 'option', 679 'capability' => 'manage_options', 680 'visibility' => array( 'show_on_front', 'page' ), 681 ) ); 682 683 $this->add_setting( 'page_for_posts', array( 684 'label' => __( 'Posts page' ), 685 // 'theme_supports' => 'static-front-page', 686 'section' => 'static_front_page', 687 'control' => 'dropdown-pages', 688 'type' => 'option', 689 'capability' => 'manage_options', 690 'visibility' => array( 'show_on_front', 'page' ), 768 ) ); 769 770 $this->add_control( 'page_for_posts', array( 771 'label' => __( 'Posts page' ), 772 'section' => 'static_front_page', 773 'type' => 'dropdown-pages', 774 'visibility' => array( 'show_on_front', 'page' ), 691 775 ) ); 692 776 … … 698 782 699 783 $this->add_setting( 'blogname', array( 700 'label' => __( 'Site Title' ), 701 'section' => 'strings', 702 'default' => get_option( 'blogname' ), 703 'type' => 'option', 704 'capability' => 'manage_options', 784 'default' => get_option( 'blogname' ), 785 'type' => 'option', 786 'capability' => 'manage_options', 787 ) ); 788 789 $this->add_control( 'blogname', array( 790 'label' => __( 'Site Title' ), 791 'section' => 'strings', 705 792 ) ); 706 793 707 794 $this->add_setting( 'blogdescription', array( 708 'label' => __( 'Tagline' ), 709 'section' => 'strings', 710 'default' => get_option( 'blogdescription' ), 711 'type' => 'option', 712 'capability' => 'manage_options', 795 'default' => get_option( 'blogdescription' ), 796 'type' => 'option', 797 'capability' => 'manage_options', 798 ) ); 799 800 $this->add_control( 'blogdescription', array( 801 'label' => __( 'Tagline' ), 802 'section' => 'strings', 713 803 ) ); 714 804 } -
trunk/wp-includes/customize-controls.php
r20276 r20295 96 96 $settings = array( 97 97 'preview' => esc_url( home_url( '/', $scheme ) ), 98 'settings' => array(), 98 99 'controls' => array(), 99 100 'prefix' => WP_Customize_Setting::name_prefix, … … 101 102 102 103 foreach ( $this->settings as $id => $setting ) { 103 $settings[' controls'][ $id ] = array(104 $settings['settings'][ $id ] = array( 104 105 'value' => $setting->value(), 105 'control' => $setting->control,106 'params' => $setting->control_params,107 106 ); 107 } 108 108 109 if ( $setting->visibility ) { 110 if ( is_string( $setting->visibility ) ) { 109 foreach ( $this->controls as $id => $control ) { 110 $settings['controls'][ $id ] = $control->json(); 111 112 if ( $control->visibility ) { 113 if ( is_string( $control->visibility ) ) { 111 114 $settings['controls'][ $id ]['visibility'] = array( 112 'id' => $ setting->visibility,115 'id' => $control->visibility, 113 116 'value' => true, 114 117 ); 115 118 } else { 116 119 $settings['controls'][ $id ]['visibility'] = array( 117 'id' => $ setting->visibility[0],118 'value' => $ setting->visibility[1],120 'id' => $control->visibility[0], 121 'value' => $control->visibility[1], 119 122 ); 120 123 } -
trunk/wp-includes/js/customize-base.dev.js
r20257 r20295 398 398 add: function( id, value ) { 399 399 if ( this.has( id ) ) 400 return ;400 return this.value( id ); 401 401 402 402 this._value[ id ] = value; -
trunk/wp-includes/js/customize-controls.dev.js
r20290 r20295 7 7 * - method - The method to use for syncing. Supports 'refresh' and 'postMessage'. 8 8 */ 9 api. Control= api.Value.extend({9 api.Setting = api.Value.extend({ 10 10 initialize: function( id, value, options ) { 11 var name = '[name="' + api.settings.prefix + id + '"]'; 12 13 this.params = {}; 11 var element; 12 14 13 api.Value.prototype.initialize.call( this, value, options ); 15 14 16 15 this.id = id; 17 this.container = $( '#customize-control-' + id );18 this.element = this.element || new api.Element( this.container.find( name ) );19 20 16 this.method = this.method || 'refresh'; 17 18 element = $( '<input />', { 19 type: 'hidden', 20 value: this.get(), 21 name: api.settings.prefix + id 22 }); 23 24 element.appendTo( this.previewer.form ); 25 this.element = new api.Element( element ); 21 26 22 27 this.element.link( this ); … … 35 40 }); 36 41 42 api.Control = api.Class.extend({ 43 initialize: function( id, options ) { 44 var control = this, 45 nodes, radios, settings; 46 47 this.params = {}; 48 $.extend( this, options || {} ); 49 50 this.id = id; 51 this.container = $( '#customize-control-' + id ); 52 53 settings = $.map( this.params.settings, function( value ) { 54 return value; 55 }); 56 57 api.apply( api, settings.concat( function() { 58 var key; 59 60 control.settings = {}; 61 for ( key in control.params.settings ) { 62 control.settings[ key ] = api( control.params.settings[ key ] ); 63 } 64 65 control.setting = control.settings['default'] || null; 66 control.ready(); 67 }) ); 68 69 control.elements = []; 70 71 nodes = this.container.find('[data-customize-setting-link]'); 72 radios = {}; 73 74 nodes.each( function() { 75 var node = $(this), 76 name; 77 78 if ( node.is(':radio') ) { 79 name = node.prop('name'); 80 if ( radios[ name ] ) 81 return; 82 83 radios[ name ] = true; 84 node = nodes.filter( '[name="' + name + '"]' ); 85 } 86 87 api( node.data('customizeSettingLink'), function( setting ) { 88 var element = new api.Element( node ); 89 control.elements.push( element ); 90 element.link( setting ).bind( function( to ) { 91 setting( to ); 92 }); 93 }); 94 }); 95 }, 96 ready: function() {} 97 }); 98 37 99 api.ColorControl = api.Control.extend({ 38 initialize: function( id, value, options) {39 var self= this,100 ready: function() { 101 var control = this, 40 102 picker, ui, text, toggle, update; 41 42 api.Control.prototype.initialize.call( this, id, value, options );43 103 44 104 picker = this.container.find( '.color-picker' ); … … 48 108 color = '#' + color; 49 109 toggle.css( 'background', color ); 50 self.farbtastic.setColor( color );110 control.farbtastic.setColor( color ); 51 111 }; 52 53 this.input = new api.Element( ui.find( 'input' ) ); // Find text input.54 55 this.link( this.input );56 this.input.link( this );57 112 58 113 picker.on( 'click', 'a', function() { … … 61 116 62 117 this.farbtastic = $.farbtastic( picker.find('.farbtastic-placeholder'), function( color ) { 63 self.set( color.replace( '#', '' ) ); 64 }); 65 66 this.bind( update ); 67 update( this() ); 68 }, 69 validate: function( to ) { 70 return /^[a-fA-F0-9]{3}([a-fA-F0-9]{3})?$/.test( to ) ? to : null; 118 control.setting.set( color.replace( '#', '' ) ); 119 }); 120 121 this.setting.bind( update ); 122 update( this.setting() ); 71 123 } 124 // , 125 // validate: function( to ) { 126 // return /^[a-fA-F0-9]{3}([a-fA-F0-9]{3})?$/.test( to ) ? to : null; 127 // } 72 128 }); 73 129 74 130 api.UploadControl = api.Control.extend({ 75 initialize: function( id, value, options) {131 ready: function() { 76 132 var control = this; 77 133 78 api.Control.prototype.initialize.call( this, id, value, options );79 134 this.params.removed = this.params.removed || ''; 80 135 … … 82 137 browser: this.container.find('.upload'), 83 138 success: function( attachment ) { 84 control.set ( attachment.url );139 control.setting.set( attachment.url ); 85 140 } 86 141 }); … … 88 143 this.remover = this.container.find('.remove'); 89 144 this.remover.click( function( event ) { 90 control.set ( control.params.removed );145 control.setting.set( control.params.removed ); 91 146 event.preventDefault(); 92 147 }); 93 148 94 this.bind( this.removerVisibility ); 95 this.removerVisibility( this.get() ); 149 this.removerVisibility = $.proxy( this.removerVisibility, this ); 150 this.setting.bind( this.removerVisibility ); 151 this.removerVisibility( this.setting.get() ); 96 152 97 153 if ( this.params.context ) … … 104 160 105 161 api.ImageControl = api.UploadControl.extend({ 106 initialize: function( id, value, options ) {162 ready: function( id, value, options ) { 107 163 var control = this; 108 164 109 api.UploadControl.prototype.initialize.call( this, id, value, options ); 110 111 this.thumbnail = this.container.find('.thumbnail img'); 112 this.bind( this.thumbnailSrc ); 165 this.thumbnail = this.container.find('.thumbnail img'); 166 this.thumbnailSrc = $.proxy( this.thumbnailSrc, this ); 167 this.setting.bind( this.thumbnailSrc ); 113 168 114 169 this.library = this.container.find('.library'); … … 138 193 139 194 this.library.on( 'click', 'a', function( event ) { 140 control.set ( $(this).attr('href') );195 control.setting.set( $(this).attr('href') ); 141 196 event.preventDefault(); 142 197 }); … … 152 207 // Change objects contained within the main customize object to Settings. 153 208 api.defaultConstructor = api.Setting; 209 210 // Create the collection of Control objects. 211 api.control = new api.Values({ defaultConstructor: api.Control }); 154 212 155 213 api.Previewer = api.Messenger.extend({ … … 273 331 * ===================================================================== */ 274 332 275 api.control s= {333 api.controlConstructor = { 276 334 color: api.ColorControl, 277 335 upload: api.UploadControl, … … 290 348 }); 291 349 350 $.each( api.settings.settings, function( id, data ) { 351 api.set( id, id, data.value, { 352 previewer: previewer 353 } ); 354 }); 355 292 356 $.each( api.settings.controls, function( id, data ) { 293 var constructor = api.control s[ data.control] || api.Control,357 var constructor = api.controlConstructor[ data.type ] || api.Control, 294 358 control; 295 359 296 control = api. add( id, new constructor( id, data.value, {360 control = api.control.add( id, new constructor( id, { 297 361 params: data.params, 298 362 previewer: previewer … … 327 391 328 392 // Background color uses postMessage by default 329 api ( 'background_color', function( control ) {393 api.control( 'background_color', function( control ) { 330 394 control.method = 'postMessage'; 331 395 }); 396 397 api.control( 'display_header_text', function( control ) { 398 var last = ''; 399 400 control.elements[0].unlink(); 401 402 control.element = new api.Element( control.container.find('input') ); 403 control.element.set( 'blank' !== control.setting() ); 404 405 control.element.bind( function( to ) { 406 if ( ! to ) 407 last = api.get( 'header_textcolor' ); 408 409 control.setting.set( to ? last : 'blank' ); 410 }); 411 412 control.setting.bind( function( to ) { 413 control.element.set( 'blank' !== to ); 414 }); 415 }); 332 416 }); 333 417 -
trunk/wp-includes/js/plupload/wp-plupload.dev.js
r20179 r20295 67 67 68 68 this.uploader.bind( 'FileUploaded', function( up, file, response ) { 69 response = JSON.parse( response.response ); 69 try { 70 response = JSON.parse( response.response ); 71 } catch ( e ) { 72 return self.error( pluploadL10n.default_error, e ); 73 } 70 74 71 75 if ( ! response || ! response.type || ! response.data )
Note: See TracChangeset
for help on using the changeset viewer.