Skip to content

Instantly share code, notes, and snippets.

@protocool
Created February 11, 2011 01:00
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save protocool/821736 to your computer and use it in GitHub Desktop.
Save protocool/821736 to your computer and use it in GitHub Desktop.
Sample Propane caveatPatchor.js file
/**
Sample Propane caveatPatchor.js file based on tmm1's avatar hack.
You'll need at least version 1.1.1 to experiment with this:
http://propaneapp.com/appcast/Propane.1.1.1.zip
Once I'm sure exposing this hack-injection point doesn't cause problems
I'll do an official auto-updating version.
As of version 1.1.1, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
Please don't tinker with enhancer.js - it's the glue that binds Campfire's
javascript to Propane's UI and features.
Also: this is totally and utterly unsupported. By all means you can
ask me questions via Propane's help forums but I can't debug your scripts
for you. My javascript isn't that good, trust me.
Finally, if Propane is acting broken in general and you've got hacks in
caveatPatchor.js, *please* tell me about your hacks up-front when opening
an issue on the support site.
*/
var displayAvatars = true;
if (displayAvatars) {
Object.extend(Campfire.Message.prototype, {
addAvatar: function() {
if (this.actsLikeTextMessage()) {
var author = this.authorElement();
if (author.visible()) {
author.hide()
if (this.bodyCell.select('strong').length == 0) {
this.bodyCell.insert({top: '<strong>'+this.author()+'</strong><br>'})
author.insert({after: '<img alt="'+this.author()+'" width="32" height="32" align="top" style="margin-left: 5px; border-radius:3px" src="'+author.getAttribute('data-avatar')+'">'});
}
}
}
},
});
/* if you can wrap rather than rewrite, use swizzle like this: */
swizzle(Campfire.Message, {
setAuthorVisibilityInRelationTo: function($super, message) {
$super(message)
this.addAvatar();
},
});
/* defining a new responder is probably the best way to insulate your hacks from Campfire and Propane */
Campfire.AvatarMangler = Class.create({
initialize: function(chat) {
this.chat = chat;
chat.transcript.element.childElements().each(function(elem){
if (elem.match('tr')) {
var msg = new Campfire.Message(chat, elem)
msg.addAvatar()
}
})
this.chat.layoutmanager.layout();
this.chat.windowmanager.scrollToBottom();
},
onMessagesInserted: function(messages) {
var scrolledToBottom = this.chat.windowmanager.isScrolledToBottom();
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
message.addAvatar();
}
if (scrolledToBottom)
this.chat.windowmanager.scrollToBottom();
},
});
/* Here is how to install your responder into the running chat */
Campfire.Responders.push("AvatarMangler");
window.chat.installPropaneResponder("AvatarMangler", "avatarmangler");
}
@5509
Copy link

5509 commented Apr 12, 2012

thanks. nice scripts:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment