npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chimee-plugin-contextmenu

v0.1.2

Published

ContextmenuPlugin for chimee

Downloads

67

Readme

ContextmenuPlugin of Chimee

右键菜单UI插件,可实现自定义菜单项及相应交互,效果参见Demo

默认菜单基本用法

使用默认菜单项,不做定制或修改。

import contextmenu from 'chimee-plugin-contextmenu';
Chimee.install(contextmenu);
const chimee = new Chimee({
  wrapper: '#wrapper',
  plugins: [contextmenu.name]
});

提示:默认菜单项中的“查看日志”,依赖 chimee-plugin-log 插件的装载。

效果示例:

增加自定义菜单项

在保留默认菜单的基础上,添加自己需要的菜单项。

import contextmenu from 'chimee-plugin-contextmenu';
Chimee.install(contextmenu);
const chimee = new Chimee({
  wrapper: '#wrapper',
  plugins: [{
    name: contextmenu.name,
    menus: [
      {
        text: '暂停',
        action: 'menu-pause'
      }
    ]
  }]
});
player.on('menu-pause', function() {
  console.log('我要暂停了');
  // 通知播放器暂停
  player.emit('pause');
});

通过上例看,菜单项的action可以触发播放器实例事件,所以也即是所菜单项的 action 在插件内部会作为 player.emit('menu-pause') 执行。

所以,如果你只是想实现暂停菜单,我们可以简化菜单项的 action 值,从 menu-pause 改为pause,就可以了(因为chimee的实现上已经支持通过该途径触发暂停或播放等基本操作)。

这么以来,如果我们要实现右键的播放暂停也就可以省掉 player.on('menu-pause', ()=>{}) 了。下面我们结合这一点了解一下另一种实现方式。

在默认菜单基础上动态更新自定义菜单项

在保留默认菜单的基础上,通过API动态实现自己需要的菜单项。

import contextmenu from 'chimee-plugin-contextmenu';
Chimee.install(contextmenu);
const chimee = new Chimee({
  wrapper: '#wrapper',
  plugins: [contextmenu.name]
});
// 访问播放器菜单插件实例
const menusPlugin = player.chimeeContextmenu;
player.on('play', () => {
  // 当播放器处于播放状态时,自定义菜单项显示暂停
  menusPlugin.updatemenu([{text: '暂停', action: 'pause'}]);
}).on('pause', () => {
  // 当播放器处于状态暂停时,自定义菜单项显示播放
  menusPlugin.updatemenu([{text: '播放', action: 'play'}]);
});

这样一个跟随播放状态切换的菜单项就实现了。

效果示例:

那么为什么要一直显示基础菜单项呢,要去掉怎么做呢?

全自定义菜单

不保留默认菜单,添加自己需要的菜单项。

import contextmenu from 'chimee-plugin-contextmenu';
Chimee.install(contextmenu);
const chimee = new Chimee({
  wrapper: '#wrapper',
  plugins: [{
    name: contextmenu.name,
    baseMenus: [], // 这里我们告诉插件,不需要基础菜单项,当然也用来定义想要的基础菜单项
    menus: [
      {
        text: '暂停',
        action: 'pause'
      },
      {
        text: 'copyright 360 vs: {VERSION}',
        disable: true
      },
      {
        text: '我是一个新窗口打开的连接',
        url: 'http://chimee.org'
      }
    ]
  }]
});

效果示例:

欢迎使用、反馈您的建议。