Skip to content

Commit

Permalink
Merge pull request #29 from sorvell/master
Browse files Browse the repository at this point in the history
g-panels minor bug fixes
  • Loading branch information
frankiefu committed Oct 29, 2012
2 parents 2eff28d + 27ff24a commit 63cbe38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/g-panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
}
}

// TODO(sorvell): need key table
var KEY_RIGHT_ARROW = 39;
var KEY_LEFT_ARROW = 37;

this.component({
created: function() {
this.initPanels();
Expand Down Expand Up @@ -53,7 +57,7 @@
var fromPanel = this.panelAtIndex(this.lastIndex),
toPanel = this.panelAtIndex(this.index),
forward = Boolean(this.index > this.lastIndex);
if (this.canTransition()) {
if (this.canTransition() && fromPanel && toPanel) {
this.beginTransition(fromPanel, toPanel, forward);
} else {
this.finishTransition(fromPanel, toPanel, forward);
Expand Down Expand Up @@ -129,19 +133,16 @@
return Boolean(this.transitionNode);
},
beginTransition: function(inFrom, inTo, inForward) {
var old = this.transitionInfo;
if (old && this.transitionNode) {
if (this.transitionNode) {
this.transitionNode.stop();
}
this.transitionInfo = {from: inFrom, to: inTo, forward: inForward};
webkitRequestAnimationFrame(function() {
inFrom.hidden = false;
inTo.hidden = false;
this.transitionNode.go(inFrom, inTo, inForward);
}.bind(this));
},
finishTransition: function() {
this.transitionInfo = null;
if (this.transitionNode && this.transitionNode.highlander) {
this.getPanels().forEach(function(p, i) {
p.hidden = (i != this.index);
Expand All @@ -155,19 +156,16 @@
this.index--;
},
keydownHandler: function(e) {
if (documentIsEditing()) {
return;
}
var i = this.index;
// right arrow
if (e.keyCode == 39) {
this.next();
// left arrow
} else if (e.keyCode == 37) {
this.previous();
}
if (i != this.index) {
e.stopPropagation();
if (!documentIsEditing()) {
var beforeIndex = this.index;
if (e.keyCode == KEY_RIGHT_ARROW) {
this.next();
} else if (e.keyCode == KEY_LEFT_ARROW) {
this.previous();
}
if (beforeIndex != this.index) {
e.stopPropagation();
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/panel-transitions/g-panel-transition.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
-->
<element name="g-panel-transition">
<!-- remove blank template when polyfill issue #62 is fixed -->
<template></template>
<script>
this.component({
prototype: {
Expand Down

0 comments on commit 63cbe38

Please sign in to comment.