Mathjax delay rendering code inside spoilers - mathjax

I am trying to render mathjax for visible elements in the following. I hid the answers and would like to render math only when someone clicks on the button. Currently mathjax is doing fantastic job even rendering math inside spoilers. Davide (mathjax) suggested a solution but I could not get what he suggested. Can anyone help me with this? The goal is to render mathjax as fast as possible. Code I am using https://cdn.jsdelivr.net/gh/srk7774/cg/mj3_chtml.js
Please make necessary changes to the html code so that I can understand it better.
Davide's suggestion:
https://groups.google.com/g/mathjax-users/c/Xr-arJPN2kI
Site:
https://www.campusgate.in/2011/11/permutations.html
<span class="q-box">1</span>How many arrangements can be made of the letters of the word “ASSASSINATION”? In how many of them are the vowels always together?<br />
<span class="step">A</span>$\dfrac{{13!}}{{{{\left( {4!} \right)}^2}}},\;\dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}}$<br />
<span class="step">B</span>$\dfrac{{13!}}{{6! \times 7!}},\;\dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}}$<br />
<span class="step">C</span>$\dfrac{{13!}}{{6! \times 7!}},\;\dfrac{{8! \times 6!}}{{6! \times 7!}}$<br />
<span class="step">D</span>$\dfrac{{13!}}{{{{\left( {4!} \right)}^2}}},\;\dfrac{{8! \times 6!}}{{6! \times 7!}}$<br />
<div class="border" id="spoiler1" style="display: none;">Answer: A<br />
<div class="border1" id="spoiler1A" style="display: none;">Explanation:<br />
Total letters in the word $ASSASSINATION$ $=13$<br />
$(SSSS), (AAA), (II), (NN), T, O$<br />
<span class="f-box">Formula:</span>Number of ways of arranging $n$ items of which $p$ are alike, $q$ alike and so on $ = \dfrac{{n!}}{{p! \times q! \times ...}}$<br />
Total number of arrangements $ = \dfrac{{13!}}{{4! \times 3! \times 2! \times 2!}}$ $ = \dfrac{{13!}}{{4! \times 4 \times 3!}}$ $ = \dfrac{{13!}}{{{{\left( {4!} \right)}^2}}} \qquad (1)$ <br />
Vowels in the given word $=AAAIIO$<br />
Let us put them in a box and name it a letter $X$.<br />
$\boxed{AAAIIO}_{\rightarrow{X}}, S, S, S, S, N, N, T $<br />
Now total letters $= 8$<br />
Number of ways of arranging $8$ letters in $8$ places $ = \dfrac{{8!}}{{4! \times 2!}}$<br />
Numebr of ways the vowels in the box arrange themselves $ = \dfrac{{6!}}{{3! \times 2!}}$<br />
Total ways in which all vowels together $ = \dfrac{{8!}}{{4! \times 2!}} \times \dfrac{{6!}}{{3! \times 2!}}$ $ = \dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}} \qquad (2)$<br />
<!-- explanation Ends--></div><button onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''}else{document.getElementById('spoiler1A') .style.display='none'}" title="Click to show/hide content" type="button">Show Explanation</button></div><button onclick="if(document.getElementById('spoiler1') .style.display=='none') {document.getElementById('spoiler1') .style.display=''}else{document.getElementById('spoiler1') .style.display='none'}" title="Click to show/hide content" type="button">Show Answer</button><br />
<br />
<span class="q-box">2</span>In how many ways can the letters of the word ARRANGE be arranged so that two R’s are never together <br />
<span class="step">A</span>900<br />
<span class="step">B</span>360<br />
<span class="step">C</span>120<br />
<span class="step">D</span>1260<br />
<div class="border" id="spoiler2" style="display: none;">Answer: A<br />
<div class="border1" id="spoiler2A" style="display: none;">Explanation:<br />
<img border="0" data-original-height="277" data-original-width="422" src="https://1.bp.blogspot.com/-3LjCBAS8QzE/Xcw3ipNYQLI/AAAAAAAAepc/R70tcTQd5j8g2wLmpmBuY-0tCv8tYq7pwCLcBGAsYHQ/s1600/aarr11%2B%25282%2529.png" /><br />
$ARRANGE$ $=(AA), (RR), N, G, E$<br />
Two R’s are never together $=$ (Total possible arrangements) $-$ (Two R’s are always together)<br />
Total number of arrangements = $\dfrac{{7!}}{{2! \times 2!}}$ = $\dfrac{{7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1}}{{2 \times 2}}$ $= 1260$<br />
<br />
Arrangements with both R’s together:<br />
Let us put both $R$'s are in a box and name it letter $X$.<br />
$\boxed{RR}_{\rightarrow{X}}, A, A, N, G, E $<br />
Number of ways of arranging above $6$ letters = $\dfrac{{{\text{6}}!}}{{{\text{2}}!}}$ $= 360$<br />
(Note: Two $R$'s in the box arrange only one way)<br />
<br />
R’s never together $= 1260 - 360 = 900$<br />
<!-- explanation Ends--></div><button onclick="if(document.getElementById('spoiler2A') .style.display=='none') {document.getElementById('spoiler2A') .style.display=''}else{document.getElementById('spoiler2A') .style.display='none'}" title="Click to show/hide content" type="button">Show Explanation</button></div><button onclick="if(document.getElementById('spoiler2') .style.display=='none') {document.getElementById('spoiler2') .style.display=''}else{document.getElementById('spoiler2') .style.display='none'}" title="Click to show/hide content" type="button">Show Answer</button><br />
<br />

Fortunately it's possible to do what Davide suggested (which I believe is the best approach) without too much knowledge of JS and HTML. The code snippet you linked tells MathJax not to render inside of an element with the tex2jax_ignore class, so you can add this class to your spoiler divs. Taking the div with id spoiler1A as an example, you would set class="border1 tex2jax_ignore" to prevent MathJax from typesetting that element when the page loads. You would also add tex2jax_ignore to every element you do not want rendering inside of.
Then you need to tell MathJax to render the math inside the spoiler when it is shown. To set that up, you'll want to define this function based off the one in MathJax documentation - I'm guessing you might want to put it in a script tag after the script tag that loads https://cdn.jsdelivr.net/gh/srk7774/cg/mj3_chtml.js:
<script>
function typeset(id) {
MathJax.startup.promise = MathJax.startup.promise
.then(() => MathJax.typesetPromise([id]))
.catch((err) => console.log('Typeset failed: ' + err.message));
return MathJax.startup.promise;
}
</script>
Finally, you need to change the onclick handler for the button that shows the math: instead of onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''}else{document.getElementById('spoiler1A') .style.display='none'}",
you could write onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''; document.getElementById('spoiler1A').classList.remove('tex2jax_ignore');typeset('spoiler1A')}else{document.getElementById('spoiler1A') .style.display='none'}".
This removes the tex2jax_ignore class and calls the typeset method we defined to tell MathJax to render that element.

