Created
May 26, 2011 19:17
-
-
Save protocool/993836 to your computer and use it in GitHub Desktop.
Propane caveatPatchor.js hack to display data:image urls inline as images
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 characters
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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment