‘;
publishBtn.before(backupField);
}
}
}
// Check for React editor on load and with a delay
setTimeout(ensureReactHeadlineField, 100);
setTimeout(ensureReactHeadlineField, 500);
setTimeout(ensureReactHeadlineField, 1000);
// Watch for React editor to appear
var observer = new MutationObserver(function(mutations) {
ensureReactHeadlineField();
});
observer.observe(document.body, { childList: true, subtree: true });
// Legacy editor – modify form template
var formTemplate = $(‘#liveblog-form-template’).html();
if (formTemplate && formTemplate.indexOf(‘liveblog-headline-field’) === -1) {
var headlineField = ‘
‘);
$(‘#liveblog-form-template’).html(formTemplate);
}
// Function to get headline value
function getHeadlineValue() {
var headline = ”;
// Look for various possible headline input selectors
var headlineInputs = $(‘.liveblog-headline-input, #liveblog-headline, .backup-headline, input[placeholder*=”headline” i], input[placeholder*=”Headline” i]’);
console.log(‘Searching for headline inputs with selectors…’);
headlineInputs.each(function() {
var val = $(this).val();
console.log(‘Headline input found:’, this, ‘value:’, val);
if (val && val.trim()) {
headline = val.trim();
return false; // break loop
}
});
// Also check all text inputs in the liveblog editor for debugging
$(‘.liveblog-editor-container input[type=”text”]’).each(function() {
console.log(‘Text input in editor:’, this, ‘placeholder:’, $(this).attr(‘placeholder’), ‘value:’, $(this).val());
});
return headline;
}
// Function to get author name value
function getAuthorNameValue() {
var authorName = ”;
var authorInputs = $(‘.liveblog-author-input’);
authorInputs.each(function() {
var val = $(this).val();
if (val && val.trim()) {
authorName = val.trim();
return false; // break loop
}
});
return authorName;
}
// Override XMLHttpRequest to add headline parameter to liveblog requests
var originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
if (this._url && (this._url.indexOf(‘liveblog’) > -1 || this._url.indexOf(‘crud’) > -1) && data) {
try {
var parsedData = JSON.parse(data);
if (parsedData && (parsedData.crud_action === ‘insert’ || parsedData.crud_action === ‘update’)) {
var headline = getHeadlineValue();
var authorName = getAuthorNameValue();
// Debug logging
console.log(‘=== Liveblog Form Submission Debug ===’);
console.log(‘Found headline inputs:’, $(‘.liveblog-headline-input, #liveblog-headline, .backup-headline’).length);
console.log(‘Headline value:’, headline);
console.log(‘Author name value:’, authorName);
console.log(‘Original data:’, parsedData);
parsedData.headline = headline || ”;
parsedData.author_name = authorName || ”;
console.log(‘Modified data:’, parsedData);
data = JSON.stringify(parsedData);
}
} catch(e) {
// Ignore JSON parse errors
}
}
return originalXHRSend.call(this, data);
};
// Track XHR URLs
var originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
this._url = url;
return originalXHROpen.apply(this, arguments);
};
// Hook into jQuery AJAX for legacy editor
$(document).ajaxSend(function(event, xhr, settings) {
// Get headline and author name values
var headline = getHeadlineValue();
var authorName = getAuthorNameValue();
// For REST API requests that contain crud_action or liveblog in URL
if (settings.url && (settings.url.indexOf(‘liveblog/v1/’) > -1 || settings.url.indexOf(‘crud’) > -1)) {
if (settings.contentType && settings.contentType.indexOf(‘application/json’) > -1 && settings.data) {
try {
var data = JSON.parse(settings.data);
if (data && (data.crud_action === ‘insert’ || data.crud_action === ‘update’)) {
data.headline = headline || ”;
data.author_name = authorName || ”;
settings.data = JSON.stringify(data);
}
} catch(e) {
// Ignore JSON parse errors
}
}
}
// For legacy form data requests
if (settings.data && typeof settings.data === ‘string’ && settings.data.indexOf(‘liveblog_’) !== -1) {
if (headline) {
settings.data += ‘&headline=’ + encodeURIComponent(headline);
}
if (authorName) {
settings.data += ‘&author_name=’ + encodeURIComponent(authorName);
}
}
});
});
//]]>
‘;
$latestEntry.append(badge);
// Add class to the entry for targeted CSS styling
$latestEntry.addClass(‘has-latest-badge’);
}
}
// Process all entries
function processAllEntries() {
$(‘.liveblog-entry’).each(function() {
enhanceEntry($(this));
});
addLatestUpdateBadge();
}
// Watch for new entries
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === ‘childList’) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1 && node.classList && node.classList.contains(‘liveblog-entry’)) {
enhanceEntry($(node));
}
});
}
});
});
// Start observing
const feedElement = document.querySelector(‘.liveblog-feed’);
if (feedElement) {
observer.observe(feedElement, { childList: true, subtree: true });
}
// Process existing entries
processAllEntries();
// Expose function for manual triggering
window.processLiveblogEnhancements = processAllEntries;
// Debug function to check entry data
window.debugLiveblogHeadlines = function() {
console.log(‘=== Liveblog Headlines Debug ===’);
$(‘.liveblog-entry’).each(function() {
const $entry = $(this);
const entryId = $entry.attr(‘id’);
const numericId = entryId ? entryId.replace(‘id_’, ”) : ‘unknown’;
console.log(‘Entry ID:’, entryId);
console.log(‘Has headline element:’, $entry.find(‘.liveblog-headline’).length > 0);
console.log(‘Data attributes:’, $entry.data());
// Check for script data
const $script = $entry.find(‘script[type=”application/json”]’);
if ($script.length) {
try {
const data = JSON.parse($script.text());
console.log(‘Script data:’, data);
} catch(e) {
console.log(‘Script data parse error:’, e);
}
}
// Check React store
if (window.liveblogEntries && window.liveblogEntries[entryId]) {
console.log(‘React store data:’, window.liveblogEntries[entryId]);
}
console.log(‘—‘);
});
};
// Debug function to inspect the editor form
window.debugLiveblogEditor = function() {
console.log(‘=== Liveblog Editor Debug ===’);
console.log(‘Editor container exists:’, $(‘.liveblog-editor-container’).length);
console.log(‘All text inputs in editor:’);
$(‘.liveblog-editor-container input[type=”text”]’).each(function(i) {
console.log(‘Input ‘ + i + ‘:’, this);
console.log(‘ – Class:’, $(this).attr(‘class’));
console.log(‘ – Placeholder:’, $(this).attr(‘placeholder’));
console.log(‘ – Value:’, $(this).val());
console.log(‘ – Parent:’, $(this).parent().get(0));
});
console.log(‘All inputs in editor (any type):’);
$(‘.liveblog-editor-container input’).each(function(i) {
console.log(‘Input ‘ + i + ‘:’, this.type, $(this).attr(‘class’), $(this).attr(‘placeholder’));
});
console.log(‘Headline-related elements:’);
$(‘*’).filter(function() {
return $(this).text().toLowerCase().includes(‘headline’) ||
$(this).attr(‘placeholder’) && $(this).attr(‘placeholder’).toLowerCase().includes(‘headline’) ||
$(this).attr(‘class’) && $(this).attr(‘class’).toLowerCase().includes(‘headline’);
}).each(function() {
console.log(‘Headline element:’, this);
});
};
});
//]]>
This article first appeared at News