Related

How can I find the element in this page for scraping?

The website is basically a colour swatch as can be seen here:
https://prnt.sc/sux913
Once I get to this page I need to to go through all colours and for the program to provide me with the stock quantity for a size i've specified. (Sometimes somebody wants to know the available quantity in all colours in a large.). At this point i'm pretty lost as i can't find the element i'm meant to be referencing in my code. If the specified size is 'L' , i need to go through each colour and provide the Qty for L. For example, Black L - 9, Navy L - 23, Red L - 334
<div class="prod__options">
<span class="attr_text">1.Pick a Color</span>
<p id="prod_color_swatch_area_id" class ="prod_color_swatch_area">
<a id="prod_color_box_Black" href ="javaScript: categoryDisplayJS.displayColorSelected('BK ', 'Black'); categoryDisplayJS.displayPDPErrorSection(null,null,null); setCurrentId('prod_color_box_Black'); if(submitRequest()){ cursor_wait();
wc.render.updateContext('ProductPageMatrixDisplay_Context',{'productId':'497940','colorSelected':'Black'});}" title ="Black">
<img src="https://a248.e.akamai.net/f/248/9086/10h/origin-d5.scene7.com/is/image/Hanesbrands/HBI_498P_Black_sw?$productSwatch$" border="1" onclick="setOptions('Black', true)" />
</a>
<a id="prod_color_box_Smoke Gray" href ="javaScript: categoryDisplayJS.displayColorSelected('8Q', 'Smoke Gray'); categoryDisplayJS.displayPDPErrorSection(null,null,null); setCurrentId('prod_color_box_Smoke Gray'); if(submitRequest()){ cursor_wait();
wc.render.updateContext('ProductPageMatrixDisplay_Context',{'productId':'497940','colorSelected':'Smoke Gray'});}" title ="Smoke Gray">
<img src="https://a248.e.akamai.net/f/248/9086/10h/origin-d5.scene7.com/is/image/Hanesbrands/HBI_498P_SmokeGray_sw?$productSwatch$" border="1" onclick="setOptions('SmokeGray', true)" />
</a>
<a id="prod_color_box_Charcoal Heather" href ="javaScript: categoryDisplayJS.displayColorSelected('HL', 'Charcoal Heather'); categoryDisplayJS.displayPDPErrorSection(null,null,null); setCurrentId('prod_color_box_Charcoal Heather'); if(submitRequest()){ cursor_wait();
wc.render.updateContext('ProductPageMatrixDisplay_Context',{'productId':'497940','colorSelected':'Charcoal Heather'});}" title ="Charcoal Heather">
<img src="https://a248.e.akamai.net/f/248/9086/10h/origin-d5.scene7.com/is/image/Hanesbrands/HBI_498P_CharcoalHeather_sw?$productSwatch$" border="1" onclick="setOptions('CharcoalHeather', true)" />
</a>
<a id="prod_color_box_Navy" href ="javaScript: categoryDisplayJS.displayColorSelected('NY', 'Navy'); categoryDisplayJS.displayPDPErrorSection(null,null,null); setCurrentId('prod_color_box_Navy'); if(submitRequest()){ cursor_wait();
wc.render.updateContext('ProductPageMatrixDisplay_Context',{'productId':'497940','colorSelected':'Navy'});}" title ="Navy">
<img src="https://a248.e.akamai.net/f/248/9086/10h/origin-d5.scene7.com/is/image/Hanesbrands/HBI_498P_Navy_sw?$productSwatch$" border="1" onclick="setOptions('Navy', true)" />
The last code i tried was as below:
html_content = requests.get(browser.current_url)
print(browser.current_url) # just to check what the URL is
print(html_content.raise_for_status())
soup = bs4.BeautifulSoup(html_content.text, 'html.parser')
ele_color_swatch = soup.select('#prod_color_swatch_area_id')
print(ele_color_swatch)
However, that just gave:
https://www... (some long url)
None
[]

