First cut of 'Show on screen' metabox show/hide. Needs styling. see #7552
git-svn-id: http://svn.automattic.com/wordpress/trunk@8712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
84f4fc27e0
commit
b314e60f74
|
@ -628,13 +628,17 @@ case 'closed-postboxes' :
|
|||
check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
|
||||
$closed = isset( $_POST['closed'] )? $_POST['closed'] : '';
|
||||
$closed = explode( ',', $_POST['closed'] );
|
||||
$hidden = isset( $_POST['hidden'] )? $_POST['hidden'] : '';
|
||||
$hidden = explode( ',', $_POST['hidden'] );
|
||||
$page = isset( $_POST['page'] )? $_POST['page'] : '';
|
||||
if ( !preg_match( '/^[a-z-]+$/', $page ) ) {
|
||||
die(-1);
|
||||
}
|
||||
if (!is_array($closed)) break;
|
||||
$current_user = wp_get_current_user();
|
||||
if ( is_array($closed) )
|
||||
update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
|
||||
if ( is_array($hidden) )
|
||||
update_usermeta($current_user->ID, 'meta-box-hidden_'.$page, $hidden);
|
||||
break;
|
||||
case 'get-permalink':
|
||||
check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
|
||||
|
|
|
@ -404,6 +404,13 @@ endif;
|
|||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<a href="#edit_settings" class="edit-settings-link hide-if-no-js"><?php _e('Edit Settings') ?></a>
|
||||
|
||||
<div id="edit-settings" class="hide-if-js hide-if-no-js">
|
||||
<h5><?php _e('Show on screen') ?></h5>
|
||||
<?php meta_box_prefs('post') ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
if ( 0 == $post_ID)
|
||||
|
|
|
@ -1254,6 +1254,8 @@ function do_meta_boxes($page, $context, $object) {
|
|||
|
||||
do_action('do_meta_boxes', $page, $context, $object);
|
||||
|
||||
$hidden = get_user_option( "meta-box-hidden_$page" );
|
||||
|
||||
echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
|
||||
|
||||
$i = 0;
|
||||
|
@ -1270,13 +1272,15 @@ function do_meta_boxes($page, $context, $object) {
|
|||
if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
|
||||
break;
|
||||
|
||||
|
||||
foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
|
||||
foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
|
||||
if ( false == $box || ! $box['title'] )
|
||||
continue;
|
||||
$i++;
|
||||
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
|
||||
$style = '';
|
||||
if ( in_array($box['id'], $hidden) )
|
||||
$style = 'style="display:none;"';
|
||||
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '" ' . $style . '>' . "\n";
|
||||
echo "<h3><span class='hndle'>{$box['title']}</span></h3>\n";
|
||||
echo '<div class="inside">' . "\n";
|
||||
call_user_func($box['callback'], $object, $box);
|
||||
|
@ -1315,4 +1319,27 @@ function remove_meta_box($id, $page, $context) {
|
|||
$wp_meta_boxes[$page][$context][$priority][$id] = false;
|
||||
}
|
||||
|
||||
function meta_box_prefs($page) {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( empty($wp_meta_boxes[$page]) )
|
||||
return;
|
||||
|
||||
$hidden = get_user_option( "meta-box-hidden_$page" );
|
||||
|
||||
echo '<ul class="metabox-prefs">';
|
||||
foreach ( array_keys($wp_meta_boxes[$page]) as $context ) {
|
||||
foreach ( array_keys($wp_meta_boxes[$page][$context]) as $priority ) {
|
||||
foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
|
||||
if ( false == $box || ! $box['title'] )
|
||||
continue;
|
||||
$box_id = $box['id'];
|
||||
echo '<label for="' . $box_id . '-hide">';
|
||||
echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
|
||||
echo "{$box['title']}</label>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -185,6 +185,16 @@ jQuery(document).ready( function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
// Edit Settings
|
||||
jQuery('.edit-settings-link').click(function () {
|
||||
if (jQuery('#edit-settings').is(":hidden")) {
|
||||
jQuery('#edit-settings').slideDown("normal");
|
||||
} else {
|
||||
jQuery('#edit-settings').slideUp("normal");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Custom Fields
|
||||
jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
|
||||
if ( jQuery.isFunction( autosave_update_post_ID ) ) {
|
||||
|
|
|
@ -5,6 +5,17 @@
|
|||
$('.postbox h3').before('<a class="togbox">+</a> ');
|
||||
$('.postbox a.togbox').click( function() { $($(this).parent().get(0)).toggleClass('closed'); save_postboxes_state(page); } );
|
||||
|
||||
$('.hide-postbox-tog').click( function() {
|
||||
var box = jQuery(this).val();
|
||||
var show = jQuery(this).attr('checked');
|
||||
if ( show ) {
|
||||
jQuery('#' + box).show();
|
||||
} else {
|
||||
jQuery('#' + box).hide();
|
||||
}
|
||||
save_postboxes_state(page);
|
||||
} );
|
||||
|
||||
if ( $.browser.msie ) {
|
||||
$('#side-sortables').append( '<div id="make-it-tall"></div>' );
|
||||
} else {
|
||||
|
@ -64,9 +75,11 @@ jQuery(document).ready(function(){postboxes.expandSidebar();});
|
|||
|
||||
function save_postboxes_state(page) {
|
||||
var closed = jQuery('.postbox').filter('.closed').map(function() { return this.id; }).get().join(',');
|
||||
var hidden = jQuery('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
|
||||
jQuery.post(postboxL10n.requestFile, {
|
||||
action: 'closed-postboxes',
|
||||
closed: closed,
|
||||
hidden: hidden,
|
||||
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
||||
page: page
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue