mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
InputfieldCKEditor updates to fix and improve support of CKE contextual settings in Repeater/RepeaterMatrix types
This commit is contained in:
@@ -218,6 +218,26 @@ function ckeSaveReadyNormal($inputfield) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get CKEditor configuration data when $editor element is available
|
||||||
|
*
|
||||||
|
* @param $editor Regular editor <textarea> or inline editor <div> having data-configName attribute
|
||||||
|
* @returns {*}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function ckeGetConfigData($editor) {
|
||||||
|
var configName = $editor.attr('data-configName');
|
||||||
|
if(typeof ProcessWire.config[configName] === 'undefined') {
|
||||||
|
// get from data-configdata attribute and populate to ProcessWire.config
|
||||||
|
if(typeof $editor.attr('data-configdata') !== 'undefined') {
|
||||||
|
ProcessWire.config[configName] = JSON.parse($editor.attr('data-configdata'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var configData = ProcessWire.config[configName];
|
||||||
|
if(typeof configData === 'undefined') configData = {};
|
||||||
|
return configData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mouseover or focus event that activates inline CKEditor instances
|
* Mouseover or focus event that activates inline CKEditor instances
|
||||||
*
|
*
|
||||||
@@ -234,14 +254,13 @@ function ckeInlineMouseoverEvent(event) {
|
|||||||
if($t.hasClass("InputfieldCKEditorLoaded")) return;
|
if($t.hasClass("InputfieldCKEditorLoaded")) return;
|
||||||
$t.effect('highlight', {}, 500);
|
$t.effect('highlight', {}, 500);
|
||||||
$t.attr('contenteditable', 'true');
|
$t.attr('contenteditable', 'true');
|
||||||
var configName = $t.attr('data-configName');
|
|
||||||
if(event.type == 'focusin') {
|
if(event.type == 'focusin') {
|
||||||
CKEDITOR.once('instanceReady', function(event) {
|
CKEDITOR.once('instanceReady', function(event) {
|
||||||
$(':focus').blur();
|
$(':focus').blur();
|
||||||
event.editor.focus();
|
event.editor.focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var editor = CKEDITOR.inline($(this).attr('id'), ProcessWire.config[configName]);
|
var editor = CKEDITOR.inline($t.attr('id'), ckeGetConfigData($t));
|
||||||
ckeInitEvents(editor);
|
ckeInitEvents(editor);
|
||||||
$t.addClass("InputfieldCKEditorLoaded");
|
$t.addClass("InputfieldCKEditorLoaded");
|
||||||
}
|
}
|
||||||
@@ -274,12 +293,12 @@ function ckeInitNormal(editorID) {
|
|||||||
|
|
||||||
var $editor = $('#' + editorID);
|
var $editor = $('#' + editorID);
|
||||||
var $parent = $editor.parent();
|
var $parent = $editor.parent();
|
||||||
|
var configName;
|
||||||
|
|
||||||
if(typeof ProcessWire.config.InputfieldCKEditor.editors[editorID] != "undefined") {
|
if(typeof ProcessWire.config.InputfieldCKEditor.editors[editorID] != "undefined") {
|
||||||
var configName = ProcessWire.config.InputfieldCKEditor.editors[editorID];
|
configName = ProcessWire.config.InputfieldCKEditor.editors[editorID];
|
||||||
} else {
|
} else {
|
||||||
var configName = $editor.attr('data-configName');
|
configName = $editor.attr('data-configName');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($parent.hasClass('ui-tabs-panel') && $parent.css('display') == 'none') {
|
if($parent.hasClass('ui-tabs-panel') && $parent.css('display') == 'none') {
|
||||||
@@ -290,16 +309,8 @@ function ckeInitNormal(editorID) {
|
|||||||
$parent.closest('.ui-tabs, .langTabs').on('tabsactivate', ckeInitTab);
|
$parent.closest('.ui-tabs, .langTabs').on('tabsactivate', ckeInitTab);
|
||||||
} else {
|
} else {
|
||||||
// visible CKEditor
|
// visible CKEditor
|
||||||
var editor;
|
var configData = ckeGetConfigData($editor);
|
||||||
if(typeof ProcessWire.config[configName] != "undefined") {
|
var editor = CKEDITOR.replace(editorID, configData);
|
||||||
var editor = CKEDITOR.replace(editorID, ProcessWire.config[configName]);
|
|
||||||
} else if(typeof $editor.attr('data-configdata') != "undefined") {
|
|
||||||
// allow for alternate option of config data being passed through a data attribute
|
|
||||||
// useful for some dynamic/ajax situations
|
|
||||||
var configData = JSON.parse($editor.attr('data-configdata'));
|
|
||||||
ProcessWire.config[configName] = configData;
|
|
||||||
var editor = CKEDITOR.replace(editorID, configData);
|
|
||||||
}
|
|
||||||
if(editor) {
|
if(editor) {
|
||||||
ckeInitEvents(editor);
|
ckeInitEvents(editor);
|
||||||
$editor.addClass('InputfieldCKEditorLoaded');
|
$editor.addClass('InputfieldCKEditorLoaded');
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -40,10 +40,10 @@ class InputfieldCKEditor extends InputfieldTextarea implements ConfigModule {
|
|||||||
public static function getModuleInfo() {
|
public static function getModuleInfo() {
|
||||||
return array(
|
return array(
|
||||||
'title' => 'CKEditor',
|
'title' => 'CKEditor',
|
||||||
'version' => 168,
|
'version' => 169,
|
||||||
'summary' => __('CKEditor textarea rich text editor.', __FILE__),
|
'summary' => __('CKEditor textarea rich text editor.', __FILE__),
|
||||||
'installs' => array('MarkupHTMLPurifier'),
|
'installs' => array('MarkupHTMLPurifier'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleCleanDIV = 2; // remove <div>s
|
const toggleCleanDIV = 2; // remove <div>s
|
||||||
@@ -529,11 +529,12 @@ class InputfieldCKEditor extends InputfieldTextarea implements ConfigModule {
|
|||||||
//$out = parent::___render() . "<script>CKEDITOR.replace('$this->id', config.$this->configName);</script>";
|
//$out = parent::___render() . "<script>CKEDITOR.replace('$this->id', config.$this->configName);</script>";
|
||||||
$this->addClass('InputfieldCKEditorNormal');
|
$this->addClass('InputfieldCKEditorNormal');
|
||||||
$this->attr('data-configName', $this->configName);
|
$this->attr('data-configName', $this->configName);
|
||||||
|
$script = 'script';
|
||||||
$out = parent::___render() .
|
$out = parent::___render() .
|
||||||
"<script>" .
|
"<$script>" .
|
||||||
"ProcessWire.config.InputfieldCKEditor.editors.$this->id = '$this->configName';" .
|
"ProcessWire.config.InputfieldCKEditor.editors.$this->id = '$this->configName';" .
|
||||||
"config.InputfieldCKEditor.editors.$this->id = '$this->configName';" .
|
"config.InputfieldCKEditor.editors.$this->id = '$this->configName';" .
|
||||||
"</script>";
|
"</$script>";
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,6 +562,13 @@ class InputfieldCKEditor extends InputfieldTextarea implements ConfigModule {
|
|||||||
$attrs['style'] = "overflow:auto;height:$height";
|
$attrs['style'] = "overflow:auto;height:$height";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow for custom data attributes
|
||||||
|
foreach($this->getAttributes() as $attrName => $attrVal) {
|
||||||
|
if(strpos($attrName, 'data-') !== 0) continue;
|
||||||
|
if(isset($attrs[$attrName])) continue;
|
||||||
|
$attrs[$attrName] = $attrVal;
|
||||||
|
}
|
||||||
|
|
||||||
$attrs = $this->getAttributesString($attrs);
|
$attrs = $this->getAttributesString($attrs);
|
||||||
$out =
|
$out =
|
||||||
"<div $attrs>$value</div>" .
|
"<div $attrs>$value</div>" .
|
||||||
|
Reference in New Issue
Block a user