Accessibility issue with p:select

Using primefaces 5.1, i'm testing my app with WCAG validator and the following code is breaking a guideline:
<p:outputLabel for="selectHowMuch" value="Do you feel edgy lately ?" />
<p:selectOneMenu id="selectHowMuch" value="Yes">
<f:selectItem itemLabel="Argggg" itemValue="3" />
<f:selectItem itemLabel="Yes" itemValue="2" />
<f:selectItem itemLabel="hmmm" itemValue="1" />
<f:selectItem itemLabel="NO!" itemValue="0" />
</p:selectOneMenu>
the broken guideline is
Success Criteria 1.3.1 Info and Relationships (A) Check 91: select
element missing an associated label.
Repair: Add a label element that surrounds the control's label. Set
the for attribute on the label element to the same value as the id
attribute of the control. And/or add a title attribute to the input
element. And/or create a label element that contains the input
element.
Error Line 1, Column 16711:
<select id="_testapp_WAR_testapp001SNAPSHOT_:j_idt3:selectHowMuch_input"
Note that the p:outputLabel actually did help (if i remove it, i get more errors), but it looks like it's not covering the <select> _input label
I also noticed that the same happens for other select components.
Any ideas to get around this ?
Edit: here's my generated code:
<label id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:j_idt62" class="ui-outputlabel ui-widget"
for="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus">Do you feel edgy lately ?</label>
<div id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all">
<div class="ui-helper-hidden-accessible">
<input
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_focus"
type="text" autocomplete="off" />
</div>
<div class="ui-helper-hidden-accessible">
<select
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
tabindex="-1"><option value="3">Argggg</option>
<option value="2">Yes</option>
<option value="1">hmmm</option>
<option value="0">NO!</option></select>
</div>
<label
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_label"
class="ui-selectonemenu-label ui-inputfield ui-corner-all"> </label>
<div
class="ui-selectonemenu-trigger ui-state-default ui-corner-right">
<span class="ui-icon ui-icon-triangle-1-s ui-c"></span>
</div>
<div
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_panel"
class="ui-selectonemenu-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow">
<div class="ui-selectonemenu-items-wrapper"
style="height: auto">
<ul
class="ui-selectonemenu-items ui-selectonemenu-list ui-widget-content ui-widget ui-corner-all ui-helper-reset">
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Argggg">Argggg</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="Yes">Yes</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="hmmm">hmmm</li>
<li
class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all"
data-label="NO!">NO!</li>
</ul>
</div>
</div>
</div>
<script id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_s"
type="text/javascript">$(function(){PrimeFaces.cw("SelectOneMenu","widget__tutorial_WAR_tutorial001SNAPSHOT__j_idt3_selectHowMuch",{id:"_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch",widgetVar:"widget__tutorial_WAR_tutorial001SNAPSHOT__j_idt3_selectHowMuch"})});</script>
Sorry, i have to contrast with the last answer...
In your example, this select does not have an associated label
<select
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
name="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_input"
tabindex="-1"><option value="3">Argggg</option>
<option value="2">Yes</option>
<option value="1">hmmm</option>
<option value="0">NO!</option></select>
There is one label after it who might have been thought for it, but it does not have a for attribute and does not contain the select tag.
<label
id="_tutorial_WAR_tutorial001SNAPSHOT_:j_idt3:selectHowMuch_label"
class="ui-selectonemenu-label ui-inputfield ui-corner-all"> </label>
As I understand, both the input and the select are generated for this one field and only one label is correctly associated with the input. This looks like a bug in primefaces, and you should ask their staff to make some corrections...
Also there would be more correction to do, because the first label should be associated with the select element, and the input element be invisible to screenreaders if I correctly understand.
There is nothing wrong with your markup per se. It conforms to one of the accepted techniques.
http://www.w3.org/TR/2015/NOTE-WCAG20-TECHS-20150226/H44#H44-ex1
Although that example shows use with an <input> element, it is equally valid with a <select> element.
This looks like a bug in your validator. I suggest trying FireEyes http://www.deque.com/products/fireeyes/fireeyes-installation/

