From: Benoît Pin <benoit.pin@gmail.com>
Date: Tue, 29 Jul 2014 15:35:53 +0000 (+0200)
Subject: Application des styles comme il faut.
X-Git-Url: https://scm.cri.minesparis.psl.eu/git/ckeditor.git/commitdiff_plain/refs/heads/plinn_styles_dev?hp=1badda86f23d981e3cc8d73cf04b7463a531c482

Application des styles comme il faut.
---

diff --git a/skins/ckeditor/plugins/plinn_styles/plugin.js b/skins/ckeditor/plugins/plinn_styles/plugin.js
index 009e5d2..245a0e1 100644
--- a/skins/ckeditor/plugins/plinn_styles/plugin.js
+++ b/skins/ckeditor/plugins/plinn_styles/plugin.js
@@ -1,6 +1,7 @@
 ( function() {
 
 var PlinnStylesCombo = function(editor) {
+	this.editor = editor;
 	this.label = 'Styles';
 	this.title = 'CSS Styles';
 	this.toolbar = 'styles,10';
@@ -9,22 +10,61 @@ var PlinnStylesCombo = function(editor) {
 		multiSelect : true,
 		attributes : {'aria-label': this.title}
 	};
+	this.styles = [];
 };
 
+PlinnStylesCombo.prototype.loadStyle = function(definition) {
+	this.styles.push(definition);
+	this.styles[definition.name] = definition;
+};
+
+PlinnStylesCombo.prototype.init = function() {
+	var i, style;
+	for (i=0 ; i < this.styles.length ; i++) {
+		style = this.styles[i];
+		this.add(style.name,
+				 '<div class="' + style.className + '">' +
+				 	style.name + 
+				 '</div>',
+				 style.name
+			 	);
+	}
+};
+
+PlinnStylesCombo.prototype.onClick = function(value) {
+	this.editor.focus();
+	this.editor.fire( 'saveSnapshot' );
+	var style = this.styles[value]
+	var className = style.className;
+	var element = this.editor.elementPath().lastElement;
+	if (element.hasClass(className)) {
+		element.removeClass(className);
+	}
+	else {
+		element.addClass(className);
+	}
+	this.editor.fire( 'saveSnapshot' );
+};
 
 var PlinnStylePlugin = function() {
 	this.requires = 'richcombo';
+	this.combo = undefined;
 };
 
 PlinnStylePlugin.prototype.init = function(editor) {
-	var psc = new PlinnStylesCombo(editor);
-	editor.ui.addRichCombo('PlinnStyles', psc);
-	editor.on('stylesSet', this.onStylesSet);
+	this.combo = new PlinnStylesCombo(editor);
+	editor.ui.addRichCombo('PlinnStyles', this.combo);
+	var self = this;
+	editor.on('stylesSet', function(evt){self.onStylesSet(evt)});
 };
 
 PlinnStylePlugin.prototype.onStylesSet = function(evt) {
 	var stylesDefinitions = evt.data.styles;
 	if (!stylesDefinitions) { return; }
+	var i;
+	for(i=0 ; i < stylesDefinitions.length ; i++) {
+		this.combo.loadStyle(stylesDefinitions[i]);
+	}
 	
 };
 
@@ -32,4 +72,4 @@ PlinnStylePlugin.prototype.onStylesSet = function(evt) {
 // main
 CKEDITOR.plugins.add( 'plinn_styles', new PlinnStylePlugin());
 
-} )();
+} ());