mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-04 01:29:21 +00:00
32 lines
653 B
JavaScript
32 lines
653 B
JavaScript
|
|
import Vue from 'vue';
|
||
|
|
|
||
|
|
import _throttle from 'lodash/throttle';
|
||
|
|
|
||
|
|
import { emit } from './directive.common';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* v-resize="throttleTimeout", @resized="callback()"
|
||
|
|
*/
|
||
|
|
|
||
|
|
const EVENT_NAME = 'resized';
|
||
|
|
|
||
|
|
export default {
|
||
|
|
bind (el, binding, vnode) {
|
||
|
|
el.handleWindowResize = _throttle(() => {
|
||
|
|
emit(vnode, EVENT_NAME, {
|
||
|
|
width: el.clientWidth,
|
||
|
|
height: el.clientHeight,
|
||
|
|
});
|
||
|
|
}, binding.value);
|
||
|
|
|
||
|
|
window.addEventListener('resize', el.handleWindowResize);
|
||
|
|
|
||
|
|
// send the first width
|
||
|
|
Vue.nextTick(el.handleWindowResize);
|
||
|
|
},
|
||
|
|
|
||
|
|
unbind (el) {
|
||
|
|
window.removeEventListener('resize', el.handleWindowResize);
|
||
|
|
},
|
||
|
|
};
|