Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 // Helpers | 2 // Helpers |
| 3 | 3 |
| 4 function $(id) { | 4 function $(id) { |
| 5 return document.getElementById(id); | 5 return document.getElementById(id); |
| 6 } | 6 } |
| 7 | 7 |
| 8 // TODO(arv): Remove these when classList is available in HTML5. | 8 // TODO(arv): Remove these when classList is available in HTML5. |
| 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 | 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 |
| 10 function hasClass(el, name) { | 10 function hasClass(el, name) { |
| (...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 this.dragEndTimer = window.setTimeout(function() { | 1470 this.dragEndTimer = window.setTimeout(function() { |
| 1471 // These things needto happen after the drop event. | 1471 // These things needto happen after the drop event. |
| 1472 mostVisited.invalidate(); | 1472 mostVisited.invalidate(); |
| 1473 mostVisited.layout(); | 1473 mostVisited.layout(); |
| 1474 self.dragItem = null; | 1474 self.dragItem = null; |
| 1475 }, 10); | 1475 }, 10); |
| 1476 } | 1476 } |
| 1477 }, | 1477 }, |
| 1478 | 1478 |
| 1479 handleDrag: function(e) { | 1479 handleDrag: function(e) { |
| 1480 // Moves the drag item making sure that it is not displayed outside the | |
| 1481 // browser viewport. | |
| 1480 var item = mostVisited.getItem(e.target); | 1482 var item = mostVisited.getItem(e.target); |
| 1481 var rect = document.querySelector('#most-visited').getBoundingClientRect(); | 1483 var rect = document.querySelector('#most-visited').getBoundingClientRect(); |
| 1482 item.style.pointerEvents = 'none'; | 1484 item.style.pointerEvents = 'none'; |
| 1483 | 1485 |
| 1484 item.style.left = this.startX + e.screenX - this.startScreenX + 'px'; | 1486 var x = this.startX + e.screenX - this.startScreenX; |
| 1485 item.style.top = this.startY + e.screenY - this.startScreenY + 'px'; | 1487 var y = this.startY + e.screenY - this.startScreenY; |
| 1488 | |
| 1489 // The position of the item is relative to #most-visited so we need to | |
| 1490 // subtract that when calculation the allowed position. | |
|
Miranda Callahan
2009/08/19 22:49:02
s/calculation/calculating
| |
| 1491 x = Math.max(x, -rect.left); | |
| 1492 x = Math.min(x, document.body.clientWidth - rect.left - item.offsetWidth - | |
| 1493 2); | |
| 1494 // The shadow is 2px | |
| 1495 y = Math.max(-rect.top, y); | |
| 1496 y = Math.min(y, document.body.clientHeight - rect.top - item.offsetHeight - | |
| 1497 2); | |
| 1498 | |
| 1499 item.style.left = x + 'px'; | |
| 1500 item.style.top = y + 'px'; | |
| 1486 }, | 1501 }, |
| 1487 | 1502 |
| 1488 // We listen to mousedown to get the relative position of the cursor for dnd. | 1503 // We listen to mousedown to get the relative position of the cursor for dnd. |
| 1489 handleMouseDown: function(e) { | 1504 handleMouseDown: function(e) { |
| 1490 var item = mostVisited.getItem(e.target); | 1505 var item = mostVisited.getItem(e.target); |
| 1491 if (item) { | 1506 if (item) { |
| 1492 this.startX = item.offsetLeft; | 1507 this.startX = item.offsetLeft; |
| 1493 this.startY = item.offsetTop; | 1508 this.startY = item.offsetTop; |
| 1494 this.startScreenX = e.screenX; | 1509 this.startScreenX = e.screenX; |
| 1495 this.startScreenY = e.screenY; | 1510 this.startScreenY = e.screenY; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1508 el.addEventListener('dragover', bind(this.handleDragOver, this)); | 1523 el.addEventListener('dragover', bind(this.handleDragOver, this)); |
| 1509 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); | 1524 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); |
| 1510 el.addEventListener('drop', bind(this.handleDrop, this)); | 1525 el.addEventListener('drop', bind(this.handleDrop, this)); |
| 1511 el.addEventListener('dragend', bind(this.handleDragEnd, this)); | 1526 el.addEventListener('dragend', bind(this.handleDragEnd, this)); |
| 1512 el.addEventListener('drag', bind(this.handleDrag, this)); | 1527 el.addEventListener('drag', bind(this.handleDrag, this)); |
| 1513 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); | 1528 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); |
| 1514 } | 1529 } |
| 1515 }; | 1530 }; |
| 1516 | 1531 |
| 1517 dnd.init(); | 1532 dnd.init(); |
| OLD | NEW |