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

Commit

Permalink
manual-change -> change
Browse files Browse the repository at this point in the history
change -> core-change

`change` event is fired when the checked state changes due to user
interaction. And `core-change` event is fired when the checked state
changes.
  • Loading branch information
frankiefu committed Aug 25, 2014
1 parent 842398c commit 96eff86
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 59 deletions.
84 changes: 58 additions & 26 deletions paper-slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,56 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
height: 32px;
}

:host([editable]) #sliderContainer {
#sliderContainer.editable {
float: left;
width: calc(100% - 72px);
margin: 12px 0;
}

.bar-container {
position: absolute;
top: 0;
left: 16px;
height: 100%;
width: 100%;
overflow: hidden;
}

.ring > .bar-container {
left: 20px;
width: calc(100% - 4px);
transition: left 0.18s ease, width 0.18s ease;
}

.ring.expand:not(.pin) > .bar-container {
left: 30px;
width: calc(100% - 14px);
}

.ring.expand.dragging > .bar-container {
transition: none;
}

#sliderBar {
position: absolute;
top: 15px;
left: 16px;
left: 0;
height: 2px;
width: 100%;
padding: 8px 0;
margin: -8px 0;
}

.ring #sliderBar {
left: -4px;
width: calc(100% + 4px);
}

.ring.expand:not(.pin) #sliderBar {
left: -14px;
width: calc(100% + 14px);
}

.slider-markers {
position: absolute;
top: 15px;
Expand All @@ -42,8 +77,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
width: calc(100% + 2px);
box-sizing: border-box;
pointer-events: none;
/* background-image: -webkit-linear-gradient(0deg, #ccc, #ccc 1px, transparent 1px, transparent);
background-size: 10%; */
}

.slider-markers::after, .slider-marker::after {
Expand Down Expand Up @@ -79,7 +112,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
transition: none;
}

#sliderKnob.snaps.dragging {
.snaps > #sliderKnob.dragging {
transition: -webkit-transform 0.08s ease;
transition: transform 0.08s ease;
}
Expand All @@ -95,26 +128,26 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
/* transition-property: height, width, background-color, border;
transition-duration: 0.1s;
transition-timing-function: ease; */
transition: height 0.18s ease, width 0.18s ease, background-color 0.28s ease, border 0.18s ease;
transition: height 0.18s ease, width 0.18s ease;
}

#sliderKnob.expand:not(.pin) > #sliderKnobInner {
.expand:not(.pin) > #sliderKnob > #sliderKnobInner {
width: 100%;
height: 100%;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}

#sliderKnob.ring > #sliderKnobInner {
background-color: #fff;
.ring > #sliderKnob > #sliderKnobInner {
background-color: transparent;
border: 2px solid #c8c8c8;
}

#sliderKnobInner::before {
background-color: #3f51b5;
}

#sliderKnob.pin > #sliderKnobInner::before {
.pin > #sliderKnob > #sliderKnobInner::before {
content: "";
position: absolute;
top: 0;
Expand All @@ -132,18 +165,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
transition: transform .2s ease, background-color .18s ease;
}

#sliderKnob.pin.ring > #sliderKnobInner::before {
.pin.ring > #sliderKnob > #sliderKnobInner::before {
background-color: #c8c8c8;
}

#sliderKnob.pin.expand > #sliderKnobInner::before {
.pin.expand > #sliderKnob > #sliderKnobInner::before {
-webkit-transform: rotate(-45deg) scale(1) translate(17px, -17px);
transform: rotate(-45deg) scale(1) translate(17px, -17px);
}

#sliderKnob.pin > #sliderKnobInner::after {
/* FIXME(ffu): add dummy quotes to workaround https://github.com/Polymer/platform/issues/57 */
content: attr(value) "";
.pin > #sliderKnob > #sliderKnobInner::after {
content: attr(value);
position: absolute;
top: 0;
left: 0;
Expand All @@ -156,15 +188,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
transform: scale(0) translate(0);
}

#sliderKnob.pin.expand > #sliderKnobInner::after {
.pin.expand > #sliderKnob > #sliderKnobInner::after {
-webkit-transform: scale(1) translate(0, -17px);
transform: scale(1) translate(0, -17px);
}

/* editable: paper-input */
.slider-input {
width: 40px;
height: 32px;
float: right;
overflow: hidden;
}

.slider-input::shadow input {
Expand All @@ -173,21 +206,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}

/* disabled state */
:host([disabled]) #sliderContainer {
#sliderContainer.disabled {
pointer-events: none;
}

:host([disabled]) {
pointer-events: none;
.disabled > #sliderKnob > #sliderKnobInner {
width: 8px;
height: 8px;
background-color: #c8c8c8;
}

:host([disabled]) #sliderKnob > #sliderKnobInner {
width: 12px;
height: 12px;
background-color: #c8c8c8;
border: 2px solid #fff;
.disabled.ring > #sliderKnob > #sliderKnobInner {
background-color: transparent;
}

:host([disabled]) #sliderContainer > #sliderBar::shadow #activeProgress {
#sliderContainer.disabled #sliderBar::shadow #activeProgress {
background-color: #c8c8c8;
}
63 changes: 30 additions & 33 deletions paper-slider.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@

<link rel="stylesheet" href="paper-slider.css">

<div id="sliderContainer" on-keydown="{{keydown}}">
<div id="sliderContainer" class="{{ {disabled: disabled, pin: pin, snaps: snaps, ring: immediateValue <= min, expand: expand, dragging: dragging, editable: editable} | tokenList }}" on-keydown="{{keydown}}">

