1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
|
function ckeGetProcessWireConfig(editor){var editorName=typeof editor=="string"?editor:editor.name;var configName=editorName.replace("Inputfield_","InputfieldCKEditor_");var $repeaterItem="";var settings={};configName=configName.replace("Inputfield_","InputfieldCKEditor_");if(typeof ProcessWire.config[configName]=="undefined"&&configName.indexOf("_repeater")>0){configName=configName.replace(/_repeater[0-9]+/,"");$repeaterItem=$("#"+editorName).closest(".InputfieldRepeaterItem")}if(typeof ProcessWire.config[configName]=="undefined"&&configName.indexOf("_ckeditor")>0){configName=configName.replace(/_ckeditor$/,"")}if(typeof ProcessWire.config[configName]=="undefined"&&configName.indexOf("__")>0){configName=configName.replace(/__\d+$/,"")}if(typeof ProcessWire.config[configName]=="undefined"){settings.error="Cannot find CKEditor settings for "+configName}else{settings=ProcessWire.config[configName]}if($repeaterItem.length){settings["repeaterItem"]=$repeaterItem}else{settings["repeaterItem"]=""}return settings}function ckeLoadPlugins(){for(var name in ProcessWire.config.InputfieldCKEditor.plugins){var file=ProcessWire.config.InputfieldCKEditor.plugins[name];CKEDITOR.plugins.addExternal(name,file,"")}}ckeLoadPlugins();function ckeBlurEvent(event){var editor=event.editor;var $textarea=$(editor.element.$);if(editor.checkDirty()){if($textarea.length){if($textarea.is("textarea"))$textarea.trigger("change");$textarea.closest(".Inputfield").addClass("InputfieldStateChanged")}}}function ckeFocusEvent(event){var editor=event.editor;var $textarea=$(editor.element.$);$textarea.trigger("pw-focus")}function ckeResizeEvent(event){var editor=event.editor;var $textarea=$(editor.element.$);if($textarea.length){$textarea.closest(".Inputfield").trigger("heightChanged")}}function ckeUploadEvent(event){var xhr=event.data.fileLoader.xhr;var fileLoader=event.data.fileLoader;var settings=ckeGetProcessWireConfig(event.editor);var uploadFieldName=settings?settings.pwUploadField:"_unknown";var $imageInputfield=$("#Inputfield_"+uploadFieldName);if(typeof settings.repeaterItem!="undefined"&&settings.repeaterItem.length){var $repeaterImageField=settings.repeaterItem.find(".InputfieldImage:not(.InputfieldFileSingle)");if($repeaterImageField.length)$imageInputfield=$repeaterImageField}if($imageInputfield.length){xhr.open("POST",fileLoader.uploadUrl,true);$imageInputfield.trigger("pwimageupload",{name:fileLoader.fileName,file:fileLoader.file,xhr:xhr});event.stop()}else{if(typeof settings.error!="undefined"&&settings.error.length){ProcessWire.alert(settings.error)}else{ProcessWire.alert("Unable to find images field for upload")}event.stop();return false}}function ckeInitEvents(editor){editor.on("blur",ckeBlurEvent);editor.on("focus",ckeFocusEvent);editor.on("change",ckeBlurEvent);editor.on("resize",ckeResizeEvent);editor.on("fileUploadRequest",ckeUploadEvent,null,null,4);var $textarea=$(editor.element.$);var $inputfield=$textarea.closest(".Inputfield.InputfieldColumnWidth");if($inputfield.length)setTimeout(function(){$inputfield.trigger("heightChanged")},1e3)}function ckeSaveReadyInline($inputfield){if(!$inputfield.length)return;var $inlines=$inputfield.hasClass(".InputfieldCKEditorInline")?$inputfield:$inputfield.find(".InputfieldCKEditorInline");if($inlines.length)$inlines.each(function(){var $t=$(this);var value;if($t.hasClass("InputfieldCKEditorLoaded")){var editor=CKEDITOR.instances[$t.attr("id")];if(typeof editor!="undefined"){if(editor.focusManager.hasFocus){editor.focusManager.focus(true);editor.focus()}value=editor.getData()}}else{value=$t.html()}var $input=$t.next("input");$input.attr("value",value)})}function ckeSaveReadyNormal($inputfield){var $normals=$inputfield.hasClass("InputfieldCKEditorNormal")?$inputfield:$inputfield.find(".InputfieldCKEditorNormal");$normals.each(function(){var $t=$(this);if(!$t.hasClass("InputfieldCKEditorLoaded"))return;var editor=CKEDITOR.instances[$t.attr("id")];editor.updateElement()})}function ckeGetConfigData($editor){var configName=$editor.attr("data-configName");if(typeof ProcessWire.config[configName]==="undefi
|