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

Commit d920b2b

Browse files
committed
Merge pull request #21 from Polymer/master
8/15 master -> stable
2 parents 9fae831 + 73b51e4 commit d920b2b

37 files changed

Lines changed: 446 additions & 349 deletions

polymer-ajax/polymer-ajax.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
* @type Object
9090
* @default null
9191
*/
92-
ready: function() {
92+
created: function() {
9393
this.xhr = document.createElement('polymer-xhr');
9494
},
9595
response: '',

polymer-anchor-point/index.html

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>polymer-anchor-point</title>
5+
<link rel="import" href="../../polymer-ui-elements/polymer-ui-icon-button/polymer-ui-icon-button.html">
6+
<link rel="import" href="../../polymer-ui-elements/polymer-ui-toolbar/polymer-ui-toolbar.html">
7+
<link rel="import" href="polymer-anchor-point.html">
8+
<script src="../../polymer/polymer.js"></script>
9+
<link rel="stylesheet" href="../../polymer-ui-elements/basic.css">
10+
<style>
11+
html, body {
12+
margin: 0;
13+
padding: 0;
14+
}
15+
html, body, #container {
16+
height: 100%;
17+
}
18+
#target {
19+
padding: 5px;
20+
border: 1px solid black;
21+
display: none;
22+
position: absolute;
23+
left: -99999px;
24+
}
25+
#target.active {
26+
display: block;
27+
}
28+
</style>
29+
</head>
30+
<body class="polymer-ui-body-text">
31+
<div id="container">
32+
<polymer-flex-layout vertical="true"></polymer-flex-layout>
33+
<polymer-ui-toolbar theme="polymer-ui-light-theme" onclick="toggle(event)">
34+
<polymer-ui-icon-button icon="menu" anchor-point="bottom left" target-anchor-point="top left"></polymer-ui-icon-button>
35+
<div flex></div>
36+
<polymer-ui-icon-button icon="refresh" anchor-point="bottom center" target-anchor-point="top center"></polymer-ui-icon-button>
37+
<div flex></div>
38+
<polymer-ui-icon-button icon="add" anchor-point="bottom right" target-anchor-point="top right"></polymer-ui-icon-button>
39+
</polymer-ui-toolbar>
40+
<div flex></div>
41+
<div style="text-align:center">
42+
<p><strong>Click icon buttons in the toolbars or enter custom <a href="http://dev.w3.org/csswg/css-backgrounds/#the-background-position" target="_blank">anchor-points</a> below.</strong></p>
43+
<br>
44+
anchor-point: <input id="customAnchorPt" value="bottom">
45+
target anchor-point: <input id="customTargetAnchorPt" value="center -10px">
46+
<br><br>
47+
Click <polymer-ui-icon-button icon="settings" onclick="toggleCustom(event)"></polymer-ui-icon-button> for custom
48+
</div>
49+
<div flex></div>
50+
<polymer-ui-toolbar theme="polymer-ui-light-theme" onclick="toggle(event)">
51+
<polymer-ui-icon-button icon="drawer" anchor-point="top left" target-anchor-point="bottom left"></polymer-ui-icon-button>
52+
<polymer-ui-icon-button icon="dots" anchor-point="top center" target-anchor-point="bottom center"></polymer-ui-icon-button>
53+
<div flex></div>
54+
<polymer-ui-icon-button icon="search" anchor-point="top right" target-anchor-point="bottom right"></polymer-ui-icon-button>
55+
</polymer-ui-toolbar>
56+
</div>
57+
<div id="target" onclick="toggle(event)"></div>
58+
<polymer-anchor-point id="anchorable"></polymer-anchor-point>
59+
<script>
60+
function toggle(e) {
61+
var anchorable = document.querySelector('#anchorable');
62+
var target = document.querySelector('#target');
63+
var anchor = e.target;
64+
if (target.classList.contains('active')) {
65+
target.classList.remove('active');
66+
} else {
67+
var targetAnchorPt = anchor.getAttribute('target-anchor-point');
68+
target.setAttribute('anchor-point', targetAnchorPt);
69+
target.innerHTML = 'anchor-point: ' + anchor.getAttribute('anchor-point') + '<br>' + 'target anchor-point: ' + targetAnchorPt;
70+
anchorable.target = target;
71+
anchorable.anchor = anchor;
72+
target.classList.add('active');
73+
anchorable.apply();
74+
}
75+
};
76+
function toggleCustom(e) {
77+
var anchorable = document.querySelector('#anchorable');
78+
var target = document.querySelector('#target');
79+
var anchor = e.target;
80+
if (target.classList.contains('active')) {
81+
target.classList.remove('active');
82+
} else {
83+
var anchorPt = document.querySelector('#customAnchorPt').value;
84+
anchor.setAttribute('anchor-point', anchorPt);
85+
var targetAnchorPt = document.querySelector('#customTargetAnchorPt').value;
86+
target.setAttribute('anchor-point', targetAnchorPt);
87+
target.innerHTML = 'anchor-point: ' + anchorPt + '<br>' + 'target anchor-point: ' + targetAnchorPt;
88+
anchorable.target = target;
89+
anchorable.anchor = anchor;
90+
target.classList.add('active');
91+
anchorable.apply();
92+
}
93+
}
94+
</script>
95+
</body>
96+
</html>
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<!--
2+
/**
3+
* @module Polymer Elements
4+
*/
5+
/**
6+
* polymer-anchor-point can be used to align two nodes. The node to
7+
* use as the reference position is the anchor node, and the node to
8+
* be positioned is the target node.
9+
*
10+
* Both the anchor and target nodes should have an anchor-point
11+
* attribute. The target node is positioned such that its anchor-point
12+
* aligns with the anchor node's anchor-point.
13+
*
14+
* Note: The target node is positioned with position: fixed, and will not
15+
* scroll with the page.
16+
*
17+
* Note: This is meant to polyfill the <dialog> positioning behavior when
18+
* an anchor is provided. Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#the-dialog-element
19+
*
20+
* Example:
21+
*
22+
* <div id="anchor" anchor-point="bottom left"></div>
23+
* <div id="target" anchor-point="top left"></div>
24+
* <polymer-anchor-point id="anchor-helper"></polymer-anchor-point>
25+
* <script>
26+
* var helper = document.querySelector('#anchor-helper');
27+
* helper.anchor = document.querySelector('#anchor');
28+
* helper.target = document.querySelector('#target');
29+
* helper.apply();
30+
* </script>
31+
*
32+
* @class polymer-anchor-point
33+
*/
34+
-->
35+
<polymer-element name="polymer-anchor-point" attributes="target anchor">
36+
<script>
37+
(function() {
38+
var DEFAULT_ANCHOR_POINT = 'center center';
39+
40+
function getAnchorPoint(node) {
41+
var anchorPt = node.getAttribute('anchor-point');
42+
if (!anchorPt || anchorPt === 'none') {
43+
anchorPt = DEFAULT_ANCHOR_POINT;
44+
}
45+
return anchorPt;
46+
};
47+
48+
function lengthIsPx(length) {
49+
return length.slice(-2) === 'px';
50+
};
51+
52+
function lengthIsPercent(length) {
53+
return length.slice(-1) === '%';
54+
};
55+
56+
function computeLength(length, ref) {
57+
var computed = 0;
58+
if (lengthIsPx(length)) {
59+
computed = length.slice(0, -2);
60+
} else if (lengthIsPercent(length)) {
61+
computed = ref * length.slice(0, -1) / 100;
62+
}
63+
return computed;
64+
};
65+
66+
function partIsX(part) {
67+
return part === 'left' || part === 'right' || part === 'center';
68+
};
69+
70+
function partIsY(part) {
71+
return part === 'top' || part === 'bottom' || part === 'center';
72+
};
73+
74+
function partIsKeyword(part) {
75+
return part.slice(-1) !== '%' && part.slice(-2) !== 'px';
76+
};
77+
78+
function parsePosition(position) {
79+
var parsed = {};
80+
var parts = position.split(' ');
81+
var i = 0;
82+
var lastEdgeX = true;
83+
do {
84+
if (partIsX(parts[i])) {
85+
parsed.x = parts[i];
86+
lastEdgeX = parts[i] !== 'center';
87+
} else if (partIsY(parts[i])) {
88+
parsed.y = parts[i];
89+
lastEdgeX = false;
90+
} else if (lastEdgeX) {
91+
parsed.xOffset = parts[i];
92+
lastEdgeX = false;
93+
} else {
94+
parsed.yOffset = parts[i];
95+
}
96+
} while (++i < parts.length);
97+
return parsed;
98+
};
99+
100+
function computeAnchorOffset(rect, anchorPt) {
101+
var offset = {
102+
left: 0,
103+
top: 0
104+
};
105+
var parsed = parsePosition(anchorPt);
106+
if (!parsed.x && !parsed.xOffset) {
107+
offset.left = rect.width / 2;
108+
} else if (parsed.x && !parsed.xOffset) {
109+
switch (parsed.x) {
110+
case 'left':
111+
offset.left = 0;
112+
break;
113+
case 'right':
114+
offset.left = rect.width;
115+
break;
116+
case 'center':
117+
offset.left = rect.width / 2;
118+
break;
119+
}
120+
} else {
121+
var computed = computeLength(parsed.xOffset, rect.width);
122+
if (parsed.x === 'right') {
123+
offset.left = rect.width - computed;
124+
} else if (!parsed.x || parsed.x === 'left') {
125+
offset.left = computed;
126+
}
127+
}
128+
if (!parsed.y && !parsed.yOffset) {
129+
offset.top = rect.height / 2;
130+
} else if (parsed.y && !parsed.yOffset) {
131+
switch (parsed.y) {
132+
case 'top':
133+
offset.top = 0;
134+
break;
135+
case 'bottom':
136+
offset.top = rect.height;
137+
break;
138+
case 'center':
139+
offset.top = rect.height / 2;
140+
break;
141+
}
142+
} else {
143+
var computed = computeLength(parsed.yOffset, rect.height);
144+
if (parsed.y === 'bottom') {
145+
offset.top = rect.height - computed;
146+
} else if (!parsed.y || parsed.y === 'top') {
147+
offset.top = computed;
148+
}
149+
}
150+
return offset;
151+
};
152+
153+
Polymer('polymer-anchor-point', {
154+
/**
155+
* The node to be positioned.
156+
* @attribute target
157+
* @type Node
158+
*/
159+
target: null,
160+
/**
161+
* The node to align the target to.
162+
* @attribute anchor
163+
* @type node
164+
*/
165+
anchor: null,
166+
canPosition: function() {
167+
return this.target && this.anchor;
168+
},
169+
apply: function() {
170+
if (!this.canPosition()) {
171+
return;
172+
}
173+
var pos = this.computePosition();
174+
this.target.style.position = 'fixed';
175+
this.target.style.top = pos.top + 'px';
176+
this.target.style.left = pos.left + 'px';
177+
},
178+
computePosition: function() {
179+
var rect = this.anchor.getBoundingClientRect();
180+
var anchorPt = getAnchorPoint(this.anchor);
181+
var anchorOffset = computeAnchorOffset(rect, anchorPt);
182+
var targetRect = this.target.getBoundingClientRect();
183+
var targetAnchorPt = getAnchorPoint(this.target);
184+
var targetOffset = computeAnchorOffset(targetRect, targetAnchorPt);
185+
var pos = {
186+
left: rect.left + anchorOffset.left - targetOffset.left,
187+
top: rect.top + anchorOffset.top - targetOffset.top
188+
};
189+
return pos;
190+
}
191+
});
192+
})();
193+
</script>
194+
</polymer-element>

