From 27ecc5b56ce5c326580d1c2afdce180454746597 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 7 Jul 2016 10:28:27 +0200 Subject: [PATCH] Fixed codemirror sometimes broken in hidden tabs --- .../files/acp/templates/codemirror.tpl | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/codemirror.tpl b/wcfsetup/install/files/acp/templates/codemirror.tpl index 9edce7d3fd..3f0a394a61 100644 --- a/wcfsetup/install/files/acp/templates/codemirror.tpl +++ b/wcfsetup/install/files/acp/templates/codemirror.tpl @@ -35,41 +35,55 @@ }); {/if} - var elements = document.querySelectorAll('{@$codemirrorSelector|encodeJS}'); - var config = { - {if $codemirrorMode|isset}mode: '{@$codemirrorMode|encodeJS}',{/if} - lineWrapping: true, - indentWithTabs: true, - lineNumbers: true, - indentUnit: 4, - readOnly: {if !$editable|isset || $editable}false{else}true{/if} - }; - - [].forEach.call(elements, function(element) { - {event name='javascriptInit'} + require(['EventHandler', 'Dom/Traverse', 'Dom/Util'], function(EventHandler, DomTraverse, DomUtil) { + var elements = document.querySelectorAll('{@$codemirrorSelector|encodeJS}'); + var config = { + {if $codemirrorMode|isset}mode: '{@$codemirrorMode|encodeJS}',{/if} + lineWrapping: true, + indentWithTabs: true, + lineNumbers: true, + indentUnit: 4, + readOnly: {if !$editable|isset || $editable}false{else}true{/if} + }; - if (element.codemirror) { - for (var key in config) { - if (config.hasOwnProperty(key)) { - element.codemirror.setOption(key, config[key]); + [].forEach.call(elements, function (element) { + {event name='javascriptInit'} + + if (element.codemirror) { + for (var key in config) { + if (config.hasOwnProperty(key)) { + element.codemirror.setOption(key, config[key]); + } } } - } - else { - element.codemirror = CodeMirror.fromTextArea(element, config); - var oldToTextArea = element.codemirror.toTextArea; - element.codemirror.toTextArea = function() { - oldToTextArea(); - element.codemirror = null; - }; - } - - setTimeout(function () { - element.codemirror.refresh(); - }, 250); - setTimeout(function () { - element.codemirror.refresh(); - }, 1000); + else { + element.codemirror = CodeMirror.fromTextArea(element, config); + var oldToTextArea = element.codemirror.toTextArea; + element.codemirror.toTextArea = function () { + oldToTextArea(); + element.codemirror = null; + }; + } + + setTimeout(function () { + element.codemirror.refresh(); + }, 250); + setTimeout(function () { + element.codemirror.refresh(); + }, 1000); + + var tab = DomTraverse.parentByClass(element, 'tabMenuContent'); + if (tab !== null) { + var name = elData(tab, 'name'); + var tabMenu = DomTraverse.parentByClass(tab, 'tabMenuContainer'); + + EventHandler.add('com.woltlab.wcf.simpleTabMenu_' + DomUtil.identify(tabMenu), 'select', function(data) { + if (data.activeName === name) { + element.codemirror.refresh(); + } + }); + } + }); }); {assign var='codemirrorLoaded' value=true} -- 2.20.1