Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/#808_update_required_prohibited_categories #810

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions modules/checklists/assets/js/meta-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@
if (link.startsWith('#')) {
return true;
}

const linkWithoutFragment = link.split('#')[0];

return linkWithoutFragment.match(
Expand Down Expand Up @@ -1047,9 +1047,21 @@
const labelEl = el.find('.status-label');
const current_label_text = label.replace(/:.*/, '');
const required_tags_str = required_tags_reached.map((el) => el.split('__')[1]).join(', ');
const final_label_text =
required_tags_str.length > 0 ? `${current_label_text}: ${required_tags_str} ` : `${current_label_text} `;

el.trigger(PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, !has_required_tags);
labelEl.text(`${current_label_text}${required_tags_str.length > 0 ? ': ' + required_tags_str : ''}`);
// Need to update the text node directly because the element has a span inside
labelEl
.contents()
.filter(function () {
return this.nodeType === 3; // Node type 3 is a text node
})
.first()
.each(function () {
// Modify the text node
this.nodeValue = final_label_text;
});
}
});
}
Expand Down Expand Up @@ -1086,7 +1098,7 @@
const current_label_text = label.replace(/:.*/, '');
const prohibited_tags_str = prohibited_tags_reached.map((el) => el.split('__')[1]).join(', ');
const final_label_text =
prohibited_tags_str.length > 0 ? `${current_label_text}: ${prohibited_tags_str}` : current_label_text;
prohibited_tags_str.length > 0 ? `${current_label_text}: ${prohibited_tags_str} ` : `${current_label_text} `;

ppChecklists = {
...ppChecklists,
Expand All @@ -1099,7 +1111,17 @@
},
};
el.trigger(PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, !has_prohibited_tags);
labelEl.text(final_label_text);
// Need to update the text node directly because the element has a span inside
labelEl
.contents()
.filter(function () {
return this.nodeType === 3; // Node type 3 is a text node
})
.first()
.each(function () {
// Modify the text node
this.nodeValue = final_label_text;
});
}
});
}
Expand Down Expand Up @@ -1152,11 +1174,23 @@
const labelEl = el.find('.status-label');
const current_label_text = label.replace(/:.*/, '');
const required_categories_str = required_categories_reached.map((el) => el.split('__')[1]).join(', ');
const final_label_text =
required_categories_str.length > 0
? `${current_label_text}: ${required_categories_str} `
: `${current_label_text} `;

el.trigger(PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, !has_required_categories);
labelEl.text(
`${current_label_text}${required_categories_str.length > 0 ? ': ' + required_categories_str : ''}`,
);
// Need to update the text node directly because the element has a span inside
labelEl
.contents()
.filter(function () {
return this.nodeType === 3; // Node type 3 is a text node
})
.first()
.each(function () {
// Modify the text node
this.nodeValue = final_label_text;
});
}
});
}
Expand Down Expand Up @@ -1185,8 +1219,8 @@
const prohibited_categories_str = prohibited_categories_reached.map((el) => el.split('__')[1]).join(', ');
const final_label_text =
prohibited_categories_str.length > 0
? `${current_label_text}: ${prohibited_categories_str}`
: current_label_text;
? `${current_label_text}: ${prohibited_categories_str} `
: `${current_label_text} `;

ppChecklists = {
...ppChecklists,
Expand All @@ -1199,7 +1233,17 @@
},
};
el.trigger(PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, !has_prohibited_categories);
labelEl.text(final_label_text);
// Need to update the text node directly because the element has a span inside
labelEl
.contents()
.filter(function () {
return this.nodeType === 3; // Node type 3 is a text node
})
.first()
.each(function () {
// Modify the text node
this.nodeValue = final_label_text;
});
}
});
}
Expand Down Expand Up @@ -1301,23 +1345,23 @@
if ($('#pp-checklists-req-title_count').length > 0) {
$(document).on(PP_Checklists.EVENT_TIC, function (event) {
var count = 0,
obj = null,
min_value = parseInt(ppChecklists.requirements.title_count.value[0]),
max_value = parseInt(ppChecklists.requirements.title_count.value[1]);

if (PP_Checklists.is_gutenberg_active()) {
// @todo: why does Multiple Authors "Remove author from new posts" setting cause this to return null?
var obj = PP_Checklists.getEditor().getEditedPostAttribute('title');
obj = wp.htmlEntities.decodeEntities(PP_Checklists.getEditor().getEditedPostAttribute('title'));
} else {
if ($('#title').length === 0) {
return;
}

var obj = $('#title').val();
obj = $('#title').val();
}

if (typeof obj !== 'undefined') {
var decodedObj = wp.htmlEntities.decodeEntities(obj);
count = decodedObj.length;
count = obj.length;

$('#pp-checklists-req-title_count').trigger(
PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE,
Expand Down