-
-
Save lidlanca/3446be0151ae3f320293 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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