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

jquery.klavier

v1.1.1

Published

A jQuery plugin to render a piano keyboard

Downloads

13

Readme

jquery.klavier

A jQuery plugin to render a piano keyboard.

Build Status

Getting Started

Download the production version or the development version.

In your web page:

<div id='container'></div>
<script src='jquery.min.js'></script>
<script src='jquery.klavier.min.js'></script>
<script>
$(document).ready(function ($) {
  $('#container').klavier();
});
</script>

Copy the following styles into your web site's CSS:

#container {
    height: 200px;
    width: 600px;
}
.klavier-key {
    border: 1px solid black;
}
.klavier-black-key {
    background-color:  black;
}
.klavier-white-key {
    background-color:  white;
}
.klavier-white-key.klavier-selected-key {
    background-color:  #CCCCCC;
}
.klavier-black-key.klavier-selected-key {
    background-color:  #333333;
}

Documentation

API

Instantiate a new keyboard by calling:

$('#container').klavier();

You can also specify options:

$('#container').klavier({ startKey: 60, endKey: 83 });

The following table lists all available options and their default values:

| option name | default value | description | |-------------------------|---------------|-------------------------------------------------------------------------------------------------------| | startKey | 60 | The MIDI value of the first key (must be a white key) | | endKey | 71 | The MIDI value of the last key (must be a white key) | | selectionMode | 'multiple' | Specifies how many keys can be selected at one time (can be 'none', 'single' or 'multiple') | | cssPrefix | 'klavier' | The first part of the generated CSS classes for the keys (can be used to style instances differently) | | zIndex | 999 | The z-index value of the white keys (black keys have zIndex + 1) | | onSelectedValuesChanged | (not set) | A function used as callback when the selection has changed |

You can set the selected keys providing an array of MIDI values:

$('#container').klavier('setSelectedValues', [60, 61]);

You can get the currently selected keys by calling:

var selectedKeys = $('#container').klavier('getSelectedValues');

You can finally destroy the keyboard by calling:

var selectedKeys = $('#container').klavier('destroy');

Please note, that all named calls to the $.klavier function are not chainable.

Styling

Every key gets assigned following CSS classes by the plugin: klavier-key, klavier-white-key (for white keys), klavier-black-key (for black keys), where the first part corresponds to the cssPrefix you provided as options (defaults to klavier).

Please note that the jQuery.klavier plugin sets position: relative on the container element during initialization. However, you have to set an explicit width and height on the container or else the keyboard won't be visible. You also have to set at least some background colors and borders for the CSS classes klavier-black-key and klavier-white-key to distinguish the keys (see also the aforementioned examples).

Examples

Have a look at the file examples.html.

Release History

  • 1.1.0 Support for CommonJS and AMD style module loading
  • 1.0 Initial release

Copyright (c) 2014 Andreas Helmberger & Ulrich Kaiser Licensed under the MIT License (MIT)