src/menu/menu.js
// executes the command when the representation is clicked.
executes the command when the representation is clicked.
executes the command when the representation is clicked .
render(pm) {
    let cmd = this.command(pm), disabled = false
    if (!cmd) return
    if (this.options.select != "ignore" && !cmd.select(pm)) {
      if (this.options.select == null || this.options.select == "hide") return null
      else if (this.options.select == "disable") disabled = true
    }
    let disp = this.options.display
    if (!disp) AssertionError.raise("No display style defined for menu command " + cmd.name)
    let dom
    if (disp.render) {
      dom = disp.render(cmd)
    } else if (disp.type == "icon") {
      dom = getIcon(cmd.name, disp)
      if (!disabled && cmd.active(pm)) dom.classList.add(prefix + "-active")
    } else if (disp.type == "label") {
      dom = elt("div", null, disp.label || cmd.spec.label)
    } else {
      AssertionError.raise("Unsupported command display style: " + disp.type)
    }
    dom.setAttribute("title", title(pm, cmd))
    if (this.options.class) dom.classList.add(this.options.class)
    if (disabled) dom.classList.add(prefix + "-disabled")
    if (this.options.css) dom.style.cssText += this.options.css
    dom.addEventListener("mousedown", e => {
      e.preventDefault(); e.stopPropagation()
      pm.signal("interaction")
      cmd.exec(pm, null, dom)
    })
    return dom
  }
render ( pm ) { let cmd = this . command ( pm ) , disabled = false if ( ! cmd ) return if ( this . options . select != "ignore" && ! cmd . select ( pm ) ) { if ( this . options . select == null || this . options . select == "hide" ) return null else if ( this . options . select == "disable" ) disabled = true } let disp = this . options . display if ( ! disp ) AssertionError . raise ( "No display style defined for menu command " + cmd . name ) let dom if ( disp . render ) { dom = disp . render ( cmd ) } else if ( disp . type == "icon" ) { dom = getIcon ( cmd . name , disp ) if ( ! disabled && cmd . active ( pm ) ) dom . classList . add ( prefix + "-active" ) } else if ( disp . type == "label" ) { dom = elt ( "div" , null , disp . label || cmd . spec . label ) } else { AssertionError . raise ( "Unsupported command display style: " + disp . type ) } dom . setAttribute ( "title" , title ( pm , cmd ) ) if ( this . options . class ) dom . classList . add ( this . options . class ) if ( disabled ) dom . classList . add ( prefix + "-disabled" ) if ( this . options . css ) dom . style . cssText += this . options . css dom . addEventListener ( "mousedown" , e => { e . preventDefault ( ) ; e . stopPropagation ( ) pm . signal ( "interaction" ) cmd . exec ( pm , null , dom ) } ) return dom }
executes the command when the representation is clicked.
executes the command when the representation is clicked .