This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 922
/
clipboard.js
92 lines (72 loc) · 2.34 KB
/
clipboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*global nativeRequire*/
define(function(require, exports, module) {
main.consumes = ["Plugin"];
main.provides = ["clipboard.provider"];
return main;
function main(options, imports, register) {
var Plugin = imports.Plugin;
/***** Initialization *****/
var plugin = new Plugin("Ajax.org", main.consumes);
var emit = plugin.getEmitter();
var clipboard;
function getClipboard() {
if (clipboard) return clipboard;
// Get System Clipbaord
return clipboard = nativeRequire('nw.gui').Clipboard.get();
}
/***** Methods *****/
function clear() {
getClipboard().clear();
}
function set(type, data) {
if (supported(type))
getClipboard().set(data, "text");
}
function get(type) {
if (supported(type))
return getClipboard().get("text");
}
function supported(type) {
return /text($|\/)/.test(type);
}
/***** Lifecycle *****/
plugin.on("load", function() {
});
plugin.on("enable", function() {
});
plugin.on("disable", function() {
});
plugin.on("unload", function() {
clipboard = false;
});
/***** Register and define API *****/
/**
* Clipboard Provider Using the node-webkit interface
**/
plugin.freezePublicAPI({
wrap: function() {},
unwrap: function() {},
/**
* Clears the clipboard
* @param {Function} callback(err)
*/
clear: clear,
/**
* Sets the clipboard
* @param {String} type
* @param {String} data
* @param {Function} callback(err)
*/
set: set,
/**
* Gets the current value of the clipboard
* @param {String} type
* * @param {Function} callback(err, data)
*/
get: get
});
register(null, {
"clipboard.provider": plugin
});
}
});