WordPress.org

Make WordPress Core

Changeset 11503


Ignore:
Timestamp:
06/01/2009 11:31:34 PM (9 years ago)
Author:
azaozz
Message:

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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/ie.css

    r11445 r11503  
    374374
    375375* html .widget-title h4 {
    376     width: 210px;
     376    width: 205px;
    377377}
    378378
  • trunk/wp-admin/css/widgets.css

    r11498 r11503  
    323323}
    324324
     325#access-off,
     326.widgets_access .widget-action,
     327.widgets_access .sidebar-name-arrow,
     328.widgets_access #access-on,
     329.widgets_access .widget-holder .description {
     330    display: none;
     331}
     332
     333.widgets_access .widget-holder,
     334.widgets_access #widget-list {
     335    padding-top: 10px;
     336}
     337
     338.widgets_access #access-off {
     339    display: inline;
     340}
     341
     342.widgets_access #wpbody-content .widget-title-action,
     343.widgets_access #wpbody-content .widget-control-edit,
     344.widgets_access .closed .widgets-sortables,
     345.widgets_access .closed .widget-holder {
     346    display: block;
     347}
     348
     349.widgets_access .closed .sidebar-name {
     350    -moz-border-radius-bottomleft: 0;
     351    -moz-border-radius-bottomright: 0;
     352    -webkit-border-bottom-right-radius: 0;
     353    -webkit-border-bottom-left-radius: 0;
     354    -khtml-border-bottom-right-radius: 0;
     355    -khtml-border-bottom-left-radius: 0;
     356    border-bottom-right-radius: 0;
     357    border-bottom-left-radius: 0;
     358}
     359
     360.widgets_access .sidebar-name,
     361.widgets_access .widget .widget-top {
     362    cursor: default;
     363}
     364
  • trunk/wp-admin/includes/template.php

    r11485 r11503  
    34323432        $_wp_contextual_help = array();
    34333433
     3434    $widgets_access = '';
     3435
    34343436    switch ( $screen ) {
    34353437        case 'post':
     
    34753477                $_wp_contextual_help['widgets'] = $help;
    34763478            }
     3479            $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";
     3480            $show_screen = true;
    34773481            break;
    34783482    }
     
    34973501<?php echo screen_layout($screen); ?>
    34983502<?php echo $screen_options; ?>
     3503<?php echo $widgets_access; ?>
    34993504<div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
    35003505</form>
  • trunk/wp-admin/js/widgets.dev.js

    r11498 r11503  
    66    init : function() {
    77        var rem;
     8
     9        if ( $('body').hasClass('widgets_access') ) {
     10            return;
     11        }
    812
    913        $('#widgets-right div.sidebar-name').click(function(){
  • trunk/wp-admin/js/widgets.js

    r11498 r11503  
    1 var wpWidgets;(function(a){wpWidgets={init:function(){var b;a("#widgets-right div.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.sortable("disable");a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed");d.sortable("enable").sortable("refresh")}});a("#widgets-left div.sidebar-name").click(function(){if(a(this).siblings(".widget-holder").is(":visible")){a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed")}});a("#widgets-right .widget, #wp_inactive_widgets .widget").each(function(){wpWidgets.appendTitle(this)});this.addEvents();a(".widget-error").parents(".widget").find("a.widget-action").click();a("#available-widgets").droppable({tolerance:"pointer",accept:function(c){return a(c).parent().attr("id")!="widget-list"},drop:function(d,c){c.draggable.addClass("deleting");a("#removing-widget").hide().children("span").html("")},over:function(d,c){c.draggable.addClass("deleting");a(".widget-placeholder").hide();if(c.draggable.hasClass("ui-sortable-helper")){a("#removing-widget").show().children("span").html(c.draggable.find(".widget-title h4").html())}},out:function(d,c){c.draggable.removeClass("deleting");a(".widget-placeholder").show();a("#removing-widget").hide().children("span").html("")}});a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,helper:"clone",zIndex:5,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.helper.find(".widget-description").hide()},stop:function(d,c){if(b){a(b).hide()}b="";wpWidgets.fixWebkit()}});a(".widgets-sortables").sortable({placeholder:"widget-placeholder",connectWith:".widgets-sortables",items:".widget",handle:".widget-title",cursor:"move",distance:2,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.item.find(".widget-inside").hide();c.item.css({marginLeft:"",width:""})},stop:function(f,c){if(c.item.hasClass("ui-draggable")){c.item.draggable("destroy")}if(c.item.hasClass("deleting")){wpWidgets.save(c.item,1,0,1);c.item.remove();return}var d=c.item.find("input.add_new").val(),i=c.item.find("input.multi_number").val(),h=c.item.attr("id"),g=a(this).attr("id");c.item.css({marginLeft:"",width:""});wpWidgets.fixWebkit();if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,i)}));c.item.attr("id",h.replace(/__i__|%i%/g,i));i++;a("div#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="div#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item,0,0,1);c.item.find("input.add_new").val("");c.item.find("a.widget-action").click();return}wpWidgets.saveOrder(g)},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable");wpWidgets.resize();wpWidgets.fixLabels()},saveOrder:function(c){if(c){a("#"+c).parents(".widgets-holder-wrap").find(".ajax-feedback").css("visibility","visible")}var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val(),sidebars:[]};a(".widgets-sortables").each(function(){b["sidebars["+a(this).attr("id")+"]"]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")});this.resize()},save:function(g,d,e,b){var h=g.parents(".widgets-sortables").attr("id"),f=g.find("form").serialize(),c;g=a(g);g.find(".ajax-feedback").css("visibility","visible");c={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:h};if(d){c.delete_widget=1}f+="&"+a.param(c);a.post(ajaxurl,f,function(i){var j;if(d){if(!a(".widget_number",g).val()){j=a(".widget-id",g).val();a("#available-widgets .widget-id").each(function(){if(a(this).val()==j){a(this).parents(".widget").show()}})}if(e){b=0;g.slideUp("fast",function(){a(this).remove();wpWidgets.saveOrder()})}else{g.remove();wpWidgets.resize()}}else{a(".ajax-feedback").css("visibility","hidden");if(i&&i.length>2){a(".widget-content",g).html(i);wpWidgets.appendTitle(g);wpWidgets.fixLabels(g)}}if(b){wpWidgets.saveOrder()}})},appendTitle:function(b){a('input[type="text"]',b).each(function(){var c;if(this.id.indexOf("title")!=-1){c=a(this).val().replace(/<[^<>]+>/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");if(c){a(".widget-title .in-widget-title",b).html(": "+c)}return false}})},resize:function(){a(".widgets-sortables").not("#wp_inactive_widgets").each(function(){var c=50,b=a(".widget",this).length;c=c+parseInt(b*48,10);a(this).css("minHeight",c+"px")})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},fixLabels:function(b){b=b||document;a(".widget-inside label",b).each(function(){var c=a(this).attr("for");if(c&&c==a("input",this).attr("id")){a(this).removeAttr("for")}})},close:function(b){b.find(".widget-inside").slideUp("fast",function(){b.css({width:"",marginLeft:""})})},addEvents:function(b){b=b||document;a("a.widget-action",b).click(function(){var d=parseInt(a(this).parents(".widget").find(".widget-width").val(),10),e={},c=a(this).parents(".widget-top").siblings(".widget-inside");if(c.is(":hidden")){if(d>250&&c.parents(".widgets-sortables").length){e.width=d+30+"px";if(c.parents(".widget-liquid-right").length){e.marginLeft=235-d+"px"}c.parents(".widget").css(e)}c.slideDown("fast")}else{c.slideUp("fast",function(){c.parents(".widget").css({width:"",marginLeft:""})})}return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents(".widget"),0,1,0);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents(".widget"),1,1,0);return false});a(".widget-control-close",b).click(function(){wpWidgets.close(a(this).parents(".widget"));return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
     1var wpWidgets;(function(a){wpWidgets={init:function(){var b;if(a("body").hasClass("widgets_access")){return}a("#widgets-right div.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.sortable("disable");a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed");d.sortable("enable").sortable("refresh")}});a("#widgets-left div.sidebar-name").click(function(){if(a(this).siblings(".widget-holder").is(":visible")){a(this).parent().addClass("closed")}else{a(this).parent().removeClass("closed")}});a("#widgets-right .widget, #wp_inactive_widgets .widget").each(function(){wpWidgets.appendTitle(this)});this.addEvents();a(".widget-error").parents(".widget").find("a.widget-action").click();a("#available-widgets").droppable({tolerance:"pointer",accept:function(c){return a(c).parent().attr("id")!="widget-list"},drop:function(d,c){c.draggable.addClass("deleting");a("#removing-widget").hide().children("span").html("")},over:function(d,c){c.draggable.addClass("deleting");a(".widget-placeholder").hide();if(c.draggable.hasClass("ui-sortable-helper")){a("#removing-widget").show().children("span").html(c.draggable.find(".widget-title h4").html())}},out:function(d,c){c.draggable.removeClass("deleting");a(".widget-placeholder").show();a("#removing-widget").hide().children("span").html("")}});a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,helper:"clone",zIndex:5,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.helper.find(".widget-description").hide()},stop:function(d,c){if(b){a(b).hide()}b="";wpWidgets.fixWebkit()}});a(".widgets-sortables").sortable({placeholder:"widget-placeholder",connectWith:".widgets-sortables",items:".widget",handle:".widget-title",cursor:"move",distance:2,containment:"document",start:function(d,c){wpWidgets.fixWebkit(1);c.item.find(".widget-inside").hide();c.item.css({marginLeft:"",width:""})},stop:function(f,c){if(c.item.hasClass("ui-draggable")){c.item.draggable("destroy")}if(c.item.hasClass("deleting")){wpWidgets.save(c.item,1,0,1);c.item.remove();return}var d=c.item.find("input.add_new").val(),i=c.item.find("input.multi_number").val(),h=c.item.attr("id"),g=a(this).attr("id");c.item.css({marginLeft:"",width:""});wpWidgets.fixWebkit();if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,i)}));c.item.attr("id",h.replace(/__i__|%i%/g,i));i++;a("div#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="div#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item,0,0,1);c.item.find("input.add_new").val("");c.item.find("a.widget-action").click();return}wpWidgets.saveOrder(g)},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable");wpWidgets.resize();wpWidgets.fixLabels()},saveOrder:function(c){if(c){a("#"+c).parents(".widgets-holder-wrap").find(".ajax-feedback").css("visibility","visible")}var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val(),sidebars:[]};a(".widgets-sortables").each(function(){b["sidebars["+a(this).attr("id")+"]"]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")});this.resize()},save:function(g,d,e,b){var h=g.parents(".widgets-sortables").attr("id"),f=g.find("form").serialize(),c;g=a(g);g.find(".ajax-feedback").css("visibility","visible");c={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:h};if(d){c.delete_widget=1}f+="&"+a.param(c);a.post(ajaxurl,f,function(i){var j;if(d){if(!a(".widget_number",g).val()){j=a(".widget-id",g).val();a("#available-widgets .widget-id").each(function(){if(a(this).val()==j){a(this).parents(".widget").show()}})}if(e){b=0;g.slideUp("fast",function(){a(this).remove();wpWidgets.saveOrder()})}else{g.remove();wpWidgets.resize()}}else{a(".ajax-feedback").css("visibility","hidden");if(i&&i.length>2){a(".widget-content",g).html(i);wpWidgets.appendTitle(g);wpWidgets.fixLabels(g)}}if(b){wpWidgets.saveOrder()}})},appendTitle:function(b){a('input[type="text"]',b).each(function(){var c;if(this.id.indexOf("title")!=-1){c=a(this).val().replace(/<[^<>]+>/g,"").replace(/</g,"&lt;").replace(/>/g,"&gt;");if(c){a(".widget-title .in-widget-title",b).html(": "+c)}return false}})},resize:function(){a(".widgets-sortables").not("#wp_inactive_widgets").each(function(){var c=50,b=a(".widget",this).length;c=c+parseInt(b*48,10);a(this).css("minHeight",c+"px")})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},fixLabels:function(b){b=b||document;a(".widget-inside label",b).each(function(){var c=a(this).attr("for");if(c&&c==a("input",this).attr("id")){a(this).removeAttr("for")}})},close:function(b){b.find(".widget-inside").slideUp("fast",function(){b.css({width:"",marginLeft:""})})},addEvents:function(b){b=b||document;a("a.widget-action",b).click(function(){var d=parseInt(a(this).parents(".widget").find(".widget-width").val(),10),e={},c=a(this).parents(".widget-top").siblings(".widget-inside");if(c.is(":hidden")){if(d>250&&c.parents(".widgets-sortables").length){e.width=d+30+"px";if(c.parents(".widget-liquid-right").length){e.marginLeft=235-d+"px"}c.parents(".widget").css(e)}c.slideDown("fast")}else{c.slideUp("fast",function(){c.parents(".widget").css({width:"",marginLeft:""})})}return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents(".widget"),0,1,0);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents(".widget"),1,1,0);return false});a(".widget-control-close",b).click(function(){wpWidgets.close(a(this).parents(".widget"));return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
  • trunk/wp-admin/widgets.php

    r11450 r11503  
    301301}
    302302
     303$widgets_access = get_user_setting( 'widgets_access' );
     304if ( isset($_GET['widgets-access']) ) {
     305    $widgets_access = 'on' == $_GET['widgets-access'] ? 'on' : 'off';
     306    set_user_setting( 'widgets_access', $widgets_access );
     307}
     308
     309if ( 'on' == $widgets_access )
     310    add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}') );
     311
    303312$messages = array(
    304313    __('Changes saved.')
  • trunk/wp-includes/functions.php

    r11493 r11503  
    784784    setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
    785785    setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );
     786    $_COOKIE['wp-settings-' . $user->ID] = $settings;
    786787}
    787788
     
    799800function get_user_setting( $name, $default = false ) {
    800801
    801     $arr = get_all_user_settings();
    802 
    803     return isset($arr[$name]) ? $arr[$name] : $default;
     802    $all = get_all_user_settings();
     803
     804    return isset($all[$name]) ? $all[$name] : $default;
     805}
     806
     807/**
     808 * Add or update user interface setting.
     809 *
     810 * Both $name and $value can contain only ASCII letters, numbers and underscores.
     811 * This function has to be used before any output has started as it calls setcookie().
     812 *
     813 * @package WordPress
     814 * @subpackage Option
     815 * @since 2.8.0
     816 *
     817 * @param string $name The name of the setting.
     818 * @param string $value The value for the setting.
     819 * @return bool true if set successfully/false if not.
     820 */
     821function set_user_setting( $name, $value ) {
     822
     823    if ( headers_sent() )
     824        return false;
     825
     826    $all = get_all_user_settings();
     827    $name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name );
     828
     829    if ( empty($name) )
     830        return false;
     831
     832    $all[$name] = $value;
     833
     834    return wp_set_all_user_settings($all);
    804835}
    805836
     
    808839 *
    809840 * Deleting settings would reset them to the defaults.
     841 * This function has to be used before any output has started as it calls setcookie().
    810842 *
    811843 * @package WordPress
     
    814846 *
    815847 * @param mixed $names The name or array of names of the setting to be deleted.
     848 * @return bool true if deleted successfully/false if not.
    816849 */
    817850function delete_user_setting( $names ) {
    818     global $current_user;
    819 
    820     $arr = get_all_user_settings();
     851
     852    if ( headers_sent() )
     853        return false;
     854
     855    $all = get_all_user_settings();
    821856    $names = (array) $names;
    822857
    823858    foreach ( $names as $name ) {
    824         if ( isset($arr[$name]) ) {
    825             unset($arr[$name]);
    826             $settings = '';
     859        if ( isset($all[$name]) ) {
     860            unset($all[$name]);
     861            $deleted = true;
    827862        }
    828863    }
    829864
    830     if ( isset($settings) ) {
    831         foreach ( $arr as $k => $v )
    832             $settings .= $k . '=' . $v . '&';
    833 
    834         $settings = rtrim($settings, '&');
    835 
    836         update_user_option( $current_user->ID, 'user-settings', $settings );
    837         setcookie('wp-settings-' . $current_user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
    838     }
     865    if ( isset($deleted) )
     866        return wp_set_all_user_settings($all);
     867
     868    return false;
    839869}
    840870
     
    849879 */
    850880function get_all_user_settings() {
     881    global $_updated_user_settings;
     882
    851883    if ( ! $user = wp_get_current_user() )
    852884        return array();
    853885
    854     $arr = array();
     886    if ( isset($_updated_user_settings) && is_array($_updated_user_settings) )
     887        return $_updated_user_settings;
     888
     889    $all = array();
    855890    if ( isset($_COOKIE['wp-settings-' . $user->ID]) ) {
    856891        $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
    857892
    858893        if ( $cookie && strpos($cookie, '=') ) // the '=' cannot be 1st char
    859             parse_str($cookie, $arr);
    860 
    861     } elseif ( isset($user->wp_usersettings) && is_string($user->wp_usersettings) ) {
    862         parse_str( $user->wp_usersettings, $arr );
    863     }
    864 
    865     return $arr;
     894            parse_str($cookie, $all);
     895
     896    } else {
     897        $option = get_user_option('user-settings', $user->ID);
     898        if ( $option && is_string($option) )
     899            parse_str( $option, $all );
     900    }
     901
     902    return $all;
     903}
     904
     905/**
     906 * Private. Set all user interface settings.
     907 *
     908 * @package WordPress
     909 * @subpackage Option
     910 * @since 2.8.0
     911 *
     912 */
     913function wp_set_all_user_settings($all) {
     914    global $_updated_user_settings;
     915
     916    if ( ! $user = wp_get_current_user() )
     917        return false;
     918
     919    $_updated_user_settings = $all;
     920    $settings = '';
     921    foreach ( $all as $k => $v ) {
     922        $v = preg_replace( '/[^A-Za-z0-9_]+/', '', $v );
     923        $settings .= $k . '=' . $v . '&';
     924    }
     925
     926    $settings = rtrim($settings, '&');
     927
     928    update_user_option( $user->ID, 'user-settings', $settings, false );
     929    update_user_option( $user->ID, 'user-settings-time', time(), false );
     930
     931    return true;
    866932}
    867933
     
    877943        return;
    878944
    879     delete_usermeta( $user->ID, 'user-settings' );
    880     setcookie('wp-settings-'.$user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
     945    update_user_option( $user->ID, 'user-settings', '', false );
     946    setcookie('wp-settings-' . $user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
    881947}
    882948
  • trunk/wp-includes/script-loader.php

    r11498 r11503  
    333333        $scripts->add_data( 'media-upload', 'group', 1 );
    334334
    335         $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090530' );
     335        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090601' );
    336336        $scripts->add_data( 'admin-widgets', 'group', 1 );
    337337
     
    439439    $styles->add( 'global', '/wp-admin/css/global.css', array(), '20090514' );
    440440    $styles->add( 'media', '/wp-admin/css/media.css', array(), '20090516' );
    441     $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090530' );
     441    $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090601' );
    442442    $styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090514' );
    443443    $styles->add( 'install', '/wp-admin/css/install.css', array(), '20090514' );
Note: See TracChangeset for help on using the changeset viewer.