1/** 2 * Handles adding/removing options from top_terms admin dropdown 3 */ 4 5 6 7 function topTerm (terms=false,selectEvent=false,Topterm=false) { 8 (function($) { 9 $(document).ready(function() { 10 var $dropdown = $('#top_term select'); 11 var $cat_checklists = $('.categorychecklist').not("[id^='prominence'], [id^='post-type']"); 12 var $tag_checklists = $('.tagchecklist'); 13 var $tags_link = $('button.mj-tagcloud-link'); 14 var selected_categories = []; 15 16 17 18 if(!terms){ 19 $(document).off('click'," div[aria-label='Categories'].editor-post-taxonomies__hierarchical-terms-list input[type='checkbox' ]"); 20 $(document).on('click'," div[aria-label='Categories'].editor-post-taxonomies__hierarchical-terms-list input[type='checkbox' ]", function() { 21 22 var value = $(this).val(); 23 24 if (this.checked) { 25 //make sure it exists 26 27 if (!$("option[value='" + value + "']", $dropdown.children()).length) { 28 var option = document.createElement('option'); 29 // option= $('<option value="'+option.value+'" >'+$(this).parent('label').text().trim()+'</option>'); 30 option.value = value; 31 option.innerText = $($(this).parent().parent().find('label')).text().trim(); 32 $dropdown.append(option); 33 } 34 } else { 35 //make sure it's gone 36 if ($("option[value='" + value + "']", $dropdown).length) { 37 $("option[value='" + value + "']", $dropdown).remove(); 38 } 39 } 40 }); 41 }else{ 42 $dropdown.empty(); 43 var none_option = document.createElement('option'); 44 none_option.value = 'none'; 45 none_option.innerText = 'None'; 46 47 $dropdown.append(none_option); 48 49 if(terms && terms.hasOwnProperty('catDesc') && Array.isArray(terms.catDesc)){ 50 51 52 53 54 terms.catDesc.forEach((category,index) => { 55 56 var option = document.createElement('option'); 57 option.value = category.id; 58 option.innerText = category.name; 59 option.dataset.taxonomy="category"; 60 $dropdown.append(option); 61 62 $dropdown.prop("disabled", false); 63 64 65 }); 66 67 68 69 70 71 72 73 74 } 75 console.log((terms && terms.hasOwnProperty('tagDescs') && Array.isArray(terms.tagDescs))); 76 if (terms && terms.hasOwnProperty('tagDescs') && Array.isArray(terms.tagDescs)){ 77 78 terms.tagDescs.forEach((tag,index) => { 79 80 var option = document.createElement('option'); 81 option.value = tag.id; 82 option.innerText = tag.name; 83 option.dataset.taxonomy="post_tag"; 84 $dropdown.append(option); 85 86 $dropdown.prop("disabled", false); 87 88 89 }); 90 91 92 } 93 94 95 if(Topterm){ 96 $('#top_term select>option[value="'+Topterm+'"]').prop('selected', true); 97 98 } 99 100 if(selectEvent && typeof selectEvent === 'function' ){ 101 102 $(document).off('change',"#top_term select"); 103 $(document).on('change',"#top_term select",(e) => { 104 e.preventDefault(); 105 selectEvent($dropdown); 106 107 108 109 110 }); 111 112 } 113 114 115 } 116 117 118 119 120 121 122 var link_interval = setInterval(function () { 123 if ($('#tagcloud-post_tag a').length > 0) { 124 clearInterval(link_interval); 125 $tags_link.addClass('loaded'); 126 //click link to add tag 127 $('#tagcloud-post_tag a').click(function(){ 128 var value = $(this).attr('href').split('#')[1]; 129 var name = $(this).text(); 130 if (!$("option[value='" + value + "']", $dropdown).length) { 131 var option = document.createElement('option'); 132 option.value = value; 133 option.innerText = name; 134 $dropdown.append(option); 135 } 136 }); 137 } 138 }, 100); 139 140 $('body').on('DOMSubtreeModified', '.tagchecklist', function() { 141 //remove tag from term list 142 $('.ntdelbutton').each(function(){ 143 var $this = $(this); 144 if ( $this.attr('data-event') === "none" ) { 145 $this.click(function() { 146 var name = $(this).closest('li').textNodes()[0].textContent; 147 var value = $('#top_term option').filter(function () { 148 return $(this).html() === name; 149 }).val(); 150 if (value) { 151 $("option[value='" + value + "']", $dropdown).remove(); 152 } 153 }); 154 155 $this.attr('data-event', 'click'); 156 } 157 }); 158 159 var tag_cloud = []; 160 $('#tagcloud-post_tag a').each(function(){ 161 tag_cloud.push( $( this ).html() ); 162 }); 163 var tag_cloud_lower = tag_cloud.map(function(tag){ 164 return tag.toLowerCase() 165 }); 166 167 // Add tags from combobox to terms list 168 $('.tagchecklist li').each(function(){ 169 var name = $(this).textNodes()[0].textContent; 170 var index = tag_cloud_lower.indexOf( name.toLowerCase() ); 171 172 if ( index >= 0) { 173 var value = $($('#tagcloud-post_tag a')[index]).attr('href').split('#')[1]; 174 175 if (!$("option[value='" + value + "']", $dropdown).length) { 176 var option = document.createElement('option'); 177 option.value = value; 178 option.innerText = tag_cloud[index]; 179 $dropdown.append(option); 180 } 181 } 182 }); 183 }); 184 185 }); 186 187 jQuery.fn.textNodes = function() { 188 return this.contents().filter(function() { 189 return (this.nodeType === Node.TEXT_NODE && this.nodeValue.trim() !== ''); 190 }); 191 } 192 193 })(jQuery); 194 195 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.