Skip to content

Commit 251f830

Browse files
committed
Merge branch 't/13199' into major
2 parents c5d7f81 + 169dd16 commit 251f830

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

plugins/embed/plugin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
'//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}'
2727
),
2828

29+
// The filter element callback actually allows all divs with data-oembed-url,
30+
// so registering styles to the filter is virtually unnecessary because
31+
// classes won't be filtered out. However, registering them will make filter.check() work
32+
// which may be important in some cases.
33+
styleToAllowedContentRules: function( style ) {
34+
// Retrieve classes defined in the style.
35+
var classes = style.getClassesArray();
36+
37+
return {
38+
div: {
39+
propertiesOnly: true,
40+
classes: classes,
41+
attributes: '!data-oembed-url'
42+
}
43+
};
44+
},
45+
2946
upcast: function( el, data ) {
3047
if ( el.name == 'div' && el.attributes[ 'data-oembed-url' ] ) {
3148
data.url = el.attributes[ 'data-oembed-url' ];

plugins/embedsemantic/plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
button: editor.lang.embedbase.button,
2626
allowedContent: 'oembed',
2727
requiredContent: 'oembed',
28+
styleableElements: 'oembed',
2829
// Share config with the embed plugin.
2930
providerUrl: new CKEDITOR.template(
3031
editor.config.embed_provider ||

tests/plugins/embed/integration.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* bender-tags: widget */
2-
/* bender-ckeditor-plugins: embed,toolbar */
2+
/* bender-ckeditor-plugins: embed,toolbar,stylescombo */
33
/* bender-include: ../widget/_helpers/tools.js, ../embedbase/_helpers/tools.js */
44
/* global embedTools, widgetTestsTools */
55

@@ -10,7 +10,11 @@ bender.editors = {
1010
name: 'editor_classic',
1111
creator: 'replace',
1212
config: {
13-
extraAllowedContent: 'div(a,b,c)'
13+
extraAllowedContent: 'div(a,b,c)',
14+
stylesSet: [
15+
{ name: 'Foo media', type: 'widget', widget: 'embed', attributes: { 'class': 'foo' } },
16+
{ name: 'Bar media', type: 'widget', widget: 'embed', attributes: { 'class': 'bar' } }
17+
]
1418
}
1519
}
1620
};
@@ -21,7 +25,7 @@ var classes2Array = widgetTestsTools.classes2Array;
2125
embedTools.mockJsonp();
2226

2327
var tcs = {
24-
'test support for widget classes': function() {
28+
'test support for widget classes - from extraAC': function() {
2529
var bot = this.editorBots.classic,
2630
editor = bot.editor,
2731
data = '<div class="a b c" data-oembed-url="http://foo.jpg">' +
@@ -36,6 +40,25 @@ var tcs = {
3640
assert.areSame( data, bot.getData( 1, 1 ), 'classes transfered from widget.element back to data' );
3741
}, 100 );
3842
} );
43+
},
44+
45+
'test support for widget classes - from stylesSet': function() {
46+
var bot = this.editorBots.classic,
47+
editor = bot.editor,
48+
data = '<div class="bar foo" data-oembed-url="http://foo.jpg">' +
49+
'<img alt="image" src="//foo.jpg" style="max-width:100%;" />' +
50+
'</div>';
51+
52+
assert.isTrue( editor.filter.check( 'div[data-oembed-url](foo)' ), 'class from a stylesSet is registered' );
53+
assert.isTrue( editor.filter.check( 'div[data-oembed-url](foo)', false, true ), 'class from a stylesSet is registered - strict check' );
54+
assert.isFalse( editor.filter.check( 'div(foo)', false, true ), 'registered rules are precise - data-oembed-url must exist' );
55+
56+
bot.setData( data, function() {
57+
arrayAssert.itemsAreSame( [ 'bar', 'foo' ],
58+
classes2Array( obj2Array( editor.widgets.instances )[ 0 ].getClasses() ).sort(), 'classes transfered from data to widget.element' );
59+
60+
assert.areSame( data, bot.getData( 1, 1 ), 'classes transfered from widget.element back to data' );
61+
} );
3962
}
4063
};
4164

tests/plugins/embedsemantic/integration.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* bender-tags: widget */
2-
/* bender-ckeditor-plugins: embedsemantic,toolbar,undo,basicstyles */
2+
/* bender-ckeditor-plugins: embedsemantic,toolbar,undo,basicstyles,stylescombo */
33
/* bender-include: ../widget/_helpers/tools.js, ../embedbase/_helpers/tools.js */
44
/* global embedTools, widgetTestsTools */
55

@@ -10,7 +10,11 @@ bender.editors = {
1010
name: 'editor_classic',
1111
creator: 'replace',
1212
config: {
13-
extraAllowedContent: 'oembed(a,b,c)'
13+
extraAllowedContent: 'oembed(a,b,c)',
14+
stylesSet: [
15+
{ name: 'Foo media', type: 'widget', widget: 'embedSemantic', attributes: { 'class': 'foo' } },
16+
{ name: 'Bar media', type: 'widget', widget: 'embedSemantic', attributes: { 'class': 'bar' } }
17+
]
1418
}
1519
}
1620
};
@@ -87,7 +91,7 @@ var tcs = {
8791
} );
8892
},
8993

90-
'test support for widget classes': function() {
94+
'test support for widget classes - from extraAC': function() {
9195
var bot = this.editorBots.classic,
9296
editor = bot.editor;
9397

@@ -99,6 +103,22 @@ var tcs = {
99103
assert.areSame( '<p>x</p><oembed class="a b c">http://widget/classes</oembed><p>x</p>', bot.getData(), 'classes transfered from widget.element back to data' );
100104
}, 100 );
101105
} );
106+
},
107+
108+
'test support for widget classes - from stylesSet': function() {
109+
var bot = this.editorBots.classic,
110+
editor = bot.editor;
111+
112+
assert.isTrue( editor.filter.check( 'oembed(foo)' ), 'class from a stylesSet is registered' );
113+
114+
bot.setData( '<p>x</p><oembed class="bar foo">http://widget/classes</oembed><p>x</p>', function() {
115+
wait( function() {
116+
arrayAssert.itemsAreSame( [ 'bar', 'foo' ],
117+
classes2Array( obj2Array( editor.widgets.instances )[ 0 ].getClasses() ).sort(), 'classes transfered from data to widget.element' );
118+
119+
assert.areSame( '<p>x</p><oembed class="bar foo">http://widget/classes</oembed><p>x</p>', bot.getData(), 'classes transfered from widget.element back to data' );
120+
}, 100 );
121+
} );
102122
}
103123
};
104124

0 commit comments

Comments
 (0)