Coder Social home page Coder Social logo

piano's Introduction

piano
⌨ Piano.js

> Customizable virtual keyboard written in pure JavaScript.

js-standard-style Join the chat at https://gitter.im/soixantecircuits/piano

Piano is still under active development.

Table of contents

Installation

Installation with Webpack

1 - Install the package and save it as a dependency

npm i -S piano.js

2 - Add some lines to your javascript code

// Add the styling (in entry.js for instance)
require('piano.js/piano.css')

// Require piano wherever you want to use it
const Piano = require('piano.js')

// Choose the layouts you want
const azerty = require('piano.js/layouts/azerty')
const qwerty = require('piano.js/layouts/qwerty')

// Instantiate Piano
const keyboard = new Piano({
  layouts: {
    'azerty': azerty,
    'qwerty': qwerty
  },
  slideContent: true
})

3 - Use data-attributes in your view

<input type="text"
  data-piano data-piano-scale="1.5"
  data-piano-layout="azerty"
  data-piano-event-id="do-stuff"
/>

4 - Use listener in your code

document
  .querySelector('[data-piano-event-id="do-stuff"]')
  .addEventListener('do-stuff', doStuffCallback)

5 - Enjoy!

Installation without Webpack

Download piano and at least the default layout into your project and load them.

<!-- Load the librarie -->
<script src="path/to/piano.js"></script>
<!-- And at least the default layout -->
<script src="path/to/layouts/default.js"></script>

Then, add the data-piano attribute to trigger the keyboard on click/touch and call piano.init() in your js.

A basic init() looks like this:

piano.init({
  triggers: ['click', 'touchstart'],
  slideContainer: '.demo-container',
  slideContent: true,
  onHidden: function () {
    console.log('hidden')
  },
  onBeforeHidden: function () {
    console.log('hidding...')
  }
})

See the demo for more information.

Usage

Positionning / styling

You can define positionning with the data-piano-position attribute. You can use the following:

  • 'left', 'center', 'right' -> x axis
  • 'top', 'middle', 'bottom' -> y axis

For example:

<input type="text" data-piano data-piano-position="left, center" />

Or, with the absolute keyword, you can define absolute x and y positions:

<input type="text" data-piano data-piano-position="absolute, 100, 150" />

Default positions are 'center, bottom'.

Submit

You can define a data-piano-event-id attribute on your element and then listen to it. For example, if you have a data-piano-event-id="input-event":

element.addEventListener('input-event', function (event) {
  console.log('element with id "%s" submitted.', event.target.id)
})

Animations

Piano provide has built-in but yet optionnal support for Animate.css.

By default, it will add fadeInUp and fadeOutDown classes to your container. Just load the animate.css stylesheet and you'll have nice animations. You can also use the data-piano-animation-in and data-piano-animation-out attributes to define custom classes to toggle on hide/show.

You can also choose to create your own animations, and thus just use the classes toggled by piano to trigger them.

Tactile events

Piano's support for tactile events is still in development (I know, for a virtual keyboard destined to touchscreens, it's kinda lame ...). However, it should work (though not ideally and efficiently) with the browser emulation of the click event on touchscreens. You can also define your own event to listen to in the initialization : piano.init('touchstart') for example (default is 'click').

This will be optimized very soon. If you have any ideas, suggestions, or even want to get your hands dirty hand submit a PR, you are more than welcome !

Options

You can pass options to your piano.init() call. Here they are:

  • trigger: Array of event triggers you want Piano to react
  • slideContent: bool [true, false], default to false. Allow to define if the content should slide
  • slideContainer: string ['.demo-container'], no default. Allow to define the part of the DOM you want to slide
  • onHidden: function, default to empty function. Allow to call a function when the keyboard is hidden
  • onBeforeHidden: function, default to empty function. Allow to call a function before the keyboard is hidden

Demo

Make sure you have node, npm and gulp installed. After you have installed development dependencies with npm i, you can run npm run dev and go to http://localhost:9966/demo to check a demo.

Or you can check it out here.

Layouts

Soon.

Development

Create a feature-[name-of-the-feature] branch and make PR on the dev branch. Please use the standard js coding style.

To Do

  • Support accentuation. (partial support for now).
  • Support hammer.js and/or other touch events librarie.
  • Make sure it works well with requireJS, AngularJS, MeteorJS, React.
  • Publish it to bower and be famous.
  • Test with IE11, Chrome, Firefox.
  • Test embeded in electron and nwjs.

piano's People

Contributors

hugohil avatar brendaoud avatar gabrielstuff avatar kucherenkovova avatar tanaki avatar kevinboudot avatar gitter-badger avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.