Ticket #1605: dynamo7.diff

File dynamo7.diff, 3.8 KB (added by mdawaffe, 7 years ago)

Now with cross browser support (dynamo6 will kill you)

  • wp-admin/edit-form-ajax-cat.php

     
    1212        $new_cat_id = func_get_arg(0); 
    1313} 
    1414 
     15function get_out_now() { exit; } 
     16 
    1517add_action('edit_category', 'grab_id'); 
    1618add_action('create_category', 'grab_id'); 
     19add_action('shutdown', 'get_out_now', -1); 
    1720 
    18 $cat_name = stripslashes($_GET['ajaxnewcat']); 
     21$cat_name = rawurldecode($_GET['ajaxnewcat']); 
    1922 
    2023if ( !$category_nicename = sanitize_title($cat_name) ) 
    2124        die('0'); 
     
    2528$cat_name = $wpdb->escape($cat_name); 
    2629$cat_array = compact('cat_name', 'category_nicename'); 
    2730wp_insert_category($cat_array); 
    28 echo $new_cat_id; 
    29 ?> 
    30  No newline at end of file 
     31die($new_cat_id); 
     32?> 
  • wp-admin/admin-header.php

     
    118118        newcat.id = 'newcat'; 
    119119        newcat.size = '16'; 
    120120        newcat.setAttribute('autocomplete', 'off'); 
    121         newcat.setAttribute('onkeypress', 'return ajaxNewCatKeyPress(event);'); 
     121        newcat.onkeypress = ajaxNewCatKeyPress; 
    122122 
    123123        var newcatSub = document.createElement('input'); 
    124124        newcatSub.type = 'button'; 
    125125        newcatSub.name = 'Button'; 
    126126        newcatSub.value = '+'; 
    127         newcatSub.setAttribute('onclick', 'ajaxNewCat();'); 
     127        newcatSub.onclick = ajaxNewCat; 
    128128 
    129129        ajaxcat.appendChild(newcat); 
    130130        ajaxcat.appendChild(newcatSub); 
     
    160160 
    161161function newCatCompletion() { 
    162162        var p = getResponseElement(); 
    163         var id = ajaxCat.response; 
     163        var id = parseInt(ajaxCat.response, 10); 
    164164        if ( id == '-1' ) { 
    165165                p.innerHTML = "You don't have permission to do that."; 
    166166                return; 
     
    172172        p.parentNode.removeChild(p); 
    173173        var exists = document.getElementById('category-' + id); 
    174174        if (exists) { 
     175                var moveIt = exists.parentNode; 
     176                var container = moveIt.parentNode; 
     177                container.removeChild(moveIt); 
     178                container.insertBefore(moveIt, container.firstChild); 
     179                moveIt.id = 'new-category-' + id; 
    175180                exists.checked = 'checked'; 
    176                 exists.parentNode.setAttribute('id', 'new-category-' + id); 
    177                 var nowClass = exists.parentNode.getAttribute('class'); 
    178                 exists.parentNode.setAttribute('class', nowClass + ' fade'); 
     181                var nowClass = moveIt.className; 
     182                moveIt.className = nowClass + ' fade'; 
    179183                Fat.fade_all(); 
    180                 exists.parentNode.setAttribute('class', nowClass); 
     184                moveIt.className = nowClass; 
    181185        } else { 
    182186                var catDiv = document.getElementById('categorychecklist'); 
    183187                var newLabel = document.createElement('label'); 
    184                 catDiv.insertBefore(newLabel, catDiv.firstChild); 
    185188                newLabel.setAttribute('for', 'category-' + id); 
    186                 newLabel.setAttribute('id', 'new-category-' + id); 
    187                 newLabel.setAttribute('class', 'selectit fade'); 
     189                newLabel.id = 'new-category-' + id; 
     190                newLabel.className = 'selectit fade'; 
    188191 
    189192                var newCheck = document.createElement('input'); 
    190                 newLabel.appendChild(newCheck); 
     193                newCheck.type = 'checkbox'; 
    191194                newCheck.value = id; 
    192                 newCheck.type = 'checkbox'; 
    193                 newCheck.checked = 'checked'; 
    194195                newCheck.name = 'post_category[]'; 
    195196                newCheck.id = 'category-' + id; 
     197                newLabel.appendChild(newCheck); 
    196198 
    197199                var newLabelText = document.createTextNode(' ' + newcat.value); 
    198200                newLabel.appendChild(newLabelText); 
     201 
     202                catDiv.insertBefore(newLabel, catDiv.firstChild); 
     203                newCheck.checked = 'checked'; 
     204 
    199205                Fat.fade_all(); 
    200                 newLabel.setAttribute('class', 'selectit'); 
     206                newLabel.className = 'selectit'; 
    201207        } 
    202208        newcat.value = ''; 
    203209} 
     
    220226 
    221227function ajaxNewCat() { 
    222228        var newcat = document.getElementById('newcat'); 
    223         var catString = 'ajaxnewcat=' + newcat.value; 
     229        var catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value); 
    224230        ajaxCat.requestFile = 'edit-form-ajax-cat.php'; 
    225231        ajaxCat.method = 'GET'; 
    226232        ajaxCat.onLoading = newCatLoading;