00001 UT_UTF8String sMathSVGScript = " \ 00002 /* \r\n \ 00003 MIT License\r\n \ 00004 Copyright (c) 2006 Sam Ruby \r\n \ 00005 \r\n \ 00006 Permission is hereby granted, free of charge, to any person obtaining a copy\r\n \ 00007 of this software and associated documentation files (the 'Software'), to deal\r\n \ 00008 in the Software without restriction, including without limitation the rights\r\n \ 00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n \ 00010 copies of the Software, and to permit persons to whom the Software is\r\n \ 00011 furnished to do so, subject to the following conditions: \r\n \ 00012 \r\n \ 00013 The above copyright notice and this permission notice shall be included in all\r\n \ 00014 copies or substantial portions of the Software.\r\n \ 00015 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n \ 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \r\n \ 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n \ 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n \ 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n \ 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n \ 00021 SOFTWARE.\r\n \ 00022 */ \r\n \ 00023 \r\n \ 00024 window.onload = function() {\r\n \ 00025 var MathML = {\r\n \ 00026 // Jacques Distler subset of Presentational MathML\r\n \ 00027 root: 'math',\r\n \ 00028 ns: 'http://www.w3.org/1998/Math/MathML',\r\n \ 00029 elements: ['maction', 'math', 'merror', 'mfrac', 'mi',\r\n \ 00030 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom',\r\n \ 00031 'mprescripts', 'mroot', 'mrow', 'mspace', 'msqrt', 'mstyle', 'msub',\r\n \ 00032 'msubsup', 'msup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder',\r\n \ 00033 'munderover', 'none'], \r\n \ 00034 attributes: ['actiontype', 'align', 'columnalign', 'columnalign', \r\n \ 00035 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'depth', \r\n \ 00036 'display', 'displaystyle', 'equalcolumns', 'equalrows', 'fence', \r\n \ 00037 'fontstyle', 'fontweight', 'frame', 'height', 'linethickness', 'lspace', \r\n \ 00038 'mathbackground', 'mathcolor', 'mathvariant', 'mathvariant', 'maxsize', \r\n \ 00039 'minsize', 'other', 'rowalign', 'rowalign', 'rowalign', 'rowlines', \r\n \ 00040 'rowspacing', 'rowspan', 'rspace', 'scriptlevel', 'selection',\r\n \ 00041 'separator', 'stretchy', 'width', 'width'] \r\n \ 00042 } \r\n \ 00043 \r\n \ 00044 var SVG = { \r\n \ 00045 // svgtiny + class + opacity + offset + style \r\n \ 00046 root: 'svg', \r\n \ 00047 ns: 'http://www.w3.org/2000/svg',\r\n \ 00048 elements: ['a', 'animate', 'animateColor', 'animateMotion', \r\n \ 00049 'animateTransform', 'circle', 'defs', 'desc', 'ellipse', 'font-face', \r\n \ 00050 'font-face-name', 'font-face-src', 'g', 'glyph', 'hkern', 'image', \r\n \ 00051 'linearGradient', 'line', 'metadata', 'missing-glyph', 'mpath', 'path', \r\n \ 00052 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop',\r\n \ 00053 'switch', 'text', 'title', 'use'], \r\n \ 00054 attributes: ['accent-height', 'accumulate', 'additive', 'alphabetic', \r\n \ 00055 'arabic-form', 'ascent', 'attributeName', 'attributeType', \r\n \ 00056 'baseProfile', 'bbox', 'begin', 'by', 'calcMode', 'cap-height', \r\n \ 00057 'class', 'color', 'color-rendering', 'content', 'cx', 'cy', 'd', \r\n \ 00058 'descent', 'display', 'dur', 'end', 'fill', 'fill-rule', 'font-family', \r\n \ 00059 'font-size', 'font-stretch', 'font-style', 'font-variant', \r\n \ 00060 'font-weight', 'from', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'hanging', \r\n \ 00061 'height', 'horiz-adv-x', 'horiz-origin-x', 'id', 'ideographic', 'k', \r\n \ 00062 'keyPoints', 'keySplines', 'keyTimes', 'lang', 'mathematical', 'max', \r\n \ 00063 'min', 'name', 'offset', 'opacity', 'origin', 'overline-position',\r\n \ 00064 'overline-thickness', 'panose-1', 'path', 'pathLength', 'points',\r\n \ 00065 'preserveAspectRatio', 'r', 'repeatCount', 'repeatDur',\r\n \ 00066 'requiredExtensions', 'requiredFeatures', 'restart', 'rotate', 'rx',\r\n \ 00067 'ry', 'slope', 'stemh', 'stemv', 'stop-color', 'stop-opacity',\r\n \ 00068 'strikethrough-position', 'strikethrough-thickness', 'stroke',\r\n \ 00069 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap',\r\n \ 00070 'stroke-linejoin', 'stroke-miterlimit', 'stroke-width', 'style',\r\n \ 00071 'systemLanguage', 'target', 'text-anchor', 'to', 'transform', 'type',\r\n \ 00072 'u1', 'u2', 'underline-position', 'underline-thickness', 'unicode',\r\n \ 00073 'unicode-range', 'units-per-em', 'values', 'version', 'viewBox',\r\n \ 00074 'visibility', 'width', 'widths', 'x', 'x-height', 'x1', 'x2',\r\n \ 00075 'y', 'y1', 'y2', 'zoomAndPan'] \r\n \ 00076 } \r\n \ 00077 \r\n \ 00078 // clone a DOM subtree \r\n \ 00079 function deepcopy(module, source, dest, nsmap) { \r\n \ 00080 // copy attributes \r\n \ 00081 for (var i=0; i<source.attributes.length; i++) { \r\n \ 00082 var oldattr = source.attributes[i];\r\n \ 00083 var colon = oldattr.name.indexOf(':');\r\n \ 00084 if (colon == -1) {\r\n \ 00085 for (var j=0; j<module.attributes.length; j++) {\r\n \ 00086 if (module.attributes[j].toLowerCase() != oldattr.name) continue;\r\n \ 00087 dest.setAttribute(module.attributes[j], oldattr.value);\r\n \ 00088 break;\r\n \ 00089 }\r\n \ 00090 } else { // namespace prefixed attribute\r\n \ 00091 var prefix = oldattr.name.slice(0,colon);\r\n \ 00092 var name = oldattr.name.slice(colon+1);\r\n \ 00093 if (prefix == 'xmlns') {\r\n \ 00094 var oldmap = nsmap;\r\n \ 00095 nsmap = {};\r\n \ 00096 for (var property in oldmap) nsmap[property] = oldmap[property];\r\n \ 00097 nsmap[name] = oldattr.value;\r\n \ 00098 } else {\r\n \ 00099 for (var ns in nsmap) {\r\n \ 00100 if (ns == prefix) {\r\n \ 00101 dest.setAttributeNS(nsmap[prefix], name, oldattr.value);\r\n \ 00102 }\r\n \ 00103 }\r\n \ 00104 }\r\n \ 00105 }\r\n \ 00106 }\r\n \ 00107 \r\n \ 00108 // copy children\r\n \ 00109 for (var i=0; i<source.childNodes.length; i++) {\r\n \ 00110 var oldchild = source.childNodes[i];\r\n \ 00111 if (oldchild.nodeType == 1) { // element\r\n \ 00112 for (var j=0; j<module.elements.length; j++) {\r\n \ 00113 if (module.elements[j].toUpperCase() != oldchild.nodeName) continue;\r\n \ 00114 var newchild = document.createElementNS(module.ns,module.elements[j]);\r\n \ 00115 deepcopy(module, oldchild, newchild, nsmap);\r\n \ 00116 dest.appendChild(newchild);\r\n \ 00117 break;\r\n \ 00118 }\r\n \ 00119 } else if (oldchild.nodeType == 3) { // text\r\n \ 00120 var newchild = document.createTextNode(oldchild.nodeValue);\r\n \ 00121 dest.appendChild(newchild); \r\n \ 00122 } \r\n \ 00123 } \r\n \ 00124 } \r\n \ 00125 \r\n \ 00126 // copy modules into their appropriate namespaces\r\n \ 00127 var modules = [MathML, SVG];\r\n \ 00128 for (var i=0; i<modules.length; i++) { \r\n \ 00129 var module = modules[i];\r\n \ 00130 var roots = document.getElementsByTagName(module.root); \r\n \ 00131 for (var j=0; j<roots.length; j++) { \r\n \ 00132 var source = roots[j]; \r\n \ 00133 if (document.createElementNS) { \r\n \ 00134 if (source.__proto__ != HTMLUnknownElement.prototype) continue; \r\n \ 00135 if (source.getAttribute('xmlns') != module.ns) continue; \r\n \ 00136 var dest = document.createElementNS(module.ns, module.root); \r\n \ 00137 deepcopy(module, source, dest, {}); \r\n \ 00138 source.parentNode.insertBefore(dest, source); \r\n \ 00139 source.parentNode.removeChild(source); \r\n \ 00140 } else { \r\n \ 00141 // fallback browsers that don't support DOM namespaces \r\n \ 00142 var img = document.createElement('img'); \r\n \ 00143 img.src = module.root + ' image'; \r\n \ 00144 img.title = module.root + ' image'; \r\n \ 00145 source.parentNode.insertBefore(img, source) ;\r\n \ 00146 } \r\n \ 00147 } \r\n \ 00148 } \r\n \ 00149 } \r\n"; 00150