topical media & game development
#javascript-code-10-wiki.js / js
// Get the name of the current page
var s = s.length);
// Determine if a revision number
// was provided - if so, remember it's ID
var s.split("&");
if ( tmp.length > 1 ) {
r = tmp[1];
}
// Go to the homepage, if no page is provided
if (!s;
$("h1").html(r = (new Date()).getTime();
// Insert the revision into the database
sqlExec("INSERT INTO wiki VALUES(?,?,?,?);",
[r], reload);
return false;
});
// If the user clicked the 'cancel' link
// inside the editing area
$("#cancel").click(showContent);
});
// Show the current revision
function showContent() {
// Show the edit link
$("#edit,#cancel").css("display","inline");
// Hide the editing area
$("#post").hide();
// Show the content
$("#content").show();
return false;
}
// Show the form to edit the current revision
function showForm() {
// Hide the edit link
$("#edit").hide();
// Show the editing area
$("#post").show();
// Hide the content
$("#content").hide();
return false;
}
// Load all of the revisions from the database
function reload(t) {
// Request all the revisions
sqlExec("SELECT * FROM wiki WHERE title=? ORDER BY date DESC;", [r ) r ) {
// Render the revision
$("#content").html(textile(sql[i].content));
// Make the revision contents editable
$("textarea").val( sql[i].content );
}
// Get a workable date object
var d = new Date(sql[i].date);
// Figure out if the revision was made within the last day, or not
if ( d.getTime() > (new Date()).getTime() - (3600 * 24000) )
// If it was, make a nice am/pm time
d = d.getHours() >= 12 ?
(d.getHours() != 12 ? d.getHours() - 12 : 12 ) + " pm" :
d.getHours() + " am";
// Otherwise, display the month and day of the revision
else {
var a = d.toUTCString().split(" ");
d = a[2] + " " + d.getDate();
}
// Add the revision to the revision list
$("#side ul").append("<li class='" + ( s + ( i > 0 ? "&" + sql[i].date : "" )
+ "'>" + d + "</a> by " + sql[i].author + "</li>");
}
// Otherwise, this page has never been revised
} else {
// Say so in the revision panel
$("#rev").html("<li>No Revisions.</li>");
// Hide the editing controls
$("#edit,#cancel").hide();
// Show the default editing form
showForm();
}
});
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.