aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js')
-rw-r--r--node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js614
1 files changed, 614 insertions, 0 deletions
diff --git a/node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js b/node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js
new file mode 100644
index 00000000..89af8eb3
--- /dev/null
+++ b/node_modules/montage/ui/rich-text-editor/rich-text-editor.reel/rich-text-editor.js
@@ -0,0 +1,614 @@
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-editor.reel"
8 @requires montage/core/core
9*/
10var Montage = require("montage").Montage,
11 RichTextEditorBase = require("./rich-text-editor-base").RichTextEditorBase,
12 Sanitizer = require("./rich-text-sanitizer").Sanitizer,
13 MutableEvent = require("core/event/mutable-event").MutableEvent,
14 defaultEventManager = require("core/event/event-manager").defaultEventManager;
15
16/**
17 @class module:"montage/ui/rich-text-editor.reel".RichTextEditor
18 @extends module:montage/ui/component.Component
19*/
20exports.RichTextEditor = Montage.create(RichTextEditorBase,/** @lends module:"montage/ui/rich-text-editor.reel".RichTextEditor# */ {
21
22 /**
23 Description TODO
24 @type {Function}
25 */
26 hasFocus: {
27 enumerable: true,
28 get: function() {
29 return this._hasFocus;
30 }
31 },
32
33 /**
34 Description TODO
35 @type {Function}
36 */
37 innerElement: {
38 enumerable: true,
39 get: function() {
40 return this._innerElement;
41 }
42 },
43
44
45 /**
46 Description TODO
47 @type {Function}
48 */
49 focus: {
50 enumerable: true,
51 value: function() {
52 this._needsFocus = true;
53 this.needsDraw = true;
54 }
55 },
56
57 /**
58 Description TODO
59 @type {Function}
60 */
61 isActiveElement: {
62 enumerable: true,
63 get: function() {
64 return this._isActiveElement;
65 }
66 },
67
68 /**
69 Description TODO
70 @type {Function}
71 */
72 readOnly: {
73 enumerable: true,
74 get: function() {
75 return this._readOnly;
76 },
77 set: function(value) {
78 if (this._readOnly !== value) {
79 this._readOnly = value;
80 if (value) {
81 // Remove any overlay
82 this.hideOverlay();
83 }
84 this.needsDraw = true;
85 }
86 }
87 },
88
89 /**
90 Description TODO
91 @type {Function}
92 */
93 value: {
94 enumerable: true,
95 serializable: true,
96 get: function() {
97 var contentNode = this._innerElement,
98 content = "",
99 overlayElement = null,
100 overlayParent,
101 overlayNextSibling;
102
103 if (this._dirtyValue) {
104 if (contentNode) {
105 // Temporary orphran the overlay slot while retrieving the content
106 overlayElement = contentNode.querySelector(".montage-editor-overlay");
107 if (overlayElement) {
108 overlayParent = overlayElement.parentNode;
109 overlayNextSibling = overlayElement.nextSibling;
110 overlayParent.removeChild(overlayElement);
111 }
112 content = contentNode.innerHTML;
113 }
114
115 if (content == "<br>") {
116 // when the contentEditable div is emptied, Chrome add a <br>, let's filter it out
117 content = "";
118 }
119 if (this._sanitizer === undefined) {
120 this._sanitizer = Sanitizer.create();
121 }
122 if (this._sanitizer) {
123 content = this._sanitizer.didGetValue(content, this._uniqueId);
124 }
125
126 // restore the overlay
127 if (overlayElement) {
128 overlayParent.insertBefore(overlayElement, overlayNextSibling);
129 }
130
131 this._value = content;
132 this._dirtyValue = false;
133 }
134 return this._value;
135 },
136 set: function(value) {
137 if (this._value !== value || this._dirtyValue) {
138 // Remove any overlay
139 this.hideOverlay();
140
141 if (this._sanitizer === undefined) {
142 this._sanitizer = Sanitizer.create();
143 }
144 if (this._sanitizer) {
145 value = this._sanitizer.willSetValue(value, this._uniqueId);
146 }
147 this._value = value;
148 this._dirtyValue = false;
149 this._dirtyTextValue = true;
150 this._needsAssingValue = true;
151 this.needsDraw = true;
152 }
153 this._needsOriginalContent = false;
154 }
155 },
156
157 /**
158 Description TODO
159 @type {Function}
160 */
161 textValue: {
162 enumerable: true,
163 get: function() {
164 var contentNode = this._innerElement,
165 overlayElement = null,
166 overlayParent,
167 overlayNextSibling;
168
169 if (this._dirtyTextValue) {
170 if (contentNode) {
171 // Temporary orphran the overlay slot in order to retrieve the content
172 overlayElement = contentNode.querySelector(".montage-editor-overlay");
173 if (overlayElement) {
174 overlayParent = overlayElement.parentNode;
175 overlayNextSibling = overlayElement.nextSibling;
176 overlayParent.removeChild(overlayElement);
177 }
178
179 this._textValue = this._innerText(contentNode);
180
181 // restore the overlay
182 if (overlayElement) {
183 overlayParent.insertBefore(overlayElement, overlayNextSibling);
184 }
185 } else {
186 this._textValue = "";
187 }
188
189 this._dirtyTextValue = false;
190 }
191 return this._textValue;
192 },
193 set: function (value) {
194 if (this._textValue !== value || this._dirtyTextValue) {
195 // Remove any overlay
196 this.hideOverlay();
197
198 this._textValue = value;