UNPKG

rkeys

Version:

A platform for creating tablet/HTML5 virtual-keyboard apps to send keystrokes to remote X11

63 lines (61 loc) 1.93 kB
// mixin to generate a single key // // args: (mandatory) one of the following: // - action // - action label // // action: (mandatory) one of the following: // - a keysym with or without the XK_ prefix eg 'XK_a' or 'a' // - id // a command-id as defined in command yaml // - id:params // command-id with a list of comma-delimited parameters // // Full list of keysyms at https://github.com/sidorares/node-x11/blob/master/lib/keysyms.js // // label: (optional) text string e.g. 'my amazing label' // May include font-awesome classes prefixed with 'fa-' in which case an // icon is displayed. If label isn't supplied then treat action as the label. // mixin key(args, label) - var arr = args.toString().split(' ') - var act = arr[0] - var faw = [] - var txt = [] - words = (label && label.split(' ')) || (arr.length > 1 && arr.slice(1)) || [act] //- console.log(words) each w in words if w && w.substring(0,3) == 'fa-' - faw.push(w) else - txt.push(w) - txt = txt.join(' ') .key.up(id=act, class=attributes.class, title=txt) if faw.length - faw = faw.join(' ') // icon .label i.fa.fa-2x(class=faw) else // text - var cla = 'len-' + txt.toString().length .label(class=cla)= txt // mixin to generate multiple keys // // accepts either // - a space-delimited string of actions e.g. 'q w e r t y' // or // - a list of args for +key // // Any classes or attributes are applied to each key in turn. Examples: // // +keys('a b').z expands to +key('a').z +key('b').z // +keys('a b c').z expands to +key('a').z +key('b').z +key('c').z // +keys('a', 'b').z expands to +key('a').z +key('b').z // +keys('a b', 'c d').z expands to +key('a b').z +key('c d').z // mixin keys(...args) if (args.length == 1) - args = args[0].split(' ') each arg in args +key(arg)&attributes(attributes)