Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for uploading of specific files besides images #43

Closed
JeanMertz opened this issue Oct 19, 2011 · 3 comments
Closed

Allow for uploading of specific files besides images #43

JeanMertz opened this issue Oct 19, 2011 · 3 comments

Comments

@JeanMertz
Copy link

I didn't want to make a pull request out of this yet, but I hacked the current uploader to allow for documents to be uploaded:

Basically it extends the current functionality by checking if the uploaded file is an image, and if it isn't, use the new code.

  • The server has to give back an extra value, called "response.document.img".
  • When the user has text selected and uploads a document, the selected text is converted to a link
  • If there is an image in the selection, that image is wrapped in a link to the document.
  • If there is no selection, a new image is used with the src set to response.document.img, on the server side I then check for the mime type and pass back the appropriate image url, for example a small PDF image, or Word image.

This needs a lot of work, and it would be best to extract this out into a separate image uploader and document uploader (because the image previewing feature (during uploading) now shows a broken image), but I don't think I am comfortable with the code yet to do this and I definitely won't have the time for the next few weeks.

Anyway, here is the snippet:

if ['image/jpeg', 'image/gif', 'image/png'].indexOf(@file.type) > -1
  Mercury.trigger('action', {action: 'insertImage', value: {src: response.document.url}})
else
  attrs = {href: response.document.url}
  content = jQuery('<img>', {src: response.document.img})
  selection = Mercury.region.selection()

  if selection.range.collapsed is false
    if selection.commonAncestor && selection.commonAncestor(true).find('img').length > 0 
      content = selection.commonAncestor(true).find('img')[0]
    else
      content = selection.fragment.textContent

    container = selection.commonAncestor(true).closest('a') if selection && selection.commonAncestor

  if container && container.length
    Mercury.trigger('action', {action: 'replaceLink', value: {tagName: 'a', attrs: attrs, content: content}, node: container.get(0)})
  else
    Mercury.trigger('action', {action: 'insertLink', value: {tagName: 'a', attrs: attrs, content: content}})
@jejacks0n
Copy link
Owner

I've been playing around with a plugin architecture.. and in doing so I've broken some image cropping/resizing features into that plugin -- I'd like to pull this into that plugin as well to see how easily all of this can be accomplished in a plugin. It'll fit right in with it since it's an "advanced uploader" plugin.

@ghost ghost assigned jejacks0n Oct 22, 2011
@milgner
Copy link

milgner commented Dec 23, 2011

Is there any way to get a sneak preview at this plugin architecture? I'm currently working on a site where I'd like to do audio uploads which would require some handling by my apps Rails controllers and I'd like to see if this could integrate with this Mercury plugin concept.

@jaemo
Copy link

jaemo commented Aug 16, 2012

I'm seconding milgner's request. It would be nice if we could see this code in context. I am trying to add a document uploader for a project I'm working on....

@gvarela gvarela closed this as completed Jan 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants