Skip to content

Commit cd0cc88

Browse files
Merge pull request #8879 from jdarwood007/3.0/feature7118
2 parents 918a5bd + c805ac0 commit cd0cc88

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

Sources/BBCode/YouTube.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,23 @@ class YouTube extends BBCode
3737
/**
3838
*
3939
*/
40-
public ?string $content = '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube.com/embed/$1?origin={hosturl}&wmode=opaque" data-youtube-id="$1" allowfullscreen loading="lazy"></iframe></div></div>';
40+
public ?array $parameters = [
41+
'start' => [
42+
'match' => '(\d+)',
43+
'optional' => true,
44+
'default' => '0',
45+
],
46+
];
4147

4248
/**
4349
*
4450
*/
45-
public ?string $disabled_content = '<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener">https://www.youtube.com/watch?v=$1</a>';
51+
public ?string $content = '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube.com/embed/$1?origin={hosturl}&wmode=opaque&start={start}" data-youtube-id="$1" allowfullscreen loading="lazy"></iframe></div></div>';
52+
53+
/**
54+
*
55+
*/
56+
public ?string $disabled_content = '<a href="https://www.youtube.com/watch?v=$1&t={start}s" target="_blank" rel="noopener">https://www.youtube.com/watch?v=$1&t={start}s</a>';
4657

4758
/**
4859
*

Themes/default/scripts/sceditor.plugins.smf.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,31 @@ sceditor.command.set(
810810
sceditor.command.set(
811811
'youtube', {
812812
exec: function (caller) {
813-
var editor = this;
813+
const editor = this;
814814

815-
editor.commands.youtube._dropDown(editor, caller, function (id, time) {
816-
editor.wysiwygEditorInsertHtml('<div class="videocontainer"><div><iframe frameborder="0" allowfullscreen src="https://www.youtube-nocookie.com/embed/' + id + '?wmode=opaque&start=' + time + '" data-youtube-id="' + id + '" loading="lazy"></iframe></div></div>');
815+
editor.commands.youtube._dropDown(editor, caller, function (id, start) {
816+
if (typeof start !== "undefined" && start > 0) {
817+
editor.wysiwygEditorInsertHtml('<div class="videocontainer"><div><iframe frameborder="0" allowfullscreen src="https://www.youtube-nocookie.com/embed/' + id + '?wmode=opaque&start=' + start + '" data-youtube-id="' + id + '" data-start="' + start + '" loading="lazy"></iframe></div></div>');
818+
} else {
819+
editor.wysiwygEditorInsertHtml('<div class="videocontainer"><div><iframe frameborder="0" allowfullscreen src="https://www.youtube-nocookie.com/embed/' + id + '?wmode=opaque" data-youtube-id="' + id + '" loading="lazy"></iframe></div></div>');
820+
}
817821
});
822+
},
823+
txtExec: function (caller) {
824+
const editor = this;
825+
826+
editor.commands.youtube._dropDown(
827+
editor,
828+
caller,
829+
function (id, start) {
830+
if (typeof start !== "undefined" && start > 0) {
831+
editor.insertText('[youtube start=' + start + ']' + id + '[/youtube]');
832+
} else {
833+
editor.insertText('[youtube]' + id + '[/youtube]');
834+
}
835+
836+
}
837+
);
818838
}
819839
}
820840
).set(
@@ -1669,14 +1689,41 @@ sceditor.formats.bbcode.set(
16691689
isInline: false,
16701690
skipLastLineBreak: true,
16711691
format: function (element, content) {
1672-
youtube_id = $(element).find('iframe').data('youtube-id');
1692+
const
1693+
iframe = $(element).find('iframe'),
1694+
youtube_id = iframe.data('youtube-id');
1695+
let attribs = '';
1696+
1697+
if (iframe.attr('data-start')) {
1698+
attribs += " start=" + iframe.attr('data-start');
1699+
}
16731700

16741701
if (typeof youtube_id !== "undefined")
1675-
return '[youtube]' + youtube_id + '[/youtube]';
1702+
return '[youtube' + attribs + ']' + youtube_id + '[/youtube]';
16761703
else
16771704
return content;
16781705
},
1679-
html: '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube-nocookie.com/embed/{0}?wmode=opaque" data-youtube-id="{0}" loading="lazy" allowfullscreen></iframe></div></div>'
1706+
html: function (token, attrs, content) {
1707+
const
1708+
id_match = /^[a-zA-Z0-9_\-]{11}$/g,
1709+
start = typeof attrs.start !== "undefined" ? attrs.start : 0;
1710+
let attribs = '';
1711+
1712+
if (content.match(id_match) === null || (start.length > 0 && !$.isNumeric(start) || Math.floor(start) != +start || +start <= 0)) {
1713+
if (attrs.start !== "undefined") {
1714+
attribs += " start=" + attrs.start;
1715+
}
1716+
1717+
return '[youtube' + attribs + ']' + content + '[/youtube]';
1718+
}
1719+
1720+
if (attrs.start !== "undefined") {
1721+
return '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube-nocookie.com/embed/{0}?wmode=opaque&start=' + attrs.start + '" data-youtube-id="' + content + '" data-start="' + attrs.start + '" loading="lazy" allowfullscreen></iframe></div></div>'
1722+
}
1723+
else {
1724+
return '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube-nocookie.com/embed/{0}?wmode=opaque" data-youtube-id="' + content + '" loading="lazy" allowfullscreen></iframe></div></div>'
1725+
}
1726+
}
16801727
}
16811728
);
16821729

0 commit comments

Comments
 (0)