[Picfinity-commit] SF.net SVN: picfinity: [61] trunk/.themes/db/db.js
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-09-01 16:16:32
|
Revision: 61 http://picfinity.svn.sourceforge.net/picfinity/?rev=61&view=rev Author: espadav8 Date: 2007-09-01 09:16:32 -0700 (Sat, 01 Sep 2007) Log Message: ----------- Set the correct action for the comments form Only set up the comments div if there are comments returned Use .firstChild.nodeValue instead if .textContent since IE doesn't support that If the comments div already exists then replace it (used to reload the comments when a new one has been posted) Modified Paths: -------------- trunk/.themes/db/db.js Modified: trunk/.themes/db/db.js =================================================================== --- trunk/.themes/db/db.js 2007-08-26 11:16:59 UTC (rev 60) +++ trunk/.themes/db/db.js 2007-09-01 16:16:32 UTC (rev 61) @@ -434,7 +434,7 @@ var commentForm = document.createElement("form"); commentForm.onsubmit = addNewComment; - commentForm.action = ".themes/db/postComment.php"; + commentForm.action = ".themes/db/addComment.php"; commentForm.style.display = "none"; var commentFormFieldset = document.createElement("fieldset"); @@ -746,7 +746,7 @@ } } xmlHttp.open("GET", ".themes/db/getcomments.php?md5=" + imageID, true); - xmlHttp.send(null) + xmlHttp.send(null); } } @@ -759,85 +759,88 @@ { var comments = xmlHttp.responseXML.documentElement; - var commentsDiv = document.createElement("div"); - commentsDiv.setAttribute("id", "comments"); - - for (var i = 0; i < comments.childNodes.length; i++) + if (comments.childNodes.length > 0) { - var currentComment = comments.childNodes[i]; + var commentsDiv = document.createElement("div"); + commentsDiv.setAttribute("id", "comments"); - var comment = document.createElement("div"); - comment.className = "comment"; - if (i % 2) comment.className += " odd"; + for (var i = 0; i < comments.childNodes.length; i++) + { + var currentComment = comments.childNodes[i]; - var commentOwner = document.createElement("span"); - commentOwner.className = "name"; - var commentOwnerAnchor = document.createElement("a"); - commentOwner.appendChild(commentOwnerAnchor); + var comment = document.createElement("div"); + comment.className = "comment"; + if (i % 2) comment.className += " odd"; - var commentOwnerWeb = document.createElement("span"); - commentOwnerWeb.className = "web"; - var commentOwnerWebAnchor = document.createElement("a"); - commentOwnerWeb.appendChild(commentOwnerWebAnchor); + var commentOwner = document.createElement("span"); + commentOwner.className = "name"; + var commentOwnerAnchor = document.createElement("a"); + commentOwner.appendChild(commentOwnerAnchor); - var commentRating = document.createElement("span"); - commentRating.className = "rating"; + var commentOwnerWeb = document.createElement("span"); + commentOwnerWeb.className = "web"; + var commentOwnerWebAnchor = document.createElement("a"); + commentOwnerWeb.appendChild(commentOwnerWebAnchor); - var commentContents = document.createElement("span"); - commentContents.className = "commenttext"; + var commentRating = document.createElement("span"); + commentRating.className = "rating"; - var commentDate = document.createElement("span"); - commentDate.className = "date"; + var commentContents = document.createElement("span"); + commentContents.className = "commenttext"; - for (var j = 0; j < currentComment.childNodes.length; j++) - { - var currentNodeName = currentComment.childNodes[j].nodeName; - var currentNodeValue = currentComment.childNodes[j].textContent; + var commentDate = document.createElement("span"); + commentDate.className = "date"; - if (currentNodeName == "name") + for (var j = 0; j < currentComment.childNodes.length; j++) { - commentOwnerAnchor.appendChild(document.createTextNode(currentNodeValue)); + var currentNodeName = currentComment.childNodes[j].nodeName; + var currentNodeValue = currentComment.childNodes[j].firstChild.nodeValue; + + if (currentNodeName == "name") + { + commentOwnerAnchor.appendChild(document.createTextNode(currentNodeValue)); + } + else if (currentNodeName == "www") + { + commentOwnerWebAnchor.appendChild(document.createTextNode(currentNodeValue)); + commentOwnerWebAnchor.setAttribute("href", "http://" + currentNodeValue); + } + else if (currentNodeName == "email") + { + commentOwnerAnchor.setAttribute("href", "mailto:" + currentNodeValue); + } + else if (currentNodeName == "rating") + { + commentRating.appendChild(document.createTextNode(currentNodeValue)); + } + else if (currentNodeName == "comment_text") + { + commentContents.appendChild(document.createTextNode(currentNodeValue)); + } + else if (currentNodeName == "added") + { + commentDate.appendChild(document.createTextNode(currentNodeValue)); + } } - else if (currentNodeName == "www") - { - commentOwnerWebAnchor.appendChild(document.createTextNode(currentNodeValue)); - commentOwnerWebAnchor.setAttribute("href", "http://" + currentNodeValue); - } - else if (currentNodeName == "email") - { - commentOwnerAnchor.setAttribute("href", "mailto:" + currentNodeValue); - } - else if (currentNodeName == "rating") - { - commentRating.appendChild(document.createTextNode(currentNodeValue)); - } - else if (currentNodeName == "comment_text") - { - commentContents.appendChild(document.createTextNode(currentNodeValue)); - } - else if (currentNodeName == "added") - { - commentDate.appendChild(document.createTextNode(currentNodeValue)); - } - } - comment.appendChild(commentDate); - comment.appendChild(commentOwner); - comment.appendChild(commentOwnerWeb); - comment.appendChild(commentContents); - comment.appendChild(commentRating); + comment.appendChild(commentDate); + comment.appendChild(commentOwner); + comment.appendChild(commentOwnerWeb); + comment.appendChild(commentContents); + comment.appendChild(commentRating); - commentsDiv.appendChild(comment); - } + commentsDiv.appendChild(comment); + } - if (document.getElementById("comments")) - { - document.getElementById("comments").parentNode.replaceChild(commentsDiv, document.getElementById("comments")); + if (document.getElementById("comments")) + { + document.getElementById("comments").parentNode.replaceChild(commentsDiv, document.getElementById("comments")); + } + else + { + document.getElementById("expandedimage").parentNode.insertBefore(commentsDiv, document.getElementById("expandedimage").nextSibling); + } } - else - { - document.getElementById("expandedimage").parentNode.insertBefore(commentsDiv, document.getElementById("expandedimage").nextSibling); - } } function toggleCommentsForm() @@ -860,6 +863,7 @@ function addNewComment() { + alert("Adding a comment"); if (window.XMLHttpRequest) { var commentForm = document.getElementById("commentform").getElementsByTagName("form")[0]; @@ -875,7 +879,6 @@ xmlHttp.open("POST", ".themes/db/addComment.php", true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xmlHttp.setRequestHeader("Content-length", postData.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.onreadystatechange = function() { @@ -887,10 +890,7 @@ xmlHttp.send(postData); return false; } - else - { - return true; - } + return true; } function checkAddedCommentReply(imageID) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |