📜  "https: unpkg.com thaana-keyboard@2.0.3 dist ThaanaKeyboard.min.js - Java (1)

📅  最后修改于: 2023-12-03 14:58:59.271000             🧑  作者: Mango

Thaana Keyboard

Thaana Keyboard is a JavaScript library that allows users to input Dhivehi (Thaana) language characters using a regular keyboard. This library works by converting English characters typed on a keyboard into Unicode Thaana characters.

Getting Started

To get started using Thaana Keyboard, you'll need to include the ThaanaKeyboard.min.js file from the unpkg.com CDN in your HTML file. You can do this using the following code:

<script src="https://unpkg.com/thaana-keyboard@2.0.3/dist/ThaanaKeyboard.min.js"></script>

Once you've included the ThaanaKeyboard.min.js file, you can create a Thaana Keyboard object by calling the ThaanaKeyboard() constructor. You'll then need to attach this object to a textarea element using the .attach() method. Here's an example:

const textarea = document.getElementById('myTextArea');
const keyboard = new ThaanaKeyboard();
keyboard.attach(textarea);
Options

The Thaana Keyboard constructor takes an options object as an optional parameter. This object can be used to customize the behavior of the keyboard. Here are the available options:

startEnabled (default: true)

Set this option to true to have the keyboard enabled when it is attached to a textarea element. Set it to false to start with the keyboard disabled.

const keyboard = new ThaanaKeyboard({ startEnabled: false });
toggleKeySelector (default: undefined)

Set this option to a CSS selector for an element on the page. When this element is clicked, the keyboard will toggle between enabled and disabled.

const toggleBtn = document.getElementById('toggleBtn');
const keyboard = new ThaanaKeyboard({ toggleKeySelector: '#toggleBtn' });
Methods

The Thaana Keyboard object has a number of methods that you can call to interact with the keyboard. Here are the available methods:

.setEnabled(state)

Use this method to enable or disable the keyboard. Pass true to enable the keyboard, and false to disable it.

keyboard.setEnabled(true); // enable the keyboard
keyboard.setEnabled(false); // disable the keyboard
.isEnabled()

Use this method to check whether the keyboard is currently enabled. Returns true if it is, and false if it isn't.

const isEnabled = keyboard.isEnabled(); // true or false
.attach(element)

Use this method to attach the Thaana Keyboard to a textarea element. Pass the element as a parameter.

const textarea = document.getElementById('myTextArea');
keyboard.attach(textarea);
.detach()

Use this method to detach the Thaana Keyboard from the currently attached textarea element.

keyboard.detach();
Conclusion

Thaana Keyboard is a useful JavaScript library for allowing users to input Dhivehi (Thaana) characters using a regular keyboard. With its easy-to-use API and customizable options, Thaana Keyboard is a great way to add support for Thaana input to your web application.