Make WordPress Core


Ignore:
Timestamp:
06/05/2014 10:00:24 PM (12 years ago)
Author:
helen
Message:

Grid view for the media library, first pass. This is alpha; expect imperfection. We will be iterating further.

props ericlewis, shaunandrews, wonderboymusic.
see #24716.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r28553 r28682  
    2424
    2525        public function prepare_items() {
    26                 global $lost, $wp_query, $post_mime_types, $avail_post_mime_types;
     26                global $lost, $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
    2727
    2828                $q = $_REQUEST;
    … …  
    3434
    3535                $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
     36
     37                $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    3638
    3739                $this->set_pagination_args( array(
    … …  
    124126        public function no_items() {
    125127                _e( 'No media attachments found.' );
     128        }
     129
     130        protected function pagination( $which ) {
     131                global $mode;
     132
     133                parent::pagination( $which );
     134
     135                $this->view_switcher( $mode );
     136        }
     137
     138        /**
     139         * Display a view switcher
     140         *
     141         * @since 3.1.0
     142         * @access protected
     143         */
     144        protected function view_switcher( $current_mode ) {
     145                $modes = array(
     146                        'list'    => __( 'List View' ),
     147                        'grid' => __( 'Grid View' )
     148                );
     149
     150?>
     151                <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
     152                <div class="view-switch">
     153<?php
     154                        foreach ( $modes as $mode => $title ) {
     155                                $classes = array( 'view-' . $mode );
     156                                if ( $current_mode == $mode )
     157                                        $classes[] = 'current';
     158                                printf(
     159                                        "<a href='%s' class='%s'><img id='view-switch-$mode' src='%s' width='20' height='20' title='%s' alt='%s' /></a>\n",
     160                                        esc_url( add_query_arg( 'mode', $mode ) ),
     161                                        implode( ' ', $classes ),
     162                                        esc_url( includes_url( 'images/blank.gif' ) ),
     163                                        $title,
     164                                        $title
     165
     166                                );
     167                        }
     168                ?>
     169                </div>
     170<?php
    126171        }
    127172
Note: See TracChangeset for help on using the changeset viewer.