WordPress.org

Make WordPress Core

Changeset 10922


Ignore:
Timestamp:
04/13/2009 04:20:58 PM (11 years ago)
Author:
azaozz
Message:

Widgets: open when adding, clean-up AJAX calls, slower animation/less jumping in IE, see #9511

Location:
trunk
Files:
4 edited

Legend:

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

    r10917 r10922  
    12781278
    12791279    unset( $_POST['savewidgets'], $_POST['action'] );
    1280     $sidebars_widgets = array('array_version' => 3);
    1281 
    1282     foreach ( $_POST as $key => $val ) {
    1283         if ( preg_match( '/^(wp_inactive_widgets|sidebar-[0-9]+)$/', $key ) ) {
    1284             if ( preg_match( '/^[0-9a-z,_-]+$/i', $val ) ) {
     1280
     1281    // save widgets order for all sidebars
     1282    if ( is_array($_POST['sidebars']) ) {
     1283        $sidebars = array();
     1284        foreach ( $_POST['sidebars'] as $key => $val ) {
     1285            $sb = array();
     1286            if ( !empty($val) ) {
    12851287                $val = explode(',', $val);
    1286 
    12871288                foreach ( $val as $k => $v ) {
    1288                     $val[$k] = substr($v, strpos($v, '_') + 1);
     1289                    if ( strpos($v, 'widget-') === false )
     1290                        continue;
     1291
     1292                    $sb[$k] = substr($v, strpos($v, '_') + 1);
    12891293                }
    1290             } elseif ( '' == $val ) {
    1291                 $val = array();
    1292             } else {
    1293                 die('-1');
    12941294            }
    1295 
    1296             $sidebars_widgets[$key] = $val;
    1297         }
    1298     }
    1299 
    1300     wp_set_sidebars_widgets($sidebars_widgets);
    1301 
    1302     die('1');
     1295            $sidebars[$key] = $sb;
     1296        }
     1297        wp_set_sidebars_widgets($sidebars);
     1298        die('1');
     1299    }
     1300
     1301    die('-1');
    13031302    break;
    13041303case 'save-widget' :
    13051304    check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
    13061305
    1307     if ( !current_user_can('switch_themes') )
     1306    if ( !current_user_can('switch_themes') || !isset($_POST['id_base']) )
    13081307        die('-1');
    13091308
    13101309    unset( $_POST['savewidgets'], $_POST['action'] );
    13111310
     1311    $id_base = $_POST['id_base'];
    13121312    $number = isset($_POST['widget_number']) ? $_POST['widget_number'] : '';
    1313     if ( isset($_POST['id_base']) )
    1314         $id_base = $_POST['id_base'];
    1315     else
    1316         die('-1');
    1317 
    1318     $sidebar_id = (string) $_POST['sidebar'];
     1313    $sidebar_id = $_POST['sidebar'];
    13191314    $sidebars = wp_get_sidebars_widgets();
    13201315    $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
  • trunk/wp-admin/js/widgets.dev.js

    r10916 r10922  
    5151                ui.item.css({'marginLeft':'','width':''});
    5252
    53                 if ( add && n ) {
     53                if ( add ) {
    5454                    if ( 'multi' == add ) {
    5555                        ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__/g, n); }) );
     
    6262                    }
    6363                    wpWidgets.addEvents(ui.item);
    64                     wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0 );
     64                    wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0, 0 );
    6565                    ui.item.find('input.add_new').val('');
     66                    ui.item.find('a.widget-action').click();
    6667                }
    6768                wpWidgets.saveOrder(sb);
     
    7778
    7879    saveOrder : function(sb) {
    79         $('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
    80         var p = {
     80        $('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
     81
     82        var a = {
    8183            action: 'widgets-order',
    82             savewidgets: $('#_wpnonce_widgets').val()
     84            savewidgets: $('#_wpnonce_widgets').val(),
     85            sidebars: []
    8386        };
     87
    8488        $('.widgets-sortables').each( function() {
    85             p[$(this).parent().attr('id')] = $(this).sortable('toArray').join(',');
     89            a['sidebars[' + $(this).parent().attr('id') + ']'] = $(this).sortable('toArray').join(',');
    8690        });
    87         $.post( ajaxurl, p, function(){
     91
     92        $.post( ajaxurl, a, function() {
    8893            $('.ajax-feedback').css('visibility', 'hidden');
    8994        });
    90     },
     95    },
    9196
    92     save : function(data, sb, del, t) {
    93         var a;
    94 
     97    save : function(data, sb, del, t) {
    9598        $('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
    9699
    97         a = {
     100        var a = {
    98101            action: 'save-widget',
    99102            savewidgets: $('#_wpnonce_widgets').val(),
     
    113116
    114117            if ( del ) {
    115                 $(t).parents('li.widget').remove();
     118                $(t).parents('li.widget').slideUp('normal', function(){ $(this).remove(); });
    116119                if ( !a.widget_number ) {
    117120                    id = a['widget-id'];
     
    122125                }
    123126            } else {
    124                 $(t).parents('.widget-inside').hide('fast');
     127                $(t).parents('.widget-inside').slideUp('fast');
    125128            }
    126129        });
     
    144147                    if ( inside.parents('.widget-liquid-right').length )
    145148                        css['marginLeft'] = 270 - w + 'px';
    146                     inside.parents('.widget').css(css); 
     149                    inside.parents('.widget').css(css);
    147150                }
    148                 inside.show('fast');
     151                inside.slideDown('normal');
    149152            } else {
    150                 inside.parents('.widget').css({'width':'','marginLeft':''});
    151                 inside.hide('fast');
     153                inside.slideUp('normal', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
    152154            }
    153155            return false;
     
    164166
    165167};
    166     $(document).ready(function(){wpWidgets.init();});
     168$(document).ready(function(){wpWidgets.init();});
    167169
    168170})(jQuery);
  • trunk/wp-admin/js/widgets.js

    r10916 r10922  
    1 var wpWidgets;(function(a){wpWidgets={init:function(){var b;a("h3.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.hide().sortable("disable")}else{d.show().sortable("enable").sortable("refresh")}a(this).siblings("#widget-list").toggle()});this.addEvents();a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,helper:"clone",zIndex:5,start:function(){wpWidgets.fixWebkit(1)},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,opacity:0.65,start:function(d,c){wpWidgets.fixWebkit(1);c.item.find(".widget-inside").hide();c.item.css({marginLeft:"",width:""})},stop:function(f,c){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).parent().attr("id");c.item.css({marginLeft:"",width:""});if(d&&i){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__/g,i)}));c.item.attr("id",h.replace(/__i__/g,i));i++;a("li#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="li#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item.find("form").serializeArray(),g,0);c.item.find("input.add_new").val("")}wpWidgets.saveOrder(g);wpWidgets.fixWebkit()},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable")},saveOrder:function(c){a("#"+c+" .ajax-feedback").css("visibility","visible");var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val()};a(".widgets-sortables").each(function(){b[a(this).parent().attr("id")]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")})},save:function(e,f,c,d){var b;a("#"+f+" .ajax-feedback").css("visibility","visible");b={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:f};if(c){b.delete_widget=1}a.map(e,function(h,g){b[h.name]=h.value});a.post(ajaxurl,b,function(g){var h;a(".ajax-feedback").css("visibility","hidden");if(!d){return}if(c){a(d).parents("li.widget").remove();if(!b.widget_number){h=b["widget-id"];a("#available-widgets .widget-id").each(function(){if(a(this).val()==h){a(this).parents("li.widget").show()}})}}else{a(d).parents(".widget-inside").hide("fast")}})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},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>270&&c.parents(".widgets-sortables").length){e.width=d+30+"px";if(c.parents(".widget-liquid-right").length){e.marginLeft=270-d+"px"}c.parents(".widget").css(e)}c.show("fast")}else{c.parents(".widget").css({width:"",marginLeft:""});c.hide("fast")}return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),0,this);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),1,this);return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
     1var wpWidgets;(function(a){wpWidgets={init:function(){var b;a("h3.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.hide().sortable("disable")}else{d.show().sortable("enable").sortable("refresh")}a(this).siblings("#widget-list").toggle()});this.addEvents();a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,helper:"clone",zIndex:5,start:function(){wpWidgets.fixWebkit(1)},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,opacity:0.65,start:function(d,c){wpWidgets.fixWebkit(1);c.item.find(".widget-inside").hide();c.item.css({marginLeft:"",width:""})},stop:function(f,c){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).parent().attr("id");c.item.css({marginLeft:"",width:""});if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__/g,i)}));c.item.attr("id",h.replace(/__i__/g,i));i++;a("li#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="li#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item.find("form").serializeArray(),g,0,0);c.item.find("input.add_new").val("");c.item.find("a.widget-action").click()}wpWidgets.saveOrder(g);wpWidgets.fixWebkit()},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable")},saveOrder:function(c){a("#"+c+" .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).parent().attr("id")+"]"]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")})},save:function(e,f,c,d){a("#"+f+" .ajax-feedback").css("visibility","visible");var b={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:f};if(c){b.delete_widget=1}a.map(e,function(h,g){b[h.name]=h.value});a.post(ajaxurl,b,function(g){var h;a(".ajax-feedback").css("visibility","hidden");if(!d){return}if(c){a(d).parents("li.widget").slideUp("normal",function(){a(this).remove()});if(!b.widget_number){h=b["widget-id"];a("#available-widgets .widget-id").each(function(){if(a(this).val()==h){a(this).parents("li.widget").show()}})}}else{a(d).parents(".widget-inside").slideUp("fast")}})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},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>270&&c.parents(".widgets-sortables").length){e.width=d+30+"px";if(c.parents(".widget-liquid-right").length){e.marginLeft=270-d+"px"}c.parents(".widget").css(e)}c.slideDown("normal")}else{c.slideUp("normal",function(){c.parents(".widget").css({width:"",marginLeft:""})})}return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),0,this);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),1,this);return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
  • trunk/wp-includes/script-loader.php

    r10912 r10922  
    331331        $scripts->add_data( 'media-upload', 'group', 1 );
    332332
    333         $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090411' );
     333        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090413' );
    334334        $scripts->add_data( 'admin-widgets', 'group', 1 );
    335335
Note: See TracChangeset for help on using the changeset viewer.