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 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 /** | 396 /** |
397 * Creates an app DOM element and places it at the last position on the | 397 * Creates an app DOM element and places it at the last position on the |
398 * page. | 398 * page. |
399 * @param {Object} appData The data object that describes the app. | 399 * @param {Object} appData The data object that describes the app. |
400 * @param {?boolean} animate If true, the app tile plays an animation. | 400 * @param {?boolean} animate If true, the app tile plays an animation. |
401 */ | 401 */ |
402 appendApp: function(appData, animate) { | 402 appendApp: function(appData, animate) { |
403 this.appendTile(new App(appData), animate); | 403 this.appendTile(new App(appData), animate); |
404 }, | 404 }, |
405 | 405 |
| 406 /** @inheritdoc */ |
| 407 doDragOver: function(e) { |
| 408 var tile = ntp4.getCurrentlyDraggingTile(); |
| 409 if (!tile.querySelector('.app')) { |
| 410 e.preventDefault(); |
| 411 e.dataTransfer.dropEffect = 'copy'; |
| 412 } else { |
| 413 TilePage.prototype.doDragOver.call(this, e); |
| 414 } |
| 415 }, |
| 416 |
406 /** @inheritDoc */ | 417 /** @inheritDoc */ |
407 shouldAcceptDrag: function(e) { | 418 shouldAcceptDrag: function(e) { |
408 return ntp4.getCurrentlyDraggingTile() || | 419 return ntp4.getCurrentlyDraggingTile() || |
409 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); | 420 (e.dataTransfer && e.dataTransfer.types.indexOf('url') != -1); |
410 }, | 421 }, |
411 | 422 |
412 /** @inheritDoc */ | 423 /** @inheritDoc */ |
413 addDragData: function(dataTransfer, index) { | 424 addDragData: function(dataTransfer, index) { |
414 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); | 425 var currentlyDraggingTile = ntp4.getCurrentlyDraggingTile(); |
415 if (currentlyDraggingTile) { | 426 if (currentlyDraggingTile) { |
416 var tileContents = currentlyDraggingTile.firstChild; | 427 var tileContents = currentlyDraggingTile.firstChild; |
417 if (tileContents.classList.contains('app')) { | 428 if (tileContents.classList.contains('app')) { |
418 this.tileGrid_.insertBefore( | 429 this.tileGrid_.insertBefore( |
419 currentlyDraggingTile, | 430 currentlyDraggingTile, |
420 this.tileElements_[index]); | 431 this.tileElements_[index]); |
421 this.tileMoved(currentlyDraggingTile); | 432 this.tileMoved(currentlyDraggingTile); |
422 } else if (tileContents.classList.contains('most-visited')) { | 433 } else if (currentlyDraggingTile.querySelector('.most-visited')) { |
423 this.generateAppForLink(tileContents.data); | 434 this.generateAppForLink(tileContents.data); |
424 } | 435 } |
425 } else { | 436 } else { |
426 this.addOutsideData_(dataTransfer, index); | 437 this.addOutsideData_(dataTransfer, index); |
427 } | 438 } |
428 }, | 439 }, |
429 | 440 |
430 /** | 441 /** |
431 * Adds drag data that has been dropped from a source that is not a tile. | 442 * Adds drag data that has been dropped from a source that is not a tile. |
432 * @param {Object} dataTransfer The data transfer object that holds drop | 443 * @param {Object} dataTransfer The data transfer object that holds drop |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 477 |
467 /** | 478 /** |
468 * Creates a new crx-less app manifest and installs it. | 479 * Creates a new crx-less app manifest and installs it. |
469 * @param {Object} data The data object describing the link. Must have |url| | 480 * @param {Object} data The data object describing the link. Must have |url| |
470 * and |title| members. | 481 * and |title| members. |
471 * TODO(estade): pass along an index. | 482 * TODO(estade): pass along an index. |
472 */ | 483 */ |
473 generateAppForLink: function(data) { | 484 generateAppForLink: function(data) { |
474 assert(data.url != undefined); | 485 assert(data.url != undefined); |
475 assert(data.title != undefined); | 486 assert(data.title != undefined); |
476 chrome.send('generateAppForLink', [data.url, data.title]); | 487 var pageIndex = ntp4.getAppsPageIndex(this); |
| 488 chrome.send('generateAppForLink', [data.url, data.title, pageIndex]); |
477 }, | 489 }, |
478 | 490 |
479 /** @inheritDoc */ | 491 /** @inheritDoc */ |
480 tileMoved: function(draggedTile) { | 492 tileMoved: function(draggedTile) { |
481 if (!(draggedTile.firstChild instanceof App)) | 493 if (!(draggedTile.firstChild instanceof App)) |
482 return; | 494 return; |
483 | 495 |
484 var pageIndex = ntp4.getAppsPageIndex(this); | 496 var pageIndex = ntp4.getAppsPageIndex(this); |
485 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]); | 497 chrome.send('setPageIndex', [draggedTile.firstChild.appId, pageIndex]); |
486 | 498 |
(...skipping 12 matching lines...) Expand all Loading... |
499 var store = document.querySelector('.webstore'); | 511 var store = document.querySelector('.webstore'); |
500 if (store) | 512 if (store) |
501 store.setAppsPromoData(data); | 513 store.setAppsPromoData(data); |
502 }; | 514 }; |
503 | 515 |
504 return { | 516 return { |
505 APP_LAUNCH: APP_LAUNCH, | 517 APP_LAUNCH: APP_LAUNCH, |
506 AppsPage: AppsPage, | 518 AppsPage: AppsPage, |
507 }; | 519 }; |
508 }); | 520 }); |
OLD | NEW |