create setMatchMedia in assist.js

This commit is contained in:
zhigang.li 2017-12-18 18:55:29 +08:00
parent 1a90ee6cb0
commit d85e572645
2 changed files with 17 additions and 13 deletions

View file

@ -15,19 +15,9 @@
</template> </template>
<script> <script>
import { on, off } from '../../utils/dom'; import { on, off } from '../../utils/dom';
import { oneOf, dimensionMap } from '../../utils/assist'; import { oneOf, dimensionMap, setMatchMedia } from '../../utils/assist';
const prefixCls = 'ivu-layout-sider'; const prefixCls = 'ivu-layout-sider';
if (typeof window !== 'undefined') { setMatchMedia();
const matchMediaPolyfill = mediaQuery => {
return {
media: mediaQuery,
matches: false,
on() {},
off() {},
};
};
window.matchMedia = window.matchMedia || matchMediaPolyfill;
}
export default { export default {
name: 'Sider', name: 'Sider',
props: { props: {

View file

@ -286,3 +286,17 @@ export const dimensionMap = {
lg: '1200px', lg: '1200px',
xl: '1600px', xl: '1600px',
}; };
export function setMatchMedia () {
if (typeof window !== 'undefined') {
const matchMediaPolyfill = mediaQuery => {
return {
media: mediaQuery,
matches: false,
on() {},
off() {},
};
};
window.matchMedia = window.matchMedia || matchMediaPolyfill;
}
}