Commit 421e3fe7 authored by Mathijs den Burger's avatar Mathijs den Burger

CMS7-7538: upgraded CKEditor to version 4.3.0.1

We now use the special CKEditor-for-Hippo-CMS build maintained at Github.
The raw sources are also included, and used when Wicket runs in development mode.
Otherwise the optimized sources in the 'optimized' subdirectory are used.
parent f363ef81

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -298,6 +298,10 @@ richtext/ckeditor/frontend/target
richtext/ckeditor/plugins/*.iml
richtext/ckeditor/plugins/target
richtext/ckeditor/resources/*.iml
richtext/ckeditor/resources/src/main/resources/ckeditor/*.iml
richtext/ckeditor/resources/src/main/resources/ckeditor/dev
richtext/ckeditor/resources/src/main/resources/ckeditor/optimized/lang/_translationstatus.txt
richtext/ckeditor/resources/src/main/resources/ckeditor/optimized/samples
richtext/ckeditor/resources/src/main/resources/ckeditor/samples
richtext/ckeditor/resources/target
richtext/ckeditor/target
......
......@@ -20,6 +20,8 @@ import java.util.List;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Application;
import org.apache.wicket.RuntimeConfigurationType;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
......@@ -94,7 +96,7 @@ public class CKEditorPanel extends Panel {
super.renderHead(response);
response.render(CssHeaderItem.forReference(CKEDITOR_PANEL_CSS));
response.render(JavaScriptUrlReferenceHeaderItem.forReference(CKEditorConstants.CKEDITOR_JS));
response.render(JavaScriptUrlReferenceHeaderItem.forReference(getCKEditorJsReference()));
response.render(JavaScriptUrlReferenceHeaderItem.forReference(CKEDITOR_PANEL_JS));
JSONObject editorConfig = getConfigurationForEditor();
......@@ -102,6 +104,15 @@ public class CKEditorPanel extends Panel {
response.render(OnDomReadyHeaderItem.forScript(getJavaScriptForEditor(editorConfig)));
}
public static ResourceReference getCKEditorJsReference() {
if (Application.get().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT)) {
log.info("Using non-optimized CKEditor sources.");
return CKEditorConstants.CKEDITOR_SRC_JS;
}
log.info("Using optimized CKEditor sources");
return CKEditorConstants.CKEDITOR_OPTIMIZED_JS;
}
private JSONObject getConfigurationForEditor() {
try {
JSONObject editorConfig = JsonUtils.createJSONObject(editorConfigJson);
......
......@@ -17,7 +17,25 @@
"use strict";
// minimum delay for setTimeout() calls as defined in HTML5 spec
var DOM_MIN_TIMEOUT_MS = 4;
var DOM_MIN_TIMEOUT_MS = 4,
CKEDITOR_READY = new Hippo.Future(function(success) {
var pollTimeoutMillis = DOM_MIN_TIMEOUT_MS;
(function succeedWhenCKEditorIsLoaded() {
if (typeof CKEDITOR.on === 'function') {
if (CKEDITOR.status === 'loaded') {
success();
} else {
CKEDITOR.on('loaded', success);
}
} else {
// try again using exponential backoff
pollTimeoutMillis *= 2;
console.log("Waiting " + pollTimeoutMillis + " ms for CKEditor's event mechanism to load...");
window.setTimeout(succeedWhenCKEditorIsLoaded, pollTimeoutMillis);
}
}());
});
function updateEditorElementWhenDataChanged(editor) {
var data = editor.getData();
......@@ -46,33 +64,37 @@
}
Hippo.createCKEditor = function(elementId, config) {
// queue editor creation
window.setTimeout(function() {
try {
var editor = CKEDITOR.replace(elementId, config);
if (editor !== null) {
updateEditorElementWhenDataChanged(editor);
destroyEditorWhenElementIsDestroyed(editor, elementId);
removeHippoEditorFieldBorder(elementId);
} else {
console.error("CKEditor instance with id '" + elementId + "' was not created");
CKEDITOR_READY.when(function() {
// queue editor creation
window.setTimeout(function() {
try {
var editor = CKEDITOR.replace(elementId, config);
if (editor !== null) {
updateEditorElementWhenDataChanged(editor);
destroyEditorWhenElementIsDestroyed(editor, elementId);
removeHippoEditorFieldBorder(elementId);
} else {
console.error("CKEditor instance with id '" + elementId + "' was not created");
}
} catch (exception) {
console.error("Cannot create CKEditor instance with id '" + elementId + "'", exception);
}
} catch (exception) {
console.error("Cannot create CKEditor instance with id '" + elementId + "'", exception);
}
}, DOM_MIN_TIMEOUT_MS);
}, DOM_MIN_TIMEOUT_MS);
});
};
if (Wicket.Browser.isIE()) {
/*
Replace CKEditor's 'appendStyleText' method. IE chokes on the original because it calls createStyleSheet()
with an empty string as argument. That throws an Error when the page is served by an HTTP server.
*/
CKEDITOR.dom.document.prototype.appendStyleText = function(cssStyleText) {
var style = this.$.createStyleSheet();
style.cssText = cssStyleText;
return style;
};
CKEDITOR_READY.when(function() {
/*
Replace CKEditor's 'appendStyleText' method. IE chokes on the original because it calls createStyleSheet()
with an empty string as argument. That throws an Error when the page is served by an HTTP server.
*/
CKEDITOR.dom.document.prototype.appendStyleText = function(cssStyleText) {
var style = this.$.createStyleSheet();
style.cssText = cssStyleText;
return style;
};
});
}
}(jQuery));
......@@ -42,6 +42,27 @@
<sourceJsFolder>${basedir}/src/main/resources</sourceJsFolder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>create-optimized-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/ckeditor/optimized</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/ckeditor</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
This artifact contains the CKEditor sources, located in 'src/main/resources/ckeditor'.
This artifact contains the CKEditor sources, located in 'src/main/resources/ckeditor',
and the optimized version of these sources, located under 'src/main/resources/ckeditor/optimized'.
Version
-------
The version number of the included CKEditor sources can be found in the changelog file:
The non-optimized sources are only used when Wicket runs in development mode.
src/main/resources/ckeditor/CHANGES.md
Both sources are maintained at Github at https://github.com/onehippo/ckeditor.
Do not modify the sources in this artifact.
The top entry displays the current version.
Version
-------
The version number of the included CKEditor sources can be found in the optimizer ckeditor.js file:
$ grep -Po 'version:"[0-9.]+"' src/main/resources/ckeditor/optimized/ckeditor.js
version:"4.3.0.1"
Updating CKEditor sources
-------------------------
The CKEditor sources can be updated as follows:
When a new tag is available of CKEditor for Hippo CMS, it can replace the sources in this Maven artifact.
The following recipe assumes you start in the directory 'cms/richtext/ckeditor/resources'.
1. Get the tag to copy
1. Go to http://ckeditor.com/builder.
2. Click 'Upload build-config.js' and upload the following file:
$ cd /tmp
$ git clone https://github.com/onehippo/ckeditor.git
$ cd ckeditor
$ git checkout hippo/4.3.0.1
(or another tag)
$ cd -