polymer core-header-panel scrollIntoView - polymer

I thought I would get lucky and just do window.scrollTo(0,500) but that did not work because the core-header-panel is doing the scrolling for me.
Suppose you have two elements
<core-header-panel>
<core-animated-pages selected="{{s}}">
<section><my-element select={{s}}></my-element></section>
<section><my-element select={{s}}></my-element></section>
</core-animated-pages>
</core-header-panel>
</template>
I see the element I want to scroll to in the console but it does not scroll?
<polymer-element name="my-element" attributes="select">
<template>
....
</template>
<script>
Polymer('my-element', {
select:0,
selectChanged: function(){
var x=this.shadowRoot.querySelector("#id")
if (x){
console.log(x)
x.scrollIntoView()
}
}
});
</script>
</polymer-element>
EDIT:
<polymer-element name="my-element" attributes="select">
<template>
<core-animated-pages fit selected="{{select}}" id="core_page">
....
</core-animated-pages>
</template>
<script>
Polymer('my-element', {
ready: function(){
this.$.core_page.addEventListener("core-animated-pages-transition-end", function(e) {
var x=this.shadowRoot.querySelector("#id")
if (x){
console.log(x)
x.scrollIntoView()
}
})
}
});
</script>
</polymer-element>

Related

Polymer paper-drawer-panel not accepting toggle from child

I have a paper-drawer-panel in one element and a toolbar in a child element. On the toolbar is a menu-button, that should toggle the drawer-panel but it does not. How can I tell the paper-drawer-panel to accept a command from the child element?
Parent-element:
<dom-module id="nav-drawer">
<template>
<paper-drawer-panel drawerFocusSelector="">
<div drawer id="drawerbox">
Contents of drawer panel here.
</div>
<div main>
<tool-bar></tool-bar>
</div>
<paper-drawer-panel>
</template>
</dom-module>
Child element:
<dom-module id="tool-bar">
<template>
<paper-toolbar>
<paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
</paper-toolbar>
</template>
</dom-module>
Thanks for your help. I'm new to Polymer.
I found the answer myself:
The tool-bar element I changed as follows, adding attributes and an on-tap function.
<dom-module id="tool-bar" attributes="togdraw">
<template>
<paper-toolbar>
<paper-icon-button icon="menu" on-tap="toggleDrawer"></paper-icon-button>
</paper-toolbar>
</template>
<script>
.....
toggleDrawer: function() {
this.fire('eventFromChild',{togdraw:"drawer"});
}
....
</script>
</dom-module>
And the nav-drawer I changed like accordingly:
<dom-module id="nav-drawer">
<template>
<paper-drawer-panel drawerFocusSelector="" selected="{{selectPanel}}">
<div drawer id="drawerbox">
Contents of drawer panel here.
</div>
<div main>
<tool-bar></tool-bar>
</div>
<paper-drawer-panel>
</template>
<script>
....
properties: {
selectPanel: String
},
ready: function() {
this.addEventListener('eventFromChild', this.toggleDrawer);
},
toggleDrawer: function(event,selectPanel) {
this.selectPanel = event.detail.togdraw;
return selectPanel;
}
....
</script>
</dom-module>

How to access details of a swiped paper-card in iron-swipeable-container

