Réinplémentation du plugin Plinn Image. Il modifie les src des images juste avanc...
[ckeditor.git] / skins / ckeditor / _source / plugins / flash / plugin.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5
6 (function()
7 {
8 var flashFilenameRegex = /\.swf(?:$|\?)/i;
9
10 function isFlashEmbed( element )
11 {
12 var attributes = element.attributes;
13
14 return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );
15 }
16
17 function createFakeElement( editor, realElement )
18 {
19 return editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true );
20 }
21
22 CKEDITOR.plugins.add( 'flash',
23 {
24 init : function( editor )
25 {
26 editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash' ) );
27 editor.ui.addButton( 'Flash',
28 {
29 label : editor.lang.common.flash,
30 command : 'flash'
31 });
32 CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
33
34 editor.addCss(
35 'img.cke_flash' +
36 '{' +
37 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
38 'background-position: center center;' +
39 'background-repeat: no-repeat;' +
40 'border: 1px solid #a9a9a9;' +
41 'width: 80px;' +
42 'height: 80px;' +
43 '}'
44 );
45
46 // If the "menu" plugin is loaded, register the menu items.
47 if ( editor.addMenuItems )
48 {
49 editor.addMenuItems(
50 {
51 flash :
52 {
53 label : editor.lang.flash.properties,
54 command : 'flash',
55 group : 'flash'
56 }
57 });
58 }
59
60 editor.on( 'doubleclick', function( evt )
61 {
62 var element = evt.data.element;
63
64 if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'flash' )
65 evt.data.dialog = 'flash';
66 });
67
68 // If the "contextmenu" plugin is loaded, register the listeners.
69 if ( editor.contextMenu )
70 {
71 editor.contextMenu.addListener( function( element, selection )
72 {
73 if ( element && element.is( 'img' ) && !element.isReadOnly()
74 && element.data( 'cke-real-element-type' ) == 'flash' )
75 return { flash : CKEDITOR.TRISTATE_OFF };
76 });
77 }
78 },
79
80 afterInit : function( editor )
81 {
82 var dataProcessor = editor.dataProcessor,
83 dataFilter = dataProcessor && dataProcessor.dataFilter;
84
85 if ( dataFilter )
86 {
87 dataFilter.addRules(
88 {
89 elements :
90 {
91 'cke:object' : function( element )
92 {
93 var attributes = element.attributes,
94 classId = attributes.classid && String( attributes.classid ).toLowerCase();
95
96 if ( !classId && !isFlashEmbed( element ) )
97 {
98 // Look for the inner <embed>
99 for ( var i = 0 ; i < element.children.length ; i++ )
100 {
101 if ( element.children[ i ].name == 'cke:embed' )
102 {
103 if ( !isFlashEmbed( element.children[ i ] ) )
104 return null;
105
106 return createFakeElement( editor, element );
107 }
108 }
109 return null;
110 }
111
112 return createFakeElement( editor, element );
113 },
114
115 'cke:embed' : function( element )
116 {
117 if ( !isFlashEmbed( element ) )
118 return null;
119
120 return createFakeElement( editor, element );
121 }
122 }
123 },
124 5);
125 }
126 },
127
128 requires : [ 'fakeobjects' ]
129 });
130 })();
131
132 CKEDITOR.tools.extend( CKEDITOR.config,
133 {
134 /**
135 * Save as EMBED tag only. This tag is unrecommended.
136 * @type Boolean
137 * @default false
138 */
139 flashEmbedTagOnly : false,
140
141 /**
142 * Add EMBED tag as alternative: &lt;object&gt&lt;embed&gt&lt;/embed&gt&lt;/object&gt
143 * @type Boolean
144 * @default false
145 */
146 flashAddEmbedTag : true,
147
148 /**
149 * Use embedTagOnly and addEmbedTag values on edit.
150 * @type Boolean
151 * @default false
152 */
153 flashConvertOnEdit : false
154 } );