var commentLuv = {
enabled: true,
message: "CommentLuv enabled",
link: "<!--commentLuvStart--><p class=\"commentLuv\"><abbr><em>{0}'s last blog post.. <a href=\"{1}\" target=\"_blank\">{2}</a></em></abbr></p>",
init: function() {
try {
var websiteBox = BlogEngine.comments.websiteBox;
if (websiteBox == null) return;
commentLuv.appendElements();
BlogEngine.addComment_Old = BlogEngine.addComment;
BlogEngine.addComment = function(preview) {
if (commentLuv.data == null || !commentLuv.enabled) {
BlogEngine.addComment_Old(preview);
return;};
if (BlogEngine.comments.contentBox.value.indexOf("<!--commentLuvStart-->") >-1) return false;
try {
var title = commentLuv.data.links[0].title;
var url = commentLuv.data.links[0].url;
var content = BlogEngine.comments.contentBox.value;
var author = commentLuv.getAuthor();
if (preview) {
commentLuv.comments = BlogEngine.comments.contentBox.value;};
var link = commentLuv.link;
BlogEngine.comments.contentBox.value = BlogEngine.comments.contentBox.value+link.replace("{0}", author).replace("{1}", url).replace("{2}", title);}
catch (errObj) {
BlogEngine.addComment_Old(preview);
return;};
BlogEngine.addComment_Old(preview);
if (preview) {
BlogEngine.comments.contentBox.value = commentLuv.comments;}
else {
BlogEngine.comments.contentBox.value = "";
commentLuv.comments = "";};}; // BlogEngine.addComment end
$addHandler(websiteBox, "change", commentLuv.website_onChange);
if (websiteBox.value.length == 0) return;
var url = "commentLuv.axd?website="+websiteBox.value;
BlogEngine.createCallback(url, function(response) {
commentLuv.data = eval(response);
commentLuv.updateLastPostMessage();});}
catch (errObj) {
alert("Unknown javascript error in CommentLuv:init, error: "+errObj.description);};},
clearLastPostElement: function() {
var lastPostElement = commentLuv.lastPostElement;
if (lastPostElement == null) return;
try {
while (lastPostElement.firstChild != null) {
lastPostElement.removeChild(lastPostElement.firstChild);};}
catch (ignorErr) {};},
updateLastPostMessage: function() {
try {
var lastPostElement = commentLuv.lastPostElement;
if (lastPostElement == null) return;
commentLuv.clearLastPostElement();
var title = commentLuv.data.links[0].title;
var url = commentLuv.data.links[0].url;
var author = commentLuv.getAuthor();
lastPostElement.appendChild(document.createTextNode(author+"'s last blog post.. "));
var link = document.createElement("a");
lastPostElement.appendChild(link);
link.target = "_blank";
link.href = url;
link.appendChild(document.createTextNode(title));}
catch (errObj) {
window.setTimeout(1000, commentLuv.updateLastPostMessage);
alert("Unknown javascript error in CommentLuv:updateLastPostMessage. Error: "+errObj.description);};},
appendElements: function() {
try {
var cbNotify = $("cbNotify");
if (cbNotify == null) {
alert("cbNotify not found");
return;};
var parent = cbNotify.parentNode;
var lastPostElement = commentLuv.lastPostElement = document.createElement("p");
lastPostElement.id = "lastPostMessage";
parent.insertBefore(lastPostElement, cbNotify);
var enabledCheckbox = document.createElement("input");
enabledCheckbox.type = "checkbox";
parent.insertBefore(enabledCheckbox, cbNotify);
$addHandler(enabledCheckbox, "change", function() {
commentLuv.enabled = !commentLuv.enabled;});
enabledCheckbox.checked = true;
enabledCheckbox.id = "commentLuvCheckbox";
enabledCheckbox.style.width = "auto";
enabledCheckbox.style.display = "inline";
var label = document.createElement("span");
label.appendChild(document.createTextNode(commentLuv.message));
parent.insertBefore(label, cbNotify);
label.style.width = "auto";
label.style.display = "inline";
label.style.cssFloat = "none";
enabledCheckbox.setAttribute("tabindex", 7);
cbNotify.setAttribute("tabindex", 8);
parent.insertBefore(document.createElement("br"), cbNotify);
parent.insertBefore(document.createElement("br"), cbNotify);}
catch (errObj) {
alert("Unknow javascript error in commentLuv:appendElements. Error, "+errObj.description);};},
getAuthor: function() {
var author = BlogEngine.comments.nameBox.value;
var keywordStartIndex = author.indexOf("@");
if (keywordStartIndex < 0)
return author;
return author = author.substring(0, keywordStartIndex)},
addHandler: function(element, eventName, handler) {
if (element.attachEvent)
element.attachEvent('on'+eventName, handler);
else if (element.addEventListener)
element.addEventListener(eventName, handler, false);
else
throw "browser not supported";},
website_onChange: function() {
try {
if (!commentLuv.enabled) return;
commentLuv.data = null;
commentLuv.clearLastPostElement();
if (BlogEngine.comments.websiteBox.value.length == 0) return;
var url = "commentLuv.axd?website="+BlogEngine.comments.websiteBox.value;
BlogEngine.createCallback(url, function(response) {
commentLuv.data = eval(response);
commentLuv.updateLastPostMessage();});}
catch (errObj) {
alert("Unknown javascript error in CommentLuv:website_onChange. Error: "+errObj.description);};}};
if (typeof ($addHandler) == "undefined")
window.$addHandler = commentLuv.addHandler;
BlogEngine.addLoadEvent(commentLuv.init);
