var gEditor; function onLoad() { if (wysiwyg) { // Initialize the WYSIWYG content editor. We could just call // HTMLArea.replace() or .replaceAll(), but we want a reference // to the editor so we can make it update the content textarea // when the user switches modes. var content = document.getElementById("content"); try { gEditor = new HTMLArea(content); gEditor.registerPlugin(FullPage); gEditor.generate(); } catch(e) { throw(e); } switchToTab("edit"); } else switchToTab("hack"); checkOriginMode(); } function synchronizeEditModes() { // Hack to make sure the content and its WYSIWYG representation // are synchronized every time the view mode changes (so any edits // get reflected in the other views) by toggling the edit mode // from the current mode to the other one and back. // Wrapped in a try/catch block because this throws an error sometimes // the first time this code is loaded, although it doesn't seem to matter. if (!wysiwyg) return; try { gEditor.setMode(); gEditor.setMode(); } catch(e) {} } const TABS = ["edit", "hack", "original", "modified", "diff", "save"]; var gActiveTab; function switchToTab(newTab) { if (newTab == "edit") { try { gEditor.setMode("wysiwyg"); } catch(e) {} } else if (newTab == "hack") { try { gEditor.setMode("textmode"); } catch(e) {} } else if (newTab == "original") {} else if (newTab == "modified") { synchronizeEditModes(); var modifiedPanel = document.getElementById('modifiedPanel'); var content_file = document.getElementById('content_file'); if (content_file.value) { modifiedPanel.innerHTML = ''; submitForm("modified", "regurgitate"); } else { modifiedPanel.innerHTML = document.getElementById('content').value; } } else if (newTab == "diff") { synchronizeEditModes(); submitForm("diffPanel", "diff", { raw: "1" }); } else if (newTab == "save") { synchronizeEditModes(); } gActiveTab = newTab; updateTabState(); } function updateTabState() { for ( var i=0 ; i