Created
May 26, 2011 19:17
-
-
Save protocool/993836 to your computer and use it in GitHub Desktop.
Revisions
-
protocool created this gist
May 26, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ if (displayDataURLImages) { Campfire.DataImageURLExpander = Class.create({ initialize: function(chat) { this.chat = chat; var messages = this.chat.transcript.messages; for (var i = 0; i < messages.length; i++) { this.detectDataURLImage(messages[i]); } }, detectDataURLImage: function(message) { if (!message.pending() && message.kind === 'text') { var links = message.bodyElement().select('a'); if (links.length > 0) { return; } var bodyContent = message.bodyElement().textContent; var match = bodyContent.match(/^data:image\/\w+;base64/); if (!match) return; message.resize((function() { message.bodyCell.insert({bottom: '<div style="width:100%; margin-top:5px; padding-top: 5px; border-top:1px dotted #ccc;"><img src="'+bodyContent+'" onload="$dispatch("inlineImageLoaded", this)" onerror="$dispatch("inlineImageLoadFailed", this)" /></div>'}); }).bind(this)); } }, onMessagesInsertedBeforeDisplay: function(messages) { for (var i = 0; i < messages.length; i++) { this.detectDataURLImage(messages[i]); } }, onMessageAccepted: function(message, messageID) { this.detectDataURLImage(message); } }); Campfire.Responders.push("DataImageURLExpander"); window.chat.installPropaneResponder("DataImageURLExpander", "dataimageurlexpander"); }