Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"options.min.js","sources":["../src/options.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Option helper for TinyMCE Editor Manager.\n *\n * @module editor_tiny/options\n * @copyright  2022 Andrew Lyons <andrew@nicols.co.uk>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst optionContextId = 'moodle:contextid';\nconst optionDraftItemId = 'moodle:draftitemid';\nconst filePickers = 'moodle:filepickers';\nconst optionsMoodleLang = 'moodle:language';\nconst currentLanguage = 'moodle:currentLanguage';\nconst optionPlaceholderSelectors = 'moodle:placeholderSelectors';\n\nexport const register = (editor, options) => {\n    const registerOption = editor.options.register;\n    const setOption = editor.options.set;\n\n    registerOption(optionContextId, {\n        processor: 'number',\n        \"default\": 0,\n    });\n    setOption(optionContextId, options.context);\n\n    registerOption(filePickers, {\n        processor: 'object',\n        \"default\": {},\n    });\n    setOption(filePickers, Object.assign({}, options.filepicker));\n\n    registerOption(optionDraftItemId, {\n        processor: 'number',\n        \"default\": 0,\n    });\n    setOption(optionDraftItemId, options.draftitemid);\n\n    registerOption(currentLanguage, {\n        processor: 'string',\n        \"default\": 'en',\n    });\n    setOption(currentLanguage, options.currentLanguage);\n\n    // This is primarily used by the media plugin, but it may be re-used elsewhere so is included here as it is large.\n    registerOption(optionsMoodleLang, {\n        processor: 'object',\n        \"default\": {},\n    });\n    setOption(optionsMoodleLang, options.language);\n\n    registerOption(optionPlaceholderSelectors, {\n        processor: 'array',\n        \"default\": [],\n    });\n    setOption(optionPlaceholderSelectors, options.placeholderSelectors);\n};\n\nexport const getContextId = (editor) => editor.options.get(optionContextId);\nexport const getDraftItemId = (editor) => editor.options.get(optionDraftItemId);\nexport const getFilepickers = (editor) => editor.options.get(filePickers);\nexport const getFilePicker = (editor, type) => getFilepickers(editor)[type];\nexport const getMoodleLang = (editor) => editor.options.get(optionsMoodleLang);\nexport const getCurrentLanguage = (editor) => editor.options.get(currentLanguage);\n\n/**\n * Get a set of namespaced options for all defined plugins.\n *\n * @param {object} options\n * @returns {object}\n */\nexport const getInitialPluginConfiguration = (options) => {\n    const config = {};\n\n    Object.entries(options.plugins).forEach(([pluginName, pluginConfig]) => {\n        const values = Object.entries(pluginConfig.config ?? {});\n        values.forEach(([optionName, value]) => {\n            config[getPluginOptionName(pluginName, optionName)] = value;\n        });\n    });\n\n    return config;\n};\n\n/**\n * Get the namespaced option name for a plugin.\n *\n * @param {string} pluginName\n * @param {string} optionName\n * @returns {string}\n */\nexport const getPluginOptionName = (pluginName, optionName) => `${pluginName}:${optionName}`;\n\n/**\n * Get the placeholder selectors.\n *\n * @param {TinyMCE} editor\n * @returns {array}\n */\nexport const getPlaceholderSelectors = (editor) => editor.options.get(optionPlaceholderSelectors);\n\n/**\n * Register placeholder selectos.\n *\n * @param {TinyMCE} editor\n * @param {array} selectors\n */\nexport const registerPlaceholderSelectors = (editor, selectors) => {\n    if (selectors.length) {\n        let existingData = getPlaceholderSelectors(editor);\n        existingData = existingData.concat(selectors);\n        editor.options.set(optionPlaceholderSelectors, existingData);\n    }\n};\n"],"names":["editor","options","registerOption","register","setOption","set","processor","context","Object","assign","filepicker","draftitemid","currentLanguage","language","placeholderSelectors","get","getFilepickers","type","config","entries","plugins","forEach","_ref","pluginName","pluginConfig","_ref2","optionName","value","getPluginOptionName","getPlaceholderSelectors","selectors","length","existingData","concat"],"mappings":"2bA8BwB,CAACA,OAAQC,iBACvBC,eAAiBF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