<paper-progress id="sliderBar" aria-hidden="true" min="{{min}}" max="{{max}}" value="{{immediateValue}}" secondaryProgress="{{secondaryProgress}}"
on-down="{{bardown}}" on-up="{{resetKnob}}"
on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{trackEnd}}"></paper-progress>
<div class="bar-container">
<paper-progress id="sliderBar" aria-hidden="true" min="{{min}}" max="{{max}}" value="{{immediateValue}}" secondaryProgress="{{secondaryProgress}}"
on-down="{{bardown}}" on-up="{{resetKnob}}"
on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{trackEnd}}"></paper-progress>
</div>

<template if="{{snaps && !disabled}}">
<div class="slider-markers" horizontal layout>
Expand All @@ -83,8 +85,7 @@
</div>
</template>

<div id="sliderKnob" class="{{ {pin : pin, snaps : snaps} | tokenList }}"
on-down="{{expandKnob}}" on-up="{{resetKnob}}"
<div id="sliderKnob" on-down="{{expandKnob}}" on-up="{{resetKnob}}"
on-trackstart="{{trackStart}}" on-trackx="{{trackx}}" on-trackend="{{trackEnd}}"
on-transitionend="{{knobTransitionEnd}}"
role="slider" aria-valuenow="{{value}}" aria-valuemin="{{min}}" aria-valuemax="{{max}}"
Expand All @@ -98,7 +99,7 @@
</div>

<template if="{{editable}}">
<paper-input id="input" class="slider-input" value="{{immediateValue}}" validate="^[-+]?[0-9]*\.?[0-9]+$" disabled?="{{disabled}}" on-change="{{inputChange}}"></paper-input>
<paper-input id="input" class="slider-input" value="{{immediateValue}}" disabled?="{{disabled}}" on-change="{{inputChange}}"></paper-input>
</template>

</template>
Expand All @@ -109,16 +110,16 @@
/**
* Fired when the slider's value changes.
*
* @event change
* @event core-change
*/

/**
* Fired when the slider's value changes due to manual interaction.
* Fired when the slider's value changes due to user interaction.
*
* Changes to the slider's value due to changes in an underlying
* bound variable will not trigger this event.
*
* @event manual-change
* @event change
*/

/**
Expand Down Expand Up @@ -194,38 +195,31 @@

valueChanged: function() {
this.update();
this.fire('change');
this.fire('core-change');
},

expandKnob: function() {
this.$.sliderKnob.classList.add('expand');
this.expand = true;
},

resetKnob: function() {
this.expandJob && this.expandJob.stop();
this.$.sliderKnob.classList.remove('expand');
this.expand = false;
},

positionKnob: function(ratio) {
this._ratio = ratio;
this.immediateValue = this.calcStep(this.calcKnobPosition()) || 0;
if (this.snaps) {
this._ratio = this.calcRatio(this.immediateValue);
}
this.immediateValue = this.calcStep(this.calcKnobPosition(ratio)) || 0;
this._ratio = this.snaps ? this.calcRatio(this.immediateValue) : ratio;
this.$.sliderKnob.style.left = this._ratio * 100 + '%';
},

immediateValueChanged: function() {
this.$.sliderKnob.classList.toggle('ring', this.immediateValue <= this.min);
},

inputChange: function() {
this.value = this.$.input.value;
this.fire('manual-change');
this.fire('change');
},

calcKnobPosition: function() {
return (this.max - this.min) * this._ratio + this.min;
calcKnobPosition: function(ratio) {
return (this.max - this.min) * ratio + this.min;
},

measureWidth: function() {
Expand All @@ -239,14 +233,15 @@
this._minx = - this._startx;
this._maxx = this._w - this._startx;
this.$.sliderKnob.classList.add('dragging');
this.dragging = true;
e.preventTap();
},

trackx: function(e) {
var x = Math.min(this._maxx, Math.max(this._minx, e.dx));
this._x = this._startx + x;
this._ratio = this._x / this._w;
this.immediateValue = this.calcStep(this.calcKnobPosition()) || 0;
this.immediateValue = this.calcStep(
this.calcKnobPosition(this._x / this._w)) || 0;
var s = this.$.sliderKnob.style;
s.transform = s.webkitTransform = 'translate3d(' + (this.snaps ?
(this.calcRatio(this.immediateValue) * this._w) - this._startx : x) + 'px, 0, 0)';
Expand All @@ -256,19 +251,21 @@
var s = this.$.sliderKnob.style;
s.transform = s.webkitTransform = '';
this.$.sliderKnob.classList.remove('dragging');
this.dragging = false;
this.resetKnob();
this.value = this.immediateValue;
this.fire('manual-change');
this.fire('change');
},

bardown: function(e) {
this.measureWidth();
this.$.sliderKnob.classList.add('transiting');
var rect = this.$.sliderBar.getBoundingClientRect();
this.positionKnob((e.x - rect.left) / this._w);
this.value = this.calcStep(this.calcKnobPosition());
var ratio = (e.x - rect.left) / this._w;
this.positionKnob(ratio);
this.value = this.calcStep(this.calcKnobPosition(ratio));
this.expandJob = this.job(this.expandJob, this.expandKnob, 60);
this.fire('manual-change');
this.fire('change');
},

knobTransitionEnd: function() {
Expand Down Expand Up @@ -297,10 +294,10 @@
var c = e.keyCode;
if (c === 37) {
this.decrement();
this.fire('manual-change');
this.fire('change');
} else if (c === 39) {
this.increment();
this.fire('manual-change');
this.fire('change');
}
}

Expand Down

0 comments on commit 96eff86

Please sign in to comment.