Widgets: drop onto closed sidebars.

- Make dropping a widget easier by preventing the source sidebar from resizing while the widget is being dragged.
- Move widgets dropped on closed sidebars to the top. UI Sortable places them randomly near the bottom.
- Fix possible regression in wp_list_widget_controls(), add an optional argument to output the sidebar name inside the sortable container.
- Updated styles for sidebar description and widget-hover class.
Part props shaunandrews, fixes #25952.
Built from https://develop.svn.wordpress.org/trunk@26426


git-svn-id: http://core.svn.wordpress.org/trunk@26326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2013-11-27 01:30:10 +00:00
parent 49a0254863
commit f46e743343
8 changed files with 285 additions and 187 deletions

View File

@ -10012,11 +10012,10 @@ input.newtag:focus ~ div.taghint {
} }
/* General Widget Styles */ /* General Widgets Styles */
.widget { .widget {
margin: 10px auto; margin: 0 auto 10px;
/* min-width: 50%; Not sure if this is needed */
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
@ -10053,10 +10052,8 @@ input.newtag:focus ~ div.taghint {
} }
/* Widget Dragging Helpers */ /* Widget Dragging Helpers */
.widget.ui-draggable-dragging { .widget.ui-draggable-dragging {
width: 280px !important; min-width: 100%;
min-width: 280px !important;
} }
.widget.ui-sortable-helper { .widget.ui-sortable-helper {
@ -10066,7 +10063,7 @@ input.newtag:focus ~ div.taghint {
.widget-placeholder { .widget-placeholder {
border: 1px dashed #bbb; border: 1px dashed #bbb;
margin: 10px 0; margin: 0 auto 10px;
height: 45px; height: 45px;
width: 100%; width: 100%;
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
@ -10078,6 +10075,12 @@ input.newtag:focus ~ div.taghint {
margin-top: 0; margin-top: 0;
} }
#widgets-right .closed .widget-placeholder {
height: 0;
border: 0;
margin-top: -10px;
}
/* Widget Sidebars */ /* Widget Sidebars */
.sidebar-name { .sidebar-name {
border: none; border: none;
@ -10106,14 +10109,15 @@ input.newtag:focus ~ div.taghint {
} }
.widgets-holder-wrap .description { .widgets-holder-wrap .description {
padding: 0; padding: 0 0 15px;
margin: 0; margin: 0;
font-style: normal; font-style: normal;
color: #777; color: #777;
} }
#available-widgets.widgets-holder-wrap .description { #widgets-right .widgets-holder-wrap .description {
padding-bottom: 10px; padding-right: 7px;
padding-left: 7px;
} }
/* Widgets 2-col Layout */ /* Widgets 2-col Layout */
@ -10173,6 +10177,10 @@ div#widgets-left .widget-holder {
font-size: 12px; font-size: 12px;
} }
#available-widgets #widget-list {
position: relative;
}
/* Inactive Sidebars */ /* Inactive Sidebars */
#widgets-left .inactive-sidebar { #widgets-left .inactive-sidebar {
clear: both; clear: both;
@ -10227,22 +10235,13 @@ div#widgets-right .widgets-holder-wrap {
margin: 10px 0 0 0; margin: 10px 0 0 0;
} }
div#widgets-right .widget {
margin: 0 auto;
margin-bottom: 10px;
}
div#widgets-right .sidebar-description { div#widgets-right .sidebar-description {
border-top: 1px solid #eeeeee; min-height: 20px;
padding: 10px 15px; margin-top: -5px;
}
div#widgets-right .closed .sidebar-description {
display: none;
} }
div#widgets-right .sidebar-name h3 { div#widgets-right .sidebar-name h3 {
padding: 15px 15px; padding: 15px 7px;
} }
div#widgets-right .sidebar-name .sidebar-name-arrow:before { div#widgets-right .sidebar-name .sidebar-name-arrow:before {
@ -10258,27 +10257,12 @@ div#widgets-right .widgets-sortables {
padding: 0 8px; padding: 0 8px;
margin-bottom: 9px; margin-bottom: 9px;
position: relative; position: relative;
min-height: 45px; min-height: 123px;
} }
div#widgets-right .widgets-sortables:after { div#widgets-right .closed .widgets-sortables {
display: block; min-height: 0;
content: ''; margin-bottom: 0;
position: absolute;
bottom: -10px;
right: 8px;
left: 8px;
z-index: 1; /* Required so that widgets hide the default dropzone indicator (.widgets-sortables:after) */
border: 1px dashed #bbb;
margin: 10px 0;
height: 45px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
div#widgets-right .widgets-sortables .widget {
z-index: 2; /* Required so that widgets hide the default dropzone indicator (.widgets-sortables:after) */
} }
.sidebar-name .spinner { .sidebar-name .spinner {
@ -10286,10 +10270,18 @@ div#widgets-right .widgets-sortables .widget {
float: none; float: none;
} }
/* Dragging a widget over a closed sidebar */
#widgets-right .widgets-holder-wrap.closed.widget-hover {
border-color: #777;
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
opacity: 0.6;
}
/* Accessibility Mode */ /* Accessibility Mode */
#available-widgets .widget-control-edit .edit { #available-widgets .widget-control-edit .edit {
display :none; display :none;
} }
#available-widgets .widget-control-edit .add { #available-widgets .widget-control-edit .add {
display: block; display: block;
position: absolute; position: absolute;
@ -10308,12 +10300,15 @@ div#widgets-right .widgets-sortables .widget {
padding: 16px 15px; padding: 16px 15px;
border-right: 1px solid #DDD; border-right: 1px solid #DDD;
} }
#widgets-right .widget-control-edit .add { #widgets-right .widget-control-edit .add {
display: none; display: none;
} }
#widgets-right .widget-control-edit:hover { #widgets-right .widget-control-edit:hover {
background: #444; background: #444;
} }
#widgets-right .widget-control-edit:before { #widgets-right .widget-control-edit:before {
content: '\f111'; content: '\f111';
display: inline-block; display: inline-block;
@ -10326,6 +10321,13 @@ div#widgets-right .widgets-sortables .widget {
padding-left: 4px; padding-left: 4px;
} }
.widgets-holder-wrap .sidebar-name,
.widgets-holder-wrap .sidebar-description {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.editwidget { .editwidget {
margin: 0 auto; margin: 0 auto;
} }
@ -10333,11 +10335,12 @@ div#widgets-right .widgets-sortables .widget {
margin-top: 20px; margin-top: 20px;
} }
.js .closed .widgets-sortables, .js .widgets-holder-wrap.closed .widget,
.js .closed .widget-holder, .js .widgets-holder-wrap.closed .sidebar-description,
.js .closed br.clear { .js .closed br.clear {
display: none; display: none;
} }
.nav-menus-php .item-edit:before, .nav-menus-php .item-edit:before,
.widget-top a.widget-action:after, .widget-top a.widget-action:after,
.control-section .accordion-section-title:after, .control-section .accordion-section-title:after,
@ -10737,6 +10740,10 @@ li#wp-admin-bar-menu-toggle {
float: right; float: right;
} }
.widget.ui-draggable-dragging {
min-width: 49%;
}
#widgets-right #available-widgets .widget:nth-child(even) { #widgets-right #available-widgets .widget:nth-child(even) {
float: left; float: left;
} }

