Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/866fb641-5c8f-47bd-ba78-94588daa606b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/984a43f9-d22e-401b-925c-78b3477795d2%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CACGqRCBc5iedqJ0G6%3D%3DivQGW5SQ3PGjEOYQKLULVgY3mq60KoA%40mail.gmail.com.
Simply place any scripts that manipulate Polymer elements at the end of the page, and all elements should be read
If you are not using the web components polyfills (for example, in a Chrome extension), the WebComponentsReady event will not fire. With native HTML imports and custom elements, elements upgrade synchronously, so the event is not required. Simply place any scripts that manipulate Polymer elements at the end of the page, and all elements should be ready.
function makeGlobalElements() { //elements is not routing list, routing list is elementList panel = document.querySelector('paper-header-panel[main]'); rippleElement = document.getElementById('ripple-element'); toolbar = document.querySelector('#main-toolbar'); headerName = document.getElementById('name-title'); drawer = document.querySelector('paper-drawer-panel'); mainPanelContent = document.getElementById('mainPanelContent');};
function attatchListeners() { panel.addEventListener("content-scroll", moveTitle); ['webkitAnimationEnd', 'animationend'] .forEach(function(vendor) { mainPanelContent.addEventListener(vendor, function (animationEvent) { if (animationEvent.animationName === "slide-down") { afterSlideDown.runStack(); mainPanelContent.classList.remove('slide-down-now'); } }); headerName.addEventListener(vendor, function() { headerName.classList.remove('fade-title'); }); });};
function initializeYay() { makeGlobalElements(); setTimeout(attatchListeners, 500); setUpRoutes();
removeSplash(); //fetchPdfjs();}
if (!webComponentsSupported) { document.addEventListener('WebComponentsReady', initializeYay);} else { initializeYay(); page('/portfolio');}
You can attach listeners to elements before they're upgraded and ready. That's a nice property of custom elements and DOM events. Waiting to attach until WCR means you may miss the event the first time it's fired.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/13dcb312-f0a9-44d5-bf55-29be4cd38441%40googlegroups.com.
function makeGlobalElements() {
//elements is not routing list, routing list is elementList
panel = Polymer.dom(parent).querySelector('paper-header-panel[main]');
rippleElement = Polymer.dom(parent).querySelector('#ripple-element');
toolbar = Polymer.dom(parent).querySelector('#main-toolbar');
headerName = Polymer.dom(parent).querySelector('#name-title');
drawer = Polymer.dom(parent).querySelector('paper-drawer-panel');
mainPanelContent = Polymer.dom(parent).querySelector('#mainPanelContent');
};
function attatchListeners() {
panel.addEventListener("content-scroll", moveTitle);
['webkitAnimationEnd', 'animationend']
.forEach(function(vendor) {
mainPanelContent.addEventListener(vendor, function (animationEvent) {
if (animationEvent.animationName === "slide-down") {
afterSlideDown.runStack();
mainPanelContent.classList.remove('slide-down-now');
}
});
headerName.addEventListener(vendor, function() {
headerName.classList.remove('fade-title');
});
});
};
function initializeYay() {
makeGlobalElements();
attatchListeners;
function makeGlobalElements() {
//elements is not routing list, routing list is elementList
panel = Polymer.dom(document.rootElement).querySelector('paper-header-panel[main]');
rippleElement = Polymer.dom(document.rootElement).querySelector('#ripple-element');
toolbar = Polymer.dom(document.rootElement).querySelector('#main-toolbar');
headerName = Polymer.dom(document.rootElement).querySelector('#name-title');
drawer = Polymer.dom(document.rootElement).querySelector('paper-drawer-panel');
mainPanelContent = Polymer.dom(document.rootElement).querySelector('#mainPanelContent');
};
function attatchListeners() {
panel.addEventListener("content-scroll", moveTitle);
....
function initializeYay() { makeGlobalElements(); attatchListeners(); setUpRoutes(); removeSplash(); //fetchPdfjs();}
if (!webComponentsSupported) {
document.addEventListener('WebComponentsReady', initializeYay);
} else {
initializeYay();
page('/portfolio');
}
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/ecbf652f-4130-4118-8a29-30de8c98ff24%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/25ca6f26-e689-4829-9dbd-5a87c2c129dc%40googlegroups.com.
Just thought I'd mention this article on promises...it mentions their use for synchronous stuff too (mixing them), so thought it might be of interest :
<http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html?utm_source=javascriptweekly&utm_medium=email>
Max.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/144ec899-6d1d-4d8b-93f3-b9485115aaf0%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/5a003271-104f-4c23-9440-124ba4565997%40googlegroups.com.
function makeGlobalElements() { var noNameFoo = new Promise(function(resolve, reject) {
//elements is not routing list, routing list is elementList
function _createElements() {
panel = document.querySelector('paper-header-panel[main]');
rippleElement = document.querySelector('#ripple-element');
toolbar = document.querySelector('#main-toolbar');
headerName = document.querySelector('#name-title');
drawer = document.querySelector('paper-drawer-panel');
mainPanelContent = document.querySelector('#mainPanelContent'); }
var iteration = 1; var completed = false;
function _checkElements() { var elements = [panel, rippleElement, toolbar, headerName, drawer, mainPanelContent];
completed = elements.every(function(el) { if (el !== null && typeof el !== 'undefined' && el.nodeType === 1) { return true; } else { return false; } }); }
var NUMBER_CHECKS = 100; do { _createElements(); _checkElements(); iteration++; if (!completed) { console.log(iteration); console.log(iteration < NUMBER_CHECKS && completed); console.log('Elements weren\'t ready, running again'); console.log('Trying attempt # ' + iteration); } else { console.log('yay! elements good'); resolve(); } } while(iteration < NUMBER_CHECKS && !completed); }); return noNameFoo;
};
function attatchListeners() { panel.addEventListener("content-scroll", moveTitle); ['webkitAnimationEnd', 'animationend'] .forEach(function(vendor) { mainPanelContent.addEventListener(vendor, function (animationEvent) { if (animationEvent.animationName === "slide-down") { afterSlideDown.runStack(); mainPanelContent.classList.remove('slide-down-now'); } }); headerName.addEventListener(vendor, function() { headerName.classList.remove('fade-title'); }); });};
//polymer bug where elements aren't ready in time
function initializeYay() { makeGlobalElements().then(function() {; attatchListeners(); setUpRoutes(); removeSplash(); //fetchPdfjs();