diff --git a/build/ctct-style-attributes-content-handler-changelog.md b/build/ctct-style-attributes-content-handler-changelog.md
new file mode 100644
index 0000000000..c0f0838b3d
--- /dev/null
+++ b/build/ctct-style-attributes-content-handler-changelog.md
@@ -0,0 +1,5 @@
+- **FEATURE**: A Style Attribute Content Handler has been added to the common content handler plugin collection.
+ The Style Attribute Content Handler will remove all unsupported style attribute items recursively
+ from all elements in the supplied content. The set of supported style attribute items is
+ configured in the same manner as other content handler plugins via config in
+ Aloha.settings.contentHandler.handler.styleattribute.
diff --git a/doc/guides/source/plugin_contenthandler.textile b/doc/guides/source/plugin_contenthandler.textile
index 385d7ae849..1d612d24cd 100644
--- a/doc/guides/source/plugin_contenthandler.textile
+++ b/doc/guides/source/plugin_contenthandler.textile
@@ -2,7 +2,7 @@ h2. The Content Handler Plugin
After reading this guide, you will be able to:
-* Understand what Content Handler are and how to use them
+* Understand what Content Handlers are and how to use them
* Use the Content Handler API to create, modify and
* Extend Content Handler with custom implementations
@@ -88,12 +88,12 @@ h4. Writing your own Content Handler
['aloha', 'jquery', 'aloha/contenthandlermanager'],
function(Aloha, jQuery, ContentHandlerManager) {
"use strict";
-
+
var MyContentHandler = ContentHandlerManager.createHandler({
handleContent: function( content ) {
-
+
// do something with the content
-
+
return content; // return as HTML text not jQuery/DOM object
}
});
@@ -185,3 +185,21 @@ Aloha.settings.contentHandler.sanitize = {
}
}
+
+h4. Style Attribute Content Handler
+
+The Style Attribute Content Handler will remove all unsupported style attribute items recursively from the style tags
+of all elements in the supplied content. The set of supported style attribute items is defined by plugin configuration.
+You may specify your own configuration based on these default settings:
+
+
+Aloha.settings.contentHandler.styleattribute = {
+ // style attribute items allowed in the content
+ supportedStyles: {
+ 'text-align': true
+ }
+}
+
+
+
+
diff --git a/src/plugins/common/contenthandler/lib/contenthandler-plugin.js b/src/plugins/common/contenthandler/lib/contenthandler-plugin.js
index 47833840c6..b02842c4b6 100644
--- a/src/plugins/common/contenthandler/lib/contenthandler-plugin.js
+++ b/src/plugins/common/contenthandler/lib/contenthandler-plugin.js
@@ -17,6 +17,7 @@ define([
'contenthandler/wordcontenthandler',
'contenthandler/genericcontenthandler',
'contenthandler/sanitizecontenthandler',
+ 'contenthandler/styleattributecontenthandler',
'contenthandler/blockelementcontenthandler'
], function (
$,
@@ -25,6 +26,7 @@ define([
WordContentHandler,
GenericContentHandler,
SanitizeContentHandler,
+ StyleAttributeContentHandler,
BlockelementContentHandler
) {
'use strict';
@@ -40,6 +42,7 @@ define([
word: WordContentHandler,
generic: GenericContentHandler,
sanitize: SanitizeContentHandler,
+ styleattribute: StyleAttributeContentHandler,
blockelement: BlockelementContentHandler
};
diff --git a/src/plugins/common/contenthandler/lib/styleattributecontenthandler.js b/src/plugins/common/contenthandler/lib/styleattributecontenthandler.js
new file mode 100644
index 0000000000..df80c25212
--- /dev/null
+++ b/src/plugins/common/contenthandler/lib/styleattributecontenthandler.js
@@ -0,0 +1,97 @@
+/* styleattributecontenthandler.js is part of Aloha Editor project http://aloha-editor.org
+ *
+ * Aloha Editor is a WYSIWYG HTML5 inline editing library and editor.
+ * Copyright (c) 2010-2012 Gentics Software GmbH, Vienna, Austria.
+ * Contributors http://aloha-editor.org/contribution.php
+ *
+ * Aloha Editor is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * Aloha Editor is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * As an additional permission to the GNU GPL version 2, you may distribute
+ * non-source (e.g., minimized or compacted) forms of the Aloha-Editor
+ * source code without the copy of the GNU GPL normally required,
+ * provided you include this license notice and a URL through which
+ * recipients can access the Corresponding Source.
+ */
+define([
+ 'jquery',
+ 'aloha',
+ 'aloha/contenthandlermanager'
+], function($, Aloha, ContentHandlerManager) {
+ var config = null,
+ defaults = {
+ supportedStyles: {
+ 'text-align': true
+ }
+ };
+
+ Aloha.settings.contentHandler = Aloha.settings.contentHandler || {};
+ Aloha.settings.contentHandler.handler = Aloha.settings.contentHandler.handler || {};
+ Aloha.settings.contentHandler.handler.styleattribute = Aloha.settings.contentHandler.handler.styleattribute || {};
+
+
+ var init = function() {
+ if (!config) {
+ config = $.extend(true, {}, defaults, Aloha.settings.contentHandler.handler.styleattribute.supportedStyles);
+ }
+ };
+
+ var cleanStyles = function(cfg, $el) {
+ var style, styleItem, styleItemSplit, styleItems, styles, _i, _len;
+
+ style = $el.attr('style');
+
+ if (style) {
+ styleItems = '';
+ styles = style.split(';');
+
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
+ styleItem = styles[_i];
+ styleItem = styleItem.trim();
+ styleItemSplit = styleItem.split(':');
+
+ if (styleItemSplit.length !== 2) continue;
+
+ if (cfg.supportedStyles[styleItemSplit[0].trim()]) {
+ styleItems += "" + styleItem + ";";
+ }
+ }
+
+ $el.removeAttr('style');
+ if (styleItems) {
+ $el.attr('style', "" + styleItems);
+ }
+ }
+ };
+
+ var cleanStyleAttribute = function($content) {
+ $content.children().each(function() {
+ var $child = $(this);
+ cleanStyleAttribute($child);
+ cleanStyles(config, $child);
+ });
+ };
+
+ var StyleAttributeContentHandler = ContentHandlerManager.createHandler({
+ handleContent: function(content) {
+ init();
+
+ $content = $('
').append(content);
+ cleanStyleAttribute($content);
+ return $content.html();
+ }
+ });
+
+ return StyleAttributeContentHandler;
+});
\ No newline at end of file