import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/modern/theme';
import 'tinymce/plugins/link';
import 'tinymce/plugins/autolink';
import 'tinymce/plugins/image';
import 'tinymce/plugins/lists';

import 'tinymce-i18n/langs/fr_FR';

require.context(
  'file-loader?name=[path][name].[ext]&context=node_modules/tinymce!tinymce/skins',
  true,
  /.*/
);

const onLoad = function() {
  tinymce.init({
    selector: 'textarea.richeditorwidget',
    plugins: 'link autolink image lists',
    toolbar: 'bold italic | formatselect | link image | bullist numlist',
    menubar: false,
    statusbar: false,
    language: 'fr_FR',
    block_formats: 'Paragraphe=p;Titre=h2;Sous-titre=h3;Petit titre=h4',
    skin_url: (process.env.NODE_ENV === 'production' ? '' : 'http://agir.local:3000') + '/static/components/skins/lightgray'
  });
};

document.addEventListener("turbolinks:load", onLoad);

import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/modern/theme';
import 'tinymce/plugins/link';
import 'tinymce/plugins/autolink';
import 'tinymce/plugins/image';
import 'tinymce/plugins/lists';

import 'tinymce-i18n/langs/fr_FR';

require.context(
  'file-loader?name=[path][name].[ext]&context=node_modules/tinymce!tinymce/skins',
  true,
  /.*/
);

tinymce.init({
  selector: 'textarea.richeditorwidget',
  plugins: 'link autolink image lists',
  toolbar: 'bold italic | formatselect | link image | bullist numlist',
  menubar: false,
  statusbar: false,
  language: 'fr_FR',
  block_formats: 'Paragraphe=p;Titre=h2;Sous-titre=h3;Petit titre=h4',
  skin_url: (process.env.NODE_ENV === 'production' ? '' : 'http://agir.local:3000') + '/static/components/skins/lightgray'
});

initialise RichEditor sans turbolinks:load