Created
November 15, 2012 21:02
-
-
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.
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
// 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', ''); | |
// 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: | |
// | |
// 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', ''); | |
// For people using plain text/HTML | |
insertTag('post_two', '<img alt="', '" src="' + src + '" />'); | |
// To get a more sensible result like: | |
// | |
//  | |
// | |
// <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