5 | | $( '#the-list' ).on( 'click', '.delete-tag', function() { |
6 | | var t = $(this), tr = t.parents('tr'), r = true, data; |
7 | | if ( 'undefined' != showNotice ) |
8 | | r = showNotice.warn(); |
9 | | if ( r ) { |
10 | | data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag'); |
11 | | $.post(ajaxurl, data, function(r){ |
12 | | if ( '1' == r ) { |
13 | | $('#ajax-response').empty(); |
14 | | tr.fadeOut('normal', function(){ tr.remove(); }); |
15 | | // Remove the term from the parent box and tag cloud |
16 | | $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove(); |
17 | | $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); |
18 | | } else if ( '-1' == r ) { |
19 | | $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>'); |
20 | | tr.children().css('backgroundColor', ''); |
21 | | } else { |
22 | | $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.broken + '</p></div>'); |
23 | | tr.children().css('backgroundColor', ''); |
24 | | } |
25 | | }); |
26 | | tr.children().css('backgroundColor', '#f33'); |
27 | | } |
28 | | return false; |
29 | | }); |
30 | | |
31 | | $('#submit').click(function(){ |
32 | | var form = $(this).parents('form'); |
33 | | |
34 | | if ( ! validateForm( form ) ) |
35 | | return false; |
36 | | |
37 | | $.post(ajaxurl, $('#addtag').serialize(), function(r){ |
38 | | var res, parent, term, indent, i; |
39 | | |
40 | | $('#ajax-response').empty(); |
41 | | res = wpAjax.parseAjaxResponse( r, 'ajax-response' ); |
42 | | if ( ! res || res.errors ) |
43 | | return; |
44 | | |
45 | | parent = form.find( 'select#parent' ).val(); |
46 | | |
47 | | 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. |
48 | | $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); // As the parent exists, Insert the version with - - - prefixed |
49 | | else |
50 | | $( '.tags' ).prepend( res.responses[0].supplemental.parents ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm |
51 | | |
52 | | $('.tags .no-items').remove(); |
53 | | |
54 | | if ( form.find('select#parent') ) { |
55 | | // Parents field exists, Add new term to the list. |
56 | | term = res.responses[1].supplemental; |
57 | | |
58 | | // Create an indent for the Parent field |
59 | | indent = ''; |
60 | | for ( i = 0; i < res.responses[1].position; i++ ) |
61 | | indent += ' '; |
62 | | |
63 | | form.find( 'select#parent option:selected' ).after( '<option value="' + term.term_id + '">' + indent + term.name + '</option>' ); |
64 | | } |
65 | | |
66 | | $('input[type="text"]:visible, textarea:visible', form).val(''); |
67 | | }); |
68 | | |
69 | | return false; |
70 | | }); |
71 | | |
72 | | }); |
| 5 | var the_list = $("#the-list"); |
| 6 | |
| 7 | $(window).on( 'wp-window-resized', function(){ |
| 8 | toggleColChange(); |
| 9 | }); |
| 10 | toggleColChange(); |
| 11 | |
| 12 | function toggleColChange(){ |
| 13 | if( $(".column-description", the_list).is(":visible") ){ |
| 14 | $(".colspanchange", the_list).attr("colspan", 5); |
| 15 | }else{ |
| 16 | $(".colspanchange", the_list).attr("colspan", 4); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | the_list.on( 'click', '.delete-tag', function() { |
| 21 | var t = $(this), tr = t.parents('tr'), r = true, data; |
| 22 | if ( 'undefined' != showNotice ) |
| 23 | r = showNotice.warn(); |
| 24 | if ( r ) { |
| 25 | data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag'); |
| 26 | $.post(ajaxurl, data, function(r){ |
| 27 | if ( '1' == r ) { |
| 28 | $('#ajax-response').empty(); |
| 29 | tr.fadeOut('normal', function(){ tr.remove(); }); |
| 30 | // Remove the term from the parent box and tag cloud |
| 31 | $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove(); |
| 32 | $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove(); |
| 33 | } else if ( '-1' == r ) { |
| 34 | $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>'); |
| 35 | tr.children().css('backgroundColor', ''); |
| 36 | } else { |
| 37 | $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.broken + '</p></div>'); |
| 38 | tr.children().css('backgroundColor', ''); |
| 39 | } |
| 40 | }); |
| 41 | tr.children().css('backgroundColor', '#f33'); |
| 42 | } |
| 43 | return false; |
| 44 | }); |
| 45 | |
| 46 | $('#submit').click(function(){ |
| 47 | var form = $(this).parents('form'); |
| 48 | |
| 49 | if ( ! validateForm( form ) ) |
| 50 | return false; |
| 51 | |
| 52 | $.post(ajaxurl, $('#addtag').serialize(), function(r){ |
| 53 | var res, parent, term, indent, i; |
| 54 | |
| 55 | $('#ajax-response').empty(); |
| 56 | res = wpAjax.parseAjaxResponse( r, 'ajax-response' ); |
| 57 | if ( ! res || res.errors ) |
| 58 | return; |
| 59 | |
| 60 | parent = form.find( 'select#parent' ).val(); |
| 61 | |
| 62 | 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. |
| 63 | $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); // As the parent exists, Insert the version with - - - prefixed |
| 64 | else |
| 65 | $( '.tags' ).prepend( res.responses[0].supplemental.parents ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm |
| 66 | |
| 67 | $('.tags .no-items').remove(); |
| 68 | |
| 69 | if ( form.find('select#parent') ) { |
| 70 | // Parents field exists, Add new term to the list. |
| 71 | term = res.responses[1].supplemental; |
| 72 | |
| 73 | // Create an indent for the Parent field |
| 74 | indent = ''; |
| 75 | for ( i = 0; i < res.responses[1].position; i++ ) |
| 76 | indent += ' '; |
| 77 | |
| 78 | form.find( 'select#parent option:selected' ).after( '<option value="' + term.term_id + '">' + indent + term.name + '</option>' ); |
| 79 | } |
| 80 | |
| 81 | $('input[type="text"]:visible, textarea:visible', form).val(''); |
| 82 | }); |
| 83 | |
| 84 | return false; |
| 85 | }); |
| 86 | |
| 87 | }); |
| 88 | No newline at end of file |