File diff suppressed because one or more lines are too long

View File

@ -10012,11 +10012,10 @@ input.newtag:focus ~ div.taghint {
} }
/* General Widget Styles */ /* General Widgets Styles */
.widget { .widget {
margin: 10px auto; margin: 0 auto 10px;
/* min-width: 50%; Not sure if this is needed */
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
@ -10053,10 +10052,8 @@ input.newtag:focus ~ div.taghint {
} }
/* Widget Dragging Helpers */ /* Widget Dragging Helpers */
.widget.ui-draggable-dragging { .widget.ui-draggable-dragging {
width: 280px !important; min-width: 100%;
min-width: 280px !important;
} }
.widget.ui-sortable-helper { .widget.ui-sortable-helper {
@ -10066,7 +10063,7 @@ input.newtag:focus ~ div.taghint {
.widget-placeholder { .widget-placeholder {
border: 1px dashed #bbb; border: 1px dashed #bbb;
margin: 10px 0; margin: 0 auto 10px;
height: 45px; height: 45px;
width: 100%; width: 100%;
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
@ -10078,6 +10075,12 @@ input.newtag:focus ~ div.taghint {
margin-top: 0; margin-top: 0;
} }
#widgets-right .closed .widget-placeholder {
height: 0;
border: 0;
margin-top: -10px;
}
/* Widget Sidebars */ /* Widget Sidebars */
.sidebar-name { .sidebar-name {
border: none; border: none;
@ -10106,14 +10109,15 @@ input.newtag:focus ~ div.taghint {
} }
.widgets-holder-wrap .description { .widgets-holder-wrap .description {
padding: 0; padding: 0 0 15px;
margin: 0; margin: 0;
font-style: normal; font-style: normal;
color: #777; color: #777;
} }
#available-widgets.widgets-holder-wrap .description { #widgets-right .widgets-holder-wrap .description {
padding-bottom: 10px; padding-left: 7px;
padding-right: 7px;
} }
/* Widgets 2-col Layout */ /* Widgets 2-col Layout */
@ -10173,6 +10177,10 @@ div#widgets-left .widget-holder {
font-size: 12px; font-size: 12px;
} }
#available-widgets #widget-list {
position: relative;
}
/* Inactive Sidebars */ /* Inactive Sidebars */
#widgets-left .inactive-sidebar { #widgets-left .inactive-sidebar {
clear: both; clear: both;
@ -10227,22 +10235,13 @@ div#widgets-right .widgets-holder-wrap {
margin: 10px 0 0 0; margin: 10px 0 0 0;
} }
div#widgets-right .widget {
margin: 0 auto;
margin-bottom: 10px;
}
div#widgets-right .sidebar-description { div#widgets-right .sidebar-description {
border-top: 1px solid #eeeeee; min-height: 20px;
padding: 10px 15px; margin-top: -5px;
}
div#widgets-right .closed .sidebar-description {
display: none;
} }
div#widgets-right .sidebar-name h3 { div#widgets-right .sidebar-name h3 {
padding: 15px 15px; padding: 15px 7px;
} }
div#widgets-right .sidebar-name .sidebar-name-arrow:before { div#widgets-right .sidebar-name .sidebar-name-arrow:before {
@ -10258,27 +10257,12 @@ div#widgets-right .widgets-sortables {
padding: 0 8px; padding: 0 8px;
margin-bottom: 9px; margin-bottom: 9px;
position: relative; position: relative;
min-height: 45px; min-height: 123px;
} }
div#widgets-right .widgets-sortables:after { div#widgets-right .closed .widgets-sortables {
display: block; min-height: 0;
content: ''; margin-bottom: 0;
position: absolute;
bottom: -10px;
left: 8px;
right: 8px;
z-index: 1; /* Required so that widgets hide the default dropzone indicator (.widgets-sortables:after) */
border: 1px dashed #bbb;
margin: 10px 0;
height: 45px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
div#widgets-right .widgets-sortables .widget {
z-index: 2; /* Required so that widgets hide the default dropzone indicator (.widgets-sortables:after) */
} }
.sidebar-name .spinner { .sidebar-name .spinner {
@ -10286,10 +10270,18 @@ div#widgets-right .widgets-sortables .widget {
float: none; float: none;
} }
/* Dragging a widget over a closed sidebar */
#widgets-right .widgets-holder-wrap.closed.widget-hover {
border-color: #777;
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
opacity: 0.6;
}
/* Accessibility Mode */ /* Accessibility Mode */
#available-widgets .widget-control-edit .edit { #available-widgets .widget-control-edit .edit {
display :none; display :none;
} }
#available-widgets .widget-control-edit .add { #available-widgets .widget-control-edit .add {
display: block; display: block;
position: absolute; position: absolute;
@ -10308,12 +10300,15 @@ div#widgets-right .widgets-sortables .widget {
padding: 16px 15px; padding: 16px 15px;
border-left: 1px solid #DDD; border-left: 1px solid #DDD;
} }
#widgets-right .widget-control-edit .add { #widgets-right .widget-control-edit .add {
display: none; display: none;
} }
#widgets-right .widget-control-edit:hover { #widgets-right .widget-control-edit:hover {
background: #444; background: #444;
} }
#widgets-right .widget-control-edit:before { #widgets-right .widget-control-edit:before {
content: '\f111'; content: '\f111';
display: inline-block; display: inline-block;
@ -10326,6 +10321,13 @@ div#widgets-right .widgets-sortables .widget {
padding-right: 4px; padding-right: 4px;
} }
.widgets-holder-wrap .sidebar-name,
.widgets-holder-wrap .sidebar-description {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.editwidget { .editwidget {
margin: 0 auto; margin: 0 auto;
} }
@ -10333,11 +10335,12 @@ div#widgets-right .widgets-sortables .widget {
margin-top: 20px; margin-top: 20px;
} }
.js .closed .widgets-sortables, .js .widgets-holder-wrap.closed .widget,
.js .closed .widget-holder, .js .widgets-holder-wrap.closed .sidebar-description,
.js .closed br.clear { .js .closed br.clear {
display: none; display: none;
} }
.nav-menus-php .item-edit:before, .nav-menus-php .item-edit:before,
.widget-top a.widget-action:after, .widget-top a.widget-action:after,
.control-section .accordion-section-title:after, .control-section .accordion-section-title:after,
@ -10737,6 +10740,10 @@ li#wp-admin-bar-menu-toggle {
float: left; float: left;
} }
.widget.ui-draggable-dragging {
min-width: 49%;
}
#widgets-left #available-widgets .widget:nth-child(even) { #widgets-left #available-widgets .widget:nth-child(even) {
float: right; float: right;
} }

