aboutsummaryrefslogtreecommitdiff
path: root/js/clipboard
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-25 11:14:40 -0700
committerArmen Kesablyan2012-06-25 11:14:40 -0700
commit446f475c35e3d0d5d6cb6ca35346e548de6c36f9 (patch)
tree0b7e7154979754db2c0ebb7b7908c555068d515d /js/clipboard
parent7867aec2620b65605180979b5049cfa154ca7dd1 (diff)
parent35aebe8d72ccfa9ea010eb79c09ecf89cc1ed44d (diff)
downloadninja-446f475c35e3d0d5d6cb6ca35346e548de6c36f9.tar.gz
Merge branch 'refs/heads/master' into binding
Conflicts: js/ninja.reel/ninja.html Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/clipboard')
-rw-r--r--js/clipboard/external-apps-clipboard-agent.js220
-rw-r--r--js/clipboard/internal-ops/component-clipboard-agent.js40
-rw-r--r--js/clipboard/internal-ops/css-clipboard-agent.js40
-rw-r--r--js/clipboard/internal-ops/elements-clipboard-agent.js364
-rw-r--r--js/clipboard/internal-ops/timeline-clipboard-agent.js40
-rw-r--r--js/clipboard/util.js28
6 files changed, 732 insertions, 0 deletions
diff --git a/js/clipboard/external-apps-clipboard-agent.js b/js/clipboard/external-apps-clipboard-agent.js
new file mode 100644
index 00000000..7e55cf08
--- /dev/null
+++ b/js/clipboard/external-apps-clipboard-agent.js
@@ -0,0 +1,220 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9
10var Montage = require("montage/core/core").Montage,
11 Component = require("montage/ui/component").Component,
12 ClipboardUtil = require("js/clipboard/util").ClipboardUtil;
13
14var ExternalAppsClipboardAgent = exports.ExternalAppsClipboardAgent = Montage.create(Component, {
15
16 paste:{
17 value: function(clipboardEvent){
18 var clipboardData = clipboardEvent.clipboardData,
19 htmlData = clipboardData.getData("text/html"),
20 textData = clipboardData.getData("text/plain"),
21 i=0,
22 imageMime, imageData, imageElement;
23
24 //handle image blobs
25 if(clipboardData.items && (clipboardData.items.length > 0)){
26 for(i=0; i < clipboardData.items.length; i++ ){
27 if((clipboardData.items[i].kind === "file") && (clipboardData.items[i].type.indexOf("image") === 0)){//example type -> "image/png"
28 imageMime = clipboardData.items[i].type;
29 imageData = clipboardData.items[i].getAsFile();
30 try{
31 imageElement = this.pasteImageBinary(imageData);
32 }catch(e){
33 console.log(""+e.stack);
34 }
35 this.application.ninja.selectionController.selectElements(imageElement);
36 this.application.ninja.currentDocument.model.needsSave = true;
37
38 }
39 }
40 }
41
42 try{
43 if(!!htmlData || !!textData){
44 this.pasteHtml(htmlData, textData);
45 }
46 }catch(e){
47 console.log(""+e.stack);
48 }
49
50 }
51 },
52
53 //todo: this will be moved to a seperate api
54 pasteImageBinary:{
55 value: function(imageBlob){
56 var element, self = this,
57 fileType = imageBlob.type;
58
59 element = this.application.ninja.ioMediator.createFileFromBinary(imageBlob, {"addFileToStage" : self.addImageElement.bind(self)});
60
61 return element;
62
63 }
64 },
65
66 addImageElement:{
67 value: function(status){
68 var save = status.save,
69 fileName = status.filename,
70 url = status.url,
71 fileType = status.fileType,
72 element, rules, self = this;
73
74 if (save && save.success && save.status === 201) {
75 //
76 if (fileType.indexOf('svg') !== -1) {
77 element = document.application.njUtils.make('embed', null, this.application.ninja.currentDocument);//TODO: Verify this is proper
78 element.type = 'image/svg+xml';
79 element.src = url+'/'+fileName;
80 } else {
81 element = document.application.njUtils.make('image', null, this.application.ninja.currentDocument);
82 element.src = url+'/'+fileName;
83 }
84 //Adding element once it is loaded
85 element.onload = function () {
86 element.onload = null;
87 self.application.ninja.elementMediator.addElements(element, rules, true);
88 };
89 //Setting rules of element
90 rules = {
91 'position': 'absolute',
92 'top' : '100px',
93 'left' : '100px'
94 };
95 //
96 self.application.ninja.elementMediator.addElements(element, rules, false);
97 } else {
98 //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT
99 }
100
101 return element;
102 }
103 },
104
105 //paste from external applicaitons
106 pasteHtml:{//todo: change to pasteNinja, pasteHTML, etc
107 value: function(htmlData, textData){
108 var i=0, j=0,
109 pasteDataObject=null,
110 pastedElements = [],
111 node = null, nodeList = null,
112 styles = null,
113 divWrapper = null,
114 spanWrapper = null,
115 metaEl = null,
116 self = this;
117
118 if(htmlData){
119
120 //TODO: cleanse HTML
121
122 htmlData.replace(/[<script]/g," ");
123
124 this.application.ninja.selectedElements.length = 0;
125 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": true} );
126
127 try{
128 nodeList = ClipboardUtil.deserializeHtmlString(htmlData);//this removes html and body tags
129 }
130 catch(e){
131 console.log(""+e.stack);
132 }
133
134 for(i=0; i < nodeList.length; i++){
135 if(nodeList[i].tagName === "META") {
136 nodeList[i] = null;
137 }
138 else if (nodeList[i].tagName === "CANVAS"){
139 //can't paste external canvas for lack of all metadata
140 nodeList[i] = null;
141 }
142 else if((nodeList[i].nodeType === 3) || (nodeList[i].tagName === "A")){
143 node = nodeList[i].cloneNode(true);
144
145 divWrapper = document.application.njUtils.make("div", null, this.application.ninja.currentDocument);
146 spanWrapper = document.application.njUtils.make("span", null, this.application.ninja.currentDocument);
147 spanWrapper.appendChild(node);
148 divWrapper.appendChild(spanWrapper);
149 styles = {"position":"absolute", "top":"100px", "left":"100px"};
150
151 this.pastePositioned(divWrapper, styles);
152
153 nodeList[i] = null;
154 pastedElements.push(divWrapper);
155
156 }else if(nodeList[i].tagName === "SPAN"){
157 node = nodeList[i].cloneNode(true);
158
159 divWrapper = document.application.njUtils.make("div", null, this.application.ninja.currentDocument);
160 divWrapper.appendChild(node);
161 styles = {"position":"absolute", "top":"100px", "left":"100px"};
162
163 this.pastePositioned(divWrapper, styles);
164
165 nodeList[i] = null;
166 pastedElements.push(divWrapper);
167 }
168 else {
169 node = nodeList[i].cloneNode(true);
170
171 //get class string while copying .... generate styles from class
172 styles = {"position":"absolute", "top":"100px", "left":"100px"};
173
174 this.pastePositioned(node, styles);
175
176 nodeList[i] = null;
177 pastedElements.push(node);
178 }
179
180 }
181
182 nodeList = null;
183
184
185 }else if(textData){
186 node = ClipboardUtil.deserializeHtmlString("<div><span>"+ textData +"</span></div>")[0];
187 styles = {"position":"absolute", "top":"100px", "left":"100px"};
188 this.pastePositioned(node, styles);
189 }
190
191 NJevent("elementAdded", pastedElements);
192 this.application.ninja.currentDocument.model.needsSave = true;
193
194 }
195 },
196
197 pastePositioned:{
198 value: function(element, styles, fromCopy){// for now can wok for both in-place and centered paste
199 var modObject = [], x,y, newX, newY, counter;
200
201 if((typeof fromCopy === "undefined") || (fromCopy && fromCopy === true)){
202 counter = this.pasteCounter;
203 }else{
204 counter = this.pasteCounter - 1;
205 }
206
207 x = styles ? ("" + styles.left + "px") : "100px";