Make WordPress Core

Changeset 24226


Ignore:
Timestamp:
05/09/2013 10:45:14 PM (11 years ago)
Author:
markjaquith
Message:

Improve the UX and flow of the Image post format.

  • Drag-and-drop
  • Textarea for HTML/URL hidden to start
  • Bigger click target for entering Media modal
  • Image preview height-contrained to 300 pixels
  • Hid the alignment, size, etc options that didn't have an effect anyway
  • Got wp-format-{format} into the <body> class

props DrewAPicture, aaroncampbell, markjaquith, azaozz. see #24291.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-header.php

    r23879 r24226  
    8686$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
    8787
     88if ( false !== $post_format = get_post_format() ) {
     89    if ( ! $post_format ) {
     90        $post_format = 'standard';
     91
     92        if ( ! empty( $_REQUEST['format'] ) && in_array( $_REQUEST['format'], get_post_format_slugs() ) )
     93            $post_format = $_REQUEST['format'];
     94    }
     95
     96    $admin_body_class .= ' wp-format-' . $post_format;
     97}
     98
    8899if ( wp_is_mobile() )
    89100    $admin_body_class .= ' mobile';
     
    99110
    100111<?php
    101 // Make sure the customize body classes are correct as early as possible. 
     112// Make sure the customize body classes are correct as early as possible.
    102113if ( current_user_can( 'edit_theme_options' ) )
    103114    wp_customize_support_script();
  • trunk/wp-admin/css/wp-admin.css

    r24219 r24226  
    40054005}
    40064006
    4007 .wp-format-gallery .post-formats-fields,
    4008 .wp-format-image .post-formats-fields,
    4009 .wp-format-link .post-formats-fields,
    4010 .wp-format-quote .post-formats-fields,
    4011 .wp-format-video .post-formats-fields,
    4012 .wp-format-audio .post-formats-fields,
    4013 .wp-format-gallery .field.wp-format-gallery,
    4014 .wp-format-image .field.wp-format-image,
    4015 .wp-format-chat .field.wp-format-chat,
    4016 .wp-format-link .field.wp-format-link,
    4017 .wp-format-quote .field.wp-format-quote,
    4018 .wp-format-video .field.wp-format-video,
    4019 .wp-format-audio .field.wp-format-audio {
     4007#post-body-content.wp-format-gallery .post-formats-fields,
     4008#post-body-content.wp-format-image .post-formats-fields,
     4009#post-body-content.wp-format-link .post-formats-fields,
     4010#post-body-content.wp-format-quote .post-formats-fields,
     4011#post-body-content.wp-format-video .post-formats-fields,
     4012#post-body-content.wp-format-audio .post-formats-fields,
     4013#post-body-content.wp-format-gallery .field.wp-format-gallery,
     4014#post-body-content.wp-format-image .field.wp-format-image,
     4015#post-body-content.wp-format-chat .field.wp-format-chat,
     4016#post-body-content.wp-format-link .field.wp-format-link,
     4017#post-body-content.wp-format-quote .field.wp-format-quote,
     4018#post-body-content.wp-format-video .field.wp-format-video,
     4019#post-body-content.wp-format-audio .field.wp-format-audio {
    40204020    display: block;
    40214021}
     
    40334033}
    40344034
    4035 .wp-format-image label,
    4036 .wp-format-video label,
    4037 .wp-format-audio label {
     4035#post-body-content.wp-format-image label,
     4036#post-body-content.wp-format-video label,
     4037#post-body-content.wp-format-audio label {
    40384038    float: left;
    40394039}
     
    40444044    width: 40%;
    40454045    height: auto;
    4046     padding: 55px 0 20px;
    40474046    border: 1px dashed #dfdfdf;
    40484047    background: #f5f5f5 url(../images/media-button-2x.png) no-repeat 50% 25%;
     4048    box-sizing: border-box;
     4049    position:relative;
    40494050}
    40504051
     
    40534054}
    40544055
     4056.wp-format-media-holder.drag-over {
     4057    background: rgba( 0, 86, 132, 0.9 );
     4058    border-color:transparent;
     4059}
     4060
     4061.wp-format-media-holder div {
     4062    display: none;
     4063}
     4064.wp-format-media-holder.drag-over div {
     4065    position: absolute;
     4066    top: 10px;
     4067    left: 10px;
     4068    right: 10px;
     4069    bottom: 10px;
     4070    border: 1px dashed #fff;
     4071    display:block;
     4072}
     4073
     4074#poststuff .wp-format-media-holder.drag-over div h3 {
     4075
     4076    position: absolute;
     4077    top: 50%;
     4078    left: 0;
     4079    right: 0;
     4080    -webkit-transform: translateY( -50% );
     4081    -moz-transform:    translateY( -50% );
     4082    -ms-transform:     translateY( -50% );
     4083    -o-transform:      translateY( -50% );
     4084    transform:         translateY( -50% );
     4085
     4086    font-size: 20px;
     4087    font-weight: 200;
     4088    color: #fff;
     4089    padding: 0;
     4090    text-align:center;
     4091    font-family: sans-serif;
     4092}
     4093
     4094#post-body-content.wp-format-image .wp-format-media-holder {
     4095    margin-top: 17px;
     4096}
     4097
    40554098.wp-format-media-preview {
    4056     margin-bottom: 20px;
    4057 }
    4058 
    4059 .wp-format-status #titlewrap,
    4060 .wp-format-image .wp-media-buttons .insert-media,
    4061 .wp-format-audio .wp-media-buttons .insert-media,
    4062 .wp-format-video .wp-media-buttons .insert-media,
    4063 .wp-format-aside .wp-media-buttons .insert-media,
    4064 .wp-format-status .wp-media-buttons .insert-media {
     4099    margin: 20px 0;
     4100}
     4101
     4102#image-preview img {
     4103    width: auto;
     4104    max-height: 300px;
     4105}
     4106
     4107#post-body-content .wp-format-image p.use-url-or-html {
     4108    padding-top: 10px;
     4109    clear: both;
     4110    width: 40%;
     4111    text-align: center;
     4112}
     4113
     4114body.wp-format-image .attachment-display-settings {
     4115    display: none;
     4116}
     4117
     4118body.wp-format-status #titlewrap,
     4119body.wp-format-image .wp-media-buttons .insert-media,
     4120body.wp-format-audio .wp-media-buttons .insert-media,
     4121body.wp-format-video .wp-media-buttons .insert-media,
     4122body.wp-format-aside .wp-media-buttons .insert-media,
     4123body.wp-format-status .wp-media-buttons .insert-media {
    40654124    display: none;
    40664125}
     
    40734132.wp-format-media-select {
    40744133    display: block;
    4075     height: 200px;
     4134    height: 20px;
     4135    padding: 55px 0 20px;
    40764136    text-align: center;
    40774137}
     
    40804140    max-width: 100%;
    40814141    max-height: 100%;
    4082 }
    4083 
    4084 .wp-format-media-select {
    4085     height: 20px;
    40864142}
    40874143
     
    41024158    float: left;
    41034159    margin-right: 23px;
    4104     max-width: 50%;
     4160    max-width: 40%;
    41054161    min-height: 97px;
    41064162}
    41074163
    4108 #icon-edit.wp-format-standard,
     4164body.wp-format-standard #icon-edit,
    41094165.post-format-options .standard {
    41104166    background: url(../images/post-formats32.png) no-repeat -3px -4px;
    41114167}
    41124168
    4113 #icon-edit.wp-format-image,
     4169body.wp-format-image #icon-edit,
    41144170.post-format-options .image {
    41154171    background: url(../images/post-formats32.png) no-repeat  -43px -4px;
    41164172}
    41174173
    4118 #icon-edit.wp-format-gallery,
     4174body.wp-format-gallery #icon-edit,
    41194175.post-format-options .gallery {
    41204176    background: url(../images/post-formats32.png) no-repeat -83px -4px;
    41214177}
    41224178
    4123 #icon-edit.wp-format-audio,
     4179body.wp-format-audio #icon-edit,
    41244180.post-format-options .audio {
    41254181    background: url(../images/post-formats32.png) no-repeat -123px -4px;
    41264182}
    41274183
    4128 #icon-edit.wp-format-video,
     4184body.wp-format-video #icon-edit,
    41294185.post-format-options .video {
    41304186    background: url(../images/post-formats32.png) no-repeat -163px -4px;
    41314187}
    41324188
    4133 #icon-edit.wp-format-chat,
     4189body.wp-format-chat #icon-edit,
    41344190.post-format-options .chat {
    41354191    background: url(../images/post-formats32.png) no-repeat -202px -4px;
    41364192}
    41374193
    4138 #icon-edit.wp-format-status,
     4194body.wp-format-status #icon-edit,
    41394195.post-format-options .status {
    41404196    background: url(../images/post-formats32.png) no-repeat -242px -4px;
    41414197}
    41424198
    4143 #icon-edit.wp-format-aside,
     4199body.wp-format-aside #icon-edit,
    41444200.post-format-options .aside {
    41454201    background: url(../images/post-formats32.png) no-repeat -282px -4px;
    41464202}
    41474203
    4148 #icon-edit.wp-format-quote,
     4204body.wp-format-quote #icon-edit,
    41494205.post-format-options .quote {
    41504206    background: url(../images/post-formats32.png) no-repeat -322px -4px;
    41514207}
    41524208
    4153 #icon-edit.wp-format-link,
     4209body.wp-format-link #icon-edit,
    41544210.post-format-options .link {
    41554211    background: url(../images/post-formats32.png) no-repeat -362px -4px;
  • trunk/wp-admin/includes/post-formats.php

    r24184 r24226  
    3939            </div>
    4040            <?php endif ?>
    41             <label for="wp_format_image"><?php
    42                 if ( current_user_can( 'unfiltered_html' ) )
    43                     _e( 'Image HTML or URL' );
    44                 else
    45                     _e( 'Image URL' );
    46             ?></label>
    47             <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
    4841            <div data-format="image" class="wp-format-media-holder hide-if-no-js">
     42                <div><h3><?php _e( 'Drop image file to upload' ); ?></h3></div>
    4943                <a href="#" class="wp-format-media-select"
    5044                    data-choose="<?php esc_attr_e( 'Choose an Image' ); ?>"
     
    5347                </a>
    5448            </div>
     49            <div class="wp-format-image-textarea hide-if-js">
     50                <label for="wp_format_image"><?php
     51                    if ( current_user_can( 'unfiltered_html' ) )
     52                        _e( 'Image HTML or URL' );
     53                    else
     54                        _e( 'Image URL' );
     55                ?></label>
     56                <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
     57            </div>
     58            <p class="use-url-or-html hide-if-no-js"><span><?php printf( __( '(or %suse an image URL or HTML%s)' ), '<a href="#">', '</a>' ); ?></span>
     59                <span style="display: none"><?php printf( __( '(or %sselect/upload an image%s)' ), '<a href="#">', '</a>' ); ?></span></p>
    5560        </div>
    5661
  • trunk/wp-admin/js/post-formats.js

    r24141 r24226  
    77
    88    var mediaFrame, insertMediaButton, container, icon, formatField,
     9        body,
    910        lastMimeType,
    1011        classRegex = /\s?\bwp-format-[^ ]+/g,
     
    1819        noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery'];
    1920
     21    function imageFormatUploadProgress( uploader, file ) {
     22        var $bar = $( '#' + uploader.settings.drop_element + ' .media-progress-bar div' );
     23        $bar.width( file.percent + '%' );
     24    }
     25
     26    function imageFormatUploadStart( uploader ) {
     27        $( '#' + uploader.settings.drop_element + ' .wp-format-media-select' ).append('<div class="media-progress-bar"><div></div></div>');
     28    }
     29
     30    function imageFormatUploadError() {
     31        $( '.media-progress-bar', $('.wp-format-media-holder[data-format=image]') ).remove();
     32    }
     33
     34    function imageFormatUploadSuccess( attachment ) {
     35        var $holder, $field, html = wp.media.string.image({
     36            size : 'full',
     37            align : false,
     38            link : getUserSetting( 'urlbutton' )
     39        }, attachment.attributes );
     40
     41        $holder = $('.wp-format-media-holder[data-format=image]');
     42        $( '.media-progress-bar', $holder ).remove();
     43
     44        if ( 'image' !== attachment.attributes.type )
     45            return;
     46
     47        $field = $( '#wp_format_' + $holder.data( 'format' ) );
     48
     49        // set the hidden input's value
     50        $field.val( html );
     51
     52        $( '#image-preview' ).remove();
     53
     54        $holder.parent().prepend( ['<div id="image-preview" class="wp-format-media-preview">',
     55            '<img src="', attachment.get('url'), '"',
     56            attachment.get('width') ? ' width="' + attachment.get('width') + '"' : '',
     57            attachment.get('height') ? ' height="' + attachment.get('height') + '"' : '',
     58            ' />',
     59        '</div>'].join( '' ) );
     60    }
     61
     62    var uploader = {
     63        dropzone:  $('.wp-format-media-holder[data-format=image]'),
     64        success:   imageFormatUploadSuccess,
     65        error: imageFormatUploadError,
     66        plupload:  {},
     67        params:    {}
     68    };
     69    uploader = new wp.Uploader( uploader );
     70    uploader.uploader.bind( 'BeforeUpload', imageFormatUploadStart );
     71    uploader.uploader.bind( 'UploadProgress', imageFormatUploadProgress );
     72
    2073    function switchFormatClass( format ) {
    2174        formatField.val( format );
    2275
    23         container
    24             .prop( 'className', container.prop( 'className' ).replace( classRegex, '' ) )
     76        $.each( [ container, icon, body ], function(i, thing) {
     77            thing.prop( 'className', thing.prop( 'className' ).replace( classRegex, '' ) )
    2578            .addClass( 'wp-format-' + format );
    26 
    27         icon
    28             .prop( 'className', icon.prop( 'className' ).replace( classRegex, '' ) )
    29             .addClass( 'wp-format-' + format );
     79        });
    3080    }
    3181
     
    138188
    139189    $(function () {
     190        body = $( 'body' );
    140191        container = $( '#post-body-content' );
    141192        icon = $( '.icon32' );
     
    163214            switchFormat( $( e.currentTarget ) );
    164215        } );
     216
     217        // Toggle select/upload and URL/HTML for images
     218        $( '.use-url-or-html' ).on( 'click', 'a', function(e) {
     219            e.preventDefault();
     220            $( '.wp-format-media-holder, .wp-format-image-textarea' ).toggle();
     221            $(this).closest( 'p' ).find( 'span' ).toggle();
     222        });
    165223
    166224        // Media selection
     
    243301                } else {
    244302                    html = wp.media.string.image({
    245                         align : getUserSetting( 'align' ),
    246                         size : getUserSetting( 'imgsize' ),
     303                        size: 'full',
     304                        align : false,
    247305                        link : getUserSetting( 'urlbutton' )
    248306                    }, attachment);
  • trunk/wp-includes/post-formats.php

    r24207 r24226  
    2525
    2626    if ( empty( $_format ) )
    27         return false;
     27        return '';
    2828
    2929    $format = array_shift( $_format );
  • trunk/wp-includes/script-loader.php

    r24204 r24226  
    408408        ) );
    409409
    410         $scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models' ), false, 1 );
     410        $scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models', 'wp-plupload' ), false, 1 );
    411411
    412412        $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.