Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a extension placed somewhere else #505

Closed
tobiasvandriessel opened this issue Jan 4, 2017 · 10 comments
Closed

Creating a extension placed somewhere else #505

tobiasvandriessel opened this issue Jan 4, 2017 · 10 comments

Comments

@tobiasvandriessel
Copy link

Is it possible to extend the keyboard with additional keys not directly attached to the keyboard? I'd like to place a 'small keyboard' at the top-right of the screen while the main keyboard is at the bottom, the way I did it right now (very hacky) was placing the wanted keys in the keyboard and then moving them to the top right on top of a div with the same background colour. I'd imagine this is not included in the library, but would you know a way even a bit more smart than my hacky way? :P Thanks a lot in advance!

@Mottie
Copy link
Owner

Mottie commented Jan 4, 2017

Hi @tobiasvandriessel!

You can use the extender extension to create a secondary set of keys - see the docs.

The extender keys are added inside of a div with a ui-keyboard-extender class name during the beforeVisible event. You can move that div to the top-right corner using the visible event. Those keys would still be bound to the input.

@tobiasvandriessel
Copy link
Author

tobiasvandriessel commented Jan 5, 2017

Thanks again for your quick reply! Your answer comes very close to the solution, but I'd like to use different sets of keys for the extender, is that possible? Or is it possible to use different extenders?

@Mottie
Copy link
Owner

Mottie commented Jan 5, 2017

The extender is set up to only accept a layout name. So, define a custom layout and save it to the $.keyboard.layouts object. Then pass that name to the extender - demo:

$(function() {

  // this layout is already included in the extender
  // code. It is added here as an example.
  $.keyboard.layouts.numpad = {
    'normal': [
      '{clear} / * -',
      '7 8 9 +',
      '4 5 6 %',
      '1 2 3 =',
      '0 {dec} {left} {right}'
    ]
  };

  $('#keyboard').keyboard({
    layout: 'custom',
    customLayout: {
      'normal': [
        '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
        '{tab} q w e r t y u i o p [ ] \\',
        'a s d f g h j k l ; \' {enter}',
        '{shift} z x c v b n m , . / {shift}',
        '{accept} {space} {cancel} {extender}'
      ],
      'shift': [
        '~ ! @ # $ % ^ & * ( ) _ + {bksp}',
        '{tab} Q W E R T Y U I O P { } |',
        'A S D F G H J K L : " {enter}',
        '{shift} Z X C V B N M < > ? {shift}',
        '{accept} {space} {cancel} {extender}'
      ]
    }
  }).addExtender({
    // choose any layout
    layout: 'numpad',
    // start with extender showing?
    showing: false,
    // reposition keyboard after toggling extender layout
    reposition: true
  });
});

@tobiasvandriessel
Copy link
Author

Thanks for your reply and sorry for being so vague with my question, but what I meant to ask was: Is it possible to define multiple extenders or (multiple) different keysets within one extender and switch between them?

@Mottie
Copy link
Owner

Mottie commented Jan 5, 2017

To add multiple extender layouts, you'll need to reinitialize the extender... I put together this demo; click on the monkey to switch extender layouts.

