app.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
  3. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  4. The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  5. The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  6. Code distributed by Google as part of the polymer project is also
  7. subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  8. */
  9. (function(document) {
  10. 'use strict';
  11. // Grab a reference to our auto-binding template
  12. // and give it some initial binding values
  13. // Learn more about auto-binding templates at http://goo.gl/Dx1u2g
  14. var app = document.querySelector('#app');
  15. // Sets app default base URL
  16. app.baseUrl = '/';
  17. if (window.location.port === '') { // if production
  18. // Uncomment app.baseURL below and
  19. // set app.baseURL to '/your-pathname/' if running from folder in production
  20. // app.baseUrl = '/polymer-starter-kit/';
  21. }
  22. app.displayInstalledToast = function() {
  23. // Check to make sure caching is actually enabled—it won't be in the dev environment.
  24. if (!Polymer.dom(document).querySelector('platinum-sw-cache').disabled) {
  25. Polymer.dom(document).querySelector('#caching-complete').show();
  26. }
  27. };
  28. // Listen for template bound event to know when bindings
  29. // have resolved and content has been stamped to the page
  30. app.addEventListener('dom-change', function() {
  31. console.log('Our app is ready to rock!');
  32. });
  33. // See https://github.com/Polymer/polymer/issues/1381
  34. window.addEventListener('WebComponentsReady', function() {
  35. // imports are loaded and elements have been registered
  36. });
  37. // Main area's paper-scroll-header-panel custom condensing transformation of
  38. // the appName in the middle-container and the bottom title in the bottom-container.
  39. // The appName is moved to top and shrunk on condensing. The bottom sub title
  40. // is shrunk to nothing on condensing.
  41. window.addEventListener('paper-header-transform', function(e) {
  42. var appName = Polymer.dom(document).querySelector('#mainToolbar .app-name');
  43. var middleContainer = Polymer.dom(document).querySelector('#mainToolbar .middle-container');
  44. var bottomContainer = Polymer.dom(document).querySelector('#mainToolbar .bottom-container');
  45. var detail = e.detail;
  46. var heightDiff = detail.height - detail.condensedHeight;
  47. var yRatio = Math.min(1, detail.y / heightDiff);
  48. // appName max size when condensed. The smaller the number the smaller the condensed size.
  49. var maxMiddleScale = 0.50;
  50. var auxHeight = heightDiff - detail.y;
  51. var auxScale = heightDiff / (1 - maxMiddleScale);
  52. var scaleMiddle = Math.max(maxMiddleScale, auxHeight / auxScale + maxMiddleScale);
  53. var scaleBottom = 1 - yRatio;
  54. // Move/translate middleContainer
  55. Polymer.Base.transform('translate3d(0,' + yRatio * 100 + '%,0)', middleContainer);
  56. // Scale bottomContainer and bottom sub title to nothing and back
  57. Polymer.Base.transform('scale(' + scaleBottom + ') translateZ(0)', bottomContainer);
  58. // Scale middleContainer appName
  59. Polymer.Base.transform('scale(' + scaleMiddle + ') translateZ(0)', appName);
  60. });
  61. // Scroll page to top and expand header
  62. app.scrollPageToTop = function() {
  63. app.$.headerPanelMain.scrollToTop(true);
  64. };
  65. app.closeDrawer = function() {
  66. app.$.paperDrawerPanel.closeDrawer();
  67. };
  68. })(document);