Fixed codemirror sometimes broken in hidden tabs
authorAlexander Ebert <ebert@woltlab.com>
Thu, 7 Jul 2016 08:28:27 +0000 (10:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 7 Jul 2016 08:28:33 +0000 (10:28 +0200)
wcfsetup/install/files/acp/templates/codemirror.tpl

index 9edce7d3fd407091d5de7cb27c68129c6c9954f9..3f0a394a617d42945111fdde651007465d2307c4 100644 (file)
                });
        {/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();
+                                       }
+                               });
+                       }
+               });
        });
 </script>
 {assign var='codemirrorLoaded' value=true}