mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Update the Themes screen, merging THX into core.
* Name: THX38 * Description: Update the Themes screen with a new design and experience. * Tags: visually-focused, bigger-screenshots, fast, mobile-friendly, backbone-driven * Author: matveb, shaunandrews, melchoyce, designsimply, shelob9 * URI: http://wordpress.org/plugins/thx38/ fixes #25948 Built from https://develop.svn.wordpress.org/trunk@26141 git-svn-id: http://core.svn.wordpress.org/trunk@26052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
87ce6cc5c3
commit
dce9327f2a
@ -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;
|
||||
}
|
279
wp-admin/js/theme-install.js
Normal file
279
wp-admin/js/theme-install.js
Normal file
@ -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( '<iframe src="' + src + '" />');
|
||||
preview.fadeIn( 200, function() {
|
||||
body.addClass('theme-installer-active full-overlay-active');
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
});
|
||||
|
||||
var ThemeViewer;
|
||||
|
||||
(function($){
|
||||
ThemeViewer = function( args ) {
|
||||
|
||||
function init() {
|
||||
$( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
|
||||
$( '#filter-click' ).toggleClass( 'current' );
|
||||
$( '#filter-box' ).slideToggle();
|
||||
$( '#current-theme' ).slideToggle( 300 );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
|
||||
var count = $( '#filter-box :checked' ).length,
|
||||
text = $( '#filter-click' ).text();
|
||||
|
||||
if ( text.indexOf( '(' ) != -1 )
|
||||
text = text.substr( 0, text.indexOf( '(' ) );
|
||||
|
||||
if ( count == 0 )
|
||||
$( '#filter-click' ).text( text );
|
||||
else
|
||||
$( '#filter-click' ).text( text + ' (' + count + ')' );
|
||||
});
|
||||
|
||||
/* $('#filter-box :submit').unbind( 'click' ).click(function() {
|
||||
var features = [];
|
||||
$('#filter-box :checked').each(function() {
|
||||
features.push($(this).val());
|
||||
});
|
||||
|
||||
listTable.update_rows({'features': features}, true, function() {
|
||||
$( '#filter-click' ).toggleClass( 'current' );
|
||||
$( '#filter-box' ).slideToggle();
|
||||
$( '#current-theme' ).slideToggle( 300 );
|
||||
});
|
||||
|
||||
return false;
|
||||
}); */
|
||||
}
|
||||
|
||||
// These are the functions we expose
|
||||
var api = {
|
||||
init: init
|
||||
};
|
||||
|
||||
return api;
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
jQuery( document ).ready( function($) {
|
||||
theme_viewer = new ThemeViewer();
|
||||
theme_viewer.init();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Class that provides infinite scroll for Themes admin screens
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @uses ajaxurl
|
||||
* @uses list_args
|
||||
* @uses theme_list_args
|
||||
* @uses $('#_ajax_fetch_list_nonce').val()
|
||||
* */
|
||||
var ThemeScroller;
|
||||
(function($){
|
||||
ThemeScroller = {
|
||||
querying: false,
|
||||
scrollPollingDelay: 500,
|
||||
failedRetryDelay: 4000,
|
||||
outListBottomThreshold: 300,
|
||||
|
||||
/**
|
||||
* Initializer
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
init: function() {
|
||||
var self = this;
|
||||
|
||||
// Get out early if we don't have the required arguments.
|
||||
if ( typeof ajaxurl === 'undefined' ||
|
||||
typeof list_args === 'undefined' ||
|
||||
typeof theme_list_args === 'undefined' ) {
|
||||
$('.pagination-links').show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle inputs
|
||||
this.nonce = $('#_ajax_fetch_list_nonce').val();
|
||||
this.nextPage = ( theme_list_args.paged + 1 );
|
||||
|
||||
// Cache jQuery selectors
|
||||
this.$outList = $('#availablethemes');
|
||||
this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
|
||||
this.$window = $(window);
|
||||
this.$document = $(document);
|
||||
|
||||
/**
|
||||
* If there are more pages to query, then start polling to track
|
||||
* when user hits the bottom of the current page
|
||||
*/
|
||||
if ( theme_list_args.total_pages >= this.nextPage )
|
||||
this.pollInterval =
|
||||
setInterval( function() {
|
||||
return self.poll();
|
||||
}, this.scrollPollingDelay );
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if user has scrolled to bottom of page.
|
||||
* If so, requests another page of content from self.ajax().
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
poll: function() {
|
||||
var bottom = this.$document.scrollTop() + this.$window.innerHeight();
|
||||
|
||||
if ( this.querying ||
|
||||
( bottom < this.$outList.height() - this.outListBottomThreshold ) )
|
||||
return;
|
||||
|
||||
this.ajax();
|
||||
},
|
||||
|
||||
/**
|
||||
* Applies results passed from this.ajax() to $outList
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*
|
||||
* @param results Array with results from this.ajax() query.
|
||||
*/
|
||||
process: function( results ) {
|
||||
if ( results === undefined ) {
|
||||
clearInterval( this.pollInterval );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( this.nextPage > theme_list_args.total_pages )
|
||||
clearInterval( this.pollInterval );
|
||||
|
||||
if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
|
||||
this.$outList.append( results.rows );
|
||||
},
|
||||
|
||||
/**
|
||||
* Queries next page of themes
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
ajax: function() {
|
||||
var self = this;
|
||||
|
||||
this.querying = true;
|
||||
|
||||
var query = {
|
||||
action: 'fetch-list',
|
||||
paged: this.nextPage,
|
||||
s: theme_list_args.search,
|
||||
tab: theme_list_args.tab,
|
||||
type: theme_list_args.type,
|
||||
_ajax_fetch_list_nonce: this.nonce,
|
||||
'features[]': theme_list_args.features,
|
||||
'list_args': list_args
|
||||
};
|
||||
|
||||
this.$spinner.show();
|
||||
$.getJSON( ajaxurl, query )
|
||||
.done( function( response ) {
|
||||
self.nextPage++;
|
||||
self.process( response );
|
||||
self.$spinner.hide();
|
||||
self.querying = false;
|
||||
})
|
||||
.fail( function() {
|
||||
self.$spinner.hide();
|
||||
self.querying = false;
|
||||
setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready( function($) {
|
||||
ThemeScroller.init();
|
||||
});
|
||||
|
||||
})(jQuery);
|
@ -1,279 +1,718 @@
|
||||
/**
|
||||
* 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( '<iframe src="' + src + '" />');
|
||||
preview.fadeIn( 200, function() {
|
||||
body.addClass('theme-installer-active full-overlay-active');
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
});
|
||||
|
||||
var ThemeViewer;
|
||||
/* global _wpThemeSettings, confirm */
|
||||
window.wp = window.wp || {};
|
||||
|
||||
( function($) {
|
||||
ThemeViewer = function( args ) {
|
||||
|
||||
function init() {
|
||||
$( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
|
||||
$( '#filter-click' ).toggleClass( 'current' );
|
||||
$( '#filter-box' ).slideToggle();
|
||||
$( '#current-theme' ).slideToggle( 300 );
|
||||
return false;
|
||||
});
|
||||
// Set up our namespace...
|
||||
var themes = wp.themes = wp.themes || {};
|
||||
|
||||
$( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
|
||||
var count = $( '#filter-box :checked' ).length,
|
||||
text = $( '#filter-click' ).text();
|
||||
// Store the theme data and settings for organized and quick access
|
||||
// themes.data.settings, themes.data.themes, themes.data.i18n
|
||||
themes.data = _wpThemeSettings;
|
||||
|
||||
if ( text.indexOf( '(' ) != -1 )
|
||||
text = text.substr( 0, text.indexOf( '(' ) );
|
||||
// Setup app structure
|
||||
_.extend( themes, { model: {}, view: {}, routes: {}, router: {}, template: wp.template });
|
||||
|
||||
if ( count == 0 )
|
||||
$( '#filter-click' ).text( text );
|
||||
else
|
||||
$( '#filter-click' ).text( text + ' (' + count + ')' );
|
||||
});
|
||||
themes.model = Backbone.Model.extend({});
|
||||
|
||||
/* $('#filter-box :submit').unbind( 'click' ).click(function() {
|
||||
var features = [];
|
||||
$('#filter-box :checked').each(function() {
|
||||
features.push($(this).val());
|
||||
});
|
||||
// Main view controller for themes.php
|
||||
// Unifies and renders all available views
|
||||
//
|
||||
// Hooks to #appearance and organizes the views to be rendered
|
||||
themes.view.Appearance = wp.Backbone.View.extend({
|
||||
|
||||
listTable.update_rows({'features': features}, true, function() {
|
||||
$( '#filter-click' ).toggleClass( 'current' );
|
||||
$( '#filter-box' ).slideToggle();
|
||||
$( '#current-theme' ).slideToggle( 300 );
|
||||
});
|
||||
// Set DOM container
|
||||
// {#appearance} by default
|
||||
el: themes.data.settings.container,
|
||||
|
||||
return false;
|
||||
}); */
|
||||
}
|
||||
window: $( window ),
|
||||
// Pagination instance
|
||||
page: 0,
|
||||
|
||||
// These are the functions we expose
|
||||
var api = {
|
||||
init: init
|
||||
};
|
||||
events: {
|
||||
'click .themes-bulk-edit': 'editMode',
|
||||
'click .theme .delete-theme': 'deleteTheme'
|
||||
},
|
||||
|
||||
return api;
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
jQuery( document ).ready( function($) {
|
||||
theme_viewer = new ThemeViewer();
|
||||
theme_viewer.init();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Class that provides infinite scroll for Themes admin screens
|
||||
*
|
||||
* @since 3.4
|
||||
*
|
||||
* @uses ajaxurl
|
||||
* @uses list_args
|
||||
* @uses theme_list_args
|
||||
* @uses $('#_ajax_fetch_list_nonce').val()
|
||||
* */
|
||||
var ThemeScroller;
|
||||
(function($){
|
||||
ThemeScroller = {
|
||||
querying: false,
|
||||
scrollPollingDelay: 500,
|
||||
failedRetryDelay: 4000,
|
||||
outListBottomThreshold: 300,
|
||||
|
||||
/**
|
||||
* Initializer
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
init: function() {
|
||||
// Sets up a throttler for binding to 'scroll'
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
|
||||
// Get out early if we don't have the required arguments.
|
||||
if ( typeof ajaxurl === 'undefined' ||
|
||||
typeof list_args === 'undefined' ||
|
||||
typeof theme_list_args === 'undefined' ) {
|
||||
$('.pagination-links').show();
|
||||
return;
|
||||
}
|
||||
// Keep a boolean check so that we don't run
|
||||
// too much code on every event trigger
|
||||
this.window.bind( 'scroll.themes', function() {
|
||||
this.throttle = true;
|
||||
});
|
||||
|
||||
// Handle inputs
|
||||
this.nonce = $('#_ajax_fetch_list_nonce').val();
|
||||
this.nextPage = ( theme_list_args.paged + 1 );
|
||||
|
||||
// Cache jQuery selectors
|
||||
this.$outList = $('#availablethemes');
|
||||
this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
|
||||
this.$window = $(window);
|
||||
this.$document = $(document);
|
||||
|
||||
/**
|
||||
* If there are more pages to query, then start polling to track
|
||||
* when user hits the bottom of the current page
|
||||
*/
|
||||
if ( theme_list_args.total_pages >= this.nextPage )
|
||||
this.pollInterval =
|
||||
setInterval( function() {
|
||||
return self.poll();
|
||||
}, this.scrollPollingDelay );
|
||||
if ( this.throttle ) {
|
||||
// Once the case is the case, the action occurs and the fact is no more
|
||||
this.throttle = false;
|
||||
self.scroller();
|
||||
}
|
||||
}, 300 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if user has scrolled to bottom of page.
|
||||
* If so, requests another page of content from self.ajax().
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
poll: function() {
|
||||
var bottom = this.$document.scrollTop() + this.$window.innerHeight();
|
||||
// Main render control
|
||||
render: function() {
|
||||
// Setup the main theme view
|
||||
// with the current theme collection
|
||||
this.view = new themes.view.Themes({
|
||||
collection: this.collection,
|
||||
parent: this
|
||||
});
|
||||
// Render and append
|
||||
this.view.render();
|
||||
this.$el.append( this.view.el );
|
||||
|
||||
if ( this.querying ||
|
||||
( bottom < this.$outList.height() - this.outListBottomThreshold ) )
|
||||
return;
|
||||
|
||||
this.ajax();
|
||||
// Search form
|
||||
this.search();
|
||||
},
|
||||
|
||||
/**
|
||||
* Applies results passed from this.ajax() to $outList
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*
|
||||
* @param results Array with results from this.ajax() query.
|
||||
*/
|
||||
process: function( results ) {
|
||||
if ( results === undefined ) {
|
||||
clearInterval( this.pollInterval );
|
||||
return;
|
||||
// Search input and view
|
||||
// for current theme collection
|
||||
search: function() {
|
||||
var view,
|
||||
self = this;
|
||||
|
||||
view = new themes.view.Search({ collection: self.collection });
|
||||
|
||||
// Render and append after screen title
|
||||
view.render();
|
||||
self.$el.find( '> h2' ).after( view.el );
|
||||
},
|
||||
|
||||
// Checks when the user gets close to the bottom
|
||||
// of the mage and triggers a theme:scroll event
|
||||
scroller: function() {
|
||||
var self = this,
|
||||
bottom, threshold;
|
||||
|
||||
bottom = this.window.scrollTop() + self.window.height();
|
||||
threshold = self.$el.offset().top + self.$el.outerHeight( false ) - self.window.height();
|
||||
threshold = Math.round( threshold * 0.9 );
|
||||
|
||||
if ( bottom > threshold ) {
|
||||
this.trigger( 'theme:scroll' );
|
||||
}
|
||||
},
|
||||
|
||||
// Enters edit mode that allows easy access to deleting themes
|
||||
editMode: function() {
|
||||
$( 'body' ).toggleClass( 'edit-mode' );
|
||||
this.$el.find( '.themes-bulk-edit' ).toggleClass( 'mp6-text-highlight' );
|
||||
},
|
||||
|
||||
deleteTheme: function() {
|
||||
return confirm( themes.data.settings.confirmDelete );
|
||||
}
|
||||
});
|
||||
|
||||
// Set up the Collection for our theme data
|
||||
// @has 'id' 'name' 'screenshot' 'author' 'authorURI' 'version' 'active' ...
|
||||
themes.Collection = Backbone.Collection.extend({
|
||||
|
||||
model: themes.model,
|
||||
|
||||
// Search terms
|
||||
terms: '',
|
||||
|
||||
// Controls searching on the current theme collection
|
||||
// and triggers an update event
|
||||
doSearch: function( value ) {
|
||||
|
||||
// Updates terms with the value passed
|
||||
this.terms = value;
|
||||
|
||||
// If we have terms, run a search...
|
||||
if ( this.terms.length > 0 ) {
|
||||
this.search( this.terms );
|
||||
}
|
||||
|
||||
if ( this.nextPage > theme_list_args.total_pages )
|
||||
clearInterval( this.pollInterval );
|
||||
// If search is blank, show all themes
|
||||
// Useful for resetting the views when you clean the input
|
||||
if ( this.terms === '' ) {
|
||||
this.reset( themes.data.themes );
|
||||
}
|
||||
|
||||
if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
|
||||
this.$outList.append( results.rows );
|
||||
// Trigger an 'update' event
|
||||
this.trigger( 'update' );
|
||||
},
|
||||
// Performs a search within the collection
|
||||
// @uses RegExp
|
||||
search: function( term ) {
|
||||
var self = this,
|
||||
match, results, haystack;
|
||||
|
||||
// Start with a full collection
|
||||
self.reset( themes.data.themes );
|
||||
|
||||
// The RegExp object to match
|
||||
//
|
||||
// Consider spaces as word delimiters and match the whole string
|
||||
// so matching terms can be combined
|
||||
term = term.replace( ' ', ')(?=.*' );
|
||||
match = new RegExp( '^(?=.*' + term + ').+', 'i' );
|
||||
|
||||
// Find results
|
||||
// _.filter and .test
|
||||
results = self.filter( function( data ) {
|
||||
haystack = _.union( data.get( 'name' ), data.get( 'author' ), data.get( 'tags' ) );
|
||||
|
||||
if ( match.test( data.get( 'author' ) ) ) {
|
||||
data.set( 'displayAuthor', true );
|
||||
}
|
||||
|
||||
return match.test( haystack );
|
||||
});
|
||||
|
||||
self.reset( results );
|
||||
},
|
||||
|
||||
/**
|
||||
* Queries next page of themes
|
||||
*
|
||||
* @since 3.4
|
||||
* @access private
|
||||
*/
|
||||
ajax: function() {
|
||||
// Paginates the collection with a helper method
|
||||
// that slices the collection
|
||||
paginate: function( instance ) {
|
||||
var collection = this;
|
||||
instance = instance || 0;
|
||||
|
||||
// Themes per instance are set at 15
|
||||
collection = _( collection.rest( 15 * instance ) );
|
||||
collection = _( collection.first( 15 ) );
|
||||
|
||||
return collection;
|
||||
}
|
||||
});
|
||||
|
||||
// This is the view that controls each theme item
|
||||
// that will be displayed on the screen
|
||||
themes.view.Theme = wp.Backbone.View.extend({
|
||||
|
||||
// Wrap theme data on a div.theme element
|
||||
className: 'theme',
|
||||
|
||||
// Reflects which theme view we have
|
||||
// 'grid' (default) or 'detail'
|
||||
state: 'grid',
|
||||
|
||||
// The HTML template for each element to be rendered
|
||||
html: themes.template( 'theme' ),
|
||||
|
||||
events: {
|
||||
'click': 'expand'
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON();
|
||||
// Render themes using the html template
|
||||
this.$el.html( this.html( data ) );
|
||||
// Renders active theme styles
|
||||
this.activeTheme();
|
||||
|
||||
if ( this.model.get( 'displayAuthor' ) ) {
|
||||
this.$el.addClass( 'display-author' );
|
||||
}
|
||||
},
|
||||
|
||||
// Adds a class to the currently active theme
|
||||
// and to the overlay in detailed view mode
|
||||
activeTheme: function() {
|
||||
if ( this.model.get( 'active' ) ) {
|
||||
this.$el.addClass( 'active' );
|
||||
this.$el.find( '.theme-name' ).addClass( 'mp6-primary' );
|
||||
$( '#theme-overlay' ).addClass( 'active' );
|
||||
}
|
||||
},
|
||||
|
||||
// Single theme overlay screen
|
||||
// It's shown when clicking a theme
|
||||
expand: function( event ) {
|
||||
var self = this;
|
||||
|
||||
this.querying = true;
|
||||
event = event || window.event;
|
||||
|
||||
var query = {
|
||||
action: 'fetch-list',
|
||||
paged: this.nextPage,
|
||||
s: theme_list_args.search,
|
||||
tab: theme_list_args.tab,
|
||||
type: theme_list_args.type,
|
||||
_ajax_fetch_list_nonce: this.nonce,
|
||||
'features[]': theme_list_args.features,
|
||||
'list_args': list_args
|
||||
// Prevent the modal from showing when the user clicks
|
||||
// one of the direct action buttons
|
||||
if ( $( event.target ).is( '.theme-actions a, .delete-theme' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.trigger( 'theme:expand', self.model.cid );
|
||||
}
|
||||
});
|
||||
|
||||
// Theme Details view
|
||||
// Set ups a modal overlay with the expanded theme data
|
||||
themes.view.Details = wp.Backbone.View.extend({
|
||||
|
||||
// Wrap theme data on a div.theme element
|
||||
id: 'theme-overlay',
|
||||
|
||||
events: {
|
||||
'click': 'collapse',
|
||||
'click .delete-theme': 'deleteTheme',
|
||||
'click .left': 'previousTheme',
|
||||
'click .right': 'nextTheme'
|
||||
},
|
||||
|
||||
// The HTML template for the theme overlay
|
||||
html: themes.template( 'theme-single' ),
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON();
|
||||
|
||||
this.$el.html( this.html( data ) );
|
||||
// Renders active theme styles
|
||||
this.activeTheme();
|
||||
// Set up navigation events
|
||||
this.navigation();
|
||||
},
|
||||
|
||||
// Adds a class to the currently active theme
|
||||
// and to the overlay in detailed view mode
|
||||
activeTheme: function() {
|
||||
// Check the model has the active property
|
||||
if ( this.model.get( 'active' ) ) {
|
||||
this.$el.addClass( 'active' );
|
||||
} else {
|
||||
$( '#theme-overlay' ).removeClass( 'active' );
|
||||
}
|
||||
},
|
||||
|
||||
// Single theme overlay screen
|
||||
// It's shown when clicking a theme
|
||||
collapse: function( event ) {
|
||||
var self = this,
|
||||
scroll;
|
||||
|
||||
event = event || window.event;
|
||||
|
||||
// Detect if the click is inside the overlay
|
||||
// and don't close it unless the target was
|
||||
// the div.back button
|
||||
if ( $( event.target ).is( '.theme-backdrop' ) || $( event.target ).is( 'div.back' ) || event.keyCode === 27 ) {
|
||||
|
||||
// Add a temporary closing class while overlay fades out
|
||||
$( 'body' ).addClass( 'closing-overlay' );
|
||||
|
||||
// With a quick fade out animation
|
||||
this.$el.fadeOut( 130, function() {
|
||||
// Clicking outside the modal box closes the overlay
|
||||
$( 'body' ).removeClass( 'theme-overlay closing-overlay' );
|
||||
// Handle event cleanup
|
||||
self.closeOverlay();
|
||||
|
||||
// Get scroll position to avoid jumping to the top
|
||||
scroll = document.body.scrollTop;
|
||||
|
||||
// Clean the url structure
|
||||
themes.router.navigate( '' );
|
||||
|
||||
// Restore scroll position
|
||||
document.body.scrollTop = scroll;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Handles arrow keys navigation for the overlay
|
||||
// Triggers theme:next and theme:previous events
|
||||
navigation: function() {
|
||||
var self = this;
|
||||
|
||||
$( 'body' ).on( 'keyup', function( event ) {
|
||||
|
||||
// Pressing the right arrow key fires a theme:next event
|
||||
if ( event.keyCode === 39 ) {
|
||||
self.trigger( 'theme:next', self.model.cid );
|
||||
}
|
||||
|
||||
// Pressing the left arrow key fires a theme:previous event
|
||||
if ( event.keyCode === 37 ) {
|
||||
self.trigger( 'theme:previous', self.model.cid );
|
||||
}
|
||||
|
||||
// Pressing the escape key closes the theme details panel
|
||||
if ( event.keyCode === 27 ) {
|
||||
self.collapse();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Performs the actions to effectively close
|
||||
// the theme details overlay
|
||||
closeOverlay: function() {
|
||||
this.remove();
|
||||
this.unbind();
|
||||
this.trigger( 'theme:collapse' );
|
||||
},
|
||||
|
||||
// Setups an image gallery using the theme screenshots supplied by a theme
|
||||
screenshotGallery: function() {
|
||||
var screenshots = $( '#theme-screenshots' ),
|
||||
current, img;
|
||||
|
||||
screenshots.find( 'div.first' ).next().addClass( 'selected' );
|
||||
|
||||
// Clicking on a screenshot thumbnail drops it
|
||||
// at the top of the stack in a larger size
|
||||
screenshots.on( 'click', 'div.thumb', function() {
|
||||
current = $( this );
|
||||
img = $( this ).find( 'img' ).clone();
|
||||
|
||||
current.siblings( '.first' ).html( img );
|
||||
current.siblings( '.selected' ).removeClass( 'selected' );
|
||||
current.addClass( 'selected' );
|
||||
});
|
||||
},
|
||||
|
||||
// Confirmation dialoge for deleting a theme
|
||||
deleteTheme: function() {
|
||||
return confirm( themes.data.settings.confirmDelete );
|
||||
},
|
||||
|
||||
nextTheme: function() {
|
||||
var self = this;
|
||||
self.trigger( 'theme:next', self.model.cid );
|
||||
},
|
||||
|
||||
previousTheme: function() {
|
||||
var self = this;
|
||||
self.trigger( 'theme:previous', self.model.cid );
|
||||
}
|
||||
});
|
||||
|
||||
// Controls the rendering of div#themes,
|
||||
// a wrapper that will hold all the theme elements
|
||||
themes.view.Themes = wp.Backbone.View.extend({
|
||||
|
||||
id: 'themes',
|
||||
|
||||
// Number to keep track of scroll position
|
||||
// while in theme-overlay mode
|
||||
index: 0,
|
||||
|
||||
// The theme count element
|
||||
count: $( '#theme-count' ),
|
||||
|
||||
initialize: function( options ) {
|
||||
var self = this;
|
||||
|
||||
// Set up parent
|
||||
this.parent = options.parent;
|
||||
|
||||
// Set current view to [grid]
|
||||
this.setView( 'grid' );
|
||||
|
||||
// Move the active theme to the beginning of the collection
|
||||
self.currentTheme();
|
||||
|
||||
// When the collection is updated by user input...
|
||||
this.listenTo( self.collection, 'update', function() {
|
||||
self.parent.page = 0;
|
||||
self.currentTheme();
|
||||
self.render( this );
|
||||
});
|
||||
|
||||
this.listenTo( this.parent, 'theme:scroll', function() {
|
||||
self.renderThemes( self.parent.page );
|
||||
});
|
||||
},
|
||||
|
||||
// Manages rendering of theme pages
|
||||
// and keeping theme count in sync
|
||||
render: function() {
|
||||
// Clear the DOM, please
|
||||
this.$el.html( '' );
|
||||
|
||||
// Generate the themes
|
||||
// Using page instance
|
||||
this.renderThemes( this.parent.page );
|
||||
|
||||
// Display a live theme count for the collection
|
||||
this.count.text( this.collection.length );
|
||||
},
|
||||
|
||||
// Iterates through each instance of the collection
|
||||
// and renders each theme module
|
||||
renderThemes: function( page ) {
|
||||
var self = this;
|
||||
|
||||
self.instance = self.collection.paginate( page );
|
||||
|
||||
// If we have no more themes bail
|
||||
if ( self.instance.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the add-new stays at the end
|
||||
if ( page >= 1 ) {
|
||||
$( '#add-new' ).remove();
|
||||
}
|
||||
|
||||
// Loop through the themes and setup each theme view
|
||||
self.instance.each( function( theme ) {
|
||||
self.theme = new themes.view.Theme({
|
||||
model: theme
|
||||
});
|
||||
|
||||
// Render the views...
|
||||
self.theme.render();
|
||||
// and append them to div#themes
|
||||
self.$el.append( self.theme.el );
|
||||
|
||||
// Binds to theme:expand to show the modal box
|
||||
// with the theme details
|
||||
self.listenTo( self.theme, 'theme:expand', self.expand, self );
|
||||
});
|
||||
|
||||
// 'Add new theme' element shown at the end of the grid
|
||||
this.$el.append( '<div id="add-new" class="theme add-new"><a href="' + themes.data.settings.install_uri + '"><div class="theme-screenshot"><span></span></div><h3 class="theme-name">' + themes.data.i18n.add_new + '</h3></a></div>' );
|
||||
|
||||
this.parent.page++;
|
||||
},
|
||||
|
||||
// Grabs current theme and puts it at the beginning of the collection
|
||||
currentTheme: function() {
|
||||
var self = this,
|
||||
current;
|
||||
|
||||
current = self.collection.findWhere({ active: true });
|
||||
|
||||
// Move the active theme to the beginning of the collection
|
||||
if ( current ) {
|
||||
self.collection.remove( current );
|
||||
self.collection.add( current, { at:0 } );
|
||||
}
|
||||
},
|
||||
|
||||
// Sets current view
|
||||
setView: function( view ) {
|
||||
return view;
|
||||
},
|
||||
|
||||
// Renders the overlay with the ThemeDetails view
|
||||
// Uses the current model data
|
||||
expand: function( id ) {
|
||||
var self = this;
|
||||
|
||||
// Set the current theme model
|
||||
this.model = self.collection.get( id );
|
||||
|
||||
// Trigger a route update for the current model
|
||||
themes.router.navigate( 'theme/' + this.model.id );
|
||||
|
||||
// Sets this.view to 'detail'
|
||||
this.setView( 'detail' );
|
||||
$( 'body' ).addClass( 'theme-overlay' );
|
||||
|
||||
// Set up the theme details view
|
||||
this.overlay = new themes.view.Details({
|
||||
model: self.model,
|
||||
className: 'theme-' + self.model.id
|
||||
});
|
||||
|
||||
this.overlay.render();
|
||||
this.$el.append( this.overlay.el );
|
||||
|
||||
this.overlay.screenshotGallery();
|
||||
|
||||
// Resets counter whenever the overlay is opened
|
||||
this.index = 0;
|
||||
|
||||
// Bind to theme:next and theme:previous
|
||||
// triggered by the arrow keys
|
||||
//
|
||||
// The index keep track of where we are at
|
||||
// any given time
|
||||
this.listenTo( this.overlay, 'theme:next', function() {
|
||||
// Bump the index number to keep track of how far
|
||||
// we should go for the next theme
|
||||
self.index++;
|
||||
// Renders the next theme on the overlay
|
||||
self.next( [ self.model.cid, self.index ] );
|
||||
self.overlay.screenshotGallery();
|
||||
|
||||
})
|
||||
.listenTo( this.overlay, 'theme:previous', function() {
|
||||
// Decrease the index number to keep track of how far
|
||||
// we should go for the previous theme
|
||||
self.index--;
|
||||
// Renders the previous theme on the overlay
|
||||
self.previous( [ self.model.cid, self.index ] );
|
||||
self.overlay.screenshotGallery();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
// This method renders the next theme on the overlay modal
|
||||
// based on the current position in the collection
|
||||
// @params [model cid] and [index]
|
||||
next: function( args ) {
|
||||
var self = this,
|
||||
model, nextModel;
|
||||
|
||||
// Get the current theme
|
||||
model = self.collection.get( args[0] );
|
||||
// Get the next one
|
||||
nextModel = self.collection.at( self.collection.indexOf( model ) + args[1] );
|
||||
|
||||
// Sanity check which also serves as a boundary test
|
||||
if ( nextModel !== undefined ) {
|
||||
|
||||
// We have a new theme...
|
||||
// Clean the overlay
|
||||
this.overlay.$el.html('');
|
||||
|
||||
// Create the view
|
||||
this.nextTheme = new themes.view.Details({
|
||||
model: nextModel,
|
||||
className: 'theme-' + nextModel.id
|
||||
});
|
||||
|
||||
// Trigger a route update for the current model
|
||||
themes.router.navigate( 'theme/' + nextModel.id );
|
||||
|
||||
// Render and fill this.overlay with the new html
|
||||
this.nextTheme.render();
|
||||
return this.overlay.$el.html( this.nextTheme.el );
|
||||
}
|
||||
|
||||
// If we got this far it means we have no other themes
|
||||
// so move back the counter to keep it sane
|
||||
self.index--;
|
||||
},
|
||||
|
||||
// This method renders the previous theme on the overlay modal
|
||||
// based on the current position in the collection
|
||||
// @params [model cid] and [index]
|
||||
previous: function( args ) {
|
||||
var self = this,
|
||||
model, previousModel;
|
||||
|
||||
// Get the current theme
|
||||
model = self.collection.get( args[0] );
|
||||
previousModel = self.collection.at( self.collection.indexOf( model ) + args[1] );
|
||||
|
||||
if ( previousModel !== undefined ) {
|
||||
|
||||
// We have a new theme...
|
||||
// Clean the overlay
|
||||
this.overlay.$el.html( '' );
|
||||
|
||||
// Create the view
|
||||
this.previousTheme = new themes.view.Details({
|
||||
model: previousModel,
|
||||
className: 'theme-' + previousModel.id
|
||||
});
|
||||
|
||||
// Trigger a route update for the current model
|
||||
themes.router.navigate( 'theme/' + previousModel.id );
|
||||
|
||||
// Render and fill this.overlay with the new html
|
||||
this.previousTheme.render();
|
||||
return this.overlay.$el.html( this.previousTheme.el );
|
||||
}
|
||||
|
||||
// If we got this far it means we have no other themes
|
||||
// so move back the counter to keep it sane
|
||||
self.index++;
|
||||
}
|
||||
});
|
||||
|
||||
// Search input view controller
|
||||
// renders #search-form
|
||||
themes.view.Search = wp.Backbone.View.extend({
|
||||
|
||||
className: 'search-form',
|
||||
|
||||
// 'keyup' triggers search
|
||||
events: {
|
||||
'keyup #theme-search': 'search'
|
||||
},
|
||||
|
||||
// Grabs template file
|
||||
html: themes.template( 'theme-search' ),
|
||||
|
||||
// Render the search form
|
||||
render: function() {
|
||||
var self = this;
|
||||
self.$el.html( self.html );
|
||||
},
|
||||
|
||||
// Runs a search on the theme collection
|
||||
// bind on 'keyup' event
|
||||
search: function() {
|
||||
this.collection.doSearch( $( '#theme-search' ).val() );
|
||||
}
|
||||
});
|
||||
|
||||
// Sets up the routes events for relevant url queries
|
||||
// Listens to [theme] and [search] params
|
||||
themes.routes = Backbone.Router.extend({
|
||||
|
||||
routes: {
|
||||
'search/:query': 'search',
|
||||
'theme/:slug': 'theme'
|
||||
},
|
||||
|
||||
// Set the search input value based on url
|
||||
search: function( query ) {
|
||||
$( '#theme-search' ).val( query );
|
||||
}
|
||||
});
|
||||
|
||||
// Make routes easily extendable
|
||||
_.extend( themes.routes, themes.data.settings.extraRoutes );
|
||||
|
||||
// Execute and setup the application
|
||||
themes.Run = {
|
||||
init: function() {
|
||||
// Initializes the blog's theme library view
|
||||
// Create a new collection with data
|
||||
this.themes = new themes.Collection( themes.data.themes );
|
||||
|
||||
// Set up the view
|
||||
this.view = new themes.view.Appearance({
|
||||
collection: this.themes
|
||||
});
|
||||
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
// Render results
|
||||
this.view.render();
|
||||
|
||||
// Calls the routes functionality
|
||||
this.routes();
|
||||
|
||||
// Set ups history with pushState and our root
|
||||
Backbone.history.start({ root: themes.data.settings.root });
|
||||
},
|
||||
|
||||
routes: function() {
|
||||
var self = this;
|
||||
// Bind to our global thx object
|
||||
// so that the object is available to sub-views
|
||||
themes.router = new themes.routes();
|
||||
|
||||
// Handles theme details route event
|
||||
themes.router.on( 'route:theme', function( slug ) {
|
||||
self.view.view.expand( slug );
|
||||
});
|
||||
|
||||
// Handles search route event
|
||||
themes.router.on( 'route:search', function( query ) {
|
||||
self.themes.doSearch( query );
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.$spinner.show();
|
||||
$.getJSON( ajaxurl, query )
|
||||
.done( function( response ) {
|
||||
self.nextPage++;
|
||||
self.process( response );
|
||||
self.$spinner.hide();
|
||||
self.querying = false;
|
||||
})
|
||||
.fail( function() {
|
||||
self.$spinner.hide();
|
||||
self.querying = false;
|
||||
setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
|
||||
});
|
||||
}
|
||||
}
|
||||
// Ready...
|
||||
jQuery( document ).ready(
|
||||
|
||||
$(document).ready( function($) {
|
||||
ThemeScroller.init();
|
||||
});
|
||||
// Bring on the themes
|
||||
_.bind( themes.Run.init, themes.Run )
|
||||
|
||||
);
|
||||
|
||||
})( jQuery );
|
||||
|
@ -12,10 +12,6 @@ require_once( dirname( __FILE__ ) . '/admin.php' );
|
||||
if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
|
||||
wp_die( __( 'Cheatin’ uh?' ) );
|
||||
|
||||
$wp_list_table = _get_list_table('WP_Themes_List_Table');
|
||||
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 's', 'features', '_ajax_fetch_list_nonce', '_wp_http_referer', 'paged' ), $_SERVER['REQUEST_URI'] );
|
||||
|
||||
if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
|
||||
if ( 'activate' == $_GET['action'] ) {
|
||||
check_admin_referer('switch-theme_' . $_GET['stylesheet']);
|
||||
@ -36,8 +32,6 @@ if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
$wp_list_table->prepare_items();
|
||||
|
||||
$title = __('Manage Themes');
|
||||
$parent_file = 'themes.php';
|
||||
|
||||
@ -66,8 +60,6 @@ if ( current_user_can( 'install_themes' ) ) {
|
||||
) );
|
||||
}
|
||||
|
||||
add_thickbox();
|
||||
|
||||
endif; // switch_themes
|
||||
|
||||
if ( current_user_can( 'edit_theme_options' ) ) {
|
||||
@ -90,21 +82,42 @@ get_current_screen()->set_help_sidebar(
|
||||
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
|
||||
);
|
||||
|
||||
if ( current_user_can( 'switch_themes' ) ) {
|
||||
$themes = wp_prepare_themes_for_js();
|
||||
} else {
|
||||
$themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
|
||||
}
|
||||
|
||||
wp_localize_script( 'theme', '_wpThemeSettings', array(
|
||||
'themes' => $themes,
|
||||
'settings' => array(
|
||||
'install_uri' => admin_url( 'theme-install.php' ),
|
||||
'customizeURI' => ( current_user_can( 'edit_theme_options' ) ) ? wp_customize_url() : null,
|
||||
'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
|
||||
'root' => '/wp-admin/themes.php',
|
||||
'container' => '#appearance',
|
||||
'extraRoutes' => '',
|
||||
),
|
||||
'i18n' => array(
|
||||
'add_new' => __( 'Add New Theme' ),
|
||||
),
|
||||
) );
|
||||
|
||||
wp_enqueue_style( 'theme' );
|
||||
wp_enqueue_script( 'theme' );
|
||||
wp_enqueue_script( 'customize-loader' );
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/admin-header.php' );
|
||||
?>
|
||||
|
||||
<div class="wrap"><?php
|
||||
screen_icon();
|
||||
if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><a href="<?php echo admin_url( 'theme-install.php'); ?>" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a>
|
||||
<?php else : ?>
|
||||
<h2><?php echo esc_html( $title ); ?>
|
||||
<div id="appearance" class="wrap">
|
||||
<h2><?php esc_html_e( 'Themes' ); ?>
|
||||
<span id="theme-count" class="theme-count"></span>
|
||||
<?php if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
|
||||
<a href="<?php echo admin_url( 'theme-install.php' ); ?>" class="add-new-h2"><?php echo esc_html( _x( 'Add New', 'Add new theme' ) ); ?></a>
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
|
||||
<div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
|
||||
@ -120,50 +133,16 @@ if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
|
||||
endif;
|
||||
|
||||
$ct = wp_get_theme();
|
||||
$screenshot = $ct->get_screenshot();
|
||||
$class = $screenshot ? 'has-screenshot' : '';
|
||||
|
||||
$customize_title = sprintf( __( 'Customize “%s”' ), $ct->display('Name') );
|
||||
|
||||
?>
|
||||
<div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
|
||||
<?php if ( $screenshot ) : ?>
|
||||
<?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
|
||||
<a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>">
|
||||
<img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<h3><?php _e('Current Theme'); ?></h3>
|
||||
<h4>
|
||||
<?php echo $ct->display('Name'); ?>
|
||||
</h4>
|
||||
|
||||
<?php
|
||||
if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
|
||||
echo '<p class="error-message">' . sprintf( __( 'ERROR: %s' ), $ct->errors()->get_error_message() ) . '</p>';
|
||||
}
|
||||
|
||||
/*
|
||||
// Certain error codes are less fatal than others. We can still display theme information in most cases.
|
||||
if ( ! $ct->errors() || ( 1 == count( $ct->errors()->get_error_codes() )
|
||||
&& in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
|
||||
|
||||
<div>
|
||||
<ul class="theme-info">
|
||||
<li><?php printf( __('By %s'), $ct->display('Author') ); ?></li>
|
||||
<li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li>
|
||||
</ul>
|
||||
<p class="theme-description"><?php echo $ct->display('Description'); ?></p>
|
||||
<?php if ( $ct->parent() ) {
|
||||
printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
|
||||
__( 'http://codex.wordpress.org/Child_Themes' ),
|
||||
$ct->parent()->display( 'Name' ) );
|
||||
} ?>
|
||||
<?php theme_update_available( $ct ); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Pretend you didn't see this.
|
||||
$options = array();
|
||||
@ -194,102 +173,8 @@ if ( ! $ct->errors() || ( 1 == count( $ct->errors()->get_error_codes() )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $options || current_user_can( 'edit_theme_options' ) ) :
|
||||
*/
|
||||
?>
|
||||
<div class="theme-options">
|
||||
<?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
|
||||
<a id="customize-current-theme-link" href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"><?php _e( 'Customize' ); ?></a>
|
||||
<?php
|
||||
endif; // edit_theme_options
|
||||
if ( $options ) :
|
||||
?>
|
||||
<span><?php _e( 'Options:' )?></span>
|
||||
<ul>
|
||||
<?php foreach ( $options as $option ) : ?>
|
||||
<li><?php echo $option; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php
|
||||
endif; // options
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endif; // options || edit_theme_options
|
||||
?>
|
||||
|
||||
<?php endif; // theme errors ?>
|
||||
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
<?php
|
||||
if ( ! current_user_can( 'switch_themes' ) ) {
|
||||
echo '</div>';
|
||||
require( ABSPATH . 'wp-admin/admin-footer.php' );
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<form class="search-form filter-form" action="" method="get">
|
||||
|
||||
<h3 class="available-themes"><?php _e('Available Themes'); ?></h3>
|
||||
|
||||
<?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?>
|
||||
|
||||
<p class="search-box">
|
||||
<label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
|
||||
<input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
|
||||
<?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
||||
<a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
|
||||
</p>
|
||||
|
||||
<div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
|
||||
<?php $feature_list = get_theme_feature_list(); ?>
|
||||
<div class="feature-filter">
|
||||
<p class="install-help"><?php _e('Theme filters') ?></p>
|
||||
<?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
|
||||
<input type="hidden" name="filter" value="1" />
|
||||
<?php endif; ?>
|
||||
<?php foreach ( $feature_list as $feature_name => $features ) :
|
||||
$feature_name = esc_html( $feature_name ); ?>
|
||||
|
||||
<div class="feature-container">
|
||||
<div class="feature-name"><?php echo $feature_name ?></div>
|
||||
|
||||
<ol class="feature-group">
|
||||
<?php foreach ( $features as $key => $feature ) :
|
||||
$feature_name = $feature;
|
||||
$feature_name = esc_html( $feature_name );
|
||||
$feature = esc_attr( $feature );
|
||||
?>
|
||||
<li>
|
||||
<input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
|
||||
<label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="feature-container">
|
||||
<?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?>
|
||||
|
||||
<a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a>
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
<br class="clear"/>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<?php $wp_list_table->display(); ?>
|
||||
|
||||
</form>
|
||||
<br class="clear" />
|
||||
|
||||
<?php
|
||||
// List broken themes, if any.
|
||||
@ -317,6 +202,106 @@ if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div><!-- .wrap -->
|
||||
|
||||
<script id="tmpl-theme" type="text/template">
|
||||
<div class="theme-screenshot">
|
||||
<img src="{{ data.screenshot[0] }}" alt="" />
|
||||
</div>
|
||||
<div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
|
||||
<h3 class="theme-name">{{ data.name }}</h3>
|
||||
<div class="theme-actions">
|
||||
|
||||
<# if ( data.active ) { #>
|
||||
<span class="current-label"><?php _e( 'Current Theme' ); ?></span>
|
||||
<# if ( wp.themes.data.settings['customizeURI'] ) { #>
|
||||
<a class="button button-primary hide-if-no-customize" href="{{ wp.themes.data.settings['customizeURI'] }}"><?php _e( 'Customize' ); ?></a>
|
||||
<# } #>
|
||||
<# } else { #>
|
||||
<a class="button button-primary activate" href="{{{ data.actions['activate'] }}}"><?php _e( 'Activate' ); ?></a>
|
||||
<a class="button button-secondary preview" href="{{{ data.actions['customize'] }}}"><?php _e( 'Live Preview' ); ?></a>
|
||||
<# } #>
|
||||
|
||||
</div>
|
||||
|
||||
<# if ( data.hasUpdate ) { #>
|
||||
<a class="theme-update"><?php _e( 'Update Available' ); ?></a>
|
||||
<# } #>
|
||||
|
||||
<# if ( ! data.active ) { #>
|
||||
<a href="{{{ data.actions.delete }}}" class="delete-theme"><?php _e( 'Delete' ); ?></a>
|
||||
<# } #>
|
||||
</script>
|
||||
|
||||
<script id="tmpl-theme-search" type="text/template">
|
||||
<input type="text" name="theme-search" id="theme-search" placeholder="<?php esc_attr_e( 'Search...' ); ?>" />
|
||||
</script>
|
||||
|
||||
<script id="tmpl-theme-single" type="text/template">
|
||||
<div class="theme-backdrop"></div>
|
||||
<div class="theme-wrap">
|
||||
<div class="theme-utility">
|
||||
<div alt="<?php _e( 'Close overlay' ); ?>" class="back dashicons dashicons-no"></div>
|
||||
<div alt="<?php _e( 'Show previous theme' ); ?>" class="left dashicons dashicons-no"></div>
|
||||
<div alt="<?php _e( 'Show next theme' ); ?>" class="right dashicons dashicons-no"></div>
|
||||
</div>
|
||||
|
||||
<div class="theme-screenshots" id="theme-screenshots">
|
||||
<div class="screenshot first"><img src="{{ data.screenshot[0] }}" alt="" /></div>
|
||||
<#
|
||||
if ( _.size( data.screenshot ) > 1 ) {
|
||||
_.each ( data.screenshot, function( image ) {
|
||||
#>
|
||||
<div class="screenshot thumb"><img src="{{ image }}" alt="" /></div>
|
||||
<#
|
||||
});
|
||||
}
|
||||
#>
|
||||
</div>
|
||||
|
||||
<div class="theme-info">
|
||||
<# if ( data.active ) { #>
|
||||
<span class="current-label"><?php _e( 'Current Theme' ); ?></span>
|
||||
<# } #>
|
||||
<h3 class="theme-name">{{ data.name }}<span class="theme-version"><?php _e('Version: '); ?> {{ data.version }}</span></h3>
|
||||
<h4 class="theme-author"><?php printf( __( 'By %s' ), '<a href="{{ data.authorURI }}">{{ data.author }}</a>' ); ?></h4>
|
||||
|
||||
<# if ( data.hasUpdate ) { #>
|
||||
<div class="theme-update-message">
|
||||
<a class="theme-update"><?php _e( 'Update Available' ); ?></a>
|
||||
<p>{{{ data.update }}}</p>
|
||||
</div>
|
||||
<# } #>
|
||||
<p class="theme-description">{{{ data.description }}}</p>
|
||||
|
||||
<# if ( data.parent ) { #>
|
||||
<p class="parent-theme"><?php printf( __( 'This is a child theme of <strong>%s</strong>.' ), '{{ data.parent }}' ); ?></p>
|
||||
<# } #>
|
||||
|
||||
<# if ( data.tags.length !== 0 ) { #>
|
||||
<p class="theme-tags">
|
||||
<span><?php _e( 'Tags:' ); ?></span>
|
||||
{{{ data.tags.join( ', ' ).replace( /-/g, ' ' ) }}}
|
||||
</p>
|
||||
<# } #>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="theme-actions">
|
||||
<div class="active-theme">
|
||||
<a href="{{{ wp.themes.data.settings.customizeURI }}}" class="button button-primary hide-if-no-customize"><?php _e( 'Customize' ); ?></a>
|
||||
<a class="button button-secondary" href="<?php echo admin_url( 'nav-menus.php' ); ?>"><?php _e( 'Menus' ); ?></a>
|
||||
<a class="button button-secondary" href="<?php echo admin_url( 'widgets.php' ); ?>"><?php _e( 'Widgets' ); ?></a>
|
||||
</div>
|
||||
<div class="inactive-theme">
|
||||
<a href="{{{ data.actions.activate }}}" class="button button-primary"><?php _e( 'Activate' ); ?></a>
|
||||
<a href="{{{ data.actions.customize }}}" class="button button-secondary"><?php _e( 'Live Preview' ); ?></a>
|
||||
</div>
|
||||
|
||||
<# if ( ! data.active ) { #>
|
||||
<a href="{{{ data.actions.delete }}}" class="delete-theme"><?php _e( 'Delete' ); ?></a>
|
||||
<# } #>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<?php require( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
|
||||
|
@ -451,7 +451,8 @@ function wp_default_scripts( &$scripts ) {
|
||||
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), false, 1 );
|
||||
|
||||
$scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'jquery' ), false, 1 );
|
||||
$scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone' ), false, 1 );
|
||||
$scripts->add( 'theme-install', "/wp-admin/js/theme-install$suffix.js", array( 'jquery' ), false, 1 );
|
||||
|
||||
// @todo: Core no longer uses theme-preview.js. Remove?
|
||||
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 );
|
||||
@ -570,6 +571,7 @@ function wp_default_styles( &$styles ) {
|
||||
// do not refer to these directly, the right one is queued by the above "meta" colors handle
|
||||
$styles->add( 'colors-fresh', "/wp-admin/css/colors-fresh$suffix.css", array( 'wp-admin', 'buttons' ) );
|
||||
|
||||
$styles->add( 'theme', "/wp-admin/css/theme.css" );
|
||||
$styles->add( 'media', "/wp-admin/css/media$suffix.css" );
|
||||
$styles->add( 'install', "/wp-admin/css/install$suffix.css", array('buttons') );
|
||||
$styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array(), '20121105' );
|
||||
|
Loading…
Reference in New Issue
Block a user