PerfectlyNormal / tinymce-rails-imageupload

Image upload plugin for TinyMCE and Rails with the asset pipeline
MIT License
149 stars 153 forks source link

Some additional upload options #18

Closed jcuervo closed 11 years ago

jcuervo commented 11 years ago

Usually we need some alignment options: Left, Center or Right. Styles can be passed for the drop-down via (in the form):

<%= tinymce(uploadimage_hint: @article.id, styles: {med: "Medium (354px)", small: "Small (120x80)"}) %>

And the Alt for the image.

Need to add the corresponding fields to the image (or asset) model you wanted to use.

Here's a sample controller implementation:


class Admin::TinymceAssetsController < ApplicationController
  before_filter :require_admin

  def create
    if params[:hint] #associate it to the article
      @article = Article.find(params[:hint])
      image = @article.images.new(:asset => params[:file])
      image.alt = params[:alt]
      image.default_size = params[:default_size]
      image.alignment = params[:alignment]
      if image.save
        render json: {
          image: {
            url: image.try(:asset).try(:url, :small)
          }
        }, content_type: "text/html"
      else
        #image could not be saved
      end
    else
      #no association
    end
  end
end
jcuervo commented 11 years ago

Wrapped the image in a span (with a class). From there we can extend to styling it. And the pop-up needs some additional styling as well.

jcuervo commented 11 years ago

Yeah, that'd be a great idea. Gimme a couple of hours, I'll jump into it.

PerfectlyNormal commented 11 years ago

Just tried out the changes, and I see all the new strings in dialog.html isn't internationalized. Copy the translations over to the english file, I can handle the norwegian when I merge, and the others will just have to be fixed later.

jcuervo commented 11 years ago

Right. My bad, will cover that asap. I also thought of some stuff to handle if some of the options are not needed. BTW, I noticed that there is a ".delta_height", where can I configure that? I manually resized the pop-up. I think if we could set values to that .delta_height and .delta_width stuff, there's no need for me to do changes in the pop-up dimension.

PerfectlyNormal commented 11 years ago

The delta-bit was there in the original plugin, and delta_height and _width is set in the I18n-file.

For example:

tinyMCE.addI18n('en.uploadimage', {
  desc: 'Insert an image from your computer',
  delta_width: 100,
  delta_height: 200
});

but for these changes I think it's better to change the dialog manually as you did. The delta-sizes is more (imo) if the locale needs it because of long lines (German, Finnish, and so on)

PerfectlyNormal commented 11 years ago

Since nothing has happened here for quite some time, I'm closing it.