-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathunique-title-checker.js
More file actions
43 lines (38 loc) · 1.19 KB
/
Copy pathunique-title-checker.js
File metadata and controls
43 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Check for the Classic Editor
*
* @package unique-title-checker
*/
document.addEventListener( "DOMContentLoaded", function () {
document.getElementById( "title" ).addEventListener( "blur", function () {
var title = this.value;
// Show no warning on empty titles.
if (title === "") {
return;
}
var requestData = new URLSearchParams( {
action: "unique_title_check",
ajax_nonce: unique_title_checker.nonce,
post_id: document.getElementById( "post_ID" ).value,
post_type: document.getElementById( "post_type" ).value,
post_title: title
} );
fetch( ajaxurl + "?" + requestData.toString() )
.then( response => response.json() )
.then( data => {
var messageElement = document.getElementById( "unique-title-message" );
if (messageElement) {
messageElement.remove();
}
if (data.status === "error" || !unique_title_checker.only_unique_error) {
document.getElementById( "post" ).insertAdjacentHTML(
"beforebegin",
`<div id="unique-title-message" class="${ data.status }">
<p>${ data.message }</p>
</div>`
);
}
} )
.catch( error => console.error( "Error fetching unique title check:", error ) );
} );
} );