1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
( function() {
|
10
|
var numberRegex = /^\d+(?:\.\d+)?$/;
|
11
|
var cssifyLength = function( length )
|
12
|
{
|
13
|
if ( numberRegex.test( length ) )
|
14
|
return length + 'px';
|
15
|
return length;
|
16
|
}
|
17
|
CKEDITOR.plugins.add( 'mediaembed',
|
18
|
{
|
19
|
requires : [ 'dialog', 'fakeobjects' ],
|
20
|
init: function( editor )
|
21
|
{
|
22
|
var addCssObj = CKEDITOR;
|
23
|
|
24
|
if (Drupal.ckeditor_ver == 3) {
|
25
|
addCssObj = editor;
|
26
|
}
|
27
|
addCssObj.addCss(
|
28
|
'img.cke_mediaembed' +
|
29
|
'{' +
|
30
|
'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.gif' ) + ');' +
|
31
|
'background-position: center center;' +
|
32
|
'background-repeat: no-repeat;' +
|
33
|
'border: 1px solid #a9a9a9;' +
|
34
|
'width: 80px;' +
|
35
|
'height: 80px;' +
|
36
|
'}'
|
37
|
);
|
38
|
|
39
|
editor.addCommand( 'mediaembedDialog', new CKEDITOR.dialogCommand( 'mediaembedDialog', { allowedContent : 'div(media_embed);iframe[*](*)' } ) );
|
40
|
editor.ui.addButton( 'MediaEmbed',
|
41
|
{
|
42
|
label: 'Embed Media',
|
43
|
command: 'mediaembedDialog',
|
44
|
icon: this.path + 'images/icon.png'
|
45
|
} );
|
46
|
CKEDITOR.dialog.add( 'mediaembedDialog', this.path + 'dialogs/mediaembed.js' );
|
47
|
},
|
48
|
afterInit : function( editor )
|
49
|
{
|
50
|
var dataProcessor = editor.dataProcessor,
|
51
|
dataFilter = dataProcessor && dataProcessor.dataFilter,
|
52
|
htmlFilter = dataProcessor && dataProcessor.htmlFilter;
|
53
|
|
54
|
if ( htmlFilter )
|
55
|
{
|
56
|
htmlFilter.addRules({
|
57
|
elements :
|
58
|
{
|
59
|
'div' : function ( element ) {
|
60
|
if( element.attributes['class'] == 'media_embed' ) {
|
61
|
for (var x in element.children) {
|
62
|
if (typeof(element.children[x].attributes) != 'undefined') {
|
63
|
if (typeof(element.children[x].attributes.width) != undefined) {
|
64
|
element.children[x].attributes.width = element.attributes.width;
|
65
|
}
|
66
|
if (typeof(element.children[x].attributes.height) != undefined) {
|
67
|
element.children[x].attributes.height = element.attributes.height;
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
}
|
74
|
});
|
75
|
}
|
76
|
if ( dataFilter )
|
77
|
{
|
78
|
dataFilter.addRules(
|
79
|
{
|
80
|
elements :
|
81
|
{
|
82
|
'div' : function( element )
|
83
|
{
|
84
|
var attributes = element.attributes,
|
85
|
classId = attributes.classid && String( attributes.classid ).toLowerCase();
|
86
|
|
87
|
if (element.attributes[ 'class' ] == 'media_embed') {
|
88
|
var fakeElement = editor.createFakeParserElement(element, 'cke_mediaembed', 'div', true);
|
89
|
var fakeStyle = fakeElement.attributes.style || '';
|
90
|
if (element.children[0] && typeof(element.children[0].attributes) != 'undefined') {
|
91
|
var height = element.children[0].attributes.height,
|
92
|
width = element.children[0].attributes.width;
|
93
|
}
|
94
|
if ( typeof width != 'undefined' )
|
95
|
fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + cssifyLength( width ) + ';';
|
96
|
|
97
|
if ( typeof height != 'undefined' )
|
98
|
fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + cssifyLength( height ) + ';';
|
99
|
|
100
|
return fakeElement;
|
101
|
}
|
102
|
return element;
|
103
|
}
|
104
|
}
|
105
|
},
|
106
|
5);
|
107
|
}
|
108
|
}
|
109
|
} );
|
110
|
} )();
|