From 1563cf61a61c5d6e77d6e19f1074f661ce1e195b Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 19 Jun 2012 15:24:05 -0700 Subject: parse html in memory, instead of using a doom element Signed-off-by: Ananya Sen --- js/controllers/clipboard-controller.js | 92 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 47 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js index bc78922c..5e63e424 100644 --- a/js/controllers/clipboard-controller.js +++ b/js/controllers/clipboard-controller.js @@ -250,27 +250,25 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component pasteFromCut:{ value:function(){ var i=0, j=0, - clipboardHelper=this.createClipboardHelper(), node = null, canvas = null, styles=null, pastedElements = [];//array of te pastes clones - for selection for(j=0; j< this.copiedObjects.cut.length; j++){ - clipboardHelper.innerHTML = this.copiedObjects.cut[j].outerhtml; + node = this.deserializeHtmlString(this.copiedObjects.cut[j].outerhtml)[0]; - if (clipboardHelper.lastChild.tagName === "CANVAS"){ + if (node.tagName === "CANVAS"){ //paste canvas canvas = this.generateNewCanvas(this.copiedObjects.cut[j].outerhtml, this.copiedObjects.cut[j].styles, this.copiedObjects.cut[j].className, this.copiedObjects.cut[j].worldJson); NJevent("elementAdded", canvas); pastedElements.push(canvas); - clipboardHelper.removeChild(clipboardHelper.lastChild); + node = null; } - else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode - + else if((node.nodeType === 3) || (node.tagName === "A")){//TextNode + node = null; } else { - node = clipboardHelper.removeChild(clipboardHelper.lastChild); this.pastePositioned(node, this.copiedObjects.cut[j].styles, true/*notify*/, false/*fromCopy*/); pastedElements.push(node); } @@ -286,78 +284,81 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component value: function(htmlData, textData){ var i=0, j=0, pasteDataObject=null, - clipboardHelper=this.createClipboardHelper(), pastedElements = null, - node = null, + node = null, nodeList = null, styles = null, divWrapper = null, spanWrapper = null, - metaEl = null; + metaEl = null, + self = this; if(htmlData){ //TODO: cleanse HTML - //TODO: remove all script tags for security htmlData.replace(/[";//add the copied html to generate the nodes - node = clipboardHelper.removeChild(clipboardHelper.lastChild); - styles = null;//get real stage center coordinates + node = self.deserializeHtmlString("
"+ textData +"
")[0]; + styles = {"position":"absolute", "top":"100px", "left":"100px"}; this.pastePositioned(node, styles, true/*notify*/); } @@ -408,25 +409,22 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component } }, - createClipboardHelper:{ - value:function(){ + deserializeHtmlString:{ + value:function(htmlString){ var doc = (this.application.ninja.currentDocument.currentView === "design") ? this.application.ninja.currentDocument.model.views.design.document : document, - clipboardHelper=doc.getElementById("clipboardHelper"); - if(!clipboardHelper){ - clipboardHelper = doc.createElement ("div"); - clipboardHelper.id = "clipboardHelper"; - clipboardHelper.style.display="none"; - clipboardHelper.style.position = "absolute"; - clipboardHelper.style.right = "-1000px"; - clipboardHelper.style.top = "-1000px"; - - doc.body.appendChild (clipboardHelper); - } - return clipboardHelper; + clipboardHelper=doc.createElement("div"), + nodeList = null; + + clipboardHelper.innerHTML = htmlString; + + nodeList = clipboardHelper.childNodes; + + clipboardHelper = null; //for garbage collection + + return nodeList; } }, - serializeHTMLElement:{ value: function(elem){ var computedStyles = null, originalStyleAttr = null, computedStylesStr = "", i=0, stylePropertyName="", outerHtml = ""; -- cgit v1.2.3