aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnanya Sen2012-06-13 10:47:25 -0700
committerAnanya Sen2012-06-13 10:47:25 -0700
commit2bffaa0204adcab02c488ba81d845ed049f517de (patch)
tree96173664d574151ce84da6a41422ee767f256c91
parent3389cd085555e188800f337525c0fc8884084c04 (diff)
downloadninja-2bffaa0204adcab02c488ba81d845ed049f517de.tar.gz
displace pasted object only if the position is absolute
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
-rw-r--r--js/controllers/clipboard-controller.js61
1 files changed, 35 insertions, 26 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js
index 9fcadaac..c8520e04 100644
--- a/js/controllers/clipboard-controller.js
+++ b/js/controllers/clipboard-controller.js
@@ -212,12 +212,14 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
212 else { 212 else {
213 node = copiedElement.cloneNode(true); 213 node = copiedElement.cloneNode(true);
214 214
215 if(node.removeAttribute) {node.removeAttribute("style");}//remove the computed styles attribute which is placed only for pasting to external applications 215 if(copiedElement.ownerDocument.defaultView.getComputedStyle(copiedElement).getPropertyValue("position") === "absolute"){
216 216 styles = {};
217 styles = {}; 217 styles.top = this.application.ninja.elementMediator.getProperty(copiedElement, "top", parseInt);
218 styles.top = this.application.ninja.elementMediator.getProperty(copiedElement, "top", parseInt); 218 styles.left = this.application.ninja.elementMediator.getProperty(copiedElement, "left", parseInt);
219 styles.left = this.application.ninja.elementMediator.getProperty(copiedElement, "left", parseInt); 219 styles.position = "absolute";
220 220 }else{
221 styles = null;
222 }
221 this.pastePositioned(node, styles); 223 this.pastePositioned(node, styles);
222 pastedElements.push(node); 224 pastedElements.push(node);
223 } 225 }
@@ -326,7 +328,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
326 node = clipboardHelper.removeChild(clipboardHelper.lastChild); 328 node = clipboardHelper.removeChild(clipboardHelper.lastChild);
327 329
328 //get class string while copying .... generate styles from class 330 //get class string while copying .... generate styles from class
329 styles = {"top":"100px", "left":"100px"}; 331 styles = null;
330 332
331 this.pastePositioned(node, styles); 333 this.pastePositioned(node, styles);
332 } 334 }
@@ -339,7 +341,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
339 //USE styles controller to create the styles of the div and span 341 //USE styles controller to create the styles of the div and span
340 clipboardHelper.innerHTML = "<div><span>"+ textData +"</span></div>";//add the copied html to generate the nodes 342 clipboardHelper.innerHTML = "<div><span>"+ textData +"</span></div>";//add the copied html to generate the nodes
341 node = clipboardHelper.removeChild(clipboardHelper.lastChild); 343 node = clipboardHelper.removeChild(clipboardHelper.lastChild);
342 styles = {"top":"100px", "left":"100px"};//get real stage center coordinates 344 styles = null;//get real stage center coordinates
343 this.pastePositioned(node, styles); 345 this.pastePositioned(node, styles);
344 } 346 }
345 347
@@ -439,21 +441,26 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
439 441
440 cloneCanvas:{ 442 cloneCanvas:{
441 value: function(sourceCanvas){ 443 value: function(sourceCanvas){
442 var canvas = document.application.njUtils.make("canvas", sourceCanvas.className, this.application.ninja.currentDocument); 444 var canvas, styles, world, worldData;
445
446 canvas = document.application.njUtils.make("canvas", sourceCanvas.className, this.application.ninja.currentDocument);
443 canvas.width = sourceCanvas.width; 447 canvas.width = sourceCanvas.width;
444 canvas.height = sourceCanvas.height; 448 canvas.height = sourceCanvas.height;
445 //end - clone copied canvas 449 //end - clone copied canvas
446 450
447 if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); 451 if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
448 452
449 var styles = canvas.elementModel.data || {}; 453 if(sourceCanvas.ownerDocument.defaultView.getComputedStyle(sourceCanvas).getPropertyValue("position") === "absolute"){
450 styles.top = "" + (this.application.ninja.elementMediator.getProperty(sourceCanvas, "top", parseInt) + (25 * this.pasteCounter))+"px"; 454 styles = canvas.elementModel.data || {};
451 styles.left = "" + (this.application.ninja.elementMediator.getProperty(sourceCanvas, "left", parseInt) + (25 * this.pasteCounter)) + "px"; 455 styles.top = "" + (this.application.ninja.elementMediator.getProperty(sourceCanvas, "top", parseInt) + (25 * this.pasteCounter))+"px";
456 styles.left = "" + (this.application.ninja.elementMediator.getProperty(sourceCanvas, "left", parseInt) + (25 * this.pasteCounter)) + "px";
457 }else{
458 styles = null;
459 }
452 460
453 //this.application.ninja.elementMediator.addElements(canvas, styles, false);//todo: clean up 461 this.application.ninja.elementMediator.addElements(canvas, styles, false);
454 this.application.ninja.elementMediator.addElements(canvas, null, false);//no displacement
455 462
456 var world, worldData = sourceCanvas.elementModel.shapeModel.GLWorld.exportJSON(); 463 worldData = sourceCanvas.elementModel.shapeModel.GLWorld.exportJSON();
457 if(worldData) 464 if(worldData)
458 { 465 {
459 var jObj; 466 var jObj;
@@ -478,20 +485,17 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
478 485
479 generateNewCanvas: { 486 generateNewCanvas: {
480 value: function(outerhtml, styles, className, worldJson){ 487 value: function(outerhtml, styles, className, worldJson){
481 var canvas = document.application.njUtils.make("canvas", className, this.application.ninja.currentDocument); 488 var canvas, newCanvasStyles, world, worldData;
489
490 canvas = document.application.njUtils.make("canvas", className, this.application.ninja.currentDocument);
482 canvas.width = styles.width; 491 canvas.width = styles.width;
483 canvas.height = styles.height; 492 canvas.height = styles.height;
484 493
485 if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); 494 if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
486 495
487 var newCanvasStyles = canvas.elementModel.data || {}; 496 this.application.ninja.elementMediator.addElements(canvas, null, false);
488 newCanvasStyles.top = styles.top;
489 newCanvasStyles.left = styles.left;
490 497
491 //this.application.ninja.elementMediator.addElements(canvas, styles, false);//todo: clean up 498 worldData = worldJson;
492 this.application.ninja.elementMediator.addElements(canvas, null, false);//no displacement
493
494 var world, worldData = worldJson;
495 499
496 if(worldData) 500 if(worldData)
497 { 501 {
@@ -561,9 +565,11 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
561 newX = styles ? ("" + (styles.left + (25 * this.pasteCounter)) + "px") : "100px"; 565 newX = styles ? ("" + (styles.left + (25 * this.pasteCounter)) + "px") : "100px";
562 newY = styles ? ("" + (styles.top + (25 * this.pasteCounter)) + "px") : "100px"; 566 newY = styles ? ("" + (styles.top + (25 * this.pasteCounter)) + "px") : "100px";
563 567
564 568 if(!styles || (styles && !styles.position)){
565 this.application.ninja.elementMediator.addElements(element, null); 569 this.application.ninja.elementMediator.addElements(element, null);
566 570 }else if(styles && (styles.position === "absolute")){
571 this.application.ninja.elementMediator.addElements(element, {"top" : newY, "left" : newX});//displace
572 }
567 573
568 //todo: cleanup 574 //todo: cleanup
569// //add pasted object with new position 575// //add pasted object with new position
@@ -585,6 +591,9 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component
585 var styles = {}; 591 var styles = {};
586 styles.top = this.application.ninja.elementMediator.getProperty(el, "top", parseInt); 592 styles.top = this.application.ninja.elementMediator.getProperty(el, "top", parseInt);
587 styles.left = this.application.ninja.elementMediator.getProperty(el, "left", parseInt); 593 styles.left = this.application.ninja.elementMediator.getProperty(el, "left", parseInt);
594 if(el.ownerDocument.defaultView.getComputedStyle(el).getPropertyValue("position") === "absolute"){
595 styles.position = "absolute";
596 }
588 if(isCanvas){ 597 if(isCanvas){
589 styles.width = (el.getAttribute("width") ? el.getAttribute("width") : null); 598 styles.width = (el.getAttribute("width") ? el.getAttribute("width") : null);
590 styles.height = (el.getAttribute("height") ? el.getAttribute("height") : null); 599 styles.height = (el.getAttribute("height") ? el.getAttribute("height") : null);