From ded2247f37e401b6556629cb4860358c053b3d6c Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 30 Aug 2005 00:57:34 +0000 Subject: [PATCH] Better ajaxness meets buzzword index compliance and fixes #1605 git-svn-id: http://svn.automattic.com/wordpress/trunk@2819 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-header.php | 36 +++++++++++++++++++-------------- wp-admin/edit-form-ajax-cat.php | 8 ++++++-- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index 41bb5b57de..cfd6e5d3a7 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -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; diff --git a/wp-admin/edit-form-ajax-cat.php b/wp-admin/edit-form-ajax-cat.php index 03bf48caee..f51c996218 100644 --- a/wp-admin/edit-form-ajax-cat.php +++ b/wp-admin/edit-form-ajax-cat.php @@ -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); ?> \ No newline at end of file