| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('ntp4', function() { | 5 cr.define('ntp4', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 // We can't pass the currently dragging tile via dataTransfer because of | 8 // We can't pass the currently dragging tile via dataTransfer because of |
| 9 // http://crbug.com/31037 | 9 // http://crbug.com/31037 |
| 10 var currentlyDraggingTile = null; | 10 var currentlyDraggingTile = null; |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 // Only change data if this was not a 'null drag'. | 894 // Only change data if this was not a 'null drag'. |
| 895 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { | 895 if (!((index == this.dragItemIndex_) && this.withinPageDrag_)) { |
| 896 var adjustedIndex = this.currentDropIndex_ + | 896 var adjustedIndex = this.currentDropIndex_ + |
| 897 (index > this.dragItemIndex_ ? 1 : 0); | 897 (index > this.dragItemIndex_ ? 1 : 0); |
| 898 if (this.withinPageDrag_) { | 898 if (this.withinPageDrag_) { |
| 899 this.tileGrid_.insertBefore( | 899 this.tileGrid_.insertBefore( |
| 900 currentlyDraggingTile, | 900 currentlyDraggingTile, |
| 901 this.tileElements_[adjustedIndex]); | 901 this.tileElements_[adjustedIndex]); |
| 902 this.tileMoved(currentlyDraggingTile); | 902 this.tileMoved(currentlyDraggingTile); |
| 903 } else { | 903 } else { |
| 904 var originalPage = currentlyDraggingTile.tilePage; |
| 904 this.addDragData(e.dataTransfer, adjustedIndex); | 905 this.addDragData(e.dataTransfer, adjustedIndex); |
| 905 currentlyDraggingTile.tilePage.cleanupDrag(); | 906 originalPage.cleanupDrag(); |
| 906 } | 907 } |
| 907 | 908 |
| 908 // Dropping the icon may cause topMargin to change, but changing it | 909 // Dropping the icon may cause topMargin to change, but changing it |
| 909 // now would cause everything to move (annoying), so we leave it | 910 // now would cause everything to move (annoying), so we leave it |
| 910 // alone. The top margin will be re-calculated next time the window is | 911 // alone. The top margin will be re-calculated next time the window is |
| 911 // resized or the page is selected. | 912 // resized or the page is selected. |
| 912 } | 913 } |
| 913 | 914 |
| 914 this.classList.remove('animating-tile-page'); | 915 this.classList.remove('animating-tile-page'); |
| 915 this.cleanupDrag(); | 916 this.cleanupDrag(); |
| 916 }, | 917 }, |
| 917 | 918 |
| 918 /** | 919 /** |
| 919 * Appends the currently dragged tile to the end of the page. Called | 920 * Appends the currently dragged tile to the end of the page. Called |
| 920 * from outside the page, e.g. when dropping on a nav dot. | 921 * from outside the page, e.g. when dropping on a nav dot. |
| 921 */ | 922 */ |
| 922 appendDraggingTile: function() { | 923 appendDraggingTile: function() { |
| 923 var originalPage = currentlyDraggingTile.tilePage; | 924 var originalPage = currentlyDraggingTile.tilePage; |
| 924 if (originalPage == this) | 925 if (originalPage == this) |
| 925 return; | 926 return; |
| 926 | 927 |
| 927 this.addDragData(null, this.tileElements_.length - 1); | 928 this.addDragData(null, this.tileElements_.length); |
| 928 originalPage.cleanupDrag(); | 929 originalPage.cleanupDrag(); |
| 929 }, | 930 }, |
| 930 | 931 |
| 931 /** | 932 /** |
| 932 * Makes sure all the tiles are in the right place after a drag is over. | 933 * Makes sure all the tiles are in the right place after a drag is over. |
| 933 * @private | 934 * @private |
| 934 */ | 935 */ |
| 935 cleanupDrag: function() { | 936 cleanupDrag: function() { |
| 936 for (var i = 0; i < this.tileElements_.length; i++) { | 937 for (var i = 0; i < this.tileElements_.length; i++) { |
| 937 // The current drag tile will be positioned in its dragend handler. | 938 // The current drag tile will be positioned in its dragend handler. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 */ | 998 */ |
| 998 tileMoved: function(draggedTile) { | 999 tileMoved: function(draggedTile) { |
| 999 }, | 1000 }, |
| 1000 }; | 1001 }; |
| 1001 | 1002 |
| 1002 return { | 1003 return { |
| 1003 getCurrentlyDraggingTile: getCurrentlyDraggingTile, | 1004 getCurrentlyDraggingTile: getCurrentlyDraggingTile, |
| 1004 TilePage: TilePage, | 1005 TilePage: TilePage, |
| 1005 }; | 1006 }; |
| 1006 }); | 1007 }); |
| OLD | NEW |