diff options
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/clipboard-controller.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js new file mode 100644 index 00000000..d26aaa80 --- /dev/null +++ b/js/controllers/clipboard-controller.js | |||
@@ -0,0 +1,103 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component; | ||
11 | |||
12 | var ClipboardController = exports.ClipboardController = Montage.create(Component, { | ||
13 | hasTemplate: { | ||
14 | value: false | ||
15 | }, | ||
16 | |||
17 | deserializedFromTemplate: { | ||
18 | value: function() { | ||
19 | document.body.addEventListener("copy", this, false); | ||
20 | document.body.addEventListener("cut", this, false); | ||
21 | document.body.addEventListener("paste", this, false); | ||
22 | |||
23 | //ninja menu events | ||
24 | this.eventManager.addEventListener("executeCut", this, false); | ||
25 | this.eventManager.addEventListener("executeCopy", this, false); | ||
26 | this.eventManager.addEventListener("executePaste", this, false); | ||
27 | } | ||
28 | }, | ||
29 | |||
30 | _copyFlag:{ | ||
31 | value:false | ||
32 | }, | ||
33 | |||
34 | copyFlag:{ | ||
35 | get:function(){return this._copyFlag;}, | ||
36 | set:function(value){this._copyFlag = value;} | ||
37 | }, | ||
38 | |||
39 | _newCopyFlag:{ | ||
40 | value:true | ||
41 | }, | ||
42 | |||
43 | newCopyFlag:{ | ||
44 | get:function(){return this._newCopyFlag;}, | ||
45 | set:function(value){this._newCopyFlag = value;} | ||
46 | }, | ||
47 | |||
48 | handleExecuteCopy:{ | ||
49 | value: function(){document.execCommand('copy',false,null);} | ||
50 | }, | ||
51 | |||
52 | handleExecuteCut:{ | ||
53 | value: function(){document.execCommand('cut',false,null);} | ||
54 | }, | ||
55 | |||
56 | handleExecutePaste:{ | ||
57 | value: function(){document.execCommand('paste',false,null);} | ||
58 | }, | ||
59 | |||
60 | handleCopy:{ | ||
61 | value:function(clipboardEvent){ | ||
62 | //depends on the clipboard event | ||
63 | if(this.application.ninja.selectedElements.length > 0){ | ||
64 | clipboardEvent.clipboardData.setData('text/html', ''+this.application.ninja.selectedElements[0].outerHTML);//copying first selected element for POC | ||
65 | |||
66 | clipboardEvent.preventDefault(); | ||
67 | } | ||
68 | } | ||
69 | }, | ||
70 | |||
71 | handleCut:{ | ||
72 | value:function(clipboardEvent){ | ||
73 | var clipboardData = clipboardEvent.clipboardData, | ||
74 | htmlData = clipboardData.getData("text/html"), | ||
75 | textData = clipboardData.getData("text/plain"); | ||
76 | |||
77 | console.log("$$$ handleCut ", textData); | ||
78 | |||
79 | |||
80 | clipboardEvent.preventDefault(); | ||
81 | } | ||
82 | }, | ||
83 | |||
84 | handlePaste:{ | ||
85 | value:function(clipboardEvent){ | ||
86 | var clipboardData = clipboardEvent.clipboardData, | ||
87 | htmlData = clipboardData.getData("text/html"), | ||
88 | textData = clipboardData.getData("text/plain"), | ||
89 | data = null; | ||
90 | |||
91 | data = htmlData || textData; | ||
92 | |||
93 | if(data){ | ||
94 | //hack - to avoid parsing html code now | ||
95 | |||
96 | this.application.ninja.documentController.activeDocument.documentRoot.innerHTML = data + this.application.ninja.documentController.activeDocument.documentRoot.innerHTML; | ||
97 | |||
98 | } | ||
99 | |||
100 | clipboardEvent.preventDefault(); | ||
101 | } | ||
102 | } | ||
103 | }); \ No newline at end of file | ||