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

Auto upper/lower case #428

Closed
ZLoG83 opened this issue Jan 15, 2016 · 8 comments
Closed

Auto upper/lower case #428

ZLoG83 opened this issue Jan 15, 2016 · 8 comments

Comments

@ZLoG83
Copy link

ZLoG83 commented Jan 15, 2016

I have used this keyboard in a webapp now. The absolutely topping issue from people is about the keyboard.
It lacks a really nice feature which I hope you will consider to implement.
It would be really nice for a parameter which would enable auto upper-case of the first letter of a word/name.
Just like on iPhone og Android devices. It seems super intuitive.
It should uppercase the first letter - and switch keyboard from from SHIFT to normal state - just like on previously mentioned devices.
If it uppercases a word/name which you manually want to have small - like "Ulrich von Doom" - then you should have the option to manually overwrite and go to "normal".

I am sure that multiple users of this nice keyboard would appreciate this update! :) I know I would.
Thanks for all the time you guys have out in to making this, It's a really nice piece of code :D

@Mottie
Copy link
Owner

Mottie commented Jan 15, 2016

Hi @ZLoG83!

It isn't build-in but you can add a little extra code to customize how the keyboard behaves.

If you look on the home wiki page under "Manipulating text" you'll find this demo which switches the keyboard to the shifted keyset at the beginning and after the user enters period + a space.

$('#keyboard').keyboard({
    visible: function(e, kb, el) {
        if (kb.$preview.caret().start === 0) {
            kb.shiftActive = true;
            kb.showKeySet(el);
        }
    },
    change: function(e, kb, el) {
        var caret = kb.$preview.caret(),
            end = caret.end - 2 >= 0 ? caret.end - 2 : caret.end,
            str = kb.$preview.val().substring(end, caret.end);
        kb.shiftActive = (caret.start === 0 || str.indexOf('. ') >= 0);
        kb.showKeySet(el);
    }
});

If you want it to type in title case, then tweak the code to only look for spaces.

@ZLoG83
Copy link
Author

ZLoG83 commented Jan 16, 2016

That's just wonderful! I will try this ASAP, thanks! :)

@ZLoG83
Copy link
Author

ZLoG83 commented Jan 18, 2016

This works like a charm with spaces... Simply changed the shiftactive criteria to str.indexOf(' ') == 1
The only thing I really miss now is the ability for the user to force the keyboard to lowercase..
When this keyboard activates, it toggles the shift key - which is great.. but if "Victor von Doom" comes to visit, I would like the ability for him to switch to lowercase manually when he wants to type "von".. makes sense? Is that possible?

@ZLoG83
Copy link
Author

ZLoG83 commented Jan 18, 2016

actually it seems that activating this keyboard renders the shift key useless :(

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2016

Oops, sorry about that! I guess I never thoroughly tested that demo 😞

Anyway, try this updated demo.

$(function(){
  $('#keyboard').keyboard({

    visible: function(e, kb) {
      if ($.keyboard.caret(kb.$preview).start === 0) {
        kb.showKeySet('shift');
      }
    },
    change: function(e, kb) {
      var caret = $.keyboard.caret(kb.$preview),
        end = caret.end - 2 >= 0 ? caret.end - 2 : caret.end;
      str = kb.$preview.val().substring(end, caret.end);
      if (!/shift|lock/i.test(kb.last.key)) {
        kb.shiftActive = (caret.start === 0 || str.indexOf('. ') >= 0);
        kb.showKeySet();
      }
    }

  })
  // activate the typing extension
  .addTyping();
});

@ZLoG83
Copy link
Author

ZLoG83 commented Jan 18, 2016

My god that is sexy.. it works 100% as I intended and dreamt of now.. Thank you so much! :D
If you in Denmark some day.. stop by for a cup of cofee and watch the keyboard in real use! :D

@Mottie
Copy link
Owner

Mottie commented Jan 18, 2016

😺

@Mottie
Copy link
Owner

Mottie commented Feb 1, 2016

I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue the discussion in this thread.

@Mottie Mottie closed this as completed Feb 1, 2016
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