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

Use fontawesome icons #701

Closed
Sch-Tim opened this issue Oct 29, 2018 · 7 comments
Closed

Use fontawesome icons #701

Sch-Tim opened this issue Oct 29, 2018 · 7 comments

Comments

@Sch-Tim
Copy link

Sch-Tim commented Oct 29, 2018

How can I use Font Awesome icons as keyboard keys?
I tried the unicode but without success. If I do so it doesn't show anything.

@Mottie
Copy link
Owner

Mottie commented Oct 29, 2018

Hi @Akhanto!

Check out this demo:

CSS

.ui-widget .ui-keyboard-bat,
.ui-widget .ui-keyboard-cat,
.ui-widget .ui-keyboard-ghost {
  /* override jquery ui font setting */
  font-family: "Font Awesome 5 Pro";
}
.ui-keyboard-bat span,
.ui-keyboard-cat span,
.ui-keyboard-ghost span {
  display: none;
}
.ui-keyboard-bat:before {
  content: '\f6b5';
}
.ui-keyboard-cat:before {
  content: '\f6be';
}
.ui-keyboard-ghost:before {
  content: '\f6e2';
}

JS

$(function() {
  $("#keyboard").keyboard({
    css: {
      buttonDefault: "fas"
    },
    layout: "custom",
    customLayout: {
      default: ["bat cat ghost", "{accept} {cancel}"]
    }
  });
});

Including the buttonDefault: 'fas' is optional. If included, the icons will appear solid and outlined when hovered. Without it the icons are outlined. I didn't test all icons, just reporting what I see with the 3 in the demo.

@Sch-Tim
Copy link
Author

Sch-Tim commented Oct 29, 2018

Great, thank you!
Unfortunately I don't own a pro license so I had to use Free instead of Pro and fas (or manually adding font-weight: 900) is not optional.
Do you have an idea how I could realize stacking?

@Mottie
Copy link
Owner

Mottie commented Oct 29, 2018

Oh, I forgot to mention that you can also include HTML in the display option; but it only works for action keys (I'll probably need to fix this) - demo:

$(function() {
  // This is entered when the user pressed the {spider} key
  $.keyboard.keyaction.spider = "x";

  $("#keyboard").keyboard({
    css: {
      buttonDefault: "fas"
    },
    layout: "custom",
    customLayout: {
      default: ["bat cat ghost {spider}", "{accept} {cancel}"]
    },
    display: {
      spider: '<i class="fas fa-spider"></i>'
    }
  });
});

@Sch-Tim
Copy link
Author

Sch-Tim commented Oct 29, 2018

Ha, perfect! In my case I only need it for action keys so it's no problem.

@Sch-Tim
Copy link
Author

Sch-Tim commented Oct 29, 2018

Your example works great but when I try to realize stacked icons the script crashes.
'<span class="fa-stack fa-2x"><i class="fas fa-hourglass fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x" style="color: tomato;"></i></span>'

@Mottie
Copy link
Owner

Mottie commented Oct 29, 2018

When a colon (:) is included in the display option, it is mistaking it for a tooltip label. Try this instead (demo):

'<span class="fa-stack fa-2x"><i class="fas fa-hourglass fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x"></i></span>'
.ui-keyboard-button .fa-ban {
  color: tomato;
}

@Sch-Tim
Copy link
Author

Sch-Tim commented Nov 2, 2018

Thank you, that makes sense

@Sch-Tim Sch-Tim closed this as completed Nov 2, 2018
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