OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @fileoverview PageListView implementation. | 6 * @fileoverview PageListView implementation. |
7 * PageListView manages page list, dot list, switcher buttons and handles apps | 7 * PageListView manages page list, dot list, switcher buttons and handles apps |
8 * pages callbacks from backend. | 8 * pages callbacks from backend. |
9 * | 9 * |
10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. | 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 this.cardSlider.selectCardByValue(this.mostVisitedPage); | 492 this.cardSlider.selectCardByValue(this.mostVisitedPage); |
493 break; | 493 break; |
494 case loadTimeData.getInteger('suggestions_page_id'): | 494 case loadTimeData.getInteger('suggestions_page_id'): |
495 if (this.suggestionsPage) | 495 if (this.suggestionsPage) |
496 this.cardSlider.selectCardByValue(this.suggestionsPage); | 496 this.cardSlider.selectCardByValue(this.suggestionsPage); |
497 break; | 497 break; |
498 } | 498 } |
499 }, | 499 }, |
500 | 500 |
501 /** | 501 /** |
502 * Called whenever tiles should be re-arranging themselves out of the way | |
503 * of a moving or insert tile. | |
504 */ | |
505 enterRearrangeMode: function() { | |
506 if (loadTimeData.getBoolean('showApps')) { | |
507 var tempPage = new ntp.AppsPage(); | |
508 tempPage.classList.add('temporary'); | |
509 var pageName = loadTimeData.getString('appDefaultPageName'); | |
510 this.appendTilePage(tempPage, pageName, true); | |
511 } | |
512 | |
513 if (ntp.getCurrentlyDraggingTile().firstChild.canBeRemoved()) | |
514 $('footer').classList.add('showing-trash-mode'); | |
515 | |
516 document.documentElement.classList.add('dragging-mode'); | |
517 }, | |
518 | |
519 /** | |
520 * Invoked whenever some app is released | |
521 */ | |
522 leaveRearrangeMode: function() { | |
523 var tempPage = document.querySelector('.tile-page.temporary'); | |
524 if (tempPage) { | |
525 var dot = tempPage.navigationDot; | |
526 if (!tempPage.tileCount && | |
527 tempPage != this.cardSlider.currentCardValue) { | |
528 this.removeTilePageAndDot_(tempPage, true); | |
529 } else { | |
530 tempPage.classList.remove('temporary'); | |
531 this.saveAppPageName(tempPage, | |
532 loadTimeData.getString('appDefaultPageName')); | |
533 } | |
534 } | |
535 | |
536 $('footer').classList.remove('showing-trash-mode'); | |
537 document.documentElement.classList.remove('dragging-mode'); | |
538 }, | |
539 | |
540 /** | |
541 * Callback for the 'pagelayout' event. | 502 * Callback for the 'pagelayout' event. |
542 * @param {Event} e The event. | 503 * @param {Event} e The event. |
543 */ | 504 */ |
544 onPageLayout_: function(e) { | 505 onPageLayout_: function(e) { |
545 if (Array.prototype.indexOf.call(this.tilePages, e.currentTarget) != | 506 if (Array.prototype.indexOf.call(this.tilePages, e.currentTarget) != |
546 this.cardSlider.currentCard) { | 507 this.cardSlider.currentCard) { |
547 return; | 508 return; |
548 } | 509 } |
549 | 510 |
550 this.updatePageSwitchers(); | 511 this.updatePageSwitchers(); |
551 }, | 512 }, |
552 | 513 |
553 /** | 514 /** |
554 * Adjusts the size and position of the page switchers according to the | 515 * Adjusts the size and position of the page switchers according to the |
555 * layout of the current card. | 516 * layout of the current card. TODO(pedrosimonetti): Delete. |
556 */ | 517 */ |
557 updatePageSwitchers: function() { | 518 updatePageSwitchers: function() { |
558 if (!this.pageSwitcherStart || !this.pageSwitcherEnd) | |
559 return; | |
560 | |
561 var page = this.cardSlider.currentCardValue; | |
562 | |
563 this.pageSwitcherStart.hidden = !page || | |
564 (this.cardSlider.currentCard == 0); | |
565 this.pageSwitcherEnd.hidden = !page || | |
566 (this.cardSlider.currentCard == this.cardSlider.cardCount - 1); | |
567 | |
568 if (!page) | |
569 return; | |
570 | |
571 var pageSwitcherLeft = isRTL() ? this.pageSwitcherEnd : | |
572 this.pageSwitcherStart; | |
573 var pageSwitcherRight = isRTL() ? this.pageSwitcherStart : | |
574 this.pageSwitcherEnd; | |
575 var scrollbarWidth = page.scrollbarWidth; | |
576 pageSwitcherLeft.style.width = | |
577 (page.sideMargin + 13) + 'px'; | |
578 pageSwitcherLeft.style.left = '0'; | |
579 pageSwitcherRight.style.width = | |
580 (page.sideMargin - scrollbarWidth + 13) + 'px'; | |
581 pageSwitcherRight.style.right = scrollbarWidth + 'px'; | |
582 | |
583 var offsetTop = page.querySelector('.tile-page-content').offsetTop + 'px'; | |
584 pageSwitcherLeft.style.top = offsetTop; | |
585 pageSwitcherRight.style.top = offsetTop; | |
586 pageSwitcherLeft.style.paddingBottom = offsetTop; | |
587 pageSwitcherRight.style.paddingBottom = offsetTop; | |
588 }, | 519 }, |
589 | 520 |
590 /** | 521 /** |
591 * Returns the index of the given apps page. | 522 * Returns the index of the given apps page. |
592 * @param {AppsPage} page The AppsPage we wish to find. | 523 * @param {AppsPage} page The AppsPage we wish to find. |
593 * @return {number} The index of |page| or -1 if it is not in the | 524 * @return {number} The index of |page| or -1 if it is not in the |
594 * collection. | 525 * collection. |
595 */ | 526 */ |
596 getAppsPageIndex: function(page) { | 527 getAppsPageIndex: function(page) { |
597 return Array.prototype.indexOf.call(this.appsPages, page); | 528 return Array.prototype.indexOf.call(this.appsPages, page); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 | 682 |
752 /** | 683 /** |
753 * Removes a page and navigation dot (if the navdot exists). | 684 * Removes a page and navigation dot (if the navdot exists). |
754 * @param {TilePage} page The page to be removed. | 685 * @param {TilePage} page The page to be removed. |
755 * @param {boolean=} opt_animate If the removal should be animated. | 686 * @param {boolean=} opt_animate If the removal should be animated. |
756 */ | 687 */ |
757 removeTilePageAndDot_: function(page, opt_animate) { | 688 removeTilePageAndDot_: function(page, opt_animate) { |
758 if (page.navigationDot) | 689 if (page.navigationDot) |
759 page.navigationDot.remove(opt_animate); | 690 page.navigationDot.remove(opt_animate); |
760 this.cardSlider.removeCard(page); | 691 this.cardSlider.removeCard(page); |
761 }, | 692 } |
762 }; | 693 }; |
763 | 694 |
764 return { | 695 return { |
765 PageListView: PageListView | 696 PageListView: PageListView |
766 }; | 697 }; |
767 }); | 698 }); |
OLD | NEW |