Complete multilingual richeditor support

Refs #1652
This commit is contained in:
Samuel Georges 2016-02-13 12:59:49 +11:00
parent 7fb1ed9bdb
commit 6347f2bb03
4 changed files with 49 additions and 38 deletions

View File

@ -1,5 +1,7 @@
<?php namespace Backend\FormWidgets;
use App;
use File;
use Event;
use Request;
use Backend\Classes\FormWidgetBase;
@ -55,6 +57,7 @@ class RichEditor extends FormWidgetBase
*/
public function prepareVars()
{
$this->vars['editorLang'] = $this->getValidEditorLang();
$this->vars['fullPage'] = $this->fullPage;
$this->vars['stretch'] = $this->formField->stretch;
$this->vars['size'] = $this->formField->size;
@ -116,6 +119,29 @@ class RichEditor extends FormWidgetBase
{
$this->addCss('css/richeditor.css', 'core');
$this->addJs('js/build-min.js', 'core');
if ($lang = $this->getValidEditorLang()) {
$this->addJs('vendor/redactor/lang/'.$lang.'.js', 'core');
}
}
/**
* Returns a valid language code for Redactor.
* @return string|mixed
*/
protected function getValidEditorLang()
{
$locale = App::getLocale();
// English is baked in
if ($locale == 'en') {
return null;
}
$locale = str_replace('-', '_', strtolower($locale));
$path = base_path('modules/backend/formwidgets/richeditor/assets/vendor/redactor/lang/'.$locale.'.js');
return File::exists($path) ? $locale : false;
}
/**

File diff suppressed because one or more lines are too long

View File

@ -40,7 +40,8 @@
dataLocker: null,
linksHandler: null,
stylesheet: null,
fullpage: false
fullpage: false,
editorLang: 'en'
}
RichEditor.prototype.init = function() {
@ -68,7 +69,7 @@
* Initialize Redactor editor
*/
var redactorOptions = {
lang: document.documentElement.lang,
lang: this.options.editorLang,
imageEditable: true,
imageResizable: true,
buttonSource: true,
@ -424,23 +425,19 @@
var old = $.fn.richEditor
$.fn.richEditor = function(option) {
$.fn.richEditor = function (option) {
var args = arguments;
return this.each(function() {
return this.each(function () {
var $this = $(this)
var data = $this.data('oc.richEditor')
var options = $.extend({}, RichEditor.DEFAULTS, $this.data(), typeof option == 'object' && option)
if (!data) {
$this.data('oc.richEditor', (data = new RichEditor(this, options)))
}
if (!data) $this.data('oc.richEditor', (data = new RichEditor(this, options)))
if (typeof option == 'string') {
var methodArgs = [];
for (var i=1; i<args.length; i++) {
for (var i=1; i<args.length; i++)
methodArgs.push(args[i])
}
data[option].apply(data, methodArgs)
}

View File

@ -5,6 +5,7 @@
<div
id="<?= $this->getId() ?>"
class="field-richeditor size-<?= $size ?> <?= $stretch?'layout-relative stretch':'' ?>"
<?php if ($editorLang): ?>data-editor-lang="<?= $editorLang ?>"<?php endif ?>
<?php if ($fullPage): ?>data-fullpage="true"<?php endif ?>
data-data-locker="#<?= $this->getId('dataLocker') ?>"
data-links-handler="<?= $this->getEventHandler('onGetPageLinks') ?>"