let uiFileDnD = {rects: [], lastOver: 0,
      data: {ctrlKey: false, shiftKey: false, index: 0},
      button: dojo.query('.mwPushButton').find(b => b.textContent==='%s')};
document.ondragenter = (e) => { // prevent default before firing ondragover
  e.dataTransfer.dropEffect = 'none';
  return false;
};
document.ondragover = (e) => {
  e.returnValue = false; // preventDefault & stopPropagation
  let now = new Date().getTime();
  if (now < uiFileDnD.lastOver+16) { return; }
  uiFileDnD.lastOver = now;
  let x = e.clientX+1, y = document.body.clientHeight-e.clientY;
  for (let i = uiFileDnD.rects.length-1; i >= 0; i--) {
    let p = uiFileDnD.rects[i]; // [left bottom width height]
    if (x>=p[0] && y>=p[1] && x<p[0]+p[2] && y<p[1]+p[3]) {
      uiFileDnD.data.index = i; // target index in rects
      return; // keep OS default dropEffect
    };
  };
  e.dataTransfer.dropEffect = 'none'; // disable drop
};
document.ondrop = (e) => {
  e.returnValue = false;
  uiFileDnD.data.ctrlKey = e.ctrlKey;
  uiFileDnD.data.shiftKey = e.shiftKey;
  uiFileDnD.button.click(); // fire Matlab callback
};