summaryrefslogtreecommitdiff
path: root/static/js/src/drag.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/src/drag.js')
-rw-r--r--static/js/src/drag.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/static/js/src/drag.js b/static/js/src/drag.js
new file mode 100644
index 0000000..c155989
--- /dev/null
+++ b/static/js/src/drag.js
@@ -0,0 +1,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);
+});