<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<style type="text/css">
@font-face {
font-family: "Bangla";
src: url(http://www.sachalayatan.com/BNG.ttf) format("truetype");
}
* {
font-family: "Bangla", Verdana, Tahoma;
}
</style>
<input type="text" onfocus="return passId(this);" />
<!--
<textarea onfocus="return passId(this);" style = "width:100%; height:300px; font-size:16px;" id = "chckItOut" name = "chckItOut">
</textarea>
-->
</body>
</html>
/// <summary>Write finalText to the text/input box</summary>
Keyboard.prototype.writeFinalValue = function (finalText, caretPosition) {
var scrollTop = this.textInputSource.scrollTop;
if (typeof this.textInputSource.selectionStart == "number" && typeof this.textInputSource.selectionEnd == "number") {
// Non-IE browsers and IE 9
this.textInputSource.value = finalText;
this.textInputSource.value = this.textInputSource.value;
// // Move the caret
// this.textInputSource.selectionStart = caretPosition;
// this.textInputSource.selectionEnd = caretPosition;
}
else if (document.selection && document.selection.createRange) {
// For IE up to version 8
var selectionRange = document.selection.createRange();
var textInputRange = this.textInputSource.createTextRange();
var precedingRange = this.textInputSource.createTextRange();
var bookmark = selectionRange.getBookmark();
textInputRange.moveToBookmark(bookmark);
precedingRange.setEndPoint("EndToStart", textInputRange);
var start = precedingRange.text.length;
var end = start + selectionRange.text.length;
this.value = finalText;
// // Move the caret
// textInputRange = this.createTextRange();
// textInputRange.collapse(true);
// textInputRange.move("character", start - (this.textInputRange.value.slice(0, start).split("\r\n").length - 1));
// textInputRange.select();
}
this.textInputSource.focus();
this.textInputSource.scrollTop = scrollTop;
// move caret
if (this.textInputSource.setSelectionRange) {
this.textInputSource.setSelectionRange(caretPosition, caretPosition);
// this.textInputSource.value = this.textInputSource.value;
}
else if (this.textInputSource.createTextRange) {
var range = this.textInputSource.createTextRange();
range.collapse(true);
range.moveEnd('character', caretPosition);
range.moveStart('character', caretPosition);
range.select();
}
}
/**************************************** END ***************************/
function passId(oTextbox) {
var inputbox = oTextbox;
//var global;
var stack = [];
global = new GlobalVariable();
global.operaDetected = !!window.opera;
_CurrentLanguage = "bn_BD";
inputbox.onkeydown = function (keyEvent) {
/*
operai keydown e kaj kora jabe na.....keypress e kora lagbe.
So jodi opera hoi taile editor exit kora hobe...Presto engine er bakigulir jonneo tai
*/
var oEvent = window.event || keyEvent;
var oSource = oEvent.srcElement || oEvent.target;
var keyboard = new Keyboard(oEvent, oSource);
var returnValue = keyboard.handleKeyboardInput(oEvent, oSource);
return returnValue;
}
inputbox.onkeypress = function (keyEvent) {
// var oEvent = window.event || keyEvent;
// var oSource = oEvent.srcElement || oEvent.target;
// var keyboard = new Keyboard( oEvent, oSource);
// alert(keyboard);
//return !!window.opera;// && keyboard.handleKeyboardInput(oEvent,oSource);
//return false;
}
inputbox.onkeyup = function (keyEvent) {
//return false;
// var oEvent = window.event || keyEvent;
// var oSource = oEvent.srcElement || oEvent.target;
// var keyboard = new Keyboard( oEvent, oSource);
// alert(keyboard);
// return global.operaDetected && keyboard.handleKeyboardInput(oEvent,oSource);
}
/*
inputbox.onmousedown= function (keyEvent)
{
var oEvent= window.event || keyEvent;
var oSource= oEvent.srcElement || oEvent.target;
if( oEvent.button == 0)
{
//updateRange(oEvent.rangeOffset);
}
return true;
}
//inputbox.focus();
*/
//if (stack.length > 0) global = stack.pop();
}
Keyboard.prototype.handleKeyboardInput = function () {
var prev = "", prevPrev = "", next = "", nextNext = "", text = this.textInputSource.value;
var keyState = this.selectKeyPressed();
//return true;
/// <summary>Decision; Should script continue or not</summary>
if (!!keyState.iShouldDealIt == false) return true;
if (global.currentLanguage == "en_US") {
return true;
}
// set prev and next characters
if (keyState.placeTo >= 2) {
prevPrev = text.charAt(keyState.placeTo - 2);
prev = text.charAt(keyState.placeTo - 1);
}
else if (keyState.placeTo >= 1)
prev = text.charAt(keyState.placeTo - 1);
if (keyState.placeTo >= 0 && keyState.placeTo <= this.textInputSource.value.length - 2) {
nextNext = this.textInputSource.value.charAt(keyState.placeTo + 1);
next = this.textInputSource.value.charAt(keyState.placeTo + 0);
}
else if (keyState.placeTo >= 0 && keyState.placeTo <= this.textInputSource.value.length - 1)
next = this.textInputSource.value.charAt(keyState.placeTo + 0);
/**************************************
unicodeKey change if necessary
***************************************/
// replace last-character
if (keyState.replaceLastChar) {
// hasanta
if (prev == "\u09CD") {
keyState.unicodeKey = "\u002B";
}
// other
else keyState.unicodeKey = global.bd.getFollower(prev, 2);
// if valid key reduce start position-1 because this will not be inserted
if (keyState.unicodeKey.length > 0) {
keyState.placeTo -= 1;
keyState.position.start -= 1;
}
}
// prev not a consonant then change vowel...
if (global.bd.getFollower(keyState.unicodeKey, 1) == 2 &&
(global.bd.getFollower(prev, 1) == 1 || global.bd.getFollower(prev, 1) == 3) == false) {
keyState.unicodeKey = global.bd.getFollower(keyState.unicodeKey, 2);
}
// prev is hasanta but current key is not consonant/fola...
if (prev == "\u09CD" && keyState.unicodeKey.length > 0 &&
(global.bd.getFollower(keyState.unicodeKey, 1) == 1 || global.bd.getFollower(keyState.unicodeKey, 1) == 3) == false) {
keyState.unicodeKey = global.ZWNJ + keyState.unicodeKey;
}
// next is hasanta but current key is not consonant/fola...
if (next == "\u09CD" && keyState.unicodeKey.length > 0 &&
(global.bd.getFollower(keyState.unicodeKey, 1) == 1 || global.bd.getFollower(keyState.unicodeKey, 1) == 3) == false) {
keyState.unicodeKey = global.ZWNJ + keyState.unicodeKey;
}
// fullstop button pressed twice will cause a dot ..
if (prev == "\u0964" && keyState.unicodeKey == "\u0964") {
keyState.unicodeKey = "\u002E";
keyState.position.start -= 1;
}
/// <summary>Backspace or Delete</summary>
// prevPrev is hasanta
if (keyState.code == 8) {
// if end==start then selected text so cursor should not move; otherwise should
keyState.position.start -= +(keyState.position.start == keyState.position.end);
keyState.position.start -= prevPrev == "\u09CD" ? 1 : 0;
if (keyState.position.start < 0)
keyState.position.start = 0;
}
// nextNext is hasanta
if (keyState.code == 46) {
// if end==start then selected text so cursor should not move; otherwise should
keyState.position.end += +(keyState.position.start == keyState.position.end);
keyState.position.end += nextNext == "\u09CD" ? 1 : 0;
}
/// <summary>Final data preparation</summary>
var firstPortion = text.slice(0, keyState.position.start);
var lastPortion = text.slice(keyState.position.end);
var finalText = firstPortion + keyState.unicodeKey + lastPortion;
var caretPosition = keyState.position.start + keyState.unicodeKey.length;
/// <summary>Write final data and update caret</summary>
this.writeFinalValue(finalText, caretPosition);
return false;
}
/// <summary>Select and return which key is pressed</summary>
Keyboard.prototype.selectKeyPressed = function () {
var code = this.oEvent.keyCode || this.oEvent.which;
var codeAsCharacter = String.fromCharCode(this.oEvent.keyCode || this.oEvent.which);
var position = this.cursorPosition();
// delete or backspace or dot-button or plus-button key
if (code == 8 || code == 46) {
return {
code: code,
unicodeKey: "",
iShouldDealIt: true,
placeTo: position.start,
position: position
}
}
/// ctrl, shift, alt, alt-grp, up arrow, down arrow
if (this.oEvent.ctrlKey || this.oEvent.altKey || code < 32 || (code >= 37 && code <= 40)) {
// using ctrl+m button to language switch
if (this.oEvent.ctrlKey && code == 77) {
var _C = global.currentLanguage == "bn_BD" ? "en_US" : "bn_BD";
global.currentLanguage = _C;
}
return {
code: code,
iShouldDealIt: false
}
}
var unicodeKey = "";
if (code >= 65 && code <= 90) {
unicodeKey = global.letterKeyMap[code - 65][+!!this.oEvent.shiftKey];
}
else if (code >= 48 && code <= 57) {
unicodeKey = global.numberKeyMap[code - 48][+!!this.oEvent.shiftKey];
}
else if ((code == 190 || code == 110) && !this.oEvent.shiftKey) // full-stop from keyboard/numpad
unicodeKey = '\u0964';
else if ((code == 107) && this.oEvent.shiftKey) // shift with plus-sign, replace with Q[0] or hasanta
unicodeKey = global.letterKeyMap[81 - 65][0];
// opera tweak for + button
else if (!!window.opera && code == 61 && this.oEvent.shiftKey)
unicodeKey = global.letterKeyMap[81 - 65][0];
else return {
code: code,
iShouldDealIt: false
};
/*
// . or +
flag = flag || (codeAsCharacter == '.' || codeAsCharacter == '+');
= flag ? global.letterKeyMap[code - 65][+!!this.oEvent.shiftKey] : "";
// h|| full-Stop || plus-Sign
var replaceLastChar =
(code == 72 || code == 190 || code == 107) && !this.oEvent.shiftKey;
var position = this.cursorPosition();
*/
// h|| full-Stop || plus-Sign
var replaceLastChar =
(code == 72 || 1 == 2) && !this.oEvent.shiftKey;
return {
code: code, // =65
iShouldDealIt: true, // =false
unicodeKey: unicodeKey, // ="\u0041"
shiftKeyPressed: this.oEvent.shiftKey, // =false
replaceLastChar: replaceLastChar, // =false
placeTo: position.start, // =3
position: position // { 1,8 }
};
}
Keyboard.prototype.asciiValue = function (c) {
// restrict input to a single character
c = c.charAt(0);
// loop through all possible ASCII values
var i;
for (i = 0; i < 256; ++i) {
if (unescape('%' + i.toString(16)) == c)
return i;
}
return null;
}
function Keyboard(oEvent, oSource) {
this.textInputSource = oSource;
this.oEvent = oEvent;
this.cursorPosition = function () {
//var textarea = document.getElementById("myTextArea");
var start=0, end=0;
if (typeof this.textInputSource.selectionStart == "number"
&& typeof this.textInputSource.selectionEnd == "number") {
// Non-IE browsers and IE 9
start = this.textInputSource.selectionStart;
end = this.textInputSource.selectionEnd;
}
else if (document.selection && document.selection.createRange) {
// For IE up to version 8
var selectionRange = document.selection.createRange();
var textInputRange = this.textInputSource.createTextRange();
var precedingRange = this.textInputSource.createTextRange();
var bookmark = selectionRange.getBookmark();
textInputRange.moveToBookmark(bookmark);
precedingRange.setEndPoint("EndToStart", textInputRange);
start = precedingRange.text.length;
end = start + selectionRange.text.length;
}
return {
start: start,
end: end
}
}
}
/// <summary>Global Variable Class</summary>
function GlobalVariable() {
this.bd = new Letter_Information();
this.currentLanguage = "bn_BD";
this.operaDetected = false;
this.replaceLastChar = false; // eita ka er por h dile kha( khata) likha hoe jai ei typer support ditey lagbe
this.ZWNJ = "\u200c";
this.ZWJ = "\u200d";
this.letterKeyMap =
[
["\u09be", "\u0985"], // aa-kar and onamika......... A
["\u09ac", "\u0981"], // bandorban and chondrobindu..... B
["\u099a", "\u099b"], // chirokaal and chobi...... C
["\u09a1", "\u09a6"], // dahu and dekha...... D
["\u09c7", "\u09c8"], // emni and oirabot...... E
["\u09ab", "\u09a5"], // ful and thimpu...... F
["\u0997", "\u0998"], // gotokal and ghatshila...... G
["", "\u09b9"], // ____ and hotath...... H
["\u09bf", "\u09c0"], // ishrat and iishaan...... I
["\u099c", "\u099d"], // jonogon and jhargram...... J
["\u0995", "\u0996"], // kotha and khagrachori...... K
["\u09b2", "\u09b6"], // lalmonirhaat and shorot...... L
["\u09ae", "\u0983"], // minisha and dukkho...... M
["\u09a8", "\u09a3"], // notun and notto-bidhan...... N
["\u09cb", "\u09cc"], // oli and oushodh...... O
["\u09aa", "\u09ab"], // polashi and farlin...... P
["\u09cd", "\u09dd"], // hasanta and ashaar...... Q
["\u09b0", "\u09dc"], // rinita and jhor....... R
["\u09b8", "\u09b7"], // seoul and sholoi-december...... S
["\u099f", "\u09A4"], // tipaimukh and tutul...... T
["\u09c1", "\u09c2"], // uttom and usha...... U
["\u09ad", "\u0982"], // vrammoman and itong-bitong...... V
["\u09c3", "\u09a7"], // rii-kar and dhakesshori...... W
["\u0999", "\u099e"], // 5th and 10th consonant...... X
["\u09df", "\u09cd\u09af"], // ayan and z-fola...... Y
["\u09af", "\u09ce"], // zoti and khanda-ta...... Z
];
this.numberKeyMap =
[
"\u09e6", "\u09e7", "\u09e8", "\u09e9", "\u09ea", "\u09eb", "\u09ec", "\u09ed", "\u09ee", "\u09ef"
];
}
/// <summary>Letter Information Class</summary>
function Letter_Information() {
;
}
/* <summary>
format: bengali letter, type, follower
Types of letters in bd =
1 = consonant
2 = vowel in kar form
3 = fola
4 = hasanta
5 = zero width non joiner
6 = mandatory end like khanda-ta
7 = vowel in Full form
</summary>
*/
Letter_Information.prototype.letter_info =
[
["\u200d", 5, ""], ["\u0964", 1, "\u002e"], ["\u0981", 6, ""], ["\u0982", 6, ""], ["\u0983", 6, ""], ["\u0985", 7, ""], ["\u0986", 7, "\u200d\u09BE"], ["\u0987", 7, "\u200d\u09bf"], ["\u0988", 7, "\u200d\u09c0"], ["\u0989", 7, "\u200d\u09c1"], ["\u098a", 7, "\u200d\u09c2"], ["\u098b", 7, "\u200d\u09c3"], ["\u098f", 7, "\u200d\u09c7"], ["\u0990", 7, "\u200d\u09c8"], ["\u0993", 7, "\u200d\u09cb"], ["\u0994", 7, "\u200d\u09cc"], /*kobor*/["\u0995", 1, "\u0996"], ["\u0996", 1, ""], ["\u0997", 1, "\u0998"], ["\u0998", 1, ""], ["\u0999", 1, ""], /*cholonto*/["\u099a", 1, "\u099b"], ["\u099b", 1, ""], ["\u099c", 1, "\u099d"], ["\u099d", 1, ""], ["\u099e", 1, ""], /*tonkar*/["\u099f", 1, "\u09a0"], ["\u09a0", 1, ""], ["\u09a1", 1, "\u09a2"], ["\u09a2", 1, ""], ["\u09a3", 3, ""], /*tutul*/["\u09a4", 1, "\u09a5"], ["\u09a5", 1, ""], ["\u09a6", 1, "\u09a7"], ["\u09a7", 1, ""], ["\u09a8", 1, ""], /*paloan*/["\u09aa", 1, "\u09ab"], ["\u09ab", 1, ""], ["\u09ac", 3, "\u09ad"], ["\u09ad", 1, ""], ["\u09ae", 1, ""], ["\u09af", 3, ""], ["\u09b0", 3, "\u09dc"], ["\u09b2", 1, ""], /*shosank*/["\u09b6", 1, ""], ["\u09b7", 1, ""], ["\u09b8", 1, "\u09b6"], ["\u09b9", 1, ""], /*ami-amra*/["\u09be", 2, "\u0986"], ["\u09bf", 2, "\u0987"], ["\u09c0", 2, "\u0988"], ["\u09c1", 2, "\u0989"], ["\u09c2", 2, "\u098a"], ["\u09c3", 2, "\u098b"], ["\u09c7", 2, "\u098f"], ["\u09c8", 2, "\u0990"], ["\u09cb", 2, "\u0993"], ["\u09cc", 2, "\u0994"], ["\u09cd", 4, "\u09cd\u200c"], ["\u09ce", 6, "\u0988"], ["\u09d7", 2, "\u0988"], ["\u09dc", 1, "\u09dd"], ["\u09dd", 1, ""], ["\u09df", 1, ""], ["\u09f7", 1, "\u002e"], ["\u09fb", 1, ""], ["\u09fc", 1, ""]
];
/// <summary>binary search for a follower value</summary>
Letter_Information.prototype.getFollower = function (inputValue, propertyNo) {
var start = 0;
var end = this.letter_info.length - 1;
var mid = Math.floor((end + start) / 2);
for (; end >= start; mid = Math.floor((end + start) / 2)) {
if (this.letter_info[mid][0] == inputValue)
return this.letter_info[mid][propertyNo];
if (this.letter_info[mid][0] > inputValue)
end = mid - 1;
else
start = mid + 1;
}
return "";
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |