From 5a34cac9594d710f6e5675bee34dc16be1b4d8a0 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Jul 2012 15:34:07 -0700 Subject: Fixed copy paste from external applications Signed-off-by: Ananya Sen --- js/clipboard/external-apps-clipboard-agent.js | 138 +++++---------------- .../internal-ops/elements-clipboard-agent.js | 24 ++-- js/mediators/element-mediator.js | 6 +- 3 files changed, 42 insertions(+), 126 deletions(-) (limited to 'js') diff --git a/js/clipboard/external-apps-clipboard-agent.js b/js/clipboard/external-apps-clipboard-agent.js index 6b9d8090..e78950df 100644 --- a/js/clipboard/external-apps-clipboard-agent.js +++ b/js/clipboard/external-apps-clipboard-agent.js @@ -38,6 +38,12 @@ var Montage = require("montage/core/core").Montage, var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.create(Component, { + //count how many times pasted + //used to move multiple pastes of same copy + pasteCounter:{ + value: 0 + }, + paste:{ value: function(clipboardEvent){ var clipboardData = clipboardEvent.clipboardData, @@ -57,16 +63,14 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr }catch(e){ console.log(""+e.stack); } - this.application.ninja.selectionController.selectElements(imageElement); this.application.ninja.currentDocument.model.needsSave = true; - } } } try{ if(!!htmlData || !!textData){ - this.pasteHtml(htmlData, textData); + this.doPasteHtml(htmlData, textData); } }catch(e){ console.log(""+e.stack); @@ -108,16 +112,16 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr //Adding element once it is loaded element.onload = function () { element.onload = null; - self.application.ninja.elementMediator.addElements(element, rules, true); + self.application.ninja.elementMediator.addElements(element, rules, true/*notify*/, false /*callAddDelegate*/); }; //Setting rules of element rules = { 'position': 'absolute', - 'top' : '100px', - 'left' : '100px' + 'top' : '0px', + 'left' : '0px' }; // - self.application.ninja.elementMediator.addElements(element, rules, false); + self.application.ninja.elementMediator.addElements(element, rules, false/*notify*/, false /*callAddDelegate*/); } else { //HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT } @@ -126,119 +130,37 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr } }, - //paste from external applicaitons - pasteHtml:{ + doPasteHtml:{ value: function(htmlData, textData){ - var i=0, j=0, - pasteDataObject=null, - pastedElements = [], - node = null, nodeList = null, - styles = null, - divWrapper = null, - spanWrapper = null, - metaEl = null, - self = this; + var divWrapper = null, data = null; if(htmlData){ - //cleanse HTML - - htmlData.replace(/["+ textData +"")[0]; - styles = {"position":"absolute", "top":"100px", "left":"100px"}; - this.pastePositioned(node, styles); + htmlData = htmlData.replace(/\]+>/gi, ""); // Remove the meta tag. + htmlData = htmlData.replace(/\