3 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 2.1 of the License, or (at your option)
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17 <%@ include file="/html/taglib/init.jsp" %>
20 String portletId = portletDisplay.getRootPortletId();
22 String mainPath = themeDisplay.getPathMain();
24 String doAsUserId = themeDisplay.getDoAsUserId();
26 if (Validator.isNull(doAsUserId)) {
27 doAsUserId = Encryptor.encrypt(company.getKeyObj(), String.valueOf(themeDisplay.getUserId()));
30 long doAsGroupId = themeDisplay.getDoAsGroupId();
32 String ckEditorConfigFileName = ParamUtil.getString(request, "ckEditorConfigFileName", "ckconfig.jsp");
34 boolean useCustomDataProcessor = false;
36 if (!ckEditorConfigFileName.equals("ckconfig.jsp")) {
37 useCustomDataProcessor = true;
40 boolean hideImageResizing = ParamUtil.getBoolean(request, "hideImageResizing");
42 Map<String, String> configParamsMap = (Map<String, String>)request.getAttribute("liferay-ui:input-editor:configParams");
43 Map<String, String> fileBrowserParamsMap = (Map<String, String>)request.getAttribute("liferay-ui:input-editor:fileBrowserParams");
45 String configParams = marshallParams(configParamsMap);
46 String fileBrowserParams = marshallParams(fileBrowserParamsMap);
48 String cssClass = GetterUtil.getString((String)request.getAttribute("liferay-ui:input-editor:cssClass"));
49 String cssClasses = GetterUtil.getString((String)request.getAttribute("liferay-ui:input-editor:cssClasses"));
50 String editorImpl = (String)request.getAttribute("liferay-ui:input-editor:editorImpl");
51 String name = namespace + GetterUtil.getString((String)request.getAttribute("liferay-ui:input-editor:name"));
52 String initMethod = (String)request.getAttribute("liferay-ui:input-editor:initMethod");
54 String onChangeMethod = (String)request.getAttribute("liferay-ui:input-editor:onChangeMethod");
56 if (Validator.isNotNull(onChangeMethod)) {
57 onChangeMethod = namespace + onChangeMethod;
60 boolean resizable = GetterUtil.getBoolean((String)request.getAttribute("liferay-ui:input-editor:resizable"));
61 boolean skipEditorLoading = GetterUtil.getBoolean((String)request.getAttribute("liferay-ui:input-editor:skipEditorLoading"));
62 String toolbarSet = (String)request.getAttribute("liferay-ui:input-editor:toolbarSet");
65 <c:if test="<%= hideImageResizing %>">
66 <liferay-util:html-top outputKey="js_editor_ckeditor_hide_image_resizing">
67 <style type="text/css">
68 td.cke_dialog_ui_hbox_first {
69 display:none !important;
72 td.cke_dialog_footer td.cke_dialog_ui_hbox_first {
73 display:block !important;
77 display: none !important;
80 a.cke_dialog_tab_selected {
81 display:block !important;
84 </liferay-util:html-top>
87 <c:if test="<%= !skipEditorLoading %>">
88 <liferay-util:html-top outputKey="js_editor_ckeditor_skip_editor_loading">
89 <style type="text/css">
91 position: absolute !important;
96 long javaScriptLastModified = ServletContextUtil.getLastModified(application, "/html/js/", true);
99 <script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNHost() + themeDisplay.getPathJavaScript() + "/editor/ckeditor/ckeditor.js", javaScriptLastModified)) %>" type="text/javascript"></script>
101 <script type="text/javascript">
102 Liferay.namespace('EDITORS')['<%= editorImpl %>'] = true;
104 </liferay-util:html-top>
108 window['<%= name %>'] = {
109 destroy: function() {
110 CKEDITOR.instances['<%= name %>'].destroy();
112 delete window['<%= name %>'];
116 CKEDITOR.instances['<%= name %>'].focus();
119 getCkData: function() {
120 var data = CKEDITOR.instances['<%= name %>'].getData();
122 if (CKEDITOR.env.gecko && (CKEDITOR.tools.trim(data) == '<br />')) {
129 getHTML: function() {
130 return window['<%= name %>'].getCkData();
133 getText: function() {
134 return window['<%= name %>'].getCkData();
138 if (Validator.isNotNull(onChangeMethod)) {
141 onChangeCallback: function () {
142 var ckEditor = CKEDITOR.instances['<%= name %>'];
143 var dirty = ckEditor.checkDirty();
146 <%= HtmlUtil.escapeJS(onChangeMethod) %>(window['<%= name %>'].getText());
148 ckEditor.resetDirty();
156 setHTML: function(value) {
157 CKEDITOR.instances['<%= name %>'].setData(value);
162 <div class="<%= cssClass %>">
163 <textarea id="<%= name %>" name="<%= name %>" style="display: none;"></textarea>
169 <c:if test="<%= Validator.isNotNull(initMethod) %>">
170 ckEditor.setData(<%= HtmlUtil.escapeJS(namespace + initMethod) %>());
175 StringBundler sb = new StringBundler(10);
178 sb.append("/portal/fckeditor?p_l_id=");
180 sb.append("&p_p_id=");
181 sb.append(HttpUtil.encodeURL(portletId));
182 sb.append("&doAsUserId=");
183 sb.append(HttpUtil.encodeURL(doAsUserId));
184 sb.append("&doAsGroupId=");
185 sb.append(HttpUtil.encodeURL(String.valueOf(doAsGroupId)));
186 sb.append(fileBrowserParams);
188 String connectorURL = HttpUtil.encodeURL(sb.toString());
194 customConfig: '<%= PortalUtil.getPathContext() %>/html/js/editor/ckeditor/<%= HtmlUtil.escapeJS(ckEditorConfigFileName) %>?p_l_id=<%= plid %>&p_p_id=<%= HttpUtil.encodeURL(portletId) %>&p_main_path=<%= HttpUtil.encodeURL(mainPath) %>&doAsUserId=<%= HttpUtil.encodeURL(doAsUserId) %>&doAsGroupId=<%= HttpUtil.encodeURL(String.valueOf(doAsGroupId)) %>&cssPath=<%= HttpUtil.encodeURL(themeDisplay.getPathThemeCss()) %>&cssClasses=<%= HttpUtil.encodeURL(cssClasses) %>&imagesPath=<%= HttpUtil.encodeURL(themeDisplay.getPathThemeImages()) %>&languageId=<%= HttpUtil.encodeURL(LocaleUtil.toLanguageId(locale)) %>&resizable=<%= resizable %><%= configParams %>',
195 filebrowserBrowseUrl: '<%= PortalUtil.getPathContext() %>/html/js/editor/ckeditor/editor/filemanager/browser/liferay/browser.html?Connector=<%= connectorURL %><%= fileBrowserParams %>',
196 filebrowserUploadUrl: null,
197 toolbar: '<%= TextFormatter.format(HtmlUtil.escapeJS(toolbarSet), TextFormatter.M) %>'
201 var ckEditor = CKEDITOR.instances['<%= name %>'];
203 var customDataProcessorLoaded = false;
206 if (useCustomDataProcessor) {
210 'customDataProcessorLoaded',
212 customDataProcessorLoaded = true;
224 var instanceReady = false;
231 if (useCustomDataProcessor) {
234 instanceReady = true;
236 if (customDataProcessorLoaded) {
250 if (Validator.isNotNull(onChangeMethod)) {
256 window['<%= name %>'].onChangeCallback();
275 public String marshallParams(Map<String, String> params) {
276 StringBundler sb = new StringBundler();
278 if (params != null) {
279 for (Map.Entry<String, String> configParam : params.entrySet()) {
280 sb.append(StringPool.AMPERSAND);
281 sb.append(configParam.getKey());
282 sb.append(StringPool.EQUAL);
283 sb.append(HttpUtil.encodeURL(configParam.getValue()));
287 return sb.toString();