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

Wrong caret positioning in input with "text-align:center" #436

Closed
nlosinsky opened this issue Feb 20, 2016 · 4 comments
Closed

Wrong caret positioning in input with "text-align:center" #436

nlosinsky opened this issue Feb 20, 2016 · 4 comments

Comments

@nlosinsky
Copy link

Hi,
I found wrong caret positioning in keyboard input when used property "text-align:center". It's shifted to the right regarding to the center. Cursor positioning is OK, but caret.

I guess the problem is in the string:
style.width = parseInt( isInput ? element.scrollWidth : computed.width, 10 ) + ( isInput ? 50 : 0 ) + 'px';
in the file jquery.keyboard.extension-caret.js

Thanks

@Mottie
Copy link
Owner

Mottie commented Feb 20, 2016

Hi @nlosinsky!

Thanks for reporting this problem! I'll see what I can do.

In the mean time, you can set the offsetX to -23 (px) to sort of re-align the caret (it depends on the font-size), but only in Webkit browsers, Firefox works fine - demo: http://jsfiddle.net/Mottie/egb3a1sk/1205/

$(function() {

  $('#keyboard').keyboard({
      usePreview: false
    })
    .addCaret({
      // extra class name added to the caret
      // "ui-keyboard-caret" class is always added
      caretClass: '',
      // *** for future use ***
      // data-attribute containing the character(s) next to the caret
      charAttr: 'data-character',
      // # character(s) next to the caret (can be negative for RTL)
      charIndex: 1,
      // caret position adjustments
      // firefox doesn't need adjustment; webkit does
      offsetX: typeof window.mozInnerScreenX !== 'undefined' ? 0 : -23,
      offsetY: 0
    })
    .addTyping({
      showTyping: true,
      delay: 250
    });

});

I'll see if I can find a better internal fix that doesn't rely on arbitrary numbers.

@nlosinsky
Copy link
Author

Hi @Mottie,

Thanks for so quick reply.

Actually, I have a specific project that focuses only on Chrome browser and I have many inputs with keyboard support with only one constructor for all of them. One part of inputs have left alignment another one - centered. The only workaround I found is setting manually $.keyboard.firefox = true during initializing. It works fine for me, but currently I don't know about possible pitfalls.

@Mottie Mottie closed this as completed in 56b6223 Feb 21, 2016
@Mottie
Copy link
Owner

Mottie commented Feb 21, 2016

Ok, this problem has been fixed and v1.25.21 is now available!

@nlosinsky
Copy link
Author

Great, thank you!

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