2015-06-15 21:52:01 -07:00
|
|
|
<!--
|
|
|
|
@license
|
|
|
|
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
|
|
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
|
|
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
|
|
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
|
|
Code distributed by Google as part of the polymer project is also
|
|
|
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
|
|
-->
|
|
|
|
|
|
|
|
<link rel="import" href="../polymer/polymer.html">
|
|
|
|
<link rel="import" href="../iron-behaviors/iron-button-state.html">
|
2015-10-07 18:49:40 -07:00
|
|
|
<link rel="import" href="paper-ripple-behavior.html">
|
2015-06-15 21:52:01 -07:00
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2015-10-07 18:49:40 -07:00
|
|
|
/** @polymerBehavior Polymer.PaperButtonBehavior */
|
2015-06-15 21:52:01 -07:00
|
|
|
Polymer.PaperButtonBehaviorImpl = {
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
|
2015-10-07 18:49:40 -07:00
|
|
|
/**
|
|
|
|
* The z-depth of this element, from 0-5. Setting to 0 will remove the
|
|
|
|
* shadow, and each increasing number greater than 0 will be "deeper"
|
|
|
|
* than the last.
|
|
|
|
*
|
|
|
|
* @attribute elevation
|
|
|
|
* @type number
|
|
|
|
* @default 1
|
|
|
|
*/
|
|
|
|
elevation: {
|
|
|
|
type: Number,
|
|
|
|
reflectToAttribute: true,
|
|
|
|
readOnly: true
|
2015-06-15 21:52:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
observers: [
|
2015-10-07 18:49:40 -07:00
|
|
|
'_calculateElevation(focused, disabled, active, pressed, receivedFocusFromKeyboard)',
|
|
|
|
'_computeKeyboardClass(receivedFocusFromKeyboard)'
|
2015-06-15 21:52:01 -07:00
|
|
|
],
|
|
|
|
|
|
|
|
hostAttributes: {
|
|
|
|
role: 'button',
|
2015-10-07 18:49:40 -07:00
|
|
|
tabindex: '0',
|
|
|
|
animated: true
|
2015-06-15 21:52:01 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_calculateElevation: function() {
|
|
|
|
var e = 1;
|
|
|
|
if (this.disabled) {
|
|
|
|
e = 0;
|
|
|
|
} else if (this.active || this.pressed) {
|
|
|
|
e = 4;
|
|
|
|
} else if (this.receivedFocusFromKeyboard) {
|
|
|
|
e = 3;
|
|
|
|
}
|
2015-10-07 18:49:40 -07:00
|
|
|
this._setElevation(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
_computeKeyboardClass: function(receivedFocusFromKeyboard) {
|
|
|
|
this.classList.toggle('keyboard-focus', receivedFocusFromKeyboard);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-14 08:43:03 -07:00
|
|
|
* In addition to `IronButtonState` behavior, when space key goes down,
|
2015-10-07 18:49:40 -07:00
|
|
|
* create a ripple down effect.
|
2015-12-14 08:43:03 -07:00
|
|
|
*
|
|
|
|
* @param {!KeyboardEvent} event .
|
2015-10-07 18:49:40 -07:00
|
|
|
*/
|
|
|
|
_spaceKeyDownHandler: function(event) {
|
|
|
|
Polymer.IronButtonStateImpl._spaceKeyDownHandler.call(this, event);
|
|
|
|
if (this.hasRipple()) {
|
|
|
|
this._ripple.uiDownAction();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-14 08:43:03 -07:00
|
|
|
* In addition to `IronButtonState` behavior, when space key goes up,
|
2015-10-07 18:49:40 -07:00
|
|
|
* create a ripple up effect.
|
2015-12-14 08:43:03 -07:00
|
|
|
*
|
|
|
|
* @param {!KeyboardEvent} event .
|
2015-10-07 18:49:40 -07:00
|
|
|
*/
|
|
|
|
_spaceKeyUpHandler: function(event) {
|
|
|
|
Polymer.IronButtonStateImpl._spaceKeyUpHandler.call(this, event);
|
|
|
|
if (this.hasRipple()) {
|
|
|
|
this._ripple.uiUpAction();
|
|
|
|
}
|
2015-06-15 21:52:01 -07:00
|
|
|
}
|
2015-10-07 18:49:40 -07:00
|
|
|
|
2015-06-15 21:52:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @polymerBehavior */
|
|
|
|
Polymer.PaperButtonBehavior = [
|
|
|
|
Polymer.IronButtonState,
|
|
|
|
Polymer.IronControlState,
|
2015-10-07 18:49:40 -07:00
|
|
|
Polymer.PaperRippleBehavior,
|
2015-06-15 21:52:01 -07:00
|
|
|
Polymer.PaperButtonBehaviorImpl
|
|
|
|
];
|
|
|
|
|
|
|
|
</script>
|