// Jodit import type { IJodit } from 'jodit/types'; // Style import './unsplash.less'; import { Basic } from 'unsplash-js/dist/methods/users/types'; import { unsplashApi } from 'jodit/src/modules/widget/search-selector/ImageMediaList'; // Main Section interface MediaSource { url: string; width: number; height: number; } export class MediaItem { element: HTMLElement; constructor( editor: IJodit, imageThumb: MediaSource, image?: string, alt?: string | null, close?: () => void, user?: Basic, downloadUrl?: string ) { this.element = editor.c.fromHTML( `
${ user ? `
${user?.username}
` : '' }
` ); this.element.style.gridRowEnd = `span ${Math.ceil( (imageThumb.height * 114) / imageThumb.width / 10 )}`; this.element.style.marginBottom = '4px'; // const img = this.element.querySelector('img'); // if (img) { // img.style.height = `${imageThumb.height}px`; // img.style.width = `${imageThumb.width}`; // } // this.element.appendChild( // editor.c.fromHTML( // `` // ) // ); // imageDom.style.height = `${ // (imageThumb.height * 114) / imageThumb.width // }px`; // this.element.firstChild?.appendChild(imageDom); // const masonry = document.querySelector('.masonry'); // if (masonry) { // // const masonryContainerStyle = getComputedStyle(masonry); // // const columnGap = parseInt( // // masonryContainerStyle.getPropertyValue('column-gap') // // ); // // document.querySelectorAll('.masonry-item').forEach(elm => { // // const htmlElm = elm as HTMLElement; // // const gridRowEnd = `span ${Math.ceil(htmlElm.offsetHeight)}`; // // console.log(gridRowEnd); // // htmlElm.style.gridRowEnd = gridRowEnd; // // }); // } this.element.addEventListener('click', () => { // const elm = j.createInside.element(tagName); const img = editor.c.fromHTML( `

${alt}

${ user ? `

Photo By ${user?.username} On Unsplash

` : '' }

` ); // const img = editor.c.fromHTML( // `

${alt}

` // ); editor.s.insertHTML(img); unsplashApi.photos.trackDownload({ downloadLocation: `${downloadUrl}&client_id=1xrBCfio58yQDy39-MQxsm8_ZG1nSacRlmfI0bcIKK0` }); if (close) close(); }); } }