]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/theme.js
WordPress 4.0
[autoinstalls/wordpress.git] / wp-admin / js / theme.js
index 77054b5cbf24983aaed1c9cb80ad7d7c076ecc74..57e33127ac9fa84b809a957c9a88a2944bd82dca 100644 (file)
@@ -105,7 +105,7 @@ themes.view.Appearance = wp.Backbone.View.extend({
                // Render and append after screen title
                view.render();
                this.searchContainer
                // Render and append after screen title
                view.render();
                this.searchContainer
-                       .append( $.parseHTML( '<label class="screen-reader-text" for="theme-search-input">' + l10n.search + '</label>' ) )
+                       .append( $.parseHTML( '<label class="screen-reader-text" for="wp-filter-search-input">' + l10n.search + '</label>' ) )
                        .append( view.el );
        },
 
                        .append( view.el );
        },
 
@@ -190,6 +190,12 @@ themes.Collection = Backbone.Collection.extend({
                        return match.test( haystack );
                });
 
                        return match.test( haystack );
                });
 
+               if ( results.length === 0 ) {
+                       this.trigger( 'query:empty' );
+               } else {
+                       $( 'body' ).removeClass( 'no-results' );
+               }
+
                this.reset( results );
        },
 
                this.reset( results );
        },
 
@@ -336,7 +342,7 @@ themes.Collection = Backbone.Collection.extend({
                        beforeSend: function() {
                                if ( ! paginated ) {
                                        // Spin it
                        beforeSend: function() {
                                if ( ! paginated ) {
                                        // Spin it
-                                       $( 'body' ).addClass( 'loading-themes' ).removeClass( 'no-results' );
+                                       $( 'body' ).addClass( 'loading-content' ).removeClass( 'no-results' );
                                }
                        }
                });
                                }
                        }
                });
@@ -362,7 +368,6 @@ themes.view.Theme = wp.Backbone.View.extend({
 
        events: {
                'click': themes.isInstall ? 'preview': 'expand',
 
        events: {
                'click': themes.isInstall ? 'preview': 'expand',
-               'click .preview': 'preview',
                'keydown': themes.isInstall ? 'preview': 'expand',
                'touchend': themes.isInstall ? 'preview': 'expand',
                'keyup': 'addFocus',
                'keydown': themes.isInstall ? 'preview': 'expand',
                'touchend': themes.isInstall ? 'preview': 'expand',
                'keyup': 'addFocus',
@@ -487,7 +492,7 @@ themes.view.Theme = wp.Backbone.View.extend({
                        preview.$el.removeClass( 'no-navigation' );
                }
 
                        preview.$el.removeClass( 'no-navigation' );
                }
 
-               // Apend preview
+               // Append preview
                $( 'div.wrap' ).append( preview.el );
 
                // Listen to our preview object
                $( 'div.wrap' ).append( preview.el );
 
                // Listen to our preview object
@@ -502,7 +507,7 @@ themes.view.Theme = wp.Backbone.View.extend({
                                current = self.current;
                        }
 
                                current = self.current;
                        }
 
-                       // Get previous theme model.
+                       // Get next theme model.
                        self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 );
 
                        // If we have no more themes, bail.
                        self.current = self.model.collection.at( self.model.collection.indexOf( current ) + 1 );
 
                        // If we have no more themes, bail.
@@ -511,15 +516,11 @@ themes.view.Theme = wp.Backbone.View.extend({
                                return self.current = current;
                        }
 
                                return self.current = current;
                        }
 
-                       // Construct a new Preview view.
-                       preview = new themes.view.Preview({
-                               model: self.current
-                       });
+                       preview.model = self.current;
 
                        // Render and append.
                        preview.render();
                        this.setNavButtonsState();
 
                        // Render and append.
                        preview.render();
                        this.setNavButtonsState();
-                       $( 'div.wrap' ).append( preview.el );
                        $( '.next-theme' ).focus();
                })
                .listenTo( preview, 'theme:previous', function() {
                        $( '.next-theme' ).focus();
                })
                .listenTo( preview, 'theme:previous', function() {
@@ -545,15 +546,11 @@ themes.view.Theme = wp.Backbone.View.extend({
                                return;
                        }
 
                                return;
                        }
 
-                       // Construct a new Preview view.
-                       preview = new themes.view.Preview({
-                               model: self.current
-                       });
+                       preview.model = self.current;
 
                        // Render and append.
                        preview.render();
                        this.setNavButtonsState();
 
                        // Render and append.
                        preview.render();
                        this.setNavButtonsState();
-                       $( 'div.wrap' ).append( preview.el );
                        $( '.previous-theme' ).focus();
                });
 
                        $( '.previous-theme' ).focus();
                });
 
