Skip to content

Instantly share code, notes, and snippets.

@lidlanca
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidlanca/3446be0151ae3f320293 to your computer and use it in GitHub Desktop.
Save lidlanca/3446be0151ae3f320293 to your computer and use it in GitHub Desktop.
Discourse.PostView.reopen({
_processHistoryLink: function() {
window.processLinks(); //scan for history::topic_id::revision pattern in a <kbd><code></code></kbd>
}.on('didInsertElement') //fire on every post render, not ideal for processLinks function we could be fine if it fire once for each post chunks being added.
});
Discourse.__container__.lookup("route:topic").reopen({
actions: {
showHistoryByPostId: function(postID, rev) {
ff = Discourse.__container__.lookup("route:topic");
Discourse.Route.showModal(this, 'history', postID);
this.controllerFor("history").refresh(postID, rev);
this.controllerFor('modal').set('modalClass', 'history-modal');
return false;
}
}
});
window.processLinks = function() {
$("kbd>code").each(function(a, b) {
b = $(b);
var m = b.text().match(/(history)::(\d+)::(\d+)/)
console.log("Match?", m);
if (m != null) {
var post_id = m[2]
var post_rev = m[3]
a = $("<div style='cursor:pointer;display:block !important'>See History of post " + post_id + " Rev" + post_rev + "</div>");
a.click(function() {
Discourse.__container__.lookup("route:topic").send("showHistoryByPostId", parseInt(post_id), parseInt(post_rev));
});
b.html("");
b.append(a);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment