// +--------------------------------------------------------------------+ // | DO NOT REMOVE THIS | // +--------------------------------------------------------------------+ // | management.js | // | Some functions, stuff for documents & folders management. | // +--------------------------------------------------------------------+ // | Author: Cezary Tomczak [www.gosu.pl] | // | Project: SimpleDoc | // | URL: http://gosu.pl/php/simpledoc.html | // | License: GPL | // +--------------------------------------------------------------------+ function Fader(id) { this.start = function() { this.timerId = setInterval(change, 80); }; this.stop = function() { clearInterval(this.timerId); this.opacity = 80; this.direction = 0; document.getElementById(this.id).style.opacity = 1; document.getElementById(this.id).style.MozOpacity = 1; document.getElementById(this.id).style.filter = 80; }; function change() { self.opacity += (self.direction ? 10 : -10); document.getElementById(self.id).style.opacity = self.opacity/100; document.getElementById(self.id).style.MozOpacity = self.opacity/100; document.getElementById(self.id).style.filter = "alpha(opacity="+self.opacity+")"; if (self.opacity == 20) { self.direction = 1; } if (self.opacity == 80) { self.direction = 0; } } var self = this; this.id = id; this.timerId = null; this.opacity = 80; this.direction = 0; } //var tabsLoading = new Fader("tabs-loading"); //var tabsSaving = new Fader("tabs-saving"); //var AjaxRequest = new AjaxRequest(); //function tabsLoadingOn() { document.getElementById("tabs-loading").style.display = "block"; tabsLoading.start(); } function tabsLoadingOn() { } //function tabsLoadingOff() { document.getElementById("tabs-loading").style.display = "none"; tabsLoading.stop(); } function tabsLoadingOff() { } //function tabsSavingOn() { document.getElementById("tabs-saving").style.display = "block"; tabsSaving.start(); } function tabsSavingOn() { } //function tabsSavingOff() { document.getElementById("tabs-saving").style.display = "none"; tabsSaving.stop(); } function tabsSavingOff() { } function documentInfo() { if (!tree.active || !tree.getActiveNode().isDocument()) { alert("You have to select a document in the Tree View to perform this action."); return; } checkContentSaved(); AjaxRequest.get( { 'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-document-info.php' ,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { clearTabs(); tabsLoadingOn(); } ,'onComplete':function() { tabsLoadingOff(); } ,'onSuccess':function(req){ el('tabs-data').innerHTML = req.responseText; updateTabs('tab1'); dhtmlHistory.add( treeGetId(), el(tree.active+"-text").innerHTML );} ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;} ,'timeout':5000 ,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); } function editContent() { if (!tree.active || !tree.getActiveNode().isDocument()) { alert("You have to select a document in the Tree View to perform this action."); return; } checkContentSaved(); AjaxRequest.get( { 'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-edit-content.php' ,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { clearTabs(); tabsLoadingOn(); } ,'onComplete':function() { tabsLoadingOff(); } ,'onSuccess':function(req){ el('tabs-data').innerHTML = req.responseText; initSimpleEditor(); el('body-tmp').value = el('body').value; updateTabs('tab2'); dhtmlHistory.add( treeGetId(), el(tree.active+"-text").innerHTML );} ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;} ,'timeout':5000 ,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); } var ste = null; function initSimpleEditor(){ ste = new SimpleTextEditor("body", "ste"); ste.path = "modules/mx_simpledoc/simpledoc/shared/SimpleTextEditor/"; ste.charset = "iso-8859-1"; ste.init(); ste.frame.document.onkeydown = keyPress; // aaa!! next IE bug, editor images not loading :\ if (document.all) { setTimeout(loadEditorImages, 50); } } function documentPreview() { if (!tree.active || !tree.getActiveNode().isDocument()) { alert("You have to select a document in the Tree View to perform this action."); return; } AjaxRequest.get( { 'url':'modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-view-content.php' ,'parameters':{ 'id':escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { clearTabs(); tabsLoadingOn(); } ,'onComplete':function() { tabsLoadingOff(); } ,'onSuccess':function(req){ el('tabs-data').innerHTML = addTocDiv(stripBodyHtml(req.responseText)); generateTOC('index'); updateTabs('tab3'); } ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;} ,'timeout':5000 ,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); } function documentView() { if (!tree.active || !tree.getActiveNode().isDocument()) { alert("You have to select a document in the Tree View to perform this action."); return; } AjaxRequest.get( { 'url':'modules/mx_kb/kb/modules/tabs/kb__tab-view.php' ,'parameters':{ 'mode':'article', 'k': escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), 'id': escape(treeGetId()), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { clearTabs(); tabsLoadingOn(); } ,'onComplete':function() { tabsLoadingOff(); } ,'onSuccess':function(req){ el('tabs-data').innerHTML = stripBodyHtml(req.responseText); generateParentTOC('view'); generateTOC('view');} ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText; } ,'timeout':5000 ,'onTimeout':function(){ clearTabs(); tabsLoadingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); } function saveContent(theform) { tabsSavingOn(); el('save-document').disabled = true; //el('tabs-data').style.visibility = "hidden"; var status = AjaxRequest.submit( theform ,{ 'onSuccess':function(req){ } } ); el('save-document').disabled = false; el('body-tmp').value = el('body').value; tabsSavingOff(); //var data = {"body": el('body').value} //var save = httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__tab-save-content.php?id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id, data); if ((typeof status == "boolean" && !status) || typeof status == "string") { alert("Unknown error, cannot save document."); } else { el("saved").innerHTML = "Saved successfuly on "+(new Date()+"
(this message will disappear in 3 seconds)"); if (savedTimerID) clearTimeout(savedTimerID); savedTimerID = setTimeout(function(){ el("saved").innerHTML = ""; }, 3000); } return status; } // The top right toc // this snippet doesn't work if there is a folder named "html" // Only used when the doc is generated as part of the app - inline (scripts are stripped in plain code) function generateTOC(mode) { var contents = ""; var link = escape(treeGetId()); contents = '
Permanent Link to this page
'; var all = document.getElementById("tabs-data").childNodes; var contents2 = ""; var text = ""; var found = false; var h3 = false; contents2 += 'Contents'; h3 = false; } if (all[i].nodeName == "H3") { if (!h3) contents2 += ''; if (found) { if (contents) contents += '
'; contents += contents2; } if (contents) { document.getElementById("contents").className = "contents"; document.getElementById("contents").innerHTML = contents; } //alert(document.getElementById("tabs-data").innerHTML); } // ?? // this snippet doesn't work if there is a folder named "html" // Only used when the doc is generated as part of the app - inline (scripts are stripped in plain code) function generateParentTOC(mode) { var contents = ""; var loc = ""; var contents2 = ""; var title = "

Section Contents

"; var s = ''; if(!document.getElementById("sectioncontents")) { //document.getElementById("tabs-data").innerHTML = addTocDiv(''); document.getElementById("tabs-data").innerHTML = addTocDiv(document.getElementById("tabs-data").innerHTML); } var node = tree.getActiveNode(); while (node && node.parentNode) { loc = (!node.isDocument() ? ' » ' + ''+node.text+'' : '') + loc; node = node.parentNode; } loc = 'Table of Contents ' + loc; node = tree.getActiveNode(); if (node.childNodes) { for (var i = 0; i < node.childNodes.length; i++) { contents2 += node.childNodes[i].toToc(); } } contents2 = contents2 != '' ? title + contents2 : ''; contents = loc + '
' + contents2; if (contents) { document.getElementById("sectioncontents").className = "sectioncontents"; document.getElementById("sectioncontents").innerHTML = contents; } } function stripBodyHtml(html) { // Remove HTML comments //html = html.replace(//gi, "" ); // Remove all HTML tags //html = html.replace(/<\/?\s*HTML[^>]*>/gi, "" ); // Remove all BODY tags //html = html.replace(/<\/?\s*BODY[^>]*>/gi, "" ); // Remove all META tags //html = html.replace(/<\/?\s*META[^>]*>/gi, "" ); // Remove all TITLE tags & content //html = html.replace(/<\s*TITLE[^>]*>([^<]*)<\/\s*TITLE\s*>/i, "" ); // Remove all HEAD tags & content //html = html.replace(/<\s*HEAD[^>]*>([^<]*)<\/\s*HEAD\s*>/i, "" ); // Remove all SCRIPT tags //html = html.replace(/<\s*SCRIPT[^>]*>([^<]*)<\/\s*SCRIPT\s*>/i, "" ); // Remove all SPAN tags //html = html.replace(/<\/?\s*SPAN[^>]*>/gi, "" ); // Remove all STYLE tags //html = html.replace(/<\s*STYLE[^>]*>([^<]*)<\/\s*STYLE\s*>/i, "" ); // Remove Class attributes //html = html.replace(/<\s*(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "") ; // Remove Style attributes //html = html.replace(/<\s*(\w[^>]*) style="([^"]*)"([^>]*)/gi, "") ; //html = html.replace(/<\s*br[^>]*>/gi,""); html = html.trim(); return html; } function addTocDiv(html) { html = '
' + '
' + html; return html; } function loadEditorImages() { var a = el('tabs-data').getElementsByTagName("img"); for (var i = 0; i < a.length; ++i) { if (!a[i].complete && a[i].outerHTML) { a[i].outerHTML = a[i].outerHTML; } } } var savedTimerID = null; function isContentSaved() { if (ste && el("body") && el("save-document")) { ste.submit(); if (el("body").value != el("body-tmp").value) { return false; } } return true; } function checkContentSaved() { if (!isContentSaved()) { if (confirm("Content has not been saved since last change.\nSave it ?")) { saveContent(); } } } function clearTabs() { if(el('tab1')) {el('tab1').className = "tab";} if(el('tab2')) {el('tab2').className = "tab right";} if(el('tabs-data')) {el('tabs-data').innerHTML = "";} } function updateTabs(active){ el('tab1').className = "tab"+((active=='tab1')?"-active":""); el('tab2').className = "tab"+((active=='tab2')?"-active":"")+" right"; el('tab3').className = "tab"+((active=='tab3')?"-active":"")+" view"; } function keyPress(e) { if (!e) { if (!this.parentWindow) return; e = this.parentWindow.event; } if (e.ctrlKey && e.keyCode == 83) { if (el("body") && el("save-document")) { el("save-document").click(); } } if (e.altKey && e.keyCode == 49) documentInfo(); if (e.altKey && e.keyCode == 50) editContent(); } document.onkeydown = keyPress;