aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnanya Sen2012-06-01 17:37:07 -0700
committerAnanya Sen2012-06-01 17:37:07 -0700
commitcf097ec69e35c07ecae5a105ed5eeb78291c9ac2 (patch)
treef33e825e3b74a33a09c5b63eb0e0c0a3a291c9ba
parent286457b4f23974277274ba388afd283e8aa085cb (diff)
downloadninja-cf097ec69e35c07ecae5a105ed5eeb78291c9ac2.tar.gz
cut/paste html elements in single document
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
-rw-r--r--js/controllers/clipboard-controller.js222
1 files changed, 146 insertions, 76 deletions
</
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js
index 3f15ac1d..865d0161 100644
--- a/js/controllers/clipboard-controller.js
+++ b/js/controllers/clipboard-controller.js
@@ -35,7 +35,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
35 }, 35 },
36 36
37 copiedObjects:{ 37 copiedObjects:{
38 value: [] 38 value: {}
39 }, 39 },
40 40
41 _copyFlag:{ 41 _copyFlag:{
@@ -69,8 +69,8 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
69 }, 69 },
70 70
71 handleCopy:{ 71 handleCopy:{
72 value:function(clipboardEvent, test){ 72 value:function(clipboardEvent){
73 if(this.application.ninja.documentController.activeDocument.currentView === "code") return; 73 if(this.application.ninja.currentDocument.currentView === "code") return;
74 74
75 this.copy(clipboardEvent); 75 this.copy(clipboardEvent);
76 76
@@ -78,9 +78,19 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
78 } 78 }
79 }, 79 },
80 80
81 handleCut:{
82 value:function(clipboardEvent){
83 if(this.application.ninja.currentDocument.currentView === "code") return;
84
85 this.cut(clipboardEvent);
86
87 clipboardEvent.preventDefault();
88 }
89 },
90
81 handlePaste:{ 91 handlePaste:{
82 value:function(clipboardEvent){ 92 value:function(clipboardEvent){
83 if(this.application.ninja.documentController.activeDocument.currentView === "code") return;//for design view only 93 if(this.application.ninja.currentDocument.currentView === "code") return;//for design view only
84 94
85 //TODO: return if stage is not focussed 95 //TODO: return if stage is not focussed
86 96
@@ -94,11 +104,12 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
94 svgData = clipboardData.getData("image/svg"); 104 svgData = clipboardData.getData("image/svg");
95 105
96 if(ninjaData){ 106 if(ninjaData){
97 this.pasteFromNinja(); 107 if(this.copiedObjects.copy){this.pasteFromCopy();}
108 else{this.pasteFromCut();}
98 }else if(imageData){ 109 }else if(imageData){
99 this.pasteImage(imageData); 110 this.pasteImage(imageData);
100 }else{ 111 }else{
101 this.pasteItems(htmlData, textData); 112 this.pasteFromExternalSource(htmlData, textData);
102 } 113 }
103 114
104 115
@@ -112,18 +123,19 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
112 copy:{ 123 copy:{
113 value: function(clipboardEvent){ 124 value: function(clipboardEvent){
114 var j=0, htmlToClipboard = "", ninjaClipboardObj = {}, textToClipboard = ""; 125 var j=0, htmlToClipboard = "", ninjaClipboardObj = {}, textToClipboard = "";
115 this.copiedObjects.length = 0; 126 this.copiedObjects = {};
127 this.copiedObjects["copy"] = [];
116 128
117 if(clipboardEvent){ 129 if(clipboardEvent){
118 for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage 130 for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage
119 this.copiedObjects.push(this.application.ninja.selectedElements[j]); 131 this.copiedObjects.copy.push(this.application.ninja.selectedElements[j]);
120 132
121 if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){ 133 if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){
122 if(!ninjaClipboardObj.canvas){ 134 if(!ninjaClipboardObj.canvas){
123 ninjaClipboardObj.canvas = true; 135 ninjaClipboardObj.canvas = true;
124 } 136 }
125 }else{ 137 }else{
126 htmlToClipboard = htmlToClipboard + this.serialize(this.application.ninja.selectedElements[j]); 138 htmlToClipboard = htmlToClipboard + this.serializeHTMLElement(this.application.ninja.selectedElements[j]);
127 if(!ninjaClipboardObj.plainHtml){ 139 if(!ninjaClipboardObj.plainHtml){
128 ninjaClipboardObj.plainHtml = true; 140 ninjaClipboardObj.plainHtml = true;
129 } 141 }
@@ -142,7 +154,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
142 } 154 }
143 }, 155 },
144 156
145 pasteFromNinja:{//todo: change to appropriate name 157 pasteFromCopy:{//todo: change to appropriate name
146 value:function(){ 158 value:function(){
147 var i=0, j=0, 159 var i=0, j=0,
148 pastedElements = [],//array of te pastes clones - for selection 160 pastedElements = [],//array of te pastes clones - for selection
@@ -157,47 +169,14 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
157 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": true} ); 169 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": true} );
158 170
159 171
160 for(j=0; j< this.copiedObjects.length; j++){ 172 for(j=0; j< this.copiedObjects.copy.length; j++){
161 copiedElement = this.copiedObjects[j]; 173 copiedElement = this.copiedObjects.copy[j];
162 styles = null; 174 styles = null;
163 175
164 if (copiedElement.tagName === "CANVAS"){ 176 if (copiedElement.tagName === "CANVAS"){
165 //clone copied canvas 177 //clone copied canvas
166 var canvas = document.application.njUtils.make("canvas", copiedElement.className, this.application.ninja.currentDocument); 178 var canvas = this.cloneCanvas(copiedElement);
167 canvas.width = copiedElement.width;
168 canvas.height = copiedElement.height;
169 //end - clone copied canvas
170
171 if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
172 document.application.njUtils.createModelWithShape(canvas);
173
174 styles = canvas.elementModel.data || {};
175 styles.top = "" + (this.application.ninja.elementMediator.getProperty(copiedElement, "top", parseInt) - 50) + "px";
176 styles.left = "" + (this.application.ninja.elementMediator.getProperty(copiedElement, "left", parseInt) - 50) + "px";
177
178 this.application.ninja.elementMediator.addElements(canvas, styles, false);
179
180 var world, worldData = copiedElement.elementModel.shapeModel.GLWorld.exportJSON();
181 if(worldData)
182 {
183 var jObj;
184 var index = worldData.indexOf( ';' );
185 if ((worldData[0] === 'v') && (index < 24))
186 {
187 // JSON format. separate the version info from the JSON info
188 var jStr = worldData.substr( index+1 );
189 jObj = JSON.parse( jStr );
190
191 world = new World(canvas, jObj.webGL);
192 canvas.elementModel.shapeModel.GLWorld = world;
193 canvas.elementModel.shapeModel.useWebGl = jObj.webGL;
194 world.importJSON(jObj);
195 this.application.ninja.currentDocument.buildShapeModel( canvas.elementModel, world );
196 }
197 }
198
199 NJevent("elementAdded", canvas); 179 NJevent("elementAdded", canvas);
200
201 pastedElements.push(canvas); 180 pastedElements.push(canvas);
202 } 181 }
203 else { 182 else {
@@ -215,16 +194,38 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
215 194
216 } 195 }
217 196
197 this.application.ninja.selectionController.selectElements(pastedElements);
218 198
219 this.application.ninja.selectionController.selectElements(pastedElements);//select pasted elements - not working! 199 this.application.ninja.currentDocument.model.needsSave = true;
200 }
201 },
220 202
203 pasteFromCut:{
204 value:function(){
205 var i=0, j=0, clipboardHelper=this.createClipboardHelper(), node=null, styles=null;
221 206
222 this.application.ninja.documentController.activeDocument.needsSave = true; 207 for(j=0; j< this.copiedObjects.cut.length; j++){
223 } 208 clipboardHelper.innerHTML = this.copiedObjects.cut[j].outerhtml;
209
210 if (clipboardHelper.lastChild.tagName === "CANVAS"){
211 //paste canvas
212
213
214 }
215 else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode
216
217
218 }
219 else {
220 node = clipboardHelper.removeChild(clipboardHelper.lastChild);
221 this.pastePositioned(node, this.copiedObjects.cut[j].styles);
222 }
223 }
224 }
224 }, 225 },
225 226
226 //paste from external applicaitons 227 //paste from external applicaitons
227 pasteItems:{//todo: change to pasteNinja, pasteHTML, etc 228 pasteFromExternalSource:{//todo: change to pasteNinja, pasteHTML, etc
228 value: function(htmlData, textData){ 229 value: function(htmlData, textData){
229 var i=0, 230 var i=0,
230 pasteDataObject=null, 231 pasteDataObject=null,
@@ -283,7 +284,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
283 284
284 } 285 }
285 286
286 this.application.ninja.documentController.activeDocument.needsSave = true; 287 this.application.ninja.currentDocument.model.needsSave = true;
287 }else if(textData){ 288 }else if(textData){
288 289
289 //USE styles controller to create the styles of the div and span 290 //USE styles controller to create the styles of the div and span