This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unresolved attribute available as a feature of platform. With native …
…imports, this should be able to be removed. It’s needed because HTMLImports does not properly polyfill loading imports before paint.
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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. | ||
*/ | ||
(function(scope) { | ||
/* | ||
Shim :unresolved via an attribute unresolved. | ||
TODO(sorvell): This is currently done once when the first | ||
round of elements are upgraded. This is incorrect, and it will | ||
need to be done dynamically. | ||
The 'resolved' attribute is experimental and may be removed. | ||
*/ | ||
var TRANSITION_TIME = 0.2; | ||
var UNRESOLVED = 'unresolved'; | ||
var RESOLVED = 'resolved'; | ||
var UNRESOLVED_SELECTOR = '[' + UNRESOLVED + ']'; | ||
var RESOLVED_SELECTOR = '[' + RESOLVED + ']'; | ||
var style = document.createElement('style'); | ||
|
||
style.textContent = UNRESOLVED_SELECTOR + ' { ' + | ||
'opacity: 0; display: block; overflow: hidden; } \n' + | ||
RESOLVED_SELECTOR + '{ display: block; overflow: hidden;\n' + | ||
'-webkit-transition: opacity ' + TRANSITION_TIME + 's; ' + | ||
'transition: opacity ' + TRANSITION_TIME +'s; }\n'; | ||
var head = document.querySelector('head'); | ||
head.insertBefore(style, head.firstChild); | ||
|
||
// remove unresolved and apply resolved class | ||
function resolveElements() { | ||
requestAnimationFrame(function() { | ||
var nodes = document.querySelectorAll(UNRESOLVED_SELECTOR); | ||
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) { | ||
n.removeAttribute(UNRESOLVED); | ||
n.setAttribute(RESOLVED, ''); | ||
} | ||
|
||
// NOTE: depends on transition end event to remove 'resolved' class. | ||
if (nodes.length) { | ||
var removeResolved = function() { | ||
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) { | ||
n.removeAttribute(RESOLVED); | ||
} | ||
document.body.removeEventListener(endEvent, removeResolved, false); | ||
} | ||
document.body.addEventListener(endEvent, removeResolved, false); | ||
}; | ||
|
||
}); | ||
} | ||
|
||
// determine transition end event | ||
var endEvent = (document.documentElement.style.webkitTransition !== undefined) ? | ||
'webkitTransitionEnd' : 'transitionend'; | ||
|
||
// hookup auto-unveiling | ||
window.addEventListener('WebComponentsReady', resolveElements); | ||
|
||
})(Platform); |