@@ -968,11 +968,31 @@ sceditor.command.set(
968968sceditor . command . set (
969969 'youtube' , {
970970 exec : function ( caller ) {
971- var editor = this ;
971+ const editor = this ;
972972
973- editor . commands . youtube . _dropDown ( editor , caller , function ( id , time ) {
974- 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>' ) ;
973+ editor . commands . youtube . _dropDown ( editor , caller , function ( id , start ) {
974+ if ( typeof start !== "undefined" && start > 0 ) {
975+ 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>' ) ;
976+ } else {
977+ 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>' ) ;
978+ }
975979 } ) ;
980+ } ,
981+ txtExec : function ( caller ) {
982+ const editor = this ;
983+
984+ editor . commands . youtube . _dropDown (
985+ editor ,
986+ caller ,
987+ function ( id , start ) {
988+ if ( typeof start !== "undefined" && start > 0 ) {
989+ editor . insertText ( '[youtube start=' + start + ']' + id + '[/youtube]' ) ;
990+ } else {
991+ editor . insertText ( '[youtube]' + id + '[/youtube]' ) ;
992+ }
993+
994+ }
995+ ) ;
976996 }
977997 }
978998) ;
@@ -1853,14 +1873,41 @@ sceditor.formats.bbcode.set(
18531873 isInline : false ,
18541874 skipLastLineBreak : true ,
18551875 format : function ( element , content ) {
1856- youtube_id = $ ( element ) . find ( 'iframe' ) . data ( 'youtube-id' ) ;
1876+ const
1877+ iframe = $ ( element ) . find ( 'iframe' ) ,
1878+ youtube_id = iframe . data ( 'youtube-id' ) ;
1879+ let attribs = '' ;
1880+
1881+ if ( iframe . attr ( 'data-start' ) ) {
1882+ attribs += " start=" + iframe . attr ( 'data-start' ) ;
1883+ }
18571884
18581885 if ( typeof youtube_id !== "undefined" )
1859- return '[youtube]' + youtube_id + '[/youtube]' ;
1886+ return '[youtube' + attribs + ' ]' + youtube_id + '[/youtube]' ;
18601887 else
18611888 return content ;
18621889 } ,
1863- 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>'
1890+ html : function ( token , attrs , content ) {
1891+ const
1892+ id_match = / ^ [ a - z A - Z 0 - 9 _ \- ] { 11 } $ / g,
1893+ start = typeof attrs . start !== "undefined" ? attrs . start : 0 ;
1894+ let attribs = '' ;
1895+
1896+ if ( content . match ( id_match ) === null || ( start . length > 0 && ! $ . isNumeric ( start ) || Math . floor ( start ) != + start || + start <= 0 ) ) {
1897+ if ( attrs . start !== "undefined" ) {
1898+ attribs += " start=" + attrs . start ;
1899+ }
1900+
1901+ return '[youtube' + attribs + ']' + content + '[/youtube]' ;
1902+ }
1903+
1904+ if ( attrs . start !== "undefined" ) {
1905+ 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>'
1906+ }
1907+ else {
1908+ 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>'
1909+ }
1910+ }
18641911 }
18651912) ;
18661913
0 commit comments