-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (68 loc) · 1.34 KB
/
index.js
File metadata and controls
86 lines (68 loc) · 1.34 KB
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
/**
* Module dependencies.
*/
var normalize = require('normalized-upload');
var Emitter = require('emitter');
var file = require('file');
/**
* Expose `Clipboard`.
*/
module.exports = Clipboard;
/**
* Initialize a `Clipboard`.
*
* @api private
*/
function Clipboard(el) {
Emitter.call(this);
this.el = el;
this.onpaste = this.onpaste.bind(this);
this.oncopy = this.oncopy.bind(this);
this.oncut = this.oncut.bind(this);
this.bind();
}
/**
* Mixin emitter.
*/
Emitter(Clipboard.prototype);
/**
* Bind event handlers.
*
* @api public
*/
Clipboard.prototype.bind = function(){
this.el.addEventListener('paste', this.onpaste, false);
this.el.addEventListener('copy', this.oncopy, false);
this.el.addEventListener('cut', this.oncut, false);
};
/**
* Unbind event handlers.
*
* @api public
*/
Clipboard.prototype.unbind = function(arg){
this.el.removeEventListener('paste', this.onpaste);
this.el.removeEventListener('copy', this.oncopy);
this.el.removeEventListener('cut', this.oncut);
};
/**
* Handle copy.
*/
Clipboard.prototype.oncopy = function(e){
this.emit('copy', e);
};
/**
* Handle cut.
*/
Clipboard.prototype.oncut = function(e){
this.emit('cut', e);
};
/**
* Handle paste.
*/
Clipboard.prototype.onpaste = function(e){
var self = this;
normalize(e, function(){
self.emit('paste', e);
});
};