@@ -704,7 +701,7 @@ themes.view.Details = wp.Backbone.View.extend({
        // Performs the actions to effectively close
        // the theme details overlay
        closeOverlay: function() {
        // Performs the actions to effectively close
        // the theme details overlay
        closeOverlay: function() {
-               $( 'body' ).removeClass( 'theme-overlay-open' );
+               $( 'body' ).removeClass( 'modal-open' );
                this.remove();
                this.unbind();
                this.trigger( 'theme:collapse' );
                this.remove();
                this.unbind();
                this.trigger( 'theme:collapse' );
@@ -786,6 +783,7 @@ themes.view.Preview = themes.view.Details.extend({
 
                themes.router.navigate( themes.router.baseUrl( '' ) );
                this.trigger( 'preview:close' );
 
                themes.router.navigate( themes.router.baseUrl( '' ) );
                this.trigger( 'preview:close' );
+               this.undelegateEvents();
                this.unbind();
                return false;
        },
                this.unbind();
                return false;
        },
@@ -1002,7 +1000,7 @@ themes.view.Themes = wp.Backbone.View.extend({
 
                // Sets this.view to 'detail'
                this.setView( 'detail' );
 
                // Sets this.view to 'detail'
                this.setView( 'detail' );
-               $( 'body' ).addClass( 'theme-overlay-open' );
+               $( 'body' ).addClass( 'modal-open' );
 
                // Set up the theme details view
                this.overlay = new themes.view.Details({
 
                // Set up the theme details view
                this.overlay = new themes.view.Details({
@@ -1082,8 +1080,8 @@ themes.view.Themes = wp.Backbone.View.extend({
 themes.view.Search = wp.Backbone.View.extend({
 
        tagName: 'input',
 themes.view.Search = wp.Backbone.View.extend({
 
        tagName: 'input',
-       className: 'theme-search',
-       id: 'theme-search-input',
+       className: 'wp-filter-search',
+       id: 'wp-filter-search-input',
        searching: false,
 
        attributes: {
        searching: false,
 
        attributes: {
@@ -1170,11 +1168,11 @@ themes.Router = Backbone.Router.extend({
        },
 
        search: function( query ) {
        },
 
        search: function( query ) {
-               $( '.theme-search' ).val( query );
+               $( '.wp-filter-search' ).val( query );
        },
 
        themes: function() {
        },
 
        themes: function() {
-               $( '.theme-search' ).val( '' );
+               $( '.wp-filter-search' ).val( '' );
        },
 
        navigate: function() {
        },
 
        navigate: function() {
@@ -1231,7 +1229,7 @@ themes.Run = {
 
                // Handles search route event
                themes.router.on( 'route:search', function() {
 
                // Handles search route event
                themes.router.on( 'route:search', function() {
-                       $( '.theme-search' ).trigger( 'keyup' );
+                       $( '.wp-filter-search' ).trigger( 'keyup' );
                });
 
                this.extraRoutes();
                });
 
                this.extraRoutes();
@@ -1290,8 +1288,8 @@ themes.view.InstallerSearch =  themes.view.Search.extend({
                        request.tag = [ value.slice( 4 ) ];
                }
 
                        request.tag = [ value.slice( 4 ) ];
                }
 
-               $( '.theme-section.current' ).removeClass( 'current' );
-               $( 'body' ).removeClass( 'more-filters-opened filters-applied' );
+               $( '.filter-links li > a.current' ).removeClass( 'current' );
+               $( 'body' ).removeClass( 'show-filters filters-applied' );
 
                // Get the themes by sending Ajax POST request to api.wordpress.org/themes
                // or searching the local cache
 
                // Get the themes by sending Ajax POST request to api.wordpress.org/themes
                // or searching the local cache
@@ -1308,14 +1306,13 @@ themes.view.Installer = themes.view.Appearance.extend({
 
        // Register events for sorting and filters in theme-navigation
        events: {
 
        // Register events for sorting and filters in theme-navigation
        events: {
-               'click .theme-section': 'onSort',
+               'click .filter-links li > a': 'onSort',
                'click .theme-filter': 'onFilter',
                'click .theme-filter': 'onFilter',
-               'click .more-filters': 'moreFilters',
-               'click .apply-filters': 'applyFilters',
-               'click [type="checkbox"]': 'addFilter',
-               'click .clear-filters': 'clearFilters',
-               'click .feature-name': 'filterSection',
-               'click .filtering-by a': 'backToFilters'
+               'click .drawer-toggle': 'moreFilters',
+               'click .filter-drawer .apply-filters': 'applyFilters',
+               'click .filter-group [type="checkbox"]': 'addFilter',
+               'click .filter-drawer .clear-filters': 'clearFilters',
+               'click .filtered-by': 'backToFilters'
        },
 
        // Initial render method
        },
 
        // Initial render method
@@ -1345,12 +1342,12 @@ themes.view.Installer = themes.view.Appearance.extend({
                });
 
                this.listenTo( this.collection, 'query:success', function() {
                });
 
                this.listenTo( this.collection, 'query:success', function() {
-                       $( 'body' ).removeClass( 'loading-themes' );
+                       $( 'body' ).removeClass( 'loading-content' );
                        $( '.theme-browser' ).find( 'div.error' ).remove();
                });
 
                this.listenTo( this.collection, 'query:fail', function() {
                        $( '.theme-browser' ).find( 'div.error' ).remove();
                });
 
                this.listenTo( this.collection, 'query:fail', function() {
-                       $( 'body' ).removeClass( 'loading-themes' );
+                       $( 'body' ).removeClass( 'loading-content' );
                        $( '.theme-browser' ).find( 'div.error' ).remove();
                        $( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p></div>' );
                });
                        $( '.theme-browser' ).find( 'div.error' ).remove();
                        $( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p></div>' );
                });
@@ -1388,7 +1385,7 @@ themes.view.Installer = themes.view.Appearance.extend({
 
                event.preventDefault();
 
 
                event.preventDefault();
 
-               $( 'body' ).removeClass( 'filters-applied more-filters-opened' );
+               $( 'body' ).removeClass( 'filters-applied show-filters' );
 
                // Bail if this is already active
                if ( $el.hasClass( this.activeClass ) ) {
 
                // Bail if this is already active
                if ( $el.hasClass( this.activeClass ) ) {
@@ -1404,7 +1401,7 @@ themes.view.Installer = themes.view.Appearance.extend({
        sort: function( sort ) {
                this.clearSearch();
 
        sort: function( sort ) {
                this.clearSearch();
 
-               $( '.theme-section, .theme-filter' ).removeClass( this.activeClass );
+               $( '.filter-links li > a, .theme-filter' ).removeClass( this.activeClass );
                $( '[data-sort="' + sort + '"]' ).addClass( this.activeClass );
 
                this.browse( sort );
                $( '[data-sort="' + sort + '"]' ).addClass( this.activeClass );
 
                this.browse( sort );
@@ -1421,7 +1418,7 @@ themes.view.Installer = themes.view.Appearance.extend({
                        return;
                }
 
                        return;
                }
 
-               $( '.theme-filter, .theme-section' ).removeClass( this.activeClass );
+               $( '.filter-links li > a, .theme-section' ).removeClass( this.activeClass );
                $el.addClass( this.activeClass );
 
                if ( ! filter ) {
                $el.addClass( this.activeClass );
 
                if ( ! filter ) {
@@ -1448,18 +1445,18 @@ themes.view.Installer = themes.view.Appearance.extend({
                var name,
                        tags = this.filtersChecked(),
                        request = { tag: tags },
                var name,
                        tags = this.filtersChecked(),
                        request = { tag: tags },
-                       filteringBy = $( '.filtering-by .tags' );
+                       filteringBy = $( '.filtered-by .tags' );
 
                if ( event ) {
                        event.preventDefault();
                }
 
                $( 'body' ).addClass( 'filters-applied' );
 
                if ( event ) {
                        event.preventDefault();
                }
 
                $( 'body' ).addClass( 'filters-applied' );
-               $( '.theme-section.current' ).removeClass( 'current' );
+               $( '.filter-links li > a.current' ).removeClass( 'current' );
                filteringBy.empty();
 
                _.each( tags, function( tag ) {
                filteringBy.empty();
 
                _.each( tags, function( tag ) {
-                       name = $( 'label[for="feature-id-' + tag + '"]' ).text();
+                       name = $( 'label[for="filter-id-' + tag + '"]' ).text();
                        filteringBy.append( '<span class="tag">' + name + '</span>' );
                });
 
                        filteringBy.append( '<span class="tag">' + name + '</span>' );
                });
 
@@ -1471,7 +1468,7 @@ themes.view.Installer = themes.view.Appearance.extend({
        // Get the checked filters
        // @return {array} of tags or false
        filtersChecked: function() {
        // Get the checked filters
        // @return {array} of tags or false
        filtersChecked: function() {
-               var items = $( '.feature-group' ).find( ':checkbox' ),
+               var items = $( '.filter-group' ).find( ':checkbox' ),
                        tags = [];
 
                _.each( items.filter( ':checked' ), function( item ) {
                        tags = [];
 
                _.each( items.filter( ':checked' ), function( item ) {
@@ -1480,14 +1477,14 @@ themes.view.Installer = themes.view.Appearance.extend({
 
                // When no filters are checked, restore initial state and return
                if ( tags.length === 0 ) {
 
                // When no filters are checked, restore initial state and return
                if ( tags.length === 0 ) {
-                       $( '.apply-filters' ).find( 'span' ).text( '' );
-                       $( '.clear-filters' ).hide();
+                       $( '.filter-drawer .apply-filters' ).find( 'span' ).text( '' );
+                       $( '.filter-drawer .clear-filters' ).hide();
                        $( 'body' ).removeClass( 'filters-applied' );
                        return false;
                }
 
                        $( 'body' ).removeClass( 'filters-applied' );
                        return false;
                }
 
-               $( '.apply-filters' ).find( 'span' ).text( tags.length );
-               $( '.clear-filters' ).css( 'display', 'inline-block' );
+               $( '.filter-drawer .apply-filters' ).find( 'span' ).text( tags.length );
+               $( '.filter-drawer .clear-filters' ).css( 'display', 'inline-block' );
 
                return tags;
        },
 
                return tags;
        },
@@ -1496,7 +1493,7 @@ themes.view.Installer = themes.view.Appearance.extend({
 
        // Overwrite search container class to append search
        // in new location
 
        // Overwrite search container class to append search
        // in new location
-       searchContainer: $( '.theme-navigation' ),
+       searchContainer: $( '.wp-filter .search-form' ),
 
        uploader: function() {
                $( 'a.upload' ).on( 'click', function( event ) {
 
        uploader: function() {
                $( 'a.upload' ).on( 'click', function( event ) {
@@ -1521,25 +1518,20 @@ themes.view.Installer = themes.view.Appearance.extend({
 
                // If the filters section is opened and filters are checked
                // run the relevant query collapsing to filtered-by state
 
                // If the filters section is opened and filters are checked
                // run the relevant query collapsing to filtered-by state
-               if ( $( 'body' ).hasClass( 'more-filters-opened' ) && this.filtersChecked() ) {
+               if ( $( 'body' ).hasClass( 'show-filters' ) && this.filtersChecked() ) {
                        return this.addFilter();
                }
 
                this.clearSearch();
 
                themes.router.navigate( themes.router.baseUrl( '' ) );
                        return this.addFilter();
                }
 
                this.clearSearch();
 
                themes.router.navigate( themes.router.baseUrl( '' ) );
-               $( 'body' ).toggleClass( 'more-filters-opened' );
-       },
-
-       // Expand/collapse each individual filter section
-       filterSection: function() {
-               $( event.target ).parent().toggleClass( 'open' );
+               $( 'body' ).toggleClass( 'show-filters' );
        },
 
        // Clears all the checked filters
        // @uses filtersChecked()
        clearFilters: function( event ) {
        },
 
        // Clears all the checked filters
        // @uses filtersChecked()
        clearFilters: function( event ) {
-               var items = $( '.feature-group' ).find( ':checkbox' ),
+               var items = $( '.filter-group' ).find( ':checkbox' ),
                        self = this;
 
                event.preventDefault();
                        self = this;
 
                event.preventDefault();
@@ -1559,7 +1551,7 @@ themes.view.Installer = themes.view.Appearance.extend({
        },
 
        clearSearch: function() {
        },
 
        clearSearch: function() {
-               $( '#theme-search-input').val( '' );
+               $( '#wp-filter-search-input').val( '' );
        }
 });
 
        }
 });
 
@@ -1577,7 +1569,7 @@ themes.InstallerRouter = Backbone.Router.extend({
        },
 
        search: function( query ) {
        },
 
        search: function( query ) {
-               $( '.theme-search' ).val( query );
+               $( '.wp-filter-search' ).val( query );
        },
 
        navigate: function() {
        },
 
        navigate: function() {
@@ -1649,7 +1641,7 @@ themes.RunInstaller = {
 
                // The `search` route event. The router populates the input field.
                themes.router.on( 'route:search', function() {
 
                // The `search` route event. The router populates the input field.
                themes.router.on( 'route:search', function() {
-                       $( '.theme-search' ).focus().trigger( 'keyup' );
+                       $( '.wp-filter-search' ).focus().trigger( 'keyup' );
                });
 
                this.extraRoutes();
                });
 
                this.extraRoutes();