Now we have your classclasses being added on click; let's update the onfocus bithandler in the same fashion:
/* lets remove the previous classes when on focus */
function removeClassesOnFocus(evt) {
// evt.target is the element that triggered the event. We bound to #message.
removeClass(evt.target, 'dropzone-wrap');
removeClass(evt.target.parent()parentNode, 'dropzone-content');
}
// this bit really should wait for `window.load` too.
document.getElementById('message').addEventListener('focus', removeClassesOnFocus);
If the classes are there nothing should happen
To address that, the removeClassesOnFocus
function could be reworked to look up the element if it isn't provided.
function txtDropClicked(evt) {
removeClassesOnFocus(false);
addClass(document.getElementById('message'), 'dropzone-wrap');
addClass(document.getElementById('dragNdrop'), 'dropzone-content');
}
function removeClassesOnFocus(evt) {
// evt.target is the element that triggered the event. We bound to #message.
var message = (evt === false) ? document.getElementById('message') : evt.target;
removeClass(message, 'dropzone-wrap');
removeClass(message.parentNode, 'dropzone-content');
}
// http://youmightnotneedjquery.com/#add_class
function addClass(el, className) {
if (el.classList) { el.classList.add(className); }
else { el.className += ' ' + className; }
}
// http://youmightnotneedjquery.com/#remove_class
function removeClass(el, className) {
if (el.classList) { el.classList.remove(className); }
else { el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); }
}
// When the txtDrop toggle is clicked, add these classes to the message and drag/drop thing.
function txtDropClicked(evt) {
removeClassesOnFocus(false);
addClass(document.getElementById('message'), 'dropzone-wrap');
addClass(document.getElementById('dragNdrop'), 'dropzone-content');
}
// Removes the classes after the message receives focus.
function removeClassesOnFocus(evt) {
// evt.target is the element that triggered the event. We bound to #message.
removeClassvar message = (evt === false) ? document.targetgetElementById('message') : evt.target;
removeClass(message, 'dropzone-wrap');
removeClass(evt.targetmessage.parent()parentNode, 'dropzone-content');
}
// Attach the click handler to txtDrop toggle when the page loads.
window.addEventListener('load', function() {
document.getElementById("ToggleTxTDrop").addEventListener( 'click' , txtDropClicked );
document.getElementById('message').addEventListener('focus', removeClassesOnFocus);
});