Theme Customizer: Fix scrolling on iOS and Kindle Fire. props azaozz, helenyhou. fixes #20805.

Also fixes uploader UIs on iOS and Kindle Fire by improving wp.Uploader.
Adds mobile viewport specifications.
Moves scrollbar back to fixed positioning.


git-svn-id: http://core.svn.wordpress.org/trunk@21014 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith 2012-06-06 21:45:17 +00:00
parent d7a9a9a231
commit 14f04132af
12 changed files with 155 additions and 58 deletions

View File

@ -402,10 +402,6 @@ body {
text-align: right; text-align: right;
} }
.customize-section .customize-control-image .actions a {
display: block;
}
.customize-section .customize-control-image .library ul { .customize-section .customize-control-image .library ul {
border-bottom: 1px solid #dfdfdf; border-bottom: 1px solid #dfdfdf;
float: left; float: left;
@ -456,7 +452,7 @@ body {
.customize-section .customize-control-image .library .thumbnail img { .customize-section .customize-control-image .library .thumbnail img {
display: block; display: block;
max-width: 220px; max-width: 90%;
max-height: 80px; max-height: 80px;
margin: 5px auto; margin: 5px auto;
@ -479,6 +475,7 @@ body {
text-align: center; text-align: center;
color: #777; color: #777;
position: relative; position: relative;
cursor: default;
} }
.customize-section .customize-control-upload .upload-dropzone.supports-drag-drop, .customize-section .customize-control-upload .upload-dropzone.supports-drag-drop,
@ -491,7 +488,29 @@ body {
transition: border-color 0.1s; transition: border-color 0.1s;
} }
.customize-section .customize-control-upload .library ul li,
.customize-section .customize-control-image .library ul li {
cursor: pointer;
}
.customize-section .customize-control-upload .upload-dropzone.supports-drag-drop.drag-over, .customize-section .customize-control-upload .upload-dropzone.supports-drag-drop.drag-over,
.customize-section .customize-control-image .upload-dropzone.supports-drag-drop.drag-over { .customize-section .customize-control-image .upload-dropzone.supports-drag-drop.drag-over {
border-color: #83b4d8; border-color: #83b4d8;
} }
/**
* iOS can't scroll iframes,
* instead it expands the iframe size to match the size of the content
*/
.ios .wp-full-overlay {
position: relative;
}
.ios #customize-preview {
position: relative;
}
.ios #customize-controls .wp-full-overlay-sidebar-content {
-webkit-overflow-scrolling: touch;
}

View File

@ -1566,19 +1566,10 @@ table .column-rating {
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
26.0 - Full Overlay w/ Sidebar 26.0 - Full Overlay w/ Sidebar
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
.wp-full-overlay {
left: 0;
right: 300px;
}
.wp-full-overlay.collapsed {
right: 0 !important;
}
.wp-full-overlay .wp-full-overlay-sidebar { .wp-full-overlay .wp-full-overlay-sidebar {
margin: 0; margin: 0;
left: 100%; left: auto;
right: auto; right: 0;
border-right: 0; border-right: 0;
border-left: 1px solid rgba( 0, 0, 0, 0.2 ); border-left: 1px solid rgba( 0, 0, 0, 0.2 );
} }
@ -1589,6 +1580,21 @@ table .column-rating {
box-shadow: inset 5px 0 4px -4px rgba(0, 0, 0, 0.1); box-shadow: inset 5px 0 4px -4px rgba(0, 0, 0, 0.1);
} }
.wp-full-overlay.collapsed,
.wp-full-overlay.expanded .wp-full-overlay-sidebar {
margin-right: 0 !important;
}
.wp-full-overlay.expanded {
margin-right: 300px;
margin-left: 0;
}
.wp-full-overlay.collapsed .wp-full-overlay-sidebar {
margin-right: -300px;
margin-left: 0;
}
/* Collapse Button */ /* Collapse Button */
.wp-full-overlay .collapse-sidebar { .wp-full-overlay .collapse-sidebar {
right: 0; right: 0;

View File

@ -5255,27 +5255,23 @@ body.full-overlay-active {
overflow: visible; overflow: visible;
top: 0; top: 0;
bottom: 0; bottom: 0;
left: 300px; left: 0;
right: 0; right: 0;
height: 100%; height: 100%;
min-width: 0; min-width: 0;
} }
.wp-full-overlay.collapsed {
left: 0 !important;
}
.wp-full-overlay-sidebar { .wp-full-overlay-sidebar {
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
position: absolute; position: fixed;
width: 300px; width: 300px;
height: 100%; height: 100%;
top: 0; top: 0;
bottom: 0; bottom: 0;
right: 100%; left: 0;
padding: 0; padding: 0;
margin: 0; margin: 0;
z-index: 10; z-index: 10;
@ -5288,6 +5284,19 @@ body.full-overlay-active {
overflow: visible; overflow: visible;
} }
.wp-full-overlay.collapsed,
.wp-full-overlay.expanded .wp-full-overlay-sidebar {
margin-left: 0 !important;
}
.wp-full-overlay.expanded {
margin-left: 300px;
}
.wp-full-overlay.collapsed .wp-full-overlay-sidebar {
margin-left: -300px;
}
.wp-full-overlay-sidebar:after { .wp-full-overlay-sidebar:after {
content: ''; content: '';
display: block; display: block;
@ -5404,11 +5413,11 @@ body.full-overlay-active {
.wp-full-overlay-sidebar, .wp-full-overlay-sidebar,
.wp-full-overlay .collapse-sidebar, .wp-full-overlay .collapse-sidebar,
.wp-full-overlay-main { .wp-full-overlay-main {
-webkit-transition-property: left, right, top, bottom, width; -webkit-transition-property: left, right, top, bottom, width, margin;
-moz-transition-property: left, right, top, bottom, width; -moz-transition-property: left, right, top, bottom, width, margin;
-ms-transition-property: left, right, top, bottom, width; -ms-transition-property: left, right, top, bottom, width, margin;
-o-transition-property: left, right, top, bottom, width; -o-transition-property: left, right, top, bottom, width, margin;
transition-property: left, right, top, bottom, width; transition-property: left, right, top, bottom, width, margin;
-webkit-transition-duration: 0.2s; -webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s; -moz-transition-duration: 0.2s;

View File

@ -34,6 +34,19 @@ do_action( 'customize_controls_enqueue_scripts' );
wp_user_settings(); wp_user_settings();
_wp_admin_html_begin(); _wp_admin_html_begin();
$body_class = '';
if ( wp_is_mobile() ) :
$body_class .= ' mobile';
?><meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=0.8, minimum-scale=0.5, maximum-scale=1.2"><?php
endif;
$is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
if ( $is_ios )
$body_class .= ' ios';
$admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) ); $admin_title = sprintf( __( '%1$s &#8212; WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
?><title><?php echo $admin_title; ?></title><?php ?><title><?php echo $admin_title; ?></title><?php
@ -41,7 +54,8 @@ do_action( 'customize_controls_print_styles' );
do_action( 'customize_controls_print_scripts' ); do_action( 'customize_controls_print_scripts' );
?> ?>
</head> </head>
<body class="wp-full-overlay"> <body class="<?php echo esc_attr( $body_class ); ?>">
<div class="wp-full-overlay expanded">
<form id="customize-controls" class="wrap wp-full-overlay-sidebar"> <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
<?php wp_nonce_field( 'customize_controls-' . $wp_customize->get_stylesheet() ); ?> <?php wp_nonce_field( 'customize_controls-' . $wp_customize->get_stylesheet() ); ?>
<div id="customize-header-actions" class="wp-full-overlay-header"> <div id="customize-header-actions" class="wp-full-overlay-header">
@ -140,6 +154,10 @@ do_action( 'customize_controls_print_scripts' );
'isCrossDomain' => $cross_domain, 'isCrossDomain' => $cross_domain,
'fallback' => $fallback_url, 'fallback' => $fallback_url,
), ),
'browser' => array(
'mobile' => wp_is_mobile(),
'ios' => $is_ios,
),
'settings' => array(), 'settings' => array(),
'controls' => array(), 'controls' => array(),
); );
@ -160,5 +178,6 @@ do_action( 'customize_controls_print_scripts' );
<script type="text/javascript"> <script type="text/javascript">
var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>; var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;
</script> </script>
</div>
</body> </body>
</html> </html>

View File

@ -250,7 +250,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
*/ */
function theme_installer() { function theme_installer() {
?> ?>
<div id="theme-installer" class="wp-full-overlay"> <div id="theme-installer" class="wp-full-overlay expanded">
<div class="wp-full-overlay-sidebar"> <div class="wp-full-overlay-sidebar">
<div class="wp-full-overlay-header"> <div class="wp-full-overlay-header">
<a href="#" class="close-full-overlay"><?php _e( '&larr; Close' ); ?></a> <a href="#" class="close-full-overlay"><?php _e( '&larr; Close' ); ?></a>

View File

@ -148,6 +148,13 @@
success: this.success success: this.success
}, this.uploader || {} ); }, this.uploader || {} );
if ( this.uploader.supported ) {
if ( control.params.context )
control.uploader.param( 'post_data[context]', this.params.context );
control.uploader.param( 'post_data[theme]', api.settings.theme.stylesheet );
}
this.uploader = new wp.Uploader( this.uploader ); this.uploader = new wp.Uploader( this.uploader );
this.remover = this.container.find('.remove'); this.remover = this.container.find('.remove');
@ -159,11 +166,6 @@
this.removerVisibility = $.proxy( this.removerVisibility, this ); this.removerVisibility = $.proxy( this.removerVisibility, this );
this.setting.bind( this.removerVisibility ); this.setting.bind( this.removerVisibility );
this.removerVisibility( this.setting.get() ); this.removerVisibility( this.setting.get() );
if ( this.params.context )
control.uploader.param( 'post_data[context]', this.params.context );
control.uploader.param( 'post_data[theme]', api.settings.theme.stylesheet );
}, },
success: function( attachment ) { success: function( attachment ) {
this.setting.set( attachment.url ); this.setting.set( attachment.url );
@ -182,7 +184,7 @@
init: function( up ) { init: function( up ) {
var fallback, button; var fallback, button;
if ( up.features.dragdrop ) if ( this.supports.dragdrop )
return; return;
// Maintain references while wrapping the fallback button. // Maintain references while wrapping the fallback button.
@ -566,6 +568,7 @@
return window.location = api.settings.url.fallback; return window.location = api.settings.url.fallback;
var body = $( document.body ), var body = $( document.body ),
overlay = body.children('.wp-full-overlay'),
query, previewer, parent; query, previewer, parent;
// Prevent the form from saving when enter is pressed. // Prevent the form from saving when enter is pressed.
@ -702,7 +705,7 @@
}); });
$('.collapse-sidebar').click( function( event ) { $('.collapse-sidebar').click( function( event ) {
body.toggleClass( 'collapsed' ); overlay.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
event.preventDefault(); event.preventDefault();
}); });

