X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fludivine-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fplugins%2Fhtml5audio%2Fplugin.js;fp=sources%2Fplugins%2Fhtml5audio%2Fplugin.js;h=86bcfbd32e5494754ef9f23a7cbb90fbfb07a173;hp=0000000000000000000000000000000000000000;hb=d1844275460a3e3a32e199326f6b36938a329091;hpb=eaa9271590ab73b6eef3fa88bc74a9553eefd857 diff --git a/sources/plugins/html5audio/plugin.js b/sources/plugins/html5audio/plugin.js new file mode 100644 index 0000000..86bcfbd --- /dev/null +++ b/sources/plugins/html5audio/plugin.js @@ -0,0 +1,112 @@ +CKEDITOR.plugins.add( 'html5audio', { + requires: 'widget', + lang: 'de,en,eu,es,fr,ru,uk,uz', + icons: 'html5audio', + init: function( editor ) { + editor.widgets.add( 'html5audio', { + button: editor.lang.html5audio.button, + template: '
', // We add the audio element when needed in the data function, to avoid having an undefined src attribute. + // See issue #9 on github: https://github.com/iametza/ckeditor-html5-audio/issues/9 + editables: {}, + /* + * Allowed content rules (http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules): + * - div-s with text-align,float,margin-left,margin-right inline style rules and required ckeditor-html5-audio class. + * - audio tags with src and controls attributes. + */ + allowedContent: 'div(!ckeditor-html5-audio){text-align,float,margin-left,margin-right}; audio[src,controls,autoplay];', + requiredContent: 'div(ckeditor-html5-audio); audio[src,controls];', + upcast: function( element ) { + return element.name === 'div' && element.hasClass( 'ckeditor-html5-audio' ); + }, + dialog: 'html5audio', + init: function() { + var src = ''; + var autoplay = ''; + var align = this.element.getStyle( 'text-align' ); + + // If there's a child (the audio element) + if ( this.element.getChild( 0 ) ) { + // get it's attributes. + src = this.element.getChild( 0 ).getAttribute( 'src' ); + autoplay = this.element.getChild( 0 ).getAttribute( 'autoplay' ); + } + + if ( src ) { + this.setData( 'src', src ); + + if ( align ) { + this.setData( 'align', align ); + } else { + this.setData( 'align', 'none' ); + } + + if ( autoplay ) { + this.setData( 'autoplay', 'yes' ); + } + } + }, + data: function() { + // If there is an audio source + if ( this.data.src ) { + // and there isn't a child (the audio element) + if ( !this.element.getChild( 0 ) ) { + // Create a new