Skip to content

Commit

Permalink
Add Fitler for title and small js for faster live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
bueltge committed Oct 2, 2012
1 parent a7bd562 commit 2d788ae
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
36 changes: 36 additions & 0 deletions functions.php
Expand Up @@ -334,3 +334,39 @@ function documentation_get_paginate_bar( $args = FALSE ) {
}

} // end if function exists

if ( ! function_exists( 'documentation_wp_title' ) ) {

add_filter( 'wp_title', 'documentation_wp_title', 10, 2 );
/**
* Creates a nicely formatted and more specific title element text
* for output in head of document, based on current view.
*
* @since 10/02/2012
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string Filtered title.
*/
function documentation_wp_title( $title, $sep ) {
global $paged, $page;

if ( is_feed() )
return $title;

// Add the site name.
$title .= get_bloginfo( 'name' );

// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";

// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );

return $title;
}

} // end if function exists
24 changes: 23 additions & 1 deletion inc/theme-customize.php
Expand Up @@ -35,6 +35,9 @@ public function __construct( $args = NULL ) {

// register our custom settings
add_action( 'customize_register', array( $this, 'customize_register' ) );

//
add_action( 'customize_preview_init', array( $this, 'customize_preview_js' ) );
}

/**
Expand Down Expand Up @@ -211,5 +214,24 @@ public function customize_register( $wp_customize ) {
) ) );

}


/**
* Mp reload for changes
*
* @since 10/02/2012
* @return void
*/
public function customize_preview_js() {

wp_register_script(
$this->theme_key . '-customizer',
get_template_directory_uri() . '/js/theme-customizer.js',
array( 'customize-preview' ),
FALSE,
TRUE
);

wp_enqueue_script( $this->theme_key . '-customizer' );
}

} // end class
32 changes: 32 additions & 0 deletions js/theme-customizer.js
@@ -0,0 +1,32 @@
/**
* Theme Customizer enhancements for a better user experience.
*
* Contains handlers to make Theme Customizer preview reload changes asynchronously.
* Things like site title, description, and background color changes.
*/

( function( $ ) {
// Site title and description.
wp.customize( 'blogname', function( value ) {
value.bind( function( to ) {
$( '#header h1' ).html( to );
} );
} );
wp.customize( 'blogdescription', function( value ) {
value.bind( function( to ) {
$( '.site-description' ).html( to );
} );
} );

// Hook into background color change and adjust body class value as needed.
wp.customize( 'background_color', function( value ) {
value.bind( function( to ) {
if ( '#ffffff' == to || '#fff' == to || '' == to )
$( 'body' ).addClass( 'custom-background-white' );
else if ( '' == to )
$( 'body' ).addClass( 'custom-background-empty' );
else
$( 'body' ).removeClass( 'custom-background-empty custom-background-white' );
} );
} );
} )( jQuery );

0 comments on commit 2d788ae

Please sign in to comment.