How to randomly assign users a font in a qualtrics survey - qualtrics

I am conducting an experiment on Qualtrics. The font used in the survey is one of the variables I am testing.
I would like to use "MS Serif" to 50% of my participants, and "MS Sans Serif" to the other 50% of participants. These fonts are part of the fonts you can pick in the "look and feel" UI of Qualtrics.
I would also have to record which font each participant saw.
How do I do this?
My first idea was to create two surveys, and just have Mechanical Turk pick one of them randomly. However, my account will only let me have one active survey at a time.

It may depend your theme, but you can try the following.
First, at the top of the Survey Flow, add a randomizer to pick one of two embedded data blocks evenly to give you a 50/50 split. Inside the embedded data blocks assign a font-family to an embedded data variable:
Randomizer
Block 1
fontFamily = 'MS Serif'
Block 2
fontFamily = 'MS Sans Serif'
Then under Look&Feel Advanced, add the following to the Header using Source editing:
<style>
#RestoredResponseBar, .Skin, .Skin .yui-skin-sam .yui-calcontainer,
.Skin button, .Skin input, .Skin select, .Skin textarea {
font-family: ${e://Field/fontFamily};
}
</style>
EDIT:
If the style tag in the header doesn't work for you, you can try adding a custom style using JavaScript in the Header instead:
<script type="text/javascript">
Qualtrics.SurveyEngine.addOnload(function() {
var fontFamily = "${e://Field/fontFamily}";
$('customStyles').update("#RestoredResponseBar, .Skin, "
+ ".Skin .yui-skin-sam .yui-calcontainer, .Skin button, .Skin input, "
+ ".Skin select, .Skin textarea { font-family: " + fontFamily + " }");
});
</script>
Note the change from double to single quotes in the embedded data assignments above.

Related

How to set font-family correctly in a bilingual text in a Nuxt-Strapi app?

Currently I am building a website with nuxt-js. For the back-end of site I am using strapi headless CMS. In article pages of the site I get data (text of articles) from rich text capability of strapi database. So I don't need to define html tags to load the content correctly. The main language of the site is Persian, but there are some English words between sentences. For better design and showing content I used two font-family in my website. The font1 variable in my CSS file is referenced to a Persian font-family and the font2 is referenced to an English font-family. When I use this code in my CSS file:
#app {
font-family: var(--font1), var(--font2);
}
I get this result in the browser page:
As you could see the number 5 in the text is rendered in Persian language (correct format), but the number 8 in laravel-8 word also is rendered in Persian (wrong format). If I change the code to this one:
#app {
font-family: var(--font2), var(--font1);
}
I get the reverse result:
As you could notice none of the above results are correct. If I used html tags in my pages, I could wrap that words in for example span tags and define custom CSS for them. But in my case I don't use html tags and they are rendered automatically by strapi. So how could I fix this issue in my website? Is there any CSS property or any other trick that could solve this problem?
With the help of #nuxtjs/markdownit package, I finally found this solution. After adding that package according to its documentation, we must add html: true in its configuration as the code below:
nuxt.config.js file:
markdownit: {
preset: 'default',
linkify: true,
breaks: true,
injected: true,
html: true,
},
So the texts that we insert in strapi rich-text data could have html tags like span inside. So I can wrap my English words to a span tag with the class of englishText like the text below:
strapi rich text:
در میان ویژگی‌هایی که در CSS برای تعریف کردن 5 استایل استفاده می‌شوند، شاید یکی از جذاب‌ترین و البته گسترده‌ترین آنها <span class="englishText">laravel-8</span> باشد.
Then when we use this.$md.render(this.text); in our nuxt app (suppose that this.text is the data that contains rich-text from strapi) and use that text in our template part, If we define the englishText class in our CSS as the code below:
span.englishText {
/* font2 is the English font and font1 is the Persian font */
font-family: var(--font2), var(--font1);
}
We could get the correct result as this one:

CSS, automatically change styles like size, etc. if font is not found and alternative is used

