aboutsummaryrefslogtreecommitdiff
path: root/js/clipboard/external-apps-clipboard-agent.js
diff options
context:
space:
mode:
authorAnanya Sen2012-07-17 14:24:17 -0700
committerAnanya Sen2012-07-17 14:24:17 -0700
commitf2dbca782bbaca3bed96dff808693693ba083ea9 (patch)
tree569e31c77fa81a04078bfb7ca89b86d2dc8a1bdb /js/clipboard/external-apps-clipboard-agent.js
parent5a34cac9594d710f6e5675bee34dc16be1b4d8a0 (diff)
downloadninja-f2dbca782bbaca3bed96dff808693693ba083ea9.tar.gz
Fixes : resize wrapper for content, prevent duplicate pastes
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/clipboard/external-apps-clipboard-agent.js')
-rw-r--r--js/clipboard/external-apps-clipboard-agent.js58
1 files changed, 38 insertions, 20 deletions
diff --git a/js/clipboard/external-apps-clipboard-agent.js b/js/clipboard/external-apps-clipboard-agent.js
index e78950df..819f515e 100644
--- a/js/clipboard/external-apps-clipboard-agent.js
+++ b/js/clipboard/external-apps-clipboard-agent.js
@@ -52,8 +52,13 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
52 i=0, 52 i=0,
53 imageMime, imageData, imageElement; 53 imageMime, imageData, imageElement;
54 54
55 //handle image blobs 55 if(!!htmlData || !!textData){
56 if(clipboardData.items && (clipboardData.items.length > 0)){ 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
57 for(i=0; i < clipboardData.items.length; i++ ){ 62 for(i=0; i < clipboardData.items.length; i++ ){
58 if((clipboardData.items[i].kind === "file") && (clipboardData.items[i].type.indexOf("image") === 0)){//example type -> "image/png" 63 if((clipboardData.items[i].kind === "file") && (clipboardData.items[i].type.indexOf("image") === 0)){//example type -> "image/png"
59 imageMime = clipboardData.items[i].type; 64 imageMime = clipboardData.items[i].type;
@@ -67,15 +72,6 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
67 } 72 }
68 } 73 }
69 } 74 }
70
71 try{
72 if(!!htmlData || !!textData){
73 this.doPasteHtml(htmlData, textData);
74 }
75 }catch(e){
76 console.log(""+e.stack);
77 }
78
79 } 75 }
80 }, 76 },
81 77
@@ -134,14 +130,8 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
134 value: function(htmlData, textData){ 130 value: function(htmlData, textData){
135 var divWrapper = null, data = null; 131 var divWrapper = null, data = null;
136 132
137 if(htmlData){ 133 htmlData = this.sanitize(htmlData);
138 //cleanse HTML 134 textData = this.sanitize(textData);
139 htmlData = htmlData.replace(/\<meta [^>]+>/gi, ""); // Remove the meta tag.
140 htmlData = htmlData.replace(/\<script [^>]+>/g," "); // Remove the script tag.
141 }
142
143 textData = textData.replace(/\<script [^>]+>/g," "); // Remove any script tag.
144
145 135
146 data = htmlData ? htmlData : textData; 136 data = htmlData ? htmlData : textData;
147 137
@@ -155,12 +145,40 @@ var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.cr
155 "left": "0px", 145 "left": "0px",
156 "position": "absolute", 146 "position": "absolute",
157 "top": "0px", 147 "top": "0px",
158 "width": "161px"}); 148 "width": "161px"}, false);
159 149
160 divWrapper.innerHTML = data; 150 divWrapper.innerHTML = data;
161 151
152 //hack to set the wrapper div's height and width as per the pasted content
153 var theclass = divWrapper.getAttribute("class");
154 //temporarily remove the class to find the computed styles for the pasted content
155 if(theclass){
156 divWrapper.removeAttribute("class");
157 }
158 var height = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("height");
159 var width = divWrapper.ownerDocument.defaultView.getComputedStyle(divWrapper).getPropertyValue("width");
160
161 divWrapper.setAttribute("class", theclass);
162
163 this.application.ninja.stylesController.setElementStyle(divWrapper, "height", height);
164 this.application.ninja.stylesController.setElementStyle(divWrapper, "width", width);
165 //-end hack
166
167 NJevent("elementAdded", divWrapper);
168
162 this.application.ninja.currentDocument.model.needsSave = true; 169 this.application.ninja.currentDocument.model.needsSave = true;
163 } 170 }
164 } 171 }
172 },
173
174 sanitize : {
175 value: function(data){
176 data = data.replace(/\<meta [^>]+>/gi, ""); // Remove meta tags
177 data = data.replace(/\<script [^>]+>/g," "); // Remove script tags
178 data = data.replace(/\<link [^>]+>/g," "); // Remove script tags
179 data = data.replace(/\<xml [^>]+>/g," "); // Remove script tags
180
181 return data;
182 }
165 } 183 }
166}); 184});