New experimental category interface, fixes #5618. Hat tip: mdawaffe.

git-svn-id: https://develop.svn.wordpress.org/trunk@6588 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2008-01-10 09:39:35 +00:00
parent 089284dadd
commit 2a77958de3
10 changed files with 731 additions and 76 deletions

View File

@ -157,21 +157,49 @@ case 'add-category' : // On the Fly
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['newcat']);
if ( 0 > $parent = (int) $_POST['newcat_parent'] )
$parent = 0;
$checked_categories = array_map( 'absint', (array) $_POST['post_category'] );
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
$category_nicename = sanitize_title($cat_name);
if ( '' === $category_nicename )
continue;
$cat_id = wp_create_category( $cat_name );
$cat_name = wp_specialchars(stripslashes($cat_name));
$cat_id = wp_create_category( $cat_name, $parent );
$checked_categories[] = $cat_id;
if ( $parent ) // Do these all at once in a second
continue;
$category = get_category( $cat_id );
$category->_is_checked = true;
ob_start();
dropdown_categories( 0, $category );
$data = ob_get_contents();
ob_end_clean();
$x->add( array(
'what' => 'category',
'id' => $cat_id,
'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>",
'data' => $data,
'position' => -1
) );
}
if ( $parent ) { // Foncy - replace the parent and all its children
$parent = get_category( $parent );
ob_start();
dropdown_categories( 0, $parent );
$data = ob_get_contents();
ob_end_clean();
$x->add( array(
'what' => 'category',
'id' => $parent->term_id,
'old_id' => $parent->term_id,
'data' => $data,
'position' => -1
) );
}
$x->send();
break;
case 'add-link-category' : // On the Fly

View File

@ -2,8 +2,6 @@
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
if (!isset($_GET["page"])) require_once('admin.php');
if ( $editing ) {
if ( current_user_can('manage_categories') )
wp_enqueue_script( 'ajaxcat' );
if ( user_can_richedit() )
wp_enqueue_script( 'wp_tiny_mce' );
}

View File

@ -121,8 +121,34 @@ else
<div id="categorydiv" class="postbox <?php echo postbox_classes('categorydiv'); ?>">
<h3><?php _e('Categories') ?></h3>
<div class="inside">
<p id="jaxcat"><?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?></p>
<ul id="categorychecklist" class="list:category"><?php dropdown_categories(); ?></ul>
<div id="category-adder" class="wp-hidden-children">
<h4><a id="category-add-toggle" href="#category-add"><?php _e( '+ Add New Category' ); ?></a></h4>
<p id="category-add" class="wp-hidden-child">
<input type="text" name="newcat" id="newcat" class="form-required" value="<?php _e( 'New category name' ); ?>" />
<?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); ?>
<a id="category-add-sumbit" class="add:categorychecklist:categorydiv button" href="<?php echo wp_nonce_url( '', 'add-category' ); ?>"><?php _e( 'Add' ); ?></a>
<span id="category-ajax-response"></span>
</p>
</div>
<ul id="category-tabs">
<li class="ui-tabs-selected"><a href="#categories-all"><?php _e( 'All Categories' ); ?></a></li>
<li><a href="#categories-pop"><?php _e( 'Most Used' ); ?></a></li>
</ul>
<div id="categories-all" class="ui-tabs-panel">
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php dropdown_categories(); ?>
</ul>
</div>
<div id="categories-pop" class="ui-tabs-panel">
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear">
<?php wp_popular_categories_checklist(); ?>
</ul>
</div>
</div>
</div>

View File

