Comparing version 0.1.0 to 0.2.0
@@ -10,3 +10,3 @@ // Generated by CoffeeScript 1.8.0 | ||
'use strict'; | ||
var EventEmitter, MapNokia, | ||
var EventEmitter, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -17,4 +17,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
MapNokia = require('./MapNokia.js').MapNokia; | ||
exports.Keypad = (function(_super) { | ||
@@ -25,2 +23,12 @@ __extends(_Class, _super); | ||
/** | ||
Name of selected map | ||
@property map_name | ||
@type String | ||
@default 'nokia' | ||
*/ | ||
_Class.prototype.map_name = 'nokia'; | ||
/** | ||
Full typed in text | ||
@@ -76,2 +84,32 @@ @property text | ||
/** | ||
List of available cases | ||
@static | ||
@property caselist | ||
@type Object | ||
*/ | ||
_Class.caselist = ['Abc', 'abc', 'ABC', '123']; | ||
/** | ||
Uppercase of lowercase | ||
@property case | ||
@type String | ||
@default 'Abc' | ||
*/ | ||
_Class.prototype["case"] = null; | ||
/** | ||
Characters that interrupt a sentence | ||
@property interrupt_case | ||
@type String | ||
@default '.\n' | ||
*/ | ||
_Class.prototype.interrupt_case = '.\n'; | ||
/** | ||
12-key keyboard layout emulation, similar to one that is used in mobile phones | ||
@@ -84,3 +122,3 @@ @class Keypad | ||
function _Class(options) { | ||
var key, val; | ||
var KeyMap, key, val; | ||
if (options == null) { | ||
@@ -93,3 +131,5 @@ options = {}; | ||
} | ||
this.mapping = MapNokia; | ||
KeyMap = require("./Map" + (this.map_name[0].toUpperCase()) + (this.map_name.slice(1)) + ".js").KeyMap; | ||
this.mapping = KeyMap; | ||
this["case"] = exports.Keypad.caselist[0]; | ||
this.on('push', (function(_this) { | ||
@@ -114,2 +154,5 @@ return function(key) { | ||
} | ||
if (key === 'c') { | ||
return this.Backspace(); | ||
} | ||
if (this.mapping[key] == null) { | ||
@@ -128,2 +171,5 @@ throw new Error("This key code was not found in mapping: '" + key + "'"); | ||
this.character = this.mapping[key][0]; | ||
if (this.character === 'CASE') { | ||
return this.LoopCase(); | ||
} | ||
return this.ResetTimeout(); | ||
@@ -134,2 +180,52 @@ }; | ||
/** | ||
Remove last character | ||
@method Backspace | ||
*/ | ||
_Class.prototype.Backspace = function() { | ||
this.character = null; | ||
if (this.text.length === 0) { | ||
return null; | ||
} | ||
return this.text = this.text.slice(0, -1); | ||
}; | ||
/** | ||
Looping through available cases | ||
@method LoopCase | ||
*/ | ||
_Class.prototype.LoopCase = function() { | ||
var current_index; | ||
this.character = null; | ||
current_index = exports.Keypad.caselist.indexOf(this["case"]); | ||
if (exports.Keypad.caselist[current_index + 1] != null) { | ||
return this["case"] = exports.Keypad.caselist[current_index + 1]; | ||
} | ||
return this["case"] = exports.Keypad.caselist[0]; | ||
}; | ||
/** | ||
Returns character that will be inserted, with current case | ||
@method GetInsertCharacter | ||
@param {String} text Selected (typed) string | ||
*/ | ||
_Class.prototype.GetInsertCharacter = function(text) { | ||
if (text == null) { | ||
text = this.character; | ||
} | ||
if (text == null) { | ||
return null; | ||
} | ||
if (this["case"][0] === 'A') { | ||
text = text.toUpperCase(); | ||
} | ||
return text; | ||
}; | ||
/** | ||
Apply selected (typed) text | ||
@@ -141,10 +237,18 @@ @method InsertCharacter | ||
_Class.prototype.InsertCharacter = function(text) { | ||
var inserted; | ||
if (text == null) { | ||
text = this.character; | ||
} | ||
if (!text) { | ||
if (text == null) { | ||
return; | ||
} | ||
this.text += text; | ||
return this.character = null; | ||
inserted = this.GetInsertCharacter(); | ||
this.text += inserted; | ||
this.character = null; | ||
if (this["case"] !== 'ABC') { | ||
this["case"] = 'abc'; | ||
} | ||
if (this["case"] !== 'ABC' && (this.interrupt_case.indexOf(inserted)) >= 0) { | ||
return this["case"] = 'Abc'; | ||
} | ||
}; | ||
@@ -151,0 +255,0 @@ |
@@ -10,12 +10,12 @@ // Generated by CoffeeScript 1.8.0 | ||
'use strict'; | ||
exports.MapNokia = { | ||
exports.KeyMap = { | ||
'1': ['.', ',', '?', '!', '\'', '"', '1', '-', '(', ')', '@', '/', ':', '_'], | ||
'2': ['a', 'b', 'c', '2'], | ||
'3': ['d', 'e', 'f', '3'], | ||
'4': ['g', 'h', 'i', '4'], | ||
'5': ['j', 'k', 'l', '5'], | ||
'6': ['m', 'n', 'o', '6'], | ||
'7': ['p', 'q', 'r', 's', '7'], | ||
'8': ['t', 'u', 'v', '8'], | ||
'9': ['w', 'x', 'y', 'z', '9'], | ||
'2': ['a', 'b', 'c', '2', 'ä', 'æ', 'å', 'à', 'á', 'â', 'ã', 'ç'], | ||
'3': ['d', 'e', 'f', '3', 'è', 'é', 'ê', 'ð'], | ||
'4': ['g', 'h', 'i', '4', 'ì', 'í', 'î', 'ï'], | ||
'5': ['j', 'k', 'l', '5', '£'], | ||
'6': ['m', 'n', 'o', '6', 'ö', 'ø', 'ò', 'ó', 'ô', 'õ', 'ñ'], | ||
'7': ['p', 'q', 'r', 's', '7', 'ß', '$'], | ||
'8': ['t', 'u', 'v', '8', 'ù', 'ú', 'û', 'ü'], | ||
'9': ['w', 'x', 'y', 'z', '9', 'ý', 'þ'], | ||
'*': [], | ||
@@ -22,0 +22,0 @@ '0': [' ', '0', '\n'], |
{ | ||
"name": "keypad", | ||
"description": "12-key keyboard layout emulation, similar to one that is used in mobile phones", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"repository": "https://github.com/muchweb/keypad", | ||
@@ -6,0 +6,0 @@ "license": "GPL-3.0+", |
@@ -1,5 +0,14 @@ | ||
# Keypad | ||
# Keypad [](https://travis-ci.org/muchweb/keypad) [](http://badge.fury.io/js/logsack-core)  | ||
12-key keyboard layout emulation, similar to one that is used in mobile phones. | ||
Nokia mappings were manually typed to match (both are confirmed to use the same mapping): | ||
- Nokia 5220 | ||
- Nokia X3-02 | ||
Sony Ericsson mapping was typed in from this model: | ||
- Sony Ericsson C902 | ||
## Usage | ||
@@ -6,0 +15,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
52436
13
269
58
2