X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..b925718b4bf2dd47a8429f844d0a255ca6e35bd1:/wp-admin/js/theme.js diff --git a/wp-admin/js/theme.js b/wp-admin/js/theme.js index 079c73b5..9cd738a1 100644 --- a/wp-admin/js/theme.js +++ b/wp-admin/js/theme.js @@ -1,254 +1,1811 @@ -/** - * Theme Browsing - * - * Controls visibility of theme details on manage and install themes pages. - */ -jQuery( function($) { - $('#availablethemes').on( 'click', '.theme-detail', function (event) { - var theme = $(this).closest('.available-theme'), - details = theme.find('.themedetaildiv'); - - if ( ! details.length ) { - details = theme.find('.install-theme-info .theme-details'); - details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide(); - } - - details.toggle(); - event.preventDefault(); - }); +/* global _wpThemeSettings, confirm */ +window.wp = window.wp || {}; + +( function($) { + +// Set up our namespace... +var themes, l10n; +themes = wp.themes = wp.themes || {}; + +// Store the theme data and settings for organized and quick access +// themes.data.settings, themes.data.themes, themes.data.l10n +themes.data = _wpThemeSettings; +l10n = themes.data.l10n; + +// Shortcut for isInstall check +themes.isInstall = !! themes.data.settings.isInstall; + +// Setup app structure +_.extend( themes, { model: {}, view: {}, routes: {}, router: {}, template: wp.template }); + +themes.Model = Backbone.Model.extend({ + // Adds attributes to the default data coming through the .org themes api + // Map `id` to `slug` for shared code + initialize: function() { + var description; + + // If theme is already installed, set an attribute. + if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) { + this.set({ installed: true }); + } + + // Set the attributes + this.set({ + // slug is for installation, id is for existing. + id: this.get( 'slug' ) || this.get( 'id' ) + }); + + // Map `section.description` to `description` + // as the API sometimes returns it differently + if ( this.has( 'sections' ) ) { + description = this.get( 'sections' ).description; + this.set({ description: description }); + } + } }); -/** - * Theme Install - * - * Displays theme previews on theme install pages. - */ -jQuery( function($) { - if( ! window.postMessage ) - return; - - var preview = $('#theme-installer'), - info = preview.find('.install-theme-info'), - panel = preview.find('.wp-full-overlay-main'), - body = $( document.body ); - - preview.on( 'click', '.close-full-overlay', function( event ) { - preview.fadeOut( 200, function() { - panel.empty(); - body.removeClass('theme-installer-active full-overlay-active'); +// Main view controller for themes.php +// Unifies and renders all available views +themes.view.Appearance = wp.Backbone.View.extend({ + + el: '#wpbody-content .wrap .theme-browser', + + window: $( window ), + // Pagination instance + page: 0, + + // Sets up a throttler for binding to 'scroll' + initialize: function( options ) { + // Scroller checks how far the scroll position is + _.bindAll( this, 'scroller' ); + + this.SearchView = options.SearchView ? options.SearchView : themes.view.Search; + // Bind to the scroll event and throttle + // the results from this.scroller + this.window.bind( 'scroll', _.throttle( this.scroller, 300 ) ); + }, + + // Main render control + render: function() { + // Setup the main theme view + // with the current theme collection + this.view = new themes.view.Themes({ + collection: this.collection, + parent: this }); - event.preventDefault(); - }); - preview.on( 'click', '.collapse-sidebar', function( event ) { - preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' ); - event.preventDefault(); - }); + // Render search form. + this.search(); - $('#availablethemes').on( 'click', '.install-theme-preview', function( event ) { - var src; + // Render and append + this.view.render(); + this.$el.empty().append( this.view.el ).addClass( 'rendered' ); + }, - info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() ); - src = info.find( '.theme-preview-url' ).val(); - panel.html( '