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); });