ZK: Menubar with Buttons

I got a ZUL Page, which is aligned by a "borderlayout". In "north" I got a Menubar, which is aligned left.
Now I want 2x Buttons and 2x Labels in "north", on the opposite direction of the Menubar (right).
I tried:
<north border="none">
<hbox width="100%">
<menubar id="menubar" width="380px">
<menu label="A">
<menupopup>
<menuitem label="A1"/>
</menupopup>
</menu>
....
</menubar>
<hbox vflex="1" hflex="1" align="center">
<div hflex="1"></div>
<label id="B"/>
<button id="C" label="C" />
<button id="D" label="D" />
<label id="E"/>
</hbox>
</hbox>
</north>
which looks fine, but when I set a value for label "b" or "e", the design gets broken.
h**p://i.imgur.com/HnRnxmj.png
The top part in the image is the right looking one, while the bottom one is screwed up. Any Idea how to fix this? The buttons are "fixed width" while both labels can "grow".
Thanks
Your spacer <div> is eating up all the space. Remove this and then set pack of the <hbox> to end.
This gives you something like that:
...
</menubar>
<hbox vflex="1" hflex="1" align="center" pack="end">
<label id="B"/>
...
As a general note I find it quite helpful to use Firefox/Firebug for debugging those layout issues. So one can easily see which resulting DOM is generated by the ZUL code.

ExpressionEngine Zoo Visitor field with Channel Images outputs four images for every one

I have a Zoo Visitor field called "member_gallery" which is a channel images field. Whenever I show the images, it creates 4 images for each one. However I do not want to output 4 images for each one. I want to output one image for each one. Here is the code I write:
{visitor:member_gallery}
{exp:channel_images:images entry_id="{entry_id}"}
<img src="{image:url:large}" alt="{image:title}" />
{/exp:channel_images:images}
{/visitor:member_gallery}
Here is the markup it spits out
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
To be clear, I do not want to display 4 images for every one. If you couldn't figure that out. To be extremely EXTREMELY clear, here is my question; How do I write this so I only get 1 image for each one I have uploaded, rather than 4? Thank you. I apologize for any confusion.
You don't need to use the channel entries tag within Zoo Visitor...
It looks as though you have a loop inside a loop, hence the duplication. Have you tried removing the channel entries tag?

Float align display:inline problem

<div style="display:inline;">
<textarea rows="10" cols="50"></textarea><br />
<div style="float:right;">remaining characters: 300</div>
It is not working in either firefox or IE. The text remaining characters is not within the "inline" bounds instead goes 100% out of the containing div.
what is the best way of accomplish something like this where text is aligned right in parent div with textarea before that?
Try this.
<div style="display:inline; text-align:right; float:left;">
<textarea cols="50" rows="10"></textarea><br />
remaining characters: 300
</div>

Resources