$(function() {

  var $keyboard = $('#keyboard'),
    // extender layout
  	hexActive = false;

  $.keyboard.layouts.numpad = {
    'normal': [
      '{clear} / * -',
      '7 8 9 +',
      '4 5 6 %',
      '1 2 3 =',
      '0 {dec} {left} {right}'
    ]
  };

  $.keyboard.layouts.hexpad = {
    'normal': [
      'C D E F',
      '8 9 A B',
      '4 5 6 7',
      '0 1 2 3',
      'x {clear} {left} {right}'
    ]
  };

  // switch extender layout
  $.keyboard.keyaction.hex = function(kb) {
    hexActive = !hexActive;
    // toggle hex button
    $keyboard.addExtender({
      layout: hexActive ? 'hexpad' : 'numpad',
      // restore current state of extender
      showing: kb.extender_options.showing
    });
    kb.redraw();
    // update state of hex button
    $('.ui-keyboard-hex').toggleClass(kb.options.css.buttonActive, hexActive);
  };

  $keyboard.keyboard({
    layout: 'custom',
    display: {
    	hex: "&#x1f435;:Hexpad",
      clear: "&#x1f5d1;:Clear",
      extender: " :Toggle Pad"
    },
    customLayout: {
      'normal': [
        '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
        '{tab} q w e r t y u i o p [ ] \\',
        'a s d f g h j k l ; \' {enter}',
        '{shift} z x c v b n m , . / {shift}',
        '{accept} {space} {cancel} {extender} {hex}'
      ],
      'shift': [
        '~ ! @ # $ % ^ & * ( ) _ + {bksp}',
        '{tab} Q W E R T Y U I O P { } |',
        'A S D F G H J K L : " {enter}',
        '{shift} Z X C V B N M < > ? {shift}',
        '{accept} {space} {cancel} {extender} {hex}'
      ]
    }
  }).addExtender({
    // choose any layout
    layout: 'numpad',
    // start with extender showing?
    showing: true,
    // reposition keyboard after toggling extender layout
    reposition: true
  });
});

@tobiasvandriessel
Copy link
Author

Thanks, a lot! :) Now I can rewrite everything to different keysets and extenders, which will probably be way more efficient! :D

@Mottie
Copy link
Owner

Mottie commented Jan 10, 2017

Ugh, sorry, some changes I made in v1.26.9 were making the extender layout shift under the main keyboard. I've fixed this in v1.26.11!

@tobiasvandriessel
Copy link
Author

No problem! :)

@Mottie
Copy link
Owner

Mottie commented Jan 12, 2017

Alrighty, this time I updated the extender code to preserve the keyset and redraw on its own; you'll still need to call the extender function to update the layout... and the hex action key no longer needs to call redraw() - updated demo

$(function() {

  var $keyboard = $('#keyboard'),
    // extender layout
    hexActive = false;

  $.keyboard.layouts.numpad = {
    'normal': [
      '{clear} / * -',
      '7 8 9 +',
      '4 5 6 %',
      '1 2 3 =',
      '0 {dec} {left} {right}'
    ]
  };

  $.keyboard.layouts.hexpad = {
    'normal': [
      'C D E F',
      '8 9 A B',
      '4 5 6 7',
      '0 1 2 3',
      'x {clear} {left} {right}'
    ]
  };

  // switch extender layout
  $.keyboard.keyaction.hex = function(kb) {
    hexActive = !hexActive;
    // update state of hex button
    $('.ui-keyboard-hex').toggleClass(kb.options.css.buttonActive, hexActive);
    // change extender layout
    $keyboard.addExtender({
      layout: hexActive ? 'hexpad' : 'numpad'
    });
  };

  $keyboard.keyboard({
    layout: 'custom',
    display: {
      hex: "&#x1f435;:Hexpad",
      clear: "&#x1f5d1;:Clear",
      extender: " :Toggle Pad"
    },
    customLayout: {
      'normal': [
        '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
        '{tab} q w e r t y u i o p [ ] \\',
        'a s d f g h j k l ; \' {enter}',
        '{shift} z x c v b n m , . / {shift}',
        '{accept} {space} {cancel} {extender} {hex}'
      ],
      'shift': [
        '~ ! @ # $ % ^ & * ( ) _ + {bksp}',
        '{tab} Q W E R T Y U I O P { } |',
        'A S D F G H J K L : " {enter}',
        '{shift} Z X C V B N M < > ? {shift}',
        '{accept} {space} {cancel} {extender} {hex}'
      ]
    }
  }).addExtender({
    // choose any layout
    layout: 'numpad',
    // start with extender showing?
    showing: true,
    // reposition keyboard after toggling extender layout
    reposition: true
  });
});

@tobiasvandriessel
Copy link
Author

Sorry for my late response on your fast response, you're amazing! Going to implement it right away :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants