AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"embedthumbnailpreview.min.js","sources":["../../src/embed/embedthumbnailpreview.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 plugin embed thumbnail preview class.\n *\n * This handles:\n * - Embed thumbnail preview.\n * - Delete thumbnail preview.\n * - Update the embed preview details with new thumbnail
.\n *\n * @module tiny_media/embed/mediathumbnail\n * @copyright 2024 Stevani Andolo <stevani@hotmail.com.au>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Selectors from '../selectors';\nimport {getString} from 'core/str';\nimport {\n sourceTypeChecked,\n setPropertiesFromData,\n showElements,\n stopMediaLoading,\n} from '../helpers';\nimport Notification from 'core/notification';\nimport {EmbedPreview} from './embedpreview';\nimport {mediaDetailsTemplateContext} from './embedhelpers';\nimport {EmbedHandler} from './embedhandler';\nimport {component} from '../common';\n\nexport class EmbedThumbnailPreview {\n\n constructor(data) {\n setPropertiesFromData(this, data); // Creates dynamic properties based on \"data\" param.\n }\n\n /**\n * Init the media thumbnail preview.\n *\n * @param {object} mediaData Object of selected media data\n */\n init = (mediaData) => {\n this.mediaData = mediaData;\n thi
s.currentModal.uploadThumbnailModal.setTitle(getString('thumbnail', component));\n sourceTypeChecked({\n source: this.media.poster,\n root: this.thumbnailModalRoot,\n fileNameSelector: Selectors.EMBED.elements.fileNameLabel,\n });\n this.setThumbnailSource();\n this.registerMediaThumbnailEventListeners();\n };\n\n /**\n * Sets media thumbnail source.\n */\n setThumbnailSource = () => {\n const thumbnailPreview = this.thumbnailModalRoot.querySelector(Selectors.EMBED.elements.thumbnailPreview);\n thumbnailPreview.src = this.media.poster;\n\n thumbnailPreview.addEventListener('error', async() => {\n // Show warning notification.\n const urlWarningLabelEle = this.thumbnailModalRoot.querySelector(Selectors.EMBED.elements.urlWarning);\n urlWarningLabelEle.innerHTML = await getString('imageurlrequired', component);\n showElements(Selectors.EMBED.elements.urlWarning, this.thu
mbnailModalRoot);\n\n // Stop the spinner.\n stopMediaLoading(this.thumbnailModalRoot, Selectors.EMBED.type);\n\n // Reset the upload form.\n (new EmbedHandler(this)).resetUploadForm(false);\n });\n\n thumbnailPreview.addEventListener('load', () => {\n this.mediaData.media.poster = this.media.poster;\n this.media = this.mediaData.media;\n stopMediaLoading(this.thumbnailModalRoot, Selectors.EMBED.type);\n });\n };\n\n /**\n * Deletes the media after confirming with the user and loads the insert media page.\n */\n deleteMedia = () => {\n Notification.deleteCancelPromise(\n getString('deletemediathumbnail', component),\n getString('deletemediathumbnailwarning', component)\n ).then(() => {\n (new EmbedHandler(this)).resetUploadForm(false);\n return;\n }).catch(error => {\n window.console.log(error);\n });\n };\n\n
/**\n * Loads and displays a media preview with thumbnail.\n */\n loadPreviewMediaThumbnail = async() => {\n (new EmbedHandler(this)).loadMediaDetails(new EmbedPreview(this), await mediaDetailsTemplateContext(this))\n .then(() => {\n // Close the thumbnail upload modal once media details have been loaded.\n this.currentModal.uploadThumbnailModal.destroy();\n const currentModal = this.currentModal.insertMediaModal;\n this.currentModal = currentModal.insertMediaModal;\n delete this.mediaData;\n return;\n }).catch(error => {\n window.console.log(error);\n });\n };\n\n /**\n * Only registers event listeners for new loaded elements in mediaThumbnail.\n */\n registerMediaThumbnailEventListeners = () => {\n // Handles delete thumbnail.\n const deleteMedia = this.thumbnailModalRoot.querySelector(Selectors.EMBED.actions.deleteThumbnail);\n if (deleteMedia) {\n
deleteMedia.addEventListener('click', (e) => {\n e.preventDefault();\n this.deleteMedia();\n });\n }\n\n // Handles setting the media poster.\n const setPoster = this.thumbnailModalRoot.querySelector(Selectors.EMBED.actions.setPoster);\n if (setPoster) {\n setPoster.addEventListener('click', () => {\n this.loadPreviewMediaThumbnail();\n });\n }\n };\n}\n"],"names":["constructor","data","mediaData","currentModal","uploadThumbnailModal","setTitle","component","source","this","media","poster","root","thumbnailModalRoot","fileNameSelector","Selectors","EMBED","elements","fileNameLabel","setThumbnailSource","registerMediaThumbnailEventListeners","thumbnailPreview","querySelector","src","addEventListener","async","urlWarning","innerHTML","type","EmbedHandler","resetUploadForm","deleteCancelPromise","then","catch","error","window","console","log","loadMediaDetails","EmbedPreview","destroy","i
nsertMediaModal","deleteMedia","actions","deleteThumbnail","e","preventDefault","setPoster","loadPreviewMediaThumbnail"],"mappings":"8vBA4CIA,YAAYC,mCASJC,iBACCA,UAAYA,eACZC,aAAaC,qBAAqBC,UAAS,kBAAU,YAAaC,mDACrD,CACdC,OAAQC,KAAKC,MAAMC,OACnBC,KAAMH,KAAKI,mBACXC,iBAAkBC,mBAAUC,MAAMC,SAASC,qBAE1CC,0BACAC,qFAMY,WACXC,iBAAmBZ,KAAKI,mBAAmBS,cAAcP,mBAAUC,MAAMC,SAASI,kBACxFA,iBAAiBE,IAAMd,KAAKC,MAAMC,OAElCU,iBAAiBG,iBAAiB,SAASC,UAEZhB,KAAKI,mBAAmBS,cAAcP,mBAAUC,MAAMC,SAASS,YACvEC,gBAAkB,kBAAU,mBAAoBpB,6CACtDQ,mBAAUC,MAAMC,SAASS,WAAYjB,KAAKI,kDAGtCJ,KAAKI,mBAAoBE,mBAAUC,MAAMY,UAGrDC,2BAAapB,MAAOqB,iBAAgB,MAG7CT,iBAAiBG,iBAAiB,QAAQ,UACjCrB,UAAUO,MAAMC,OAASF,KAAKC,MAAMC,YACpCD,MAAQD,KAAKN,UAAUO,oCACXD,KAAKI,mBAAoBE,mBAAUC,MAAMY,gDAOpD,2BACGG,qBACT,kBAAU,uBAAwBxB,oBAClC,kBAAU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