diff options
-rw-r--r-- | js/controllers/clipboard-controller.js | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js index 865d0161..38102512 100644 --- a/js/controllers/clipboard-controller.js +++ b/js/controllers/clipboard-controller.js | |||
@@ -202,15 +202,20 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
202 | 202 | ||
203 | pasteFromCut:{ | 203 | pasteFromCut:{ |
204 | value:function(){ | 204 | value:function(){ |
205 | var i=0, j=0, clipboardHelper=this.createClipboardHelper(), node=null, styles=null; | 205 | var i=0, j=0, |
206 | clipboardHelper=this.createClipboardHelper(), | ||
207 | node = null, canvas = null, | ||
208 | styles=null, | ||
209 | pastedElements = [];//array of te pastes clones - for selection | ||
206 | 210 | ||
207 | for(j=0; j< this.copiedObjects.cut.length; j++){ | 211 | for(j=0; j< this.copiedObjects.cut.length; j++){ |
208 | clipboardHelper.innerHTML = this.copiedObjects.cut[j].outerhtml; | 212 | clipboardHelper.innerHTML = this.copiedObjects.cut[j].outerhtml; |
209 | 213 | ||
210 | if (clipboardHelper.lastChild.tagName === "CANVAS"){ | 214 | if (clipboardHelper.lastChild.tagName === "CANVAS"){ |
211 | //paste canvas | 215 | //paste canvas |
212 | 216 | canvas = this.generateNewCanvas(this.copiedObjects.cut[j].outerhtml, this.copiedObjects.cut[j].styles, this.copiedObjects.cut[j].className, this.copiedObjects.cut[j].worldJson); | |
213 | 217 | NJevent("elementAdded", canvas); | |
218 | pastedElements.push(canvas); | ||
214 | } | 219 | } |
215 | else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode | 220 | else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode |
216 | 221 | ||
@@ -219,6 +224,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
219 | else { | 224 | else { |
220 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); | 225 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); |
221 | this.pastePositioned(node, this.copiedObjects.cut[j].styles); | 226 | this.pastePositioned(node, this.copiedObjects.cut[j].styles); |
227 | pastedElements.push(node); | ||
222 | } | 228 | } |
223 | } | 229 | } |
224 | } | 230 | } |
@@ -307,14 +313,16 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
307 | for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage | 313 | for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage |
308 | elObj = {}; | 314 | elObj = {}; |
309 | elObj["outerhtml"] = this.application.ninja.selectedElements[j].outerHTML; | 315 | elObj["outerhtml"] = this.application.ninja.selectedElements[j].outerHTML; |
310 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j]); | ||
311 | 316 | ||
312 | if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){ | 317 | if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){ |
318 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], true); | ||
313 | if(!ninjaClipboardObj.canvas){ | 319 | if(!ninjaClipboardObj.canvas){ |
314 | ninjaClipboardObj.canvas = true; | 320 | ninjaClipboardObj.canvas = true; |
315 | } | 321 | } |
316 | elObj["worldJson"] = this.application.ninja.selectedElements[j].elementModel.shapeModel.GLWorld.exportJSON(); | 322 | elObj["worldJson"] = this.application.ninja.selectedElements[j].elementModel.shapeModel.GLWorld.exportJSON(); |
323 | elObj["className"] = this.application.ninja.selectedElements[j].className; | ||
317 | }else{ | 324 | }else{ |
325 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], false); | ||
318 | htmlToClipboard = htmlToClipboard + this.serializeHTMLElement(this.application.ninja.selectedElements[j]); | 326 | htmlToClipboard = htmlToClipboard + this.serializeHTMLElement(this.application.ninja.selectedElements[j]); |
319 | if(!ninjaClipboardObj.plainHtml){ | 327 | if(!ninjaClipboardObj.plainHtml){ |
320 | ninjaClipboardObj.plainHtml = true; | 328 | ninjaClipboardObj.plainHtml = true; |
@@ -425,6 +433,45 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
425 | } | 433 | } |
426 | }, | 434 | }, |
427 | 435 | ||
436 | generateNewCanvas: { | ||
437 | value: function(outerhtml, styles, className, worldJson){ | ||
438 | var canvas = document.application.njUtils.make("canvas", className, this.application.ninja.currentDocument); | ||
439 | canvas.width = styles.width; | ||
440 | canvas.height = styles.height; | ||
441 | |||
442 | if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); | ||
443 | document.application.njUtils.createModelWithShape(canvas); | ||
444 | |||
445 | var newCanvasStyles = canvas.elementModel.data || {}; | ||
446 | newCanvasStyles.top = styles.top; | ||
447 | newCanvasStyles.left = styles.left; | ||
448 | |||
449 | this.application.ninja.elementMediator.addElements(canvas, styles, false); | ||
450 | |||
451 | var world, worldData = worldJson; | ||
452 | |||
453 | if(worldData) | ||
454 | { | ||
455 | var jObj; | ||
456 | var index = worldData.indexOf( ';' ); | ||
457 | if ((worldData[0] === 'v') && (index < 24)) | ||
458 | { | ||
459 | // JSON format. separate the version info from the JSON info | ||
460 | var jStr = worldData.substr( index+1 ); | ||
461 | jObj = JSON.parse( jStr ); | ||
462 | |||
463 | world = new World(canvas, jObj.webGL); | ||
464 | canvas.elementModel.shapeModel.GLWorld = world; | ||
465 | canvas.elementModel.shapeModel.useWebGl = jObj.webGL; | ||
466 | world.importJSON(jObj); | ||
467 | this.application.ninja.currentDocument.model.webGlHelper.buildShapeModel( canvas.elementModel, world ); | ||
468 | } | ||
469 | } | ||
470 | |||
471 | return canvas; | ||
472 | } | ||
473 | }, | ||
474 | |||
428 | serializeCanvas:{ | 475 | serializeCanvas:{ |
429 | value:function(sourceCanvas){ | 476 | value:function(sourceCanvas){ |
430 | 477 | ||
@@ -477,12 +524,15 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
477 | }, | 524 | }, |
478 | 525 | ||
479 | getDominantStyles:{ | 526 | getDominantStyles:{ |
480 | value: function(el){ | 527 | value: function(el, isCanvas){ |
481 | var styles = {}; | 528 | var styles = {}; |
482 | styles.top = "" + (this.application.ninja.elementMediator.getProperty(el, "top", parseInt) - 50) + "px"; | 529 | styles.top = "" + (this.application.ninja.elementMediator.getProperty(el, "top", parseInt) - 50) + "px"; |
483 | styles.left = "" + (this.application.ninja.elementMediator.getProperty(el, "left", parseInt) - 50) + "px"; | 530 | styles.left = "" + (this.application.ninja.elementMediator.getProperty(el, "left", parseInt) - 50) + "px"; |
484 | 531 | if(isCanvas){ | |
485 | return null; | 532 | styles.width = (el.getAttribute("width") ? el.getAttribute("width") : null); |
533 | styles.height = (el.getAttribute("height") ? el.getAttribute("height") : null); | ||
534 | } | ||
535 | return styles; | ||
486 | } | 536 | } |
487 | } | 537 | } |
488 | 538 | ||