@@ -810,11 +810,31 @@ sceditor.command.set(
810810sceditor . 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 - z A - Z 0 - 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