X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9c40b4d36daed9e28e48a5fe9205c32557195a4b..96bc8e88cf39086a9e0a883b8e2c311fe82a5e97:/wp-admin/js/tags.dev.js diff --git a/wp-admin/js/tags.dev.js b/wp-admin/js/tags.dev.js index 3f1da879..045f2b26 100644 --- a/wp-admin/js/tags.dev.js +++ b/wp-admin/js/tags.dev.js @@ -1,37 +1,68 @@ jQuery(document).ready(function($) { - var options = false, addAfter, addAfter2, delBefore, delAfter; - addAfter = function( r, settings ) { - var name = $("" + $('name', r).text() + "").html(), id = $('tag', r).attr('id'); - options[options.length] = new Option(name, id); - } + $('.delete-tag').live('click', function(e){ + var t = $(this), tr = t.parents('tr'), r = true, data; + if ( 'undefined' != showNotice ) + r = showNotice.warn(); + if ( r ) { + data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag'); + $.post(ajaxurl, data, function(r){ + if ( '1' == r ) { + $('#ajax-response').empty(); + tr.fadeOut('normal', function(){ tr.remove(); }); + // Remove the term from the parent box and tag cloud + $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove(); + $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); + } else if ( '-1' == r ) { + $('#ajax-response').empty().append('

' + tagsl10n.noPerm + '

'); + tr.children().css('backgroundColor', ''); + } else { + $('#ajax-response').empty().append('

' + tagsl10n.broken + '

'); + tr.children().css('backgroundColor', ''); + } + }); + tr.children().css('backgroundColor', '#f33'); + } + return false; + }); - addAfter2 = function( x, r ) { - var t = $(r.parsed.responses[0].data); - if ( t.length == 1 ) - inlineEditTax.addEvents($(t.id)); - } + $('#submit').click(function(){ + var form = $(this).parents('form'); - delAfter = function( r, settings ) { - var id = $('tag', r).attr('id'), o; - for ( o = 0; o < options.length; o++ ) - if ( id == options[o].value ) - options[o] = null; - } + if ( !validateForm( form ) ) + return false; - delBefore = function(s) { - s.data.taxonomy = $('input[name="taxonomy"]').val(); + $.post(ajaxurl, $('#addtag').serialize(), function(r){ + $('#ajax-response').empty(); + var res = wpAjax.parseAjaxResponse(r, 'ajax-response'); + if ( ! res ) + return; - if ( 'undefined' != showNotice ) - return showNotice.warn() ? s : false; + var parent = form.find('select#parent').val(); + + if ( parent > 0 && $('#tag-' + parent ).length > 0 ) // If the parent exists on this page, insert it below. Else insert it at the top of the list. + $('.tags #tag-' + parent).after( res.responses[0].supplemental['noparents'] ); // As the parent exists, Insert the version with - - - prefixed + else + $('.tags').prepend( res.responses[0].supplemental['parents'] ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm + + $('.tags .no-items').remove(); + + if ( form.find('select#parent') ) { + // Parents field exists, Add new term to the list. + var term = res.responses[1].supplemental; + + // Create an indent for the Parent field + var indent = ''; + for ( var i = 0; i < res.responses[1].position; i++ ) + indent += '   '; + + form.find('select#parent option:selected').after(''); + } - return s; - } + $('input[type="text"]:visible, textarea:visible', form).val(''); + }); - if ( options ) - $('#the-list').wpList( { addAfter: addAfter, delBefore: delBefore, delAfter: delAfter } ); - else - $('#the-list').wpList({ addAfter: addAfter2, delBefore: delBefore }); + return false; + }); - $('.delete a[class^="delete"]').click(function(){return false;}); -}); \ No newline at end of file +});