Still not ready for release but here is the experamental code I'm using to enable CommentLuv, I installed it with the new website look.
Here is the script for enabling CommentLuv there are still a few features that need to be added.
Once I'm done I'll upload all the code changes with instructions on how to implement the new code
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>",
//link: "<!--commentLuvStart--><br/><br/>{0}'s last blog post.. <a href=\"{1}\" target=\"_blank\">{2}</a>",
init: function() {
try {
var websiteBox = BlogEngine.comments.websiteBox;
if (websiteBox == null) return;
// attach UI elements: checkbox and label
commentLuv.appendElements();
// keep ref for old addComment to be used later
BlogEngine.addComment_Old = BlogEngine.addComment;
// create a new addComment function that support commentLuv
BlogEngine.addComment = function(preview) {
// if no data was found or commentluv is disabled by the user exit, use addComment_Old and exit
if (commentLuv.data == null || !commentLuv.enabled) {
BlogEngine.addComment_Old(preview);
return;
};
// check for html injection
if (BlogEngine.comments.contentBox.value.indexOf("<!--commentLuvStart-->") > -1) return false;
try {
// process data from commentLuv web service, service is called in websitebox.onchange and when posibly during init
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 ref for preview, used to revert back to comment without latest post
commentLuv.comments = BlogEngine.comments.contentBox.value;
};
var link = commentLuv.link;
// replace comment contents with content and latest post
BlogEngine.comments.contentBox.value = BlogEngine.comments.contentBox.value + link.replace("{0}", author).replace("{1}", url).replace("{2}", title);
}
catch (errObj) {
// unknown error, just use old addComment_Old and exit, not critical that commentluv works
BlogEngine.addComment_Old(preview);
return;
};
// prep work done add comment
BlogEngine.addComment_Old(preview);
if (preview) {
// the user requested a preview revert back to original comments
BlogEngine.comments.contentBox.value = commentLuv.comments;
}
else {
// clear
BlogEngine.comments.contentBox.value = "";
commentLuv.comments = "";
};
}; // BlogEngine.addComment end
// add onchange handler to websitebox to capture url changes
$addHandler(websiteBox, "change", commentLuv.website_onChange);
// test if url was cached
if (websiteBox.value.length == 0) return;
// url was cached contact server to get latest post
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) {
// do nothing
};
},
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() {
// this function contains basic javascrit not going to document
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";
// using a label element wouldn't display properly, moving on by using span
var label = document.createElement("span");
label.appendChild(document.createTextNode(commentLuv.message));
parent.insertBefore(label, cbNotify);
//label.htmlFor = enabledCheckbox.id;
label.style.width = "auto";
label.style.display = "inline";
label.style.cssFloat = "none";
enabledCheckbox.setAttribute("tabindex", 7);
cbNotify.setAttribute("tabindex", 8);
//width:auto;float:none;display:inline
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() {
// if keyword is passed in with the author name parse out the keywords and return the author name
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) {
// basic add handler function
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 the websitetextbox changes we call the server to get the latest post here
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);
};
}
};
//create a global addHandler function
if (typeof ($addHandler) == "undefined")
window.$addHandler = commentLuv.addHandler;
// hook into the app load event so that commentLuv can attach to the elements
BlogEngine.addLoadEvent(commentLuv.init);