var x = document.getElementsByTagName("A");
var elem, match;
for ( var i in x ) {
var h = x[i].href;
// Look for an anchor that links to editpost.php
if ( match = h.match(/editpost\.php\?pid=([0-9]+)$/) ) {
pid = match[1];
elem = x[i];
// Creates an event listener for the inline edit button
function createListener( pid ) {
var args = arguments;
return function() {
// Call inlineEditor(pid) when clicked
unsafeWindow.inlineEditor.apply(null, args);
};
}
function createInlineEditor(pid) {
// Prepare some DIVs to hold the inline editor
var tDiv = getId ( 'pid_'+pid );
var oDiv = oDivLoading.cloneNode( true );
oDiv.setAttribute( 'id', 'pid_inline_'+pid);
tDiv.parentNode.insertBefore ( oDiv, tDiv );
tDiv.style.display = 'none';
//Start an XML HTTP Request for editpost.php
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', url+'?pid='+pid, true);
xmlhttp.onreadystatechange = function () {
if ( xmlhttp.readyState !== 4 ) return;
// Get the post_key and subject values
var match = xmlhttp.responseText.match(/name="post_key" value="([a-f0-9]+)"/);
if(match) {
postkey = match[1]; // All OK
}
unsafeWindow.inlineEditor = function ( pid ) {
// Create an inline editor if not available yet
var obj = getId ( 'pid_inline_'+pid );
if (obj === null) return createInlineEditor( pid );
// Swap the editor style between visible and hidden
if ( obj.style.display === 'none' ) { obj.style.display = ''; }
else { obj.style.display = 'none'; }
// Swap the post body style between visible and hidden
obj = getId ( 'pid_'+pid );
if ( obj.style.display === '' ) { obj.style.display = 'none'; }
else { obj.style.display = ''; }
}
function getId ( id ) { return document.getElementById ( id ); }