Skip to content

Instantly share code, notes, and snippets.

@tombruijn
Forked from protocool/caveatPatchor.js
Last active December 14, 2015 10:18
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 tombruijn/5070636 to your computer and use it in GitHub Desktop.
Save tombruijn/5070636 to your computer and use it in GitHub Desktop.
Propane extension that shows avatars and full names
/*
As of version 1.1.2, 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.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
1 - A responder that adds avatars to your chat view
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var displayAvatars = true;
/*
Display avatars in the chat view - based on code originally by @tmm1
*/
if (displayAvatars) {
Object.extend(Campfire.Message.prototype, {
addAvatar: function() {
if (this.actsLikeTextMessage()) {
var author = this.authorElement();
var avatar = '';
if (author.visible()) {
author.hide();
if (this.bodyCell.select('strong').length === 0) {
this.bodyCell.insert({top: '<strong style="color:#333;">'+author.dataset['name']+'</strong><br>'});
avatar = author.getAttribute('data-avatar') || 'http://asset1.37img.com/global/missing/avatar.png?r=3';
author.insert({after: '<img alt="'+this.author()+'" width="32" height="32" align="top" style="opacity: 1.0; margin-left: 5px; border-radius:3px" src="'+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;
var messages = this.chat.transcript.messages;
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
message.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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment