public
Last active

Sample Propane caveatPatchor.js file

  • Download Gist
caveatPatchor.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/**
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");
}

thanks. nice scripts:)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.