-
Notifications
You must be signed in to change notification settings - Fork 521
Expand file tree
/
Copy pathstyleattributecontenthandler.js
More file actions
97 lines (83 loc) · 3.37 KB
/
Copy pathstyleattributecontenthandler.js
File metadata and controls
97 lines (83 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 = $('<div/>').append(content);
cleanStyleAttribute($content);
return $content.html();
}
});
return StyleAttributeContentHandler;
});