Alien-GvaScript

 view release on metacpan or  search on metacpan

test/functional/keyMap/basic.html  view on Meta::CPAN

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <link href="../../test.css" rel="stylesheet" type="text/css">
  <link href="../../images/GvaScript.css" rel="stylesheet" type="text/css">
  <script src="../../../lib/Alien/GvaScript/lib/prototype.js"></script>
  <script src="../../../lib/Alien/GvaScript/lib/GvaScript.js"></script>

  <style type="text/css">
    #current_cell {background-color: blue; color: yellow;}
    tt {font-size:1.2em;background-color:#eee;}
    table {border-width: 2px;}
    td {width: 20px; text-align: center;}
    td.rborder {border-right: 2px solid black;}
    tr.bborder td {border-bottom: 2px solid black;}
  </style>

<script>

function Red(event) {
  $('current_cell').style.backgroundColor="red";
  Event.stop(event);
}

function Up() {
  var cell = $('current_cell');
  var colIndex = cell.cellIndex;
  var row = cell.parentNode;
  if (row.rowIndex > 0) {
    cell.id = null;
    row.parentNode.rows[row.rowIndex - 1].cells[colIndex].id = "current_cell";
  }
}

function Down() {
  var cell = $('current_cell');
  var colIndex = cell.cellIndex;
  var row = cell.parentNode;
  if (row.rowIndex + 1 < row.parentNode.rows.length) {
    cell.id = null;
    row.parentNode.rows[row.rowIndex + 1].cells[colIndex].id = "current_cell";
  }
}

function Left() {
  var cell = $('current_cell');
  if (cell.cellIndex > 0) {
    cell.id = null;
    cell.parentNode.cells[cell.cellIndex - 1].id = "current_cell";
  }
}

function Right() {
  var cell = $('current_cell');
  if (cell.cellIndex + 1 < cell.parentNode.cells.length) {
    cell.id = null;
    cell.parentNode.cells[cell.cellIndex + 1].id = "current_cell";
  }
}

function fill_cell_from_key(event) {
  $('current_cell').innerHTML = event.keyName; 
  Event.stop(event);
}


function say(msg) {
  return function() {alert(msg)};
}


var keymap;
document.observe('dom:loaded', function() {
  var C_X_map = {A: say('A'),
                 B: say('B'),
                 R: GvaScript.KeyMap.Prefix({K: say('Ctrl-X R K'),
                                          O: say('Ctrl-X R O')})};

  var rules   = {UP:     Up, 
                 DOWN:   Down, 
                 LEFT:   Left, 
                 RIGHT:  Right, 
                 RETURN: Red,
                 27:     say('no escape from here'),

                 C_X: GvaScript.KeyMap.Prefix(C_X_map),

                 REGEX: [ ["",   /[0-9]/,             fill_cell_from_key],
                          ["C_", /^[aeiou]$/i,        fill_cell_from_key],
                          [null, "RETURN|TAB|ESCAPE", add_msg           ] ]};

  keymap = new GvaScript.KeyMap(rules);

  keymap.observe("keydown", 'table');

  $('table').focus();
});


function push_grab_all() {
  keymap.rules.push(GvaScript.KeyMap.MapAllKeys(add_msg));
}

function push_ignore_all() {
  keymap.rules.push(GvaScript.KeyMap.MapAllKeys(function () {}));
}

function push_navigate_divs() {
  var cur_div = 3;

  var tmp_rules = {
    UP : function () {
      if (cur_div > 1) {
        document.getElementById("d" + cur_div).style.background = "";
        cur_div -= 1;



( run in 0.329 second using v1.01-cache-2.11-cpan-02777c243ea )