|
5 | 5 | $(document).ready(function () {
|
6 | 6 | var editor = ace.edit("editor");
|
7 | 7 |
|
8 |
| - function hasCalc(aPrefix) { |
9 |
| - var el = null; |
| 8 | + function hasRelative(aPrefix) { |
| 9 | + var hasCalc = null; |
| 10 | + var hasUnitV = null; |
10 | 11 |
|
11 | 12 | aPrefix = aPrefix || "";
|
12 |
| - el = document.createElement("div"); |
13 |
| - el.style.setProperty(aPrefix + "width", "calc(1px)", ""); |
14 |
| - return !!el.style.length; |
| 13 | + hasCalc = document.createElement("div"); |
| 14 | + hasCalc.style.setProperty(aPrefix + "width", "calc(1px)", ""); |
| 15 | + |
| 16 | + if (!!hasCalc.style.length) { |
| 17 | + hasUnitV = document.createElement("div"); |
| 18 | + hasUnitV.style.setProperty(aPrefix + "width", "calc(5vw + 5vw)", ""); |
| 19 | + } |
| 20 | + |
| 21 | + return !!hasCalc.style.length && !!hasUnitV.style.length; |
15 | 22 | }
|
16 | 23 |
|
17 |
| - function hasAnyCalc() { |
18 |
| - return hasCalc("-moz-") || hasCalc("-ms-") || hasCalc("-o-") || hasCalc("-webkit-") || hasCalc(); |
| 24 | + function hasOurRelative() { |
| 25 | + return hasRelative("-moz-") || hasRelative("-ms-") || hasRelative("-o-") || |
| 26 | + hasRelative("-webkit-") || hasRelative(); |
19 | 27 | }
|
20 | 28 |
|
21 | 29 | function calcHeight() {
|
22 |
| - return window.innerHeight - {{#newScript}}190{{/newScript}}{{^newScript}}303{{/newScript}}; |
| 30 | + return window.innerHeight - {{#newScript}}190{{/newScript}}{{^newScript}}302{{/newScript}}; |
23 | 31 | }
|
24 | 32 |
|
25 | 33 | editor.setTheme("ace/theme/dawn");
|
|
34 | 42 | });
|
35 | 43 | {{/readOnly}}
|
36 | 44 |
|
37 |
| - // Older browser JavaScript work-around for #136 |
38 |
| - if (!hasAnyCalc()) { |
| 45 | + // Some older and newer browser JavaScript work-around for #136 |
| 46 | + if (!hasOurRelative()) { |
39 | 47 | $("#editor").height(calcHeight());
|
40 |
| - $(document).on("resize", function () { |
| 48 | + |
| 49 | + function onresize() { |
41 | 50 | $("#editor").height(calcHeight);
|
42 |
| - }); |
| 51 | + } |
| 52 | + |
| 53 | + if (window.addEventListener) { |
| 54 | + window.addEventListener('resize', onresize, false); |
| 55 | + } else if (window.attachEvent) { |
| 56 | + window.attachEvent('resize', onresize); |
| 57 | + } |
43 | 58 | }
|
44 | 59 | });
|
45 | 60 |
|
|
0 commit comments