2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/theme.js
|
|
|
|
*/
|
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
/* global _wpThemeSettings, confirm, tb_position */
|
2013-11-13 15:58:05 -05:00
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
( function($) {
|
|
|
|
|
|
|
|
// Set up our namespace...
|
2013-11-20 14:44:12 -05:00
|
|
|
var themes, l10n;
|
|
|
|
themes = wp.themes = wp.themes || {};
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Store the theme data and settings for organized and quick access.
|
|
|
|
// themes.data.settings, themes.data.themes, themes.data.l10n.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.data = _wpThemeSettings;
|
2013-11-20 14:44:12 -05:00
|
|
|
l10n = themes.data.l10n;
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Shortcut for isInstall check.
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.isInstall = !! themes.data.settings.isInstall;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Setup app structure.
|
2013-11-13 15:58:05 -05:00
|
|
|
_.extend( themes, { model: {}, view: {}, routes: {}, router: {}, template: wp.template });
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.Model = Backbone.Model.extend({
|
2020-01-28 19:45:18 -05:00
|
|
|
// Adds attributes to the default data coming through the .org themes api.
|
|
|
|
// Map `id` to `slug` for shared code.
|
2014-03-11 03:47:15 -04:00
|
|
|
initialize: function() {
|
2014-04-14 21:16:14 -04:00
|
|
|
var description;
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2020-06-13 10:26:07 -04:00
|
|
|
if ( this.get( 'slug' ) ) {
|
|
|
|
// If the theme is already installed, set an attribute.
|
|
|
|
if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) {
|
|
|
|
this.set({ installed: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the theme is active, set an attribute.
|
|
|
|
if ( themes.data.activeTheme === this.get( 'slug' ) ) {
|
|
|
|
this.set({ active: true });
|
|
|
|
}
|
2020-06-08 14:16:10 -04:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set the attributes.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.set({
|
2020-01-28 19:45:18 -05:00
|
|
|
// `slug` is for installation, `id` is for existing.
|
2014-03-11 20:29:15 -04:00
|
|
|
id: this.get( 'slug' ) || this.get( 'id' )
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
2014-04-14 18:06:15 -04:00
|
|
|
|
|
|
|
// Map `section.description` to `description`
|
2020-01-28 19:45:18 -05:00
|
|
|
// as the API sometimes returns it differently.
|
2014-04-14 18:06:15 -04:00
|
|
|
if ( this.has( 'sections' ) ) {
|
|
|
|
description = this.get( 'sections' ).description;
|
|
|
|
this.set({ description: description });
|
|
|
|
}
|
2014-03-11 03:47:15 -04:00
|
|
|
}
|
|
|
|
});
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Main view controller for themes.php.
|
|
|
|
// Unifies and renders all available views.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.view.Appearance = wp.Backbone.View.extend({
|
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
el: '#wpbody-content .wrap .theme-browser',
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
window: $( window ),
|
2020-01-28 19:45:18 -05:00
|
|
|
// Pagination instance.
|
2013-11-13 15:58:05 -05:00
|
|
|
page: 0,
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sets up a throttler for binding to 'scroll'.
|
2014-03-11 03:47:15 -04:00
|
|
|
initialize: function( options ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Scroller checks how far the scroll position is.
|
2013-11-29 00:14:09 -05:00
|
|
|
_.bindAll( this, 'scroller' );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.SearchView = options.SearchView ? options.SearchView : themes.view.Search;
|
2013-11-29 00:14:09 -05:00
|
|
|
// Bind to the scroll event and throttle
|
2020-01-28 19:45:18 -05:00
|
|
|
// the results from this.scroller.
|
2013-11-29 00:14:09 -05:00
|
|
|
this.window.bind( 'scroll', _.throttle( this.scroller, 300 ) );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Main render control.
|
2013-11-13 15:58:05 -05:00
|
|
|
render: function() {
|
|
|
|
// Setup the main theme view
|
2020-01-28 19:45:18 -05:00
|
|
|
// with the current theme collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.view = new themes.view.Themes({
|
|
|
|
collection: this.collection,
|
|
|
|
parent: this
|
|
|
|
});
|
2013-11-20 14:44:12 -05:00
|
|
|
|
|
|
|
// Render search form.
|
|
|
|
this.search();
|
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
this.$el.removeClass( 'search-loading' );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render and append.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.view.render();
|
2015-04-02 22:32:28 -04:00
|
|
|
this.$el.empty().append( this.view.el ).addClass( 'rendered' );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Defines search element container.
|
2017-05-08 11:59:44 -04:00
|
|
|
searchContainer: $( '.search-form' ),
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
// Search input and view
|
2020-01-28 19:45:18 -05:00
|
|
|
// for current theme collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
search: function() {
|
|
|
|
var view,
|
|
|
|
self = this;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Don't render the search if there is only one theme.
|
2013-12-04 19:16:10 -05:00
|
|
|
if ( themes.data.themes.length === 1 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
view = new this.SearchView({
|
|
|
|
collection: self.collection,
|
|
|
|
parent: this
|
|
|
|
});
|
2017-11-23 14:29:46 -05:00
|
|
|
self.SearchView = view;
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render and append after screen title.
|
2013-11-13 15:58:05 -05:00
|
|
|
view.render();
|
2014-03-11 03:47:15 -04:00
|
|
|
this.searchContainer
|
2014-07-17 23:40:16 -04:00
|
|
|
.append( $.parseHTML( '<label class="screen-reader-text" for="wp-filter-search-input">' + l10n.search + '</label>' ) )
|
2017-09-05 13:26:45 -04:00
|
|
|
.append( view.el )
|
|
|
|
.on( 'submit', function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Checks when the user gets close to the bottom
|
2020-01-28 19:45:18 -05:00
|
|
|
// of the mage and triggers a theme:scroll event.
|
2013-11-13 15:58:05 -05:00
|
|
|
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' );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up the Collection for our theme data.
|
2013-11-13 15:58:05 -05:00
|
|
|
// @has 'id' 'name' 'screenshot' 'author' 'authorURI' 'version' 'active' ...
|
|
|
|
themes.Collection = Backbone.Collection.extend({
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
model: themes.Model,
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Search terms.
|
2013-11-13 15:58:05 -05:00
|
|
|
terms: '',
|
|
|
|
|
|
|
|
// Controls searching on the current theme collection
|
2020-01-28 19:45:18 -05:00
|
|
|
// and triggers an update event.
|
2013-11-13 15:58:05 -05:00
|
|
|
doSearch: function( value ) {
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Don't do anything if we've already done this search.
|
|
|
|
// Useful because the Search handler fires multiple times per keystroke.
|
2013-12-02 02:16:10 -05:00
|
|
|
if ( this.terms === value ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Updates terms with the value passed.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.terms = value;
|
|
|
|
|
|
|
|
// If we have terms, run a search...
|
|
|
|
if ( this.terms.length > 0 ) {
|
|
|
|
this.search( this.terms );
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If search is blank, show all themes.
|
|
|
|
// Useful for resetting the views when you clean the input.
|
2013-11-13 15:58:05 -05:00
|
|
|
if ( this.terms === '' ) {
|
|
|
|
this.reset( themes.data.themes );
|
2015-04-02 22:32:28 -04:00
|
|
|
$( 'body' ).removeClass( 'no-results' );
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trigger a 'themes:update' event.
|
2016-02-18 16:21:26 -05:00
|
|
|
this.trigger( 'themes:update' );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
2013-12-01 19:55:09 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/**
|
|
|
|
* Performs a search within the collection.
|
|
|
|
*
|
|
|
|
* @uses RegExp
|
|
|
|
*/
|
2013-11-13 15:58:05 -05:00
|
|
|
search: function( term ) {
|
2015-01-18 15:40:23 -05:00
|
|
|
var match, results, haystack, name, description, author;
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Start with a full collection.
|
2013-12-05 14:15:11 -05:00
|
|
|
this.reset( themes.data.themes, { silent: true } );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trim the term.
|
2019-06-20 10:15:53 -04:00
|
|
|
term = term.trim();
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Escape the term string for RegExp meta characters.
|
2014-03-21 17:04:15 -04:00
|
|
|
term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' );
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
// Consider spaces as word delimiters and match the whole string
|
2020-01-28 19:45:18 -05:00
|
|
|
// so matching terms can be combined.
|
2014-03-21 17:04:15 -04:00
|
|
|
term = term.replace( / /g, ')(?=.*' );
|
2013-11-13 15:58:05 -05:00
|
|
|
match = new RegExp( '^(?=.*' + term + ').+', 'i' );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Find results.
|
|
|
|
// _.filter() and .test().
|
2013-12-05 14:15:11 -05:00
|
|
|
results = this.filter( function( data ) {
|
2015-01-18 15:40:23 -05:00
|
|
|
name = data.get( 'name' ).replace( /(<([^>]+)>)/ig, '' );
|
|
|
|
description = data.get( 'description' ).replace( /(<([^>]+)>)/ig, '' );
|
|
|
|
author = data.get( 'author' ).replace( /(<([^>]+)>)/ig, '' );
|
|
|
|
|
2016-02-18 16:21:26 -05:00
|
|
|
haystack = _.union( [ name, data.get( 'id' ), description, author, data.get( 'tags' ) ] );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2013-12-05 14:57:11 -05:00
|
|
|
if ( match.test( data.get( 'author' ) ) && term.length > 2 ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
data.set( 'displayAuthor', true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return match.test( haystack );
|
|
|
|
});
|
|
|
|
|
2014-06-29 05:16:14 -04:00
|
|
|
if ( results.length === 0 ) {
|
|
|
|
this.trigger( 'query:empty' );
|
|
|
|
} else {
|
|
|
|
$( 'body' ).removeClass( 'no-results' );
|
|
|
|
}
|
|
|
|
|
2013-12-05 14:15:11 -05:00
|
|
|
this.reset( results );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Paginates the collection with a helper method
|
2020-01-28 19:45:18 -05:00
|
|
|
// that slices the collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
paginate: function( instance ) {
|
|
|
|
var collection = this;
|
|
|
|
instance = instance || 0;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Themes per instance are set at 20.
|
2014-03-26 13:46:16 -04:00
|
|
|
collection = _( collection.rest( 20 * instance ) );
|
|
|
|
collection = _( collection.first( 20 ) );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
return collection;
|
2014-03-28 17:49:14 -04:00
|
|
|
},
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
count: false,
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* Handles requests for more themes and caches results.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* When we are missing a cache object we fire an apiCall()
|
|
|
|
* which triggers events of `query:success` or `query:fail`.
|
|
|
|
*/
|
2014-04-14 21:16:14 -04:00
|
|
|
query: function( request ) {
|
2014-03-28 17:49:14 -04:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type Array
|
|
|
|
*/
|
|
|
|
var queries = this.queries,
|
|
|
|
self = this,
|
|
|
|
query, isPaginated, count;
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
// Store current query request args
|
2020-01-28 19:45:18 -05:00
|
|
|
// for later use with the event `theme:end`.
|
2014-04-03 19:53:15 -04:00
|
|
|
this.currentQuery.request = request;
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Search the query cache for matches.
|
|
|
|
query = _.find( queries, function( query ) {
|
|
|
|
return _.isEqual( query.request, request );
|
|
|
|
});
|
|
|
|
|
|
|
|
// If the request matches the stored currentQuery.request
|
|
|
|
// it means we have a paginated request.
|
|
|
|
isPaginated = _.has( request, 'page' );
|
|
|
|
|
2020-06-20 08:16:10 -04:00
|
|
|
// Reset the internal api page counter for non-paginated queries.
|
2014-03-28 17:49:14 -04:00
|
|
|
if ( ! isPaginated ) {
|
|
|
|
this.currentQuery.page = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, send a new API call and add it to the cache.
|
2014-04-03 19:53:15 -04:00
|
|
|
if ( ! query && ! isPaginated ) {
|
2014-04-14 21:16:14 -04:00
|
|
|
query = this.apiCall( request ).done( function( data ) {
|
2014-04-14 18:06:15 -04:00
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Update the collection with the queried data.
|
2014-04-14 18:06:15 -04:00
|
|
|
if ( data.themes ) {
|
|
|
|
self.reset( data.themes );
|
|
|
|
count = data.info.results;
|
2020-01-28 19:45:18 -05:00
|
|
|
// Store the results and the query request.
|
2014-04-14 18:06:15 -04:00
|
|
|
queries.push( { themes: data.themes, request: request, total: count } );
|
|
|
|
}
|
2014-03-28 17:49:14 -04:00
|
|
|
|
|
|
|
// Trigger a collection refresh event
|
|
|
|
// and a `query:success` event with a `count` argument.
|
2016-02-18 16:21:26 -05:00
|
|
|
self.trigger( 'themes:update' );
|
2014-03-28 17:49:14 -04:00
|
|
|
self.trigger( 'query:success', count );
|
|
|
|
|
2014-04-14 18:06:15 -04:00
|
|
|
if ( data.themes && data.themes.length === 0 ) {
|
2014-04-01 18:20:14 -04:00
|
|
|
self.trigger( 'query:empty' );
|
|
|
|
}
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
}).fail( function() {
|
|
|
|
self.trigger( 'query:fail' );
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// If it's a paginated request we need to fetch more themes...
|
|
|
|
if ( isPaginated ) {
|
2014-04-14 21:16:14 -04:00
|
|
|
return this.apiCall( request, isPaginated ).done( function( data ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Add the new themes to the current collection.
|
|
|
|
// @todo Update counter.
|
2014-03-28 17:49:14 -04:00
|
|
|
self.add( data.themes );
|
|
|
|
self.trigger( 'query:success' );
|
|
|
|
|
2014-03-29 05:09:14 -04:00
|
|
|
// We are done loading themes for now.
|
|
|
|
self.loadingThemes = false;
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
}).fail( function() {
|
|
|
|
self.trigger( 'query:fail' );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:20:14 -04:00
|
|
|
if ( query.themes.length === 0 ) {
|
|
|
|
self.trigger( 'query:empty' );
|
|
|
|
} else {
|
|
|
|
$( 'body' ).removeClass( 'no-results' );
|
|
|
|
}
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Only trigger an update event since we already have the themes
|
2020-01-28 19:45:18 -05:00
|
|
|
// on our cached object.
|
2014-04-03 19:53:15 -04:00
|
|
|
if ( _.isNumber( query.total ) ) {
|
|
|
|
this.count = query.total;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:16:14 -04:00
|
|
|
this.reset( query.themes );
|
2014-04-03 19:53:15 -04:00
|
|
|
if ( ! query.total ) {
|
|
|
|
this.count = this.length;
|
|
|
|
}
|
|
|
|
|
2016-02-18 16:21:26 -05:00
|
|
|
this.trigger( 'themes:update' );
|
2014-04-14 21:16:14 -04:00
|
|
|
this.trigger( 'query:success', this.count );
|
2014-03-28 17:49:14 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Local cache array for API queries.
|
2014-03-28 17:49:14 -04:00
|
|
|
queries: [],
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Keep track of current query so we can handle pagination.
|
2014-03-28 17:49:14 -04:00
|
|
|
currentQuery: {
|
|
|
|
page: 1,
|
|
|
|
request: {}
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Send request to api.wordpress.org/themes.
|
2014-04-14 21:16:14 -04:00
|
|
|
apiCall: function( request, paginated ) {
|
|
|
|
return wp.ajax.send( 'query-themes', {
|
2014-03-28 17:49:14 -04:00
|
|
|
data: {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Request data.
|
2014-03-28 17:49:14 -04:00
|
|
|
request: _.extend({
|
2018-02-01 00:19:30 -05:00
|
|
|
per_page: 100
|
2014-03-28 17:49:14 -04:00
|
|
|
}, request)
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeSend: function() {
|
|
|
|
if ( ! paginated ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Spin it.
|
2014-07-17 23:40:16 -04:00
|
|
|
$( 'body' ).addClass( 'loading-content' ).removeClass( 'no-results' );
|
2014-03-28 17:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-29 05:09:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Static status controller for when we are loading themes.
|
|
|
|
loadingThemes: false
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// This is the view that controls each theme item
|
2020-01-28 19:45:18 -05:00
|
|
|
// that will be displayed on the screen.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.view.Theme = wp.Backbone.View.extend({
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Wrap theme data on a div.theme element.
|
2013-11-13 15:58:05 -05:00
|
|
|
className: 'theme',
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Reflects which theme view we have.
|
|
|
|
// 'grid' (default) or 'detail'.
|
2013-11-13 15:58:05 -05:00
|
|
|
state: 'grid',
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The HTML template for each element to be rendered.
|
2013-11-13 15:58:05 -05:00
|
|
|
html: themes.template( 'theme' ),
|
|
|
|
|
|
|
|
events: {
|
2014-03-11 03:47:15 -04:00
|
|
|
'click': themes.isInstall ? 'preview': 'expand',
|
|
|
|
'keydown': themes.isInstall ? 'preview': 'expand',
|
|
|
|
'touchend': themes.isInstall ? 'preview': 'expand',
|
2014-03-27 23:16:15 -04:00
|
|
|
'keyup': 'addFocus',
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
'touchmove': 'preventExpand',
|
|
|
|
'click .theme-install': 'installTheme',
|
|
|
|
'click .update-message': 'updateTheme'
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2013-12-09 14:38:10 -05:00
|
|
|
touchDrag: false,
|
|
|
|
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
initialize: function() {
|
|
|
|
this.model.on( 'change', this.render, this );
|
|
|
|
},
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
render: function() {
|
|
|
|
var data = this.model.toJSON();
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render themes using the html template.
|
2014-01-22 16:00:11 -05:00
|
|
|
this.$el.html( this.html( data ) ).attr({
|
|
|
|
tabindex: 0,
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
'aria-describedby' : data.id + '-action ' + data.id + '-name',
|
|
|
|
'data-slug': data.id
|
2014-01-22 16:00:11 -05:00
|
|
|
});
|
2014-01-08 16:35:09 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Renders active theme styles.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.activeTheme();
|
|
|
|
|
|
|
|
if ( this.model.get( 'displayAuthor' ) ) {
|
|
|
|
this.$el.addClass( 'display-author' );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Adds a class to the currently active theme
|
2020-01-28 19:45:18 -05:00
|
|
|
// and to the overlay in detailed view mode.
|
2013-11-13 15:58:05 -05:00
|
|
|
activeTheme: function() {
|
|
|
|
if ( this.model.get( 'active' ) ) {
|
|
|
|
this.$el.addClass( 'active' );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-27 23:16:15 -04:00
|
|
|
// Add class of focus to the theme we are focused on.
|
|
|
|
addFocus: function() {
|
|
|
|
var $themeToFocus = ( $( ':focus' ).hasClass( 'theme' ) ) ? $( ':focus' ) : $(':focus').parents('.theme');
|
|
|
|
|
|
|
|
$('.theme.focus').removeClass('focus');
|
|
|
|
$themeToFocus.addClass('focus');
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Single theme overlay screen.
|
|
|
|
// It's shown when clicking a theme.
|
2013-11-13 15:58:05 -05:00
|
|
|
expand: function( event ) {
|
|
|
|
var self = this;
|
|
|
|
|
2014-01-08 16:35:09 -05:00
|
|
|
event = event || window.event;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// 'Enter' and 'Space' keys expand the details view when a theme is :focused.
|
2014-01-08 16:35:09 -05:00
|
|
|
if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bail if the user scrolled on a touch device.
|
2013-12-09 14:38:10 -05:00
|
|
|
if ( this.touchDrag === true ) {
|
|
|
|
return this.touchDrag = false;
|
|
|
|
}
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
// Prevent the modal from showing when the user clicks
|
2020-01-28 19:45:18 -05:00
|
|
|
// one of the direct action buttons.
|
2013-12-01 19:55:09 -05:00
|
|
|
if ( $( event.target ).is( '.theme-actions a' ) ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
// Prevent the modal from showing when the user clicks one of the direct action buttons.
|
|
|
|
if ( $( event.target ).is( '.theme-actions a, .update-message, .button-link, .notice-dismiss' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set focused theme to current element.
|
2014-01-08 16:35:09 -05:00
|
|
|
themes.focusedTheme = this.$el;
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
this.trigger( 'theme:expand', self.model.cid );
|
2013-12-09 14:38:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
preventExpand: function() {
|
|
|
|
this.touchDrag = true;
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
preview: function( event ) {
|
2014-04-03 19:53:15 -04:00
|
|
|
var self = this,
|
2014-04-04 01:23:14 -04:00
|
|
|
current, preview;
|
2014-04-03 19:53:15 -04:00
|
|
|
|
2015-08-19 14:54:27 -04:00
|
|
|
event = event || window.event;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bail if the user scrolled on a touch device.
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( this.touchDrag === true ) {
|
|
|
|
return this.touchDrag = false;
|
|
|
|
}
|
|
|
|
|
2014-04-07 19:04:15 -04:00
|
|
|
// Allow direct link path to installing a theme.
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
if ( $( event.target ).not( '.install-theme-preview' ).parents( '.theme-actions' ).length ) {
|
2014-04-07 19:04:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// 'Enter' and 'Space' keys expand the details view when a theme is :focused.
|
2014-03-27 23:16:15 -04:00
|
|
|
if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Pressing Enter while focused on the buttons shouldn't open the preview.
|
2014-03-27 23:16:15 -04:00
|
|
|
if ( event.type === 'keydown' && event.which !== 13 && $( ':focus' ).hasClass( 'button' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
event = event || window.event;
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
// Set focus to current theme.
|
|
|
|
themes.focusedTheme = this.$el;
|
|
|
|
|
|
|
|
// Construct a new Preview view.
|
2017-05-23 16:32:44 -04:00
|
|
|
themes.preview = preview = new themes.view.Preview({
|
2014-03-11 03:47:15 -04:00
|
|
|
model: this.model
|
|
|
|
});
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
// Render the view and append it.
|
2014-03-11 03:47:15 -04:00
|
|
|
preview.render();
|
2014-04-08 12:24:14 -04:00
|
|
|
this.setNavButtonsState();
|
2014-04-14 18:06:15 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Hide previous/next navigation if there is only one theme.
|
2014-04-14 18:06:15 -04:00
|
|
|
if ( this.model.collection.length === 1 ) {
|
|
|
|
preview.$el.addClass( 'no-navigation' );
|
|
|
|
} else {
|
|
|
|
preview.$el.removeClass( 'no-navigation' );
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Append preview.
|
2014-03-11 03:47:15 -04:00
|
|
|
$( 'div.wrap' ).append( preview.el );
|
2014-04-03 19:53:15 -04:00
|
|
|
|
|
|
|
// Listen to our preview object
|
|
|
|
// for `theme:next` and `theme:previous` events.
|
|
|
|
this.listenTo( preview, 'theme:next', function() {
|
|
|
|
|
|
|
|
// Keep local track of current theme model.
|
|
|
|
current = self.model;
|
|
|
|
|
|
|
|
// If we have ventured away from current model update the current model position.
|
|
|
|
if ( ! _.isUndefined( self.current ) ) {
|
|
|
|
current = self.current;
|
|
|
|
}
|
|
|
|
|
2014-06-18 21:36:14 -04:00
|
|
|
// Get next theme model.
|
2014-04-03 19:53:15 -04:00
|
|
|
self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 );
|
|
|
|
|
|
|
|
// If we have no more themes, bail.
|
|
|
|
if ( _.isUndefined( self.current ) ) {
|
2014-04-07 19:04:15 -04:00
|
|
|
self.options.parent.parent.trigger( 'theme:end' );
|
2014-04-03 19:53:15 -04:00
|
|
|
return self.current = current;
|
|
|
|
}
|
|
|
|
|
2014-06-27 12:06:15 -04:00
|
|
|
preview.model = self.current;
|
2014-04-03 19:53:15 -04:00
|
|
|
|
|
|
|
// Render and append.
|
|
|
|
preview.render();
|
2014-04-07 23:57:15 -04:00
|
|
|
this.setNavButtonsState();
|
2014-04-07 19:04:15 -04:00
|
|
|
$( '.next-theme' ).focus();
|
2014-04-03 19:53:15 -04:00
|
|
|
})
|
|
|
|
.listenTo( preview, 'theme:previous', function() {
|
|
|
|
|
|
|
|
// Keep track of current theme model.
|
|
|
|
current = self.model;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bail early if we are at the beginning of the collection.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( self.model.collection.indexOf( self.current ) === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
// If we have ventured away from current model update the current model position.
|
|
|
|
if ( ! _.isUndefined( self.current ) ) {
|
|
|
|
current = self.current;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get previous theme model.
|
|
|
|
self.current = self.model.collection.at( self.model.collection.indexOf( current ) - 1 );
|
|
|
|
|
|
|
|
// If we have no more themes, bail.
|
|
|
|
if ( _.isUndefined( self.current ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-27 12:06:15 -04:00
|
|
|
preview.model = self.current;
|
2014-04-03 19:53:15 -04:00
|
|
|
|
|
|
|
// Render and append.
|
|
|
|
preview.render();
|
2014-04-07 23:57:15 -04:00
|
|
|
this.setNavButtonsState();
|
2014-04-07 19:04:15 -04:00
|
|
|
$( '.previous-theme' ).focus();
|
2014-04-03 19:53:15 -04:00
|
|
|
});
|
2014-04-08 12:24:14 -04:00
|
|
|
|
|
|
|
this.listenTo( preview, 'preview:close', function() {
|
2014-04-08 20:58:15 -04:00
|
|
|
self.current = self.model;
|
2014-04-08 12:24:14 -04:00
|
|
|
});
|
2017-02-24 12:48:42 -05:00
|
|
|
|
2014-04-08 12:24:14 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles .disabled classes for previous/next buttons in theme installer preview.
|
2014-04-08 12:24:14 -04:00
|
|
|
setNavButtonsState: function() {
|
|
|
|
var $themeInstaller = $( '.theme-install-overlay' ),
|
2018-04-29 13:04:22 -04:00
|
|
|
current = _.isUndefined( this.current ) ? this.model : this.current,
|
|
|
|
previousThemeButton = $themeInstaller.find( '.previous-theme' ),
|
|
|
|
nextThemeButton = $themeInstaller.find( '.next-theme' );
|
2014-04-08 12:24:14 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Disable previous at the zero position.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( 0 === this.model.collection.indexOf( current ) ) {
|
2018-04-29 13:04:22 -04:00
|
|
|
previousThemeButton
|
|
|
|
.addClass( 'disabled' )
|
|
|
|
.prop( 'disabled', true );
|
|
|
|
|
|
|
|
nextThemeButton.focus();
|
2014-04-08 12:24:14 -04:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Disable next if the next model is undefined.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( _.isUndefined( this.model.collection.at( this.model.collection.indexOf( current ) + 1 ) ) ) {
|
2018-04-29 13:04:22 -04:00
|
|
|
nextThemeButton
|
|
|
|
.addClass( 'disabled' )
|
|
|
|
.prop( 'disabled', true );
|
|
|
|
|
|
|
|
previousThemeButton.focus();
|
2014-04-08 12:24:14 -04:00
|
|
|
}
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
installTheme: function( event ) {
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
wp.updates.maybeRequestFilesystemCredentials( event );
|
|
|
|
|
2016-08-08 18:49:28 -04:00
|
|
|
$( document ).on( 'wp-theme-install-success', function( event, response ) {
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
if ( _this.model.get( 'id' ) === response.slug ) {
|
|
|
|
_this.model.set( { 'installed': true } );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.updates.installTheme( {
|
|
|
|
slug: $( event.target ).data( 'slug' )
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
updateTheme: function( event ) {
|
|
|
|
var _this = this;
|
2016-10-21 06:36:46 -04:00
|
|
|
|
|
|
|
if ( ! this.model.get( 'hasPackage' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
wp.updates.maybeRequestFilesystemCredentials( event );
|
|
|
|
|
|
|
|
$( document ).on( 'wp-theme-update-success', function( event, response ) {
|
|
|
|
_this.model.off( 'change', _this.render, _this );
|
|
|
|
if ( _this.model.get( 'id' ) === response.slug ) {
|
|
|
|
_this.model.set( {
|
|
|
|
hasUpdate: false,
|
|
|
|
version: response.newVersion
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
_this.model.on( 'change', _this.render, _this );
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.updates.updateTheme( {
|
|
|
|
slug: $( event.target ).parents( 'div.theme' ).first().data( 'slug' )
|
|
|
|
} );
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
2013-07-05 11:15:58 -04:00
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Theme Details view.
|
|
|
|
// Sets up a modal overlay with the expanded theme data.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.view.Details = wp.Backbone.View.extend({
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Wrap theme data on a div.theme element.
|
2013-11-20 14:44:12 -05:00
|
|
|
className: 'theme-overlay',
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
events: {
|
|
|
|
'click': 'collapse',
|
|
|
|
'click .delete-theme': 'deleteTheme',
|
|
|
|
'click .left': 'previousTheme',
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
'click .right': 'nextTheme',
|
2020-06-01 16:53:15 -04:00
|
|
|
'click #update-theme': 'updateTheme',
|
|
|
|
'click .toggle-auto-update': 'autoupdateState'
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The HTML template for the theme overlay.
|
2013-11-13 15:58:05 -05:00
|
|
|
html: themes.template( 'theme-single' ),
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var data = this.model.toJSON();
|
|
|
|
this.$el.html( this.html( data ) );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Renders active theme styles.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.activeTheme();
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up navigation events.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.navigation();
|
2020-01-28 19:45:18 -05:00
|
|
|
// Checks screenshot size.
|
2013-12-06 14:42:11 -05:00
|
|
|
this.screenshotCheck( this.$el );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Contain "tabbing" inside the overlay.
|
2014-01-08 16:35:09 -05:00
|
|
|
this.containFocus( this.$el );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Adds a class to the currently active theme
|
2020-01-28 19:45:18 -05:00
|
|
|
// and to the overlay in detailed view mode.
|
2013-11-13 15:58:05 -05:00
|
|
|
activeTheme: function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Check the model has the active property.
|
2013-11-20 14:44:12 -05:00
|
|
|
this.$el.toggleClass( 'active', this.model.get( 'active' ) );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2016-07-17 18:19:30 -04:00
|
|
|
// Set initial focus and constrain tabbing within the theme browser modal.
|
2014-01-08 16:35:09 -05:00
|
|
|
containFocus: function( $el ) {
|
|
|
|
|
2016-07-17 18:19:30 -04:00
|
|
|
// Set initial focus on the primary action control.
|
2014-01-08 16:35:09 -05:00
|
|
|
_.delay( function() {
|
2017-10-01 09:48:46 -04:00
|
|
|
$( '.theme-overlay' ).focus();
|
2016-07-17 18:19:30 -04:00
|
|
|
}, 100 );
|
2014-01-08 16:35:09 -05:00
|
|
|
|
2016-07-17 18:19:30 -04:00
|
|
|
// Constrain tabbing within the modal.
|
2014-01-08 16:35:09 -05:00
|
|
|
$el.on( 'keydown.wp-themes', function( event ) {
|
2016-07-17 18:19:30 -04:00
|
|
|
var $firstFocusable = $el.find( '.theme-header button:not(.disabled)' ).first(),
|
|
|
|
$lastFocusable = $el.find( '.theme-actions a:visible' ).last();
|
2014-01-08 16:35:09 -05:00
|
|
|
|
2016-07-17 18:19:30 -04:00
|
|
|
// Check for the Tab key.
|
|
|
|
if ( 9 === event.which ) {
|
|
|
|
if ( $firstFocusable[0] === event.target && event.shiftKey ) {
|
|
|
|
$lastFocusable.focus();
|
2014-01-08 16:35:09 -05:00
|
|
|
event.preventDefault();
|
2016-07-17 18:19:30 -04:00
|
|
|
} else if ( $lastFocusable[0] === event.target && ! event.shiftKey ) {
|
|
|
|
$firstFocusable.focus();
|
2014-01-08 16:35:09 -05:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Single theme overlay screen.
|
|
|
|
// It's shown when clicking a theme.
|
2013-11-13 15:58:05 -05:00
|
|
|
collapse: function( event ) {
|
|
|
|
var self = this,
|
|
|
|
scroll;
|
|
|
|
|
|
|
|
event = event || window.event;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Prevent collapsing detailed view when there is only one theme available.
|
2013-12-04 23:57:10 -05:00
|
|
|
if ( themes.data.themes.length === 1 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Detect if the click is inside the overlay and don't close it
|
|
|
|
// unless the target was the div.back button.
|
2014-01-08 16:35:09 -05:00
|
|
|
if ( $( event.target ).is( '.theme-backdrop' ) || $( event.target ).is( '.close' ) || event.keyCode === 27 ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Add a temporary closing class while overlay fades out.
|
2013-11-13 15:58:05 -05:00
|
|
|
$( 'body' ).addClass( 'closing-overlay' );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// With a quick fade out animation.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.$el.fadeOut( 130, function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Clicking outside the modal box closes the overlay.
|
2014-02-26 19:18:13 -05:00
|
|
|
$( 'body' ).removeClass( 'closing-overlay' );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handle event cleanup.
|
2013-11-13 15:58:05 -05:00
|
|
|
self.closeOverlay();
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get scroll position to avoid jumping to the top.
|
2013-11-13 15:58:05 -05:00
|
|
|
scroll = document.body.scrollTop;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Clean the URL structure.
|
2014-02-25 14:22:13 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( '' ) );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Restore scroll position.
|
2013-11-13 15:58:05 -05:00
|
|
|
document.body.scrollTop = scroll;
|
2014-01-08 16:35:09 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Return focus to the theme div.
|
2014-01-08 16:35:09 -05:00
|
|
|
if ( themes.focusedTheme ) {
|
|
|
|
themes.focusedTheme.focus();
|
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles .disabled classes for next/previous buttons.
|
2013-11-13 15:58:05 -05:00
|
|
|
navigation: function() {
|
2013-12-01 00:59:11 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Disable Left/Right when at the start or end of the collection.
|
2013-12-01 00:59:11 -05:00
|
|
|
if ( this.model.cid === this.model.collection.at(0).cid ) {
|
2016-07-17 18:19:30 -04:00
|
|
|
this.$el.find( '.left' )
|
|
|
|
.addClass( 'disabled' )
|
|
|
|
.prop( 'disabled', true );
|
2013-12-01 00:59:11 -05:00
|
|
|
}
|
|
|
|
if ( this.model.cid === this.model.collection.at( this.model.collection.length - 1 ).cid ) {
|
2016-07-17 18:19:30 -04:00
|
|
|
this.$el.find( '.right' )
|
|
|
|
.addClass( 'disabled' )
|
|
|
|
.prop( 'disabled', true );
|
2013-12-01 00:59:11 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Performs the actions to effectively close
|
2020-01-28 19:45:18 -05:00
|
|
|
// the theme details overlay.
|
2013-11-13 15:58:05 -05:00
|
|
|
closeOverlay: function() {
|
2014-08-01 16:15:15 -04:00
|
|
|
$( 'body' ).removeClass( 'modal-open' );
|
2013-11-13 15:58:05 -05:00
|
|
|
this.remove();
|
|
|
|
this.unbind();
|
|
|
|
this.trigger( 'theme:collapse' );
|
|
|
|
},
|
|
|
|
|
2020-06-01 16:53:15 -04:00
|
|
|
// Set state of the auto-update settings link after it has been changed and saved.
|
|
|
|
autoupdateState: function() {
|
|
|
|
var callback,
|
|
|
|
_this = this;
|
|
|
|
|
|
|
|
// Support concurrent clicks in different Theme Details overlays.
|
|
|
|
callback = function( event, data ) {
|
|
|
|
if ( _this.model.get( 'id' ) === data.asset ) {
|
|
|
|
_this.model.set( { autoupdate: 'enable' === data.state } );
|
|
|
|
$( document ).off( 'wp-auto-update-setting-changed', callback );
|
|
|
|
}
|
2020-06-01 17:41:09 -04:00
|
|
|
};
|
2020-06-01 16:53:15 -04:00
|
|
|
|
|
|
|
// Triggered in updates.js
|
|
|
|
$( document ).on( 'wp-auto-update-setting-changed', callback );
|
|
|
|
},
|
|
|
|
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
updateTheme: function( event ) {
|
|
|
|
var _this = this;
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
wp.updates.maybeRequestFilesystemCredentials( event );
|
|
|
|
|
|
|
|
$( document ).on( 'wp-theme-update-success', function( event, response ) {
|
|
|
|
if ( _this.model.get( 'id' ) === response.slug ) {
|
|
|
|
_this.model.set( {
|
|
|
|
hasUpdate: false,
|
|
|
|
version: response.newVersion
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
_this.render();
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.updates.updateTheme( {
|
|
|
|
slug: $( event.target ).data( 'slug' )
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteTheme: function( event ) {
|
|
|
|
var _this = this,
|
|
|
|
_collection = _this.model.collection,
|
|
|
|
_themes = themes;
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// Confirmation dialog for deleting a theme.
|
|
|
|
if ( ! window.confirm( wp.themes.data.settings.confirmDelete ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.updates.maybeRequestFilesystemCredentials( event );
|
|
|
|
|
2016-08-08 18:49:28 -04:00
|
|
|
$( document ).one( 'wp-theme-delete-success', function( event, response ) {
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
_this.$el.find( '.close' ).trigger( 'click' );
|
2016-12-12 04:32:41 -05:00
|
|
|
$( '[data-slug="' + response.slug + '"]' ).css( { backgroundColor:'#faafaa' } ).fadeOut( 350, function() {
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
$( this ).remove();
|
|
|
|
_themes.data.themes = _.without( _themes.data.themes, _.findWhere( _themes.data.themes, { id: response.slug } ) );
|
|
|
|
|
|
|
|
$( '.wp-filter-search' ).val( '' );
|
|
|
|
_collection.doSearch( '' );
|
|
|
|
_collection.remove( _this.model );
|
|
|
|
_collection.trigger( 'themes:update' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.updates.deleteTheme( {
|
|
|
|
slug: this.model.get( 'id' )
|
|
|
|
} );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
nextTheme: function() {
|
|
|
|
var self = this;
|
|
|
|
self.trigger( 'theme:next', self.model.cid );
|
2014-04-07 23:57:15 -04:00
|
|
|
return false;
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
previousTheme: function() {
|
|
|
|
var self = this;
|
|
|
|
self.trigger( 'theme:previous', self.model.cid );
|
2014-04-07 23:57:15 -04:00
|
|
|
return false;
|
2013-12-06 14:42:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Checks if the theme screenshot is the old 300px width version
|
2020-01-28 19:45:18 -05:00
|
|
|
// and adds a corresponding class if it's true.
|
2013-12-06 14:42:11 -05:00
|
|
|
screenshotCheck: function( el ) {
|
2013-12-07 02:52:11 -05:00
|
|
|
var screenshot, image;
|
2013-12-06 14:42:11 -05:00
|
|
|
|
|
|
|
screenshot = el.find( '.screenshot img' );
|
|
|
|
image = new Image();
|
|
|
|
image.src = screenshot.attr( 'src' );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Width check.
|
2013-12-06 20:59:10 -05:00
|
|
|
if ( image.width && image.width <= 300 ) {
|
2013-12-07 02:52:11 -05:00
|
|
|
el.addClass( 'small-screenshot' );
|
2013-12-06 14:42:11 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Theme Preview view.
|
|
|
|
// Sets up a modal overlay with the expanded theme data.
|
2014-04-03 19:53:15 -04:00
|
|
|
themes.view.Preview = themes.view.Details.extend({
|
2014-03-11 03:47:15 -04:00
|
|
|
|
|
|
|
className: 'wp-full-overlay expanded',
|
2014-04-07 23:57:15 -04:00
|
|
|
el: '.theme-install-overlay',
|
2014-03-11 03:47:15 -04:00
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .close-full-overlay': 'close',
|
2014-04-03 19:53:15 -04:00
|
|
|
'click .collapse-sidebar': 'collapse',
|
2016-03-05 17:07:25 -05:00
|
|
|
'click .devices button': 'previewDevice',
|
2014-04-03 19:53:15 -04:00
|
|
|
'click .previous-theme': 'previousTheme',
|
2014-04-08 12:24:14 -04:00
|
|
|
'click .next-theme': 'nextTheme',
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
'keyup': 'keyEvent',
|
|
|
|
'click .theme-install': 'installTheme'
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The HTML template for the theme preview.
|
2014-03-11 03:47:15 -04:00
|
|
|
html: themes.template( 'theme-preview' ),
|
|
|
|
|
|
|
|
render: function() {
|
2016-09-04 17:51:31 -04:00
|
|
|
var self = this,
|
|
|
|
currentPreviewDevice,
|
|
|
|
data = this.model.toJSON(),
|
|
|
|
$body = $( document.body );
|
|
|
|
|
|
|
|
$body.attr( 'aria-busy', 'true' );
|
2014-04-08 20:58:15 -04:00
|
|
|
|
2015-10-20 01:36:25 -04:00
|
|
|
this.$el.removeClass( 'iframe-ready' ).html( this.html( data ) );
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2016-03-05 17:07:25 -05:00
|
|
|
currentPreviewDevice = this.$el.data( 'current-preview-device' );
|
|
|
|
if ( currentPreviewDevice ) {
|
|
|
|
self.tooglePreviewDeviceButtons( currentPreviewDevice );
|
|
|
|
}
|
|
|
|
|
2017-02-24 12:48:42 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.get( 'id' ) ), { replace: false } );
|
2014-03-11 03:47:15 -04:00
|
|
|
|
|
|
|
this.$el.fadeIn( 200, function() {
|
2016-09-04 17:51:31 -04:00
|
|
|
$body.addClass( 'theme-installer-active full-overlay-active' );
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
2015-10-20 01:36:25 -04:00
|
|
|
|
|
|
|
this.$el.find( 'iframe' ).one( 'load', function() {
|
|
|
|
self.iframeLoaded();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
iframeLoaded: function() {
|
|
|
|
this.$el.addClass( 'iframe-ready' );
|
2016-09-04 17:51:31 -04:00
|
|
|
$( document.body ).attr( 'aria-busy', 'false' );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
this.$el.fadeOut( 200, function() {
|
2014-04-08 12:24:14 -04:00
|
|
|
$( 'body' ).removeClass( 'theme-installer-active full-overlay-active' );
|
2014-04-03 19:53:15 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Return focus to the theme div.
|
2014-04-03 19:53:15 -04:00
|
|
|
if ( themes.focusedTheme ) {
|
|
|
|
themes.focusedTheme.focus();
|
|
|
|
}
|
2015-10-20 01:36:25 -04:00
|
|
|
}).removeClass( 'iframe-ready' );
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2017-05-23 16:32:44 -04:00
|
|
|
// Restore the previous browse tab if available.
|
|
|
|
if ( themes.router.selectedTab ) {
|
|
|
|
themes.router.navigate( themes.router.baseUrl( '?browse=' + themes.router.selectedTab ) );
|
|
|
|
themes.router.selectedTab = false;
|
|
|
|
} else {
|
|
|
|
themes.router.navigate( themes.router.baseUrl( '' ) );
|
|
|
|
}
|
2014-04-08 12:24:14 -04:00
|
|
|
this.trigger( 'preview:close' );
|
2014-06-27 12:06:15 -04:00
|
|
|
this.undelegateEvents();
|
2014-04-14 18:06:15 -04:00
|
|
|
this.unbind();
|
2014-03-11 03:47:15 -04:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-07-10 17:22:26 -04:00
|
|
|
collapse: function( event ) {
|
|
|
|
var $button = $( event.currentTarget );
|
|
|
|
if ( 'true' === $button.attr( 'aria-expanded' ) ) {
|
|
|
|
$button.attr({ 'aria-expanded': 'false', 'aria-label': l10n.expandSidebar });
|
|
|
|
} else {
|
|
|
|
$button.attr({ 'aria-expanded': 'true', 'aria-label': l10n.collapseSidebar });
|
|
|
|
}
|
2014-04-01 18:20:14 -04:00
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.$el.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
|
|
|
|
return false;
|
2014-04-08 12:24:14 -04:00
|
|
|
},
|
|
|
|
|
2016-03-05 17:07:25 -05:00
|
|
|
previewDevice: function( event ) {
|
|
|
|
var device = $( event.currentTarget ).data( 'device' );
|
|
|
|
|
|
|
|
this.$el
|
|
|
|
.removeClass( 'preview-desktop preview-tablet preview-mobile' )
|
|
|
|
.addClass( 'preview-' + device )
|
|
|
|
.data( 'current-preview-device', device );
|
|
|
|
|
|
|
|
this.tooglePreviewDeviceButtons( device );
|
|
|
|
},
|
|
|
|
|
|
|
|
tooglePreviewDeviceButtons: function( newDevice ) {
|
|
|
|
var $devices = $( '.wp-full-overlay-footer .devices' );
|
|
|
|
|
|
|
|
$devices.find( 'button' )
|
|
|
|
.removeClass( 'active' )
|
|
|
|
.attr( 'aria-pressed', false );
|
|
|
|
|
|
|
|
$devices.find( 'button.preview-' + newDevice )
|
|
|
|
.addClass( 'active' )
|
|
|
|
.attr( 'aria-pressed', true );
|
|
|
|
},
|
|
|
|
|
2014-04-08 12:24:14 -04:00
|
|
|
keyEvent: function( event ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// The escape key closes the preview.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( event.keyCode === 27 ) {
|
|
|
|
this.undelegateEvents();
|
|
|
|
this.close();
|
|
|
|
}
|
2020-01-28 19:45:18 -05:00
|
|
|
// The right arrow key, next theme.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( event.keyCode === 39 ) {
|
|
|
|
_.once( this.nextTheme() );
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The left arrow key, previous theme.
|
2014-04-08 12:24:14 -04:00
|
|
|
if ( event.keyCode === 37 ) {
|
|
|
|
this.previousTheme();
|
|
|
|
}
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
installTheme: function( event ) {
|
|
|
|
var _this = this,
|
|
|
|
$target = $( event.target );
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ( $target.hasClass( 'disabled' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.updates.maybeRequestFilesystemCredentials( event );
|
|
|
|
|
2016-08-08 18:49:28 -04:00
|
|
|
$( document ).on( 'wp-theme-install-success', function() {
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
_this.model.set( { 'installed': true } );
|
|
|
|
} );
|
|
|
|
|
|
|
|
wp.updates.installTheme( {
|
|
|
|
slug: $target.data( 'slug' )
|
|
|
|
} );
|
2014-03-11 03:47:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
// Controls the rendering of div.themes,
|
2020-01-28 19:45:18 -05:00
|
|
|
// a wrapper that will hold all the theme elements.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.view.Themes = wp.Backbone.View.extend({
|
|
|
|
|
2016-01-12 12:13:29 -05:00
|
|
|
className: 'themes wp-clearfix',
|
2013-12-06 22:11:10 -05:00
|
|
|
$overlay: $( 'div.theme-overlay' ),
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
// Number to keep track of scroll position
|
2020-01-28 19:45:18 -05:00
|
|
|
// while in theme-overlay mode.
|
2013-11-13 15:58:05 -05:00
|
|
|
index: 0,
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The theme count element.
|
2016-01-06 17:32:28 -05:00
|
|
|
count: $( '.wrap .theme-count' ),
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// The live themes count.
|
2015-04-02 22:32:28 -04:00
|
|
|
liveThemeCount: 0,
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
initialize: function( options ) {
|
|
|
|
var self = this;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up parent.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.parent = options.parent;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set current view to [grid].
|
2013-11-13 15:58:05 -05:00
|
|
|
this.setView( 'grid' );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Move the active theme to the beginning of the collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
self.currentTheme();
|
|
|
|
|
|
|
|
// When the collection is updated by user input...
|
2016-02-18 16:21:26 -05:00
|
|
|
this.listenTo( self.collection, 'themes:update', function() {
|
2013-11-13 15:58:05 -05:00
|
|
|
self.parent.page = 0;
|
|
|
|
self.currentTheme();
|
|
|
|
self.render( this );
|
2016-02-18 16:21:26 -05:00
|
|
|
} );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Update theme count to full result set when available.
|
|
|
|
this.listenTo( self.collection, 'query:success', function( count ) {
|
|
|
|
if ( _.isNumber( count ) ) {
|
|
|
|
self.count.text( count );
|
2015-04-02 22:32:28 -04:00
|
|
|
self.announceSearchResults( count );
|
2014-03-28 17:49:14 -04:00
|
|
|
} else {
|
|
|
|
self.count.text( self.collection.length );
|
2015-04-02 22:32:28 -04:00
|
|
|
self.announceSearchResults( self.collection.length );
|
2014-03-28 17:49:14 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-01 18:20:14 -04:00
|
|
|
this.listenTo( self.collection, 'query:empty', function() {
|
|
|
|
$( 'body' ).addClass( 'no-results' );
|
|
|
|
});
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
this.listenTo( this.parent, 'theme:scroll', function() {
|
|
|
|
self.renderThemes( self.parent.page );
|
|
|
|
});
|
2013-12-06 22:11:10 -05:00
|
|
|
|
2014-02-25 14:22:13 -05:00
|
|
|
this.listenTo( this.parent, 'theme:close', function() {
|
|
|
|
if ( self.overlay ) {
|
|
|
|
self.overlay.closeOverlay();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2013-12-06 22:11:10 -05:00
|
|
|
// Bind keyboard events.
|
2014-03-28 17:49:14 -04:00
|
|
|
$( 'body' ).on( 'keyup', function( event ) {
|
2013-12-09 02:07:10 -05:00
|
|
|
if ( ! self.overlay ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
// Bail if the filesystem credentials dialog is shown.
|
|
|
|
if ( $( '#request-filesystem-credentials-dialog' ).is( ':visible' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Pressing the right arrow key fires a theme:next event.
|
2013-12-06 22:11:10 -05:00
|
|
|
if ( event.keyCode === 39 ) {
|
|
|
|
self.overlay.nextTheme();
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Pressing the left arrow key fires a theme:previous event.
|
2013-12-06 22:11:10 -05:00
|
|
|
if ( event.keyCode === 37 ) {
|
|
|
|
self.overlay.previousTheme();
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Pressing the escape key fires a theme:collapse event.
|
2013-12-06 22:11:10 -05:00
|
|
|
if ( event.keyCode === 27 ) {
|
|
|
|
self.overlay.collapse( event );
|
|
|
|
}
|
|
|
|
});
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Manages rendering of theme pages
|
2020-01-28 19:45:18 -05:00
|
|
|
// and keeping theme count in sync.
|
2013-11-13 15:58:05 -05:00
|
|
|
render: function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Clear the DOM, please.
|
2015-03-09 15:44:26 -04:00
|
|
|
this.$el.empty();
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If the user doesn't have switch capabilities or there is only one theme
|
|
|
|
// in the collection, render the detailed view of the active theme.
|
2013-12-04 19:16:10 -05:00
|
|
|
if ( themes.data.themes.length === 1 ) {
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Constructs the view.
|
2013-12-04 19:16:10 -05:00
|
|
|
this.singleTheme = new themes.view.Details({
|
|
|
|
model: this.collection.models[0]
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render and apply a 'single-theme' class to our container.
|
2013-12-04 19:16:10 -05:00
|
|
|
this.singleTheme.render();
|
|
|
|
this.$el.addClass( 'single-theme' );
|
|
|
|
this.$el.append( this.singleTheme.el );
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Generate the themes using page instance
|
|
|
|
// while checking the collection has items.
|
2014-03-28 17:49:14 -04:00
|
|
|
if ( this.options.collection.size() > 0 ) {
|
|
|
|
this.renderThemes( this.parent.page );
|
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Display a live theme count for the collection.
|
2015-04-02 22:32:28 -04:00
|
|
|
this.liveThemeCount = this.collection.count ? this.collection.count : this.collection.length;
|
|
|
|
this.count.text( this.liveThemeCount );
|
|
|
|
|
2016-07-05 10:38:29 -04:00
|
|
|
/*
|
|
|
|
* In the theme installer the themes count is already announced
|
|
|
|
* because `announceSearchResults` is called on `query:success`.
|
|
|
|
*/
|
|
|
|
if ( ! themes.isInstall ) {
|
|
|
|
this.announceSearchResults( this.liveThemeCount );
|
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Iterates through each instance of the collection
|
2020-01-28 19:45:18 -05:00
|
|
|
// and renders each theme module.
|
2013-11-13 15:58:05 -05:00
|
|
|
renderThemes: function( page ) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.instance = self.collection.paginate( page );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If we have no more themes, bail.
|
2014-03-28 17:49:14 -04:00
|
|
|
if ( self.instance.size() === 0 ) {
|
|
|
|
// Fire a no-more-themes event.
|
|
|
|
this.parent.trigger( 'theme:end' );
|
2013-11-13 15:58:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure the add-new stays at the end.
|
2015-10-19 18:04:25 -04:00
|
|
|
if ( ! themes.isInstall && page >= 1 ) {
|
2013-11-20 14:44:12 -05:00
|
|
|
$( '.add-new-theme' ).remove();
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Loop through the themes and setup each theme view.
|
2013-11-13 15:58:05 -05:00
|
|
|
self.instance.each( function( theme ) {
|
|
|
|
self.theme = new themes.view.Theme({
|
2014-04-07 19:04:15 -04:00
|
|
|
model: theme,
|
|
|
|
parent: self
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
// Render the views...
|
|
|
|
self.theme.render();
|
2020-01-28 19:45:18 -05:00
|
|
|
// ...and append them to div.themes.
|
2013-11-13 15:58:05 -05:00
|
|
|
self.$el.append( self.theme.el );
|
|
|
|
|
|
|
|
// Binds to theme:expand to show the modal box
|
2020-01-28 19:45:18 -05:00
|
|
|
// with the theme details.
|
2013-11-13 15:58:05 -05:00
|
|
|
self.listenTo( self.theme, 'theme:expand', self.expand, self );
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// 'Add new theme' element shown at the end of the grid.
|
2015-10-19 18:04:25 -04:00
|
|
|
if ( ! themes.isInstall && themes.data.settings.canInstall ) {
|
2015-08-30 23:51:21 -04:00
|
|
|
this.$el.append( '<div class="theme add-new-theme"><a href="' + themes.data.settings.installURI + '"><div class="theme-screenshot"><span></span></div><h2 class="theme-name">' + l10n.addNew + '</h2></a></div>' );
|
2013-11-20 09:09:10 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
this.parent.page++;
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Grabs current theme and puts it at the beginning of the collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
currentTheme: function() {
|
|
|
|
var self = this,
|
|
|
|
current;
|
|
|
|
|
|
|
|
current = self.collection.findWhere({ active: true });
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Move the active theme to the beginning of the collection.
|
2013-11-13 15:58:05 -05:00
|
|
|
if ( current ) {
|
|
|
|
self.collection.remove( current );
|
|
|
|
self.collection.add( current, { at:0 } );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sets current view.
|
2013-11-13 15:58:05 -05:00
|
|
|
setView: function( view ) {
|
|
|
|
return view;
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Renders the overlay with the ThemeDetails view.
|
|
|
|
// Uses the current model data.
|
2013-11-13 15:58:05 -05:00
|
|
|
expand: function( id ) {
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
var self = this, $card, $modal;
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set the current theme model.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.model = self.collection.get( id );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trigger a route update for the current model.
|
2014-11-21 12:30:22 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( themes.router.themePath + this.model.id ) );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sets this.view to 'detail'.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.setView( 'detail' );
|
2014-08-01 16:15:15 -04:00
|
|
|
$( 'body' ).addClass( 'modal-open' );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up the theme details view.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.overlay = new themes.view.Details({
|
2013-11-20 14:44:12 -05:00
|
|
|
model: self.model
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.overlay.render();
|
Update/Install: Shiny Updates v2.
Gone are the days of isolation and feelings of "meh", brought on by The Bleak Screen of Sadness. For a shiny knight has arrived to usher our plugins and themes along their arduous journey of installation, updates, and the inevitable fate of ultimate deletion.
Props swissspidy, adamsilverstein, mapk, afragen, ocean90, ryelle, j-falk, michael-arestad, melchoyce, DrewAPicture, AdamSoucie, ethitter, pento, dd32, kraftbj, Ipstenu, jorbin, afercia, stephdau, paulwilde, jipmoors, khag7, svovaf, jipmoors, obenland.
Fixes #22029, #25828, #31002, #31529, #31530, #31773, #33637, #35032.
Built from https://develop.svn.wordpress.org/trunk@37714
git-svn-id: http://core.svn.wordpress.org/trunk@37680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-15 12:37:29 -04:00
|
|
|
|
|
|
|
if ( this.model.get( 'hasUpdate' ) ) {
|
|
|
|
$card = $( '[data-slug="' + this.model.id + '"]' );
|
|
|
|
$modal = $( this.overlay.el );
|
|
|
|
|
|
|
|
if ( $card.find( '.updating-message' ).length ) {
|
|
|
|
$modal.find( '.notice-warning h3' ).remove();
|
|
|
|
$modal.find( '.notice-warning' )
|
|
|
|
.removeClass( 'notice-large' )
|
|
|
|
.addClass( 'updating-message' )
|
|
|
|
.find( 'p' ).text( wp.updates.l10n.updating );
|
|
|
|
} else if ( $card.find( '.notice-error' ).length ) {
|
|
|
|
$modal.find( '.notice-warning' ).remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 22:11:10 -05:00
|
|
|
this.$overlay.html( this.overlay.el );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bind to theme:next and theme:previous triggered by the arrow keys.
|
|
|
|
// Keep track of the current model so we can infer an index position.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.listenTo( this.overlay, 'theme:next', function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Renders the next theme on the overlay.
|
2013-11-20 14:44:12 -05:00
|
|
|
self.next( [ self.model.cid ] );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
})
|
|
|
|
.listenTo( this.overlay, 'theme:previous', function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Renders the previous theme on the overlay.
|
2013-11-20 14:44:12 -05:00
|
|
|
self.previous( [ self.model.cid ] );
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* This method renders the next theme on the overlay modal
|
|
|
|
* based on the current position in the collection.
|
|
|
|
*
|
|
|
|
* @params [model cid]
|
|
|
|
*/
|
2013-11-13 15:58:05 -05:00
|
|
|
next: function( args ) {
|
|
|
|
var self = this,
|
|
|
|
model, nextModel;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the current theme.
|
2013-11-13 15:58:05 -05:00
|
|
|
model = self.collection.get( args[0] );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Find the next model within the collection.
|
2013-11-20 14:44:12 -05:00
|
|
|
nextModel = self.collection.at( self.collection.indexOf( model ) + 1 );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sanity check which also serves as a boundary test.
|
2013-11-13 15:58:05 -05:00
|
|
|
if ( nextModel !== undefined ) {
|
|
|
|
|
|
|
|
// We have a new theme...
|
2020-01-28 19:45:18 -05:00
|
|
|
// Close the overlay.
|
2013-11-20 14:44:12 -05:00
|
|
|
this.overlay.closeOverlay();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trigger a route update for the current model.
|
2013-12-06 22:11:10 -05:00
|
|
|
self.theme.trigger( 'theme:expand', nextModel.cid );
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* This method renders the previous theme on the overlay modal
|
|
|
|
* based on the current position in the collection.
|
|
|
|
*
|
|
|
|
* @params [model cid]
|
|
|
|
*/
|
2013-11-13 15:58:05 -05:00
|
|
|
previous: function( args ) {
|
|
|
|
var self = this,
|
|
|
|
model, previousModel;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the current theme.
|
2013-11-13 15:58:05 -05:00
|
|
|
model = self.collection.get( args[0] );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Find the previous model within the collection.
|
2013-11-20 14:44:12 -05:00
|
|
|
previousModel = self.collection.at( self.collection.indexOf( model ) - 1 );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
if ( previousModel !== undefined ) {
|
|
|
|
|
|
|
|
// We have a new theme...
|
2020-01-28 19:45:18 -05:00
|
|
|
// Close the overlay.
|
2013-11-20 14:44:12 -05:00
|
|
|
this.overlay.closeOverlay();
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trigger a route update for the current model.
|
2013-12-06 22:11:10 -05:00
|
|
|
self.theme.trigger( 'theme:expand', previousModel.cid );
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2015-04-02 22:32:28 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Dispatch audible search results feedback message.
|
2015-04-02 22:32:28 -04:00
|
|
|
announceSearchResults: function( count ) {
|
|
|
|
if ( 0 === count ) {
|
|
|
|
wp.a11y.speak( l10n.noThemesFound );
|
|
|
|
} else {
|
|
|
|
wp.a11y.speak( l10n.themesFound.replace( '%d', count ) );
|
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
// Search input view controller.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.view.Search = wp.Backbone.View.extend({
|
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
tagName: 'input',
|
2014-07-17 23:40:16 -04:00
|
|
|
className: 'wp-filter-search',
|
|
|
|
id: 'wp-filter-search-input',
|
2014-02-25 14:22:13 -05:00
|
|
|
searching: false,
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
attributes: {
|
2013-12-09 02:41:10 -05:00
|
|
|
placeholder: l10n.searchPlaceholder,
|
2015-04-02 22:32:28 -04:00
|
|
|
type: 'search',
|
|
|
|
'aria-describedby': 'live-search-desc'
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
events: {
|
2015-04-02 22:32:28 -04:00
|
|
|
'input': 'search',
|
|
|
|
'keyup': 'search',
|
|
|
|
'blur': 'pushState'
|
2014-02-25 14:22:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
|
|
|
|
this.parent = options.parent;
|
|
|
|
|
|
|
|
this.listenTo( this.parent, 'theme:close', function() {
|
|
|
|
this.searching = false;
|
|
|
|
} );
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-20 14:44:12 -05:00
|
|
|
search: function( event ) {
|
|
|
|
// Clear on escape.
|
|
|
|
if ( event.type === 'keyup' && event.which === 27 ) {
|
|
|
|
event.target.value = '';
|
|
|
|
}
|
2013-12-01 19:48:09 -05:00
|
|
|
|
2017-10-26 23:31:53 -04:00
|
|
|
// Since doSearch is debounced, it will only run when user input comes to a rest.
|
2015-04-02 22:32:28 -04:00
|
|
|
this.doSearch( event );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Runs a search on the theme collection.
|
2017-10-26 23:31:53 -04:00
|
|
|
doSearch: function( event ) {
|
2015-04-02 22:32:28 -04:00
|
|
|
var options = {};
|
2014-03-15 01:14:15 -04:00
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
this.collection.doSearch( event.target.value.replace( /\+/g, ' ' ) );
|
2013-12-01 19:48:09 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// if search is initiated and key is not return.
|
2014-02-25 14:22:13 -05:00
|
|
|
if ( this.searching && event.which !== 13 ) {
|
|
|
|
options.replace = true;
|
|
|
|
} else {
|
|
|
|
this.searching = true;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Update the URL hash.
|
2013-12-01 20:51:09 -05:00
|
|
|
if ( event.target.value ) {
|
2014-11-21 12:30:22 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + event.target.value ), options );
|
2013-12-01 20:51:09 -05:00
|
|
|
} else {
|
2014-02-25 14:22:13 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( '' ) );
|
|
|
|
}
|
2017-10-26 23:31:53 -04:00
|
|
|
},
|
2014-02-25 14:22:13 -05:00
|
|
|
|
|
|
|
pushState: function( event ) {
|
|
|
|
var url = themes.router.baseUrl( '' );
|
|
|
|
|
|
|
|
if ( event.target.value ) {
|
2017-10-09 12:04:48 -04:00
|
|
|
url = themes.router.baseUrl( themes.router.searchPath + encodeURIComponent( event.target.value ) );
|
2013-12-01 20:51:09 -05:00
|
|
|
}
|
2014-02-25 14:22:13 -05:00
|
|
|
|
|
|
|
this.searching = false;
|
|
|
|
themes.router.navigate( url );
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
/**
|
|
|
|
* Navigate router.
|
|
|
|
*
|
|
|
|
* @since 4.9.0
|
|
|
|
*
|
|
|
|
* @param {string} url - URL to navigate to.
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} state - State.
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-10-09 12:04:48 -04:00
|
|
|
*/
|
|
|
|
function navigateRouter( url, state ) {
|
|
|
|
var router = this;
|
|
|
|
if ( Backbone.history._hasPushState ) {
|
|
|
|
Backbone.Router.prototype.navigate.call( router, url, state );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sets up the routes events for relevant url queries.
|
|
|
|
// Listens to [theme] and [search] params.
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.Router = Backbone.Router.extend({
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2014-02-25 14:22:13 -05:00
|
|
|
routes: {
|
|
|
|
'themes.php?theme=:slug': 'theme',
|
|
|
|
'themes.php?search=:query': 'search',
|
|
|
|
'themes.php?s=:query': 'search',
|
|
|
|
'themes.php': 'themes',
|
|
|
|
'': 'themes'
|
2013-12-06 22:11:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
baseUrl: function( url ) {
|
2014-02-25 14:22:13 -05:00
|
|
|
return 'themes.php' + url;
|
|
|
|
},
|
|
|
|
|
2014-11-21 12:30:22 -05:00
|
|
|
themePath: '?theme=',
|
|
|
|
searchPath: '?search=',
|
|
|
|
|
2014-02-25 14:22:13 -05:00
|
|
|
search: function( query ) {
|
2017-10-09 12:04:48 -04:00
|
|
|
$( '.wp-filter-search' ).val( query.replace( /\+/g, ' ' ) );
|
2014-02-25 14:22:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
themes: function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( '.wp-filter-search' ).val( '' );
|
2014-04-15 20:04:15 -04:00
|
|
|
},
|
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
navigate: navigateRouter
|
2014-02-25 14:22:13 -05:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Execute and setup the application.
|
2013-11-13 15:58:05 -05:00
|
|
|
themes.Run = {
|
|
|
|
init: function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Initializes the blog's theme library view.
|
|
|
|
// Create a new collection with data.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.themes = new themes.Collection( themes.data.themes );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up the view.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.view = new themes.view.Appearance({
|
|
|
|
collection: this.themes
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
this.render();
|
2017-10-26 23:31:53 -04:00
|
|
|
|
|
|
|
// Start debouncing user searches after Backbone.history.start().
|
2017-11-23 14:29:46 -05:00
|
|
|
this.view.SearchView.doSearch = _.debounce( this.view.SearchView.doSearch, 500 );
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2014-02-25 14:22:13 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render results.
|
2013-11-13 15:58:05 -05:00
|
|
|
this.view.render();
|
|
|
|
this.routes();
|
|
|
|
|
2017-02-17 17:00:42 -05:00
|
|
|
if ( Backbone.History.started ) {
|
|
|
|
Backbone.history.stop();
|
|
|
|
}
|
2014-02-25 14:22:13 -05:00
|
|
|
Backbone.history.start({
|
|
|
|
root: themes.data.settings.adminUrl,
|
|
|
|
pushState: true,
|
|
|
|
hashChange: false
|
|
|
|
});
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
routes: function() {
|
2014-02-25 14:22:13 -05:00
|
|
|
var self = this;
|
2013-11-13 15:58:05 -05:00
|
|
|
// Bind to our global thx object
|
2020-01-28 19:45:18 -05:00
|
|
|
// so that the object is available to sub-views.
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.router = new themes.Router();
|
2014-02-25 14:22:13 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles theme details route event.
|
2014-02-25 14:22:13 -05:00
|
|
|
themes.router.on( 'route:theme', function( slug ) {
|
|
|
|
self.view.view.expand( slug );
|
|
|
|
});
|
|
|
|
|
|
|
|
themes.router.on( 'route:themes', function() {
|
|
|
|
self.themes.doSearch( '' );
|
|
|
|
self.view.trigger( 'theme:close' );
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles search route event.
|
2014-04-08 04:29:14 -04:00
|
|
|
themes.router.on( 'route:search', function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( '.wp-filter-search' ).trigger( 'keyup' );
|
2014-02-25 14:22:13 -05:00
|
|
|
});
|
2014-03-11 03:47:15 -04:00
|
|
|
|
|
|
|
this.extraRoutes();
|
|
|
|
},
|
|
|
|
|
|
|
|
extraRoutes: function() {
|
|
|
|
return false;
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
};
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Extend the main Search view.
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.view.InstallerSearch = themes.view.Search.extend({
|
|
|
|
|
|
|
|
events: {
|
2015-04-02 22:32:28 -04:00
|
|
|
'input': 'search',
|
2014-03-11 03:47:15 -04:00
|
|
|
'keyup': 'search'
|
|
|
|
},
|
|
|
|
|
2016-07-05 10:38:29 -04:00
|
|
|
terms: '',
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles Ajax request for searching through themes in public repo.
|
2014-03-11 03:47:15 -04:00
|
|
|
search: function( event ) {
|
2014-03-27 23:16:15 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Tabbing or reverse tabbing into the search input shouldn't trigger a search.
|
2014-03-27 23:16:15 -04:00
|
|
|
if ( event.type === 'keyup' && ( event.which === 9 || event.which === 16 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.collection = this.options.parent.view.collection;
|
|
|
|
|
|
|
|
// Clear on escape.
|
|
|
|
if ( event.type === 'keyup' && event.which === 27 ) {
|
|
|
|
event.target.value = '';
|
|
|
|
}
|
|
|
|
|
2015-04-02 22:37:32 -04:00
|
|
|
this.doSearch( event.target.value );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2017-10-26 23:31:53 -04:00
|
|
|
doSearch: function( value ) {
|
2014-03-29 04:53:16 -04:00
|
|
|
var request = {};
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2016-07-05 10:38:29 -04:00
|
|
|
// Don't do anything if the search terms haven't changed.
|
|
|
|
if ( this.terms === value ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates terms with the value passed.
|
|
|
|
this.terms = value;
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
request.search = value;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* Intercept an [author] search.
|
|
|
|
*
|
|
|
|
* If input value starts with `author:` send a request
|
|
|
|
* for `author` instead of a regular `search`.
|
|
|
|
*/
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( value.substring( 0, 7 ) === 'author:' ) {
|
|
|
|
request.search = '';
|
|
|
|
request.author = value.slice( 7 );
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* Intercept a [tag] search.
|
|
|
|
*
|
|
|
|
* If input value starts with `tag:` send a request
|
|
|
|
* for `tag` instead of a regular `search`.
|
|
|
|
*/
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( value.substring( 0, 4 ) === 'tag:' ) {
|
|
|
|
request.search = '';
|
|
|
|
request.tag = [ value.slice( 4 ) ];
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:44:47 -04:00
|
|
|
$( '.filter-links li > a.current' )
|
|
|
|
.removeClass( 'current' )
|
|
|
|
.removeAttr( 'aria-current' );
|
|
|
|
|
2015-11-16 14:50:26 -05:00
|
|
|
$( 'body' ).removeClass( 'show-filters filters-applied show-favorites-form' );
|
2016-09-21 13:54:28 -04:00
|
|
|
$( '.drawer-toggle' ).attr( 'aria-expanded', 'false' );
|
2014-04-03 19:53:15 -04:00
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Get the themes by sending Ajax POST request to api.wordpress.org/themes
|
2020-01-28 19:45:18 -05:00
|
|
|
// or searching the local cache.
|
2014-03-28 17:49:14 -04:00
|
|
|
this.collection.query( request );
|
2014-04-07 19:04:15 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set route.
|
2017-10-09 12:04:48 -04:00
|
|
|
themes.router.navigate( themes.router.baseUrl( themes.router.searchPath + encodeURIComponent( value ) ), { replace: true } );
|
2017-10-26 23:31:53 -04:00
|
|
|
}
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
themes.view.Installer = themes.view.Appearance.extend({
|
|
|
|
|
|
|
|
el: '#wpbody-content .wrap',
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Register events for sorting and filters in theme-navigation.
|
2014-03-11 03:47:15 -04:00
|
|
|
events: {
|
2014-08-25 11:58:15 -04:00
|
|
|
'click .filter-links li > a': 'onSort',
|
2014-03-11 03:47:15 -04:00
|
|
|
'click .theme-filter': 'onFilter',
|
2014-08-25 11:58:15 -04:00
|
|
|
'click .drawer-toggle': 'moreFilters',
|
|
|
|
'click .filter-drawer .apply-filters': 'applyFilters',
|
|
|
|
'click .filter-group [type="checkbox"]': 'addFilter',
|
|
|
|
'click .filter-drawer .clear-filters': 'clearFilters',
|
2016-09-21 13:54:28 -04:00
|
|
|
'click .edit-filters': 'backToFilters',
|
2015-11-04 16:49:26 -05:00
|
|
|
'click .favorites-form-submit' : 'saveUsername',
|
2015-11-04 18:49:26 -05:00
|
|
|
'keyup #wporg-username-input': 'saveUsername'
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Initial render method.
|
2014-04-14 18:06:15 -04:00
|
|
|
render: function() {
|
2014-03-11 03:47:15 -04:00
|
|
|
var self = this;
|
|
|
|
|
2014-04-14 18:06:15 -04:00
|
|
|
this.search();
|
|
|
|
this.uploader();
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.collection = new themes.Collection();
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Bump `collection.currentQuery.page` and request more themes if we hit the end of the page.
|
|
|
|
this.listenTo( this, 'theme:end', function() {
|
2014-03-29 05:09:14 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure we are not already loading.
|
2014-03-29 05:09:14 -04:00
|
|
|
if ( self.collection.loadingThemes ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set loadingThemes to true and bump page instance of currentQuery.
|
|
|
|
self.collection.loadingThemes = true;
|
2014-03-28 17:49:14 -04:00
|
|
|
self.collection.currentQuery.page++;
|
2014-03-29 05:09:14 -04:00
|
|
|
|
|
|
|
// Use currentQuery.page to build the themes request.
|
2014-03-28 17:49:14 -04:00
|
|
|
_.extend( self.collection.currentQuery.request, { page: self.collection.currentQuery.page } );
|
|
|
|
self.collection.query( self.collection.currentQuery.request );
|
|
|
|
});
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
this.listenTo( this.collection, 'query:success', function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( 'body' ).removeClass( 'loading-content' );
|
2014-03-11 03:47:15 -04:00
|
|
|
$( '.theme-browser' ).find( 'div.error' ).remove();
|
|
|
|
});
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
this.listenTo( this.collection, 'query:fail', function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( 'body' ).removeClass( 'loading-content' );
|
2014-03-28 17:49:14 -04:00
|
|
|
$( '.theme-browser' ).find( 'div.error' ).remove();
|
2017-10-01 09:48:46 -04:00
|
|
|
$( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p><p><button class="button try-again">' + l10n.tryAgain + '</button></p></div>' );
|
|
|
|
$( '.theme-browser .error .try-again' ).on( 'click', function( e ) {
|
|
|
|
e.preventDefault();
|
|
|
|
$( 'input.wp-filter-search' ).trigger( 'input' );
|
2017-09-27 04:46:45 -04:00
|
|
|
} );
|
2014-03-28 17:49:14 -04:00
|
|
|
});
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( this.view ) {
|
|
|
|
this.view.remove();
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sets up the view and passes the section argument.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.view = new themes.view.Themes({
|
|
|
|
collection: this.collection,
|
|
|
|
parent: this
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Reset pagination every time the install view handler is run.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.page = 0;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render and append.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.$el.find( '.themes' ).remove();
|
|
|
|
this.view.render();
|
|
|
|
this.$el.find( '.theme-browser' ).append( this.view.el ).addClass( 'rendered' );
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles all the rendering of the public theme directory.
|
2014-04-14 18:06:15 -04:00
|
|
|
browse: function( section ) {
|
|
|
|
// Create a new collection with the proper theme data
|
2020-01-28 19:45:18 -05:00
|
|
|
// for each section.
|
2014-04-14 18:06:15 -04:00
|
|
|
this.collection.query( { browse: section } );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sorting navigation.
|
2014-03-11 03:47:15 -04:00
|
|
|
onSort: function( event ) {
|
|
|
|
var $el = $( event.target ),
|
|
|
|
sort = $el.data( 'sort' );
|
|
|
|
|
2014-03-27 23:16:15 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
2014-08-25 11:58:15 -04:00
|
|
|
$( 'body' ).removeClass( 'filters-applied show-filters' );
|
2016-09-21 13:54:28 -04:00
|
|
|
$( '.drawer-toggle' ).attr( 'aria-expanded', 'false' );
|
2014-04-01 18:20:14 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bail if this is already active.
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( $el.hasClass( this.activeClass ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sort( sort );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Trigger a router.navigate update.
|
2014-11-21 12:30:22 -05:00
|
|
|
themes.router.navigate( themes.router.baseUrl( themes.router.browsePath + sort ) );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
sort: function( sort ) {
|
2014-04-07 19:04:15 -04:00
|
|
|
this.clearSearch();
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2017-05-23 16:32:44 -04:00
|
|
|
// Track sorting so we can restore the correct tab when closing preview.
|
|
|
|
themes.router.selectedTab = sort;
|
|
|
|
|
2017-10-02 15:44:47 -04:00
|
|
|
$( '.filter-links li > a, .theme-filter' )
|
|
|
|
.removeClass( this.activeClass )
|
|
|
|
.removeAttr( 'aria-current' );
|
|
|
|
|
|
|
|
$( '[data-sort="' + sort + '"]' )
|
|
|
|
.addClass( this.activeClass )
|
|
|
|
.attr( 'aria-current', 'page' );
|
2014-03-11 03:47:15 -04:00
|
|
|
|
2015-11-04 16:49:26 -05:00
|
|
|
if ( 'favorites' === sort ) {
|
2016-09-21 13:54:28 -04:00
|
|
|
$( 'body' ).addClass( 'show-favorites-form' );
|
2015-11-04 16:49:26 -05:00
|
|
|
} else {
|
2016-09-21 13:54:28 -04:00
|
|
|
$( 'body' ).removeClass( 'show-favorites-form' );
|
2015-11-04 16:49:26 -05:00
|
|
|
}
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.browse( sort );
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Filters and Tags.
|
2014-03-11 03:47:15 -04:00
|
|
|
onFilter: function( event ) {
|
|
|
|
var request,
|
|
|
|
$el = $( event.target ),
|
2014-03-29 04:53:16 -04:00
|
|
|
filter = $el.data( 'filter' );
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Bail if this is already active.
|
2014-03-11 03:47:15 -04:00
|
|
|
if ( $el.hasClass( this.activeClass ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:44:47 -04:00
|
|
|
$( '.filter-links li > a, .theme-section' )
|
|
|
|
.removeClass( this.activeClass )
|
|
|
|
.removeAttr( 'aria-current' );
|
|
|
|
$el
|
|
|
|
.addClass( this.activeClass )
|
|
|
|
.attr( 'aria-current', 'page' );
|
2014-03-11 03:47:15 -04:00
|
|
|
|
|
|
|
if ( ! filter ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the filter request
|
2020-01-28 19:45:18 -05:00
|
|
|
// using the default values.
|
2016-02-18 16:21:26 -05:00
|
|
|
filter = _.union( [ filter, this.filtersChecked() ] );
|
2014-03-11 03:47:15 -04:00
|
|
|
request = { tag: [ filter ] };
|
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Get the themes by sending Ajax POST request to api.wordpress.org/themes
|
2020-01-28 19:45:18 -05:00
|
|
|
// or searching the local cache.
|
2014-03-28 17:49:14 -04:00
|
|
|
this.collection.query( request );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Clicking on a checkbox to add another filter to the request.
|
2014-04-05 16:46:15 -04:00
|
|
|
addFilter: function() {
|
|
|
|
this.filtersChecked();
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Applying filters triggers a tag request.
|
2014-04-05 16:46:15 -04:00
|
|
|
applyFilters: function( event ) {
|
2014-04-01 18:20:14 -04:00
|
|
|
var name,
|
|
|
|
tags = this.filtersChecked(),
|
|
|
|
request = { tag: tags },
|
2014-08-25 11:58:15 -04:00
|
|
|
filteringBy = $( '.filtered-by .tags' );
|
2014-04-01 18:20:14 -04:00
|
|
|
|
|
|
|
if ( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:54:28 -04:00
|
|
|
if ( ! tags ) {
|
|
|
|
wp.a11y.speak( l10n.selectFeatureFilter );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:20:14 -04:00
|
|
|
$( 'body' ).addClass( 'filters-applied' );
|
2017-10-02 15:44:47 -04:00
|
|
|
$( '.filter-links li > a.current' )
|
|
|
|
.removeClass( 'current' )
|
|
|
|
.removeAttr( 'aria-current' );
|
|
|
|
|
2014-04-01 18:20:14 -04:00
|
|
|
filteringBy.empty();
|
|
|
|
|
|
|
|
_.each( tags, function( tag ) {
|
2014-07-17 23:40:16 -04:00
|
|
|
name = $( 'label[for="filter-id-' + tag + '"]' ).text();
|
2014-04-01 18:20:14 -04:00
|
|
|
filteringBy.append( '<span class="tag">' + name + '</span>' );
|
|
|
|
});
|
2014-03-20 00:20:15 -04:00
|
|
|
|
2014-03-28 17:49:14 -04:00
|
|
|
// Get the themes by sending Ajax POST request to api.wordpress.org/themes
|
2020-01-28 19:45:18 -05:00
|
|
|
// or searching the local cache.
|
2014-03-28 17:49:14 -04:00
|
|
|
this.collection.query( request );
|
2014-03-20 00:20:15 -04:00
|
|
|
},
|
|
|
|
|
2015-11-04 16:49:26 -05:00
|
|
|
// Save the user's WordPress.org username and get his favorite themes.
|
|
|
|
saveUsername: function ( event ) {
|
|
|
|
var username = $( '#wporg-username-input' ).val(),
|
2016-03-30 14:36:26 -04:00
|
|
|
nonce = $( '#wporg-username-nonce' ).val(),
|
2015-11-04 16:49:26 -05:00
|
|
|
request = { browse: 'favorites', user: username },
|
|
|
|
that = this;
|
|
|
|
|
|
|
|
if ( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Save username on enter.
|
2015-11-04 16:49:26 -05:00
|
|
|
if ( event.type === 'keyup' && event.which !== 13 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wp.ajax.send( 'save-wporg-username', {
|
|
|
|
data: {
|
2016-03-30 14:36:26 -04:00
|
|
|
_wpnonce: nonce,
|
2015-11-04 16:49:26 -05:00
|
|
|
username: username
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
// Get the themes by sending Ajax POST request to api.wordpress.org/themes
|
2020-01-28 19:45:18 -05:00
|
|
|
// or searching the local cache.
|
2015-11-04 16:49:26 -05:00
|
|
|
that.collection.query( request );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/**
|
|
|
|
* Get the checked filters.
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {Array} of tags or false
|
2020-01-28 19:45:18 -05:00
|
|
|
*/
|
2014-03-20 00:20:15 -04:00
|
|
|
filtersChecked: function() {
|
2014-08-25 11:58:15 -04:00
|
|
|
var items = $( '.filter-group' ).find( ':checkbox' ),
|
2014-03-20 00:20:15 -04:00
|
|
|
tags = [];
|
|
|
|
|
|
|
|
_.each( items.filter( ':checked' ), function( item ) {
|
|
|
|
tags.push( $( item ).prop( 'value' ) );
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// When no filters are checked, restore initial state and return.
|
2014-04-01 18:20:14 -04:00
|
|
|
if ( tags.length === 0 ) {
|
2014-08-25 11:58:15 -04:00
|
|
|
$( '.filter-drawer .apply-filters' ).find( 'span' ).text( '' );
|
|
|
|
$( '.filter-drawer .clear-filters' ).hide();
|
2014-04-01 18:20:14 -04:00
|
|
|
$( 'body' ).removeClass( 'filters-applied' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-25 11:58:15 -04:00
|
|
|
$( '.filter-drawer .apply-filters' ).find( 'span' ).text( tags.length );
|
|
|
|
$( '.filter-drawer .clear-filters' ).css( 'display', 'inline-block' );
|
2014-04-01 18:20:14 -04:00
|
|
|
|
2014-03-20 00:20:15 -04:00
|
|
|
return tags;
|
|
|
|
},
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
activeClass: 'current',
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/**
|
2016-06-17 16:47:28 -04:00
|
|
|
* When users press the "Upload Theme" button, show the upload form in place.
|
2016-04-16 12:43:27 -04:00
|
|
|
*/
|
2014-03-11 03:47:15 -04:00
|
|
|
uploader: function() {
|
2016-04-16 12:43:27 -04:00
|
|
|
var uploadViewToggle = $( '.upload-view-toggle' ),
|
|
|
|
$body = $( document.body );
|
|
|
|
|
2016-06-17 16:47:28 -04:00
|
|
|
uploadViewToggle.on( 'click', function() {
|
|
|
|
// Toggle the upload view.
|
|
|
|
$body.toggleClass( 'show-upload-view' );
|
|
|
|
// Toggle the `aria-expanded` button attribute.
|
|
|
|
uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
|
|
|
|
});
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Toggle the full filters navigation.
|
2014-04-01 18:20:14 -04:00
|
|
|
moreFilters: function( event ) {
|
2016-09-21 13:54:28 -04:00
|
|
|
var $body = $( 'body' ),
|
|
|
|
$toggleButton = $( '.drawer-toggle' );
|
|
|
|
|
2014-04-01 18:20:14 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
2016-09-21 13:54:28 -04:00
|
|
|
if ( $body.hasClass( 'filters-applied' ) ) {
|
2014-04-03 19:53:15 -04:00
|
|
|
return this.backToFilters();
|
2014-04-01 18:20:14 -04:00
|
|
|
}
|
|
|
|
|
2014-04-07 19:04:15 -04:00
|
|
|
this.clearSearch();
|
|
|
|
|
|
|
|
themes.router.navigate( themes.router.baseUrl( '' ) );
|
2016-09-21 13:54:28 -04:00
|
|
|
// Toggle the feature filters view.
|
|
|
|
$body.toggleClass( 'show-filters' );
|
|
|
|
// Toggle the `aria-expanded` button attribute.
|
|
|
|
$toggleButton.attr( 'aria-expanded', $body.hasClass( 'show-filters' ) );
|
2014-04-01 18:20:14 -04:00
|
|
|
},
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/**
|
|
|
|
* Clears all the checked filters.
|
|
|
|
*
|
|
|
|
* @uses filtersChecked()
|
|
|
|
*/
|
2014-04-01 18:20:14 -04:00
|
|
|
clearFilters: function( event ) {
|
2014-08-25 11:58:15 -04:00
|
|
|
var items = $( '.filter-group' ).find( ':checkbox' ),
|
2014-04-01 18:20:14 -04:00
|
|
|
self = this;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
_.each( items.filter( ':checked' ), function( item ) {
|
|
|
|
$( item ).prop( 'checked', false );
|
|
|
|
return self.filtersChecked();
|
|
|
|
});
|
2014-04-03 19:53:15 -04:00
|
|
|
},
|
|
|
|
|
2014-04-14 21:16:14 -04:00
|
|
|
backToFilters: function( event ) {
|
|
|
|
if ( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2014-04-03 19:53:15 -04:00
|
|
|
$( 'body' ).removeClass( 'filters-applied' );
|
2014-04-07 19:04:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
clearSearch: function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( '#wp-filter-search-input').val( '' );
|
2014-03-11 03:47:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
themes.InstallerRouter = Backbone.Router.extend({
|
|
|
|
routes: {
|
|
|
|
'theme-install.php?theme=:slug': 'preview',
|
2014-04-08 00:13:16 -04:00
|
|
|
'theme-install.php?browse=:sort': 'sort',
|
2014-04-07 19:04:15 -04:00
|
|
|
'theme-install.php?search=:query': 'search',
|
2014-04-14 18:06:15 -04:00
|
|
|
'theme-install.php': 'sort'
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
baseUrl: function( url ) {
|
|
|
|
return 'theme-install.php' + url;
|
2014-04-07 19:04:15 -04:00
|
|
|
},
|
|
|
|
|
2014-11-21 12:30:22 -05:00
|
|
|
themePath: '?theme=',
|
|
|
|
browsePath: '?browse=',
|
|
|
|
searchPath: '?search=',
|
|
|
|
|
2014-04-07 19:04:15 -04:00
|
|
|
search: function( query ) {
|
2017-10-09 12:04:48 -04:00
|
|
|
$( '.wp-filter-search' ).val( query.replace( /\+/g, ' ' ) );
|
2014-04-15 20:04:15 -04:00
|
|
|
},
|
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
navigate: navigateRouter
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
themes.RunInstaller = {
|
|
|
|
|
|
|
|
init: function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up the view.
|
|
|
|
// Passes the default 'section' as an option.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.view = new themes.view.Installer({
|
|
|
|
section: 'featured',
|
|
|
|
SearchView: themes.view.InstallerSearch
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render results.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.render();
|
|
|
|
|
2017-10-26 23:31:53 -04:00
|
|
|
// Start debouncing user searches after Backbone.history.start().
|
2017-11-23 14:29:46 -05:00
|
|
|
this.view.SearchView.doSearch = _.debounce( this.view.SearchView.doSearch, 500 );
|
2014-03-11 03:47:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Render results.
|
2014-03-11 03:47:15 -04:00
|
|
|
this.view.render();
|
|
|
|
this.routes();
|
|
|
|
|
2017-02-17 17:00:42 -05:00
|
|
|
if ( Backbone.History.started ) {
|
|
|
|
Backbone.history.stop();
|
|
|
|
}
|
2014-03-11 03:47:15 -04:00
|
|
|
Backbone.history.start({
|
|
|
|
root: themes.data.settings.adminUrl,
|
|
|
|
pushState: true,
|
|
|
|
hashChange: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
routes: function() {
|
2014-04-14 18:06:15 -04:00
|
|
|
var self = this,
|
|
|
|
request = {};
|
|
|
|
|
|
|
|
// Bind to our global `wp.themes` object
|
2020-01-28 19:45:18 -05:00
|
|
|
// so that the router is available to sub-views.
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.router = new themes.InstallerRouter();
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handles `theme` route event.
|
|
|
|
// Queries the API for the passed theme slug.
|
2014-04-14 18:06:15 -04:00
|
|
|
themes.router.on( 'route:preview', function( slug ) {
|
2017-02-24 12:48:42 -05:00
|
|
|
|
2017-05-23 16:32:44 -04:00
|
|
|
// Remove existing handlers.
|
|
|
|
if ( themes.preview ) {
|
|
|
|
themes.preview.undelegateEvents();
|
|
|
|
themes.preview.unbind();
|
|
|
|
}
|
|
|
|
|
2017-02-24 12:48:42 -05:00
|
|
|
// If the theme preview is active, set the current theme.
|
|
|
|
if ( self.view.view.theme && self.view.view.theme.preview ) {
|
|
|
|
self.view.view.theme.model = self.view.collection.findWhere( { 'slug': slug } );
|
2015-08-19 14:54:27 -04:00
|
|
|
self.view.view.theme.preview();
|
2017-02-24 12:48:42 -05:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Select the theme by slug.
|
|
|
|
request.theme = slug;
|
|
|
|
self.view.collection.query( request );
|
|
|
|
self.view.collection.trigger( 'update' );
|
|
|
|
|
|
|
|
// Open the theme preview.
|
|
|
|
self.view.collection.once( 'query:success', function() {
|
|
|
|
$( 'div[data-slug="' + slug + '"]' ).trigger( 'click' );
|
2017-02-24 13:40:40 -05:00
|
|
|
});
|
2017-02-24 12:48:42 -05:00
|
|
|
|
|
|
|
}
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* Handles sorting / browsing routes.
|
|
|
|
* Also handles the root URL triggering a sort request
|
|
|
|
* for `featured`, the default view.
|
|
|
|
*/
|
2014-03-11 03:47:15 -04:00
|
|
|
themes.router.on( 'route:sort', function( sort ) {
|
|
|
|
if ( ! sort ) {
|
|
|
|
sort = 'featured';
|
2017-05-23 16:32:44 -04:00
|
|
|
themes.router.navigate( themes.router.baseUrl( '?browse=featured' ), { replace: true } );
|
2014-03-11 03:47:15 -04:00
|
|
|
}
|
|
|
|
self.view.sort( sort );
|
2017-02-24 12:48:42 -05:00
|
|
|
|
|
|
|
// Close the preview if open.
|
2017-05-23 16:32:44 -04:00
|
|
|
if ( themes.preview ) {
|
|
|
|
themes.preview.close();
|
2017-02-24 12:48:42 -05:00
|
|
|
}
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
|
|
|
|
2014-04-14 18:06:15 -04:00
|
|
|
// The `search` route event. The router populates the input field.
|
2014-04-08 04:29:14 -04:00
|
|
|
themes.router.on( 'route:search', function() {
|
2014-07-17 23:40:16 -04:00
|
|
|
$( '.wp-filter-search' ).focus().trigger( 'keyup' );
|
2014-04-07 19:04:15 -04:00
|
|
|
});
|
|
|
|
|
2014-03-11 03:47:15 -04:00
|
|
|
this.extraRoutes();
|
|
|
|
},
|
|
|
|
|
|
|
|
extraRoutes: function() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ready...
|
|
|
|
$( document ).ready(function() {
|
|
|
|
if ( themes.isInstall ) {
|
|
|
|
themes.RunInstaller.init();
|
|
|
|
} else {
|
|
|
|
themes.Run.init();
|
|
|
|
}
|
2014-10-16 15:46:18 -04:00
|
|
|
|
2017-10-09 12:04:48 -04:00
|
|
|
// Update the return param just in time.
|
|
|
|
$( document.body ).on( 'click', '.load-customize', function() {
|
|
|
|
var link = $( this ), urlParser = document.createElement( 'a' );
|
|
|
|
urlParser.href = link.prop( 'href' );
|
|
|
|
urlParser.search = $.param( _.extend(
|
|
|
|
wp.customize.utils.parseQueryString( urlParser.search.substr( 1 ) ),
|
|
|
|
{
|
|
|
|
'return': window.location.href
|
|
|
|
}
|
|
|
|
) );
|
|
|
|
link.prop( 'href', urlParser.href );
|
|
|
|
});
|
|
|
|
|
2014-10-16 15:46:18 -04:00
|
|
|
$( '.broken-themes .delete-theme' ).on( 'click', function() {
|
|
|
|
return confirm( _wpThemeSettings.settings.confirmDelete );
|
|
|
|
});
|
2014-03-11 03:47:15 -04:00
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
})( jQuery );
|
2013-11-22 03:06:09 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Align theme browser thickbox.
|
2013-11-22 03:06:09 -05:00
|
|
|
jQuery(document).ready( function($) {
|
2018-08-19 09:33:24 -04:00
|
|
|
window.tb_position = function() {
|
2013-11-22 03:06:09 -05:00
|
|
|
var tbWindow = $('#TB_window'),
|
|
|
|
width = $(window).width(),
|
|
|
|
H = $(window).height(),
|
|
|
|
W = ( 1040 < width ) ? 1040 : width,
|
|
|
|
adminbar_height = 0;
|
|
|
|
|
2014-02-24 19:26:13 -05:00
|
|
|
if ( $('#wpadminbar').length ) {
|
|
|
|
adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 );
|
2013-11-22 03:06:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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(); });
|
|
|
|
});
|