|
357 | 357 | //
|
358 | 358 | MMLnamespace: "http://www.w3.org/1998/Math/MathML",
|
359 | 359 |
|
| 360 | + isFullWidth: function (node) { |
| 361 | + if (!node) return; |
| 362 | + var width = node.getAttribute("width") || |
| 363 | + (String(node.getAttribute("style")).match(/(?:^| )width: *([^; ]*)/)||[])[1]; |
| 364 | + if (width) return !!width.match(/%/); |
| 365 | + if (node.nodeName.match(/^(semantics|math|mstyle)$/)) { |
| 366 | + width = this.isFullWidth(node.firstChild); |
| 367 | + } else if (node.nodeName.toLowerCase() === "mrow") { |
| 368 | + for (var i = 0, m = node.childNodes.length; i < m && !width; i++) |
| 369 | + width = this.isFullWidth(node.childNodes[i]); |
| 370 | + } |
| 371 | + if (width) { |
| 372 | + var style = "width:100%; "+(node.getAttribute("style")||""); |
| 373 | + node.setAttribute("style",style.replace(/ +$/,"")); |
| 374 | + } |
| 375 | + return width; |
| 376 | + }, |
| 377 | + |
360 | 378 | //
|
361 | 379 | // For MSIE, we must overlay the MathPlayer object to trap the events
|
362 | 380 | // (since they can't be cancelled when the events are on the <math> tag
|
|
954 | 972 | }
|
955 | 973 | //
|
956 | 974 | // Look for a top-level mtable and if it has labels
|
957 |
| - // Make sure the containers have 100% width, when needed |
| 975 | + // Make sure the containers have 100% width, when needed. |
958 | 976 | // If the label is on the same side as alignment,
|
959 | 977 | // override the margin set by the stylesheet.
|
960 | 978 | //
|
961 |
| - var mtable = ((this.data[0]||[]).data[0]||{}); |
| 979 | + var mtable = ((this.data[0]||{data:[]}).data[0]||{}); |
962 | 980 | if (mtable.nMMLhasLabels) {
|
963 | 981 | if (mtable.nMMLforceWidth || !mtable.nMMLlaMatch) {
|
964 | 982 | tag.setAttribute("style","width:100%") // mrow node
|
965 |
| - parent.style.width = parent.parentNode.style.width="100%"; |
966 | 983 | if (annotate) tag.parentNode.setAttribute("style","width:100%"); // semantics node
|
967 | 984 | };
|
968 | 985 | if (mtable.nMMLlaMatch) {
|
|
973 | 990 | }
|
974 | 991 | }
|
975 | 992 | //
|
| 993 | + // Check if container must have width set to 100% |
| 994 | + // |
| 995 | + var fullWidth = nMML.isFullWidth(math); |
| 996 | + if (fullWidth) {parent.style.width = parent.parentNode.style.width = "100%"} |
| 997 | + // |
976 | 998 | // Add the math to the page
|
977 | 999 | //
|
978 | 1000 | parent.appendChild(math);
|
|
982 | 1004 | // parent element to match. Even if we set the <math> width properly,
|
983 | 1005 | // it doesn't seem to propagate up to the <span> correctly.
|
984 | 1006 | //
|
985 |
| - if (nMML.widthBug && |
986 |
| - !(mtable.nMMLhasLabels && (mtable.nMMLforceWidth || !mtable.nMMLlaMatch))) { |
| 1007 | + if (nMML.widthBug &&!fullWidth) { |
987 | 1008 | //
|
988 | 1009 | // Convert size to ex's so that it scales properly if the print media
|
989 | 1010 | // has a different font size.
|
|
0 commit comments