diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index ccfad6b169..94e811606a 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -345,3 +345,60 @@ function themes_api( $action, $args = null ) { */ return apply_filters( 'themes_api_result', $res, $action, $args ); } + +/** + * Prepare themes for JavaScript. + * + * @since 3.8.0 + * + * @param array $themes Optional. Array of WP_Theme objects to prepare. + * Defaults to all allowed themes. + * + * @return array An associative array of theme data. + */ +function wp_prepare_themes_for_js( $themes = null ) { + if ( null === $themes ) { + $themes = wp_get_themes( array( 'allowed' => true ) ); + } + + $prepared_themes = array(); + $current_theme = get_stylesheet(); + + $updates = array(); + if ( current_user_can( 'update_themes' ) ) { + $updates = get_site_transient( 'update_themes' ); + $updates = $updates->response; + } + + foreach( $themes as $slug => $theme ) { + $parent = false; + if ( $theme->parent() ) { + $parent = $theme->parent()->display( 'Name' ); + } + + $encoded_slug = urlencode( $slug ); + + $prepared_themes[] = array( + 'id' => $slug, + 'name' => $theme->display( 'Name' ), + 'screenshot' => array( $theme->get_screenshot() ), // @todo multiple + 'description' => $theme->display( 'Description' ), + 'author' => $theme->get( 'Author' ), + 'authorURI' => $theme->get( 'AuthorURI' ), + 'version' => $theme->get( 'Version' ), + 'tags' => $theme->get( 'Tags' ), + 'parent' => $parent, + 'active' => $slug === $current_theme, + 'hasUpdate' => isset( $updates[ $slug ] ), + 'update' => 'New version available', // @todo complete this + 'actions' => array( + 'activate' => wp_nonce_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug, 'switch-theme_' . $slug ), + 'customize'=> admin_url( 'customize.php?theme=' . $encoded_slug ), + 'delete' => wp_nonce_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug, 'delete-theme_' . $slug ), + ), + ); + } + // var_dump( $prepared_themes ); + + return $prepared_themes; +} \ No newline at end of file diff --git a/wp-admin/js/theme-install.js b/wp-admin/js/theme-install.js new file mode 100644 index 0000000000..0899ab72f0 --- /dev/null +++ b/wp-admin/js/theme-install.js @@ -0,0 +1,279 @@ +/** + * Theme Browsing + * + * Controls visibility of theme details on manage and install themes pages. + */ +jQuery( function($) { + $('#availablethemes').on( 'click', '.theme-detail', function (event) { + var theme = $(this).closest('.available-theme'), + details = theme.find('.themedetaildiv'); + + if ( ! details.length ) { + details = theme.find('.install-theme-info .theme-details'); + details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide(); + } + + details.toggle(); + event.preventDefault(); + }); +}); + +/** + * Theme Browser Thickbox + * + * Aligns theme browser thickbox. + */ +var tb_position; +jQuery(document).ready( function($) { + tb_position = function() { + var tbWindow = $('#TB_window'), width = $(window).width(), H = $(window).height(), W = ( 1040 < width ) ? 1040 : width, adminbar_height = 0; + + if ( $('body.admin-bar').length ) + adminbar_height = 28; + + if ( tbWindow.size() ) { + tbWindow.width( W - 50 ).height( H - 45 - adminbar_height ); + $('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height ); + tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'}); + if ( typeof document.body.style.maxWidth != 'undefined' ) + tbWindow.css({'top': 20 + adminbar_height + 'px','margin-top':'0'}); + }; + }; + + $(window).resize(function(){ tb_position(); }); +}); + +/** + * Theme Install + * + * Displays theme previews on theme install pages. + */ +jQuery( function($) { + if( ! window.postMessage ) + return; + + var preview = $('#theme-installer'), + info = preview.find('.install-theme-info'), + panel = preview.find('.wp-full-overlay-main'), + body = $( document.body ); + + preview.on( 'click', '.close-full-overlay', function( event ) { + preview.fadeOut( 200, function() { + panel.empty(); + body.removeClass('theme-installer-active full-overlay-active'); + }); + event.preventDefault(); + }); + + preview.on( 'click', '.collapse-sidebar', function( event ) { + preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' ); + event.preventDefault(); + }); + + $('#availablethemes').on( 'click', '.install-theme-preview', function( event ) { + var src; + + info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() ); + src = info.find( '.theme-preview-url' ).val(); + panel.html( '