I have a swipeable-container with a dom-repeat (firebase data)
<iron-swipeable-container id="teamchat">
<template is="dom-repeat" items="[[tcmmessages]]" as="tcmmessage">
<paper-card id="tcmcard" class="swipe item blue" data-index$="[[tcmmessage.__firebaseKey__]]">
<div class="card-content">
<b>[[tcmmessage.teamname]]</b>
<paper-icon-button style="color: red;" on-tap="_startChat" icon="communication:chat"></paper-icon-button><br>
[[tcmmessage.beitrag]]<br>
<span class="chatmetadata">von [[tcmmessage.username]]
• [[tcmmessage.update]] • [[tcmmessage.uptime]] </span>
</div>
</paper-card>
</template>
</iron-swipeable-container>
I defined a listener
listeners: {
'teamchat.iron-swipe': '_onTeamChatSwipe'
},
I try to access data-index from the swiped paper-card.
_onTeamChatSwipe: function() {
var card = this.$$('#tcmcard');
var key = card.getAttribute("data-index");
but after swipe event I can not access data-index of the swiped card.
With this.$$('#tcmcard') in the iron-swipe handler, you're querying the local DOM for the swiped element, but it's removed from the DOM before the iron-swipe event fires, so the query would not return what you'd expect.
But you don't need to query for the swiped element because <iron-swipeable-container> fires the iron-swipe event with the swiped element stored in event.detail.target.
Try this:
_onTeamChatSwipe: function(e) {
var card = e.detail.target;
var key = card.getAttribute("data-index");
// simpler syntax to get `data-index`
// key = card.dataset.index;
}
<head>
<base href="https://polygit.org/polymer+1.4.0/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-card/paper-card.html">
<link rel="import" href="iron-swipeable-container/iron-swipeable-container.html">
<link rel="import" href="iron-flex-layout/iron-flex-layout-classes.html">
</head>
<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<style include="iron-flex">
paper-card {
margin-bottom: 16px;
}
</style>
<template>
<iron-swipeable-container class="container" on-iron-swipe="_onSwipe">
<template is="dom-repeat" items="[[items]]">
<paper-card heading="{{item}}" data-index$="{{index}}" class="layout vertical">
<div class="card-content">
Swipe me left or right
</div>
</paper-card>
</template>
</iron-swipeable-container>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-foo',
properties : {
items: {
type: Array,
value: function() {
return [1,2,3];
}
}
},
_onSwipe: function(e) {
var card = e.detail.target;
console.log(card.getAttribute('data-index'));
// simpler syntax to get 'data-index'
console.log(card.dataset.index);
}
});
});
</script>
</dom-module>
</body>
codepen

How can I "refresh" iron-swipeable-container after a change of data in firebase

My code with swipable-container and dom-repeat of firebase-data
<iron-swipeable-container id="teamchat">
<paper-card class="swipe item blue">
<template is="dom-repeat" items="[[tcmmessages]]" as="tcmmessage">
<div class="card-content">
<b>[[tcmmessage.teamname]]</b><br>
[[tcmmessage.beitrag]]<br>
<span class="chatmetadata">von [[tcmmessage.username]]
• [[tcmmessage.update]] • [[tcmmessage.uptime]] </span>
</div>
</template>
</paper-card>
</iron-swipeable-container>
I have defined a listener
listeners: {
'teamchat.iron-swipe': '_onTeamChatSwipe'
},
and remove the firebase-data with '_onTeamChatSwipe'.
That work fine!
But when there is new firebase-data, how can I bring the iron-swipeable-container back again without refreshing the entire page? I don't find a solution.
It looks like you've created just one paper-card that contains multiple messages. When the card is swiped away, your code has no template to refill the container.
Did you actually mean to create a card for each message? That would require moving paper-card inside the template repeater like this:
<iron-swipeable-container id="teamchat">
<template is="dom-repeat" items="[[tcmmessages]]" as="tcmmessage">
<paper-card class="swipe item blue">
<div class="card-content">
<b>[[tcmmessage.teamname]]</b><br>
[[tcmmessage.beitrag]]<br>
<span class="chatmetadata">von [[tcmmessage.username]]
• [[tcmmessage.update]] • [[tcmmessage.uptime]] </span>
</div>
</paper-card>
</template>
</iron-swipeable-container>
When tcmmessages refills (via Firebase), the iron-swipeable-container automatically repopulates with a paper-card per message.
Here's a demo of similar code that shows that behavior:
<head>
<base href="https://polygit.org/polymer+1.4.0/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-card/paper-card.html">
<link rel="import" href="iron-swipeable-container/iron-swipeable-container.html">
<link rel="import" href="iron-flex-layout/iron-flex-layout-classes.html">
</head>
<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<style include="iron-flex">
paper-card {
margin-bottom: 16px;
}
</style>
<template>
<iron-swipeable-container class="container">
<template is="dom-repeat" items="[[items]]">
<paper-card heading="{{item}}" class="layout vertical">
<div class="card-content">
Swipe me left or right
</div>
</paper-card>
</template>
</iron-swipeable-container>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-foo',
properties : {
items: {
type: Array,
value: function() {
return [1,2,3];
}
}
},
_clearListAfterDelay: function(delay) {
this.async(function() {
this.set('items', []);
}, delay);
},
_refillListAfterDelay: function(delay) {
this.async(function() {
this.push('items', 4);
this.push('items', 5);
}, delay);
},
ready: function() {
this._clearListAfterDelay(1000);
this._refillListAfterDelay(2000);
}
});
});
</script>
</dom-module>
</body>
codepen

