Skip to content

Commit

Permalink
Merge pull request #7 from davmillar/drag-drop-fix
Browse files Browse the repository at this point in the history
Fixed drag and drop faulty behavior
  • Loading branch information
ao5357 authored Oct 31, 2017
2 parents 730457d + db15f5c commit 98e9553
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions options/deps/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ document.addEventListener('DOMContentLoaded',function() {
});
}

var findParentFieldset = function (domElement) {
while (domElement.tagName.toUpperCase() !== 'FIELDSET' && domElement.tagName.toUpperCase() !== 'BODY') {
domElement = domElement.parentNode;
}
if (domElement.tagName.toUpperCase() === 'FIELDSET') {
return domElement;
}
return null;
};

/**
* The form should never submit.
*/
Expand Down Expand Up @@ -132,22 +142,34 @@ document.addEventListener('DOMContentLoaded',function() {
}, false);

options.rowForm.addEventListener('dragenter', function(evt) {
evt.srcElement.classList.add('over');
var targetElement = findParentFieldset(evt.srcElement);

if (targetElement) {
targetElement.classList.add('over');
}
}, false);

options.rowForm.addEventListener('dragleave', function(evt) {
evt.srcElement.classList.remove('over');
var targetElement = findParentFieldset(evt.srcElement);

if (targetElement) {
targetElement.classList.remove('over');
}
}, false);

options.rowForm.addEventListener('dragover', function(evt) {
evt.preventDefault();
}, false);

options.rowForm.addEventListener('drop', function(evt) {
evt.srcElement.classList.remove('over');
srcElem.innerHTML = evt.srcElement.innerHTML;
evt.srcElement.innerHTML = evt.dataTransfer.getData('text/html');
saveValues();
var targetElement = findParentFieldset(evt.srcElement);

if (targetElement) {
targetElement.classList.remove('over');
srcElem.innerHTML = targetElement.innerHTML;
targetElement.innerHTML = evt.dataTransfer.getData('text/html');
saveValues();
}
}, false);

/**
Expand Down

0 comments on commit 98e9553

Please sign in to comment.