@ -16,11 +16,11 @@ function get_category_to_edit( $id ) {
return $category;
}
function wp_create_category($cat_name) {
function wp_create_category( $cat_name, $parent = 0 ) {
if ( $id = category_exists($cat_name) )
return $id;
return wp_insert_category( array('cat_name' => $cat_name) );
return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
}
function wp_create_categories($categories, $post_id = '') {

View File

@ -118,7 +118,7 @@ function sort_cats( $cat1, $cat2 ) {
return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
}
function get_nested_categories( $default = 0, $parent = 0 ) {
function wp_set_checked_post_categories( $default = 0 ) {
global $post_ID, $checked_categories;
if ( empty($checked_categories) ) {
@ -134,15 +134,33 @@ function get_nested_categories( $default = 0, $parent = 0 ) {
}
}
}
function get_nested_categories( $default = 0, $parent = 0 ) {
global $checked_categories;
wp_set_checked_post_categories( $default = 0 );
if ( is_object($parent) ) { // Hack: if passed a category object, will return nested cats with parent as root
$root = array(
'children' => get_nested_categories( $default, $parent->term_id ),
'cat_ID' => $parent->term_id,
'checked' => isset($parent->_is_checked) && $parent->_is_checked,
'cat_name' => get_the_category_by_ID( $parent->term_id )
);
$result = array( $parent->term_id => $root );
} else {
$parent = (int) $parent;
$cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
$result = array ();
$result = array();
if ( is_array( $cats ) ) {
foreach ( $cats as $cat) {
$result[$cat]['children'] = get_nested_categories( $default, $cat);
foreach ( $cats as $cat ) {
$result[$cat]['children'] = get_nested_categories( $default, $cat );
$result[$cat]['cat_ID'] = $cat;
$result[$cat]['checked'] = in_array( $cat, $checked_categories );
$result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
$result[$cat]['cat_name'] = get_the_category_by_ID( $cat );
}
}
}
@ -165,8 +183,31 @@ function write_nested_categories( $categories ) {
}
}
function dropdown_categories( $default = 0 ) {
write_nested_categories( get_nested_categories( $default) );
function dropdown_categories( $default = 0, $parent = 0 ) {
write_nested_categories( get_nested_categories( $default, $parent ) );
}
function wp_popular_categories_checklist( $default = 0, $number = 10 ) {
global $checked_categories;
wp_set_checked_post_categories( $default );
$categories = get_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) );
foreach ( (array) $categories as $category ) {
$id = "popular-category-$category->term_id";
$checked = in_array( $category->term_id, $checked_categories ) ? ' checked="checked"' : '';
?>
<li id="<?php echo $id; ?>">
<label class="selectit" for="in-<?php echo $id; ?>">
<input id="in-<?php echo $id; ?>" type="checkbox" name="post_category[]" value="<?php echo (int) $category->term_id; ?>"<?php echo $checked; ?> />
<?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
</label>
</li>
<?php
}
}
function dropdown_link_categories( $default = 0 ) {

View File

@ -90,4 +90,29 @@ addLoadEvent( function() {
// postboxes
add_postbox_toggles();
// category tabs
var categoryTabs =jQuery('#category-tabs').tabs();
// Ajax Cat
var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ) } );
jQuery('#category-add-sumbit').click( function() { newCat.focus(); } );
var catAddAfter = function( r, s ) {
jQuery(s.what + ' response_data', r).each( function() {
var t = jQuery(jQuery(this).text());
var o = jQuery( '<option value="' + parseInt( t.find(':input').val(), 10 ) + '"></option>' );
o.text( jQuery.trim( t.text() ) );
jQuery('#newcat_parent').prepend( o );
} );
};
jQuery('#categorychecklist').wpList( {
alt: '',
response: 'category-ajax-response',
addAfter: catAddAfter
} );
jQuery('#category-add-toggle').click( function() {
jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
categoryTabs.tabsClick( 1 );
return false;
} );
});

View File

@ -687,27 +687,6 @@ set display:none; */
height: 22px;
}
#categorydiv ul {
list-style: none;
padding: 0;
margin-left: 10px;
}
#categorychecklist {
height: 12em;
overflow: auto;
margin-top: 8px;
}
#categorychecklist li {
margin: 0;
padding: 0;
}
#ajaxcat input {
border: 1px solid #ccc;
}
#your-profile #rich_editing {
border: none;
background: #fff;
@ -737,41 +716,12 @@ set display:none; */
font-size: 22px;
}
#newcat {
width: 120px;
margin-right: 5px;
}
input #catadd {
background: #a4a4a4;
border-bottom: 1px solid #898989;
border-left: 1px solid #bcbcbc;
border-right: 1px solid #898989;
border-top: 1px solid #bcbcbc;
color: #fff;
font-size: 10px;
padding: 0;
margin: 0;
font-weight: bold;
height: 20px;
margin-bottom: 2px;
text-align: center;
width: 37px;
}
#howto {
font-size: 11px;
margin: 0 5px;
display: block;
}
#jaxcat {
margin: 0;
padding: 0;
}
#ajax-response.alignleft {
margin-left: 2em;
}
@ -1279,3 +1229,58 @@ a.view-comment-post-link {
background-image:url(images/toggle-arrow.gif);
background-position: 4px 18px;
}
/* Categories */
#categorydiv #category-adder {
margin-left: 120px;
padding: 4px 0;
}
#category-add input, #category-add select {
width: 30%;
}
#categorydiv ul#category-tabs {
float: left;
width: 120px;
text-align: right;
/* Negative margin for the sake of those without JS: all tabs display */
margin: 0 -120px 0 0;
padding: 0;
}
ul#category-tabs li {
padding: 8px;
}
ul#category-tabs li.ui-tabs-selected {
background-color: #CEE1EF;
}
div.ui-tabs-panel {
margin: 0 0 0 120px;
padding: .5em .9em;
height: 12em;
overflow: auto;
border: 4px solid #CEE1EF;
}
#categorydiv ul {
list-style: none;
padding: 0;
margin: 0;
}
#categorydiv ul.categorychecklist ul {
margin-left: 18px;
}
ul.categorychecklist li {
margin: 0;
padding: 0;
}
/* Global classes */
.wp-hidden-children .wp-hidden-child { display: none; }
.ui-tabs-hide { display: none; }

