Skip to content

Commit

Permalink
Fixed issue #12349: RTL languages not dispayed correctly in the admin…
Browse files Browse the repository at this point in the history
… editor (#1879)

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed May 20, 2021
1 parent 243ee17 commit 76b17d7
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 30 deletions.
2 changes: 2 additions & 0 deletions application/config/internal.php
Expand Up @@ -275,6 +275,7 @@
'checkPermission' => 'LS_Twig_Extension::checkPermission',/* Not in 3.X */
'getAllQuestionClasses' => 'LS_Twig_Extension::getAllQuestionClasses',
'getLanguageNameFromCode' => 'getLanguageNameFromCode',/* Not in 3.X */
'getLanguageRTL' => 'LS_Twig_Extension::getLanguageRTL',

'intval' => 'intval',
'empty' => 'empty',
Expand Down Expand Up @@ -360,6 +361,7 @@
),
'functions' => array(
'getLanguageData',
'getLanguageRTL',
'array_flip',
'array_intersect_key',

Expand Down
1 change: 1 addition & 0 deletions application/controllers/admin/htmleditor_pop.php
Expand Up @@ -37,6 +37,7 @@ public function index()
$aData['sControlIdDis'] = $aData['sFieldName'] . '_popupctrldis';
$aData['toolbarname'] = 'popup';
$aData['htmlformatoption'] = '';
$aData['contentsLangDirection'] = sanitize_xss_string(App()->request->getQuery('contdir'));
if (in_array($aData['sFieldType'], array('email-invitation', 'email-registration', 'email-confirmation', 'email-reminder'))) {
$aData['htmlformatoption'] = ',fullPage:true';
}
Expand Down
9 changes: 9 additions & 0 deletions application/core/LS_Twig_Extension.php
Expand Up @@ -676,4 +676,13 @@ public static function getAllTokenAnswers($iSurveyID)

return $aResponses;
}

/**
* Returns true if the language uses RTL writing system.
*/
public static function getLanguageRTL($sLanguageCode)
{
Yii::app()->loadHelper('surveytranslator');
return getLanguageRTL($sLanguageCode);
}
}
32 changes: 20 additions & 12 deletions application/helpers/admin/htmleditor_helper.php
Expand Up @@ -288,18 +288,26 @@ function getInlineEditor($fieldtype, $fieldname, $fieldtext, $surveyID = null, $
$('#" . $fieldname . "').before('$loaderHTML');
$oCKeditorVarName = CKEDITOR.replace('$fieldname', {
LimeReplacementFieldsType : \"" . $fieldtype . "\"
,LimeReplacementFieldsSID : \"" . $surveyID . "\"
,LimeReplacementFieldsGID : \"" . $gID . "\"
,LimeReplacementFieldsQID : \"" . $qID . "\"
,LimeReplacementFieldsAction : \"" . $action . "\"
,LimeReplacementFieldsPath : \"" . Yii::app()->getController()->createUrl("limereplacementfields/index") . "\"
,language:'" . sTranslateLangCode2CK(Yii::app()->session['adminlang']) . "'"
. $sFileBrowserAvailable
. $htmlformatoption
. $toolbaroption
. "});
var ckeConfig = {
LimeReplacementFieldsType : \"" . $fieldtype . "\"
,LimeReplacementFieldsSID : \"" . $surveyID . "\"
,LimeReplacementFieldsGID : \"" . $gID . "\"
,LimeReplacementFieldsQID : \"" . $qID . "\"
,LimeReplacementFieldsAction : \"" . $action . "\"
,LimeReplacementFieldsPath : \"" . Yii::app()->getController()->createUrl("limereplacementfields/index") . "\"
,language:'" . sTranslateLangCode2CK(Yii::app()->session['adminlang']) . "'"
. $sFileBrowserAvailable
. $htmlformatoption
. $toolbaroption
. "};
// Override language direction if 'data-contents-dir' attribute is set in the target field
if ($('#" . $fieldname . "').get(0).hasAttribute('data-contents-dir')) {
var inputLangDirection = $('#" . $fieldname . "').attr('data-contents-dir');
ckeConfig.contentsLangDirection = inputLangDirection ? inputLangDirection : '';
}
$oCKeditorVarName = CKEDITOR.replace('$fieldname', ckeConfig);
\$('#$fieldname').parents('ul:eq(0)').addClass('editor-parent');
}";
Expand Down
2 changes: 2 additions & 0 deletions application/views/admin/htmleditor/pop_editor_view.php
Expand Up @@ -41,6 +41,7 @@ function closeme()
*/
if($('textarea').length > 0){
CKEDITOR.on('instanceReady',CKeditor_OnComplete);

var oCKeditor = CKEDITOR.replace( 'MyTextarea' , { height : '350',
width : '98%',
toolbarStartupExpanded : true,
Expand All @@ -53,6 +54,7 @@ function closeme()
LimeReplacementFieldsAction: "<?php echo $sAction; ?>",
LimeReplacementFieldsPath : "<?php echo $this->createUrl("/limereplacementfields/index"); ?>",
language : "<?php echo $ckLanguage ?>"
<?php echo !is_null($contentsLangDirection) ? ",contentsLangDirection: '{$contentsLangDirection}'" : ''; ?>
<?php echo $htmlformatoption; ?> });
}
});
Expand Down
13 changes: 11 additions & 2 deletions application/views/admin/survey/prepareEditorScript_view.php
Expand Up @@ -60,10 +60,19 @@ function start_popup_editor(fieldname, fieldtext, sid, gid, qid, fieldtype, acti
if (activepopup == null)
{
document.getElementById(fieldname).readOnly=true;
var targetField = document.getElementById(fieldname);
targetField.readOnly=true;
document.getElementById(controlidena).style.display='none';
document.getElementById(controliddis).style.display='';
popup = window.open('".$this->createUrl('admin/htmleditor_pop/sa/index')."/name/'+fieldname+'/text/'+fieldtext+'/type/'+fieldtype+'/action/'+action+'/sid/'+sid+'/gid/'+gid+'/qid/'+qid+'/lang/".App()->language."','', 'location=no, status=yes, scrollbars=auto, menubar=no, resizable=yes, width=690, height=500');
var editorurl = '".$this->createUrl('admin/htmleditor_pop/sa/index')."/name/'+fieldname+'/text/'+fieldtext+'/type/'+fieldtype+'/action/'+action+'/sid/'+sid+'/gid/'+gid+'/qid/'+qid+'/lang/".App()->language."';
// Override language direction if 'data-contents-dir' attribute is set in the target field
if (targetField.hasAttribute('data-contents-dir')) {
var inputLangDirection = targetField.getAttribute('data-contents-dir');
editorurl = editorurl + '/contdir/' + (inputLangDirection ? inputLangDirection : '');
}
popup = window.open(editorurl,'', 'location=no, status=yes, scrollbars=auto, menubar=no, resizable=yes, width=690, height=500');
editorwindowsHash[fieldname] = popup;
}
Expand Down
Expand Up @@ -115,6 +115,7 @@
id='answeroptions[{{ answerOption.aid }}][{{ scale_id }}][answeroptionl10n][{{ language }}]'
name='answeroptions[{{ answerOption.aid }}][{{ scale_id }}][answeroptionl10n][{{ language }}]'
placeholder='{{ gT("Some example answer option") }}'
data-contents-dir="{{ getLanguageRTL(language) ? 'rtl' : 'ltr' }}"
value="{{ answerOptionl10n.answer|escape('html_attr') }}"
/>
<span class="input-group-addon">
Expand Down
Expand Up @@ -112,6 +112,7 @@
name='subquestions[{{ subquestion.qid }}][{{ scale_id }}][subquestionl10n][{{ language }}]'
placeholder='{{ gT("Some example subquestion","js") }}'
value="{{ subquestionl10n.question|escape('html_attr') }}"
data-contents-dir="{{ getLanguageRTL(language) ? 'rtl' : 'ltr' }}"
onkeypress=" if(event.keyCode==13) { if (event && event.preventDefault) event.preventDefault(); document.getElementById('save-button').click(); return false;}"
/>
<span class="input-group-addon">
Expand Down
16 changes: 14 additions & 2 deletions application/views/questionAdministration/textElements.php
Expand Up @@ -16,7 +16,13 @@
<?= CHtml::textArea(
"questionI10N[$lang][question]",
$question->questionl10ns[$lang]->question ?? '',
array('class'=>'form-control','cols'=>'60','rows'=>'8','id'=>"question_{$lang}")
[
'class' => 'form-control',
'cols' => '60',
'rows' => '8',
'id' => "question_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr'
]
); ?>
<?= getEditor(
'question-text',//"question_" . $lang, //this is important for LimereplacementfieldsController function getReplacementFields(...)!
Expand All @@ -39,7 +45,13 @@
<?= CHtml::textArea(
"questionI10N[$lang][help]",
$question->questionl10ns[$lang]->help ?? '',
array('class'=>'form-control','cols'=>'60','rows'=>'4','id'=>"help_{$lang}")
[
'class' => 'form-control',
'cols' => '60',
'rows' => '4',
'id' => "help_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr'
]
); ?>
<?= getEditor(
"help_".$lang,
Expand Down
37 changes: 23 additions & 14 deletions assets/packages/modaleditor/js/modaleditor.js
Expand Up @@ -45,22 +45,31 @@ var ModalEditor = function () {
settings = ckSettings || {};

CKEDITOR.on('instanceReady',CKeditor_OnComplete);

ckeConfig = {
height: '200',
width: '98%',
toolbarStartupExpanded: true,
ToolbarCanCollapse: false,
toolbar: settings.toolbar || 'inline',
LimeReplacementFieldsSID : settings.sid,
LimeReplacementFieldsGID : settings.gid,
LimeReplacementFieldsQID : settings.qid,
//LimeReplacementFieldsType: "",
//LimeReplacementFieldsAction: "",
LimeReplacementFieldsPath : settings.replacementFieldsPath,
language : settings.language,
};

// Override language direction if 'data-contents-dir' attribute is set in the target field
if ($(targetField).get(0).hasAttribute('data-contents-dir')) {
var inputLangDirection = $(targetField).attr('data-contents-dir');
ckeConfig.contentsLangDirection = inputLangDirection ? inputLangDirection : '';
}

oCKeditor = CKEDITOR.replace(
'htmleditor-modal-textarea',
{
height: '200',
width: '98%',
toolbarStartupExpanded: true,
ToolbarCanCollapse: false,
toolbar: settings.toolbar || 'inline',
LimeReplacementFieldsSID : settings.sid,
LimeReplacementFieldsGID : settings.gid,
LimeReplacementFieldsQID : settings.qid,
//LimeReplacementFieldsType: "",
//LimeReplacementFieldsAction: "",
LimeReplacementFieldsPath : settings.replacementFieldsPath,
language : settings.language,
}
ckeConfig
);
};

Expand Down

0 comments on commit 76b17d7

Please sign in to comment.