Skip to content

Instantly share code, notes, and snippets.

@aitor
Created November 15, 2012 21:02
Show Gist options
  • Save aitor/4081234 to your computer and use it in GitHub Desktop.
Save aitor/4081234 to your computer and use it in GitHub Desktop.
Upload photo link is ignoring selected text for Markdown and plain text/HTML users.
// TL;DR: Upload photo link is ignoring selected text for
// Markdown and plain text/HTML users.
// Go to any Tumblr account
// Create text post http://www.tumblr.com/new/text
// Write and select some text. Click on "Upload photo". See the result.
// After uploader iframe has been reloaded, it's calling the function
// "catch_uploaded_photo" with a param containing the fres link to the
// uploaded pic:
function catch_uploaded_photo(src) {
//
if (tinyMCE && (ed = tinyMCE.get('post_two'))) {
ed.execCommand('mceInsertContent', false, '<img src="' + src + '" />');
} else {
// For people -like me- using Markdown
insertTag('post_two', '![](' + src + ')');
// For people using plain text/HTML
insertTag('post_two', '<img src="' + src + '" />');
}
}
// The signature for function insertTag() is the following:
function insertTag(field_id, start, end) {}
// The function is designed to wrap the selection with the inserted tag
// Unfortunately catch_uploaded_photo is skipping the 2nd param
// Side effect is that the link with the new photo is appended before
// selection -literally appended, no space- so I get something like:
//
// ![](link)The originally selected text
//
// Wouldn't it be nicer -and more logical- to respect the user selection
// and made something like:
// For people -like me- using Markdown
insertTag('post_two', '![', '](' + src + ')');
// For people using plain text/HTML
insertTag('post_two', '<img alt="', '" src="' + src + '" />');
// To get a more sensible result like:
//
// ![The originally selected text](link)
//
// <img alt="The originally selected text" src="link" />
//
// Can please someone at tumblr.com think/evaluate/fix this?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment