Something went wrong. Try again.
fork of mathquill to add matrix support. used in cartesium
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304<!doctype html><html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=624" />
<title>MathQuill Test Page</title>
<link rel="stylesheet" type="text/css" href="support/home.css" /> <link rel="stylesheet" type="text/css" href="../build/mathquill.css" />
<script type="text/javascript" src="support/jquery-1.5.2.js"></script>
<style type="text/css"> body { font-size: 0.8em; } #body { padding: 1.25em; } h1 { font-size: 2.5em; } td { width: 33%; } #static-latex-rendering-table td { width: 50%; } #show-textareas-button { float: right; } .show-textareas .mq-editable-field.mq-text-mode { overflow: visible; } .show-textareas .mq-textarea textarea { font-size: inherit; clip: auto !important; resize: auto !important; height: auto !important; width: auto !important; top: -45px; }
/* Non-white background test */ .different-bgcolor.mq-editable-field { background: black; color: white; } .different-bgcolor.mq-editable-field .cursor { border-color: white; }
#overflow-test { width: 100px; } </style> </head> <body> <div id="body"> <a href="http://github.com/laughinghan/mathquill" ><img style="position: absolute; top: 0; right: 0; border: 0" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub!" /></a>
<h1> <a href="http://mathquill.github.com">MathQuill</a> Tests <small>local test page</small> </h1>
<button id="show-textareas-button">Show Textareas</button>
<h3>MathQuill Editables</h3>
<p> In all editable fields, the selection should clear and ghost parens should solidify if you click outside, but not if you switch tabs/windows and switch back to this page. </p>
<table id="editables"> <tr> <th colspan="3"> Initial LaTeX <tr> <td> <span class="mathquill-math-field" >\frac{d}{dx}\sqrt{x}=\frac{1}{2\sqrt{x}}</span > </td> <td> <span class="mathquill-text-field" >lolwut $a^2 + b^2 = c^2$. Also, awesomesauce: $\int_0^1 \sin x dx.</span > </td> <td> <span class="mathquill-static-math" >\sqrt{\MathQuillMathField{x^2+y^2}}</span > </td> </tr> </th> </tr> </table>
<p> Touch taps/clicks/mousedown to drag should work anywhere in the blue box: </p> <div class="math-container" style=" border: solid 1px lightblue; height: 5em; width: 15em; line-height: 5em; text-align: center; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); " > <span class="mathquill-math-field" >x_{very\ long\ thing}^2 + a_0 = 0</span > </div>
<h3>Redrawing</h3> <p> <span id="reflowing-test">\sqrt{}</span> should look the same as <span class="mathquill-static-math"> \sqrt{\pi\sqrt\sqrt\frac12} </span> </p> <script type="text/javascript"> $(function () { var count = 0; MQ.MathField($('#reflowing-test')[0], { handlers: { edit: function () { count += 1; } } // also test 'edit' hook }) .focus() .moveToLeftEnd() .keystroke('Right'); var textarea = $('#reflowing-test textarea'); // paste some stuff that needs resizing textarea[0].dispatchEvent(new ClipboardEvent('paste')); textarea.val('\\pi\\sqrt{\\sqrt{\\frac12}}'); setTimeout(function () { if (count !== 1) throw 'reflow not called'; }); }); </script>
<h3>Behavior Options</h3>
<p> <span id="custom-behavior" >x_a^b + \frac{\sqrt[n]{x}}{\frac{1}{2}}</span > </p> <p> Space should behave like Tab, left and right should go through the upper block, sums should start with <code>n=</code>, exponents should require an base, any of <code>+-=<></code> should break out of an exponent, <code>pi</code>, <code>theta</code>, <code>sqrt</code>, and <code>sum</code> should all be auto-commands, but <code>only</code> should be the only auto-operator name (so <code>sin</code> etc. shouldn't automatically become non-italicized). </p>
<script> $(function () { MQ.MathField($('#custom-behavior')[0], { spaceBehavesLikeTab: true, leftRightIntoCmdGoes: 'up', restrictMismatchedBrackets: true, sumStartsWithNEquals: true, supSubsRequireOperand: true, charsThatBreakOutOfSupSub: '+-=<>', autoSubscriptNumerals: true, autoCommands: 'pi theta sqrt sum', autoOperatorNames: 'only' }); }); </script>
<h3>Up/Down seeking and caching</h3>
<p> <span id="seek-test" class="mathquill-math-field"> \frac{1}{\sqrt \sqrt \sqrt \sqrt \sqrt \sqrt x} </span> </p>
<p> ↑ If you hit down from next to the 1, you should end up inside one of the square roots. If you hit up from the right of the x and then hit down again, you should end up where you were. </p>
<h3>Horizontal overflow</h3>
<p> <span id="overflow-test"> \frac{d}{dx}\sqrt{x}=\frac{d}{dx}x^{\frac{1}{2}}=\frac{1}{2}x^{-\frac{1}{2}}=\frac{1}{2\sqrt{x}} </span> (for comparison: <input value="\frac{d}{dx}\sqrt{x}=\frac{d}{dx}x^{\frac{1}{2}}=\frac{1}{2}x^{-\frac{1}{2}}=\frac{1}{2\sqrt{x}}" />) </p>
<script> $(function () { var overflowTest = $('#overflow-test'); MQ.MathField(overflowTest[0]); var width = overflowTest.outerWidth(true); if (width !== 102) { throw 'math field ' + width + 'px wide instead of 102px'; } }); </script>
<h3>Selection Tests</h3>
<p id="selection-tests"> <span class="mathquill-text-field different-bgcolor" >lolwut $a^2 + b^2 = c^2$. $\sqrt{ \left( \frac{1}{2} \right) }$. Also, awesomesauce: $\int_0^1 \sin x dx.</span > </p>
<p> Even in IE<9, the background color of the parens and square root radical should be the background color of the selection. </p>
<p> Static math with mouseEvents set to false should not interact with the mouse: <span class="static-math-no-mouse-events">12 + 34</span> </p>
<p> Even in the case where it has an empty element: <span class="static-math-no-mouse-events">\sqrt{} </span> </p>
<h3>Dynamic mathquill-ification</h3> <table id="dynamic-initial"> <tr> <th colspan="3"> Initial LaTeX <tr> <td> <span >\frac{d}{dx}\sqrt{x} = \frac{d}{dx}x^{\frac{1}{2}} = \frac{1}{2}x^{-\frac{1}{2}} = \frac{1}{2\sqrt{x}}</span > </td> <td> <span >\frac{d}{dx}\sqrt{x} = \frac{d}{dx}x^{\frac{1}{2}} = \frac{1}{2}x^{-\frac{1}{2}} = \frac{1}{2\sqrt{x}}</span > </td> <td> <span >\frac{d}{dx}\sqrt{x} = \frac{d}{dx}x^{\frac{1}{2}} = \frac{1}{2}x^{-\frac{1}{2}} = \frac{1}{2\sqrt{x}}</span > <tr> <td> <span >\frac{ \text{apples} }{ \text{oranges} } = \text{NaN}</span > </td> <td> <span >\frac{ \text{apples} }{ \text{oranges} } = \text{NaN}</span > </td> <td> <span >\frac{ \text{apples} }{ \text{oranges} } = \text{NaN}</span > </td> </tr> </td> </tr> </th> </tr> </table>
<table id="dynamic-reflow"> <tr> <th colspan="3"> <code>MQ(...).reflow()</code> <tr> <td> <span >\sqrt{ \left ( \frac{x^2 + y^2}{2} \right ) } + \binom{n}{k}</span > </td> <td> <span >\sqrt{ \left ( \frac{x^2 + y^2}{2} \right ) } + \binom{n}{k}</span > </td> <td> <span >\sqrt{ \left ( \frac{x^2 + y^2}{2} \right ) } + \binom{n}{k}</span > </td> </tr> </th> </tr> </table>
<h3> Static LaTeX rendering (<code>.mathquill-static-math</code>) tests </h3> <table id="static-latex-rendering-table"> <tr> <td><span class="mathquill-static-math">^{\frac{as}{ }df}</span></td> <td> <span>^{\frac{as}{ }df}</span> <tr> <td><span class="mathquill-static-math">e^{i\pi}+1=0</span></td> <td> <span>e^{i\pi}+1=0</span> <tr> <td> <span class="mathquill-static-math">\sqrt[n]{1}</span> </td> <td> <span>\sqrt[n]{1}</span> <tr> <td> <span class="mathquill-static-math" >\sin ^2x+\sin ^2\left(x\right)+\sin ^2(x)</span > </td> <td> <span>\sin ^2x+\sin ^2\left(x\right)+\sin ^2(x)</span> <tr> <td> <span class="mathquill-static-math">12a\sin b</span> </td> <td> <span>12a\sin b</span> <tr> <td> <span class="mathquill-static-math" >1a^2 \sin b</span > </td> <td> <span>1a^2 \sin b</span> <tr> <td> <span class="mathquill-static-math" >a + \sin b</span > </td> <td> <span>a + \sin b</span> <tr> <td> <span class="mathquill-static-math" >a + b</span > </td> <td> <span>a + b</span> <tr> <td> <span class="mathquill-static-math" >\sum\sin</span > </td> <td> <span>\sum\sin</span> <tr> <td> <span class="mathquill-static-math" >\sum a</span > </td> <td> <span>\sum a</span> <tr> <td> <span class="mathquill-static-math" >(\sin)</span > </td> <td> <span>(\sin)</span> <tr> <td> <span class="mathquill-static-math" >\left(\sin\right)</span > </td> <td> <span >\left(\sin\right)</span > <tr> <td> <span class="mathquill-static-math" >(x)\sin(x)</span > </td> <td> <span >(x)\sin(x)</span > <tr> <td> <span class="mathquill-static-math" >\left(x\right)\sin\left(x\right)</span > </td> <td> <span >\left(x\right)\sin\left(x\right)</span > <tr> <td> <span class="mathquill-static-math" >a \sin b</span > </td> <td> <span >a \sin b</span > <tr> <td> <span class="mathquill-static-math" >-1 + +-2</span > </td> <td> <span >-1 + +-2</span > <tr> <td> <span class="mathquill-static-math" >\left ( n+1 \right ) + \frac{1}{\frac{n}{k}} + \binom{n}{k}</span > </td> <td> <span >\left ( n+1 \right ) + \frac{1}{\frac{n}{k}} + \binom{n}{k}</span > <tr> <td> <span class="mathquill-static-math" >x_{\frac{1}{\frac{2}{3}}}^{\frac{\frac{1}{2}}{3}}</span > </td> <td> <span >x_{\frac{1}{\frac{2}{3}}}^{\frac{\frac{1}{2}}{3}}</span > <tr> <td> <span class="mathquill-static-math" style=" font-size: 14.99px; " >\left(\frac{\frac{\frac{1}{2}}{\frac{3}{4}}}{\frac{\frac{5}{6}}{\frac{7}{8}}}\right)</span > </td> <td> <span >\left(\frac{\frac{\frac{1}{2}}{\frac{3}{4}}}{\frac{\frac{5}{6}}{\frac{7}{8}}}\right)</span > <tr> <td> <span class="mathquill-static-math" style=" font-size: 1.4375em; " >\left| a + \left| b \right| \right|</span > </td> <td> <span >\left| a + \left| b \right| \right|</span > <tr> <td> <span class="mathquill-static-math" style=" font-size: 1.4375em; " >\sqrt{x}+\sqrt{\frac{x}{\frac{ }{\frac{ }{ }}}}+\sqrt{\frac{x}{\frac{ }{\frac{ }{\frac{ }{\frac{ }{ }}}}}}</span > </td> <td> <span >\sqrt{x}+\sqrt{\frac{x}{\frac{ }{\frac{ }{ }}}}+\sqrt{\frac{x}{\frac{ }{\frac{ }{\frac{ }{\frac{ }{ }}}}}}</span > <tr> <td> <span class="mathquill-static-math" >1+\sum_0^n+\sum_{i=0123}^n+\sum_0^{wordiness}</span > </td> <td> <span >1+\sum_0^n+\sum_{i=0123}^n+\sum_0^{wordiness}</span >^M <tr> <td> <span class="mathquill-static-math" >x\ \ \ +\ \ \ y</span > </td> <td> <span >x\ \ \ +\ \ \ y</span >^M <tr> <td> <span class="mathquill-static-math" >\sum _{n=0}^3\cos x</span > </td> <td> <span >\sum _{n=0}^3\cos x</span >^M <tr> <td> <span class="mathquill-static-math" >\vec x + \tilde x + \vec A + \tilde A + \vec{abcd} + \tilde{abcd}</span > </td> <td> <span >\vec x + \tilde x + \vec A + \tilde A + \vec{abcd} + \tilde{abcd}</span >^M <tr> <td> <span class="mathquill-static-math" >\int _{\phi =0}^{2\pi }\int _{\theta =0}^{\pi }\int _{r=0}^{\infty }f(r,\theta ,\phi )r^2\sin \theta drd\theta d\phi </span> </td> <td> <span >\int _{\phi =0}^{2\pi }\int _{\theta =0}^{\pi }\int _{r=0}^{\infty }f(r,\theta ,\phi )r^2\sin \theta drd\theta d\phi </span> <tr> <td> <span class="mathquill-static-math" >\int_0^{\frac{\frac{1}{2}}{3}} \int_0^{\frac{1}{\frac{2}{3}}} \int_0^{\frac{1}{\frac{2}{\frac{3}{\frac{4}{5}}}}}</span > </td> <td> <span >\int_0^{\frac{\frac{1}{2}}{3}} \int_0^{\frac{1}{\frac{2}{3}}} \int_0^{\frac{1}{\frac{2}{\frac{3}{\frac{4}{5}}}}}</span > <tr> <td> <span class="mathquill-static-math" >\overline{abc}</span > </td> <td> <span >\overline{abc}</span > <tr> <td> <span class="mathquill-static-math" >\overleftarrow{abc}</span > </td> <td> <span >\overleftarrow{abc}</span > <tr> <td> <span class="mathquill-static-math" >\overrightarrow{abc}</span > </td> <td> <span >\overrightarrow{abc}</span > <tr> <td> <span class="mathquill-static-math" >\overleftrightarrow{abc}</span > </td> <td> <span >\overleftrightarrow{abc}</span > <tr> <td> <span class="mathquill-static-math" >\overarc{abc}</span > </td> <td> <span >\overarc{abc}</span > <tr> <td colspan="2" > <span id="sixes" ></span> <script> $( function () { var i, sixes = '', start = 10, end = 40; for ( i = start; i <= end; i++ ) { sixes += '<span style="font-size: ' + i + 'px" class="mathquill-math-field">6<\/span>'; } $( '#sixes' ).html( sixes ); $( '#sixes .mathquill-math-field' ).each( function () { MQ.MathField( this ); } ); } ); </script> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </td> </tr> </table>
<p id="paren-alignment"> Parentheses vertical alignment at font sizes ranging from 10px to 24px: <button>Click Me</button> </p> <script> $('#paren-alignment button').click(function () { var html = '<div>'; for (var i = 10; i <= 24; i += 1) { html += i + 'px: <span class="mathquill-static-math" style="font-size:' + i + 'px">\\left(\\left(\\left(\\left(\\left(\\left(\\left( \\right)\\right)\\right)\\right)\\right)\\right)\\right)+\\left(1\\right)+\\left(x\\right)+\\left(y\\right)+\\left(\\frac{1}{2}\\right)+\\left(\\frac{\\frac{1}{x}}{2}\\right)+\\left(\\frac{1}{\\frac{x}{2}}\\right)+\\left(\\frac{\\frac{\\frac{1}{2}}{\\frac{3}{4}}}{\\frac{\\frac{5}{6}}{\\frac{7}{8}}}\\right)</span><br>'; } html += '</div>'; $(html) .insertAfter('#paren-alignment') .find('.mathquill-static-math') .each(function () { MQ.StaticMath(this); }); }); </script>
<h3>Dynamic rendering performance</h3> <p id="latex-render-perf"> LaTeX: <textarea></textarea> <button>→</button> <span class="mathquill-math-field"></span> </p> <p id="html-render-perf"> HTML: <textarea></textarea> <button>→</button> <span class="mq-math-mode"></span> </p>
<p> There should be no space between here <span class="mathquill-static-math"> </span>and here, even in IE8 </p>
<h3>Textcolor</h3>
<p> Colors should match their names: <span class="mathquill-static-math"> \textcolor{#0000FF}{blue} + \textcolor{red}{red} = \textcolor { rgb(255, -10, 255) } {magenta} </span> </p> <p> Nested <code>\textcolor</code>: the 2 should be red, the "a+" green, the 4 blue, and the "+b" green again. <span class="mathquill-static-math"> e^{\textcolor{#FF0000}{2}}\sin(x^\textcolor{#00FF00}{{a+\textcolor{blue}{4}+b}}) </span> </p>
<h3>Adding CSS class</h3> <style type="text/css"> .testclass { background-color: #5a8; border-radius: 5px; padding: 4px; font-weight: bold; color: gold; } </style> <p> Second term should be styled like <span class="testclass">this</span>: <span class="mathquill-static-math"> x+\class{testclass}{y}+z </span> </p>
<h3>substituteTextarea</h3>
<p> In Safari on iOS, this should be focusable but not bring up the on-screen keyboard; to test, try focusing anything else and confirm this blurs: <span id="no-kbd-math"></span> (confirmed working on iOS 6.1.3) </p>
<h3>overrideKeystroke and overrideTypedText</h3>
<p> Should be able to prevent typing in this field: <span id="disable-typing">1+2+3</span> </p>
<p> Should wrap anything you type in '<>': <span id="wrap-typing">1+2+3</span> </p>
<h3>Text mode</h3>
<p> Spaces at the beginning and end of text mode blocks should be visible: <span class="mathquill-static-math">1\text{ And }2</span> </p>
<p> Mutiple consecutive spaces in the middle of a text mode block should not collapse into one space: <span class="mathquill-static-math">\text{three spaces}</span> </p> <ul> <li> [Firefox] Should not change '3' to '33' when you select all and press right arrow. </li> <li>[All Browsers] ctrl-c or cmd-c should not throw an error</li> </ul> <span id="select-all-right-arrow">3</span>
<h3> substituteKeyboardEvents (legacy, use overrideKeystroke and overrideTypedText instead) </h3>
<p> Should be able to prevent cut, typing, and pasting in this field: <span id="disable-typing-ske">1+2+3</span> </p>
<p> Should wrap anything you type in '<>': <span id="wrap-typing-ske">1+2+3</span> </p>
<ul> <li> [Firefox] Should not change '3' to '33' when you select all and press right arrow. </li> <li>[All Browsers] ctrl-c or cmd-c should not throw an error</li> </ul> <span id="select-all-right-arrow-ske">3</span> </div> <script type="text/javascript"> window.onerror = function (err) { console.log(err); // to show up in Selenium WebDriver logs $('html').css('background', 'red'); }; </script> <script type="text/javascript" src="../build/mathquill.js"></script> <script type="text/javascript"> MQ = MathQuill.getInterface(MathQuill.getInterface.MAX);
$('#show-textareas-button').click(function () { $(document.body).toggleClass('show-textareas'); });
//on document ready, mathquill-ify all `<tag class="mathquill-*">latex</tag>` //elements according to their CSS class. $(function () { $('.mathquill-static-math').each(function () { MQ.StaticMath(this); }); $('.static-math-no-mouse-events').each(function () { MQ.StaticMath(this, { mouseEvents: false }); }); $('.mathquill-math-field').each(function () { MQ.MathField(this); }); $('.mathquill-text-field').each(function () { MQ.TextField(this); }); });
// test selecting from outside the mathquill editable var $mq = $('.math-container .mathquill-math-field'); $('.math-container') .mousedown(function (e) { if (e.target === $mq[0] || $.contains($mq[0], e.target)) return; var originalEvent = e.originalEvent; var newEvent = new MouseEvent(originalEvent.type, originalEvent); $mq[0].dispatchEvent(newEvent); }) // test API for "fast touch taps" #622 & #403 .bind('touchstart', function () { var moved = false; $(this) .bind('touchmove.tmp', function () { moved = true; }) .bind('touchend.tmp', function (e) { $(this).off('.tmp'); MathQuill($mq[0]).ignoreNextMousedown(function () { return Date.now() < e.timeStamp + 1000; }); if (moved) return; // note that this happens after .ignoreNextMousedown() // because even if the touch gesture doesn't 'count' as a tap to us, // we still want to suppress the legacy mouse events, else we'd react // fast to some taps and slow to others, that'd be weird var touch = e.originalEvent.changedTouches[0]; MathQuill($mq[0]).clickAt( touch.clientX, touch.clientY, touch.target ); }); });
// Selection Tests document.body.onload = function () { setTimeout(function () { $('#selection-tests .mathquill-text-field').each(function () { var start = +new Date(); $('textarea', this) .focus()[0] .dispatchEvent( new KeyboardEvent('keydown', { key: 'A', ctrlKey: true }) ); console.log( 'Time taken to Select All (should be <50ms):', new Date() - start ); }); }); };
// Dynamic MathQuill-ification // Initial LaTeX $('#dynamic-initial tr').each(function () { var math = $('span', this); if (!math.length) return;
MQ.StaticMath(math[0]); MQ.MathField(math[1]); MQ.MathField(math[2]).revert(); }); // MQ(...).reflow() $('#dynamic-reflow tr').each(function () { var math = $('span', this), td; if (!math.length) return;
td = math.eq(0).parent(); math.eq(0).detach(); MQ.StaticMath(math[0]); math.eq(0).appendTo(td); MQ(math[0]).reflow();
td = math.eq(1).parent(); math.eq(1).detach(); MQ.MathField(math[1]); math.eq(1).appendTo(td); MQ(math[1]).reflow();
td = math.eq(2).parent(); math.eq(2).detach(); MQ.MathField(math[2]).revert(); math.eq(2).appendTo(td); if (MQ(math[2])) throw 'should been have reverted'; });
// Dynamic rendering performance function Avgs() { return { avgs: {}, add: function (k, v) { if (!this.avgs[k]) this.avgs[k] = { n: 0, avg: 0 }; var avgObj = this.avgs[k]; avgObj.avg = (avgObj.n * avgObj.avg + v) / (avgObj.n + 1); avgObj.n += 1; return avgObj.avg + 'ms (across ' + avgObj.n + ' trials)'; } }; } var performance = window.performance || Date; window.rawLogs = []; function timeAndLog(f) { var currentLog = []; $.fn.mathquill.setLogFn(function (msg) { currentLog.push({ msg: msg, now: performance.now() }); }); var start = performance.now(); f(); var duration = performance.now() - start; $.fn.mathquill.setLogFn($.noop);
var timeline = [], prev = 0; for (var i = 0; i < currentLog.length; i += 1) { var now = Math.round((currentLog[i].now - start) * 1000); timeline.push( now + ': [' + (now - prev) + 'µs] ' + currentLog[i].msg ); prev = now; } timeline = timeline.join('\n');
rawLogs.push({ start: start, duration: duration, log: currentLog, timeline: timeline }); if (timeline.length) { // for tablets without a console if (location.hash === '#alert') alert(timeline); else console.log(timeline); } return duration; } (function () { var textarea = $('#latex-render-perf textarea'); var mathquill = $('#latex-render-perf .mathquill-math-field'); var avgs = Avgs(); $('#latex-render-perf button').click(function () { var latex = textarea.val(); var duration = timeAndLog(function () { mathquill.mathquill('latex', latex); }); $('#html-render-perf').after( '<p>' + duration + 'ms rendering <code>' + latex + '</code>, for an average of ' + avgs.add(latex, duration) + '</p>' ); $('#html-render-perf textarea').val(mathquill.mathquill('html')); }); })(); (function () { var textarea = $('#html-render-perf textarea'); var span = $('#html-render-perf span'); var avgs = Avgs(); $('#html-render-perf button').click(function () { var html = textarea.val(); var duration = timeAndLog(function () { span.html(html); }); $( '<p>' + duration + 'ms rendering <code></code>, for an average of ' + avgs.add(html, duration) + '</p>' ) .find('code') .text(html) .end() .insertAfter('#html-render-perf'); }); })();
MQ.MathField($('#no-kbd-math')[0], { substituteTextarea: function () { return $( '<span tabindex=0 style="display:inline-block;width:1px;height:1px" />' )[0]; } });
MQ.MathField($('#disable-typing')[0], { overrideTypedText: $.noop });
var OTTMQ = MQ.MathField($('#wrap-typing')[0], { overrideTypedText: function (text) { OTTMQ.typedText('<'); OTTMQ.typedText(text); OTTMQ.typedText('>'); } });
var OKSMQ = MQ.MathField($('#select-all-right-arrow')[0], { overrideKeystroke: function (key) { OKSMQ.keystroke(key); } });
var MQ2 = MathQuill.getInterface(2);
MQ2.MathField($('#disable-typing-ske')[0], { substituteKeyboardEvents: function (textarea, handlers) { return MQ2.saneKeyboardEvents( textarea, $.extend({}, handlers, { cut: $.noop, paste: $.noop, keystroke: $.noop, typedText: $.noop }) ); } });
var SKEMQ1 = MQ2.MathField($('#wrap-typing-ske')[0], { substituteKeyboardEvents: function (textarea, handlers) { return MQ2.saneKeyboardEvents( textarea, $.extend({}, handlers, { typedText: function (text) { SKEMQ1.typedText('<'); SKEMQ1.typedText(text); SKEMQ1.typedText('>'); } }) ); } });
var SKEMQ2 = MQ2.MathField($('#select-all-right-arrow-ske')[0], { substituteKeyboardEvents: function (textarea, handlers) { return MQ2.saneKeyboardEvents( textarea, $.extend({}, handlers, { keystroke: function (key) { SKEMQ2.keystroke(key); } }) ); } }); </script> </body></html>