added tests with paper-slider

This commit is contained in:
DadaMonad
2015-01-03 03:44:50 +00:00
parent e73829f73b
commit 17a752c93e
158 changed files with 9702 additions and 7 deletions

View File

@@ -0,0 +1,18 @@
{
"name": "core-focusable",
"private": false,
"dependencies": {
"polymer": "Polymer/polymer#^0.5.0"
},
"version": "0.5.2",
"homepage": "https://github.com/Polymer/core-focusable",
"_release": "0.5.2",
"_resolution": {
"type": "version",
"tag": "0.5.2",
"commit": "54fda73ce01c1e68041a3e89d2d0656a8f9f8543"
},
"_source": "git://github.com/Polymer/core-focusable.git",
"_target": "^0.5.0",
"_originalSource": "Polymer/core-focusable"
}

View File

@@ -0,0 +1,6 @@
core-focusable
==============
owner: @morethanreal
See the [component page](http://polymer-project.org/docs/elements/core-elements.html#core-focusable) for more information.

View File

@@ -0,0 +1,8 @@
{
"name": "core-focusable",
"private": false,
"dependencies": {
"polymer": "Polymer/polymer#^0.5.0"
},
"version": "0.5.2"
}

View File

@@ -0,0 +1,4 @@
<link href="../polymer/polymer.html" rel="import">
<script src="polymer-mixin.js"></script>
<script src="core-focusable.js"></script>

View File

@@ -0,0 +1,134 @@
/**
* @group Polymer Mixins
*
* `Polymer.CoreFocusable` is a mixin for elements that the user can interact with.
* Elements using this mixin will receive attributes reflecting the focus, pressed
* and disabled states.
*
* @element Polymer.CoreFocusable
* @status unstable
*/
Polymer.CoreFocusable = {
mixinPublish: {
/**
* If true, the element is currently active either because the
* user is touching it, or the button is a toggle
* and is currently in the active state.
*
* @attribute active
* @type boolean
* @default false
*/
active: {value: false, reflect: true},
/**
* If true, the element currently has focus due to keyboard
* navigation.
*
* @attribute focused
* @type boolean
* @default false
*/
focused: {value: false, reflect: true},
/**
* If true, the user is currently holding down the button.
*
* @attribute pressed
* @type boolean
* @default false
*/
pressed: {value: false, reflect: true},
/**
* If true, the user cannot interact with this element.
*
* @attribute disabled
* @type boolean
* @default false
*/
disabled: {value: false, reflect: true},
/**
* If true, the button toggles the active state with each tap.
* Otherwise, the button becomes active when the user is holding
* it down.
*
* @attribute toggle
* @type boolean
* @default false
*/
toggle: false
},
mixinDelegates: {
contextMenu: '_contextMenuAction',
down: '_downAction',
up: '_upAction',
focus: '_focusAction',
blur: '_blurAction'
},
mixinObserve: {
disabled: '_disabledChanged'
},
_disabledChanged: function() {
if (this.disabled) {
this.style.pointerEvents = 'none';
this.removeAttribute('tabindex');
this.setAttribute('aria-disabled', '');
} else {
this.style.pointerEvents = '';
this.setAttribute('tabindex', 0);
this.removeAttribute('aria-disabled');
}
},
_downAction: function() {
this.pressed = true;
if (this.toggle) {
this.active = !this.active;
} else {
this.active = true;
}
},
// Pulling up the context menu for an item should focus it; but we need to
// be careful about how we deal with down/up events surrounding context
// menus. The up event typically does not fire until the context menu
// closes: so we focus immediately.
//
// This fires _after_ downAction.
_contextMenuAction: function(e) {
// Note that upAction may fire _again_ on the actual up event.
this._upAction(e);
this._focusAction();
},
_upAction: function() {
this.pressed = false;
if (!this.toggle) {
this.active = false;
}
},
_focusAction: function() {
if (!this.pressed) {
// Only render the "focused" state if the element gains focus due to
// keyboard navigation.
this.focused = true;
}
},
_blurAction: function() {
this.focused = false;
}
}

View File

@@ -0,0 +1,109 @@
<!doctype html>
<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<title>core-focusable</title>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link href="core-focusable.html" rel="import">
<style shim-shadowdom>
body {
font-family: RobotoDraft, 'Helvetica Neue', Helvetica, Arial;
font-size: 14px;
margin: 0;
padding: 24px;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-touch-callout: none;
}
section {
padding: 20px 0;
}
section > div {
padding: 14px;
font-size: 16px;
}
focusable-button {
display: inline-block;
padding: 0.5em 1em;
border-radius: 3px;
outline: none;
}
focusable-button[disabled] {
background: #e0e0e0;
}
focusable-button[active] {
background: #000;
color: #fff;
}
focusable-button[pressed] {
background: #ffb74d;
color: #000;
}
focusable-button[focused] {
border: 1px solid #4fc3f7;
}
</style>
</head>
<body unresolved>
<polymer-element name="focusable-button" tabindex="0">
<script>
(function() {
var p = {
eventDelegates: {
down: 'downAction',
up: 'upAction'
},
downAction: function() {
// call overriden event delegate
this._downAction();
console.log('down');
},
upAction: function() {
// call overriden event delegate
this._upAction();
console.log('up');
}
};
Polymer.mixin2(p, Polymer.CoreFocusable);
Polymer(p);
})();
</script>
</polymer-element>
<section>
<focusable-button>button</focusable-button>
<focusable-button toggle>toggle</focusable-button>
<focusable-button disabled>disabled</focusable-button>
</section>
</body>
</html>

View File

@@ -0,0 +1,35 @@
Polymer.mixin2 = function(prototype, mixin) {
// adds a single mixin to prototype
if (mixin.mixinPublish) {
prototype.publish = prototype.publish || {};
Polymer.mixin(prototype.publish, mixin.mixinPublish);
}
if (mixin.mixinDelegates) {
prototype.eventDelegates = prototype.eventDelegates || {};
for (var e in mixin.mixinDelegates) {
if (!prototype.eventDelegates[e]) {
prototype.eventDelegates[e] = mixin.mixinDelegates[e];
}
}
}
if (mixin.mixinObserve) {
prototype.observe = prototype.observe || {};
for (var o in mixin.mixinObserve) {
if (!prototype.observe[o] && !prototype[o + 'Changed']) {
prototype.observe[o] = mixin.mixinObserve[o];
}
}
}
Polymer.mixin(prototype, mixin);
delete prototype.mixinPublish;
delete prototype.mixinDelegates;
delete prototype.mixinObserve;
return prototype;
};