-
Notifications
You must be signed in to change notification settings - Fork 329
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
typography field with transport postMessage not working as expected #1186
Comments
@aristath Your plugin/toolkit is really cool and useful. Thank you for your job! I really hope, that this issue will be fixed soon! It would be really cool to change the font without refreshing of the page. |
If you use postMessage on any field (not just typography) use js_vars or write some jQuery. And there will be a delay because the choice of font is not pre-loaded. Not even easy google fonts plugin does that. https://aristath.github.io/kirki/docs/arguments/js_vars.html |
Just to be clear: there is nothing to fix as it is working correctly. |
Oops, you set the transport to 'auto' for typography fields. Then it works without writing js_vars but there is a delay while the loading of google fonts. This is normal. |
@carasmo I am sorry for the delay with the answer. But I've tried both variants - using 'auto' and using 'postMessage' for transport. And in both situations - it's still refreshing the page. It's a definitely refresh, not a small delay with loading font. And actually in Easy Google Fonts I did not saw that refresh, even if it loads the font from google api. So I am thinking, what I did wrong. And why the issue is 'Open' if it's not an issue and there is nothing to fix. Thank you. |
I am also confused on what @carasmo means. Because no matter what I do, even using @carasmo If you can tell me how you are keeping the typography field from reloading the full page, please let us know. |
Quick update. I am now running the latest dev version of Kirki, and I tried everything from using transport "auto", "postMessage, each with and without js_vars. No matter what I do, the page always reloads. @carasmo Can you post your code snipped, which works for you without refreshing the page?This way we can see where our mistake is. |
@carasmo I am also thinking now, that it would be great if you can provide some example of the working code as @kmob2 suggested. I've struggled with that issue, and did not get the result which I expected. Hope you can help us , and share with us your working snippet. I've read all the parts of your documentation, also tried to find solution in the web to fix that problem, but unfortunately without results... Again , Thank you. |
I just tried Easy Google fonts again, you are right, there is no delay. I was seeing a refresh. It's been about 2-3 months since I used it. I see that they have a customize-preview.js file that writes the google font to the head. So this is what I used for Typography. There is no delay on all fields except the google fonts, which does refresh.
|
Thank you for posting your code snipped. I just tried it and unfortunately it does refresh the page, just as before. I am not sure why this seems to work for you, but not for the rest of us. Just to clarify, that there is absolutely not misunderstanding. The code you posted, creates a typography field for you, and when you switch between different font types, it does NOT refresh the page, and still applies the new font to the preview website? I had a look at the Easy Google fonts plugin, and their way is exactly as I would expect Kirki to work, no refreshing of the page, and no delays. |
In my previous post with the code I wrote that all Typography fields except the font-family has no delay. That is that yes, there is a delay when choosing a font. I am not the author of Kirki, just a user. The author is updating the plugin as he is available to do so. Easy Google Fonts is something I haven't used in a few months, so between now and then, they added some nice js to load the font with js for live preview. |
Ah yes, so I assume when you say "delay", that you refer to the page being refreshed? I thought you were talking about a delay in fetching the google fonts via API. I think this is what lead a my misunderstanding. |
Yes, by delay I mean refresh because of getting the google fonts. Easy Google Fonts uses js to add the font for preview. |
When changing the font-family we have to get the new font-family scripts from the google-API. |
This thread prompted me to switch things around. I used: https://github.com/typekit/webfontloader with my limited choice font selection. I didn't use the Kirki Typography. I used https://github.com/devinsays/customizer-library just for font selection (not actually Typography), I stripped out all other customizer stuff, since that is for Kirki, then I made my own list of fonts and added missing ones. I did this as a work around so I could add the weights of my choice. That is the user selects Raleway they get 300, 400, and 700 and italic if it's there (I don't want all the weights on all fonts in my list). Then I added webfontloader script and the list of fonts I wanted in my customizer.js. It's instant.
|
Hmmm... Have you tried if the webfontloader allows updating the fonts instantly without a delay? WebFont.load({
google: {
families: ['Droid Sans', 'Droid Serif']
}
}); So I'm assuming you're changing the array of fonts there. |
I also went ahead and created my own temporary field until this is solved.
I basically create an array in PHP with Google fonts and web safe fonts. If a web safe font is selected, there is no need for an API call, if a Google font is selected, then I use jquery for this: Works like a charm. Only downside with my solution, I don't cross reference the font family with the supported font-weights. To be honest, I don't really need that. I have a slider field below the font-family, which goes from 100-900 (in steps of 100). If a font supports a certain font weight, just slide the font-weight and see if a change occurs. CSS will always fallback to the closest available font-weight if the current selected font-weight is not available.
|
Update: This solution also contains the web safe fonts, as mentioned here: #1189 |
Easy google fonts has another way, looks great.. The way they do the implementation of changing fonts is similar to Kirki. If I choose a paragraph font, Open Sans, and then I choose the weight as 400, then strong will be the fake bold and not 700 or whatever it is. When I was doing this, I removed all local installs of any google fonts to make sure I wasn't seeing the wrong thing. |
Works with Web Font Loader, instead of loading all of them.
|
@carasmo that looks great, thanks for checking into that! |
I wanted to do this in 3.0 but there's lots of other things in this version so I'll move this to the 3.1 milestone. |
I had some free time today so I implemented this in 3.0, and I have to say it's pretty cool! Too bad it took me so long to fix this 👍 |
Hi @aristath,
Is there any other way to force all variants, perhaps ? |
Duplicate of #1420, we'll continue the discussion there. |
Issue description:
When I use the typography field with transport postMessage, it doesn't work as I would expect it.
When selecting a font family, it will ALWAYS refresh the page. When I change any of the other typography sub fields, such as font size or color, nothing happens unless I change the font family, so that it refreshes, and only then are all the other changed options applied as well.
When I set the typography field to transport refresh, then the page refreshes on every single change on any sub field, which is as expected.
Version used:
Latest github version. Tested older versions from 2 months ago. Same issue
Using theme_mods or options?
theme_mods
Code to reproduce the issue (config + field(s))
The text was updated successfully, but these errors were encountered: