aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/clipboard-controller.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-21 16:26:52 -0700
committerValerio Virgillito2012-06-21 16:26:52 -0700
commit2af33f19de48bb8fe269c51ceddd1bc1f591651f (patch)
tree564528119093e4e3408ccf180d55ac3d5e413813 /js/controllers/clipboard-controller.js
parentc411f76d89c543837548085ff468fee0fb4f2ff9 (diff)
parent47be0919aa271e97fd7ca86e65cdf93aeee2bf81 (diff)
downloadninja-2af33f19de48bb8fe269c51ceddd1bc1f591651f.tar.gz
Merge pull request #320 from ananyasen/cut-copy-paste
copy cut paste - project phase 1 check in
Diffstat (limited to 'js/controllers/clipboard-controller.js')
-rw-r--r--js/controllers/clipboard-controller.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js
new file mode 100644
index 00000000..259d916e
--- /dev/null
+++ b/js/controllers/clipboard-controller.js
@@ -0,0 +1,120 @@
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//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 ElementsClipboardAgent = require("js/clipboard/internal-ops/elements-clipboard-agent").ElementsClipboardAgent,
12 ExternalAppsClipboardAgent= require("js/clipboard/external-apps-clipboard-agent").ExternalAppsClipboardAgent;
13
14var ClipboardController = exports.ClipboardController = Montage.create(Component, {
15
16 deserializedFromTemplate: {
17 value: function() {
18 document.body.addEventListener("copy", this, false);
19 document.body.addEventListener("cut", this, false);
20 document.body.addEventListener("paste", this, false);
21
22 //ninja menu events
23 this.eventManager.addEventListener("executeCut", this, false);
24 this.eventManager.addEventListener("executeCopy", this, false);
25 this.eventManager.addEventListener("executePaste", this, false);
26
27 }
28 },
29
30 clipboardContext:{
31 value : "stage" /* cleanup: formulate better context representation */
32 },
33
34 operationsAgent:{//appropriate agent instant required for execution of cut/copy/paste
35 value: null
36 },
37
38 handleExecuteCopy:{
39 value: function(){document.execCommand('copy',false,null);}
40 },
41
42 handleExecuteCut:{
43 value: function(){document.execCommand('cut',false,null);}
44 },
45
46 handleExecutePaste:{
47 value: function(){document.execCommand('paste',false,null);}
48 },
49
50 handleCopy:{
51 value:function(clipboardEvent){
52 if(!this.application.ninja.currentDocument
53 || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){
54
55 return;
56 }//for design view only
57
58 // Don't do anything if an input or other control is focused
59 if(document.activeElement.nodeName !== "BODY") {
60 return;
61 }
62
63 if(this.clipboardContext === "stage"){
64 ElementsClipboardAgent.copy(clipboardEvent);
65 }
66
67 clipboardEvent.preventDefault();
68 }
69 },
70
71 handleCut:{
72 value:function(clipboardEvent){
73 if(this.application.ninja.currentDocument.currentView === "code") return;
74
75 // Don't do anything if an input or other control is focused
76 if(document.activeElement.nodeName !== "BODY") {
77 return;
78 }
79
80 if(this.clipboardContext === "stage"){
81 ElementsClipboardAgent.cut(clipboardEvent);
82 }
83
84 clipboardEvent.preventDefault();
85 }
86 },
87
88 handlePaste:{
89 value:function(clipboardEvent){
90 var clipboardData = clipboardEvent.clipboardData,
91 ninjaData = clipboardData.getData("ninja");
92
93 if(!this.application.ninja.currentDocument
94 || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){
95
96 return;
97 }//for design view only
98
99 // Don't do anything if an input or other control is focused
100 if(document.activeElement.nodeName !== "BODY") {
101 return;
102 }
103
104 //TODO: return if stage is not focussed
105
106 if(this.clipboardContext === "stage"){
107 if(ninjaData){
108 ElementsClipboardAgent.pasteInternal();
109 }
110 else{
111 ExternalAppsClipboardAgent.paste(clipboardEvent);
112 }
113 }
114
115 clipboardEvent.preventDefault();
116 }
117 }
118
119
120}); \ No newline at end of file