-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from sjmiles/master
various changes to enable g-overlay
- Loading branch information
Showing
3 changed files
with
328 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!-- | ||
/* | ||
* Copyright 2012 The Toolkitchen Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
--> | ||
<element name="g-overlay" attributes="showClass, hideClass, showing, timeout"> | ||
<link rel="components" href="g-component.html"> | ||
<template> | ||
<style scoped> | ||
@host { | ||
position: absolute; | ||
z-index: 10; | ||
} | ||
</style> | ||
<content></content> | ||
</template> | ||
<script> | ||
this.component({ | ||
created: function(inSuper) { | ||
this.jobId = "animate-" + Math.random(); | ||
this._squelchShowingChange = true; | ||
this.showingAttributeChanged(); | ||
}, | ||
prototype: { | ||
timeout: 1000, | ||
// TODO(sorvell): why is this not an attr-prop? | ||
allowAnimation: true, | ||
toggleShowing: function() { | ||
this.showing = this.showing == "true" ? "false" : "true"; | ||
}, | ||
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; | ||
}, | ||
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); | ||
}, | ||
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(); | ||
}, | ||
listen: function() { | ||
this.animationListener = this.finishAnimate.bind(this); | ||
this.addEventListener("webkitAnimationEnd", this.animationListener, false); | ||
this.addEventListener("webkitTransitionEnd", this.animationListener, false); | ||
// always finish animation within timeout | ||
this.utils.job(this.jobId, this.animationListener, this.timeout); | ||
}, | ||
finishAnimate: function() { | ||
//console.log("end animate"); | ||
if (this.showing == "false") { | ||
this.setAttribute("hidden", "true"); | ||
this.classList.remove(this.hideClass); | ||
} | ||
this.unlisten(); | ||
}, | ||
unlisten: function() { | ||
this.removeEventListener("webkitAnimationEnd", this.animationListener, false); | ||
this.removeEventListener("webkitTransitionEnd", this.animationListener, false); | ||
this.utils.job.stop(this.jobId); | ||
} | ||
} | ||
}); | ||
</script> | ||
</element> |
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,142 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Overlay</title> | ||
<script src="../../polyfills/Components/components-polyfill.js" shimShadow></script> | ||
<link rel="components" href="../../toolkit/src/g-overlay.html"> | ||
<style> | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
margin: 20px; | ||
-webkit-user-select: none; | ||
font-size: 13px; | ||
} | ||
|
||
.dialog { | ||
box-shadow: 0 4px 16px rgba(0,0,0,0.2); | ||
background: white; | ||
left: 50%; | ||
outline: 1px solid rgba(0,0,0,0.2); | ||
padding:30px 42px; | ||
position: fixed; | ||
right: auto; | ||
width: 512px; | ||
height: auto; | ||
overflow: hidden; | ||
z-index: 100; | ||
top: 72px; | ||
margin-left: -256px; | ||
|
||
/*display: none;*/ | ||
opacity: 0.0; | ||
-webkit-transform: scale(1.05); | ||
-webkit-transition: all 0.218s; | ||
} | ||
|
||
.dialogShown { | ||
/*display: block;*/ | ||
opacity: 1.0; | ||
-webkit-transform: scale(1.0); | ||
} | ||
|
||
.dialogHidden { | ||
/*display: block;*/ | ||
opacity: 0; | ||
-webkit-transform: translateY(-100%); | ||
-webkit-transition: all 1s; | ||
} | ||
|
||
@-webkit-keyframes shakeFadeIn { | ||
0% { | ||
display: block; | ||
opacity: 0; | ||
-webkit-transform: translateX(0); | ||
} | ||
10% { | ||
display: block; | ||
-webkit-transform: translateX(-50px); | ||
} | ||
30% { | ||
display: block; | ||
-webkit-transform: translateX(50px); | ||
} | ||
50% { | ||
display: block; | ||
-webkit-transform: translateX(-25px); | ||
} | ||
70% { | ||
display: block; | ||
-webkit-transform: translateX(25px); | ||
} | ||
90% { | ||
display: block; | ||
-webkit-transform: translateX(-13px); | ||
} | ||
100% { | ||
display: block; | ||
-webkit-transform: translateX(0); | ||
opacity: 1; | ||
} | ||
} | ||
|
||
@-webkit-keyframes shakeFadeOut { | ||
0% { | ||
opacity: 1; | ||
-webkit-transform: translateX(0); | ||
} | ||
10% { | ||
-webkit-transform: translateX(-50px); | ||
} | ||
30% { | ||
-webkit-transform: translateX(50px); | ||
} | ||
100% { | ||
-webkit-transform: translateX(-100%); | ||
opacity: 0; | ||
} | ||
} | ||
|
||
.dialog2Shown { | ||
-webkit-animation-duration: 0.5s; | ||
-webkit-animation-fill-mode: both; | ||
-webkit-animation-name: shakeFadeIn; | ||
} | ||
|
||
.dialog2Hidden { | ||
-webkit-animation-duration: 0.3s; | ||
-webkit-animation-fill-mode: both; | ||
-webkit-animation-name: shakeFadeOut; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<button onclick="toggleDialog()">Toggle Dialog</button> | ||
<g-overlay id="dialog" class="dialog" showClass="dialogShown" hideClass="dialogHidden"> | ||
<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> | ||
<div> | ||
<g-checkbox></g-checkbox> | ||
I agree with this wholeheartedly. | ||
</div><br><br> | ||
<button onclick="toggleDialog()">OK</button> | ||
</g-overlay> | ||
<br><br> | ||
<button onclick="toggleDialog2()">Toggle Dialog 2</button> | ||
<g-overlay id="dialog2" class="dialog" showClass="dialog2Shown" hideClass="dialog2Hidden"> | ||
<h2>Dialog 2</h2> | ||
I'm dizzy. | ||
</div><br><br> | ||
<button onclick="toggleDialog2()">OK</button> | ||
</g-overlay> | ||
<script> | ||
toggleDialog = function() { | ||
document.querySelector("#dialog").toggleShowing(); | ||
} | ||
toggleDialog2 = function() { | ||
document.querySelector("#dialog2").toggleShowing(); | ||
} | ||
</script> | ||
</body> | ||
</html> |