aboutsummaryrefslogtreecommitdiff
path: root/node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js
diff options
context:
space:
mode:
authorEric Guzman2012-06-27 10:32:47 -0700
committerEric Guzman2012-06-27 10:32:47 -0700
commit58f1de4f1cb0f59abd47cec4430a032c073f85e9 (patch)
treea6c2af9be68e6881311074bd3c8cc461deee7203 /node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js
parenta72b6809e214eb524f866440a55f8366f078c240 (diff)
parent2ebf3e3ea24d0d580575dfa13d31588dac1de445 (diff)
downloadninja-58f1de4f1cb0f59abd47cec4430a032c073f85e9.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into CSSPanel_GIO
Diffstat (limited to 'node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js')
-rw-r--r--node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js132
1 files changed, 0 insertions, 132 deletions
diff --git a/node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js b/node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js
deleted file mode 100644
index 3282d3e6..00000000
--- a/node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js
+++ /dev/null
@@ -1,132 +0,0 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6/**
7 @module "montage/ui/rich-text-sanitizer.js"
8 @requires montage/core/core
9*/
10var Montage = require("montage").Montage;
11
12/**
13 @class module:"montage/ui/rich-text-sanitizer.js".Sanitizer
14 @extends module:montage/core/core.Montage
15*/
16exports.Sanitizer = Montage.create(Montage,/** @lends module:"montage/ui/rich-text-sanitizer.js".Sanitizer# */ {
17
18 willSetValue: {
19 value: function(value, identifier) {
20 return this._scopeCSS(value, identifier);
21 }
22 },
23
24 didGetValue: {
25 value: function(value, identifier) {
26 return this._unscopeCSS(value, identifier);
27 }
28 },
29
30 willInsertHTMLData: {
31 value: function(data, identifier) {
32 return this._scopeCSS(this._removeScript(data), identifier);
33 }
34 },
35
36 _scopeCSS: {
37 enumerable: true,
38 value: function(htmlFragment, identifier) {
39 var identifierSelector = ".editor-" + identifier+ " ";
40
41 if (typeof htmlFragment == "string") {
42 // Extract the style tag and its content
43 htmlFragment = htmlFragment.replace(/(<style ?[^>]*>)([^<]*)(<\/style>)/ig, function(match, pre, style, post) {
44 // Remove any newlines and tab for easier processing
45 style = style.replace(/\t|\n|\r/g, function(char) {if (char == "\t") return " "; return ""});
46
47 // Cleanup any potential leftover from a previous scoping
48 style = style.replace(/\*\.editor-[^ ] +/g, "body");
49 style = style.replace(/\.editor-[^ ]+ /g, "");
50
51 // Extract the selectors for each css block
52 style = style.replace(/([^{]+)({[^}]*})/ig, function(match, selectors, rules) {
53
54 // Split the selectors and add the identifierSelector
55 selectors = selectors.replace(/ *([^,]+)/g, function(match, selector) {
56 // convert body selector
57 if (selector.toLowerCase() == "body") {
58 return "*" + identifierSelector;
59 } else {
60 return identifierSelector + selector;
61 }
62 })
63 return selectors + rules;
64 })
65 return pre + style + post;
66 });
67 }
68
69 return htmlFragment;
70 }
71 },
72
73 _unscopeCSS: {
74 enumerable: true,
75 value: function(htmlFragment, identifier) {
76
77 if (typeof htmlFragment == "string") {
78 // Extract the style tag and its content
79 htmlFragment = htmlFragment.replace(/(<style ?[^>]*>)([^<]*)(<\/style>)/ig, function(match, pre, style, post) {
80 style = style.replace(/\*\.editor-[^ ] +/g, "body");
81 style = style.replace(/\.editor-[^ ]+ /g, "");
82 return pre + style + post;
83 });
84 }
85 return htmlFragment;
86 }
87 },
88
89 _removeScript: {
90 enumerable: true,
91 value: function(htmlFragment) {
92 /*
93 Will remove any script tag, onXXX handlers and javascript URLs
94 */
95 var div = document.createElement("div"),
96 _removeScript = function(element) {
97 var children = element.children,
98 child,
99 nbrChildren = children.length,
100 attributes = element.attributes,
101 attribute,
102 nbrAttributes = attributes.length,
103 i;
104
105 for (i = 0; i < nbrAttributes; i ++) {
106 attribute = attributes[i];
107 if (attribute.name.match(/^on[a-z]+/i) || attribute.value.match(/^javascript:/)) {
108 element.removeAttribute(attribute.name);
109 i --;
110 nbrAttributes --;
111 }
112 }
113
114 for (i = 0; i < nbrChildren; i ++) {
115 child = children[i];
116 if (child.tagName == "SCRIPT") {
117 child.parentNode.removeChild(child);
118 i --;
119 nbrChildren --;
120 } else {
121 _removeScript(child);
122 }
123 }
124 };
125
126 div.innerHTML = htmlFragment;
127 _removeScript(div);
128
129 return div.innerHTML;
130 }
131 }
132});