Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 8327b07

Browse files
committed
Merge pull request #3 from warnerandy/disble-selection
Disble selection
2 parents 02fbcd9 + d5ffe62 commit 8327b07

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

core-splitter.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
1414
box-shadow: inset 0 0 2px 1px #ccc;
1515
cursor: col-resize;
1616
}
17-
17+
1818
:host(.horizontal) {
1919
width: auto;
2020
height: 12px;
2121
cursor: row-resize;
2222
background-image: url(handle-h.svg);
2323
}
24-
24+
2525
:host(:hover, :active) {
2626
background-color: #ddd;
27-
}
27+
}

core-splitter.html

+35-16
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<core-splitter direction="left"></core-splitter>
2222
<div flex>right</div>
2323
</div>
24-
24+
2525
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
2727
`flex`, the _right_ elemnt will be auto-resized.
2828
2929
For horizontal splitter set `direction` to "up" or "down".
@@ -43,17 +43,17 @@
4343

4444
<link rel="import" href="../polymer/polymer.html">
4545

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+
4848
<template>
4949

5050
<link rel="stylesheet" href="core-splitter.css">
51-
51+
5252
</template>
5353
<script>
5454

5555
Polymer('core-splitter', {
56-
56+
5757
/**
5858
* Possible values are "left", "right", "up" and "down".
5959
*
@@ -71,7 +71,7 @@
7171
* @default 0
7272
*/
7373
minSize: 0,
74-
74+
7575
/**
7676
* Locks the split bar so it can't be dragged.
7777
*
@@ -91,7 +91,16 @@
9191
* @default false
9292
*/
9393
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+
95104
ready: function() {
96105
this.directionChanged();
97106
},
@@ -102,13 +111,13 @@
102111
this.previousElementSibling.style.overflow = 'hidden';
103112
}
104113
},
105-
114+
106115
directionChanged: function() {
107116
this.isNext = this.direction === 'right' || this.direction === 'down';
108117
this.horizontal = this.direction === 'up' || this.direction === 'down';
109118
this.update();
110119
},
111-
120+
112121
update: function() {
113122
this.target = this.isNext ? this.nextElementSibling : this.previousElementSibling;
114123
this.dimension = this.horizontal ? 'height' : 'width';
@@ -122,22 +131,32 @@
122131
var min = this.target.__splitterMinSize = this.horizontal ? 'minHeight' : 'minWidth';
123132
this.target.style[min] = this.minSize + 'px';
124133
},
125-
134+
126135
trackStart: function() {
127136
this.update();
128137
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+
}
129142
},
130-
143+
131144
track: function(e) {
132145
if (this.locked) {
133146
return;
134147
}
135148
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+
}
138157
}
139-
158+
140159
});
141-
160+
142161
</script>
143162
</polymer-element>

0 commit comments

Comments
 (0)