diff options
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/TextTool.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/js/tools/TextTool.js b/js/tools/TextTool.js index 0aef6c1c..7f82855b 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 | ||