* eMail/api: attempt to fix the focus on body issue with FF; thanks to CKEditor support

This commit is contained in:
Klaus Leithoff 2013-03-04 11:53:53 +00:00
parent 472f262eb1
commit 62541c2c42
3 changed files with 28 additions and 41 deletions

View File

@ -739,7 +739,7 @@
#if (isset($GLOBALS['egw_info']['server']['enabled_spellcheck'])) $mode = 'egw_simple_spellcheck';
$style="border:0px; width:100%; height:400px;";
// dont run purify, as we already did that (getCleanHTML).
$this->t->set_var('tinymce', html::fckEditorQuick('body', $mode, $sessionData['body'],'400px','100%',false));
$this->t->set_var('tinymce', html::fckEditorQuick('body', $mode, $sessionData['body'],'400px','100%',false,'0px',($_focusElement=='body'?true:false)));
$this->t->set_var('mimeType', 'html');
$ishtml=1;
} else {

View File

@ -230,23 +230,12 @@ if (toFocus=='body')
{
'instanceReady': function (ev) {
CKEDITOR.instances.body.focus();
var ckeditor = CKEDITOR.instances['body'];
var s = ckeditor.getSelection();
if (typeof s != 'undefined')
{
var selected_ranges = s.getRanges()[0]; // save selected range
// do something
//var spanCont = selected_ranges.startContainer.getAscendant({ span: 1, div: 1});
//var newRange = new CKEDIOR.dom.range(selected_ranges);
//newRange.setStart(spanCont,selected_ranges.StartOffset);
//newRange.setEnd(spanCont,selected_ranges.StartOffset+50);
//newRange.select();
//s.selectRanges(selected_ranges); // restore it
}
else
{
document.doit.fm_compose_subject.focus();
}
var d = CKEDITOR.document;
var r = new CKEDITOR.dom.range(d);
r.collapse(true);
r.selectNodeContents(d.getBody());
r.collapse(true);
r.select();
}
}
});
@ -256,26 +245,12 @@ if (toFocus=='body')
{
'pluginsLoaded': function (ev) {
CKEDITOR.instances.body.focus();
var ckeditor = CKEDITOR.instances['body'];
var s = ckeditor.getSelection();
if (typeof s != 'undefined')
{
var selected_ranges = s.getRanges()[0]; // save selected range
// do something
if (typeof selected_ranges != undefined)
{
//var spanCont = selected_ranges.startContainer.getAscendant({ span: 1, div: 1});
//var newRange = new CKEDIOR.dom.range(selected_ranges);
//newRange.setStart(spanCont,selected_ranges.StartOffset);
//newRange.setEnd(spanCont,selected_ranges.StartOffset+50);
//newRange.select();
//s.selectRanges(selected_ranges); // restore it
}
}
else
{
document.doit.fm_compose_subject.focus();
}
var d = CKEDITOR.document;
var r = new CKEDITOR.dom.range(d);
r.collapse(true);
r.selectNodeContents(d.getBody());
r.collapse(true);
r.select();
}
}
});

View File

@ -498,10 +498,11 @@ class html
* @param string $_width='100%'
* @param string $_start_path='' if passed activates the browser for image at absolute path passed
* @param boolean $_purify=true run $_content through htmlpurifier before handing it to fckEditor
* @param mixed (boolean/string) $_focusToBody USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
* @return string the necessary html for the textarea
*/
static function fckEditor($_name, $_content, $_mode, $_options=array('toolbar_expanded' =>'true'),
$_height='400px', $_width='100%',$_start_path='',$_purify=true)
$_height='400px', $_width='100%',$_start_path='',$_purify=true, $_focusToBody=false)
{
if (!self::htmlarea_availible() || $_mode == 'ascii')
{
@ -541,6 +542,16 @@ class html
"instanceReady",
function (ev)
{
'.($_focusToBody?'
ev.editor.focus();
var d = ev.editor.document;
var r = new CKEDITOR.dom.range(d);
r.collapse(true);
r.selectNodeContents(d.getBody());
r.collapse('.($_focusToBody==='BOTTOM'?'false':'true').');
r.select();
':'').
'
ev.editor.resize("100%", '.str_replace('px', '', $pxheight).');
}
);'.
@ -561,9 +572,10 @@ class html
* @param string $_width='100%'
* @param boolean $_purify=true
* @param string $_border='0px' NOT used for CKEditor
* @param mixed (boolean/string) $_focusToBody USED only for CKEDIOR true means yes, focus on top, you may specify TOP or BOTTOM (to focus on the end of the editor area)
* @return string the necessary html for the textarea
*/
static function fckEditorQuick($_name, $_mode, $_content='', $_height='400px', $_width='100%',$_purify=true, $_border='0px')
static function fckEditorQuick($_name, $_mode, $_content='', $_height='400px', $_width='100%',$_purify=true, $_border='0px',$_focusToBody=false)
{
if (!self::htmlarea_availible() || $_mode == 'ascii')
{
@ -572,7 +584,7 @@ class html
}
else
{
return self::fckEditor($_name, $_content, $_mode, array(), $_height, $_width,'',$_purify);
return self::fckEditor($_name, $_content, $_mode, array(), $_height, $_width,'',$_purify,$_focusToBody);
}
}