polymer 1.0 dom-repeat filter only runs once

When I change the year using the drop-down, I want the list to re-filter and display the info for that chosen year. What am I missing? Changing the year does not re-filter the dom-repeat.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="http://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
<title>dropdown</title>
<link rel="import" href="http://polygit.org/components/paper-menu/paper-menu.html">
<link rel="import" href="http://polygit.org/components/paper-item/paper-item.html">
<link rel="import" href="http://polygit.org/components/paper-button/paper-button.html">
<link rel="import" href="http://polygit.org/components/paper-menu-button/paper-menu-button.html">
<style>
.taller{
height:120px;
}
[vertical-align="top"] ul {
margin-top: 0;
}
[vertical-align="bottom"] ul {
margin-bottom: 0;
}
button, paper-button {
border: 1px solid #ccc;
background-color: #eee;
/*padding: 1em;*/
border-radius: 3px;
cursor: pointer;
}
button:focus {
outline: none;
border-color: blue;
}
</style>
</head>
<body>
<dom-module id="x-demo">
<template>
<div class="horizontal-section flex layout horizontal taller">
<paper-menu-button>
<paper-button icon="menu" class="dropdown-trigger"><span>Year<br/></span><span>{{year}}</span></paper-button>
<paper-menu id="selectedYear" class="dropdown-content" selected="{{selectedIndex}}">
<template is="dom-repeat" items="{{allData}}">
<paper-item on-tap='yearTapped'>{{item.year}}</paper-item>
</template>
</paper-menu>
</paper-menu-button>
<paper-menu-button>
<paper-button icon="menu" class="dropdown-trigger"><span>Make<br/></span><span>{{make}}</span></paper-button>
<paper-menu id="selectedMake" class="dropdown-content" selected="{{selectedIndex}}">
<template is="dom-repeat" items="{{allData}}">
<paper-item on-tap='makeTapped'>{{item.make}}</paper-item>
</template>
</paper-menu>
</paper-menu-button>
<paper-menu-button>
<paper-button icon="menu" class="dropdown-trigger"><span>Model<br/></span><span>{{model}}</span></paper-button>
<paper-menu id="selectedModel" class="dropdown-content" selected="{{selectedIndex}}">
<template is="dom-repeat" items="{{allData}}">
<paper-item on-tap='modelTapped'>{{item.model}}</paper-item>
</template>
</paper-menu>
</paper-menu-button>
<paper-menu-button>
<paper-button icon="menu" class="dropdown-trigger"><span>Engine<br/></span><span>{{engine}}</span></paper-button>
<paper-menu id="selectedEngine" class="dropdown-content" selected="{{selectedIndex}}">
<template is="dom-repeat" items="{{allData}}">
<paper-item on-tap='engineTapped'>{{item.engine}}</paper-item>
</template>
</paper-menu>
</paper-menu-button>
</div>
<div>Vehicle list filtered by selected year: </div>
<template is="dom-repeat" id="vehicleList" items="{{allData}}" filter="yearMatch" observe="year item.year">
<div>Year <span>{{item.year}}</span></div>
<div>Make <span>{{item.make}}</span></div>
<div>Model <span>{{item.model}}</span></div>
<div>Engine <span>{{item.engine}}</span></div>
<button on-click="toggleSelection">Select</button>
</template>
<array-selector id="selector" items="{{allData}}" selected="{{selected}}" multi toggle></array-selector>
<div>Selected vehicle: </div>
<template is="dom-repeat" items="{{selected}}">
<div><span>{{item.year}}</span></div>
<div><span>{{item.make}}</span></div>
<div><span>{{item.model}}</span></div>
<div><span>{{item.engine}}</span></div>
</template>
</template>
<script>
Polymer({
is: 'x-demo',
properties:{
allData:{type:Array,
value: function() {
return [{year:'2015',make:'HONDA',model:'CB300F',engine:'300cc'},
{year:'2014',make:'HONDA',model:'CBR300R',engine:'300cc'}];
}
},
year:{type:String,value:'2014',notify:true}
},
observers: [
'yearChanged(year)'
],
yearChanged: function(item) {
console.log(item);
this.set('item.year', item);
this.$.vehicleList.render();
},
yearMatch: function(item) {
console.log('year checked');
return item.year = this.year;
},
toggleSelection: function(e) {
var item = this.$.vehicleList.itemForElement(e.target);
this.$.selector.select(item);
},
yearTapped: function(e) {
this.year=e.target.innerText;
},
makeTapped: function(e) {
this.make=e.target.innerText;
},
modelTapped: function(e) {
this.model=e.target.innerText;
},
engineTapped: function(e) {
this.engine=e.target.innerText;
}
});
</script>
</dom-module>
<x-demo></x-demo>
</body>
</html>
this works for me
<script>
HTMLImports.whenReady(function () {
Polymer({
is: 'x-demo',
properties:{
allData:{
type:Array,
value: [{
year:'2015',
make:'HONDA',
model:'CB300F',
engine:'300cc'
}, {
year:'2014',
make:'HONDA',
model:'CBR300R',
engine:'300cc'
}]
},
year:{
type:
String,
value:'2014',
observer: 'yearChanged'
}
},
yearChanged: function() {
console.log(this.year)
this.$.vehicleList.render();
},
yearMatch: function(item) {
return item.year == this.year;
},
toggleSelection: function(e) {
var item = this.$.vehicleList.itemForElement(e.target);
this.$.selector.select(item);
},
yearTapped: function(event) {
var res = event.target.innerText || event.target.textContent;
this.year = res.replace(/\s+/g, '');
},
makeTapped: function(event) {
var res = event.target.innerText || event.target.textContent;
this.make = res.replace(/\s+/g, '');
},
modelTapped: function(event) {
var res = event.target.innerText || event.target.textContent;
this.model = res.replace(/\s+/g, '');
},
engineTapped: function(event) {
var res = event.target.innerText || event.target.textContent;
this.engine = res.replace(/\s+/g, '');
}
});
});

