diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index ca7de560d8..817b70c515 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1,9 +1,9 @@ 250 ) + li.animate( { marginLeft: 0 } ); + t.siblings('h4').children('a').text( editText ); + } else { + t.animate( { height: 'show' } ); + if ( width > 250 ) + li.animate( { marginLeft: ( width - 250 ) * -1 } ); + t.siblings('h4').children('a').text( cancText ); + } + } ).end(); + }; + + // onclick for edit links + var editClick = function() { + var q = wpAjax.unserialize( this.href ); + // if link is in available widgets list, make sure it points to the current sidebar + if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) { + var w = q.edit || q.add; + toggleWidget( $('#current-sidebar .widget-control-list input[@name^="widget-id"][@value=' + w + ']').parents('li:first') ).blur(); + return false; + } else if ( q.sidebar ) { // otherwise, redirect to correct page + return true; + } + + // If link is in current widgets list, just open the form + toggleWidget( $(this).parents('li:first') ).blur(); + return false; + }; + + // onclick for add links + var addClick = function() { + var oldLi = $(this).parents('li:first').find('ul.widget-control-info li'); + var newLi = oldLi.clone(); + + if ( newLi.html().match( /%i%/ ) ) { + // supplid form is a template, replace %i% by unique id + var i = $('#generated-time').val() + increment.toString(); + increment++; + newLi.html( newLi.html().replace( /%i%/g, i ) ); + } else { + $(this).text( editText ).unbind().click( editClick ); + // save form content in textarea so we don't have any conflicting HTML ids + oldLi.html( '' ); + } + + // add event handlers + addWidgetControls( newLi ); + + // add widget to sidebar sortable + widgetSortable.append( newLi ).SortableAddItem( newLi[0] ); + + // increment widget counter + var n = parseInt( $('#widget-count').text(), 10 ) + 1; + $('#widget-count').text( n.toString() ) + + return false; + }; + + // add event handlers to all links found in context + var addWidgetControls = function( context ) { + if ( !context ) + context = document; + + $('a.widget-control-edit', context).click( editClick ); + + // onclick for save links + $('a.widget-control-save', context).click( function() { + toggleWidget( $(this).parents('li:first') ).blur() + return false; + } ); + + // onclick for remove links + $('a.widget-control-remove', context).click( function() { + var w = $(this).parents('li:first').find('input[@name^="widget-id"]').val(); + $(this).parents('li:first').remove(); + var t = $('#widget-list ul#widget-control-info-' + w + ' textarea'); + t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action') + .show().text( addText ).unbind().click( addClick ); + var n = parseInt( $('#widget-count').text(), 10 ) - 1; + $('#widget-count').text( n.toString() ) + return false; + } ); + } + + addWidgetControls(); + + $('a.widget-control-add').click( addClick ); + + // initialize sortable + var widgetSortable = $('#current-sidebar .widget-control-list').Sortable( { + accept: 'widget-sortable', + helperclass: 'sorthelper', + handle: 'h4.widget-title' + } ); + +}); diff --git a/wp-admin/widgets.php b/wp-admin/widgets.php index a33dc8463b..aa0364f16a 100644 --- a/wp-admin/widgets.php +++ b/wp-admin/widgets.php @@ -1,360 +1,272 @@ - - - $sidebar ) { - $cols[] = '\'' . $index . '\''; - } - $cols = implode( ', ', $cols ); - - $widgets = array(); - foreach ( $wp_registered_widgets as $name => $widget ) { - $widgets[] = '\'' . $widget['id'] . '\''; - } - $widgets = implode( ', ', $widgets ); -?> - -≡' - : ''; - - $output = '
follow these instructions.' ); /* TODO: article on codex */; ?>
View site »' ), get_bloginfo( 'url' ) . '/' ); ?>
+/* TODO: Paginate widgets list +$page_links = paginate_links( array( + 'base' => add_query_arg( 'apage', '%#%' ), + 'format' => '', + 'total' => ceil(($total = 105 )/ 10), + 'current' => $page +)); +*/ +$page_links = false; + +// Unsanitized! +$widget_search = isset($_GET['s']) ? $_GET['s'] : false; + +// Not entirely sure what all should be here +$show_values = array( + '' => $widget_search ? __( 'Show any widgets' ) : __( 'Show all widgets' ), + 'unused' => __( 'Show unused widgets' ), + 'used' => __( 'Show used widgets' ) +); + +$show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false; + + +$messages = array( + 'updated' => __('Changes saved.') +); + +require_once( 'admin-header.php' ); + +if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) : ?> + +