]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/flash/plugin.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / flash / plugin.js
1 /**
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 ( function() {
7 var flashFilenameRegex = /\.swf(?:$|\?)/i;
8
9 function isFlashEmbed( element ) {
10 var attributes = element.attributes;
11
12 return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );
13 }
14
15 function createFakeElement( editor, realElement ) {
16 return editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true );
17 }
18
19 CKEDITOR.plugins.add( 'flash', {
20 requires: 'dialog,fakeobjects',
21 // jscs:disable maximumLineLength
22 lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
23 // jscs:enable maximumLineLength
24 icons: 'flash', // %REMOVE_LINE_CORE%
25 hidpi: true, // %REMOVE_LINE_CORE%
26 onLoad: function() {
27 CKEDITOR.addCss( 'img.cke_flash' +
28 '{' +
29 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
30 'background-position: center center;' +
31 'background-repeat: no-repeat;' +
32 'border: 1px solid #a9a9a9;' +
33 'width: 80px;' +
34 'height: 80px;' +
35 '}'
36 );
37
38 },
39 init: function( editor ) {
40 var allowed = 'object[classid,codebase,height,hspace,vspace,width];' +
41 'param[name,value];' +
42 'embed[height,hspace,pluginspage,src,type,vspace,width]';
43
44 if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'properties' ) )
45 allowed += ';object[align]; embed[allowscriptaccess,quality,scale,wmode]';
46 if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'advanced' ) )
47 allowed += ';object[id]{*}; embed[bgcolor]{*}(*)';
48
49 editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash', {
50 allowedContent: allowed,
51 requiredContent: 'embed'
52 } ) );
53 editor.ui.addButton && editor.ui.addButton( 'Flash', {
54 label: editor.lang.common.flash,
55 command: 'flash',
56 toolbar: 'insert,20'
57 } );
58 CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
59
60 // If the "menu" plugin is loaded, register the menu items.
61 if ( editor.addMenuItems ) {
62 editor.addMenuItems( {
63 flash: {
64 label: editor.lang.flash.properties,
65 command: 'flash',
66 group: 'flash'
67 }
68 } );
69 }
70
71 editor.on( 'doubleclick', function( evt ) {
72 var element = evt.data.element;
73
74 if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'flash' )
75 evt.data.dialog = 'flash';
76 } );
77
78 // If the "contextmenu" plugin is loaded, register the listeners.
79 if ( editor.contextMenu ) {
80 editor.contextMenu.addListener( function( element ) {
81 if ( element && element.is( 'img' ) && !element.isReadOnly() && element.data( 'cke-real-element-type' ) == 'flash' )
82 return { flash: CKEDITOR.TRISTATE_OFF };
83 } );
84 }
85 },
86
87 afterInit: function( editor ) {
88 var dataProcessor = editor.dataProcessor,
89 dataFilter = dataProcessor && dataProcessor.dataFilter;
90
91 if ( dataFilter ) {
92 dataFilter.addRules( {
93 elements: {
94 'cke:object': function( element ) {
95 var attributes = element.attributes,
96 classId = attributes.classid && String( attributes.classid ).toLowerCase();
97
98 if ( !classId && !isFlashEmbed( element ) ) {
99 // Look for the inner <embed>
100 for ( var i = 0; i < element.children.length; i++ ) {
101 if ( element.children[ i ].name == 'cke:embed' ) {
102 if ( !isFlashEmbed( element.children[ i ] ) )
103 return null;
104
105 return createFakeElement( editor, element );
106 }
107 }
108 return null;
109 }
110
111 return createFakeElement( editor, element );
112 },
113
114 'cke:embed': function( element ) {
115 if ( !isFlashEmbed( element ) )
116 return null;
117
118 return createFakeElement( editor, element );
119 }
120 }
121 }, 5 );
122 }
123 }
124 } );
125 } )();
126
127 CKEDITOR.tools.extend( CKEDITOR.config, {
128 /**
129 * Save as `<embed>` tag only. This tag is unrecommended.
130 *
131 * @cfg {Boolean} [flashEmbedTagOnly=false]
132 * @member CKEDITOR.config
133 */
134 flashEmbedTagOnly: false,
135
136 /**
137 * Add `<embed>` tag as alternative: `<object><embed></embed></object>`.
138 *
139 * @cfg {Boolean} [flashAddEmbedTag=false]
140 * @member CKEDITOR.config
141 */
142 flashAddEmbedTag: true,
143
144 /**
145 * Use {@link #flashEmbedTagOnly} and {@link #flashAddEmbedTag} values on edit.
146 *
147 * @cfg {Boolean} [flashConvertOnEdit=false]
148 * @member CKEDITOR.config
149 */
150 flashConvertOnEdit: false
151 } );