View File

@ -41,7 +41,7 @@ jQuery( function($) {
}); });
preview.on( 'click', '.collapse-sidebar', function( event ) { preview.on( 'click', '.collapse-sidebar', function( event ) {
preview.toggleClass('collapsed'); preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
event.preventDefault(); event.preventDefault();
}); });

View File

@ -331,7 +331,7 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
$src = call_user_func( $this->get_url, $src ); $src = call_user_func( $this->get_url, $src );
?> ?>
<label class="customize-image-picker"> <div class="customize-image-picker">
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<div class="customize-control-content"> <div class="customize-control-content">
@ -366,7 +366,7 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
<div class="actions"> <div class="actions">
<a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a> <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
</div> </div>
</label> </div>
<?php <?php
} }
@ -382,6 +382,11 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
} }
public function tab_upload_new() { public function tab_upload_new() {
if ( ! _device_can_upload() ) {
?>
<p><?php _e('The web browser on your device cannot be used to upload files. You may be able to use the <a href="http://wordpress.org/extend/mobile/">native app for your device</a> instead.'); ?></p>
<?php
} else {
?> ?>
<div class="upload-dropzone"> <div class="upload-dropzone">
<?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?> <?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?>
@ -391,6 +396,7 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
</div> </div>
<?php <?php
} }
}
public function tab_uploaded() { public function tab_uploaded() {
?> ?>

View File

@ -67,6 +67,10 @@ if ( typeof wp === 'undefined' )
if ( this.active ) if ( this.active )
return; return;
// Load the full page on mobile devices.
if ( Loader.settings.browser.mobile )
return window.location = src;
this.active = true; this.active = true;
this.body.addClass('customize-loading'); this.body.addClass('customize-loading');

View File

@ -4,6 +4,9 @@ if ( typeof wp === 'undefined' )
(function( exports, $ ) { (function( exports, $ ) {
var Uploader; var Uploader;
if ( typeof _wpPluploadSettings === 'undefined' )
return;
/* /*
* An object that helps create a WordPress uploader using plupload. * An object that helps create a WordPress uploader using plupload.
* *
@ -27,8 +30,17 @@ if ( typeof wp === 'undefined' )
}, },
key; key;
this.supports = {
upload: Uploader.browser.supported
};
this.supported = this.supports.upload;
if ( ! this.supported )
return;
// Use deep extend to ensure that multipart_params and other objects are cloned. // Use deep extend to ensure that multipart_params and other objects are cloned.
this.plupload = $.extend( true, { multipart_params: {} }, wpPluploadDefaults ); this.plupload = $.extend( true, { multipart_params: {} }, Uploader.defaults );
this.container = document.body; // Set default container. this.container = document.body; // Set default container.
// Extend the instance with options // Extend the instance with options
@ -68,10 +80,10 @@ if ( typeof wp === 'undefined' )
this.param( this.params || {} ); this.param( this.params || {} );
delete this.params; delete this.params;
this.uploader.bind( 'Init', this.init );
this.uploader.init(); this.uploader.init();
this.supports.dragdrop = this.uploader.features.dragdrop && ! Uploader.browser.mobile;
// Generate drag/drop helper classes. // Generate drag/drop helper classes.
(function( dropzone, supported ) { (function( dropzone, supported ) {
var sensitivity = 50, var sensitivity = 50,
@ -99,7 +111,7 @@ if ( typeof wp === 'undefined' )
active = false; active = false;
dropzone.removeClass('drag-over'); dropzone.removeClass('drag-over');
}); });
}( this.dropzone, this.uploader.features.dragdrop )); }( this.dropzone, this.supports.dragdrop ));
this.browser.on( 'mouseenter', this.refresh ); this.browser.on( 'mouseenter', this.refresh );
@ -147,8 +159,13 @@ if ( typeof wp === 'undefined' )
up.refresh(); up.refresh();
up.start(); up.start();
}); });
this.init();
}; };
// Adds the 'defaults' and 'browser' properties.
$.extend( Uploader, _wpPluploadSettings );
Uploader.uuid = 0; Uploader.uuid = 0;
Uploader.errorMap = { Uploader.errorMap = {

View File

@ -1467,7 +1467,7 @@ function wp_plupload_default_settings() {
$max_upload_size = wp_max_upload_size(); $max_upload_size = wp_max_upload_size();
$settings = array( $defaults = array(
'runtimes' => 'html5,silverlight,flash,html4', 'runtimes' => 'html5,silverlight,flash,html4',
'file_data_name' => 'async-upload', // key passed to $_FILE. 'file_data_name' => 'async-upload', // key passed to $_FILE.
'multiple_queues' => true, 'multiple_queues' => true,
@ -1480,7 +1480,7 @@ function wp_plupload_default_settings() {
'urlstream_upload' => true, 'urlstream_upload' => true,
); );
$settings = apply_filters( 'plupload_default_settings', $settings ); $defaults = apply_filters( 'plupload_default_settings', $defaults );
$params = array( $params = array(
'action' => 'upload-attachment', 'action' => 'upload-attachment',
@ -1488,9 +1488,17 @@ function wp_plupload_default_settings() {
$params = apply_filters( 'plupload_default_params', $params ); $params = apply_filters( 'plupload_default_params', $params );
$params['_wpnonce'] = wp_create_nonce( 'media-form' ); $params['_wpnonce'] = wp_create_nonce( 'media-form' );
$settings['multipart_params'] = $params; $defaults['multipart_params'] = $params;
$script = 'var wpPluploadDefaults = ' . json_encode( $settings ) . ';'; $settings = array(
'defaults' => $defaults,
'browser' => array(
'mobile' => wp_is_mobile(),
'supported' => _device_can_upload(),
),
);
$script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';';
$data = $wp_scripts->get_data( 'wp-plupload', 'data' ); $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
if ( $data ) if ( $data )

View File

@ -1605,9 +1605,15 @@ function _wp_customize_loader_settings() {
$home_origin = parse_url( home_url() ); $home_origin = parse_url( home_url() );
$cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
$browser = array(
'mobile' => wp_is_mobile(),
'ios' => wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ),
);
$settings = array( $settings = array(
'url' => esc_url( admin_url( 'customize.php' ) ), 'url' => esc_url( admin_url( 'customize.php' ) ),
'isCrossDomain' => $cross_domain, 'isCrossDomain' => $cross_domain,
'browser' => $browser,
); );
$script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';'; $script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';