X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fludivine-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fplugins%2Fhtml5video%2Fplugin.js;fp=sources%2Fplugins%2Fhtml5video%2Fplugin.js;h=1bfff7f9b518c6236b3354d3335318b54ad4b463;hp=0000000000000000000000000000000000000000;hb=7183f6a6a21ad9124e70c997e0168459f377a9f2;hpb=d1844275460a3e3a32e199326f6b36938a329091 diff --git a/sources/plugins/html5video/plugin.js b/sources/plugins/html5video/plugin.js new file mode 100644 index 0000000..1bfff7f --- /dev/null +++ b/sources/plugins/html5video/plugin.js @@ -0,0 +1,129 @@ +CKEDITOR.plugins.add( 'html5video', { + requires: 'widget', + lang: 'de,en,eu,es,ru,uk,fr', + icons: 'html5video', + init: function( editor ) { + editor.widgets.add( 'html5video', { + button: editor.lang.html5video.button, + template: '
', + /* + * 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-video class. + * - video tags with src and controls attributes. + */ + allowedContent: 'div(!ckeditor-html5-video){text-align,float,margin-left,margin-right}; video[src,controls,autoplay];', + requiredContent: 'div(ckeditor-html5-video); video[src,controls];', + upcast: function( element ) { + return element.name === 'div' && element.hasClass( 'ckeditor-html5-video' ); + }, + dialog: 'html5video', + init: function() { + var src = ''; + var autoplay = ''; + var align = this.element.getStyle( 'text-align' ); + + var width = ''; + var height = ''; + + // If there's a child (the video element) + if ( this.element.getChild( 0 ) ) { + // get it's attributes. + src = this.element.getChild( 0 ).getAttribute( 'src' ); + width = this.element.getChild( 0 ).getAttribute( 'width' ); + height = this.element.getChild( 0 ).getAttribute( 'height' ); + 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 ( width ) { + this.setData( 'width', width ); + } else { + this.setData( 'width', '400' ); + } + + if ( height ) { + this.setData( 'height', height ); + } else { + this.setData( 'height', '300' ); + } + + if ( autoplay ) { + this.setData( 'autoplay', 'yes' ); + } + } + }, + data: function() { + // If there is an video source + if ( this.data.src ) { + // and there isn't a child (the video element) + if ( !this.element.getChild( 0 ) ) { + // Create a new