File diff suppressed because one or more lines are too long

View File

@ -63,21 +63,35 @@ function _sort_name_callback( $a, $b ) {
* @since 2.5.0 * @since 2.5.0
* *
* @param string $sidebar id slug of the sidebar * @param string $sidebar id slug of the sidebar
* @param string optional $sidebar_name Include the HTML for the sidebar name
*/ */
function wp_list_widget_controls( $sidebar ) { function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) {
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' ); add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
$description = wp_sidebar_description( $sidebar ); $description = wp_sidebar_description( $sidebar );
if ( !empty( $description ) ) { echo '<div id="' . esc_attr( $sidebar ) . '" class="widgets-sortables">';
echo "<div class='sidebar-description'>\n";
echo "\t<p class='description'>$description</p>"; if ( $sidebar_name ) {
echo "</div>\n"; ?>
<div class="sidebar-name">
<div class="sidebar-name-arrow"><br /></div>
<h3><?php echo esc_html( $sidebar_name ); ?> <span class="spinner"></span></h3>
</div>
<?php
} }
echo "<div id='$sidebar' class='widgets-sortables'>\n"; echo '<div class="sidebar-description">';
if ( ! empty( $description ) ) {
echo '<p class="description">' . $description . '</p>';
}
echo '</div>';
dynamic_sidebar( $sidebar ); dynamic_sidebar( $sidebar );
echo "</div>\n";
echo '</div>';
} }
/** /**

View File

@ -13,18 +13,19 @@ wpWidgets = {
isRTL = !! ( 'undefined' !== typeof isRtl && isRtl ); isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
$('#widgets-right .sidebar-name').click( function() { $('#widgets-right .sidebar-name').click( function() {
var $this = $(this), wrap = $this.closest('.widgets-holder-wrap'); var $this = $(this),
$wrap = $this.closest('.widgets-holder-wrap');
if ( wrap.hasClass('closed') ) { if ( $wrap.hasClass('closed') ) {
wrap.removeClass('closed'); $wrap.removeClass('closed');
$this.siblings('.widgets-sortables').sortable('refresh'); $this.parent().sortable('refresh');
} else { } else {
wrap.addClass('closed'); $wrap.addClass('closed');
} }
}); });
$('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() { $('#widgets-left .sidebar-name').click( function() {
$(this).parent().toggleClass('closed'); $(this).closest('.widgets-holder-wrap').toggleClass('closed');
}); });
$(document.body).bind('click.widgets-toggle', function(e) { $(document.body).bind('click.widgets-toggle', function(e) {
@ -36,7 +37,7 @@ wpWidgets = {
widget = target.closest('div.widget'); widget = target.closest('div.widget');
inside = widget.children('.widget-inside'); inside = widget.children('.widget-inside');
targetWidth = parseInt( widget.find('input.widget-width').val(), 10 ), targetWidth = parseInt( widget.find('input.widget-width').val(), 10 ),
widgetWidth = widget.width(); widgetWidth = widget.parent().width();
if ( inside.is(':hidden') ) { if ( inside.is(':hidden') ) {
if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) { if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
@ -69,9 +70,12 @@ wpWidgets = {
}); });
sidebars.children('.widget').each( function() { sidebars.children('.widget').each( function() {
var $this = $(this);
wpWidgets.appendTitle( this ); wpWidgets.appendTitle( this );
if ( $('p.widget-error', this).length ) {
$('a.widget-action', this).click(); if ( $this.find( 'p.widget-error' ).length ) {
$this.find( 'a.widget-action' ).trigger('click');
} }
}); });
@ -112,59 +116,128 @@ wpWidgets = {
cursor: 'move', cursor: 'move',
distance: 2, distance: 2,
containment: 'document', containment: 'document',
start: function(e,ui) { start: function( event, ui ) {
var inside = ui.item.children('.widget-inside'); var $this = $(this),
$wrap = $this.parent(),
inside = ui.item.children('.widget-inside');
//console.log(this);console.log(ui);
if ( inside.css('display') === 'block' ) { if ( inside.css('display') === 'block' ) {
inside.hide(); inside.hide();
$(this).sortable('refreshPositions'); $(this).sortable('refreshPositions');
} }
},
stop: function(e,ui) {
if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') ) {
ui.item.draggable('destroy');
}
if ( ui.item.hasClass('deleting') ) { if ( $wrap.hasClass('closed') ) {
wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget // There is a bug in UI Sortable that prevents firing of "over" when dragging a connected Draggable.
ui.item.remove(); // This won't be needed when the bug is fixed.
$wrap.addClass('widget-hover');
} else {
// Lock all open sidebars min-height when starting to drag.
// Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
$wrap.css( 'min-height', $wrap.height() + 'px' );
$this.css( 'min-height', $this.height() - 2 + 'px' );
}
},
stop: function( event, ui ) {
var addNew, widgetNumber, $sidebar, $children, child, item,
$widget = ui.item,
id = the_id;
if ( $widget.hasClass('deleting') ) {
wpWidgets.save( $widget, 1, 0, 1 ); // delete widget
$widget.remove();
return; return;
} }
var add = ui.item.find('input.add_new').val(), addNew = $widget.find('input.add_new').val();
n = ui.item.find('input.multi_number').val(), widgetNumber = $widget.find('input.multi_number').val();
id = the_id,
sb = $(this).attr('id');
ui.item.attr( 'style', '' ); $widget.attr( 'style', '' );
the_id = ''; the_id = '';
if ( add ) { if ( addNew ) {
if ( 'multi' === add ) { if ( 'multi' === addNew ) {
ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) ); $widget.html(
ui.item.attr( 'id', id.replace('__i__', n) ); $widget.html().replace( /<[^<>]+>/g, function( tag ) {
n++; return tag.replace( /__i__|%i%/g, widgetNumber );
$('div#' + id).find('input.multi_number').val(n); })
} else if ( 'single' === add ) { );
ui.item.attr( 'id', 'new-' + id );
$widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
widgetNumber++;
$( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
} else if ( 'single' === addNew ) {
$widget.attr( 'id', 'new-' + id );
rem = 'div#' + id; rem = 'div#' + id;
} }
wpWidgets.save( ui.item, 0, 0, 1 );
ui.item.find('input.add_new').val(''); wpWidgets.save( $widget, 0, 0, 1 );
ui.item.find('a.widget-action').click(); $widget.find('input.add_new').val('');
}
$sidebar = $widget.parent();
if ( $sidebar.parent().hasClass('closed') ) {
$sidebar.parent().removeClass('widget-hover closed jump-open');
$children = $sidebar.children('.widget');
// Make sure the dropped widget is at the top
if ( $children.length > 1 ) {
child = $children.get(0);
item = $widget.get(0);
if ( child.id && item.id && child.id !== item.id ) {
$( child ).before( $widget );
}
}
}
if ( addNew ) {
$widget.find( 'a.widget-action' ).trigger('click');
} else {
wpWidgets.saveOrder( $sidebar.attr('id') );
}
},
over: function( event, ui ) {
var $wrap = $(this).parent();
if ( $wrap.hasClass('closed') ) {
$wrap.addClass('widget-hover');
}
},
out: function( event, ui ) {
$(this).parent().removeClass('widget-hover');
},
deactivate: function( event, ui ) {
// Remove all min-height added on "start"
$(this).css( 'min-height', '' ).parent().css( 'min-height', '' );
},
receive: function( event, ui ) {
var $sender = $( ui.sender );
// Don't add more widgets to orphaned sidebars
if ( this.id.indexOf('orphaned_widgets') > -1 ) {
$sender.sortable('cancel');
return; return;
} }
wpWidgets.saveOrder(sb);
},
receive: function(e, ui) {
var sender = $(ui.sender);
if ( ! $(this).is(':visible') || this.id.indexOf('orphaned_widgets') > -1 ) { // If the last widget was moved out of an orphaned sidebar, close and remove it.
sender.sortable('cancel'); if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
} $sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
if ( sender.attr('id').indexOf('orphaned_widgets') > -1 && !sender.children('.widget').length ) {
sender.parents('.orphan-sidebar').slideUp(400, function(){ $(this).remove(); });
} }
} }
}).sortable( 'option', 'connectWith', 'div.widgets-sortables' ); }).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
@ -210,17 +283,16 @@ wpWidgets = {
}); });
$( '#available-widgets .widget .widget-title' ).on( 'click.widgets-chooser', function() { $( '#available-widgets .widget .widget-title' ).on( 'click.widgets-chooser', function() {
var widget = $(this).closest( '.widget' ); var $widget = $(this).closest( '.widget' );
if ( widget.hasClass( 'widget-in-question' ) || ( $( '#widgets-left' ).hasClass( 'chooser' ) ) ) { if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
self.closeChooser(); self.closeChooser();
} else { } else {
// Open the chooser // Open the chooser
self.clearWidgetSelection(); self.clearWidgetSelection();
$( '#widgets-left' ).addClass( 'chooser' ); $( '#widgets-left' ).addClass( 'chooser' );
widget.addClass( 'widget-in-question' ); $widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
widget.find( '.widget-description' ).after( chooser );
chooser.slideDown( 300, function() { chooser.slideDown( 300, function() {
selectSidebar.find('.widgets-chooser-selected').focus(); selectSidebar.find('.widgets-chooser-selected').focus();
}); });
@ -257,37 +329,39 @@ wpWidgets = {
}); });
}, },
saveOrder : function(sb) { saveOrder : function( sidebarId ) {
if ( sb ) { var data = {
$('#' + sb).closest('div.widgets-holder-wrap').find('.spinner:first').css('display', 'inline-block');
}
var a = {
action: 'widgets-order', action: 'widgets-order',
savewidgets: $('#_wpnonce_widgets').val(), savewidgets: $('#_wpnonce_widgets').val(),
sidebars: [] sidebars: []
}; };
if ( sidebarId ) {
$( '#' + sidebarId ).find('.spinner:first').css('display', 'inline-block');
}
$('div.widgets-sortables').each( function() { $('div.widgets-sortables').each( function() {
if ( $(this).sortable ) { if ( $(this).sortable ) {
a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(','); data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
} }
}); });
$.post( ajaxurl, a, function() { $.post( ajaxurl, data, function() {
$('.spinner').hide(); $('.spinner').hide();
}); });
}, },
save : function( widget, del, animate, order ) { save : function( widget, del, animate, order ) {
var sb = widget.closest('div.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a; var sidebarId = widget.closest('div.widgets-sortables').attr('id'),
data = widget.find('form').serialize(), a;
widget = $(widget); widget = $(widget);
$('.spinner', widget).show(); $('.spinner', widget).show();
a = { a = {
action: 'save-widget', action: 'save-widget',
savewidgets: $('#_wpnonce_widgets').val(), savewidgets: $('#_wpnonce_widgets').val(),
sidebar: sb sidebar: sidebarId
}; };
if ( del ) { if ( del ) {
@ -379,9 +453,9 @@ wpWidgets = {
// Open the widgets container // Open the widgets container
sidebar.closest( '.widgets-holder-wrap' ).removeClass('closed'); sidebar.closest( '.widgets-holder-wrap' ).removeClass('closed');
sidebar.sortable('refresh');
widget.prependTo( sidebar ); sidebar.find('.sidebar-description').after( widget );
sidebar.sortable('refresh');
wpWidgets.save( widget, 0, 0, 1 ); wpWidgets.save( widget, 0, 0, 1 );
// No longer "new" widget // No longer "new" widget

File diff suppressed because one or more lines are too long

View File

@ -333,9 +333,12 @@ do_action( 'widgets_admin_page' ); ?>
<div id="available-widgets" class="widgets-holder-wrap"> <div id="available-widgets" class="widgets-holder-wrap">
<div class="sidebar-name"> <div class="sidebar-name">
<div class="sidebar-name-arrow"><br /></div> <div class="sidebar-name-arrow"><br /></div>
<h3><?php _e('Available Widgets'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3></div> <h3><?php _e('Available Widgets'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3>
</div>
<div class="widget-holder"> <div class="widget-holder">
<div class="sidebar-description">
<p class="description"><?php _e('Drag widgets from here to a sidebar on the right to activate them. Drag widgets back here to deactivate them and delete their settings.'); ?></p> <p class="description"><?php _e('Drag widgets from here to a sidebar on the right to activate them. Drag widgets back here to deactivate them and delete their settings.'); ?></p>
</div>
<div id="widget-list"> <div id="widget-list">
<?php wp_list_widgets(); ?> <?php wp_list_widgets(); ?>
</div> </div>
@ -355,16 +358,13 @@ foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
?> ?>
<div class="<?php echo esc_attr( $wrap_class ); ?>"> <div class="<?php echo esc_attr( $wrap_class ); ?>">
<div class="sidebar-name">
<div class="sidebar-name-arrow"><br /></div>
<h3><?php echo esc_html( $registered_sidebar['name'] ); ?> <span class="spinner"></span></h3>
</div>
<div class="widget-holder inactive"> <div class="widget-holder inactive">
<?php wp_list_widget_controls( $registered_sidebar['id'] ); ?> <?php wp_list_widget_controls( $registered_sidebar['id'], $registered_sidebar['name'] ); ?>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</div> </div>
<?php <?php
} else { } else {
$theme_sidebars[$sidebar] = $registered_sidebar; $theme_sidebars[$sidebar] = $registered_sidebar;
} }
@ -407,11 +407,7 @@ foreach ( $theme_sidebars as $sidebar => $registered_sidebar ) {
?> ?>
<div class="<?php echo esc_attr( $wrap_class ); ?>"> <div class="<?php echo esc_attr( $wrap_class ); ?>">
<div class="sidebar-name"> <?php wp_list_widget_controls( $sidebar, $registered_sidebar['name'] ); // Show the control forms for each of the widgets in this sidebar ?>
<div class="sidebar-name-arrow"><br /></div>
<h3><?php echo esc_html( $registered_sidebar['name'] ); ?> <span class="spinner"></span></h3>
</div>
<?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?>
</div> </div>
<?php <?php