Mercurial Hosting > freedit
view src/test/tiny.html @ 28:d9d7aa2a79db
more video types
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Jul 2022 23:44:49 -0600 |
parents | 6871eec2cf4c |
children | 8ff35379cc89 |
line wrap: on
line source
<!doctype html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="http://tinymce.luan.software/tinymce.min.js" xreferrerpolicy="origin"></script> <style> </style> <script> function videoIframe(url) { return '<iframe data-video="'+url+'" width="560" height="315" frameborder="0" allowfullscreen src="'+url+'"></iframe>'; } var videoHandlers = {}; { let ptn1 = new RegExp('https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?'); let ptn2 = new RegExp('https://www.youtube.com/watch\\?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?'); videoHandlers.youtube = function(url) { let result = url.match(ptn1) || url.match(ptn2); if( result ) { url = 'https://www.youtube.com/embed/' + result[1]; if( result[2] ) url += '?start=' + result[2]; return videoIframe(url); } } } { let ptn = new RegExp('https://rumble.com/embed/[a-z0-9]+/\\?pub=[a-z0-9]+'); videoHandlers.rumble = function(url) { if( url.match(ptn) ) { return videoIframe(url); } } } { let ptn = new RegExp('https://www.bitchute.com/video/([a-zA-Z0-9]+)/'); videoHandlers.bitchute = function(url) { let result = url.match(ptn); if( result ) { url = 'https://www.bitchute.com/embed/' + result[1]; return videoIframe(url); } } } { let ptn = new RegExp('https://vimeo.com/([0-9]+)'); videoHandlers.vimeo = function(url) { let result = url.match(ptn); if( result ) { url = 'https://player.vimeo.com/video/' + result[1]; return videoIframe(url); } } } { let ptn = new RegExp('https://dai.ly/([a-z0-9]+)'); videoHandlers.dailymotion = function(url) { let result = url.match(ptn); if( result ) { url = 'https://www.dailymotion.com/embed/video/' + result[1]; return videoIframe(url); } } } { let ptn = new RegExp('https://www.tiktok.com/[^/]+/video/([0-9]+)'); videoHandlers.tiktok = function(url) { let result = url.match(ptn); if( result ) { let html = '<blockquote class="tiktok-embed" data-video-id="'+result[1]+'" style="max-width: 560px; margin-left: 0;"><section></section></blockquote>'; //html += '<script async src="https://www.tiktok.com/embed.js"></'+'script>'; return html; } } } { let ptn = new RegExp('\\.[a-zA-Z0-9]+$'); videoHandlers.file = function(url) { if( url.match(ptn) ) { return '<video controls width="560" height><source src="'+url+'"></video>'; } } } function videoUrlToHtml(url) { for (let key in videoHandlers) { let handle = videoHandlers[key]; let html = handle(url); if(html) return html; } return '<a data-video="'+url+'" href="'+url+'">'+url+'</a>'; } console.log(videoUrlToHtml('https://www.tiktok.com/@chantelleef/video/7112118342181276933?is_from_webapp=1&sender_device=pc&web_id=7073254106622838318')); function media_url_resolver(data,resolve,reject) { let html = videoUrlToHtml(data.url); resolve({ html: html }); } function tinymceSetup(editor) { editor.ui.registry.addToggleButton('styleCode', { icon: 'sourcecode', tooltip: 'Code', onAction: function(api) { editor.execCommand('mceToggleFormat', false, 'code') }, onSetup: function(api) { api.setActive(editor.formatter.match('code')); let changed = editor.formatter.formatChanged('code', api.setActive); return function() { changed.unbind(); }; } }); editor.ui.registry.addMenuButton('styleText', { icon: 'format', tooltip: 'Text', fetch: function(callback) { callback([ 'fontsize', 'forecolor', ]) } }); editor.on( 'init', function(e) {editor.focus()} ); } tinymce.init({ selector: 'textarea', setup: tinymceSetup, //menubar: false, statusbar: false, toolbar: 'link image media | styleCode bold italic underline strikethrough superscript styleText | blockquote numlist bullist', plugins: ['link', 'image', 'media', 'lists', 'code', 'autoresize'], autoresize_bottom_margin: 0, link_target_list: false, link_title: false, image_description: false, image_dimensions: false, object_resizing: false, contextmenu: false, media_alt_source: false, media_dimensions: false, media_poster: false, media_url_resolver: media_url_resolver, text_patterns: false, content_style: 'img {max-width: 500px;} p {margin: 0}', //newline_behavior: 'linebreak', extended_valid_elements: 'b,i', formats: { bold: { inline: 'b' }, italic: {inline: 'i'}, underline: {inline: 'u'}, }, }); function log() { console.log(tinymce.activeEditor.getContent()); } </script> </head> <body> <p><a href="https://www.tiny.cloud/">TinyMCE</a></p> <textarea></textarea> <p><button onclick="log()">log</button></p> </body> </html>