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
|
window.Drag = {
'imgSrc': "",
'bindImages': function (){
$('.unbound').each(function(index,img){
img.addEventListener('dragstart', Drag.start, false);
$(this).removeClass('unbound');
});
},
'start': function(e){
// console.log(this);
if (this.src) Drag.imgSrc = this.src;
},
'enter': function(e){
Drag.chatbox.classList.add('over');
// console.log('enter')
return false;
},
'over': function(e){
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}
// console.log('over')
return false;
},
'leave': function(e){
Drag.chatbox.classList.remove('leave');
// console.log('leave')
return false;
},
'end': function(e){
Drag.chatbox.classList.remove('end');
// console.log('end')
return false;
},
'drop': function(e){
Drag.chatbox.classList.remove('over');
if (e.stopPropagation) {
e.stopPropagation(); // stops the browser from redirecting.
}
if (e.preventDefault) {
e.preventDefault();
}
// console.log('drop');
Drag.chatbox.value += " " + Drag.imgSrc;
Drag.chatbox.value += " ";
Drag.chatbox.focus();
// console.log(Drag.imgSrc);
Drag.imgSrc = "";
// ok.onclick();
return false;
}
}
$(function(){
Drag.chatbox = document.getElementById("msgInput");
if (! Drag.chatbox || $.browser.mozilla) return;
Drag.chatbox.addEventListener('dragenter', Drag.enter, false);
Drag.chatbox.addEventListener('dragover', Drag.over, false);
Drag.chatbox.addEventListener('dragleave', Drag.leave, false);
Drag.chatbox.addEventListener('dragend', Drag.end, false);
Drag.chatbox.addEventListener('drop', Drag.drop, false);
});
|