aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-05 23:13:03 -0700
committerArmen Kesablyan2012-06-05 23:13:03 -0700
commit7d3bdf39e6d1534de1848ca2744aed66dfeb5d2a (patch)
tree12cf81e70f38e4bbe8739654d6c4aa4e5f8f498c /js/tools
parent73a62c95b5635fee903457279f0f5b57f164e0b5 (diff)
downloadninja-7d3bdf39e6d1534de1848ca2744aed66dfeb5d2a.tar.gz
Initial Text Tool Changes
Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/TextTool.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/js/tools/TextTool.js b/js/tools/TextTool.js
index 024a92ce..cff3b6e3 100755
--- a/js/tools/TextTool.js
+++ b/js/tools/TextTool.js
@@ -27,7 +27,7 @@ exports.TextTool = Montage.create(DrawingTool, {
27 this.selectedElement.innerHTML = this.application.ninja.stage.textTool.value; 27 this.selectedElement.innerHTML = this.application.ninja.stage.textTool.value;
28 this.application.ninja.stage.textTool.value = ""; 28 this.application.ninja.stage.textTool.value = "";
29 this.application.ninja.stage.textTool.element.style.display = "none"; 29 this.application.ninja.stage.textTool.element.style.display = "none";
30 ElementsMediator.setProperty(this.application.ninja.selectedElements, "color", [window.getComputedStyle(this.application.ninja.stage.textTool.element.firstChild)["color"]], "Change", "textTool"); 30 ElementsMediator.setProperty(this.application.ninja.selectedElements, "color", [window.getComputedStyle(this.application.ninja.stage.textTool.element)["color"]], "Change", "textTool");
31 } 31 }
32 //Set Selected Element 32 //Set Selected Element
33 this._selectedElement = val; 33 this._selectedElement = val;
@@ -96,6 +96,22 @@ exports.TextTool = Montage.create(DrawingTool, {
96 } 96 }
97 }, 97 },
98 98
99 getSelectedElement: {
100 value: function(editor) {
101 var element = editor._selectedRange.startContainer;
102 if (element.nodeType == 3) {
103 element = element.parentNode;
104 }
105 return element;
106 }
107 },
108
109 getStyleOfSelectedElement: {
110 value: function(editor) {
111 return window.getComputedStyle(this.getSelectedElement(editor));
112 }
113 },
114
99 applyElementStyles : { 115 applyElementStyles : {
100 value: function(fromElement, toElement, styles) { 116 value: function(fromElement, toElement, styles) {
101 styles.forEach(function(style) { 117 styles.forEach(function(style) {
@@ -108,11 +124,11 @@ exports.TextTool = Montage.create(DrawingTool, {
108 drawTextTool: { 124 drawTextTool: {
109 value: function() { 125 value: function() {
110 var self = this; 126 var self = this;
111
112 this.application.ninja.stage.textTool.value = this.selectedElement.innerHTML; 127 this.application.ninja.stage.textTool.value = this.selectedElement.innerHTML;
113 if(this.application.ninja.stage.textTool.value === "") { this.application.ninja.stage.textTool.value = " "; } 128 if(this.application.ninja.stage.textTool.value === "") { this.application.ninja.stage.textTool.value = " "; }
114 this.selectedElement.innerHTML = ""; 129 this.selectedElement.innerHTML = "";
115 130
131
116 //Styling Options for text tool to look identical to the text you are manipulating. 132 //Styling Options for text tool to look identical to the text you are manipulating.
117 this.application.ninja.stage.textTool.element.style.display = "block"; 133 this.application.ninja.stage.textTool.element.style.display = "block";
118 this.application.ninja.stage.textTool.element.style.position = "absolute"; 134 this.application.ninja.stage.textTool.element.style.position = "absolute";
@@ -124,14 +140,11 @@ exports.TextTool = Montage.create(DrawingTool, {
124 // Set font styling (Size, Style, Weight) 140 // Set font styling (Size, Style, Weight)
125 this.application.ninja.stage.textTool.didDraw = function() { 141 this.application.ninja.stage.textTool.didDraw = function() {
126 self.applyElementStyles(self.selectedElement, self.application.ninja.stage.textTool.element, ["overflow"]); 142 self.applyElementStyles(self.selectedElement, self.application.ninja.stage.textTool.element, ["overflow"]);
127 self.applyElementStyles(self.selectedElement, self.application.ninja.stage.textTool.element.firstChild, ["font","padding-left","padding-top","padding-right","padding-bottom", "color"]); 143 self.applyElementStyles(self.selectedElement, self.application.ninja.stage.textTool.element, ["font","padding-left","padding-top","padding-right","padding-bottom", "color"]);
128 var range = document.createRange(), 144 this.selectAll();
129 sel = window.getSelection();
130 sel.removeAllRanges();
131 range.selectNodeContents(self.application.ninja.stage.textTool.element.firstChild);
132 sel.addRange(range);
133 this.didDraw = function() {}; 145 this.didDraw = function() {};
134 } 146 }
147
135 } 148 }
136 }, 149 },
137 150