In case anyone is interested in fixing, here is the current implementation of the raw button:
(function(){
//@Monarch at what.thedailywtf.com
//Button is redelcared and sligthly modified due to new scope. it can be further simplified.
Button = function(action, label, icon, opts) {
this.action = action;
this.label = label;
if (typeof icon === "object") { this.opts = icon; } else { this.icon = icon;}
this.opts = this.opts || opts || {};
this.render = function (buffer){
var opts = this.opts;
buffer.push("<button title=\"" + this.label + "\"");
if (opts.className) { buffer.push(" class=\"" + opts.className + "\""); }
buffer.push(" data-action=\"" + this.action + "\">");
if (this.icon) { buffer.push("<i class=\"fa fa-" + this.icon + "\"></i>"); }
buffer.push("</button>");
}
};
/* Remove this clause after update from v1.4.0.beta4
https://what.thedailywtf.com/t/fa-code-will-break-next-upgrade/49921/9?u=pjh
*/
if (typeof Discourse.PostMenuView == 'function'){
Discourse.PostMenuComponent = Discourse.PostMenuView;
}
Discourse.PostMenuComponent.reopen({
buttonForRaw:function(post){
return new Button('raw', 'view raw post', 'code', {className: "raw-button", disabled: false});
},
clickRaw:function(post){
var topicID = post.topic_id,
postID = post.post_number,
postArea = $("article[data-post-id='"+post.id+"'] div.contents"),
$rawButton = $(this.element).find("button.raw-button"),
styles = [{backgroundColor: 'transparent', color: '#A7A7A7'},{backgroundColor: '#08C', color: '#FFF'}];
if (postArea.find('.tdwtf-raw-area').length == 0){
var postArea_raw_content = $('<pre class="tdwtf-raw-area"></pre>'),
cooked = postArea.find('.cooked');
cooked.after(postArea_raw_content);
$.get('/raw/' + topicID + '/' + postID) .done(function (content) {
postArea_raw_content.addClass("active");
$rawButton.css(styles[1]);//active
postArea_raw_content.css({"white-space":"pre-wrap", 'border':'2px dashed #E7E7E7','padding':'3px'}) .text(content);
cooked.hide();
});
} else {
var postArea_raw_content = postArea.find('.tdwtf-raw-area');
if ( !postArea_raw_content.hasClass("active") ){ //raw no active
postArea.find('.cooked').hide();
postArea.find('.tdwtf-raw-area').show();
postArea_raw_content.addClass("active");
$rawButton.css(styles[1]);
} else{
postArea.find('.cooked').show();
postArea.find('.tdwtf-raw-area').hide();
postArea_raw_content.removeClass("active");
$rawButton.css(styles[0]);
}
}
}
});
})();