| 9653 | TextareaInput.prototype.needsContentAttribute = false; |
| 9654 | |
| 9655 | function fromTextArea(textarea, options) { |
| 9656 | options = options ? copyObj(options) : {}; |
| 9657 | options.value = textarea.value; |
| 9658 | if (!options.tabindex && textarea.tabIndex) |
| 9659 | { options.tabindex = textarea.tabIndex; } |
| 9660 | if (!options.placeholder && textarea.placeholder) |
| 9661 | { options.placeholder = textarea.placeholder; } |
| 9662 | // Set autofocus to true if this textarea is focused, or if it has |
| 9663 | // autofocus and no other element is focused. |
| 9664 | if (options.autofocus == null) { |
| 9665 | var hasFocus = activeElt(); |
| 9666 | options.autofocus = hasFocus == textarea || |
| 9667 | textarea.getAttribute("autofocus") != null && hasFocus == document.body; |
| 9668 | } |
| 9669 | |
| 9670 | function save() {textarea.value = cm.getValue();} |
| 9671 | |
| 9672 | var realSubmit; |
| 9673 | if (textarea.form) { |
| 9674 | on(textarea.form, "submit", save); |
| 9675 | // Deplorable hack to make the submit method do the right thing. |
| 9676 | if (!options.leaveSubmitMethodAlone) { |
| 9677 | var form = textarea.form; |
| 9678 | realSubmit = form.submit; |
| 9679 | try { |
| 9680 | var wrappedSubmit = form.submit = function () { |
| 9681 | save(); |
| 9682 | form.submit = realSubmit; |
| 9683 | form.submit(); |
| 9684 | form.submit = wrappedSubmit; |
| 9685 | }; |
| 9686 | } catch(e) {} |
| 9687 | } |
| 9688 | } |
| 9689 | |
| 9690 | options.finishInit = function (cm) { |
| 9691 | cm.save = save; |
| 9692 | cm.getTextArea = function () { return textarea; }; |
| 9693 | cm.toTextArea = function () { |
| 9694 | cm.toTextArea = isNaN; // Prevent this from being ran twice |
| 9695 | save(); |
| 9696 | textarea.parentNode.removeChild(cm.getWrapperElement()); |
| 9697 | textarea.style.display = ""; |
| 9698 | if (textarea.form) { |
| 9699 | off(textarea.form, "submit", save); |
| 9700 | if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function") |
| 9701 | { textarea.form.submit = realSubmit; } |
| 9702 | } |
| 9703 | }; |
| 9704 | }; |
| 9705 | |
| 9706 | textarea.style.display = "none"; |
| 9707 | var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); }, |
| 9708 | options); |
| 9709 | return cm |
| 9710 | } |
| 9711 | |
| 9712 | function addLegacyProps(CodeMirror) { |