aboutsummaryrefslogtreecommitdiff
path: root/js/clipboard/external-apps-clipboard-agent.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/clipboard/external-apps-clipboard-agent.js')
-rw-r--r--js/clipboard/external-apps-clipboard-agent.js50
1 files changed, 31 insertions, 19 deletions
diff --git a/js/clipboard/external-apps-clipboard-agent.js b/js/clipboard/external-apps-clipboard-agent.js
index 819f515e..5a82314b 100644
--- a/js/clipboard/external-apps-clipboard-agent.js
+++ b/js/clipboard/external-apps-clipboard-agent.js
@@ -50,28 +50,40 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
50 htmlData = clipboardData.getData("text/html"), 50 htmlData = clipboardData.getData("text/html"),
51 textData = clipboardData.getData("text/plain"), 51 textData = clipboardData.getData("text/plain"),
52 i=0, 52 i=0,
53 imageMime, imageData, imageElement; 53 imageMime, imageData, imageElement, isImage = false, imageItem;
54 54
55 if(!!htmlData || !!textData){ 55 if(clipboardData.items && (clipboardData.items.length > 0)){//handle image blobs
56 try{
57 this.doPasteHtml(htmlData, textData);
58 }catch(e){
59 console.log(""+e.stack);
60 }
61 }else if(clipboardData.items && (clipboardData.items.length > 0)){//handle image blobs
62 for(i=0; i < clipboardData.items.length; i++ ){ 56 for(i=0; i < clipboardData.items.length; i++ ){
63 if((clipboardData.items[i].kind === "file") && (clipboardData.items[i].type.indexOf("image") === 0)){//example type -> "image/png" 57 if((clipboardData.items[i].kind === "file") && (clipboardData.items[i].type.indexOf("image") === 0)){//example type -> "image/png"
64 imageMime = clipboardData.items[i].type; 58 isImage = true;
65 imageData = clipboardData.items[i].getAsFile(); 59 if(clipboardData.items[i].type === "image/png"){
66 try{ 60 imageItem = clipboardData.items[i];//grab the png image from clipboard
67 imageElement = this.pasteImageBinary(imageData); 61 }
68 }catch(e){ 62 else if(i===0){
69 console.log(""+e.stack); 63 imageItem = clipboardData.items[i];
70 } 64 }
71 this.application.ninja.currentDocument.model.needsSave = true;
72 } 65 }
73 } 66 }
74 } 67 }
68
69 if(isImage && imageItem){
70 imageMime = imageItem.type;
71 imageData = imageItem.getAsFile();
72 try{
73 imageElement = this.pasteImageBinary(imageData);
74 }catch(e){
75 console.log(""+e.stack);
76 }
77 this.application.ninja.currentDocument.model.needsSave = true;
78 }
79
80 if(!isImage && (!!htmlData || !!textData)){
81 try{
82 this.doPasteHtml(htmlData, textData);
83 }catch(e){
84 console.log(""+e.stack);
85 }
86 }
75 } 87 }
76 }, 88 },
77 89
@@ -128,7 +140,7 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
128 140
129 doPasteHtml:{ 141 doPasteHtml:{
130 value: function(htmlData, textData){ 142 value: function(htmlData, textData){
131 var divWrapper = null, data = null; 143 var divWrapper = null, data = null, theclass, height, width;
132 144
133 htmlData = this.sanitize(htmlData); 145 htmlData = this.sanitize(htmlData);
134 textData = this.sanitize(textData); 146 textData = this.sanitize(textData);
@@ -150,13 +162,13 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
150 divWrapper.innerHTML = data; 162 divWrapper.innerHTML = data;
151 163
152 //hack to set the wrapper div's height and width as per the pasted content 164 //hack to set the wrapper div's height and width as per the pasted content
153 var theclass = divWrapper.getAttribute("class"); 165 theclass = divWrapper.getAttribute("class");
154 //temporarily remove the class to find the computed styles for the pasted content 166 //temporarily remove the class to find the computed styles for the pasted content
155 if(theclass){ 167 if(theclass){
156 divWrapper.removeAttribute("class"); 168 divWrapper.removeAttribute("class");
157 } 169 }
158 var height = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("height"); 170 height = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("height");
159 var width = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("width"); 171 width = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("width");
160 172
161 divWrapper.setAttribute("class", theclass); 173 divWrapper.setAttribute("class", theclass);
162 174