From 5c64fec92095754c8441dc68764a9c0d122a006e Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 5 May 2016 15:17:35 +0900 Subject: [PATCH] Auto-detect inherited style in editor if no font is specified --- modules/editor/skins/ckeditor/editor.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/editor/skins/ckeditor/editor.html b/modules/editor/skins/ckeditor/editor.html index 0abe555bf..b485c7a71 100755 --- a/modules/editor/skins/ckeditor/editor.html +++ b/modules/editor/skins/ckeditor/editor.html @@ -46,9 +46,23 @@ var auto_saved_msg = "{$lang->msg_auto_saved}"; $(function(){ CKEDITOR.config.customConfig = ''; + // Import CSS content from PHP. + var css_content = {json_encode($css_content)}; + // Get default font name and list of other supported fonts. var default_font_name = {json_encode($content_font ? trim(array_first(explode(',', $content_font)), '\'" ') : null)}; var default_font_fullname = {json_encode($content_font ?: null)}; + if (default_font_fullname === null && window.getComputedStyle) { + var test_content = $('
').hide().appendTo($(document.body)); + var test_styles = window.getComputedStyle(test_content[0], null); + if (test_styles && test_styles.getPropertyValue) { + default_font_fullname = test_styles.getPropertyValue("font-family"); + if (default_font_fullname) { + default_font_name = $.trim(default_font_fullname.split(',')[0].replace(/['"]/g, '')); + css_content = ".xe_content.editable { font-family:" + default_font_fullname + "; } " + css_content; + } + } + } var font_list = []; font_list.push({json_encode($fontname)}); if (default_font_fullname !== null && !$.inArray(default_font_fullname, font_list)) { @@ -115,7 +129,7 @@ var auto_saved_msg = "{$lang->msg_auto_saved}"; settings.ckeconfig.removeButtons = 'Save,Preview,Print,Cut,Copy,Paste,Source'; - CKEDITOR.addCss('{$css_content}'); + CKEDITOR.addCss(css_content); var ckeApp = $('#ckeditor_instance_{$editor_sequence}').XeCkEditor(settings);