iceshrimp-legacy/src/web/app/desktop/tags/contextmenu.tag

139 lines
2.5 KiB
HTML
Raw Normal View History

2017-02-20 12:13:42 +01:00
<mk-contextmenu>
<yield />
2017-02-19 04:31:53 +01:00
<style>
2017-01-11 21:55:38 +01:00
:scope
$width = 240px
$item-height = 38px
$padding = 10px
display none
position fixed
top 0
left 0
z-index 4096
width $width
font-size 0.8em
background #fff
border-radius 0 4px 4px 4px
box-shadow 2px 2px 8px rgba(0, 0, 0, 0.2)
2017-03-20 10:43:04 +01:00
opacity 0
2017-01-11 21:55:38 +01:00
ul
display block
margin 0
padding $padding 0
list-style none
li
display block
&.separator
margin-top $padding
padding-top $padding
border-top solid 1px #eee
&.has-child
> p
cursor default
> i:last-child
position absolute
top 0
right 8px
line-height $item-height
&:hover > ul
visibility visible
&:active
> p, a
background $theme-color
2016-12-28 23:49:51 +01:00
> p, a
2017-01-11 21:55:38 +01:00
display block
z-index 1
margin 0
padding 0 32px 0 38px
line-height $item-height
color #868C8C
text-decoration none
cursor pointer
&:hover
text-decoration none
*
pointer-events none
> i
width 28px
margin-left -28px
text-align center
&:hover
> p, a
text-decoration none
background $theme-color
color $theme-color-foreground
&:active
> p, a
text-decoration none
background darken($theme-color, 10%)
color $theme-color-foreground
li > ul
visibility hidden
position absolute
top 0
left $width
margin-top -($padding)
width $width
background #fff
border-radius 0 4px 4px 4px
box-shadow 2px 2px 8px rgba(0, 0, 0, 0.2)
transition visibility 0s linear 0.2s
</style>
<script>
2017-03-20 10:43:04 +01:00
import anime from 'animejs';
2017-03-18 12:05:11 +01:00
import contains from '../../common/scripts/contains';
2017-02-20 12:13:42 +01:00
this.root.addEventListener('contextmenu', e => {
2017-02-20 02:27:44 +01:00
e.preventDefault();
2017-02-20 12:13:42 +01:00
});
2017-01-11 21:55:38 +01:00
2017-02-20 12:13:42 +01:00
this.mousedown = e => {
2017-02-20 02:27:44 +01:00
e.preventDefault();
2017-02-20 12:13:42 +01:00
if (!contains(this.root, e.target) && (this.root != e.target)) this.close();
return false;
};
this.open = pos => {
document.querySelectorAll('body *').forEach(el => {
el.addEventListener('mousedown', this.mousedown);
});
this.root.style.display = 'block';
this.root.style.left = pos.x + 'px';
this.root.style.top = pos.y + 'px';
2017-03-20 10:43:04 +01:00
anime({
targets: this.root,
opacity: [0, 1],
2017-02-20 12:13:42 +01:00
duration: 100,
easing: 'linear'
});
};
2017-01-11 21:55:38 +01:00
2017-02-20 02:34:57 +01:00
this.close = () => {
2017-02-20 12:13:42 +01:00
document.querySelectorAll('body *').forEach(el => {
el.removeEventListener('mousedown', this.mousedown);
});
2017-02-20 01:53:57 +01:00
this.trigger('closed');
this.unmount();
2017-02-20 12:13:42 +01:00
};
2017-01-11 21:55:38 +01:00
</script>
</mk-contextmenu>