Slicker category adding, fixes #1882
git-svn-id: https://develop.svn.wordpress.org/trunk@3135 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9e6d93b6d6
commit
7711e1ba8f
|
@ -110,6 +110,32 @@ tinyMCE.init({
|
|||
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
|
||||
|
||||
<?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">
|
||||
var ajaxCat = new sack();
|
||||
var newcat;
|
||||
|
@ -129,12 +155,18 @@ function newCatAddIn() {
|
|||
var newcatSub = document.createElement('input');
|
||||
newcatSub.type = 'button';
|
||||
newcatSub.name = 'Button';
|
||||
newcatSub.value = '+';
|
||||
newcat.onkeypress = ajaxNewCatKeyPress;
|
||||
newcatSub.id = 'catadd';
|
||||
newcatSub.value = '<?php _e('Add'); ?>';
|
||||
newcatSub.onclick = ajaxNewCat;
|
||||
|
||||
ajaxcat.appendChild(newcat);
|
||||
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);
|
||||
|
@ -143,7 +175,7 @@ function getResponseElement() {
|
|||
var p = document.getElementById('ajaxcatresponse');
|
||||
if (!p) {
|
||||
p = document.createElement('p');
|
||||
document.getElementById('categorydiv').appendChild(p);
|
||||
document.getElementById('jaxcat').appendChild(p);
|
||||
p.id = 'ajaxcatresponse';
|
||||
}
|
||||
return p;
|
||||
|
@ -161,12 +193,22 @@ function newCatLoaded() {
|
|||
|
||||
function newCatInteractive() {
|
||||
var p = getResponseElement();
|
||||
p.innerHTML = 'Processing Data...';
|
||||
p.innerHTML = 'Processing Request...';
|
||||
}
|
||||
|
||||
function newCatCompletion() {
|
||||
var p = getResponseElement();
|
||||
var id = parseInt(ajaxCat.response, 10);
|
||||
// alert(ajaxCat.response);
|
||||
var id = 0;
|
||||
var ids = new Array();
|
||||
var names = new Array();
|
||||
|
||||
ids = myPload( ajaxCat.response );
|
||||
names = myPload( newcat.value );
|
||||
|
||||
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;
|
||||
|
@ -175,8 +217,9 @@ function newCatCompletion() {
|
|||
p.innerHTML = "That category name is invalid. Try something else.";
|
||||
return;
|
||||
}
|
||||
p.parentNode.removeChild(p);
|
||||
|
||||
var exists = document.getElementById('category-' + id);
|
||||
|
||||
if (exists) {
|
||||
var moveIt = exists.parentNode;
|
||||
var container = moveIt.parentNode;
|
||||
|
@ -202,7 +245,7 @@ function newCatCompletion() {
|
|||
newCheck.id = 'category-' + id;
|
||||
newLabel.appendChild(newCheck);
|
||||
|
||||
var newLabelText = document.createTextNode(' ' + newcat.value);
|
||||
var newLabelText = document.createTextNode(' ' + names[i]);
|
||||
newLabel.appendChild(newLabelText);
|
||||
|
||||
catDiv.insertBefore(newLabel, catDiv.firstChild);
|
||||
|
@ -212,6 +255,11 @@ function newCatCompletion() {
|
|||
newLabel.className = 'selectit';
|
||||
}
|
||||
newcat.value = '';
|
||||
}
|
||||
p.parentNode.removeChild(p);
|
||||
// var id = parseInt(ajaxCat.response, 10);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function ajaxNewCatKeyPress(e) {
|
||||
|
@ -232,7 +280,10 @@ function ajaxNewCatKeyPress(e) {
|
|||
|
||||
function ajaxNewCat() {
|
||||
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.method = 'GET';
|
||||
ajaxCat.onLoading = newCatLoading;
|
||||
|
@ -241,6 +292,30 @@ function ajaxNewCat() {
|
|||
ajaxCat.onCompletion = newCatCompletion;
|
||||
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>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -90,7 +90,9 @@ addLoadEvent(focusit);
|
|||
|
||||
<fieldset id="categorydiv" class="dbx-box">
|
||||
<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 class="dbx-box">
|
||||
|
|
|
@ -12,13 +12,26 @@ function get_out_now() { exit; }
|
|||
|
||||
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) )
|
||||
die('0');
|
||||
if ( $already = category_exists($cat_name) )
|
||||
die((string) $already);
|
||||
foreach ($names as $cat_name) {
|
||||
$cat_name = trim( $cat_name );
|
||||
|
||||
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[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'][10] = array(__('Write Page'), 'edit_pages', 'page-new.php');
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ textarea, input, select {
|
|||
.available-theme a.screenshot {
|
||||
width: 250px;
|
||||
height: 200px;
|
||||
display: inline-block;
|
||||
display: block;
|
||||
margin: auto;
|
||||
background: #f1f1f1;
|
||||
border: 1px solid #ccc;
|
||||
|
@ -817,7 +817,7 @@ a.dbx-toggle, a.dbx-toggle:visited {
|
|||
position: absolute;
|
||||
top: 10px;
|
||||
right: 14px;
|
||||
background-repeat: none;
|
||||
background-repeat: no-repeat;
|
||||
border-bottom: 0;
|
||||
background-position: 0 9px;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue