| 48 | }; |
| 49 | |
| 50 | function initPanels(cm) { |
| 51 | var wrap = cm.getWrapperElement(); |
| 52 | var style = window.getComputedStyle ? window.getComputedStyle(wrap) : wrap.currentStyle; |
| 53 | var height = parseInt(style.height); |
| 54 | var info = cm.state.panels = { |
| 55 | setHeight: wrap.style.height, |
| 56 | heightLeft: height, |
| 57 | panels: 0, |
| 58 | wrapper: document.createElement("div") |
| 59 | }; |
| 60 | wrap.parentNode.insertBefore(info.wrapper, wrap); |
| 61 | var hasFocus = cm.hasFocus(); |
| 62 | info.wrapper.appendChild(wrap); |
| 63 | if (hasFocus) cm.focus(); |
| 64 | |
| 65 | cm._setSize = cm.setSize; |
| 66 | if (height != null) cm.setSize = function(width, newHeight) { |
| 67 | if (newHeight == null) return this._setSize(width, newHeight); |
| 68 | info.setHeight = newHeight; |
| 69 | if (typeof newHeight != "number") { |
| 70 | var px = /^(\d+\.?\d*)px$/.exec(newHeight); |
| 71 | if (px) { |
| 72 | newHeight = Number(px[1]); |
| 73 | } else { |
| 74 | info.wrapper.style.height = newHeight; |
| 75 | newHeight = info.wrapper.offsetHeight; |
| 76 | info.wrapper.style.height = ""; |
| 77 | } |
| 78 | } |
| 79 | cm._setSize(width, info.heightLeft += (newHeight - height)); |
| 80 | height = newHeight; |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | function removePanels(cm) { |
| 85 | var info = cm.state.panels; |