diff --git a/Sources/BBCode/YouTube.php b/Sources/BBCode/YouTube.php index 6262bdf2e45..190a481b85e 100644 --- a/Sources/BBCode/YouTube.php +++ b/Sources/BBCode/YouTube.php @@ -37,12 +37,23 @@ class YouTube extends BBCode /** * */ - public ?string $content = '
'; + public ?array $parameters = [ + 'start' => [ + 'match' => '(\d+)', + 'optional' => true, + 'default' => '0', + ], + ]; /** * */ - public ?string $disabled_content = 'https://www.youtube.com/watch?v=$1'; + public ?string $content = '
'; + + /** + * + */ + public ?string $disabled_content = 'https://www.youtube.com/watch?v=$1&t={start}s'; /** * diff --git a/Themes/default/scripts/sceditor.plugins.smf.js b/Themes/default/scripts/sceditor.plugins.smf.js index 66242f00984..7e5c3a0a3fb 100644 --- a/Themes/default/scripts/sceditor.plugins.smf.js +++ b/Themes/default/scripts/sceditor.plugins.smf.js @@ -810,11 +810,31 @@ sceditor.command.set( sceditor.command.set( 'youtube', { exec: function (caller) { - var editor = this; + const editor = this; - editor.commands.youtube._dropDown(editor, caller, function (id, time) { - editor.wysiwygEditorInsertHtml('
'); + editor.commands.youtube._dropDown(editor, caller, function (id, start) { + if (typeof start !== "undefined" && start > 0) { + editor.wysiwygEditorInsertHtml('
'); + } else { + editor.wysiwygEditorInsertHtml('
'); + } }); + }, + txtExec: function (caller) { + const editor = this; + + editor.commands.youtube._dropDown( + editor, + caller, + function (id, start) { + if (typeof start !== "undefined" && start > 0) { + editor.insertText('[youtube start=' + start + ']' + id + '[/youtube]'); + } else { + editor.insertText('[youtube]' + id + '[/youtube]'); + } + + } + ); } } ).set( @@ -1669,14 +1689,41 @@ sceditor.formats.bbcode.set( isInline: false, skipLastLineBreak: true, format: function (element, content) { - youtube_id = $(element).find('iframe').data('youtube-id'); + const + iframe = $(element).find('iframe'), + youtube_id = iframe.data('youtube-id'); + let attribs = ''; + + if (iframe.attr('data-start')) { + attribs += " start=" + iframe.attr('data-start'); + } if (typeof youtube_id !== "undefined") - return '[youtube]' + youtube_id + '[/youtube]'; + return '[youtube' + attribs + ']' + youtube_id + '[/youtube]'; else return content; }, - html: '
' + html: function (token, attrs, content) { + const + id_match = /^[a-zA-Z0-9_\-]{11}$/g, + start = typeof attrs.start !== "undefined" ? attrs.start : 0; + let attribs = ''; + + if (content.match(id_match) === null || (start.length > 0 && !$.isNumeric(start) || Math.floor(start) != +start || +start <= 0)) { + if (attrs.start !== "undefined") { + attribs += " start=" + attrs.start; + } + + return '[youtube' + attribs + ']' + content + '[/youtube]'; + } + + if (attrs.start !== "undefined") { + return '
' + } + else { + return '
' + } + } } );