View File

@ -0,0 +1,529 @@
/*
* Tabs 3 - New Wave Tabs
*
* Copyright (c) 2007 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*/
(function($) {
// if the UI scope is not availalable, add it
$.ui = $.ui || {};
// tabs initialization
$.fn.tabs = function(initial, options) {
if (initial && initial.constructor == Object) { // shift arguments
options = initial;
initial = null;
}
options = options || {};
initial = initial && initial.constructor == Number && --initial || 0;
return this.each(function() {
new $.ui.tabs(this, $.extend(options, { initial: initial }));
});
};
// other chainable tabs methods
$.each(['Add', 'Remove', 'Enable', 'Disable', 'Click', 'Load', 'Href'], function(i, method) {
$.fn['tabs' + method] = function() {
var args = arguments;
return this.each(function() {
var instance = $.ui.tabs.getInstance(this);
instance[method.toLowerCase()].apply(instance, args);
});
};
});
$.fn.tabsSelected = function() {
var selected = -1;
if (this[0]) {
var instance = $.ui.tabs.getInstance(this[0]),
$lis = $('li', this);
selected = $lis.index( $lis.filter('.' + instance.options.selectedClass)[0] );
}
return selected >= 0 ? ++selected : -1;
};
// tabs class
$.ui.tabs = function(el, options) {
this.source = el;
this.options = $.extend({
// basic setup
initial: 0,
event: 'click',
disabled: [],
cookie: null, // pass options object as expected by cookie plugin: { expires: 7, path: '/', domain: 'jquery.com', secure: true }
// TODO bookmarkable: $.ajaxHistory ? true : false,
unselected: false,
unselect: options.unselected ? true : false,
// Ajax
spinner: 'Loading&#8230;',
cache: false,
idPrefix: 'ui-tabs-',
ajaxOptions: {},
// animations
/*fxFade: null,
fxSlide: null,
fxShow: null,
fxHide: null,*/
fxSpeed: 'normal',
/*fxShowSpeed: null,
fxHideSpeed: null,*/
// callbacks
add: function() {},
remove: function() {},
enable: function() {},
disable: function() {},
click: function() {},
hide: function() {},
show: function() {},
load: function() {},
// templates
tabTemplate: '<li><a href="#{href}"><span>#{text}</span></a></li>',
panelTemplate: '<div></div>',
// CSS classes
navClass: 'ui-tabs-nav',
selectedClass: 'ui-tabs-selected',
unselectClass: 'ui-tabs-unselect',
disabledClass: 'ui-tabs-disabled',
panelClass: 'ui-tabs-panel',
hideClass: 'ui-tabs-hide',
loadingClass: 'ui-tabs-loading'
}, options);
this.options.event += '.ui-tabs'; // namespace event
this.options.cookie = $.cookie && $.cookie.constructor == Function && this.options.cookie;
// save instance for later
$.data(el, $.ui.tabs.INSTANCE_KEY, this);
// create tabs
this.tabify(true);
};
// static
$.ui.tabs.INSTANCE_KEY = 'ui_tabs_instance';
$.ui.tabs.getInstance = function(el) {
return $.data(el, $.ui.tabs.INSTANCE_KEY);
};
// instance methods
$.extend($.ui.tabs.prototype, {
tabId: function(a) {
return a.title ? a.title.replace(/\s/g, '_')
: this.options.idPrefix + $.data(a);
},
tabify: function(init) {
this.$lis = $('li:has(a[href])', this.source);
this.$tabs = this.$lis.map(function() { return $('a', this)[0] });
this.$panels = $([]);
var self = this, o = this.options;
this.$tabs.each(function(i, a) {
// inline tab
if (a.hash && a.hash.replace('#', '')) { // Safari 2 reports '#' for an empty hash
self.$panels = self.$panels.add(a.hash);
}
// remote tab
else if ($(a).attr('href') != '#') { // prevent loading the page itself if href is just "#"
$.data(a, 'href', a.href);
var id = self.tabId(a);
a.href = '#' + id;
self.$panels = self.$panels.add(
$('#' + id)[0] || $(o.panelTemplate).attr('id', id).addClass(o.panelClass)
.insertAfter( self.$panels[i - 1] || self.source )
);
}
// invalid tab href
else {
o.disabled.push(i + 1);
}
});
if (init) {
// attach necessary classes for styling if not present
$(this.source).hasClass(o.navClass) || $(this.source).addClass(o.navClass);
this.$panels.each(function() {
var $this = $(this);
$this.hasClass(o.panelClass) || $this.addClass(o.panelClass);
});
// disabled tabs
for (var i = 0, position; position = o.disabled[i]; i++) {
this.disable(position);
}
// Try to retrieve initial tab:
// 1. from fragment identifier in url if present
// 2. from cookie
// 3. from selected class attribute on <li>
// 4. otherwise use given initial argument
// 5. check if tab is disabled
this.$tabs.each(function(i, a) {
if (location.hash) {
if (a.hash == location.hash) {
o.initial = i;
// prevent page scroll to fragment
//if (($.browser.msie || $.browser.opera) && !o.remote) {
if ($.browser.msie || $.browser.opera) {
var $toShow = $(location.hash), toShowId = $toShow.attr('id');
$toShow.attr('id', '');
setTimeout(function() {
$toShow.attr('id', toShowId); // restore id
}, 500);
}
scrollTo(0, 0);
return false; // break
}
} else if (o.cookie) {
o.initial = parseInt($.cookie( $.ui.tabs.INSTANCE_KEY + $.data(self.source) )) || 0;
return false; // break
} else if ( self.$lis.eq(i).hasClass(o.selectedClass) ) {
o.initial = i;
return false; // break
}
});
var n = this.$lis.length;
while (this.$lis.eq(o.initial).hasClass(o.disabledClass) && n) {
o.initial = ++o.initial < this.$lis.length ? o.initial : 0;
n--;
}
if (!n) { // all tabs disabled, set option unselected to true
o.unselected = o.unselect = true;
}
// highlight selected tab
this.$panels.addClass(o.hideClass);
this.$lis.removeClass(o.selectedClass);
if (!o.unselected) {
this.$panels.eq(o.initial).show().removeClass(o.hideClass); // use show and remove class to show in any case no matter how it has been hidden before
this.$lis.eq(o.initial).addClass(o.selectedClass);
}
// load if remote tab
var href = !o.unselected && $.data(this.$tabs[o.initial], 'href');
if (href) {
this.load(o.initial + 1, href);
}
// disable click if event is configured to something else
if (!/^click/.test(o.event)) {
this.$tabs.bind('click', function(e) { e.preventDefault(); });
}
}
// setup animations
var showAnim = {}, showSpeed = o.fxShowSpeed || o.fxSpeed,
hideAnim = {}, hideSpeed = o.fxHideSpeed || o.fxSpeed;
if (o.fxSlide || o.fxFade) {
if (o.fxSlide) {
showAnim['height'] = 'show';
hideAnim['height'] = 'hide';
}
if (o.fxFade) {
showAnim['opacity'] = 'show';
hideAnim['opacity'] = 'hide';
}
} else {
if (o.fxShow) {
showAnim = o.fxShow;
} else { // use some kind of animation to prevent browser scrolling to the tab
showAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox
showSpeed = 1; // as little as 1 is sufficient
}
if (o.fxHide) {
hideAnim = o.fxHide;
} else { // use some kind of animation to prevent browser scrolling to the tab
hideAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox
hideSpeed = 1; // as little as 1 is sufficient
}
}
// reset some styles to maintain print style sheets etc.
var resetCSS = { display: '', overflow: '', height: '' };
if (!$.browser.msie) { // not in IE to prevent ClearType font issue
resetCSS['opacity'] = '';
}
// Hide a tab, animation prevents browser scrolling to fragment,
// $show is optional.
function hideTab(clicked, $hide, $show) {
$hide.animate(hideAnim, hideSpeed, function() { //
$hide.addClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc.
if ($.browser.msie && hideAnim['opacity']) {
$hide[0].style.filter = '';
}
o.hide(clicked, $hide[0], $show && $show[0] || null);
if ($show) {
showTab(clicked, $show, $hide);
}
});
}
// Show a tab, animation prevents browser scrolling to fragment,
// $hide is optional
function showTab(clicked, $show, $hide) {
if (!(o.fxSlide || o.fxFade || o.fxShow)) {
$show.css('display', 'block'); // prevent occasionally occuring flicker in Firefox cause by gap between showing and hiding the tab panels
}
$show.animate(showAnim, showSpeed, function() {
$show.removeClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc.
if ($.browser.msie && showAnim['opacity']) {
$show[0].style.filter = '';
}
o.show(clicked, $show[0], $hide && $hide[0] || null);
});
}
// switch a tab
function switchTab(clicked, $li, $hide, $show) {
/*if (o.bookmarkable && trueClick) { // add to history only if true click occured, not a triggered click
$.ajaxHistory.update(clicked.hash);
}*/
$li.addClass(o.selectedClass)
.siblings().removeClass(o.selectedClass);
hideTab(clicked, $hide, $show);
}
// attach tab event handler, unbind to avoid duplicates from former tabifying...
this.$tabs.unbind(o.event).bind(o.event, function() {
//var trueClick = e.clientX; // add to history only if true click occured, not a triggered click
var $li = $(this).parents('li:eq(0)'),
$hide = self.$panels.filter(':visible'),
$show = $(this.hash);
// If tab is already selected and not unselectable or tab disabled or click callback returns false stop here.
// Check if click handler returns false last so that it is not executed for a disabled tab!
if (($li.hasClass(o.selectedClass) && !o.unselect) || $li.hasClass(o.disabledClass)
|| o.click(this, $show[0], $hide[0]) === false) {
this.blur();
return false;
}
if (o.cookie) {
$.cookie($.ui.tabs.INSTANCE_KEY + $.data(self.source), self.$tabs.index(this), o.cookie);
}
// if tab may be closed
if (o.unselect) {
if ($li.hasClass(o.selectedClass)) {
$li.removeClass(o.selectedClass);
self.$panels.stop();
hideTab(this, $hide);
this.blur();
return false;
} else if (!$hide.length) {
self.$panels.stop();
if ($.data(this, 'href')) { // remote tab
var a = this;
self.load(self.$tabs.index(this) + 1, $.data(this, 'href'), function() {
$li.addClass(o.selectedClass).addClass(o.unselectClass);
showTab(a, $show);
});
} else {
$li.addClass(o.selectedClass).addClass(o.unselectClass);
showTab(this, $show);
}
this.blur();
return false;
}
}
// stop possibly running animations
self.$panels.stop();
// show new tab
if ($show.length) {
// prevent scrollbar scrolling to 0 and than back in IE7, happens only if bookmarking/history is enabled
/*if ($.browser.msie && o.bookmarkable) {
var showId = this.hash.replace('#', '');
$show.attr('id', '');
setTimeout(function() {
$show.attr('id', showId); // restore id
}, 0);
}*/
if ($.data(this, 'href')) { // remote tab
var a = this;
self.load(self.$tabs.index(this) + 1, $.data(this, 'href'), function() {
switchTab(a, $li, $hide, $show);
});
} else {
switchTab(this, $li, $hide, $show);
}
// Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash
/*var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0;
var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0;
setTimeout(function() {
scrollTo(scrollX, scrollY);
}, 0);*/
} else {
throw 'jQuery UI Tabs: Mismatching fragment identifier.';
}
// Prevent IE from keeping other link focussed when using the back button
// and remove dotted border from clicked link. This is controlled in modern
// browsers via CSS, also blur removes focus from address bar in Firefox
// which can become a usability and annoying problem with tabsRotate.
if ($.browser.msie) {
this.blur();
}
//return o.bookmarkable && !!trueClick; // convert trueClick == undefined to Boolean required in IE
return false;
});
},
add: function(url, text, position) {
if (url && text) {
position = position || this.$tabs.length; // append by default
var o = this.options,
$li = $(o.tabTemplate.replace(/#\{href\}/, url).replace(/#\{text\}/, text));
var id = url.indexOf('#') == 0 ? url.replace('#', '') : this.tabId( $('a:first-child', $li)[0] );
// try to find an existing element before creating a new one
var $panel = $('#' + id);
$panel = $panel.length && $panel
|| $(o.panelTemplate).attr('id', id).addClass(o.panelClass).addClass(o.hideClass);
if (position >= this.$lis.length) {
$li.appendTo(this.source);
$panel.appendTo(this.source.parentNode);
} else {
$li.insertBefore(this.$lis[position - 1]);
$panel.insertBefore(this.$panels[position - 1]);
}
this.tabify();
if (this.$tabs.length == 1) {
$li.addClass(o.selectedClass);
$panel.removeClass(o.hideClass);
var href = $.data(this.$tabs[0], 'href');
if (href) {
this.load(position + 1, href);
}
}
o.add(this.$tabs[position], this.$panels[position]); // callback
} else {
throw 'jQuery UI Tabs: Not enough arguments to add tab.';
}
},
remove: function(position) {
if (position && position.constructor == Number) {
var o = this.options, $li = this.$lis.eq(position - 1).remove(),
$panel = this.$panels.eq(position - 1).remove();
// If selected tab was removed focus tab to the right or
// tab to the left if last tab was removed.
if ($li.hasClass(o.selectedClass) && this.$tabs.length > 1) {
this.click(position + (position < this.$tabs.length ? 1 : -1));
}
this.tabify();
o.remove($li.end()[0], $panel[0]); // callback
}
},
enable: function(position) {
var o = this.options, $li = this.$lis.eq(position - 1);
$li.removeClass(o.disabledClass);
if ($.browser.safari) { // fix disappearing tab (that used opacity indicating disabling) after enabling in Safari 2...
$li.css('display', 'inline-block');
setTimeout(function() {
$li.css('display', 'block')
}, 0)
}
o.enable(this.$tabs[position - 1], this.$panels[position - 1]); // callback
},
disable: function(position) {
var o = this.options;
this.$lis.eq(position - 1).addClass(o.disabledClass);
o.disable(this.$tabs[position - 1], this.$panels[position - 1]); // callback
},
click: function(position) {
this.$tabs.eq(position - 1).trigger(this.options.event);
},
load: function(position, url, callback) {
var self = this, o = this.options,
$a = this.$tabs.eq(position - 1), a = $a[0], $span = $('span', a);
// shift arguments
if (url && url.constructor == Function) {
callback = url;
url = null;
}
// set new URL or get existing
if (url) {
$.data(a, 'href', url);
} else {
url = $.data(a, 'href');
}
// load
if (o.spinner) {
$.data(a, 'title', $span.html());
$span.html('<em>' + o.spinner + '</em>');
}
var finish = function() {
self.$tabs.filter('.' + o.loadingClass).each(function() {
$(this).removeClass(o.loadingClass);
if (o.spinner) {
$('span', this).html( $.data(this, 'title') );
}
});
self.xhr = null;
};
var ajaxOptions = $.extend(o.ajaxOptions, {
url: url,
success: function(r) {
$(a.hash).html(r);
finish();
// This callback is required because the switch has to take
// place after loading has completed.
if (callback && callback.constructor == Function) {
callback();
}
if (o.cache) {
$.removeData(a, 'href'); // if loaded once do not load them again
}
o.load(self.$tabs[position - 1], self.$panels[position - 1]); // callback
}
});
if (this.xhr) {
// terminate pending requests from other tabs and restore title
this.xhr.abort();
finish();
}
$a.addClass(o.loadingClass);
setTimeout(function() { // timeout is again required in IE, "wait" for id being restored
self.xhr = $.ajax(ajaxOptions);
}, 0);
},
href: function(position, href) {
$.data(this.$tabs.eq(position - 1)[0], 'href', href);
}
});
})(jQuery);

View File

@ -309,8 +309,7 @@ var wpList = {
if ( 'none' != s.addColor ) {
var b = e.css( 'background-color' );
if ( b == 'transparent' ) { b = ''; }
$('#' + s.element).css('background-color', s.addColor).animate( { backgroundColor: '#fff' }, 300 );
e.css('background-color', s.addColor).animate( { backgroundColor: '#fff' }, 300 );
}
list.each( function() { this.wpList.process( e ); } );
return e;
@ -321,6 +320,8 @@ var wpList = {
e = $(e);
if ( list.wpList && e.parents( '#' + list.id ).size() ) { return; }
e.find(':input').each( function() {
if ( $(this).parents('.form-no-clear').size() )
return;
var t = this.type.toLowerCase(); var tag = this.tagName.toLowerCase();
if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; }
else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; }

View File

@ -60,7 +60,7 @@ class WP_Scripts {
'delText' => __('Are you sure you want to delete this %thing%?')
) );
$this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20071101' );
$this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20080109' );
$this->localize( 'wp-lists', 'wpListL10n', array(
'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php'
) );
@ -85,6 +85,8 @@ class WP_Scripts {
$this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20');
$this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1');
$this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' );
if ( is_admin() ) {
$this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
$this->localize( 'ajaxcat', 'catL10n', array(
@ -106,7 +108,7 @@ class WP_Scripts {
$this->add( 'admin-forms', '/wp-admin/js/forms.js', array('wp-lists'), '20080108' );
$this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
$this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest'), '20080102' );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists'), '20080109' );
$this->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')),
@ -137,7 +139,7 @@ class WP_Scripts {
'saveText' => attribute_escape(__('Save &raquo;')),
'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
) );
$this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), mt_rand() );
$this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080109' );
}
}