Widgets: open when adding, clean-up AJAX calls, slower animation/less jumping in IE, see #9511
git-svn-id: http://svn.automattic.com/wordpress/trunk@10922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c15b0ba08b
commit
4be0d4b866
|
@ -1277,45 +1277,40 @@ case 'widgets-order' :
|
|||
die('-1');
|
||||
|
||||
unset( $_POST['savewidgets'], $_POST['action'] );
|
||||
$sidebars_widgets = array('array_version' => 3);
|
||||
|
||||
foreach ( $_POST as $key => $val ) {
|
||||
if ( preg_match( '/^(wp_inactive_widgets|sidebar-[0-9]+)$/', $key ) ) {
|
||||
if ( preg_match( '/^[0-9a-z,_-]+$/i', $val ) ) {
|
||||
// save widgets order for all sidebars
|
||||
if ( is_array($_POST['sidebars']) ) {
|
||||
$sidebars = array();
|
||||
foreach ( $_POST['sidebars'] as $key => $val ) {
|
||||
$sb = array();
|
||||
if ( !empty($val) ) {
|
||||
$val = explode(',', $val);
|
||||
|
||||
foreach ( $val as $k => $v ) {
|
||||
$val[$k] = substr($v, strpos($v, '_') + 1);
|
||||
}
|
||||
} elseif ( '' == $val ) {
|
||||
$val = array();
|
||||
} else {
|
||||
die('-1');
|
||||
}
|
||||
if ( strpos($v, 'widget-') === false )
|
||||
continue;
|
||||
|
||||
$sidebars_widgets[$key] = $val;
|
||||
$sb[$k] = substr($v, strpos($v, '_') + 1);
|
||||
}
|
||||
}
|
||||
$sidebars[$key] = $sb;
|
||||
}
|
||||
wp_set_sidebars_widgets($sidebars);
|
||||
die('1');
|
||||
}
|
||||
|
||||
wp_set_sidebars_widgets($sidebars_widgets);
|
||||
|
||||
die('1');
|
||||
die('-1');
|
||||
break;
|
||||
case 'save-widget' :
|
||||
check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
|
||||
|
||||
if ( !current_user_can('switch_themes') )
|
||||
if ( !current_user_can('switch_themes') || !isset($_POST['id_base']) )
|
||||
die('-1');
|
||||
|
||||
unset( $_POST['savewidgets'], $_POST['action'] );
|
||||
|
||||
$id_base = $_POST['id_base'];
|
||||
$number = isset($_POST['widget_number']) ? $_POST['widget_number'] : '';
|
||||
if ( isset($_POST['id_base']) )
|
||||
$id_base = $_POST['id_base'];
|
||||
else
|
||||
die('-1');
|
||||
|
||||
$sidebar_id = (string) $_POST['sidebar'];
|
||||
$sidebar_id = $_POST['sidebar'];
|
||||
$sidebars = wp_get_sidebars_widgets();
|
||||
$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ wpWidgets = {
|
|||
var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).parent().attr('id');
|
||||
ui.item.css({'marginLeft':'','width':''});
|
||||
|
||||
if ( add && n ) {
|
||||
if ( add ) {
|
||||
if ( 'multi' == add ) {
|
||||
ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__/g, n); }) );
|
||||
ui.item.attr( 'id', id.replace(/__i__/g, n) );
|
||||
|
@ -61,8 +61,9 @@ wpWidgets = {
|
|||
rem = 'li#' + id;
|
||||
}
|
||||
wpWidgets.addEvents(ui.item);
|
||||
wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0 );
|
||||
wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0, 0 );
|
||||
ui.item.find('input.add_new').val('');
|
||||
ui.item.find('a.widget-action').click();
|
||||
}
|
||||
wpWidgets.saveOrder(sb);
|
||||
wpWidgets.fixWebkit();
|
||||
|
@ -76,25 +77,27 @@ wpWidgets = {
|
|||
},
|
||||
|
||||
saveOrder : function(sb) {
|
||||
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
||||
var p = {
|
||||
action: 'widgets-order',
|
||||
savewidgets: $('#_wpnonce_widgets').val()
|
||||
};
|
||||
$('.widgets-sortables').each( function() {
|
||||
p[$(this).parent().attr('id')] = $(this).sortable('toArray').join(',');
|
||||
});
|
||||
$.post( ajaxurl, p, function(){
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
});
|
||||
},
|
||||
|
||||
save : function(data, sb, del, t) {
|
||||
var a;
|
||||
|
||||
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
||||
|
||||
a = {
|
||||
var a = {
|
||||
action: 'widgets-order',
|
||||
savewidgets: $('#_wpnonce_widgets').val(),
|
||||
sidebars: []
|
||||
};
|
||||
|
||||
$('.widgets-sortables').each( function() {
|
||||
a['sidebars[' + $(this).parent().attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
||||
});
|
||||
|
||||
$.post( ajaxurl, a, function() {
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
});
|
||||
},
|
||||
|
||||
save : function(data, sb, del, t) {
|
||||
$('#' + sb + ' .ajax-feedback').css('visibility', 'visible');
|
||||
|
||||
var a = {
|
||||
action: 'save-widget',
|
||||
savewidgets: $('#_wpnonce_widgets').val(),
|
||||
sidebar: sb
|
||||
|
@ -112,7 +115,7 @@ wpWidgets = {
|
|||
return;
|
||||
|
||||
if ( del ) {
|
||||
$(t).parents('li.widget').remove();
|
||||
$(t).parents('li.widget').slideUp('normal', function(){ $(this).remove(); });
|
||||
if ( !a.widget_number ) {
|
||||
id = a['widget-id'];
|
||||
$('#available-widgets .widget-id').each(function(){
|
||||
|
@ -121,7 +124,7 @@ wpWidgets = {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
$(t).parents('.widget-inside').hide('fast');
|
||||
$(t).parents('.widget-inside').slideUp('fast');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -143,12 +146,11 @@ wpWidgets = {
|
|||
css['width'] = w + 30 + 'px';
|
||||
if ( inside.parents('.widget-liquid-right').length )
|
||||
css['marginLeft'] = 270 - w + 'px';
|
||||
inside.parents('.widget').css(css);
|
||||
inside.parents('.widget').css(css);
|
||||
}
|
||||
inside.show('fast');
|
||||
inside.slideDown('normal');
|
||||
} else {
|
||||
inside.parents('.widget').css({'width':'','marginLeft':''});
|
||||
inside.hide('fast');
|
||||
inside.slideUp('normal', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
@ -163,6 +165,6 @@ wpWidgets = {
|
|||
}
|
||||
|
||||
};
|
||||
$(document).ready(function(){wpWidgets.init();});
|
||||
$(document).ready(function(){wpWidgets.init();});
|
||||
|
||||
})(jQuery);
|
||||
|
|
|
@ -1 +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);
|
||||
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){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);
|
|
@ -330,7 +330,7 @@ function wp_default_scripts( &$scripts ) {
|
|||
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' );
|
||||
$scripts->add_data( 'media-upload', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090411' );
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090413' );
|
||||
$scripts->add_data( 'admin-widgets', 'group', 1 );
|
||||
|
||||
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090102' );
|
||||
|
|
Loading…
Reference in New Issue