Skip to content

Commit

Permalink
Add escape key binding and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
supachailllpay committed Mar 1, 2018
1 parent 24a09de commit 7844c0a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions photo-gallery.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<link rel='import' href='../polymer/polymer-element.html'>
<link rel='import' href='../shadycss/apply-shim.html'>
<link rel="import" href="../iron-a11y-keys/iron-a11y-keys.html">
<link rel='import' href='../iron-a11y-keys/iron-a11y-keys.html'>

<link rel='import' href='anime.html'>
<link rel='import' href='photo-gallery-icon.html'>
Expand Down Expand Up @@ -99,14 +99,15 @@
}
</style>

<iron-a11y-keys target="[[keyEventTarget]]" keys="left up" on-keys-pressed="previous"></iron-a11y-keys>
<iron-a11y-keys target="[[keyEventTarget]]" keys="right down" on-keys-pressed="next"></iron-a11y-keys>
<iron-a11y-keys target='[[$.slideshow]]' keys='esc' on-keys-pressed='close'></iron-a11y-keys>

This comment has been minimized.

Copy link
@alejost848

alejost848 Mar 1, 2018

Contributor

Great add! I didn't know you could reference an element directly like this, awesome! ...and sorry about the double quotes 😅

This comment has been minimized.

Copy link
@supachailllpay

supachailllpay Mar 1, 2018

Author Owner

Thanks and no problem :)

<iron-a11y-keys target='[[$.slideshow]]' keys='left up' on-keys-pressed='previous'></iron-a11y-keys>
<iron-a11y-keys target='[[$.slideshow]]' keys='right down' on-keys-pressed='next'></iron-a11y-keys>

<div class='grid' on-click='open'>
<slot id='grid'></slot>
</div>

<div class='slideshow' id='slideshow'>
<div class='slideshow' tabindex='-1' id='slideshow'>
<img class='slide' id='slide'>
<img class='slide' style='display: none' id='exitSlide'>
<photo-gallery-icon class='chevron' icon='chevron-left' on-click='previous'></photo-gallery-icon>
Expand Down Expand Up @@ -144,9 +145,6 @@
type: Number,
value: -1,
notify: true
},
keyEventTarget: {
type: Object
}
}
}
Expand Down Expand Up @@ -209,6 +207,7 @@
let rect = item.getBoundingClientRect()
slide.src = item.dataset.url
slideshow.style.display = 'block'
slideshow.focus()
this.anime({
targets: slideshow,
top: [rect.top, 0],
Expand Down Expand Up @@ -271,7 +270,6 @@

ready () {
super.ready()
this.keyEventTarget = document.body

This comment has been minimized.

Copy link
@alejost848

alejost848 Mar 1, 2018

Contributor

I tried using this.$.slideshow but couldn't get it to work. I guess it was the missing slideshow.focus() that did the trick, wasn't it?

This comment has been minimized.

Copy link
@supachailllpay

supachailllpay Mar 1, 2018

Author Owner

The key part is make slideshow be focusable by set tabindex on it. When it was opened make it focused by slideshow.focus() (without this you need to click on it first).


let grid = this.$.grid
this.updateItems()
Expand Down

0 comments on commit 7844c0a

Please sign in to comment.