Skip to content

Commit

Permalink
chore(package) v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Sep 23, 2015
1 parent 5ac55ed commit a55ab28
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2015.09.23, v1.3.0

feature:
- (smalltalk) add handling of keys: left, right, up, down


2015.09.23, v1.2.0

feature:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smalltalk",
"version": "1.2.0",
"version": "1.3.0",
"homepage": "https://github.com/coderaiser/smalltalk",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
Expand Down
59 changes: 47 additions & 12 deletions dist/smalltalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,78 @@

function keyDown(dialog, ok, cancel) {
return function (event) {
var ENTER = 13;
var ESC = 27;
var TAB = 9;
var KEY = {
ENTER: 13,
ESC: 27,
TAB: 9,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40
};

var keyCode = event.keyCode,
el = event.target;

var namesAll = ['cancel', 'ok', 'input'],
names = find(dialog, namesAll).map(function (el) {
return getDataName(el);
});

switch (keyCode) {
case ENTER:
case KEY.ENTER:
closeDialog(el, dialog, ok, cancel);
break;

case ESC:
case KEY.ESC:
remove();
cancel();
break;

case TAB:
var namesAll = ['cancel', 'ok', 'input'],
names = find(dialog, namesAll).map(function (el) {
return el.getAttribute('data-name').replace('js-', '');
});

case KEY.TAB:
if (event.shiftKey) tab(dialog, names);

tab(dialog, names);
event.preventDefault();
break;

default:
var is = ['left', 'right', 'up', 'down'].some(function (name) {
return keyCode === KEY[name.toUpperCase()];
});

if (is) changeButtonFocus(dialog, names);

break;
}

event.stopPropagation();
};
}

function getDataName(el) {
return el.getAttribute('data-name').replace('js-', '');
}

function changeButtonFocus(dialog, names) {
var name = '',
active = document.activeElement,
activeName = getDataName(active),
isButton = /ok|cancel/.test(activeName),
count = names.length - 1;

if (count === 2 && isButton) {
if (activeName === 'cancel') name = 'ok';else name = 'cancel';

find(dialog, [name]).forEach(function (el) {
return el.focus();
});
}
}

function tab(dialog, names) {
var active = document.activeElement,
activeName = active.getAttribute('data-name').replace('js-', ''),
activeName = getDataName(active),
count = names.length - 1,
index = names.indexOf(activeName);

Expand Down
2 changes: 1 addition & 1 deletion dist/smalltalk.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/smalltalk.poly.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smalltalk",
"version": "1.2.0",
"version": "1.3.0",
"description": "Promise-based Alert, Confirm and Prompt replacement",
"homepage": "http://github.com/coderaiser/smalltalk",
"repository": {
Expand Down

0 comments on commit a55ab28

Please sign in to comment.