access polymer elements attribute, inside of a polymer attribute

I am trying to access the attribute of an polymer element inside of an other polymer element
So, when the flatter-navbar-toggle is clicked I want the flatter-navbar to know so I can change some styling based on the attribute.
<link rel="import" href="../../bower_components/polymer/polymer.html">
<polymer-element name="flatter-navbar-toggle" on-click="{{ toggle }}" attributes="toggled">
<template>
<link rel="stylesheet" href="flatter-navbar-toggle.css"/>
<div>
<span></span>
<span></span>
<span></span>
</div>
</template>
<script>
Polymer('flatter-navbar-toggle', {
toggled: false,
toggle: function () {
this.toggled = this.toggled === true ? false : true;
}
})
</script>
</polymer-element>
<polymer-element name="flatter-navbar">
<template>
<flatter-navbar-toggle id="flatterNavbarToggle">
</flatter-navbar-toggle>
<div id="flatterNavbarBody">
<content>
</content>
</div>
</template>
<script>
Polymer('flatter-navbar', {
toggledChanged: function () {
if (this.$.flatterNavbarToggle.toggled) {
this.$.flatterNavbarBody.style.display = 'block';
} else {
this.$.flatterNavbarBody.style.display = 'none';
}
}
})
</script>
</polymer-element>
You can bind to the flatter-navbar to the flatter-navbar-toggle toggle attribute like this.
<polymer-element name="flatter-navbar" noscript>
<template>
<flatter-navbar-toggle toggled="{{toggled}}"></flatter-navbar-toggle>
<template if="{{toggled}}">
<div><content></content></div>
</template>
</template>
</polymer-element>
jsbin example here http://jsbin.com/pusoj/1