$(document).on('turbolinks:load', function() {

var froala_editor = $('.froala-editor');

if (froala_editor.length > 0) {
  var aws_s3 = JSON.parse(froala_editor.attr('data'));

  froala_editor.froalaEditor({
    language: window.location.href.indexOf('/zh/') > 0 ? 'zh_cn' : 'en',
    charCounterCount: false,
    heightMin: '50rem',
    toolbarButtons:['selectAll', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontFamily', 'fontSize', '|', 'specialCharacters', 'color', 'inlineStyle', 'paragraphStyle', '|', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', 'insertHR', '|', 'insertLink', 'insertImage', 'insertVideo', 'insertTable', 'clearFormatting'],
    toolbarButtonsXS: ['bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'insertLink', 'insertImage'],
    videoInsertButtons: ['videoBack', '|', 'videoByURL', 'videoEmbed'],
    imageUploadToS3: {
      bucket: aws_s3['bucket'],
      region: aws_s3['region'],
      keyStart: aws_s3['key_start'],
      params: {
        acl: aws_s3['acl'],
        AWSAccessKeyId: aws_s3['access_id'],
        policy: aws_s3['policy'],
        signature: aws_s3['signature']
      }
    }
  });
}

});