Ticket #30409: 30409.4.1.diff
| File 30409.4.1.diff, 18.2 KB (added by , 11 years ago) |
|---|
-
src/wp-content/themes/twentyfifteen/inc/customizer.php
27 27 'transport' => 'postMessage', 28 28 ) ); 29 29 30 $wp_customize->add_setting( 'color_scheme_css', array(31 'default' => '',32 'transport' => 'postMessage',33 ) );34 35 30 $wp_customize->add_control( 'color_scheme', array( 36 31 'label' => esc_html__( 'Base Color Scheme', 'twentyfifteen' ), 37 32 'section' => 'colors', … … 231 226 */ 232 227 function twentyfifteen_color_scheme_css() { 233 228 $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); 234 $color_scheme_css = get_theme_mod( 'color_scheme_css', '' );235 229 236 230 // Don't do anything if the default color scheme is selected. 237 if ( 'default' === $color_scheme_option || empty( $color_scheme_css )) {231 if ( 'default' === $color_scheme_option ) { 238 232 return; 239 233 } 240 234 235 $color_scheme = twentyfifteen_get_color_scheme(); 236 237 $colors = array( 238 'background_color' => $color_scheme[0], 239 'header_background_color' => $color_scheme[1], 240 'box_background_color' => $color_scheme[2], 241 'textcolor' => $color_scheme[3], 242 'secondary_sidebar_textcolor' => $color_scheme[4], 243 'meta_box_background_color' => $color_scheme[5], 244 ); 245 246 $color_scheme_css = twentyfifteen_get_color_scheme_css( $colors ); 247 241 248 wp_add_inline_style( 'twentyfifteen-style', $color_scheme_css ); 242 249 } 243 250 add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' ); … … 266 273 add_action( 'customize_preview_init', 'twentyfifteen_customize_preview_js' ); 267 274 268 275 /** 269 * Output an Underscore template for generating CSS for the color scheme.276 * Returns CSS for the color schemes. 270 277 * 271 * The template generates the css dynamically for instant display in the Customizer 272 * preview, and to be saved in a `theme_mod` for display on the front-end. 278 * @since Twenty Fifteen 1.0 273 279 * 274 * @since Twenty Fifteen 1.0 280 * @param array $colors Color scheme colors. 281 * @return string Color scheme CSS. 275 282 */ 276 function twentyfifteen_color_scheme_css_template() { 277 ?> 278 <script type="text/html" id="tmpl-twentyfifteen-color-scheme"> 283 function twentyfifteen_get_color_scheme_css( $colors ) { 284 $colors = wp_parse_args( $colors, array( 285 'background_color' => '', 286 'header_background_color' => '', 287 'box_background_color' => '', 288 'textcolor' => '', 289 'secondary_textcolor' => '', // Will be calculated from textcolor if omitted 290 'border_color' => '', // Will be calculated from textcolor if omitted 291 'border_focus_color' => '', // Will be calculated from textcolor if omitted 292 'sidebar_textcolor' => '', // Will be calculated from secondary_sidebar_textcolor if omitted 293 'sidebar_border_color' => '', // Will be calculated from secondary_sidebar_textcolor if omitted 294 'sidebar_border_focus_color' => '', // Will be calculated from secondary_sidebar_textcolor if omitted 295 'secondary_sidebar_textcolor' => '', 296 'meta_box_background_color' => '', 297 ) ); 298 299 // Calculate textcolor derivatives if any have been omitted 300 if ( empty( $colors['secondary_textcolor'] ) || empty( $colors['border_color'] ) || empty( $colors['border_focus_color'] ) ) { 301 $textcolor_rgb = twentyfifteen_hex2rgb( $colors['textcolor'] ); 302 303 if ( empty( $colors['secondary_textcolor'] ) ) { 304 $colors['secondary_textcolor'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $textcolor_rgb ); 305 } 306 307 if ( empty( $colors['border_color'] ) ) { 308 $colors['border_color'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $textcolor_rgb ); 309 } 310 311 if ( empty( $colors['border_focus_color'] ) ) { 312 $colors['border_focus_color'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $textcolor_rgb ); 313 } 314 } 315 316 // Calculate secondary_sidebar_textcolor derivatives if any have been omitted 317 if ( empty( $colors['sidebar_textcolor'] ) || empty( $colors['sidebar_border_color'] ) || empty( $colors['sidebar_border_focus_color'] ) ) { 318 $secondary_sidebar_textcolor_rgb = twentyfifteen_hex2rgb( $colors['secondary_sidebar_textcolor'] ); 319 320 if ( empty( $colors['sidebar_textcolor'] ) ) { 321 $colors['sidebar_textcolor'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $secondary_sidebar_textcolor_rgb ); 322 } 323 324 if ( empty( $colors['sidebar_border_color'] ) ) { 325 $colors['sidebar_border_color'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $secondary_sidebar_textcolor_rgb ); 326 } 327 328 if ( empty( $colors['sidebar_border_focus_color'] ) ) { 329 $colors['sidebar_border_focus_color'] = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $secondary_sidebar_textcolor_rgb ); 330 } 331 } 332 333 $css = <<<CSS 279 334 /* Color Scheme */ 280 335 281 336 /* Background Color */ 282 337 body { 283 background-color: { { data.background_color }};338 background-color: {$colors['background_color']}; 284 339 } 285 340 286 341 /* Sidebar Background Color */ 287 342 body:before, 288 343 .site-header { 289 background-color: { { data.header_background_color }};344 background-color: {$colors['header_background_color']}; 290 345 } 291 346 292 347 /* Box Background Color */ … … 298 353 .page-header, 299 354 .page-content, 300 355 .comments-area { 301 background-color: { { data.box_background_color }};356 background-color: {$colors['box_background_color']}; 302 357 } 303 358 304 359 /* Box Background Color */ … … 315 370 .page-links a:hover, 316 371 .page-links a:focus, 317 372 .sticky-post { 318 color: { { data.box_background_color }};373 color: {$colors['box_background_color']}; 319 374 } 320 375 321 376 /* Main Text Color */ … … 328 383 .widget_calendar tbody a, 329 384 .page-links a, 330 385 .sticky-post { 331 background-color: { { data.textcolor }};386 background-color: {$colors['textcolor']}; 332 387 } 333 388 334 389 /* Main Text Color */ … … 352 407 .comment-list .reply a:focus, 353 408 .site-info a:hover, 354 409 .site-info a:focus { 355 color: { { data.textcolor }};410 color: {$colors['textcolor']}; 356 411 } 357 412 358 413 /* Main Text Color */ … … 369 424 .pingback .edit-link a:hover, 370 425 .comment-list .reply a:hover, 371 426 .site-info a:hover { 372 border-color: { { data.textcolor }};427 border-color: {$colors['textcolor']}; 373 428 } 374 429 375 430 /* Secondary Text Color */ … … 389 444 .widget_calendar tbody a:focus, 390 445 .page-links a:hover, 391 446 .page-links a:focus { 392 background-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */393 background-color: { { data.secondary_textcolor }};447 background-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 448 background-color: {$colors['secondary_textcolor']}; 394 449 } 395 450 396 451 /* Secondary Text Color */ … … 429 484 .wp-caption-text, 430 485 .gallery-caption, 431 486 .comment-list .reply a { 432 color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */433 color: { { data.secondary_textcolor }};487 color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 488 color: {$colors['secondary_textcolor']}; 434 489 } 435 490 436 491 /* Secondary Text Color */ … … 437 492 blockquote, 438 493 .logged-in-as a:hover, 439 494 .comment-author a:hover { 440 border-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */441 border-color: { { data.secondary_textcolor }};495 border-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 496 border-color: {$colors['secondary_textcolor']}; 442 497 } 443 498 444 499 /* Border Color */ … … 445 500 hr, 446 501 .dropdown-toggle:hover, 447 502 .dropdown-toggle:focus { 448 background-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */449 background-color: { { data.border_color }};503 background-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 504 background-color: {$colors['border_color']}; 450 505 } 451 506 452 507 /* Border Color */ … … 481 536 .comment-list .trackback, 482 537 .comment-list .reply a, 483 538 .no-comments { 484 border-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */485 border-color: { { data.border_color }};539 border-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 540 border-color: {$colors['border_color']}; 486 541 } 487 542 488 543 /* Border Focus Color */ … … 489 544 a:focus, 490 545 button:focus, 491 546 input:focus { 492 outline-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */493 outline-color: { { data.border_focus_color }};547 outline-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 548 outline-color: {$colors['border_focus_color']}; 494 549 } 495 550 496 551 input:focus, 497 552 textarea:focus { 498 border-color: { { data.textcolor }}; /* Fallback for IE7 and IE8 */499 border-color: { { data.border_focus_color }};553 border-color: {$colors['textcolor']}; /* Fallback for IE7 and IE8 */ 554 border-color: {$colors['border_focus_color']}; 500 555 } 501 556 502 557 /* Sidebar Link Color */ 503 558 .secondary-toggle:before { 504 color: { { data.sidebar_textcolor }};559 color: {$colors['sidebar_textcolor']}; 505 560 } 506 561 507 562 .site-title a, 508 563 .site-description { 509 color: { { data.sidebar_textcolor }};564 color: {$colors['sidebar_textcolor']}; 510 565 } 511 566 512 567 /* Sidebar Text Color */ 513 568 .site-title a:hover, 514 569 .site-title a:focus { 515 color: { { data.secondary_sidebar_textcolor }};570 color: {$colors['secondary_sidebar_textcolor']}; 516 571 } 517 572 518 573 /* Sidebar Border Color */ 519 574 .secondary-toggle { 520 border-color: { { data.sidebar_textcolor }}; /* Fallback for IE7 and IE8 */521 border-color: { { data.sidebar_border_color }};575 border-color: {$colors['sidebar_textcolor']}; /* Fallback for IE7 and IE8 */ 576 border-color: {$colors['sidebar_border_color']}; 522 577 } 523 578 524 579 /* Sidebar Border Focus Color */ 525 580 .secondary-toggle:hover, 526 581 .secondary-toggle:focus { 527 border-color: { { data.sidebar_textcolor }}; /* Fallback for IE7 and IE8 */528 border-color: { { data.sidebar_border_focus_color }};582 border-color: {$colors['sidebar_textcolor']}; /* Fallback for IE7 and IE8 */ 583 border-color: {$colors['sidebar_border_focus_color']}; 529 584 } 530 585 531 586 .site-title a { 532 outline-color: { { data.sidebar_textcolor }}; /* Fallback for IE7 and IE8 */533 outline-color: { { data.sidebar_border_focus_color }};587 outline-color: {$colors['sidebar_textcolor']}; /* Fallback for IE7 and IE8 */ 588 outline-color: {$colors['sidebar_border_focus_color']}; 534 589 } 535 590 536 591 /* Meta Background Color */ 537 592 .entry-footer { 538 background-color: { { data.meta_box_background_color }};593 background-color: {$colors['meta_box_background_color']}; 539 594 } 540 595 541 596 @media screen and (min-width: 38.75em) { 542 597 /* Main Text Color */ 543 598 .page-header { 544 border-color: { { data.textcolor }};599 border-color: {$colors['textcolor']}; 545 600 } 546 601 } 547 602 … … 560 615 .widget_calendar tbody a, 561 616 .widget_calendar tbody a:hover, 562 617 .widget_calendar tbody a:focus { 563 color: { { data.header_background_color }};618 color: {$colors['header_background_color']}; 564 619 } 565 620 566 621 /* Sidebar Link Color */ … … 569 624 .widget-title, 570 625 .widget blockquote cite, 571 626 .widget blockquote small { 572 color: { { data.sidebar_textcolor }};627 color: {$colors['sidebar_textcolor']}; 573 628 } 574 629 575 630 .widget button, … … 577 632 .widget input[type="reset"], 578 633 .widget input[type="submit"], 579 634 .widget_calendar tbody a { 580 background-color: { { data.sidebar_textcolor }};635 background-color: {$colors['sidebar_textcolor']}; 581 636 } 582 637 583 638 .textwidget a { 584 border-color: { { data.sidebar_textcolor }};639 border-color: {$colors['sidebar_textcolor']}; 585 640 } 586 641 587 642 /* Sidebar Text Color */ … … 592 647 .widget blockquote, 593 648 .widget .wp-caption-text, 594 649 .widget .gallery-caption { 595 color: { { data.secondary_sidebar_textcolor }};650 color: {$colors['secondary_sidebar_textcolor']}; 596 651 } 597 652 598 653 .widget button:hover, … … 605 660 .widget input[type="submit"]:focus, 606 661 .widget_calendar tbody a:hover, 607 662 .widget_calendar tbody a:focus { 608 background-color: { { data.secondary_sidebar_textcolor }};663 background-color: {$colors['secondary_sidebar_textcolor']}; 609 664 } 610 665 611 666 .widget blockquote { 612 border-color: { { data.secondary_sidebar_textcolor }};667 border-color: {$colors['secondary_sidebar_textcolor']}; 613 668 } 614 669 615 670 /* Sidebar Border Color */ … … 626 681 .widget_nav_menu .sub-menu, 627 682 .widget_pages .children, 628 683 .widget abbr[title] { 629 border-color: { { data.sidebar_border_color }};684 border-color: {$colors['sidebar_border_color']}; 630 685 } 631 686 632 687 .dropdown-toggle:hover, 633 688 .dropdown-toggle:focus, 634 689 .widget hr { 635 background-color: { { data.sidebar_border_color }};690 background-color: {$colors['sidebar_border_color']}; 636 691 } 637 692 638 693 .widget input:focus, 639 694 .widget textarea:focus { 640 border-color: { { data.sidebar_border_focus_color }};695 border-color: {$colors['sidebar_border_focus_color']}; 641 696 } 642 697 643 698 .sidebar a:focus, 644 699 .dropdown-toggle:focus { 645 outline-color: { { data.sidebar_border_focus_color }};700 outline-color: {$colors['sidebar_border_focus_color']}; 646 701 } 647 702 } 703 CSS; 704 705 return $css; 706 } 707 708 /** 709 * Output an Underscore template for generating CSS for the color scheme. 710 * 711 * The template generates the css dynamically for instant display in the Customizer 712 * preview. 713 * 714 * @since Twenty Fifteen 1.0 715 */ 716 function twentyfifteen_color_scheme_css_template() { 717 $colors = array( 718 'background_color' => '{{ data.background_color }}', 719 'header_background_color' => '{{ data.header_background_color }}', 720 'box_background_color' => '{{ data.box_background_color }}', 721 'textcolor' => '{{ data.textcolor }}', 722 'secondary_textcolor' => '{{ data.secondary_textcolor }}', 723 'border_color' => '{{ data.border_color }}', 724 'border_focus_color' => '{{ data.border_focus_color }}', 725 'sidebar_textcolor' => '{{ data.sidebar_textcolor }}', 726 'sidebar_border_color' => '{{ data.sidebar_border_color }}', 727 'sidebar_border_focus_color' => '{{ data.sidebar_border_focus_color }}', 728 'secondary_sidebar_textcolor' => '{{ data.secondary_sidebar_textcolor }}', 729 'meta_box_background_color' => '{{ data.meta_box_background_color }}', 730 ); 731 ?> 732 <script type="text/html" id="tmpl-twentyfifteen-color-scheme"> 733 <?php echo twentyfifteen_get_color_scheme_css( $colors ); ?> 648 734 </script> 649 735 <?php 650 736 } -
src/wp-content/themes/twentyfifteen/js/color-scheme-control.js
47 47 } ); 48 48 49 49 // Generate the CSS for the current Color Scheme. 50 function getCSS() {51 var scheme = api( 'color_scheme' )(), 50 function updateCSS() { 51 var scheme = api( 'color_scheme' )(), css, 52 52 colors = _.object( colorSchemeKeys, colorScheme[ scheme ].colors ); 53 53 54 54 // Merge in color scheme overrides. … … 64 64 colors.sidebar_border_color = Color( colors.sidebar_textcolor ).toCSS( 'rgba', 0.1 ); 65 65 colors.sidebar_border_focus_color = Color( colors.sidebar_textcolor ).toCSS( 'rgba', 0.3 ); 66 66 67 return cssTemplate( colors ); 67 css = cssTemplate( colors ); 68 69 api.previewer.send( 'update-color-scheme-css', css ); 68 70 } 69 71 70 72 // Update the CSS whenever a color setting is changed. 71 73 _.each( colorSettings, function( setting ) { 72 74 api( setting, function( setting ) { 73 setting.bind( _.throttle( function() { 74 api( 'color_scheme_css' ).set( getCSS() ); 75 }, 250 ) ); 75 setting.bind( updateCSS ); 76 76 } ); 77 77 } ); 78 78 } )( wp.customize ); -
src/wp-content/themes/twentyfifteen/js/customize-preview.js
3 3 */ 4 4 5 5 ( function( $ ) { 6 var $style = $( '#twentyfifteen-color-scheme-css' ); 6 var $style = $( '#twentyfifteen-color-scheme-css' ), 7 api = wp.customize; 7 8 8 9 if ( ! $style.length ) { 9 10 $style = $( 'head' ).append( '<style type="text/css" id="twentyfifteen-color-scheme-css" />' ) … … 11 12 } 12 13 13 14 // Site title. 14 wp.customize( 'blogname', function( value ) {15 api( 'blogname', function( value ) { 15 16 value.bind( function( to ) { 16 17 $( '.site-title a' ).text( to ); 17 18 } ); … … 18 19 } ); 19 20 20 21 // Site tagline. 21 wp.customize( 'blogdescription', function( value ) {22 api( 'blogdescription', function( value ) { 22 23 value.bind( function( to ) { 23 24 $( '.site-description' ).text( to ); 24 25 } ); … … 25 26 } ); 26 27 27 28 // Color Scheme CSS. 28 wp.customize( 'color_scheme_css', function( value) {29 value.bind( function( to) {30 $style.html( to);29 api.bind( 'preview-ready', function() { 30 api.preview.bind( 'update-color-scheme-css', function( css ) { 31 $style.html( css ); 31 32 } ); 32 33 } ); 33 34 -
src/wp-includes/js/customize-preview.js
67 67 if ( ! api.settings ) 68 68 return; 69 69 70 var preview,bg;70 var bg; 71 71 72 preview = new api.Preview({72 api.preview = new api.Preview({ 73 73 url: window.location.href, 74 74 channel: api.settings.channel 75 75 }); 76 76 77 preview.bind( 'settings', function( values ) {77 api.preview.bind( 'settings', function( values ) { 78 78 $.each( values, function( id, value ) { 79 79 if ( api.has( id ) ) 80 80 api( id ).set( value ); … … 83 83 }); 84 84 }); 85 85 86 preview.trigger( 'settings', api.settings.values );86 api.preview.trigger( 'settings', api.settings.values ); 87 87 88 preview.bind( 'setting', function( args ) {88 api.preview.bind( 'setting', function( args ) { 89 89 var value; 90 90 91 91 args = args.slice(); … … 94 94 value.set.apply( value, args ); 95 95 }); 96 96 97 preview.bind( 'sync', function( events ) {97 api.preview.bind( 'sync', function( events ) { 98 98 $.each( events, function( event, args ) { 99 preview.trigger( event, args );99 api.preview.trigger( event, args ); 100 100 }); 101 preview.send( 'synced' );101 api.preview.send( 'synced' ); 102 102 }); 103 103 104 preview.bind( 'active', function() {104 api.preview.bind( 'active', function() { 105 105 if ( api.settings.nonce ) { 106 preview.send( 'nonce', api.settings.nonce );106 api.preview.send( 'nonce', api.settings.nonce ); 107 107 } 108 108 109 preview.send( 'documentTitle', document.title );109 api.preview.send( 'documentTitle', document.title ); 110 110 }); 111 111 112 preview.send( 'ready', {112 api.preview.send( 'ready', { 113 113 activePanels: api.settings.activePanels, 114 114 activeSections: api.settings.activeSections, 115 115 activeControls: api.settings.activeControls … … 154 154 this.bind( update ); 155 155 }); 156 156 }); 157 158 api.trigger( 'preview-ready' ); 157 159 }); 158 160 159 161 })( wp, jQuery );