diff --git a/src/css/g-overlay.css b/src/css/g-overlay.css index f9d30cf1..81323cb3 100644 --- a/src/css/g-overlay.css +++ b/src/css/g-overlay.css @@ -19,7 +19,7 @@ -webkit-transition: all 0.218s; } -@host.g-overlay-fade[opened] { +@host.g-overlay-fade.opened { opacity: 1; } @@ -29,12 +29,12 @@ -webkit-transition: all 0.218s; } -@host.g-overlay-scale-slideup[opened] { +@host.g-overlay-scale-slideup.opened { opacity: 1.0; -webkit-transform: scale(1.0); } -@host.g-overlay-scale-slideup:not([opened])[animating] { +@host.g-overlay-scale-slideup.animating:not(.opened) { opacity: 0; -webkit-transform: translateY(-100%); -webkit-transition: all 1s; @@ -90,13 +90,13 @@ } } -@host.g-overlay-shake[opened] { +@host.g-overlay-shake.opened { -webkit-animation-duration: 0.5s; -webkit-animation-fill-mode: both; -webkit-animation-name: g-overlay-shakeFadeIn; } -@host.g-overlay-shake:not([opened])[animating] { +@host.g-overlay-shake.animating:not(.opened) { -webkit-animation-duration: 0.3s; -webkit-animation-fill-mode: both; -webkit-animation-name: g-overlay-shakeFadeOut; diff --git a/src/css/g-page.css b/src/css/g-page.css new file mode 100644 index 00000000..cf34587f --- /dev/null +++ b/src/css/g-page.css @@ -0,0 +1,10 @@ +/* + * 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. + */ +html, body { + height: 100%; + margin: 0; + font-family: 'Helvetica Nue', 'Helvetica', Arial, 'open sans' sans-serif; +} \ No newline at end of file diff --git a/src/css/g-panels.css b/src/css/g-panels.css index b32b2d9c..aea168ce 100644 --- a/src/css/g-panels.css +++ b/src/css/g-panels.css @@ -3,14 +3,14 @@ * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. */ -@host { +@host, g-panels { display: block; position: relative; outline: none; overflow: hidden; } -@host > * { +@host > *, g-panels > * { position: absolute; top: 0; left: 0; @@ -21,11 +21,11 @@ /* TODO(sorvell): note: this is a workaround for reference combinators approach defined in shadowDom spec */ /* TODO(sorvell): expose animation timing via css variable */ -@host > .transition { +@host > .transition, g-panels > .transition { -webkit-transition: all 0.5s ease-in-out; } -@host > .animate { +@host > .animate, g-panels > .animate { -webkit-animation-duration: 0.5s; -webkit-animation-fill-mode: both; } @@ -39,12 +39,17 @@ approach defined in shadowDom spec */ */ /* fade */ -@host.g-panels-fade > .panels-ascending-from, -@host.g-panels-fade > .panels-descending-from { +@host > .panels-ascending-from, +@host > .panels-descending-from, +g-panels > .panels-ascending-from, +g-panels > .panels-descending-from, +{ -webkit-animation-name: g-panels-fadeOut; } -@host.g-panels-fade > .panels-ascending-to, -@host.g-panels-fade > .panels-descending-to { +@host > .panels-ascending-to, +@host > .panels-descending-to, +g-panels > .panels-ascending-to, +g-panels > .panels-descending-to { -webkit-animation-name: g-panels-fadeIn; } @@ -62,6 +67,19 @@ approach defined in shadowDom spec */ -webkit-animation-name: g-panels-slideFromLeft; } +g-panels.g-panels-hslide > .panels-ascending-from { + -webkit-animation-name: g-panels-slideLeft; +} +g-panels.g-panels-hslide > .panels-ascending-to { + -webkit-animation-name: g-panels-slideFromRight; +} +g-panels.g-panels-hslide > .panels-descending-from { + -webkit-animation-name: g-panels-slideRight; +} +g-panels.g-panels-hslide > .panels-descending-to { + -webkit-animation-name: g-panels-slideFromLeft; +} + /* vslide */ @host.g-panels-vslide > .panels-ascending-from { -webkit-animation-name: g-panels-slideTop; @@ -77,6 +95,10 @@ approach defined in shadowDom spec */ } /* hslideover */ +@host.g-panels-hslideover > .panels-ascending-from, +@host.g-panels-hslideover > .panels-descending-from { + -webkit-animation-name: none; +} @host.g-panels-hslideover > .panels-ascending-to { -webkit-animation-name: g-panels-slideFromRight; } @@ -85,6 +107,10 @@ approach defined in shadowDom spec */ } /* vslideover */ +@host.g-panels-vslideover > .panels-ascending-from, +@host.g-panels-vslideover > .panels-descending-from { + -webkit-animation-name: none; +} @host.g-panels-vslideover > .panels-ascending-to { -webkit-animation-name: g-panels-slideFromBottom; } diff --git a/src/g-ajax.html b/src/g-ajax.html index 274c21ad..a02a72d9 100644 --- a/src/g-ajax.html +++ b/src/g-ajax.html @@ -5,7 +5,7 @@ * license that can be found in the LICENSE file. */ --> - + + diff --git a/src/g-panels.html b/src/g-panels.html index 92fb8a6a..582e6056 100644 --- a/src/g-panels.html +++ b/src/g-panels.html @@ -26,18 +26,29 @@ } // TODO(sorvell): need key table - var KEY_RIGHT_ARROW = 39; - var KEY_LEFT_ARROW = 37; + var RIGHT_ARROW_KEY = 39; + var LEFT_ARROW_KEY = 37; this.component({ created: function() { + // ensure default transition + if (!this.transition) { + this.transition = this.defaultTransition; + if (this.index != null) { + this.indexChanged(); + } + } + // make focusable; note that default tabIndex == -1 but node is + // only focusable if tabIndex attr is set. + if (this.tabIndex < 0) { + this.tabIndex = -1; + } this.initPanels(); if (!this.index) { this.index = 0; } }, prototype: { - tabIndex: -1, defaultTransition: 'keyframe', initPanels: function() { this.getPanels().forEach(function(p, i) { @@ -47,13 +58,11 @@ initPanel: function() {}, indexChanged: function(inOldValue) { var i = this.clampIndex(this.index); - var old = this.clampIndex(inOldValue); if (i != this.index) { this.index = i; return; } - if (this.index != old) { - this.lastIndex = old; + if (this.index != this.lastIndex) { var fromPanel = this.panelAtIndex(this.lastIndex), toPanel = this.panelAtIndex(this.index), forward = Boolean(this.index > this.lastIndex); @@ -62,20 +71,26 @@ } else { this.finishTransition(fromPanel, toPanel, forward); } + this.lastIndex = this.index; + // TODO(sorvell): replace with getter/setter for selected when + // g-component does not override these on instances. + this.selected = this.getSelectedValue(); } }, clampIndex: function(inIndex) { - return Math.max(0, Math.min(this.count-1, inIndex)); + var i = isNaN(inIndex) ? 0 : inIndex; + return Math.max(0, Math.min(this.count-1, i)); }, - // selected is a virtual property so override getter - get selected() { + getSelectedValue: function() { var selected = this.getSelectedPanel(); - var name = selected && selected.getAttribute('name'); + var name = selected && (selected.getAttribute('id') || + selected.getAttribute('name')); return name || this.index; }, // selected is the name property of the panel to select selectedChanged: function(inOldValue) { - var index = this.indexOfName(this.selected); + var index = this.indexOfPropValue('id', this.selected); + index = index >= 0 ? index : this.indexOfPropValue('name', this.selected); if (index >= 0) { this.index = index; } @@ -95,23 +110,23 @@ this.makeTransitionNode(this.defaultTransition); }, tagNameForTransition: function(inName) { - return "g-" + inName + (inName ? "-" : "") + "panel-transition"; + return 'g-' + inName + (inName ? '-' : '') + 'panel-transition'; }, // TODO: consider selecting something more specific so we don't need to // filter out style/templates children. getPanels: function() { var n$ = this.$.content.getDistributedNodes(); return Array.prototype.filter.call(n$, function(c) { - return c.tagName != "STYLE" && c.tagName != "TEMPLATE"; + return c.tagName != 'STYLE' && c.tagName != 'TEMPLATE'; }); }, getSelectedPanel: function() { return this.getPanels()[this.index]; }, - indexOfName: function(inName) { + indexOfPropValue: function(inProp, inValue) { var c$ = this.getPanels(); for (var i=0, c; c=c$[i]; i++) { - if (c.getAttribute("name") == inName) { + if (c.getAttribute(inProp) == inValue) { return i; } } @@ -130,43 +145,57 @@ return this.getPanels().length; }, canTransition: function() { - return Boolean(this.transitionNode); + return Boolean(this.transitionNode && + this.transitionNode.canTransition()); }, beginTransition: function(inFrom, inTo, inForward) { if (this.transitionNode) { this.transitionNode.stop(); } webkitRequestAnimationFrame(function() { - inFrom.hidden = false; - inTo.hidden = false; + this.enablePanelShowing(inFrom, true); + this.enablePanelShowing(inTo, true); this.transitionNode.go(inFrom, inTo, inForward); }.bind(this)); }, finishTransition: function() { if (this.transitionNode && this.transitionNode.highlander) { this.getPanels().forEach(function(p, i) { - p.hidden = (i != this.index); + this.enablePanelShowing(p, i == this.index); }, this); } }, + // note: cannot use hidden attr for this since it's trumped by display + // setting e.g. hidden + display: -webkit-flex == showing. + enablePanelShowing: function(inPanel, inEnable) { + inPanel.style.display = inEnable ? null : 'none'; + }, next: function() { this.index++; }, previous: function() { this.index--; }, + toggleBetween: function(inA, inB) { + this.selected = this.selected == inA ? inB : inA; + }, keydownHandler: function(e) { if (!documentIsEditing()) { var beforeIndex = this.index; - if (e.keyCode == KEY_RIGHT_ARROW) { + if (e.keyCode == RIGHT_ARROW_KEY) { this.next(); - } else if (e.keyCode == KEY_LEFT_ARROW) { + } else if (e.keyCode == LEFT_ARROW_KEY) { this.previous(); } if (beforeIndex != this.index) { e.stopPropagation(); } } + }, + refresh: function() { + if (this.transitionNode && this.transitionNode.canTransition()) { + this.transitionNode.refresh(); + } } } }); diff --git a/src/panel-transitions/g-flow-panel-transition.html b/src/panel-transitions/g-flow-panel-transition.html index e0d9d2dd..f23d26d5 100644 --- a/src/panel-transitions/g-flow-panel-transition.html +++ b/src/panel-transitions/g-flow-panel-transition.html @@ -8,13 +8,13 @@