polymer-animation/polymer-animation-group.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
type: 'par'
3434
},
35-
ready: function() {
35+
created: function() {
3636
// TODO: need to do this for now.
3737
this.super();
3838
},

polymer-animation/polymer-animation.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if (p) {
1414
target = p.querySelector(inSelector);
1515
}
16-
if (!target && p.host) {
16+
if (!target && p && p.host) {
1717
target = findTarget(inSelector, p.host);
1818
}
1919
return target;
@@ -133,7 +133,7 @@
133133
autoplay: false
134134
},
135135
animation: false,
136-
ready: function() {
136+
created: function() {
137137
this.asyncApply();
138138
},
139139
/**

polymer-animation/polymer-bounce.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
targetSelector: '',
66
duration: 1,
77
magnitude: '-30px',
8-
ready: function() {
8+
created: function() {
99
this.super();
1010
this.magnitudeChanged();
1111
},

polymer-animation/polymer-flip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
duration: 0.5,
88
axis: 'x',
99
},
10-
ready: function() {
10+
created: function() {
1111
this.generate();
1212
},
1313
axisChanged: function() {

polymer-animation/polymer-shake.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
magnitude: '10px',
4646
period: 0.1,
4747
easing: 'ease-in',
48-
ready: function() {
48+
created: function() {
4949
this.super();
5050
this.magnitudeChanged();
5151
this.periodChanged();

polymer-collapse/polymer-collapse.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @class polymer-collapse
3030
*/
3131
-->
32-
<polymer-element name="polymer-collapse" attributes="targetId target horizontal closed duration fixedSize defaultClosed">
32+
<polymer-element name="polymer-collapse" attributes="targetId target horizontal closed duration fixedSize">
3333
<template>
3434
<style>
3535
@host {
@@ -93,7 +93,6 @@
9393
*/
9494
fixedSize: false,
9595
size: null,
96-
defaultClosed: false,
9796
removed: function() {
9897
this.removeListeners(this.target);
9998
},
@@ -113,9 +112,7 @@
113112
this.target.style.overflow = 'hidden';
114113
this.addListeners(this.target);
115114
}
116-
if (this.closed || this.defaultClosed) {
117-
this.update();
118-
}
115+
this.update();
119116
},
120117
addListeners: function(node) {
121118
this.transitionEndListener = this.transitionEndListener ||

polymer-cookie/polymer-cookie.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
var cookieProps = ['expires', 'secure', 'max-age', 'domain', 'path'];
1717
Polymer('polymer-cookie', {
1818
expires: FOREVER,
19-
ready: function() {
19+
created: function() {
2020
this.load();
2121
},
2222
parseCookie: function() {

0 commit comments

Comments
 (0)