Slicker category adding, fixes #1882
git-svn-id: http://svn.automattic.com/wordpress/trunk@3135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c9685b895a
commit
20660c0ffb
|
@ -110,6 +110,32 @@ tinyMCE.init({
|
||||||
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
|
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
|
||||||
|
|
||||||
<?php if ( current_user_can('manage_categories') ) : ?>
|
<?php if ( current_user_can('manage_categories') ) : ?>
|
||||||
|
<style type="text/css">
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var ajaxCat = new sack();
|
var ajaxCat = new sack();
|
||||||
var newcat;
|
var newcat;
|
||||||
|
@ -129,12 +155,18 @@ function newCatAddIn() {
|
||||||
var newcatSub = document.createElement('input');
|
var newcatSub = document.createElement('input');
|
||||||
newcatSub.type = 'button';
|
newcatSub.type = 'button';
|
||||||
newcatSub.name = 'Button';
|
newcatSub.name = 'Button';
|
||||||
newcatSub.value = '+';
|
newcatSub.id = 'catadd';
|
||||||
newcat.onkeypress = ajaxNewCatKeyPress;
|
newcatSub.value = '<?php _e('Add'); ?>';
|
||||||
|
newcatSub.onclick = ajaxNewCat;
|
||||||
|
|
||||||
ajaxcat.appendChild(newcat);
|
ajaxcat.appendChild(newcat);
|
||||||
ajaxcat.appendChild(newcatSub);
|
ajaxcat.appendChild(newcatSub);
|
||||||
document.getElementById('categorychecklist').parentNode.appendChild(ajaxcat);
|
document.getElementById('jaxcat').appendChild(ajaxcat);
|
||||||
|
|
||||||
|
howto = document.createElement('span');
|
||||||
|
howto.innerHTML = '<?php _e('Separate multiple categories with commas.'); ?>';
|
||||||
|
howto.id = 'howto';
|
||||||
|
ajaxcat.appendChild(howto);
|
||||||
}
|
}
|
||||||
|
|
||||||
addLoadEvent(newCatAddIn);
|
addLoadEvent(newCatAddIn);
|
||||||
|
@ -143,7 +175,7 @@ function getResponseElement() {
|
||||||
var p = document.getElementById('ajaxcatresponse');
|
var p = document.getElementById('ajaxcatresponse');
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = document.createElement('p');
|
p = document.createElement('p');
|
||||||
document.getElementById('categorydiv').appendChild(p);
|
document.getElementById('jaxcat').appendChild(p);
|
||||||
p.id = 'ajaxcatresponse';
|
p.id = 'ajaxcatresponse';
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
@ -161,57 +193,73 @@ function newCatLoaded() {
|
||||||
|
|
||||||
function newCatInteractive() {
|
function newCatInteractive() {
|
||||||
var p = getResponseElement();
|
var p = getResponseElement();
|
||||||
p.innerHTML = 'Processing Data...';
|
p.innerHTML = 'Processing Request...';
|
||||||
}
|
}
|
||||||
|
|
||||||
function newCatCompletion() {
|
function newCatCompletion() {
|
||||||
var p = getResponseElement();
|
var p = getResponseElement();
|
||||||
var id = parseInt(ajaxCat.response, 10);
|
// alert(ajaxCat.response);
|
||||||
if ( id == '-1' ) {
|
var id = 0;
|
||||||
p.innerHTML = "You don't have permission to do that.";
|
var ids = new Array();
|
||||||
return;
|
var names = new Array();
|
||||||
}
|
|
||||||
if ( id == '0' ) {
|
ids = myPload( ajaxCat.response );
|
||||||
p.innerHTML = "That category name is invalid. Try something else.";
|
names = myPload( newcat.value );
|
||||||
return;
|
|
||||||
|
for ( i = 0; i < ids.length; i++ ) {
|
||||||
|
id = ids[i];
|
||||||
|
// alert(id);
|
||||||
|
if ( id == '-1' ) {
|
||||||
|
p.innerHTML = "You don't have permission to do that.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( id == '0' ) {
|
||||||
|
p.innerHTML = "That category name is invalid. Try something else.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = document.getElementById('category-' + id);
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
var moveIt = exists.parentNode;
|
||||||
|
var container = moveIt.parentNode;
|
||||||
|
container.removeChild(moveIt);
|
||||||
|
container.insertBefore(moveIt, container.firstChild);
|
||||||
|
moveIt.id = 'new-category-' + id;
|
||||||
|
exists.checked = 'checked';
|
||||||
|
var nowClass = moveIt.className;
|
||||||
|
moveIt.className = nowClass + ' fade';
|
||||||
|
Fat.fade_all();
|
||||||
|
moveIt.className = nowClass;
|
||||||
|
} else {
|
||||||
|
var catDiv = document.getElementById('categorychecklist');
|
||||||
|
var newLabel = document.createElement('label');
|
||||||
|
newLabel.setAttribute('for', 'category-' + id);
|
||||||
|
newLabel.id = 'new-category-' + id;
|
||||||
|
newLabel.className = 'selectit fade';
|
||||||
|
|
||||||
|
var newCheck = document.createElement('input');
|
||||||
|
newCheck.type = 'checkbox';
|
||||||
|
newCheck.value = id;
|
||||||
|
newCheck.name = 'post_category[]';
|
||||||
|
newCheck.id = 'category-' + id;
|
||||||
|
newLabel.appendChild(newCheck);
|
||||||
|
|
||||||
|
var newLabelText = document.createTextNode(' ' + names[i]);
|
||||||
|
newLabel.appendChild(newLabelText);
|
||||||
|
|
||||||
|
catDiv.insertBefore(newLabel, catDiv.firstChild);
|
||||||
|
newCheck.checked = 'checked';
|
||||||
|
|
||||||
|
Fat.fade_all();
|
||||||
|
newLabel.className = 'selectit';
|
||||||
|
}
|
||||||
|
newcat.value = '';
|
||||||
}
|
}
|
||||||
p.parentNode.removeChild(p);
|
p.parentNode.removeChild(p);
|
||||||
var exists = document.getElementById('category-' + id);
|
// var id = parseInt(ajaxCat.response, 10);
|
||||||
if (exists) {
|
|
||||||
var moveIt = exists.parentNode;
|
|
||||||
var container = moveIt.parentNode;
|
|
||||||
container.removeChild(moveIt);
|
|
||||||
container.insertBefore(moveIt, container.firstChild);
|
|
||||||
moveIt.id = 'new-category-' + id;
|
|
||||||
exists.checked = 'checked';
|
|
||||||
var nowClass = moveIt.className;
|
|
||||||
moveIt.className = nowClass + ' fade';
|
|
||||||
Fat.fade_all();
|
|
||||||
moveIt.className = nowClass;
|
|
||||||
} else {
|
|
||||||
var catDiv = document.getElementById('categorychecklist');
|
|
||||||
var newLabel = document.createElement('label');
|
|
||||||
newLabel.setAttribute('for', 'category-' + id);
|
|
||||||
newLabel.id = 'new-category-' + id;
|
|
||||||
newLabel.className = 'selectit fade';
|
|
||||||
|
|
||||||
var newCheck = document.createElement('input');
|
|
||||||
newCheck.type = 'checkbox';
|
|
||||||
newCheck.value = id;
|
|
||||||
newCheck.name = 'post_category[]';
|
|
||||||
newCheck.id = 'category-' + id;
|
|
||||||
newLabel.appendChild(newCheck);
|
|
||||||
|
|
||||||
var newLabelText = document.createTextNode(' ' + newcat.value);
|
|
||||||
newLabel.appendChild(newLabelText);
|
|
||||||
|
|
||||||
catDiv.insertBefore(newLabel, catDiv.firstChild);
|
|
||||||
newCheck.checked = 'checked';
|
|
||||||
|
|
||||||
Fat.fade_all();
|
|
||||||
newLabel.className = 'selectit';
|
|
||||||
}
|
|
||||||
newcat.value = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ajaxNewCatKeyPress(e) {
|
function ajaxNewCatKeyPress(e) {
|
||||||
|
@ -232,7 +280,10 @@ function ajaxNewCatKeyPress(e) {
|
||||||
|
|
||||||
function ajaxNewCat() {
|
function ajaxNewCat() {
|
||||||
var newcat = document.getElementById('newcat');
|
var newcat = document.getElementById('newcat');
|
||||||
var catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
|
var split_cats = new Array(1);
|
||||||
|
var catString = '';
|
||||||
|
|
||||||
|
catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
|
||||||
ajaxCat.requestFile = 'edit-form-ajax-cat.php';
|
ajaxCat.requestFile = 'edit-form-ajax-cat.php';
|
||||||
ajaxCat.method = 'GET';
|
ajaxCat.method = 'GET';
|
||||||
ajaxCat.onLoading = newCatLoading;
|
ajaxCat.onLoading = newCatLoading;
|
||||||
|
@ -241,6 +292,30 @@ function ajaxNewCat() {
|
||||||
ajaxCat.onCompletion = newCatCompletion;
|
ajaxCat.onCompletion = newCatCompletion;
|
||||||
ajaxCat.runAJAX(catString);
|
ajaxCat.runAJAX(catString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function myPload( str ) {
|
||||||
|
var fixedExplode = new Array();
|
||||||
|
var comma = new String(',');
|
||||||
|
var count = 0;
|
||||||
|
var currentElement = '';
|
||||||
|
|
||||||
|
for( x=0; x < str.length; x++) {
|
||||||
|
andy = str.charAt(x);
|
||||||
|
if ( comma.indexOf(andy) != -1 ) {
|
||||||
|
fixedExplode[count] = currentElement;
|
||||||
|
currentElement = "";
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
if ( ' ' != andy )
|
||||||
|
currentElement += andy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( currentElement != "" )
|
||||||
|
fixedExplode[count] = currentElement;
|
||||||
|
return fixedExplode;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,9 @@ addLoadEvent(focusit);
|
||||||
|
|
||||||
<fieldset id="categorydiv" class="dbx-box">
|
<fieldset id="categorydiv" class="dbx-box">
|
||||||
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
|
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
|
||||||
<div class="dbx-content"><div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
|
<div class="dbx-content">
|
||||||
|
<p id="jaxcat"></p>
|
||||||
|
<div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset class="dbx-box">
|
<fieldset class="dbx-box">
|
||||||
|
|
|
@ -12,13 +12,26 @@ function get_out_now() { exit; }
|
||||||
|
|
||||||
add_action('shutdown', 'get_out_now', -1);
|
add_action('shutdown', 'get_out_now', -1);
|
||||||
|
|
||||||
$cat_name = rawurldecode($_GET['ajaxnewcat']);
|
$names = explode(',', rawurldecode($_GET['ajaxnewcat']) );
|
||||||
|
$ids = array();
|
||||||
|
|
||||||
if ( !$category_nicename = sanitize_title($cat_name) )
|
foreach ($names as $cat_name) {
|
||||||
die('0');
|
$cat_name = trim( $cat_name );
|
||||||
if ( $already = category_exists($cat_name) )
|
|
||||||
die((string) $already);
|
if ( !$category_nicename = sanitize_title($cat_name) )
|
||||||
|
continue;
|
||||||
|
if ( $already = category_exists($cat_name) ) {
|
||||||
|
$ids[] = (string) $already;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_cat_id = wp_create_category($cat_name);
|
||||||
|
|
||||||
|
$ids[] = (string) $new_cat_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = join(',', $ids);
|
||||||
|
|
||||||
|
die( (string) $return );
|
||||||
|
|
||||||
$new_cat_id = wp_create_category($cat_name);
|
|
||||||
die((string) $new_cat_id);
|
|
||||||
?>
|
?>
|
|
@ -17,9 +17,6 @@ else
|
||||||
$menu[40] = array(__('Options'), 'read', 'options-general.php');
|
$menu[40] = array(__('Options'), 'read', 'options-general.php');
|
||||||
$menu[45] = array(__('Import'), 'import', 'import.php');
|
$menu[45] = array(__('Import'), 'import', 'import.php');
|
||||||
|
|
||||||
if ( get_option('use_fileupload') )
|
|
||||||
$menu[50] = array(__('Upload'), 'upload_files', 'upload.php');
|
|
||||||
|
|
||||||
$submenu['post.php'][5] = array(__('Write Post'), 'edit_posts', 'post.php');
|
$submenu['post.php'][5] = array(__('Write Post'), 'edit_posts', 'post.php');
|
||||||
$submenu['post.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php');
|
$submenu['post.php'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php');
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ textarea, input, select {
|
||||||
.available-theme a.screenshot {
|
.available-theme a.screenshot {
|
||||||
width: 250px;
|
width: 250px;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
display: inline-block;
|
display: block;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
background: #f1f1f1;
|
background: #f1f1f1;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
|
@ -817,7 +817,7 @@ a.dbx-toggle, a.dbx-toggle:visited {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 14px;
|
right: 14px;
|
||||||
background-repeat: none;
|
background-repeat: no-repeat;
|
||||||
border-bottom: 0;
|
border-bottom: 0;
|
||||||
background-position: 0 9px;
|
background-position: 0 9px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue