Permalink
Browse files

g-overlay: with webanimations

  • Loading branch information...
Yvonne Yip
Yvonne Yip committed Apr 15, 2013
1 parent c13fd11 commit 9f8f036cebb5ddff9849a37ddb53e62081540715
Showing with 225 additions and 1 deletion.
  1. +1 −1 components/css/g-overlay.css
  2. +108 −0 components/g-overlay-webanimations.html
  3. +116 −0 workbench/overlay2.html
@@ -114,4 +114,4 @@ We address this by using script based positioning =(
-webkit-animation-fill-mode: both;
-webkit-animation-name: g-overlay-shakeFadeOut;
}
-}
+}
@@ -0,0 +1,108 @@
+<link rel="import" href="g-overlay.html">
+<link rel="import" href="g-animation.html">
+<element name="g-overlay-webanimations" extends="g-overlay">
+ <link rel="stylesheet" href="css/g-overlay.css">
+ <link rel="stylesheet" toolkit-scope="global" href="css/g-overlay-global.css">
+ <template>
+ <style>
+ @host {
+ .revealed {
+ opacity: 0;
+ }
+ }
+ </style>
+ <g-animation id="scale" duration="0.218" on-complete="completeOpening">
+ <g-property name="transform">
+ <g-keyframe value="scale(1.05)"></g-keyframe>
+ <g-keyframe value="scale(1.0)"></g-keyframe>
+ </g-property>
+ <g-property name="opacity">
+ <g-keyframe value="0"></g-keyframe>
+ <g-keyframe value="1"></g-keyframe>
+ </g-property>
+ <g-property name="visibility">
+ <g-keyframe value="hidden"></g-keyframe>
+ <g-keyframe value="visible"></g-keyframe>
+ </g-property>
+ </g-animation>
+ <g-animation id="slideUp" duration="0.4">
+ <g-property name="opacity">
+ <g-keyframe value="1"></g-keyframe>
+ <g-keyframe value="0"></g-keyframe>
+ </g-property>
+ <g-property name="transform">
+ <g-keyframe value="translateY(0)"></g-keyframe>
+ <g-keyframe value="translateY(-100%)"></g-keyframe>
+ </g-property>
+ </g-animation>
+ <g-animation id="shakeFadeIn" duration="0.5">
+ <g-property name="transform">
+ <g-keyframe offset="0" value="translateX(0)"></g-keyframe>
+ <g-keyframe offset="0.1" value="translateX(-50px)"></g-keyframe>
+ <g-keyframe offset="0.3" value="translateX(50px)"></g-keyframe>
+ <g-keyframe offset="0.5" value="translateX(-25px)"></g-keyframe>
+ <g-keyframe offset="0.7" value="translateX(25px)"></g-keyframe>
+ <g-keyframe offset="0.9" value="translateX(-13px)"></g-keyframe>
+ <g-keyframe offset="1" value="translateX(0)"></g-keyframe>
+ </g-property>
+ <g-property name="opacity">
+ <g-keyframe value="0"></g-keyframe>
+ <g-keyframe value="1"></g-keyframe>
+ </g-property>
+ <g-property name="visibility">
+ <g-keyframe value="hidden"></g-keyframe>
+ <g-keyframe value="visible"></g-keyframe>
+ </g-property>
+ </g-animation>
+ <g-animation id="shakeFadeOut" duration="0.5">
+ <g-property name="transform">
+ <g-keyframe offset="0" value="translateX(0)"></g-keyframe>
+ <g-keyframe offset="0.1" value="translateX(-50px)"></g-keyframe>
+ <g-keyframe offset="0.3" value="translateX(50px)"></g-keyframe>
+ <g-keyframe offset="1" value="translateX(-100%)"></g-keyframe>
+ </g-property>
+ <g-property name="opacity">
+ <g-keyframe value="1"></g-keyframe>
+ <g-keyframe value="0"></g-keyframe>
+ </g-property>
+ </g-animation>
+ <content></content>
+ </template>
+ <script>
+ Toolkit.register(this, {
+ publish: {
+ animation: 'scale-slideup'
+ },
+ ready: function() {
+ this.$.scale.target = this;
+ this.$.slideUp.target = this;
+ this.$.shakeFadeIn.target = this;
+ this.$.shakeFadeOut.target = this;
+ this.animationChanged();
+ },
+ animationChanged: function() {
+ if (this.animation == 'scale-slideup') {
+ this.openAnimation = this.$.scale;
+ this.closeAnimation = this.$.slideUp;
+ } else if (this.animation == 'shake') {
+ this.openAnimation = this.$.shakeFadeIn;
+ this.closeAnimation = this.$.shakeFadeOut;
+ }
+ },
+ renderOpened: function() {
+ this.classList.add('revealed');
+ if (this.opened) {
+ this.openAnimation.play();
+ } else {
+ this.closeAnimation.play();
+ }
+ },
+ openedAnimationStart: function(e) {
+ },
+ openedAnimationEnd: function(e) {
+ },
+ openedTransitionEnd: function(e) {
+ }
+ });
+ </script>
+</element>
View
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<!--
+Copyright 2013 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.
+-->
+<html>
+<head>
+ <title>Overlay</title>
+ <script src="../platform/platform.js"></script>
+ <script src="../toolkit.js"></script>
+ <!--<script src="../platform/PointerGestures/src/pointergestures.js"></script>-->
+ <link rel="import" href="../components/g-overlay-webanimations.html">
+ <style>
+ g-overlay-webanimations {
+ box-sizing: border-box;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 13px;
+ -webkit-user-select: none;
+ overflow: hidden;
+ background: white;
+ padding:30px 42px;
+ outline: 1px solid rgba(0,0,0,0.2);
+ box-shadow: 0 4px 16px rgba(0,0,0,0.2);
+ }
+
+ #dialog, #dialog2 {
+ top: 72px;
+ left: 50%;
+ width: 512px;
+ margin-left: -256px;
+ }
+
+ #confirmation {
+ position: absolute;
+ left: 50%;
+ top: 100px;
+ text-align: center;
+ width: 150px;
+ margin-left: -75px;
+ }
+ </style>
+</head>
+<body>
+ <button overlay="#dialog">Toggle Dialog</button>
+ ( open styling:
+ <select onchange="changeOpening(event)">
+ <option>g-overlay-scale-slideup</option>
+ <option>g-overlay-shake</option>
+ <option>g-overlay-fade</option>
+ <option>none</option>
+ </select>,
+ <label>modal: <input type="checkbox" onchange="modalChange(event)"></label>
+ <label>scrim: <input type="checkbox" onchange="scrimChange(event)"></label>
+ )
+ <br>
+ <g-overlay-webanimations id="dialog" animation="scale-slideup">
+ <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>
+ <input placeholder="say something..." autofocus oninput="somethingCheck()"></input><br>
+ I agree with this wholeheartedly.
+ <g-overlay-webanimations id="confirmation">
+ Thank you.
+ </g-overlay-webanimations>
+ </div><br><br>
+ <button overlay-toggle>OK</button>
+ </g-overlay-webanimations>
+
+ <br><br>
+
+ <button overlay="#dialog2">Toggle Dialog 2</button>
+
+ <g-overlay-webanimations id="dialog2" animation="shake" modal>
+ <h2>Dialog 2</h2>
+ I'm dizzy.
+ </div><br><br>
+ <button overlay-toggle>OK</button>
+ </g-overlay-webanimations>
+ <script>
+ $ = document.querySelector.bind(document);
+
+ somethingCheck = function() {
+ $('#confirmation').opened = (event.target.value == 'something');
+ }
+
+ changeOpening = function(e) {
+ var s = e.target.selectedOptions[0];
+ if (s) {
+ dialog.className = dialog.className.replace(/g-[^\s]*/, '')
+ dialog.classList.add(s.textContent);
+ }
+ }
+
+ modalChange = function(e) {
+ dialog.modal = e.target.checked;
+ }
+
+ scrimChange = function(e) {
+ dialog.scrim = e.target.checked;
+ }
+
+ var overlayButtons = document.querySelectorAll('button[overlay]');
+ Array.prototype.forEach.call(overlayButtons, function(b) {
+ b.setAttribute('touch-action', 'none');
+ b.addEventListener('click', function(e) {
+ var overlay = document.querySelector(e.target.getAttribute('overlay'));
+ if (overlay) {
+ overlay.toggle();
+ }
+ })
+ });
+ </script>
+</body>
+</html>

0 comments on commit 9f8f036

Please sign in to comment.