X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/699231ae09f7057a4d0000cdf32e50a3df6a04ca..784f914b1e4b1c62d6657e86397c2e83bcee4295:/wp-admin/js/tags.js diff --git a/wp-admin/js/tags.js b/wp-admin/js/tags.js index 8431c835..333a2eb5 100644 --- a/wp-admin/js/tags.js +++ b/wp-admin/js/tags.js @@ -1 +1,72 @@ -jQuery(document).ready(function(a){a(".delete-tag").live("click",function(g){var b=a(this),f=b.parents("tr"),c=true,d;if("undefined"!=showNotice){c=showNotice.warn()}if(c){d=b.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag");a.post(ajaxurl,d,function(e){if("1"==e){a("#ajax-response").empty();f.fadeOut("normal",function(){f.remove()});a("select#parent option[value="+d.match(/tag_ID=(\d+)/)[1]+"]").remove();a("a.tag-link-"+d.match(/tag_ID=(\d+)/)[1]).remove()}else{if("-1"==e){a("#ajax-response").empty().append('

'+tagsl10n.noPerm+"

");f.children().css("backgroundColor","")}else{a("#ajax-response").empty().append('

'+tagsl10n.broken+"

");f.children().css("backgroundColor","")}}});f.children().css("backgroundColor","#f33")}return false});a("#submit").click(function(){var b=a(this).parents("form");if(!validateForm(b)){return false}a.post(ajaxurl,a("#addtag").serialize(),function(h){a("#ajax-response").empty();var f=wpAjax.parseAjaxResponse(h,"ajax-response");if(!f){return}var g=b.find("select#parent").val();if(g>0&&a("#tag-"+g).length>0){a("#the-list #tag-"+g).after(f.responses[0].supplemental.noparents)}else{a("#the-list").prepend(f.responses[0].supplemental.parents)}if(b.find("select#parent")){var e=f.responses[1].supplemental;var c="";for(var d=0;d'+c+e.name+"")}a('input[type="text"]:visible, textarea:visible',b).val("")});return false})}); \ No newline at end of file +/* global ajaxurl, wpAjax, tagsl10n, showNotice, validateForm */ + +jQuery(document).ready(function($) { + + $( '#the-list' ).on( 'click', '.delete-tag', function() { + 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; + }); + + $('#submit').click(function(){ + var form = $(this).parents('form'); + + if ( ! validateForm( form ) ) + return false; + + $.post(ajaxurl, $('#addtag').serialize(), function(r){ + var res, parent, term, indent, i; + + $('#ajax-response').empty(); + res = wpAjax.parseAjaxResponse( r, 'ajax-response' ); + if ( ! res || res.errors ) + return; + + 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. + term = res.responses[1].supplemental; + + // Create an indent for the Parent field + indent = ''; + for ( i = 0; i < res.responses[1].position; i++ ) + indent += '   '; + + form.find( 'select#parent option:selected' ).after( '' ); + } + + $('input[type="text"]:visible, textarea:visible', form).val(''); + }); + + return false; + }); + +});