Created
September 14, 2017 14:09
-
-
Save jbawgs/d2a97e71b299314b2a2f089a84fc0afc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A script for use in a Visualforce page to override RichText inputFields with an expanded CKEditor | |
//values we need from the old editor | |
var instanceName; | |
var uploadURL; | |
var extraPlugins; | |
//the default editor exists in our scope as the variable 'editor' | |
//get the name of the text area element the editor lives in | |
instanceName = editor.name; | |
//add an event that launches our code when the editor instance is loaded | |
editor.on('instanceReady', reInitEditor()); | |
function reInitEditor() { | |
//test if the value we need is null | |
if (editor.config.filebrowserImageUploadUrl) { | |
//Assign the values we need for our new editor instance | |
uploadUrl = editor.config.filebrowserImageUploadUrl; | |
xtraPlugins = editor.config.extraPlugins; | |
//DESTROY ! | |
editor.destroy(true); | |
//Init our new editor instance with config. Configuring the editor is well documented at http://docs.ckeditor.com/ | |
editor = CKEDITOR.replace(instanceName, { | |
removePlugins: 'image', | |
toolbar: [ | |
{ | |
name: 'clipboard', | |
items: ['Undo', 'Redo'] | |
}, | |
{ | |
name: 'styles', | |
items: ['Format', 'Font', 'FontSize'] | |
}, | |
{ | |
name: 'basicstyles', | |
items: ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', 'CopyFormatting'] | |
}, | |
{ | |
name: 'colors', | |
items: ['TextColor', 'BGColor'] | |
}, | |
{ | |
name: 'align', | |
items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] | |
}, | |
{ | |
name: 'links', | |
items: ['Link', 'Unlink'] | |
}, | |
{ | |
name: 'paragraph', | |
items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote'] | |
}, | |
{ | |
name: 'insert', | |
items: ['sfdcImage', 'sfdcMediaEmbed', 'Table', 'CodeSnippet'] | |
}, | |
{ | |
name: 'tools', | |
items: ['Maximize'] | |
}, | |
{ | |
name: 'editing', | |
items: ['Scayt'] | |
}, | |
{ | |
name: 'document', | |
items: ['Print', 'Source'] | |
} | |
], | |
customConfig: '', | |
extraAllowedContent: 'iframe', | |
//xtraPlugins is a value we saved from the old instance to load the SF proprietary plugins | |
extraPlugins: xtraPlugins + ',autoembed,embed,codesnippet', | |
//This is a mess but necessary for SF plugins to function | |
sfdcLabels: { | |
CkeMediaEmbed: { | |
iframeMissing: 'Invalid <iframe> element. Please use valid code from the approved sites.', | |
description: 'Use <iframe> code from DailyMotion, Vimeo, and Youtube.', | |
title: 'Embed Multimedia Content', | |
exampleTitle: 'Example:', | |
subtitle: 'Paste &lt;iframe&gt; code here:', | |
example: '\n \n <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/KcOm0TNvKBA\" frameborder=\"0\" allowfullscreen></iframe>\n \n ' | |
}, | |
CkeImagePaste: { | |
CkeImagePasteWarning: 'Pasting an image is not working properly with Firefox, please use [Copy Image location] instead.' | |
}, | |
CkeImageDialog: { | |
infoTab_desc_info: 'Enter a description of the image for visually impaired users', | |
uploadTab_desc: 'Description', | |
defaultImageDescription: 'User-added image', | |
uploadTab_file_info: 'Maximum size 1 MB. Only png, gif or jpeg', | |
uploadTab_desc_info: 'Enter a description of the image for visually impaired users', | |
imageUploadLimit_info: 'Max number of upload images exceeded', | |
btn_insert_tooltip: 'Insert Image', | |
httpUrlWarning: 'Are you sure you want to use an HTTP URL? Using HTTP image URLs may result in security warnings about insecure content. To avoid these warnings, use HTTPS image URLs instead.', | |
title: 'Insert Image', | |
error: 'Error:', | |
uploadTab: 'Upload Image', | |
wrongFileTypeError: 'You can insert only .gif .jpeg and .png files.', | |
infoTab_url: 'URL', | |
infoTab: 'Web Address', | |
infoTab_url_info: 'Example: http://www.mysite.com/myimage.jpg', | |
missingUrlError: 'You must enter a URL', | |
uploadTab_file: 'Select Image', | |
btn_update_tooltip: 'Update Image', | |
infoTab_desc: 'Description', | |
btn_insert: 'Insert', | |
btn_update: 'Update', | |
btn_upadte: 'Update', | |
invalidUrlError: 'You can only use http:, https:, data:, //, /, or relative URL schemes.' | |
}, | |
sfdcSwitchToText: { | |
sfdcSwitchToTextAlt: 'Use plain text' | |
} | |
}, | |
//load up the URL and token from the old editor instance | |
filebrowserImageUploadUrl: uploadUrl, | |
codeSnippet_theme: 'monokai_sublime', | |
contentsCss: [ 'https://cdn.ckeditor.com/4.6.1/standard-all/contents.css'], | |
removeDialogTabs: 'image:advanced;', | |
embed_provider: '//noembed.com/embed?url={url}&callback={callback}' | |
}); | |
} else { | |
//Our IF test failed so we wait 50 millis | |
setTimeout(reInitEditor, 50); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment