OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.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/CONTRI
BUTORS.txt | 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
6 Code distributed by Google as part of the polymer project is also | 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/PATEN
TS.txt | 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
8 --> | 8 --> |
9 | 9 |
10 <link rel="import" href="../polymer/polymer.html"> | 10 <link rel="import" href="../polymer/polymer.html"> |
11 <link rel="import" href="../core-transition/core-transition.html"> | 11 <link rel="import" href="../core-transition/core-transition.html"> |
| 12 <link rel="import" href="../core-resizable/core-resizable.html"> |
12 <link rel="import" href="core-key-helper.html"> | 13 <link rel="import" href="core-key-helper.html"> |
13 <link rel="import" href="core-overlay-layer.html"> | 14 <link rel="import" href="core-overlay-layer.html"> |
14 | 15 |
15 <!-- | 16 <!-- |
16 The `core-overlay` element displays overlayed on top of other content. It starts | 17 The `core-overlay` element displays overlayed on top of other content. It starts |
17 out hidden and is displayed by setting its `opened` property to true. | 18 out hidden and is displayed by setting its `opened` property to true. |
18 A `core-overlay's` opened state can be toggled by calling the `toggle` | 19 A `core-overlay's` opened state can be toggled by calling the `toggle` |
19 method. | 20 method. |
20 | 21 |
21 The `core-overlay` will, by default, show/hide itself when it's opened. The | 22 The `core-overlay` will, by default, show/hide itself when it's opened. The |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 109 |
109 .core-overlay-backdrop.core-opened { | 110 .core-overlay-backdrop.core-opened { |
110 opacity: 0.6; | 111 opacity: 0.6; |
111 } | 112 } |
112 </style> | 113 </style> |
113 | 114 |
114 <polymer-element name="core-overlay"> | 115 <polymer-element name="core-overlay"> |
115 <script> | 116 <script> |
116 (function() { | 117 (function() { |
117 | 118 |
118 Polymer('core-overlay', { | 119 Polymer(Polymer.mixin({ |
119 | 120 |
120 publish: { | 121 publish: { |
121 /** | 122 /** |
122 * The target element that will be shown when the overlay is | 123 * The target element that will be shown when the overlay is |
123 * opened. If unspecified, the core-overlay itself is the target. | 124 * opened. If unspecified, the core-overlay itself is the target. |
124 * | 125 * |
125 * @attribute target | 126 * @attribute target |
126 * @type Object | 127 * @type Object |
127 * @default the overlay element | 128 * @default the overlay element |
128 */ | 129 */ |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 transition: 'core-transition-fade' | 230 transition: 'core-transition-fade' |
230 | 231 |
231 }, | 232 }, |
232 | 233 |
233 captureEventName: 'tap', | 234 captureEventName: 'tap', |
234 targetListeners: { | 235 targetListeners: { |
235 'tap': 'tapHandler', | 236 'tap': 'tapHandler', |
236 'keydown': 'keydownHandler', | 237 'keydown': 'keydownHandler', |
237 'core-transitionend': 'transitionend' | 238 'core-transitionend': 'transitionend' |
238 }, | 239 }, |
239 | 240 |
| 241 attached: function() { |
| 242 this.resizerAttachedHandler(); |
| 243 }, |
| 244 |
| 245 detached: function() { |
| 246 this.resizerDetachedHandler(); |
| 247 }, |
| 248 |
| 249 resizerShouldNotify: function() { |
| 250 return this.opened; |
| 251 }, |
| 252 |
240 registerCallback: function(element) { | 253 registerCallback: function(element) { |
241 this.layer = document.createElement('core-overlay-layer'); | 254 this.layer = document.createElement('core-overlay-layer'); |
242 this.keyHelper = document.createElement('core-key-helper'); | 255 this.keyHelper = document.createElement('core-key-helper'); |
243 this.meta = document.createElement('core-transition'); | 256 this.meta = document.createElement('core-transition'); |
244 this.scrim = document.createElement('div'); | 257 this.scrim = document.createElement('div'); |
245 this.scrim.className = 'core-overlay-backdrop'; | 258 this.scrim.className = 'core-overlay-backdrop'; |
246 }, | 259 }, |
247 | 260 |
248 ready: function() { | 261 ready: function() { |
249 this.target = this.target || this; | 262 this.target = this.target || this; |
250 // flush to ensure styles are installed before paint | 263 // flush to ensure styles are installed before paint |
251 Platform.flush(); | 264 Polymer.flush(); |
252 }, | 265 }, |
253 | 266 |
254 /** | 267 /** |
255 * Toggle the opened state of the overlay. | 268 * Toggle the opened state of the overlay. |
256 * @method toggle | 269 * @method toggle |
257 */ | 270 */ |
258 toggle: function() { | 271 toggle: function() { |
259 this.opened = !this.opened; | 272 this.opened = !this.opened; |
260 }, | 273 }, |
261 | 274 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 if (this.layered) { | 393 if (this.layered) { |
381 this.layer.addElement(this.target); | 394 this.layer.addElement(this.target); |
382 this.layer.opened = this.opened; | 395 this.layer.opened = this.opened; |
383 } | 396 } |
384 } | 397 } |
385 }, | 398 }, |
386 | 399 |
387 // tasks which cause the overlay to actually open; typically play an | 400 // tasks which cause the overlay to actually open; typically play an |
388 // animation | 401 // animation |
389 renderOpened: function() { | 402 renderOpened: function() { |
| 403 this.notifyResize(); |
390 var transition = this.getTransition(); | 404 var transition = this.getTransition(); |
391 if (transition) { | 405 if (transition) { |
392 transition.go(this.target, {opened: this.opened}); | 406 transition.go(this.target, {opened: this.opened}); |
393 } else { | 407 } else { |
394 this.transitionend(); | 408 this.transitionend(); |
395 } | 409 } |
396 this.renderBackdropOpened(); | 410 this.renderBackdropOpened(); |
397 }, | 411 }, |
398 | 412 |
399 // finishing tasks; typically called via a transition | 413 // finishing tasks; typically called via a transition |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 } | 578 } |
565 | 579 |
566 if (!this.dimensions.position.h) { | 580 if (!this.dimensions.position.h) { |
567 var l = (window.innerWidth - this.target.offsetWidth) / 2; | 581 var l = (window.innerWidth - this.target.offsetWidth) / 2; |
568 l -= this.dimensions.margin.left; | 582 l -= this.dimensions.margin.left; |
569 this.target.style.left = l + 'px'; | 583 this.target.style.left = l + 'px'; |
570 } | 584 } |
571 }, | 585 }, |
572 | 586 |
573 resetTargetDimensions: function() { | 587 resetTargetDimensions: function() { |
574 if (!this.dimensions.size.v) { | 588 if (!this.dimensions || !this.dimensions.size.v) { |
575 this.sizingTarget.style.maxHeight = ''; | 589 this.sizingTarget.style.maxHeight = ''; |
| 590 this.target.style.top = ''; |
576 } | 591 } |
577 if (!this.dimensions.size.h) { | 592 if (!this.dimensions || !this.dimensions.size.h) { |
578 this.sizingTarget.style.maxWidth = ''; | 593 this.sizingTarget.style.maxWidth = ''; |
| 594 this.target.style.left = ''; |
579 } | 595 } |
580 this.dimensions = null; | 596 this.dimensions = null; |
581 }, | 597 }, |
582 | 598 |
583 tapHandler: function(e) { | 599 tapHandler: function(e) { |
584 // closeSelector takes precedence since closeAttribute has a default non-n
ull value. | 600 // closeSelector takes precedence since closeAttribute has a default non-n
ull value. |
585 if (e.target && | 601 if (e.target && |
586 (this.closeSelector && e.target.matches(this.closeSelector)) || | 602 (this.closeSelector && e.target.matches(this.closeSelector)) || |
587 (this.closeAttribute && e.target.hasAttribute(this.closeAttribute))) { | 603 (this.closeAttribute && e.target.hasAttribute(this.closeAttribute))) { |
588 this.toggle(); | 604 this.toggle(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 if (!method) { | 682 if (!method) { |
667 return; | 683 return; |
668 } | 684 } |
669 var bound = '_bound' + methodName; | 685 var bound = '_bound' + methodName; |
670 if (!this[bound]) { | 686 if (!this[bound]) { |
671 this[bound] = function(e) { | 687 this[bound] = function(e) { |
672 method.call(self, e); | 688 method.call(self, e); |
673 }; | 689 }; |
674 } | 690 } |
675 return this[bound]; | 691 return this[bound]; |
676 }, | 692 } |
677 }); | 693 |
| 694 }, Polymer.CoreResizer)); |
678 | 695 |
679 // TODO(sorvell): This should be an element with private state so it can | 696 // TODO(sorvell): This should be an element with private state so it can |
680 // be independent of overlay. | 697 // be independent of overlay. |
681 // track overlays for z-index and focus managemant | 698 // track overlays for z-index and focus managemant |
682 var overlays = []; | 699 var overlays = []; |
683 function addOverlay(overlay) { | 700 function addOverlay(overlay) { |
684 var z0 = currentOverlayZ(); | 701 var z0 = currentOverlayZ(); |
685 overlays.push(overlay); | 702 overlays.push(overlay); |
686 var z1 = currentOverlayZ(); | 703 var z1 = currentOverlayZ(); |
687 if (z1 <= z0) { | 704 if (z1 <= z0) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 766 } |
750 } | 767 } |
751 } | 768 } |
752 | 769 |
753 function getBackdrops() { | 770 function getBackdrops() { |
754 return backdrops; | 771 return backdrops; |
755 } | 772 } |
756 })(); | 773 })(); |
757 </script> | 774 </script> |
758 </polymer-element> | 775 </polymer-element> |
OLD | NEW |