| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 | <html> |
|---|
| 3 | <head> |
|---|
| 4 | <title>API Interface Test</title> |
|---|
| 5 | <script type="text/javascript" src="http://www.google.com/jsapi"></script> |
|---|
| 6 | <script type="text/javascript"> |
|---|
| 7 | //<![CDATA[ |
|---|
| 8 | google.load("dojo", "1.1.1"); |
|---|
| 9 | google.setOnLoadCallback(function() { |
|---|
| 10 | dojo.provide('dojo.string'); |
|---|
| 11 | // removed after dojo 0.4.x, so copied from http://trac.dojotoolkit.org/browser/trunk/src/string/extras.js?rev=3266#L88 |
|---|
| 12 | dojo.string.escapeXml = function(str, noSingleQuotes) { |
|---|
| 13 | str = str.replace(/&/gm, "&").replace(/</gm, "<") |
|---|
| 14 | .replace(/>/gm, ">").replace(/\"/gm, """); |
|---|
| 15 | if(!noSingleQuotes) { str = str.replace(/\'/gm, "'"); } |
|---|
| 16 | return str; |
|---|
| 17 | } |
|---|
| 18 | var f = dojo.byId('testForm'); |
|---|
| 19 | var submitFunc = function(ev) { |
|---|
| 20 | ev.preventDefault(); |
|---|
| 21 | dojo.byId('msg').innerHTML = 'loading...'; |
|---|
| 22 | dojo.byId('testSubmit').enabled = false; |
|---|
| 23 | dojo.xhrPost({ |
|---|
| 24 | url: 'api.php', |
|---|
| 25 | handleAs: 'json', |
|---|
| 26 | form: 'testForm', |
|---|
| 27 | load: function(response, args) { |
|---|
| 28 | if (response.result == 'ok') { |
|---|
| 29 | var img = dojo.byId('result'); |
|---|
| 30 | // TODO: We need workaround for IE6 and IE7. |
|---|
| 31 | img.src = 'data:' + response.format + ';base64,' + response.content; |
|---|
| 32 | img.width = response.sizeX; img.height = response.sizeY; |
|---|
| 33 | dojo.byId('msg').innerHTML = 'Complete : (' + response.sizeX + 'x' + response.sizeY + ')'; |
|---|
| 34 | } else { |
|---|
| 35 | dojo.byId('msg').innerHTML = 'Error : <' + response.error_type + '> ' + dojo.string.escapeXml(response.message); |
|---|
| 36 | } |
|---|
| 37 | dojo.byId('testSubmit').enabled = true; |
|---|
| 38 | }, |
|---|
| 39 | error: function(response, args) { |
|---|
| 40 | alert('AJAX Error : ' + response); |
|---|
| 41 | dojo.byId('loadingMsg').innerHTML = 'Error during AJAX request.'; |
|---|
| 42 | dojo.byId('testSubmit').enabled = true; |
|---|
| 43 | } |
|---|
| 44 | }); |
|---|
| 45 | return false; |
|---|
| 46 | }; |
|---|
| 47 | dojo.connect(f, 'onsubmit', submitFunc); |
|---|
| 48 | }); |
|---|
| 49 | //]]> |
|---|
| 50 | </script> |
|---|
| 51 | <style type="text/css"> |
|---|
| 52 | body { font-family: Trebuchet MS, Verdana, sans-serif; font-size: 0.85em; } |
|---|
| 53 | label { font-weight: bold; } |
|---|
| 54 | .desc { font-size: 0.9em; color:gray; } |
|---|
| 55 | #msg { color: #736998; } |
|---|
| 56 | #result-container { background: #f2f2f2 url(slash01_10x10.png) repeat; width: 800px; height: 500px; padding: 0;} |
|---|
| 57 | </style> |
|---|
| 58 | </head> |
|---|
| 59 | <body> |
|---|
| 60 | <form id="testForm" method="post" action="api.php"> |
|---|
| 61 | <p><label>API Key : <input type="text" name="key" value="TESTING" /></label></p> |
|---|
| 62 | <p> |
|---|
| 63 | <label>Extra packages : <input type="text" name="packages" value="" /></label> |
|---|
| 64 | <br/><span class="desc">Separate multiple packages with comma. Default packages are amsmath, amsfonts, amssymb, color.</span> |
|---|
| 65 | </p> |
|---|
| 66 | <p> |
|---|
| 67 | <label>Mode : |
|---|
| 68 | <select name="mode"> |
|---|
| 69 | <option value="$">Inline math</option> |
|---|
| 70 | <option value="displaymath" selected="selected">Display math</option> |
|---|
| 71 | <option value="eqnarray">Eqn. Array</option> |
|---|
| 72 | </select> |
|---|
| 73 | </label> |
|---|
| 74 | </p> |
|---|
| 75 | <p> |
|---|
| 76 | <label>Transparent Background : <input type="checkbox" name="transparent" value="true" checked="checked" /></label> |
|---|
| 77 | <br/><span class="desc">If you use PNG format, this will generate 32bit ARGB PNG to preserve semi-transparent pixels correctly.</span> |
|---|
| 78 | </p> |
|---|
| 79 | <p><label>Size : |
|---|
| 80 | <select name="size"> |
|---|
| 81 | <option value="scriptsize">Very small</option> |
|---|
| 82 | <option value="footnotesize">Smaller</option> |
|---|
| 83 | <option value="small">Small</option> |
|---|
| 84 | <option value="normalsize" selected="selected">Normal</option> |
|---|
| 85 | <option value="large">Large</option> |
|---|
| 86 | <option value="Large">Larger</option> |
|---|
| 87 | <option value="huge">Very large</option> |
|---|
| 88 | <option value="Huge">Largest</option> |
|---|
| 89 | </select> |
|---|
| 90 | </label></p> |
|---|
| 91 | <p><label>Format : |
|---|
| 92 | <select name="format"> |
|---|
| 93 | <option value="gif">GIF</option> |
|---|
| 94 | <option value="png" selected="selected">PNG</option> |
|---|
| 95 | </select> |
|---|
| 96 | </label></p> |
|---|
| 97 | <p><label>Formula : <textarea name="formula" rows="5" cols="40"><?php echo htmlentities(''); ?></textarea></label></p> |
|---|
| 98 | <p><input type="submit" id="testSubmit" value="Submit" /></p> |
|---|
| 99 | </form> |
|---|
| 100 | <p id="msg">Test your formula.</p> |
|---|
| 101 | <div id="result-container"> |
|---|
| 102 | <img id="result" src="" /> |
|---|
| 103 | </div> |
|---|
| 104 | </body> |
|---|
| 105 | </html> |
|---|