If the font I am using couldn't be loaded or is not found, the alternate font will be used. If so, I need to change some other styles like font-weight, letter-spacing, font-size, etc.
for example:
div {
font-family:"Lemon",sans-serif;
}
Here Lemon is a really thick font, so the way I style this font might not be suitable for the alternative font. So if the first specified font could not be loaded, how can I change style of the alternative font accordingly?
Caveat: this method should be able to detect whether any non monospaced font is loaded or not.
It appears it is not possible to sense the actual font in use using CSS alone. Taking ideas from font.js highlighted in #Eddie Reeder answer and also from github.com/philoye/fontunstack/tree/master we can measure the required font against another font. I have chosen a monospace font to test against and a string of narrow characters (i) as being the most likely to be different from the required font.
Code like this (which I've deliberately spelled out to make clear what is going on) placed possibly in the head or at the start of body. It could of course be placed in a function to be called at the start and/or made to remove its test divs once the required script has been set up and/or to set CSS variables if that makes more sense than having two separate css style files.
<div id="maybeOurFont" style="font-family: Lemon, monospace; font-size: 100px; position: absolute; left: -9999px; top:0;">iiiiiiiiiiiiiiiiiiii</div>
<div id="testFont" style="font-family: monospace; font-size: 100px; position: absolute; left: -9999px; top:0;">iiiiiiiiiiiiiiiiiiii</div>
<script>
const pathToLemonStyle = "lemonstyle.css"; //replace with your path
const pathToNoLemonstyle = "nolemonstyle.css"; // ditto
const lemonLength = document.getElementById("maybeOurFont").offsetWidth;
const monoLength = document.getElementById("testFont").offsetWidth;
let useThisStyle = pathToLemonStyle;
if ( lemonLength == monoLength ) {
useThisStyle= pathToNoLemonstyle;
}
document.head.append('<style src="' + useThisStyle + '"></style>');
</script>
Using pure CSS, you can't. One option would be to use javascript to detect if a font is installed, then adjust your styles accordingly.
Something like:
$(document).ready(function () {
font.setup(); // run setup when the DOM is ready
if (!font.isInstalled("Lemon")) {
document.getElementById("example-div").style.fontWeight = "900";
}
});
This utilises font.js which must be included in your page.

My attribute selector rule isn't working

I am trying to write a rule to style a navigation item bold when the user is on the page it refers to. I don't have access to the HTML for that page. The rule I have written to get around that issue is:
html link[href="http://www.stuff.com/tagged/patterns"] + a[href="/patterns"] {
font-weight: bold; }
This does not work. Neither does it work using a * instead of the HTML or taking it away altogether, using a > instead of a + or taking it away altogether, or any combination of these options.
This however:
a[href="/patterns"] {
font-weight: bold; }
does make the navigation item I want bold, but it is bold on all pages. Now I just need to get it bold on that one page only. However, I don't see anything else on that one page to refer to other than it's specific url. Is there anyway to write that rule and make it work using only the URL I have?
Thanks.

How to change the font in Markdown cells when they are in Edit Mode?

I want to change the font type in Markdown cells when I am editing them.
How Can I do that?
I can edit the file .jupyter/custom/custom.css and change the font when they are "run":
div.text_cell_render {
font-family: 'Linux Libertine O';
font-size: 12pt;
}
As shown in the figure, the upper half is a Markdown cell in edit mode, and that is the place where I want to change the font.
A simple possibility is
from IPython.display import HTML, display
display(HTML('<style>.CodeMirror{font-family:whatever}</style>')
but beware that the code above changes also the fonts used for
editing cells of code
rendered code cells
Also note, that my simple proposal works on a notebook by notebook base, you have to add the lines to every notebook you want to modify. On the contrary, if you have a custom.css file where it can be accessed by jupiter during startup you can add the font-family:whatever to it, to make the customization hold for every notebook that you are using.
For an example of permanent customization please have a look at this question from Joel Ostblom — in a nutshell, edit ~/.jupyter/custom/custom.css and put in it
.CodeMirror pre {
font-family: "Ubuntu Mono", monospace;
font-size: 14pt;
...
}

organizing font family usage, site colors, etc

If I want to limit font family usage across my site, say to 2 or 3 font different typefaces (e.g. Times, Arial, etc). Is there a way I can organize my CSS so that I have something like
fontType1 is font-family: "Times New Roman", Times, serif;
fontType2 is font-family: Arial, sans-serif
Then for each of my UI elements that I style in the CSS, pick from the available font types, i.e. fontType1, fontType2. Likewise for my set of color choices.
If I change the font-family of fontType1, I want it go all the way across the site/stylesheet. I don't want to have to go into each css declaration and change it. If I want to change one of my site's "dark colors", I want it to go all the way across the site; I don't want to go into each usage of it and change it.
If I understand your issue correctly, the best way (without using a preprocessor) would be:
h1,h2,h3,h4,h5,h6,
.button, .promo{ /* Your list of selectors that need to use this font stack */
font-family:one;
}
p,ul,
.small-print,.error{ /* Your list of selectors that need to use this font stack */
font-family:two;
}
#nav,#footer{ /* Your list of selectors that need to use this font stack */
font-family:three;
}
This doesn't rely on JS, it won't bloat your HTML, and the best thing is that you can update all instances at once :)
This way you only need to add new selectors to your list, and don't have to redefine your families. Have that in a 'Shared' section. I write about it here: http://coding.smashingmagazine.com/2011/08/26/writing-css-for-others/ (do a find for 'Shared').
H
There's no way to do this directly with CSS but it's one of the major features of libraries such as Sass, LESS, and Compass. LESS can be compiled by server-side or client-side Javascript, and Sass is compiled with Ruby. Compass is a library that allows compiling Sass outside the context of a Rails or Ruby web app.
Here's an example of what you can do with Sass:
$color: #4D926F;
#header {
color: $color;
}
h2 {
color: $color;
}
And the CSS that it's compiled into:
#header {
color: #4D926F;
}
h2 {
color: #4D926F;
}
In addition to variables, as shows above, you also get mixins (which are basically functions) and nested selectors.
Have something like so:
.font-type1 { font-family: font1, font2, font3; }
.font-type2 { font-family: font4, font5, font6; }
.font-type3 { font-family: font7, font8, font9; }
And set them on the <body> element.
If you wish to dynamically change it with JavaScript:
HTML
<a class=changefont data-font="font-type1" href=#>Font 1</a>
<a class=changefont data-font="font-type2" href=#>Font 2</a>
<a class=changefont data-font="font-type3" href=#>Font 3</a>
JavaScript
And with javascript (I'm using jQuery for simplicity, can be done with js alone too)
$('.changefont').click(function() { $('body').removeClass().addClass($(this).data('font')); });
Here's an Example!
By changing a higher level ancestor class, you cause a nice cascade (Cascading Style Sheet) over the entire document.
Another way of doing this is adding some classes to UI elements.
CSS:
.fontType1 {font-family: "Times New Roman", Times, serif}
.fontType2 {font-family: Arial, sans-serif}
HTML:
<h1 class="fontType1">Header 1</h1>
<p class="someOtherCssClass fontType2">paragraph text goes here</p>

Resources