Sha256: 11e55f949b11466e317ba6192be8bb77f2f53f9081decd0bc12979f90b38d65f

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

import {MDCMenu} from '@material/menu';
import {Corner} from '@material/menu';


function createMenuHandler(menu, element) {
    return function () {
        let offset = parseInt(element.dataset.rightOffset);
        let placement = element.dataset.placement === 'contextual' ? Corner.TOP_LEFT : Corner.BOTTOM_LEFT
        menu.setAnchorMargin({left: offset});
        menu.setAnchorCorner(placement);
        menu.open = !menu.open;
    };
}

export function initMenus() {
    console.log('\tMenus');

    var components = document.querySelectorAll('.v-menu');
    if (components) {
        for (var i = 0; i < components.length; i++) {
            var component = components[i];
            if (!component.mdcComponent) {
                component.mdcComponent = new MDCMenu(component);
                var anchor = component.closest('.mdc-menu-anchor');
                if (anchor) {
                    var menulink = anchor.querySelector('.v-menu-click');
                    menulink.addEventListener('click', createMenuHandler(component.mdcComponent, component));
                }

            }
        }
    }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
voom-presenters-0.1.13 views/mdc/assets/js/components/menus.js
voom-presenters-0.1.12 views/mdc/assets/js/components/menus.js
voom-presenters-0.1.11 views/mdc/assets/js/components/menus.js
voom-presenters-0.1.10 views/mdc/assets/js/components/menus.js
voom-presenters-0.1.9 views/mdc/assets/js/components/menus.js