Add "Accessibility Mode" for widgets screen (can be turned on from Screen Options). Add set_user_setting() to the UI state saving functions.

git-svn-id: http://svn.automattic.com/wordpress/trunk@11503 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-06-01 23:31:34 +00:00
parent 6a9fd7c2bb
commit a71b8736cd
8 changed files with 150 additions and 26 deletions

View File

@ -373,7 +373,7 @@ table.ie-fixed {
} }
* html .widget-title h4 { * html .widget-title h4 {
width: 210px; width: 205px;
} }
* html #removing-widget .in-widget-title { * html #removing-widget .in-widget-title {

View File

@ -322,3 +322,43 @@ a.widget-control-edit {
font-size: 12px; font-size: 12px;
} }
#access-off,
.widgets_access .widget-action,
.widgets_access .sidebar-name-arrow,
.widgets_access #access-on,
.widgets_access .widget-holder .description {
display: none;
}
.widgets_access .widget-holder,
.widgets_access #widget-list {
padding-top: 10px;
}
.widgets_access #access-off {
display: inline;
}
.widgets_access #wpbody-content .widget-title-action,
.widgets_access #wpbody-content .widget-control-edit,
.widgets_access .closed .widgets-sortables,
.widgets_access .closed .widget-holder {
display: block;
}
.widgets_access .closed .sidebar-name {
-moz-border-radius-bottomleft: 0;
-moz-border-radius-bottomright: 0;
-webkit-border-bottom-right-radius: 0;
-webkit-border-bottom-left-radius: 0;
-khtml-border-bottom-right-radius: 0;
-khtml-border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.widgets_access .sidebar-name,
.widgets_access .widget .widget-top {
cursor: default;
}

View File

@ -3431,6 +3431,8 @@ function screen_meta($screen) {
if ( !isset($_wp_contextual_help) ) if ( !isset($_wp_contextual_help) )
$_wp_contextual_help = array(); $_wp_contextual_help = array();
$widgets_access = '';
switch ( $screen ) { switch ( $screen ) {
case 'post': case 'post':
if ( !isset($_wp_contextual_help['post']) ) { if ( !isset($_wp_contextual_help['post']) ) {
@ -3474,6 +3476,8 @@ function screen_meta($screen) {
$help = widgets_help(); $help = widgets_help();
$_wp_contextual_help['widgets'] = $help; $_wp_contextual_help['widgets'] = $help;
} }
$widgets_access = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
$show_screen = true;
break; break;
} }
?> ?>
@ -3496,6 +3500,7 @@ function screen_meta($screen) {
<?php endif; ?> <?php endif; ?>
<?php echo screen_layout($screen); ?> <?php echo screen_layout($screen); ?>
<?php echo $screen_options; ?> <?php echo $screen_options; ?>
<?php echo $widgets_access; ?>
<div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div> <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
</form> </form>
</div> </div>

View File

@ -6,6 +6,10 @@ wpWidgets = {
init : function() { init : function() {
var rem; var rem;
if ( $('body').hasClass('widgets_access') ) {
return;
}
$('#widgets-right div.sidebar-name').click(function(){ $('#widgets-right div.sidebar-name').click(function(){
var c = $(this).siblings('.widgets-sortables'); var c = $(this).siblings('.widgets-sortables');
if ( c.is(':visible') ) { if ( c.is(':visible') ) {

File diff suppressed because one or more lines are too long

View File

@ -300,6 +300,15 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
exit; exit;
} }
$widgets_access = get_user_setting( 'widgets_access' );
if ( isset($_GET['widgets-access']) ) {
$widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off';
set_user_setting( 'widgets_access', $widgets_access );
}
if ( 'on' == $widgets_access )
add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}') );
$messages = array( $messages = array(
__('Changes saved.') __('Changes saved.')
); );

View File

@ -783,6 +783,7 @@ function wp_user_settings() {
setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH ); setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH ); setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );
$_COOKIE['wp-settings-' . $user->ID] = $settings;
} }
/** /**
@ -798,44 +799,73 @@ function wp_user_settings() {
*/ */
function get_user_setting( $name, $default = false ) { function get_user_setting( $name, $default = false ) {
$arr = get_all_user_settings(); $all = get_all_user_settings();
return isset($arr[$name]) ? $arr[$name] : $default; return isset($all[$name]) ? $all[$name] : $default;
}
/**
* Add or update user interface setting.
*
* Both $name and $value can contain only ASCII letters, numbers and underscores.
* This function has to be used before any output has started as it calls setcookie().
*
* @package WordPress
* @subpackage Option
* @since 2.8.0
*
* @param string $name The name of the setting.
* @param string $value The value for the setting.
* @return bool true if set successfully/false if not.
*/
function set_user_setting( $name, $value ) {
if ( headers_sent() )
return false;
$all = get_all_user_settings();
$name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name );
if ( empty($name) )
return false;
$all[$name] = $value;
return wp_set_all_user_settings($all);
} }
/** /**
* Delete user interface settings. * Delete user interface settings.
* *
* Deleting settings would reset them to the defaults. * Deleting settings would reset them to the defaults.
* This function has to be used before any output has started as it calls setcookie().
* *
* @package WordPress * @package WordPress
* @subpackage Option * @subpackage Option
* @since 2.7.0 * @since 2.7.0
* *
* @param mixed $names The name or array of names of the setting to be deleted. * @param mixed $names The name or array of names of the setting to be deleted.
* @return bool true if deleted successfully/false if not.
*/ */
function delete_user_setting( $names ) { function delete_user_setting( $names ) {
global $current_user;
$arr = get_all_user_settings(); if ( headers_sent() )
return false;
$all = get_all_user_settings();
$names = (array) $names; $names = (array) $names;
foreach ( $names as $name ) { foreach ( $names as $name ) {
if ( isset($arr[$name]) ) { if ( isset($all[$name]) ) {
unset($arr[$name]); unset($all[$name]);
$settings = ''; $deleted = true;
} }
} }
if ( isset($settings) ) { if ( isset($deleted) )
foreach ( $arr as $k => $v ) return wp_set_all_user_settings($all);
$settings .= $k . '=' . $v . '&';
$settings = rtrim($settings, '&'); return false;
update_user_option( $current_user->ID, 'user-settings', $settings );
setcookie('wp-settings-' . $current_user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
}
} }
/** /**
@ -848,21 +878,57 @@ function delete_user_setting( $names ) {
* @return array the last saved user settings or empty array. * @return array the last saved user settings or empty array.
*/ */
function get_all_user_settings() { function get_all_user_settings() {
global $_updated_user_settings;
if ( ! $user = wp_get_current_user() ) if ( ! $user = wp_get_current_user() )
return array(); return array();
$arr = array(); if ( isset($_updated_user_settings) && is_array($_updated_user_settings) )
return $_updated_user_settings;
$all = array();
if ( isset($_COOKIE['wp-settings-' . $user->ID]) ) { if ( isset($_COOKIE['wp-settings-' . $user->ID]) ) {
$cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] ); $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
if ( $cookie && strpos($cookie, '=') ) // the '=' cannot be 1st char if ( $cookie && strpos($cookie, '=') ) // the '=' cannot be 1st char
parse_str($cookie, $arr); parse_str($cookie, $all);
} elseif ( isset($user->wp_usersettings) && is_string($user->wp_usersettings) ) { } else {
parse_str( $user->wp_usersettings, $arr ); $option = get_user_option('user-settings', $user->ID);
if ( $option && is_string($option) )
parse_str( $option, $all );
} }
return $arr; return $all;
}
/**
* Private. Set all user interface settings.
*
* @package WordPress
* @subpackage Option
* @since 2.8.0
*
*/
function wp_set_all_user_settings($all) {
global $_updated_user_settings;
if ( ! $user = wp_get_current_user() )
return false;
$_updated_user_settings = $all;
$settings = '';
foreach ( $all as $k => $v ) {
$v = preg_replace( '/[^A-Za-z0-9_]+/', '', $v );
$settings .= $k . '=' . $v . '&';
}
$settings = rtrim($settings, '&');
update_user_option( $user->ID, 'user-settings', $settings, false );
update_user_option( $user->ID, 'user-settings-time', time(), false );
return true;
} }
/** /**
@ -876,8 +942,8 @@ function delete_all_user_settings() {
if ( ! $user = wp_get_current_user() ) if ( ! $user = wp_get_current_user() )
return; return;
delete_usermeta( $user->ID, 'user-settings' ); update_user_option( $user->ID, 'user-settings', '', false );
setcookie('wp-settings-'.$user->ID, ' ', time() - 31536000, SITECOOKIEPATH); setcookie('wp-settings-' . $user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
} }
/** /**

View File

@ -332,7 +332,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' ); $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' );
$scripts->add_data( 'media-upload', 'group', 1 ); $scripts->add_data( 'media-upload', 'group', 1 );
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090530' ); $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090601' );
$scripts->add_data( 'admin-widgets', 'group', 1 ); $scripts->add_data( 'admin-widgets', 'group', 1 );
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090422' ); $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090422' );
@ -438,7 +438,7 @@ function wp_default_styles( &$styles ) {
$styles->add( 'global', '/wp-admin/css/global.css', array(), '20090514' ); $styles->add( 'global', '/wp-admin/css/global.css', array(), '20090514' );
$styles->add( 'media', '/wp-admin/css/media.css', array(), '20090516' ); $styles->add( 'media', '/wp-admin/css/media.css', array(), '20090516' );
$styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090530' ); $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090601' );
$styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090514' ); $styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090514' );
$styles->add( 'install', '/wp-admin/css/install.css', array(), '20090514' ); $styles->add( 'install', '/wp-admin/css/install.css', array(), '20090514' );
$styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css', array(), '20090514' ); $styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css', array(), '20090514' );