3 var PlinnStylesCombo = function(editor
) {
6 this.title
= 'CSS Styles';
7 this.toolbar
= 'styles,10';
9 css
: [CKEDITOR
.skin
.getPath( 'editor' )].concat(editor
.config
.contentsCss
),
11 attributes
: {'aria-label': this.title
}
16 PlinnStylesCombo
.prototype.loadStyle = function(definition
) {
17 this.styles
.push(definition
);
18 this.styles
[definition
.name
] = definition
;
21 PlinnStylesCombo
.prototype.init = function() {
23 for (i
=0 ; i
< this.styles
.length
; i
++) {
24 style
= this.styles
[i
];
26 '<div class="' + style
.className
+ '">' +
34 PlinnStylesCombo
.prototype.onClick = function(value
) {
36 this.editor
.fire('saveSnapshot');
37 var style
= this.styles
[value
]
38 var className
= style
.className
;
39 var ranges
= this.editor
.getSelection().getRanges();
40 var element
= this.editor
.elementPath().lastElement
;
41 if(ranges
.length
=== 1) {
42 var start
= ranges
[0].startContainer
;
43 var end
= ranges
[0].endContainer
;
44 if(start
.$ !== end
.$) {
45 // selection is a fragment that need to be wrapped in container to apply style
46 element
= new CKEDITOR
.dom
.element('div');
47 element
.append(ranges
[0].cloneContents());
48 this.editor
.insertElement(element
);
51 if (element
.hasClass(className
)) {
52 element
.removeClass(className
);
55 element
.addClass(className
);
57 this.editor
.fire('saveSnapshot');
60 var PlinnStylePlugin = function() {
61 this.requires
= 'richcombo';
62 this.combo
= undefined;
65 PlinnStylePlugin
.prototype.init = function(editor
) {
66 this.combo
= new PlinnStylesCombo(editor
);
67 editor
.ui
.addRichCombo('PlinnStyles', this.combo
);
69 editor
.on('stylesSet', function(evt
){self
.onStylesSet(evt
)});
72 PlinnStylePlugin
.prototype.onStylesSet = function(evt
) {
73 var stylesDefinitions
= evt
.data
.styles
;
74 if (!stylesDefinitions
) { return; }
76 for(i
=0 ; i
< stylesDefinitions
.length
; i
++) {
77 this.combo
.loadStyle(stylesDefinitions
[i
]);
84 CKEDITOR
.plugins
.add( 'plinn_styles', new PlinnStylePlugin());