Changeset 41311
- Timestamp:
- 08/24/2017 05:51:19 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/tags.js
r40655 r41311 1 1 /* global ajaxurl, wpAjax, tagsl10n, showNotice, validateForm */ 2 /** 3 * Contains logic for both adding and deleting tags. For deleting tags it makes a request 4 * to the server to delete the tag. For adding tags it makes a request to the server to 5 * add the tag. 6 * 7 * @summary Contains logic for deleting and adding tags 8 */ 2 9 3 10 jQuery(document).ready(function($) { 4 11 12 /** 13 * @summary Adds an event handler to the delete term link on the term overview page. 14 * 15 * Adds an event handler to the delete term link on the term overview page. 16 * Cancels default event handling and event bubbling. 17 * 18 * @since 2.8.0 19 * 20 * @returns boolean Always returns false to cancel the default event handling. 21 */ 5 22 $( '#the-list' ).on( 'click', '.delete-tag', function() { 6 23 var t = $(this), tr = t.parents('tr'), r = true, data; 24 7 25 if ( 'undefined' != showNotice ) 8 26 r = showNotice.warn(); 27 9 28 if ( r ) { 10 29 data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag'); 30 31 /** 32 * @summary Makes a request to the server to delete the term that 33 * corresponds to the delete term button. 34 * 35 * @param {string} r The response from the server. 36 * 37 * @returns {void} 38 */ 11 39 $.post(ajaxurl, data, function(r){ 12 40 if ( '1' == r ) { 13 41 $('#ajax-response').empty(); 14 42 tr.fadeOut('normal', function(){ tr.remove(); }); 15 // Remove the term from the parent box and tag cloud 43 44 /** 45 * @summary Remove the term from the parent box and the tag cloud 46 * 47 * `data.match(/tag_ID=(\d+)/)[1]` matches the term id from the data variable. 48 * This term id is then used to select the relevant HTML elements: 49 * The parent box and the tag cloud. 50 */ 16 51 $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove(); 17 52 $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); 53 18 54 } else if ( '-1' == r ) { 19 55 $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>'); 20 56 tr.children().css('backgroundColor', ''); 57 21 58 } else { 22 59 $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.broken + '</p></div>'); … … 24 61 } 25 62 }); 63 26 64 tr.children().css('backgroundColor', '#f33'); 27 65 } 66 28 67 return false; 29 68 }); 30 69 70 /** 71 * Adds a deletion confirmation when removing a tag. 72 * 73 * @since 4.8.0 74 * 75 * @returns {void} 76 */ 31 77 $( '#edittag' ).on( 'click', '.delete', function( e ) { 32 78 if ( 'undefined' === typeof showNotice ) { … … 34 80 } 35 81 82 // Confirms the deletion, a negative response means the deletion must not be executed. 36 83 var response = showNotice.warn(); 37 84 if ( ! response ) { … … 40 87 }); 41 88 89 /** 90 * @summary Adds an event handler tot he form submit on the term overview page. 91 * 92 * Cancels default event handling and event bubbling. 93 * 94 * @since 2.8.0 95 * 96 * @returns boolean Always returns false to cancel the default event handling. 97 */ 42 98 $('#submit').click(function(){ 43 99 var form = $(this).parents('form'); … … 46 102 return false; 47 103 104 /** 105 * Does a request to the server to add a new term to the database 106 * 107 * @param {string} r The response from the server. 108 * 109 * @returns {void} 110 */ 48 111 $.post(ajaxurl, $('#addtag').serialize(), function(r){ 49 112 var res, parent, term, indent, i;
Note: See TracChangeset
for help on using the changeset viewer.