OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2013 The Polymer Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style |
| 4 license that can be found in the LICENSE file. |
| 5 --> |
| 6 <!-- |
| 7 /** |
| 8 * @module Polymer UI Elements |
| 9 */ |
| 10 /** |
| 11 * polymer-ui-splitter provides a spilt bar and dragging on the split bar |
| 12 * will resize the sibling element. Use the property "direction" to indicate |
| 13 * which sibling to be resized and the orientation. |
| 14 * |
| 15 * Example: |
| 16 * |
| 17 * <div class="flexbox"> |
| 18 * <div>left</div> |
| 19 * <polymer-ui-splitter direction="left"></polymer-ui-splitter> |
| 20 * <div flex>right</div> |
| 21 * </div> |
| 22 * |
| 23 * For horizontal splitter set direction to "up" or "down". |
| 24 * |
| 25 * Example: |
| 26 * |
| 27 * <div class="flexbox column"> |
| 28 * <div>top</div> |
| 29 * <polymer-ui-splitter direction="up"></polymer-ui-splitter> |
| 30 * <div flex>bottom</div> |
| 31 * </div> |
| 32 * |
| 33 * @class polymer-ui-splitter |
| 34 */ |
| 35 --> |
| 36 <link rel="import" href="../polymer/polymer.html"> |
| 37 |
| 38 <polymer-element name="polymer-ui-splitter" attributes="direction locked" |
| 39 on-trackstart="{{trackStart}}" on-track="{{track}}" on-trackend="{{trackEnd}
}"> |
| 40 <template> |
| 41 <link rel="stylesheet" href="polymer-ui-splitter.css"> |
| 42 </template> |
| 43 <script> |
| 44 Polymer('polymer-ui-splitter', { |
| 45 /** |
| 46 * Possible values are "left", "right", "up" and "down". |
| 47 * |
| 48 * @attribute direction |
| 49 * @type string |
| 50 * @default 'left' |
| 51 */ |
| 52 direction: 'left', |
| 53 /** |
| 54 * Locks the split bar so it can't be dragged. |
| 55 * |
| 56 * @attribute locked |
| 57 * @type boolean |
| 58 * @default false |
| 59 */ |
| 60 locked: false, |
| 61 ready: function() { |
| 62 this.directionChanged(); |
| 63 }, |
| 64 directionChanged: function() { |
| 65 this.isNext = this.direction === 'right' || this.direction === 'down'; |
| 66 this.horizontal = this.direction === 'up' || this.direction === 'down'; |
| 67 this.update(); |
| 68 }, |
| 69 update: function() { |
| 70 this.target = this.isNext ? this.nextElementSibling : this.previousEleme
ntSibling; |
| 71 this.dimension = this.horizontal ? 'height' : 'width'; |
| 72 this.classList.toggle('horizontal', this.horizontal); |
| 73 }, |
| 74 trackStart: function(e) { |
| 75 this.update(); |
| 76 this.classList.add('active'); |
| 77 this.size = parseInt(getComputedStyle(this.target)[this.dimension]); |
| 78 }, |
| 79 track: function(e) { |
| 80 if (this.locked) { |
| 81 return; |
| 82 } |
| 83 var d = e[this.horizontal ? 'dy' : 'dx']; |
| 84 this.target.style[this.dimension] = |
| 85 this.size + (this.isNext ? -d : d) + 'px'; |
| 86 }, |
| 87 trackEnd: function() { |
| 88 this.classList.remove('active'); |
| 89 } |
| 90 }); |
| 91 </script> |
| 92 </polymer-element> |
OLD | NEW |