|
21 | 21 | <core-splitter direction="left"></core-splitter>
|
22 | 22 | <div flex>right</div>
|
23 | 23 | </div>
|
24 |
| - |
| 24 | +
|
25 | 25 | In the above example, dragging the splitter will resize the _left_ element. And
|
26 |
| -since the parent container is a flexbox and the _right_ element has |
| 26 | +since the parent container is a flexbox and the _right_ element has |
27 | 27 | `flex`, the _right_ elemnt will be auto-resized.
|
28 | 28 |
|
29 | 29 | For horizontal splitter set `direction` to "up" or "down".
|
|
43 | 43 |
|
44 | 44 | <link rel="import" href="../polymer/polymer.html">
|
45 | 45 |
|
46 |
| -<polymer-element name="core-splitter" attributes="direction locked minSize allowOverflow" on-trackstart="{{trackStart}}" on-track="{{track}}"> |
47 |
| - |
| 46 | +<polymer-element name="core-splitter" attributes="direction locked minSize allowOverflow disableSelection" on-trackstart="{{trackStart}}" on-track="{{track}}" on-trackend={{trackEnd}}> |
| 47 | + |
48 | 48 | <template>
|
49 | 49 |
|
50 | 50 | <link rel="stylesheet" href="core-splitter.css">
|
51 |
| - |
| 51 | + |
52 | 52 | </template>
|
53 | 53 | <script>
|
54 | 54 |
|
55 | 55 | Polymer('core-splitter', {
|
56 |
| - |
| 56 | + |
57 | 57 | /**
|
58 | 58 | * Possible values are "left", "right", "up" and "down".
|
59 | 59 | *
|
|
71 | 71 | * @default 0
|
72 | 72 | */
|
73 | 73 | minSize: 0,
|
74 |
| - |
| 74 | + |
75 | 75 | /**
|
76 | 76 | * Locks the split bar so it can't be dragged.
|
77 | 77 | *
|
|
91 | 91 | * @default false
|
92 | 92 | */
|
93 | 93 | allowOverflow: false,
|
94 |
| - |
| 94 | + |
| 95 | + /** |
| 96 | + * Disables the selection of text while the splitter is being moved |
| 97 | + * |
| 98 | + * @attribute disableSelection |
| 99 | + * @type boolean |
| 100 | + * @type default false |
| 101 | + */ |
| 102 | + disableSelection: false, |
| 103 | + |
95 | 104 | ready: function() {
|
96 | 105 | this.directionChanged();
|
97 | 106 | },
|
|
102 | 111 | this.previousElementSibling.style.overflow = 'hidden';
|
103 | 112 | }
|
104 | 113 | },
|
105 |
| - |
| 114 | + |
106 | 115 | directionChanged: function() {
|
107 | 116 | this.isNext = this.direction === 'right' || this.direction === 'down';
|
108 | 117 | this.horizontal = this.direction === 'up' || this.direction === 'down';
|
109 | 118 | this.update();
|
110 | 119 | },
|
111 |
| - |
| 120 | + |
112 | 121 | update: function() {
|
113 | 122 | this.target = this.isNext ? this.nextElementSibling : this.previousElementSibling;
|
114 | 123 | this.dimension = this.horizontal ? 'height' : 'width';
|
|
122 | 131 | var min = this.target.__splitterMinSize = this.horizontal ? 'minHeight' : 'minWidth';
|
123 | 132 | this.target.style[min] = this.minSize + 'px';
|
124 | 133 | },
|
125 |
| - |
| 134 | + |
126 | 135 | trackStart: function() {
|
127 | 136 | this.update();
|
128 | 137 | this.size = parseInt(getComputedStyle(this.target)[this.dimension]);
|
| 138 | + if (this.disableSelection) { |
| 139 | + var s = this.parentNode.style; |
| 140 | + s.webkitUserSelect = s.MozUserSelect = s.msUserSelect = 'none'; |
| 141 | + } |
129 | 142 | },
|
130 |
| - |
| 143 | + |
131 | 144 | track: function(e) {
|
132 | 145 | if (this.locked) {
|
133 | 146 | return;
|
134 | 147 | }
|
135 | 148 | var d = e[this.horizontal ? 'dy' : 'dx'];
|
136 |
| - this.target.style[this.dimension] = |
137 |
| - this.size + (this.isNext ? -d : d) + 'px'; |
| 149 | + this.target.style[this.dimension] = |
| 150 | + this.size + (this.isNext ? -d : d) + 'px'; |
| 151 | + }, |
| 152 | + trackEnd: function (e) { |
| 153 | + if (this.disableSelection) { |
| 154 | + var s = this.parentNode.style; |
| 155 | + s.webkitUserSelect = s.MozUserSelect = s.msUserSelect = ''; |
| 156 | + } |
138 | 157 | }
|
139 |
| - |
| 158 | + |
140 | 159 | });
|
141 |
| - |
| 160 | + |
142 | 161 | </script>
|
143 | 162 | </polymer-element>
|
0 commit comments