2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10 <link rel=
"import" href=
"../polymer/polymer.html">
12 <polymer-element name=
"core-slide" attributes=
"open closed vertical target targetId">
26 Polymer('core-slide', {
35 this.setAttribute('nolayout', '');
38 attached: function() {
39 this.target
= this.parentNode
;
42 targetIdChanged: function() {
43 var p
= this.parentNode
;
44 while (p
.parentNode
) {p
= p
.parentNode
;};
45 this.target
= p
.querySelector('#' + this.targetId
);
48 targetChanged: function() {
50 this.asyncMethod(this.update
);
55 this.open
= !this.open
;
58 closedChanged: function() {
59 this.open
= !this.closed
;
62 openChanged: function() {
63 this.asyncMethod(this.update
);
67 this.closed
= !this.open
;
70 if (this.target
.style
.top
!== '') {
76 if (this.target
.style
.left
!== '') {
85 updateLeft: function() {
86 var w
= this.target
.offsetWidth
;
87 var l
= this.open
? 0 : -w
;
88 this.target
.style
.left
= l
+ 'px';
89 var s
= this.target
.nextElementSibling
;
91 if (!s
.hasAttribute('nolayout')) {
92 if (s
.style
.left
=== '' && s
.style
.right
!== '') {
96 s
.style
.left
= l
+ 'px';
99 s
= s
.nextElementSibling
;
103 updateRight: function() {
104 var w
= this.target
.offsetWidth
;
105 var r
= this.open
? 0 : -w
;
106 this.target
.style
.right
= r
+ 'px';
107 //var s = this.target.previousElementSibling;
108 var s
= previousElementSibling(this.target
);
110 if (!s
.hasAttribute('nolayout')) {
111 if (s
.style
.right
=== '' && s
.style
.left
!== '') {
115 s
.style
.right
= r
+ 'px';
118 //if (s == s.previousElementSibling) {
119 // console.error(s.localName + ' is its own sibling', s);
122 //s = s.previousElementSibling;
123 s
= previousElementSibling(s
);
127 updateTop: function() {
128 var h
= this.target
.offsetHeight
;
129 var t
= this.open
? 0 : -h
;
130 this.target
.style
.top
= t
+ 'px';
131 var s
= this.target
.nextElementSibling
;
133 if (!s
.hasAttribute('nolayout')) {
134 if (s
.style
.top
=== '' && s
.style
.bottom
!== '') {
138 s
.style
.top
= t
+ 'px';
141 s
= s
.nextElementSibling
;
145 updateBottom: function() {
146 var h
= this.target
.offsetHeight
;
147 var b
= this.open
? 0 : -h
;
148 this.target
.style
.bottom
= b
+ 'px';
149 //var s = this.target.previousElementSibling;
150 var s
= previousElementSibling(this.target
);
152 if (!s
.hasAttribute('nolayout')) {
153 if (s
.style
.bottom
=== '' && s
.style
.top
!== '') {
157 s
.style
.bottom
= b
+ 'px';
160 //if (s == s.previousElementSibling) {
161 // console.error(s.localName + ' is its own sibling', s);
164 //s = s.previousElementSibling;
165 s
= previousElementSibling(s
);
171 // TODO(sjmiles): temporary workaround for b0rked property in ShadowDOMPolyfill
172 function previousElementSibling(e
) {
174 e
= e
.previousSibling
;
175 } while (e
&& e
.nodeType
!== Node
.ELEMENT_NODE
);