Update of /cvsroot/mxbb/mx_bugsbt/bugsbt/includes/js In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7691/bugsbt/includes/js Added Files: common.js debug.js form.js index.htm init_main.js management.js.php request.js.php Log Message: Ok. here we go. This is the cool new mxBB Bugtracker ;) --- NEW FILE: form.js --- // Forms, some help functions. // Author: Cezary Tomczak [www.gosu.pl] // submit button must have name "submit" to get this working window.onload = function() { document.forms[0].onsubmit = function() { if (!document.forms[0].submit.disabled) { document.forms[0].submit.disabled = true; return true; } return false; }; }; function isNumber(s) { if (s.length && s.charAt(0) == "-") { return isNumber(s.substr(1)); } if (!(/^[\d.]+$/.test(s))) { return false; } if (s.indexOf(".") != -1 && (s.indexOf(".") != s.lastIndexOf("."))) { return false; } if (s.charAt(0) == ".") { return false; } if (s.length >= 2 && s.charAt(0) == "0" && s.charAt(1) != ".") { return false; } return !isNaN(s); } --- NEW FILE: management.js.php --- <?php //require '../../../config.php'; //$CONFIG['encoding'] is replaced by iso-8859-1 ?> // +--------------------------------------------------------------------+ // | 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; } product_update = false; //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 viewBugs() { //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_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'mode':'product', 'cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), '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('tab_bugs'); 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 reportBug() { if ( !tree.active || !tree.getActiveNode().isDocument()) { alert("You have to select a Product Build in the Tree View to perform this action."); return; } checkContentSaved(); AjaxRequest.get( { 'url':'modules/mx_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'mode':'post', 'cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), '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('tab_report'); 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 editBug(bug_id) { if ( !bug_id && (typeof current_bug_id == "undefined") ) { alert("You have to select a Bug to perform this action."); return; } bug_id = (bug_id > 0) ? bug_id : current_bug_id; current_bug_id = bug_id; checkContentSaved(); AjaxRequest.get( { 'url':'modules/mx_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'k': bug_id, 'mode':'post', 'cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), '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('tab_edit'); 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 viewBug(bug_id) { if ( !bug_id && (typeof current_bug_id == "undefined") ) { alert("You have to select a Bug to perform this action."); return; } bug_id = (bug_id > 0) ? bug_id : current_bug_id; current_bug_id = bug_id; checkContentSaved(); AjaxRequest.get( { 'url':'modules/mx_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'k': bug_id, 'mode':'view', 'cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), '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('tab_view'); 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 updateTree() { if ( !tree.active ) { alert("Problem updating the tree."); return; } AjaxRequest.get( { 'url':'modules/mx_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'mode':'update_tree', 'cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { } ,'onComplete':function() { } ,'onSuccess':function(req){ tree.rename(req.responseText);} ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;} ,'timeout':5000 ,'onTimeout':function(){ el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); } function saveContent(theform) { if (!checkForm(theform)) { return; } var return_data = ''; var status = AjaxRequest.submit( theform ,{ 'onLoading':function() { tabsSavingOn(); el('submit').disabled = true; } ,'onComplete':function() { tabsSavingOff(); el('submit').disabled = false; } ,'onSuccess':function(req){ return_data = stripBodyHtml(req.responseText); } ,'onError':function(req){ el('tabs-data').innerHTML = 'Error!\nStatusText='+req.statusText+'\nContents='+req.responseText;} ,'timeout':5000 ,'onTimeout':function(){ clearTabs(); tabsSavingOff(); el('tabs-data').innerHTML = 'Timed out. Try again!'; } } ); //el('body-tmp').value = el('body').value; if ((typeof status == "boolean" && !status) || typeof status == "string") { alert("Unknown error, cannot save document."); } else { el('saved').innerHTML = "Saved successfuly on "+(new Date()+"<br>(this message will disappear in 1 second)"); if (return_data != "") { el('saved').innerHTML = return_data; return; } product_update = true; if (savedTimerID) clearTimeout(savedTimerID); savedTimerID = setTimeout(function(){ clearTabs(); viewBugs(); updateTabs('tab_bugs');}, 1000); } return status; } function deleteBug(do_delete) { if ( typeof current_bug_id == "undefined" ) { alert("You have to select a Bug to perform this action."); return; } bug_id = current_bug_id; current_bug_id = bug_id; if (!confirm("Really Delete this Bug?")) { return; } var return_data = ''; AjaxRequest.get( { 'url':'modules/mx_bugsbt/bugsbt/modules/tabs/bugsbt__tab-index.php' ,'parameters':{ 'k': bug_id, 'mode':'edit', 'do':'delete','cat':escape(treeGetId().substr(treeGetId().lastIndexOf("/")+1)), 'block_id':mxBlock.block_id, 'page_id':mxBlock.page_id } ,'onLoading':function() { tabsLoadingOn(); } ,'onComplete':function() { tabsLoadingOff(); } ,'onSuccess':function(req){ return_data = stripBodyHtml(req.responseText); updateTabs('tab_delete');} ,'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!'; } } ); el('saved').innerHTML = "Deleted successfuly on "+(new Date()+"<br>(this message will disappear in 1 second)"); if (return_data != "") { el('saved').innerHTML = return_data; return; } product_update = true; if (savedTimerID) clearTimeout(savedTimerID); savedTimerID = setTimeout(function(){ clearTabs(); viewBugs(); updateTabs('tab_bugs');}, 1000); } 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 stripBodyHtml(html) { // Remove HTML comments //html = html.replace(/<!--[\w\s\d@{}:.;,'"%!#_=&|?~()[*+\/\-\]]*-->/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 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("submit")) { 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('tab_bugs')) {el('tab_bugs').className = "tab";} if(el('tab_report')) {el('tab_report').className = "tab view";} if(el('tab_view')) {el('tab_view').className = "tab";} if(el('tab_edit')) {el('tab_edit').className = "tab right";} if(el('tab_delete')) {el('tab_delete').className = "tab view";} if (product_update) { updateTree(); product_update = false; } //if(el('tabs-data')) {el('tabs-data').innerHTML = "";} } function updateTabs(active){ if(el('tab_bugs')) {el('tab_bugs').className = "tab"+((active=='tab_bugs')?"-active":"");} if(el('tab_report')) {el('tab_report').className = "tab"+((active=='tab_report')?"-active":"")+" view";} if(el('tab_view')) {el('tab_view').className = "tab"+((active=='tab_view')?"-active":"")+"";} if(el('tab_edit')) {el('tab_edit').className = "tab"+((active=='tab_edit')?"-active":"")+" right";} if(el('tab_delete')) {el('tab_delete').className = "tab"+((active=='tab_delete')?"-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("submit")) { el("submit").click(); } } if (e.altKey && e.keyCode == 49) viewBugs(); if (e.altKey && e.keyCode == 50) reportBug(); } document.onkeydown = keyPress; --- NEW FILE: init_main.js --- function treeGetId() { if (tree.active) { return tree.active.substr("tree-".length); } return ""; } /** RSH must be initialized after the page is finished loading. */ window.onload = initialize; tree.textClickListener.add(function() { if (document.getElementById("tree-insert-form").style.display == "block") { treeInsert(); } }); tree.textClickListener.add(function() { if (!tree.getActiveNode().isDocument()) { if (tree.getActiveNode().childNodes) { for (var i = 0; i < tree.getActiveNode().childNodes.length; i++) { if (tree.getActiveNode().childNodes[i].isDocument()) { //queryPath = tree.getActiveNode().childNodes[i].id; //tree.queryPath = queryPath.replace('tree-', ""); //tree.active = queryPath; //tree.loadState(); //tree.updateHtml(); //break; } } } } }); tree.textClickListener.add(function() { //if (tree.getActiveNode().isDocument()) { // if (getCookie('openEditBug')) editBug(); // else viewBugs(); viewBugs(); document.title = el(tree.active+"-text").innerHTML; //} //else //{ // clearTabs(); //} }); function initialize() { // initialize RSH dhtmlHistory.initialize(); // add ourselves as a listener for history change events dhtmlHistory.addListener(handleHistoryChange); if (dhtmlHistory.isFirstLoad()) { // determine our current location so we can initialize ourselves at startup var initialLocation = dhtmlHistory.getCurrentLocation(); // if no location specified, use the default if ((initialLocation == '' || initialLocation == null) && tree.allNodes[0]) { if (tree.allNodes[0].childNodes) { // First set default, then loop to find real document queryPath = tree.allNodes[0].id; for (var i = 0; i < tree.allNodes[0].childNodes.length; i++) { if (tree.allNodes[0].childNodes[i].isDocument()) { queryPath = tree.allNodes[0].childNodes[i].id; break; } } } else { queryPath = tree.allNodes[0].id; } initialLocation = queryPath.replace('tree-', ""); } // now initialize our starting UI if (tree.allNodes[0]) { updateUI(initialLocation, null); } } } /** A function that is called whenever the user presses the back or forward buttons. This function will be passed the newLocation, as well as any history data we associated with the location. */ function handleHistoryChange(newLocation, historyData) { // use the history data to update our UI updateUI(newLocation, historyData); } /** A simple method that updates our user interface using the new location. */ function updateUI(newLocation, historyData) { //alert('updateUI'); tree.queryPath = newLocation; tree.setActive(); tree.loadState(); tree.updateHtml(); } var treeElements = ["tree-moveUp", "tree-moveDown", "tree-moveLeft", "tree-moveRight", "tree-insert", "tree-remove"]; var treeTooltips = ["Move Up", "Move Down", "Move Left", "Move Right", "Insert", "Delete"]; function treeTooltipOn() { document.getElementById("tree-tooltip").innerHTML = treeTooltips[treeElements.indexOf(this.id)]; } function treeTooltipOff() { document.getElementById("tree-tooltip").innerHTML = ""; } for (var i = 0; i < treeElements.length; i++) { document.getElementById(treeElements[i]).onmouseover = treeTooltipOn; document.getElementById(treeElements[i]).onmouseout = treeTooltipOff; } document.getElementById("tree-moveUp").onclick = treeMoveUp; document.getElementById("tree-moveDown").onclick = treeMoveDown; document.getElementById("tree-moveLeft").onclick = treeMoveLeft; document.getElementById("tree-moveRight").onclick = treeMoveRight; if (document.all && !/opera/i.test(navigator.userAgent)) { document.getElementById("tree-moveUp").ondblclick = treeMoveUp; document.getElementById("tree-moveDown").ondblclick = treeMoveDown; document.getElementById("tree-moveLeft").ondblclick = treeMoveLeft; document.getElementById("tree-moveRight").ondblclick = treeMoveRight; } document.getElementById("tree-insert").onclick = treeInsert; document.getElementById("tree-remove").onclick = treeRemove; document.getElementById("tree-insert-button").onclick = treeInsertExecute; document.getElementById("tree-insert-cancel").onclick = treeHideInsert; function treeMoveUp() { if (tree.mayMoveUp() && httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=moveUp&id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.moveUp(); } else { alert('Cannot move up'); } } function treeMoveDown() { if (tree.mayMoveDown() && httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=moveDown&id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.moveDown(); } else { alert('Cannot move down'); } } function treeMoveLeft() { if (tree.mayMoveLeft() && httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=moveLeft&id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.moveLeft(); } else { alert('Cannot move left'); } } function treeMoveRight() { if (tree.mayMoveRight() && httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=moveRight&id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.moveRight(); } else { alert('Cannot move right'); } } function treeInsert() { document.getElementById("tree-insert-form").style.display = "block"; document.getElementById("tree-insert-where-div").style.display = (tree.active ? "" : "none"); if (tree.active) { var where = document.getElementById("tree-insert-where"); if (tree.mayInsertInside()) { if (!where.options[2] && !where.options[3]) { where.options[2] = new Option("Inside at start", "inside_start"); where.options[3] = new Option("Inside at end", "inside_end"); } } else if (where.options[2] && where.options[3]) { where.options[2] = null; where.options[3] = null; where.options.length = 2; } } } /* only event - blur */ function treeInsertExecute() { var where = document.getElementById("tree-insert-where"); var type = document.getElementById("tree-insert-type"); var name = document.getElementById("tree-insert-name"); name.value = name.value.trim(); if (!name.value) { alert("Name is empty"); return; } if (name.value.substr(-5) == ".html") { name.value = name.value.substr(0, name.value.length-5); } var id = escape(name.value); if (type.value != "folder") { id = escape(name.value + ".html"); } if (tree.active) { switch (where.value) { case "before": if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=insertBefore&id="+escape(treeGetId())+"&name="+id+"&is_folder="+(type.value=="folder" ? 1 : 0)+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.insertBefore(id, name.value, type.value); } break; case "after": if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=insertAfter&id="+escape(treeGetId())+"&name="+id+"&is_folder="+(type.value=="folder" ? 1 : 0)+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.insertAfter(id, name.value, type.value); } break; case "inside_start": if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=insertInsideAtStart&id="+escape(treeGetId())+"&name="+id+"&is_folder="+(type.value=="folder" ? 1 : 0)+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.insertInsideAtStart(id, name.value, type.value); } break; case "inside_end": if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=insertInsideAtEnd&id="+escape(treeGetId())+"&name="+id+"&is_folder="+(type.value=="folder" ? 1 : 0)+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.insertInsideAtEnd(id, name.value, type.value); } break; } } else { if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=insert&id="+escape(treeGetId())+"&name="+id+"&is_folder="+(type.value=="folder" ? 1 : 0)+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.insert(id, name.value, type.value); } } name.value = ""; this.blur(); } function treeHideInsert() { var name = document.getElementById("tree-insert-name"); name.value = ""; document.getElementById("tree-insert-form").style.display = "none"; } function treeRemove() { if (tree.mayRemove()) { if (confirm("Delete current node ?")) { if (httpSave("modules/mx_simpledoc/simpledoc/modules/simpledoc__node.php?do=remove&id="+escape(treeGetId())+'&block_id='+mxBlock.block_id+'&page_id='+mxBlock.page_id)) { tree.remove(); if (document.getElementById("tree-insert-form").style.display == "block") { treeInsert(); } clearTabs(); } } } else { alert('Cannot remove. You have not selected any node or the folder is not empty.'); } } --- NEW FILE: request.js.php --- <?php //require '../../../config.php'; //$CONFIG['encoding'] is replaced by iso-8859-1 ?> // +--------------------------------------------------------------------+ // | DO NOT REMOVE THIS | // +--------------------------------------------------------------------+ // | request.js | // | Functions for getting and saving data using XMLHttpRequest object. | // +--------------------------------------------------------------------+ // | Author: Cezary Tomczak [www.gosu.pl] | // | Project: SimpleDoc | // | URL: http://gosu.pl/php/simpledoc.html | // | License: GPL | // +--------------------------------------------------------------------+ /* Note (httpLoad): seems like IE always caches retrieved data until you close the browser, so when you call a few times the same url, it always returns the same, even if the content in the given url changed. There are 2 solutions: add to url some random query string or in the url script send NOCACHE headers. */ // returns: false|string(responseText) function httpLoad(url) { var req; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.open("GET", url, false); req.setRequestHeader('Accept-Charset','iso-8859-1'); req.send(null); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.open("GET", url, false); req.setRequestHeader('Accept-Charset','iso-8859-1'); req.send(); } else { alert("Could not create ActiveXObject (XMLHttpRequest)"); return false; } } else { alert("Your browser does not support XMLHttpRequest object"); return false; } if (req.status != 200) { alert("There was a problem while retrieving the data:\n" + req.statusText); req.abort(); return false; } return req.responseText; } // returns: true|false|string(responseText) function httpSave(url, data) { var req; var p; var content = ""; if (data) { for (var p in data) { if (content) { content += "&"; } content += (p + "=" + escape(data[p])); } } if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.open("POST", url, false); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); req.send(content); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.open("POST", url, false); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); req.send(content); } else { alert("Could not create ActiveXObject (XMLHttpRequest)"); return false; } } else { alert("Your browser does not support XMLHttpRequest object"); return false; } if (req.status != 200) { alert("There was a problem while sending the data:\n" + req.statusText); req.abort(); return false; } if (req.responseText.length) { alert(req.responseText); return false; } return true; } --- NEW FILE: common.js --- // +--------------------------------------------------------------------+ // | DO NOT REMOVE THIS | // +--------------------------------------------------------------------+ // | common.js | // | Some common help functions used all over the project. | // +--------------------------------------------------------------------+ // | Author: Cezary Tomczak [www.gosu.pl] | // | Project: SimpleDoc | // | URL: http://gosu.pl/php/simpledoc.html | // | License: GPL | // +--------------------------------------------------------------------+ function element(id) { return document.getElementById(id); } function elem(id) { return document.getElementById(id); } function el(id) { return document.getElementById(id); } /* Check whether array contains given string */ Array.prototype.contains = function(s) { for (var i = 0; i < this.length; i++) { if (this[i] === s) { return true; } } return false; }; /* Finds the index of the first occurence of item in the array, or -1 if not found */ Array.prototype.indexOf = function(item) { for (var i = 0; i < this.length; i++) { if (this[i] === item) { return i; } } return -1; }; /* Get the last element from the array */ Array.prototype.getLast = function() { return this[this.length-1]; }; /* Remove element with given index (mutates) */ Array.prototype.removeByIndex = function(index) { this.splice(index, 1); }; /* Remove elements with such value (mutates) */ Array.prototype.removeByValue = function(value) { var i, indexes = []; for (i = 0; i < this.length; i++) { if (this[i] === value) { indexes.push(i); } } for (i = indexes.length - 1; i >= 0; i--) { this.splice(indexes[i], 1); } }; /* Push an element at specified index */ Array.prototype.pushAtIndex = function(el, index) { this.splice(index, 0, el); }; /* Strip whitespace from the beginning and end of a string */ String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g, ""); }; /* Count the number of substring occurrences */ String.prototype.substrCount = function(s) { return this.split(s).length - 1; }; // Getting, Setting and Deleteing cookies. // Author: Cezary Tomczak [www.gosu.pl] // Note: name cannot contain 2 chars: =; function Cookie() { this.get = function(name) { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; ++i) { var a = cookies[i].split("="); if (a.length == 2) { a[0] = a[0].trim(); a[1] = a[1].trim(); if (a[0] == name) { return unescape(a[1]); } } } return ""; }; this.set = function(name, value, seconds, path) { var cookie = (name + "=" + escape(value)); if (seconds) { var date = new Date(new Date().getTime()+seconds*1000); cookie += ("; expires="+date.toGMTString()); } cookie += (path ? "; path="+path : ""); document.cookie = cookie; }; this.del = function(name, path) { var cookie = (name + "="); cookie += (path ? "; path="+path : ""); cookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT"; document.cookie = cookie; }; } var COOKIE_MONTH = 3600*24*30; var COOKIE_YEAR = 3600*24*30*12; function getCookie(name) { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; ++i) { var a = cookies[i].split("="); if (a.length == 2) { a[0] = a[0].trim(); a[1] = a[1].trim(); if (a[0] == name) { return unescape(a[1]); } } } return ""; } function setCookie(name, value, seconds, path) { var cookie = (name + "=" + escape(value)); if (seconds) { var date = new Date(new Date().getTime()+seconds*1000); cookie += ("; expires="+date.toGMTString()); } cookie += (path ? "; path="+path : ""); document.cookie = cookie; } function delCookie(name, path) { var cookie = (name + "="); cookie += (path ? "; path="+path : ""); cookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT"; document.cookie = cookie; } function addEvent(obj, event, func) { if (obj.addEventListener) { obj.addEventListener(event, func, false); } else if (obj.attachEvent) { obj.attachEvent("on"+event, func); } } --- NEW FILE: debug.js --- var debugWindow = null; function debug(s, name) { if (!debugWindow) { debugWindow = window.open("", "debugWindow", "width=400,height=500,scrollbars=yes,resizable=yes"); debugWindow.document.write("<pre>"); } if (name) { debugWindow.document.write('<div style="font: 12px sans-serif; font-weight: bold;">'+name+'</div>'); } debugWindow.document.write(s + "\n"); } function debugObject(obj, name) { var s = ''; for (var i in obj) { if (obj[i] && (typeof obj[i] == "object" || typeof obj[i] == "function") && obj[i].toString) { s += "Object." + i + "=" + obj[i].toString().replace(/\n/g, "") + "\n"; } else { s += "Object." + i + "=" + obj[i] + "\n"; } } debug(s, name); } function debugArray(arr, name) { var s = ''; for (var i = 0; i < arr.length; ++i) { s += "Array[" + i + "]=" + arr[i] + "\n"; } debug(s, name); } --- NEW FILE: index.htm --- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> |