| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. | 4 found in the LICENSE file. |
| 5 --> | 5 --><html><head><link href="../bower_components/polymer/polymer.html" rel="import
"> |
| 6 <link href="../bower_components/polymer/polymer.html" rel="import"> | 6 <link href="../bower_components/iron-icon/iron-icon.html" rel="import"> |
| 7 <link href="../bower_components/core-icon/core-icon.html" rel="import"> | |
| 8 | 7 |
| 9 <polymer-element name="ct-popup-menu" attributes="{{ icon }}"> | 8 <dom-module id="ct-popup-menu"> |
| 10 <template> | 9 <style> |
| 11 <style> | |
| 12 :host { | 10 :host { |
| 13 display: inline-block; | 11 display: inline-block; |
| 14 } | 12 } |
| 15 #menu { | 13 #menu { |
| 16 background-color: white; | 14 background-color: white; |
| 17 border: 1px solid grey; | 15 border: 1px solid grey; |
| 18 max-height: 300px; | 16 max-height: 300px; |
| 19 overflow-y: scroll; /* FIXME: should be auto, but that triggers prematur
e line wrapping */ | 17 overflow-y: scroll; /* FIXME: should be auto, but that triggers prematur
e line wrapping */ |
| 20 padding: 1em; | 18 padding: 1em; |
| 21 position: absolute; | 19 position: absolute; |
| 22 transition: transform 0.2s ease-in-out, opacity 0.2s ease-in; | 20 transition: transform 0.2s ease-in-out, opacity 0.2s ease-in; |
| 23 z-index: 50; | 21 z-index: 50; |
| 24 -webkit-box-shadow: 3px 4px 20px 0px rgba(0,0,0,0.75); | 22 -webkit-box-shadow: 3px 4px 20px 0px rgba(0,0,0,0.75); |
| 25 } | 23 } |
| 26 .hidden { | 24 .hidden { |
| 27 opacity: 0; | 25 opacity: 0; |
| 28 visibility: hidden; /* Necessary to avoid eating clicks. */ | 26 visibility: hidden; /* Necessary to avoid eating clicks. */ |
| 29 } | 27 } |
| 30 </style> | 28 </style> |
| 31 <core-icon id="icon" src="{{ src }}" icon="{{ icon }}" on-click="{{ _toggleA
ction }}"></core-icon> | 29 <template> |
| 30 <iron-icon id="icon" src="{{ src }}" icon="{{ icon }}" on-click=" _toggleAct
ion "></iron-icon> |
| 32 <div id="menu" class="hidden"> | 31 <div id="menu" class="hidden"> |
| 33 <content></content> | 32 <content></content> |
| 34 </div> | 33 </div> |
| 35 </template> | 34 </template> |
| 36 <script> | 35 <script> |
| 37 (function() { | 36 (function () { |
| 38 Polymer({ | 37 Polymer({ |
| 39 attached: function() { | 38 is: 'ct-popup-menu', |
| 40 // FIXME: hitting escape should also hide the menu. | 39 properties: { |
| 41 document.body.addEventListener('click', this._handleClick.bind(this), tr
ue) | 40 icon: { notify: true }, |
| 42 }, | 41 {{: { notify: true }, |
| 43 | 42 }}: { notify: true } |
| 44 detached: function() { | 43 }, |
| 45 document.body.removeEventListener('click', this._handleClick.bind(this),
true) | 44 attached: function () { |
| 46 }, | 45 // FIXME: hitting escape should also hide the menu. |
| 47 | 46 document.body.addEventListener('click', this._handleClick.bind(this),
true); |
| 48 _toggleAction: function() { | 47 }, |
| 49 this.$.menu.classList.toggle('hidden'); | 48 detached: function () { |
| 50 }, | 49 document.body.removeEventListener('click', this._handleClick.bind(this
), true); |
| 51 | 50 }, |
| 52 _handleClick: function(event) { | 51 _toggleAction: function () { |
| 53 if (this.$.menu.classList.contains('hidden')) | 52 this.$.menu.classList.toggle('hidden'); |
| 54 return; | 53 }, |
| 55 for (var i = event.path.length - 1; i >= 0; i--) { | 54 _handleClick: function (event) { |
| 56 if (event.path[i] === this) | 55 if (this.$.menu.classList.contains('hidden')) |
| 57 return; | 56 return; |
| 57 for (var i = event.path.length - 1; i >= 0; i--) { |
| 58 if (event.path[i] === this) |
| 59 return; |
| 60 } |
| 61 event.preventDefault(); |
| 62 this.$.menu.classList.add('hidden'); |
| 58 } | 63 } |
| 59 event.preventDefault(); | 64 }); |
| 60 this.$.menu.classList.add('hidden'); | 65 }()); |
| 61 }, | |
| 62 }); | |
| 63 })(); | |
| 64 </script> | 66 </script> |
| 65 </polymer-element> | 67 </dom-module> |
| OLD | NEW |