<commit_before>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.ui.input.tinymce;

import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.CmsTinyMceToolbarHelper;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

/**
 * Helper class for dealing wth TinyMCE widgets.<p>
 */
public final class CmsTinyMCEHelper {

    /**
     * Hidden default constructor.<p>
     */
    private CmsTinyMCEHelper() {
        // nothing here
    }

    /**
     * Generate options for TinyMCE.<p>
     *
     * @param configuration the widget configuration generated by the server
     *
     * @return the TinyMCE configuration
     */
    public static JavaScriptObject generateOptionsForTiny(String configuration) {

        return generateOptionsForTiny(configuration, getCodeMirrorPath());
    }

    /**
    * Generates the tinyMCE editor options according to the configuration.<p>
    *
    * @param configuration the widget configuration
    * @param codeMirrorPath the path to the CodeMirror editor
    *
    * @return the tinyMCE options
    */
    public static native JavaScriptObject generateOptionsForTiny(String configuration, String codeMirrorPath)/*-{

		var options = null;
		try {
			var config = @org.opencms.gwt.client.util.CmsDomUtil::parseJSON(Ljava/lang/String;)(configuration);
			options = {
				entity_encoding : 'named',
				entities : '160,nbsp',
				// the browser call back function is defined in /system/workplace/editors/tinymce/opencms_plugin.js
				file_picker_callback : $wnd.cmsTinyMceFileBrowser
			};
			if (config.downloadGalleryConfig) {
				options.downloadGalleryConfig = config.downloadGalleryConfig;
			}

			if (config.imageGalleryConfig) {
				options.imageGalleryConfig = config.imageGalleryConfig;
			}

			if (config.language) {
                var languageMap = { "it": "it_IT", "cs": "cs_CZ", "ru": "ru_RU", "zh": "zh_CN"};
                var translatedLanguage = languageMap[config.language];
                if (translatedLanguage) {
                    options.language = translatedLanguage;
                } else {
				    options.language = config.language;
				}
			}
			if (config.content_css) {
				options.content_css = config.content_css;
			}
			options.importcss_append = true;
			if (config.importCss) {
				options.importcss_selector_filter = ""; // always matches
			} else {
				options.importcss_selector_filter = new $wnd.RegExp("$.^"); // never matches
			}
			if (config.height) {
				var height = parseInt(config.height);
				if (height != NaN) {
					options.editorHeight = height;
				}
			}
			if (config.block_formats) {
				options.block_formats = config.block_formats;
			}
			if (config.style_formats) {
				var temp = null;
				try {
					temp = eval('(' + config.style_formats + ')');
				} catch (error) {
					$wnd.alert("Could not parse WYSIWYG editor options: "
							+ error);
				}
				if (typeof temp != 'undefined' && temp != null) {
					options.style_formats = temp;
				}
			}
			if (config.cmsGalleryEnhancedOptions) {
				options.cmsGalleryEnhancedOptions = config.cmsGalleryEnhancedOptions;
			}
			if (config.cmsGalleryUseThickbox) {
				options.cmsGalleryUseThickbox = config.cmsGalleryUseThickbox;
			}
			options.plugins = "anchor charmap importcss autolink lists pagebreak table save hr codemirror image link emoticons insertdatetime preview media searchreplace print paste directionality fullscreen noneditable visualchars nonbreaking template wordcount advlist spellchecker -opencms";
			if (config.fullpage) {<commit_msg>Fixed problem where TinyMCE style menu became unreadable because it used colors from the page itself (github issue #645).<commit_after>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.gwt.client.ui.input.tinymce;

import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.CmsTinyMceToolbarHelper;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

/**
 * Helper class for dealing wth TinyMCE widgets.<p>
 */
public final class CmsTinyMCEHelper {

    /**
     * Hidden default constructor.<p>
     */
    private CmsTinyMCEHelper() {

        // nothing here
    }

    /**
     * Generate options for TinyMCE.<p>
     *
     * @param configuration the widget configuration generated by the server
     *
     * @return the TinyMCE configuration
     */
    public static JavaScriptObject generateOptionsForTiny(String configuration) {

        return generateOptionsForTiny(configuration, getCodeMirrorPath());
    }

    /**
    * Generates the tinyMCE editor options according to the configuration.<p>
    *
    * @param configuration the widget configuration
    * @param codeMirrorPath the path to the CodeMirror editor
    *
    * @return the tinyMCE options
    */
    public static native JavaScriptObject generateOptionsForTiny(String configuration, String codeMirrorPath)/*-{

		var options = null;
		try {
			var config = @org.opencms.gwt.client.util.CmsDomUtil::parseJSON(Ljava/lang/String;)(configuration);
			options = {
				entity_encoding : 'named',
				entities : '160,nbsp',
				// the browser call back function is defined in /system/workplace/editors/tinymce/opencms_plugin.js
				file_picker_callback : $wnd.cmsTinyMceFileBrowser
			};
			if (config.downloadGalleryConfig) {
				options.downloadGalleryConfig = config.downloadGalleryConfig;
			}

			if (config.imageGalleryConfig) {
				options.imageGalleryConfig = config.imageGalleryConfig;
			}

			if (config.language) {
                var languageMap = { "it": "it_IT", "cs": "cs_CZ", "ru": "ru_RU", "zh": "zh_CN"};
                var translatedLanguage = languageMap[config.language];
                if (translatedLanguage) {
                    options.language = translatedLanguage;
                } else {
				    options.language = config.language;
				}
			}
			if (config.content_css) {
				options.content_css = config.content_css;
			}
			options.importcss_append = true;
			if (config.importCss) {
				options.importcss_selector_filter = ""; // always matches
			} else {
				options.importcss_selector_filter = new $wnd.RegExp("$.^"); // never matches
			}
			if (config.height) {
				var height = parseInt(config.height);
				if (height != NaN) {
					options.editorHeight = height;
				}
			}
			if (config.block_formats) {
				options.block_formats = config.block_formats;
			}
			if (config.style_formats) {
				var temp = null;
				try {
					temp = eval('(' + config.style_formats + ')');
				} catch (error) {
					$wnd.alert("Could not parse WYSIWYG editor options: "
							+ error);
				}
				if (typeof temp != 'undefined' && temp != null) {
					options.style_formats = temp;
				}
			}
			if (config.cmsGalleryEnhancedOptions) {
				options.cmsGalleryEnhancedOptions = config.cmsGalleryEnhancedOptions;
			}
			if (config.cmsGalleryUseThickbox) {
				options.cmsGalleryUseThickbox = config.cmsGalleryUseThickbox;
			}
			options.plugins = "anchor charmap importcss autolink lists pagebreak table save hr codemirror image link emoticons insertdatetime preview media searchreplace print paste directionality fullscreen noneditable visualchars nonbreaking template wordcount advlist spellchecker -opencms";
			options.preview_styles="font-family font-size font-weight font-style text-decoration text-transform border border-radius outline text-shadow";
			if (config.fullpage) {
{'fraction_non_alphanumeric': 0.09328168008971353, 'fraction_numerical': 0.004179834845550005, 'mean_word_length': 3.3311258278145695, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5013192', 'n_tokens_mistral': 3212, 'n_tokens_neox': 2815, 'n_words': 834}