mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
convert property-model, use attributes to flag opening/closing states for CSS, remove showClass, hideClass props, other reductions
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
-->
|
||||
<element name="g-overlay" attributes="showClass, hideClass, showing, timeout">
|
||||
<element name="g-overlay" attributes="showing, timeout">
|
||||
<link rel="components" href="g-component.html">
|
||||
<template>
|
||||
<style scoped>
|
||||
@@ -18,74 +18,56 @@
|
||||
</template>
|
||||
<script>
|
||||
this.component({
|
||||
created: function(inSuper) {
|
||||
this.jobId = "animate-" + Math.random();
|
||||
this._squelchShowingChange = true;
|
||||
this.showingAttributeChanged();
|
||||
shadowRootCreated: function() {
|
||||
this.hidden = true;
|
||||
},
|
||||
prototype: {
|
||||
timeout: 1000,
|
||||
// TODO(sorvell): why is this not an attr-prop?
|
||||
allowAnimation: true,
|
||||
toggleShowing: function() {
|
||||
this.showing = this.showing == "true" ? "false" : "true";
|
||||
showingChanged: function() {
|
||||
this.animateShowing();
|
||||
webkitRequestAnimationFrame(this.fireShowingChange.bind(this));
|
||||
},
|
||||
showingAttributeChanged: function() {
|
||||
if (this.canAnimate()) {
|
||||
this.animateShowing();
|
||||
} else {
|
||||
this[this.showing == "true" ? "removeAttribute" : "setAttribute"]("hidden", "true");
|
||||
}
|
||||
if (this._squelchShowingChange) {
|
||||
this._squelchShowingChange = false;
|
||||
} else {
|
||||
webkitRequestAnimationFrame(this.fireShowingChange.bind(this));
|
||||
}
|
||||
},
|
||||
setShowingDirect: function(inValue) {
|
||||
this._squelchShowingChange = true;
|
||||
this.showing = inValue;
|
||||
dispatch: function(inName, inDetail) {
|
||||
this.dispatchEvent(new CustomEvent(inName, {
|
||||
bubbles: true,
|
||||
detail: inDetail
|
||||
}));
|
||||
},
|
||||
fireShowingChange: function() {
|
||||
var detail = {showing: this.showing == "true", rect: this.getBoundingClientRect()};
|
||||
var event = new CustomEvent("showingChange", {bubbles: true, detail: detail})
|
||||
this.dispatchEvent(event);
|
||||
},
|
||||
canAnimate: function() {
|
||||
return this.allowAnimation && Boolean(this.hideClass || this.showClass);
|
||||
this.dispatch("showingChange", {
|
||||
showing: this.showing,
|
||||
rect: this.getBoundingClientRect()
|
||||
});
|
||||
},
|
||||
animateShowing: function() {
|
||||
this.removeAttribute("hidden");
|
||||
webkitRequestAnimationFrame(this._animateShowing.bind(this));
|
||||
},
|
||||
_animateShowing: function() {
|
||||
if (this.showClass) {
|
||||
this.classList.enable(this.showClass, this.showing == "true");
|
||||
}
|
||||
if (this.hideClass) {
|
||||
this.classList.enable(this.hideClass, this.showing == "false");
|
||||
}
|
||||
this.unlisten();
|
||||
this.listen();
|
||||
this.hidden = false;
|
||||
webkitRequestAnimationFrame(function() {
|
||||
var setBooleanAttribute = function(inNode, inName, inValue) {
|
||||
inNode[inValue ? "setAttribute" : "removeAttribute"](inName, "");
|
||||
};
|
||||
setBooleanAttribute(this, "opening", this.showing);
|
||||
setBooleanAttribute(this, "closing", !this.showing);
|
||||
this.unlisten();
|
||||
this.listen();
|
||||
}.bind(this));
|
||||
},
|
||||
listen: function() {
|
||||
this.animationListener = this.finishAnimate.bind(this);
|
||||
this.addEventListener("webkitAnimationEnd", this.animationListener, false);
|
||||
this.addEventListener("webkitTransitionEnd", this.animationListener, false);
|
||||
this.addEventListener("webkitAnimationEnd", this.animationListener);
|
||||
this.addEventListener("webkitTransitionEnd", this.animationListener);
|
||||
// always finish animation within timeout
|
||||
this.utils.job(this.jobId, this.animationListener, this.timeout);
|
||||
this.jobId = this.utils.job(this.jobId, this.animationListener, this.timeout);
|
||||
},
|
||||
finishAnimate: function() {
|
||||
//console.log("end animate");
|
||||
if (this.showing == "false") {
|
||||
this.setAttribute("hidden", "true");
|
||||
if (!this.showing) {
|
||||
this.hidden = true;
|
||||
this.classList.remove(this.hideClass);
|
||||
}
|
||||
this.unlisten();
|
||||
},
|
||||
unlisten: function() {
|
||||
this.removeEventListener("webkitAnimationEnd", this.animationListener, false);
|
||||
this.removeEventListener("webkitTransitionEnd", this.animationListener, false);
|
||||
this.removeEventListener("webkitAnimationEnd", this.animationListener);
|
||||
this.removeEventListener("webkitTransitionEnd", this.animationListener);
|
||||
this.utils.job.stop(this.jobId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,14 +33,12 @@
|
||||
-webkit-transition: all 0.218s;
|
||||
}
|
||||
|
||||
.dialogShown {
|
||||
/*display: block;*/
|
||||
#dialog[opening] {
|
||||
opacity: 1.0;
|
||||
-webkit-transform: scale(1.0);
|
||||
}
|
||||
|
||||
.dialogHidden {
|
||||
/*display: block;*/
|
||||
#dialog[closing] {
|
||||
opacity: 0;
|
||||
-webkit-transform: translateY(-100%);
|
||||
-webkit-transition: all 1s;
|
||||
@@ -96,13 +94,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
.dialog2Shown {
|
||||
#dialog2[opening] {
|
||||
-webkit-animation-duration: 0.5s;
|
||||
-webkit-animation-fill-mode: both;
|
||||
-webkit-animation-name: shakeFadeIn;
|
||||
}
|
||||
|
||||
.dialog2Hidden {
|
||||
#dialog2[closing] {
|
||||
-webkit-animation-duration: 0.3s;
|
||||
-webkit-animation-fill-mode: both;
|
||||
-webkit-animation-name: shakeFadeOut;
|
||||
@@ -111,8 +109,8 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="toggleDialog()">Toggle Dialog</button>
|
||||
<g-overlay id="dialog" class="dialog" showClass="dialogShown" hideClass="dialogHidden">
|
||||
<button onclick="toggleDialog('#dialog')">Toggle Dialog</button>
|
||||
<g-overlay id="dialog" class="dialog">
|
||||
<h2>Dialog</h2>
|
||||
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fringilla sapien sed enim sollicitudin laoreet. Suspendisse suscipit, metus ac volutpat sodales, libero magna semper lacus, molestie fringilla massa orci ut arcu. Nullam sodales urna sit amet odio vehicula mattis.</div><br><br>
|
||||
<div>Ut aliquam vulputate congue. Vestibulum pretium pretium nulla quis sollicitudin. Praesent lacinia congue erat nec mattis. Fusce commodo lacus est. Duis turpis eros, ultrices sed aliquet non, blandit egestas velit. Integer a augue nec lorem tristique hendrerit. Curabitur imperdiet risus id enim bibendum vestibulum. Integer id magna at arcu faucibus fermentum vel a augue. Sed fringilla venenatis dolor, in blandit magna molestie luctus. Vestibulum dignissim posuere ultrices. Aenean urna nisl, tincidunt vitae iaculis ut, pharetra nec eros.</div><br><br>
|
||||
@@ -120,22 +118,20 @@
|
||||
<g-checkbox></g-checkbox>
|
||||
I agree with this wholeheartedly.
|
||||
</div><br><br>
|
||||
<button onclick="toggleDialog()">OK</button>
|
||||
<button onclick="toggleDialog('#dialog')">OK</button>
|
||||
</g-overlay>
|
||||
<br><br>
|
||||
<button onclick="toggleDialog2()">Toggle Dialog 2</button>
|
||||
<g-overlay id="dialog2" class="dialog" showClass="dialog2Shown" hideClass="dialog2Hidden">
|
||||
<button onclick="toggleDialog('#dialog2')">Toggle Dialog 2</button>
|
||||
<g-overlay id="dialog2" class="dialog" showing="true">
|
||||
<h2>Dialog 2</h2>
|
||||
I'm dizzy.
|
||||
</div><br><br>
|
||||
<button onclick="toggleDialog2()">OK</button>
|
||||
<button onclick="toggleDialog('#dialog2')">OK</button>
|
||||
</g-overlay>
|
||||
<script>
|
||||
toggleDialog = function() {
|
||||
document.querySelector("#dialog").toggleShowing();
|
||||
}
|
||||
toggleDialog2 = function() {
|
||||
document.querySelector("#dialog2").toggleShowing();
|
||||
toggleDialog = function(inSlctr) {
|
||||
var d = document.querySelector(inSlctr);
|
||||
d.showing = !d.showing;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user