Better ajaxness meets buzzword index compliance and fixes #1605

git-svn-id: https://develop.svn.wordpress.org/trunk@2819 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2005-08-30 00:57:34 +00:00
parent 081527cd3e
commit 94e8148c6c
2 changed files with 27 additions and 17 deletions

View File

@ -119,13 +119,13 @@ function newCatAddIn() {
newcat.id = 'newcat';
newcat.size = '16';
newcat.setAttribute('autocomplete', 'off');
newcat.setAttribute('onkeypress', 'return ajaxNewCatKeyPress(event);');
newcat.onkeypress = ajaxNewCatKeyPress;
var newcatSub = document.createElement('input');
newcatSub.type = 'button';
newcatSub.name = 'Button';
newcatSub.value = '+';
newcatSub.setAttribute('onclick', 'ajaxNewCat();');
newcat.onkeypress = ajaxNewCatKeyPress;
ajaxcat.appendChild(newcat);
ajaxcat.appendChild(newcatSub);
@ -161,7 +161,7 @@ function newCatInteractive() {
function newCatCompletion() {
var p = getResponseElement();
var id = ajaxCat.response;
var id = parseInt(ajaxCat.response, 10);
if ( id == '-1' ) {
p.innerHTML = "You don't have permission to do that.";
return;
@ -173,32 +173,38 @@ function newCatCompletion() {
p.parentNode.removeChild(p);
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';
exists.parentNode.setAttribute('id', 'new-category-' + id);
var nowClass = exists.parentNode.getAttribute('class');
exists.parentNode.setAttribute('class', nowClass + ' fade');
var nowClass = moveIt.className;
moveIt.className = nowClass + ' fade';
Fat.fade_all();
exists.parentNode.setAttribute('class', nowClass);
moveIt.className = nowClass;
} else {
var catDiv = document.getElementById('categorychecklist');
var newLabel = document.createElement('label');
catDiv.insertBefore(newLabel, catDiv.firstChild);
newLabel.setAttribute('for', 'category-' + id);
newLabel.setAttribute('id', 'new-category-' + id);
newLabel.setAttribute('class', 'selectit fade');
newLabel.id = 'new-category-' + id;
newLabel.className = 'selectit fade';
var newCheck = document.createElement('input');
newLabel.appendChild(newCheck);
newCheck.value = id;
newCheck.type = 'checkbox';
newCheck.checked = 'checked';
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.setAttribute('class', 'selectit');
newLabel.className = 'selectit';
}
newcat.value = '';
}
@ -221,7 +227,7 @@ function ajaxNewCatKeyPress(e) {
function ajaxNewCat() {
var newcat = document.getElementById('newcat');
var catString = 'ajaxnewcat=' + newcat.value;
var catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
ajaxCat.requestFile = 'edit-form-ajax-cat.php';
ajaxCat.method = 'GET';
ajaxCat.onLoading = newCatLoading;

View File

@ -12,10 +12,14 @@ function grab_id() {
$new_cat_id = func_get_arg(0);
}
function get_out_now() { exit; }
add_action('edit_category', 'grab_id');
add_action('create_category', 'grab_id');
add_action('shutdown', 'get_out_now', -1);
$cat_name = stripslashes($_GET['ajaxnewcat']);
$cat_name = rawurldecode($_GET['ajaxnewcat']);
if ( !$category_nicename = sanitize_title($cat_name) )
die('0');
@ -25,5 +29,5 @@ if ( $already = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE categ
$cat_name = $wpdb->escape($cat_name);
$cat_array = compact('cat_name', 'category_nicename');
wp_insert_category($cat_array);
echo $new_cat_id;
die($new_cat_id);
?>