SammyLin / redactor-rails

This repo is deprecated. Please check out official gem for Redactor 2. https://github.com/Redactor2/redactor2_rails
MIT License
389 stars 253 forks source link

How to add class to images added in the redactor? #144

Closed suramai closed 9 years ago

suramai commented 9 years ago

Hi. I would like to add class="img-responsive" to all the images inserted using the redactor editor. Can anyone share how to do that? Kindly help. Thanks.

napster3000 commented 9 years ago

$(document).ready( function(){ var csrf_token = $('meta[name=csrf-token]').attr('content'); var csrf_param = $('meta[name=csrf-param]').attr('content'); var params; if (csrf_param !== undefined && csrf_token !== undefined) { params = csrf_param + "=" + encodeURIComponent(csrf_token); } $('.redactor').redactor( { "imageUpload":"/redactor_rails/pictures?" + params, "imageGetJson":"/redactor_rails/pictures", "fileUpload":"/redactor_rails/documents?" + params, "fileGetJson":"/redactor_rails/documents", "path":"/assets/redactor-rails", "css":"style.css", "plugins": ['video'], fileUploadErrorCallback: function(json) { alert(json['error']['data'][1]); }, imageUploadCallback: function(image, json) { image.addClass('img-responsive') } } ); });

suramai commented 9 years ago

@napster3000 That worked like a charm. Perfect. Thank you sooooooooooo much.