WordPress.org

Make WordPress Core

Changeset 11498


Ignore:
Timestamp:
05/31/2009 11:34:08 AM (9 years ago)
Author:
azaozz
Message:

Reload the widget form with the ajax response after save, add Close link to the widgets, don't auto-close on save to show possible errors returned from validation

Location:
trunk
Files:
7 edited

Legend:

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

    r11450 r11498  
    12901290    $widget_id = $_POST['widget-id'];
    12911291    $sidebar_id = $_POST['sidebar'];
     1292    $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
     1293    $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
     1294    $error = '<p>' . __('An error has occured. Please reload the page and try again.') . '</p>';
    12921295
    12931296    $sidebars = wp_get_sidebars_widgets();
     
    12981301
    12991302        if ( !isset($wp_registered_widgets[$widget_id]) )
    1300             die('-1');
     1303            die($error);
    13011304
    13021305        $sidebar = array_diff( $sidebar, array($widget_id) );
    13031306        $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
     1307    } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
     1308        if ( !$multi_number )
     1309            die($error);
     1310
     1311        $_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
     1312        $widget_id = $id_base . '-' . $multi_number;
     1313        $sidebar[] = $widget_id;
    13041314    }
    13051315    $_POST['widget-id'] = $sidebar;
     
    13251335    }
    13261336
    1327     die('1');
     1337    if ( !empty($_POST['add_new']) )
     1338        die();
     1339
     1340    if ( $form = $wp_registered_widget_controls[$widget_id] )
     1341        call_user_func_array( $form['callback'], $form['params'] );
     1342
     1343    die();
    13281344    break;
    13291345default :
  • trunk/wp-admin/css/widgets.css

    r11482 r11498  
    189189.widget .widget-inside,
    190190.widget .widget-description {
    191     padding: 15px;
     191    padding: 12px 12px 10px;
    192192    font-size: 11px;
    193193    line-height: 16px;
     
    225225.widget-control-actions a {
    226226    text-decoration: none;
     227}
     228
     229.widget-control-actions a:hover {
     230    text-decoration: underline;
     231}
     232
     233.widget-control-actions .ajax-feedback {
     234    padding-bottom: 3px;
     235}
     236
     237.widget-control-actions div.alignleft {
     238    margin-top: 6px;
    227239}
    228240
  • trunk/wp-admin/includes/widgets.php

    r11445 r11498  
    169169    <div class="widget-inside">
    170170    <form action="" method="post">
     171    <div class="widget-content">
    171172<?php
    172173    if ( isset($control['callback']) )
     
    174175    else
    175176        echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
    176 
     177    </div>
    177178    <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" />
    178179    <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
     
    184185
    185186    <div class="widget-control-actions">
    186         <a class="button widget-control-remove alignleft" href="#remove"><?php _e('Remove'); ?></a>
     187        <div class="alignleft">
     188        <a class="widget-control-remove" href="#remove"><?php _e('Remove'); ?></a> |
     189        <a class="widget-control-close" href="#close"><?php _e('Close'); ?></a>
     190        </div>
    187191<?php       if ( 'noform' !== $has_form ) { ?>
    188         <input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php esc_attr_e('Save'); ?>" />
     192        <div class="alignright">
     193        <img src="images/wpspin_light.gif" class="ajax-feedback " title="" alt="" />
     194        <input type="submit" name="savewidget" class="button-primary widget-control-save" value="<?php esc_attr_e('Save'); ?>" />
     195        </div>
    189196<?php       } ?>
    190197        <br class="clear" />
  • trunk/wp-admin/js/widgets.dev.js

    r11445 r11498  
    9393
    9494                if ( ui.item.hasClass('deleting') ) {
    95                     wpWidgets.save( ui.item, 1, 0, 0, 1 ); // delete widget
     95                    wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget
    9696                    ui.item.remove();
    9797                    return;
     
    113113                    }
    114114                    wpWidgets.addEvents(ui.item);
    115                     wpWidgets.save( ui.item, 0, 0, 0, 1 );
     115                    wpWidgets.save( ui.item, 0, 0, 1 );
    116116                    ui.item.find('input.add_new').val('');
    117117                    ui.item.find('a.widget-action').click();
     
    126126        }).not(':visible').sortable('disable');
    127127        wpWidgets.resize();
    128 
    129         $('.widget-inside label').each(function(){
    130             var f = $(this).attr('for');
    131             if ( f && f == $('input', this).attr('id') )
    132                 $(this).removeAttr('for');
    133         });
     128        wpWidgets.fixLabels();
    134129    },
    135130
     
    154149    },
    155150
    156     save : function(widget, del, close, animate, order) {
     151    save : function(widget, del, animate, order) {
    157152        var sb = widget.parents('.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
    158153        widget = $(widget);
    159         $('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
     154        widget.find('.ajax-feedback').css('visibility', 'visible');
    160155
    161156        a = {
     
    192187                    wpWidgets.resize();
    193188                }
    194             } else if ( close ) {
    195                 widget.find('.widget-inside').slideUp('fast', function(){
    196                     widget.css({'width':'','marginLeft':''});
     189            } else {
     190                $('.ajax-feedback').css('visibility', 'hidden');
     191                if ( r && r.length > 2 ) {
     192                    $('.widget-content', widget).html(r);
    197193                    wpWidgets.appendTitle(widget);
    198                     $('.ajax-feedback').css('visibility', 'hidden');
    199                 });
     194                    wpWidgets.fixLabels(widget);
     195                }
    200196            }
    201197            if ( order )
     
    231227        });
    232228    },
     229   
     230    fixLabels : function(sc) {
     231        sc = sc || document;
     232
     233        $('.widget-inside label', sc).each(function(){
     234            var f = $(this).attr('for');
     235
     236            if ( f && f == $('input', this).attr('id') )
     237                $(this).removeAttr('for');
     238        });
     239    },
     240   
     241    close : function(widget) {
     242        widget.find('.widget-inside').slideUp('fast', function(){
     243            widget.css({'width':'','marginLeft':''});
     244        });
     245    },
    233246
    234247    addEvents : function(sc) {
     
    250263        });
    251264        $('.widget-control-save', sc).click(function(){
    252             wpWidgets.save( $(this).parents('.widget'), 0, 1, 1, 0 );
     265            wpWidgets.save( $(this).parents('.widget'), 0, 1, 0 );
    253266            return false;
    254267        });
    255268        $('.widget-control-remove', sc).click(function(){
    256             wpWidgets.save( $(this).parents('.widget'), 1, 1, 1, 0 );
     269            wpWidgets.save( $(this).parents('.widget'), 1, 1, 0 );
     270            return false;
     271        });
     272        $('.widget-control-close', sc).click(function(){
     273            wpWidgets.close( $(this).parents('.widget') );
    257274            return false;
    258275        });
  • trunk/wp-admin/js/widgets.js

    r11445 r11498  
    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,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,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();a(".widget-inside label").each(function(){var c=a(this).attr("for");if(c&&c==a("input",this).attr("id")){a(this).removeAttr("for")}})},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,h,e,b){var i=g.parents(".widgets-sortables").attr("id"),f=g.find("form").serialize(),c;g=a(g);a("#"+i).parents(".widgets-holder-wrap").find(".ajax-feedback").css("visibility","visible");c={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:i};if(d){c.delete_widget=1}f+="&"+a.param(c);a.post(ajaxurl,f,function(j){var k;if(d){if(!a(".widget_number",g).val()){k=a(".widget-id",g).val();a("#available-widgets .widget-id").each(function(){if(a(this).val()==k){a(this).parents(".widget").show()}})}if(e){b=0;g.slideUp("fast",function(){a(this).remove();wpWidgets.saveOrder()})}else{g.remove();wpWidgets.resize()}}else{if(h){g.find(".widget-inside").slideUp("fast",function(){g.css({width:"",marginLeft:""});wpWidgets.appendTitle(g);a(".ajax-feedback").css("visibility","hidden")})}}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})},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,1,0);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents(".widget"),1,1,1,0);return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery);
     1var 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);
  • trunk/wp-includes/script-loader.php

    r11483 r11498  
    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' ), '20090524' );
     335        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090530' );
    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(), '20090514' );
     441    $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090530' );
    442442    $styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090514' );
    443443    $styles->add( 'install', '/wp-admin/css/install.css', array(), '20090514' );
  • trunk/wp-includes/widgets.php

    r11484 r11498  
    298298        }
    299299
    300         unset($settings['_multiwidget']);
     300        unset($settings['_multiwidget'], $settings['__i__']);
    301301        return $settings;
    302302    }
Note: See TracChangeset for help on using the changeset viewer.