Rev 1 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
{"version":3,"file":"commands.min.js","sources":["../src/commands.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 * Tiny Media commands.\n *\n * @module tiny_media/commands\n * @copyright 2022 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getStrings} from
'core/str';\nimport {\n component,\n imageButtonName,\n videoButtonName,\n mediaManagerButtonName\n} from './common';\nimport MediaImage from './image';\nimport MediaEmbed from './embed';\nimport MediaManager from './manager';\nimport {getButtonImage} from 'editor_tiny/utils';\nimport Selectors from './selectors';\n\nconst isImage = (node) => node.nodeName.toLowerCase() === 'img';\nconst isVideo = (node) => node.nodeName.toLowerCase() === 'video' || node.nodeName.toLowerCase() === 'audio';\n\nconst registerImageCommand = (editor, imageButtonText) => {\n const imageIcon = 'image';\n const handleImageAction = () => {\n const mediaImage = new MediaImage(editor);\n mediaImage.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n // This means that when highlighted over an existing Media Image element it will show as toggled on.\n editor.ui.registry.addToggleButton(imageButtonName, {\n icon: imageIcon,\n tooltip: imageButtonText,\n
onAction: handleImageAction,\n onSetup: api => {\n return editor.selection.selectorChangedWithUnbind(\n 'img:not([data-mce-object]):not([data-mce-placeholder]),figure.image',\n api.setActive\n ).unbind;\n }\n });\n\n editor.ui.registry.addMenuItem(imageButtonName, {\n icon: imageIcon,\n text: imageButtonText,\n onAction: handleImageAction,\n });\n\n editor.ui.registry.addContextToolbar(imageButtonName, {\n predicate: isImage,\n items: imageButtonName,\n position: 'node',\n scope: 'node'\n });\n\n editor.ui.registry.addContextMenu(imageButtonName, {\n update: isImage,\n });\n\n // Let's check for image file at dragged and dropped and add img-fluid class if it does't have it yet.\n editor.on('SetContent', function() {\n const imgs = editor.getBody().querySelectorAll(`img:not(.${Selectors.IMAGE.styles.responsive})`);\n imgs.forEach(img => img.classLis
t.add(`${Selectors.IMAGE.styles.responsive}`));\n });\n};\n\nconst registerEmbedCommand = (editor, videoButtonText) => {\n const videoIcon = 'embed';\n const handleEmbedAction = () => {\n const mediaImage = new MediaEmbed(editor);\n mediaImage.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n // This means that when highlighted over an existing Media Video element it will show as toggled on.\n editor.ui.registry.addToggleButton(videoButtonName, {\n icon: videoIcon,\n tooltip: videoButtonText,\n onAction: handleEmbedAction,\n onSetup: api => {\n return editor.selection.selectorChangedWithUnbind(\n 'video:not([data-mce-object]):not([data-mce-placeholder]),' +\n 'audio:not([data-mce-object]):not([data-mce-placeholder]),' +\n 'a:not([data-mce-object]):not([data-mce-placeholder])[class=external-media-provider]',\n api.setActive\n ).unbind;\n }
\n });\n\n editor.ui.registry.addMenuItem(videoButtonName, {\n icon: videoIcon,\n text: videoButtonText,\n onAction: handleEmbedAction,\n });\n\n editor.ui.registry.addContextMenu(videoButtonName, {\n update: isVideo,\n });\n\n editor.ui.registry.addContextToolbar(videoButtonName, {\n predicate: isVideo,\n items: videoButtonName,\n position: 'node',\n scope: 'node'\n });\n\n};\n\nconst registerManagerCommand = (editor, mediaManagerButtonText, mediaManagerButtonImage) => {\n const mediaManagerIcon = 'filemanager';\n const handleMediaManager = () => {\n const mediaManager = new MediaManager(editor);\n mediaManager.displayDialogue();\n };\n\n // Register the Menu Button as a toggle.\n editor.ui.registry.addIcon(mediaManagerIcon, mediaManagerButtonImage.html);\n editor.ui.registry.addButton(mediaManagerButtonName, {\n icon: mediaManagerIcon,\n tooltip: mediaManagerButtonText,\n onActi
on: () => {\n handleMediaManager();\n }\n });\n\n editor.ui.registry.addMenuItem(mediaManagerButtonName, {\n icon: mediaManagerIcon,\n text: mediaManagerButtonText,\n onAction: () => {\n handleMediaManager();\n }\n });\n};\n\nexport const getSetup = async() => {\n const [\n imageButtonText,\n mediaButtonText,\n mediaManagerButtonText\n ] = await getStrings(['imagebuttontitle', 'mediabuttontitle', 'mediamanagerbuttontitle'].map((key) => ({key, component})));\n\n const [\n mediaManagerButtonImage,\n ] = await Promise.all([\n getButtonImage('filemanager', component)\n ]);\n\n // Note: The function returned here must be synchronous and cannot use promises.\n // All promises must be resolved prior to returning the function.\n return (editor) => {\n registerImageCommand(editor, imageButtonText);\n registerEmbedCommand(editor, mediaButtonText);\n registerManagerCommand(ed
itor, mediaManagerButtonText, mediaManagerButtonImage);\n };\n};\n"],"names":["isImage","node","nodeName","toLowerCase","isVideo","async","imageButtonText","mediaButtonText","mediaManagerButtonText","map","key","component","mediaManagerButtonImage","Promise","all","editor","handleImageAction","MediaImage","displayDialogue","ui","registry","addToggleButton","imageButtonName","icon","tooltip","onAction","onSetup","api","selection","selectorChangedWithUnbind","setActive","unbind","addMenuItem","text","addContextToolbar","predicate","items","position","scope","addContextMenu","update","on","getBody","querySelectorAll","Selectors","IMAGE","styles","responsive","forEach","img","classList","add","registerImageCommand","videoButtonText","handleEmbedAction","MediaEmbed","videoButtonName","registerEmbedCommand","handleMediaManager","MediaManager","addIcon","html","addButton","mediaManagerButtonName","registerManagerCommand"],"mappings":";;;;;;;gQAoCMA,QAAWC,MAAyC,QAAhCA,KAAKC,SAASC,cAClCC,QAAWH,MAAyC,UAAhCA,KAAKC,S
AASC,eAA6D,UAAhCF,KAAKC,SAASC,gCAmH3DE,gBAEhBC,gBACAC,gBACAC,8BACM,mBAAW,CAAC,mBAAoB,mBAAoB,2BAA2BC,KAAKC,OAAUA,IAAAA,IAAKC,UAAAA,wBAGzGC,+BACMC,QAAQ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