Skip to content

Commit

Permalink
Merge branch 'release/1.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
sten committed Oct 10, 2022
2 parents 7cca024 + 4d56c0e commit b195193
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/sir-trevor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
75 changes: 75 additions & 0 deletions resources/js/sir-trevor/blocks/iframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
SirTrevor.Blocks.Iframe = (function() {

return SirTrevor.Block.extend({

regex_src : /(?:<iframe)(?:.+)(?:src="){1}([^"].+?)(?:")(?:.+)(?:<\/iframe>)/i,
regex_width : /(?:<iframe)(?:.+)(?:width="){1}([^"].+?)(?:")(?:.+)(?:<\/iframe>)/i,
regex_height : /(?:<iframe)(?:.+)(?:height="){1}([^"].+?)(?:")(?:.+)(?:<\/iframe>)/i,

type : 'iframe',

icon_name : 'iframe',

title : function() {
return "Iframe";
},

toolbarEnabled : true,

droppable : false,

pastable : true,

paste_options : {
html : '<input type="text" placeholder="<iframe>" class="st-block__paste-input st-paste-block">'
},

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(
$('<iframe>')
.attr('src', data.src)
.attr('class', 'st-block-embed')
.attr('width', data.width)
.attr('height', data.height)
);

this.ready();
},
});

})();
1 change: 1 addition & 0 deletions src/SirTrevor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function includeScripts()
$html .= HTML::script("js/sir-trevor/blocks/rich_text.js") . PHP_EOL;
$html .= HTML::script("js/sir-trevor/blocks/image_extended.js") . PHP_EOL;
$html .= HTML::script("js/quill/quill.js") . PHP_EOL;
$html .= HTML::script("js/sir-trevor/blocks/iframe.js") . PHP_EOL;

return $html.view('sirtrevor::js', ['config' => $config]);
}
Expand Down

0 comments on commit b195193

Please sign in to comment.