From 4d56c0e775dcebe41e118aab2cc20ddfa4d3eb4b Mon Sep 17 00:00:00 2001 From: sten Date: Mon, 10 Oct 2022 15:29:44 +0200 Subject: [PATCH] Add iframe block --- config/sir-trevor.php | 2 +- resources/js/sir-trevor/blocks/iframe.js | 75 ++++++++++++++++++++++++ src/SirTrevor.php | 1 + 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 resources/js/sir-trevor/blocks/iframe.js diff --git a/config/sir-trevor.php b/config/sir-trevor.php index 3d9f09c..9110006 100644 --- a/config/sir-trevor.php +++ b/config/sir-trevor.php @@ -4,7 +4,7 @@ 'class' => 'sir-trevor', - 'blocktypes' => ['Text', 'List', 'Quote', 'Video', 'Tweet', 'Heading', 'RichText', 'ImageExtended'], + 'blocktypes' => ['Text', 'List', 'Quote', 'Video', 'Tweet', 'Heading', 'RichText', 'ImageExtended', 'Iframe'], 'js_path' => '/js/sir-trevor/sir-trevor.js', diff --git a/resources/js/sir-trevor/blocks/iframe.js b/resources/js/sir-trevor/blocks/iframe.js new file mode 100644 index 0000000..91f191c --- /dev/null +++ b/resources/js/sir-trevor/blocks/iframe.js @@ -0,0 +1,75 @@ +SirTrevor.Blocks.Iframe = (function() { + + return SirTrevor.Block.extend({ + + regex_src : /(?:)/i, + regex_width : /(?:)/i, + regex_height : /(?:)/i, + + type : 'iframe', + + icon_name : 'iframe', + + title : function() { + return "Iframe"; + }, + + toolbarEnabled : true, + + droppable : false, + + pastable : true, + + paste_options : { + html : '' + }, + + onContentPasted : function(event) { + this.loading(); + + obj = {}; + + val = $(event.target).val(); + + match_src = this.regex_src.exec(val); + + if (match_src !== null && !_.isUndefined(match_src[1])) { + obj.src = match_src[1]; + + match_width = val.match(this.regex_width); + + if (match_width !== null && !_.isUndefined(match_width[1])) { + obj.width = match_width[1]; + } + + match_height = val.match(this.regex_height); + + if (match_height !== null && !_.isUndefined(match_height[1])) { + obj.height = match_height[1]; + } + + this.setAndLoadData(obj); + } + }, + + uploadable : false, + + formattable : false, + + loadData : function(data) { + data.width = (typeof data.width == undefined || !data.width) ? '100%' : data.width; + data.height = (typeof data.height == undefined || !data.height) ? '100%' : data.height; + + this.$inner.prepend( + $('