Removing AJAX from Mid-Century Commenting

Edit 2010-04-20: A year and a half after implementing Mid Century, while playing with Byrne Reese’s Mid Century 2.0 I was having these same issues. I let him know and he tells me that the Mid Century AJAX requires the option “Use Comment Confirmation Page” to be turned on under commenting preferences. Bingo! Now everything works. Probably would have fixed it here too, so if you’re having commenting issues with Mid Century, try that first.
Edit 2008-11-26: I added a download file to make it easier and clarified the instructions.
When I changed over to Mid-Century, I had some goofy things happening with commenting. It seemed related to the AJAX that powered commenting in Mid-Century.
In theory, the AJAX is pretty cool. When a comment is posted, the entire page doesn’t get rebuilt, only the comment section. The new comment is then highlighted in yellow, which is neat. In practice, it didn’t work at all on my site and adding my Google Analytics code really messed it up. I decided the AJAX magic wasn’t worth it, so I went looking for ways to de-AJAX.
Help wasn’t very forthcoming from the MT Forums or Jim Ramsey, the developer of Mid-Century (hey, people are busy), so I did some detective work.
I created a test blog and loaded the Classic Blog template set to compare Mid-Century to the default templates. I found that the two template sets to be very similar, with Mid-Century having a few more template modules and an additional javascript index template. Of course, the template content is very different, but the template listings are similar. The problem was in the ‘Comments’ template module.
I loaded each into EditPad Pro and hitting ‘compare files’ I found a lot of differences. Digging further, I found that most were due to Mid-Century using old syntax for some MT tags and Mid-Century having an ‘Individual Comment’ module that was included into the ‘Comments’ module. Reconciling those differences revealed a couple additional div tags and two script tag differences. The script tags was what I was looking for.
Mid-Century has a long additional script tag just after the ‘Comment Greeting’ div and before the form tag. It’s also missing the script from the end of the Classic Blog ‘Comments’ template, just before the closing ‘mt:IfCommentsAccepted’ tag. Fixing this removed the AJAX and made commenting worked as expected again.
While that worked, commenting was fine and the page loaded fine, I did notice that it generated a JavaScript error related to the ‘mtEntryOnUnload’ function. The JavaScript is generated by an index template named, cleverly, ‘JavaScript’. After comparing the Mid-Century JavaScript template to the Classic Blog JavaScript template, I found several variations (the template is 800+ lines), at least one relating to the ‘mtEntryOnUnload’ function. I don’t know JavaScript, but I figured I could replace the Mid-Centurry file with the lassic Blog file and see what happens, backing up the original first. I gave it a shot and it worked, no more JavaScript errors.
So, removing AJAX is fairly easy. I made a duplicate of my original JavaScript & Comments templates in MT before I started, just in case. Here are the changes you need to make:

  1. In your Mid-Century ‘Comments’ template module, comment or delete the long script tag just before the form tag.
  2. Also in your Mid-Century ‘Comments’ template module, add the short, 6 line script tag from the Classic Blog ‘Comments’ template module, just before the closing ‘mt:IfCommentsAccepted’ tag.
  3. Swap out the contents of the MidCentury JavaScript template for the contents of the Classic Blog JavaScript template.

So you don’t have to create a new blog to get the Classic Blog template content, you can find the added content in this text file.
That’s it, now your Mid-Century comment system is de-AJAX’ed.

16 thoughts on “Removing AJAX from Mid-Century Commenting

  1. Any chance you could post the code changes — what’s there now, and what to replace them with? While your instructions seem clear, that would reduce any chance for error, and ensure that people who want to try this do it right. Unless I’m mistaken, what you’re recommending would require creating a new blog to get the appropriate template code.

  2. You’re right, I added a download file with the added content and cleaned up the instructions. I included the script to remove, the script to add and the new contents of the JavaScript index template.

  3. If your weirdness is related to commenting, it might. If it’s not related to commenting, I doubt it will.
    BTW – I like what you’ve done with Mid-Century, specifically expanding the top border. That was on my to-do list, mind sharing the CSS code you used to do that?

  4. I had the same weirdness you did, but I also have a situation with all my registration/signing-in options disappearing with Mid-Century. (It used to work properly.)
    I’ve e-mailed you the css file and template code that should include all the modifications necessary. Alas, it is not in anything resembling a user-friendly instruction format. If you’d like, I can try to work on that.
    In addition to the header, I added a hanging indent on the entry metadata and switched the comment balloon the right side. Again, I’m happy to try to figure out what I did and assist anybody else who wants to make similar changes.

  5. Thanks, I’m going to play with it. I’m still having issues with the standard MT commenting script that’s supposed to hide & show the form depending on if you’re logged in. I’ve noticed it doesn’t work right on Byrne’s blog either, I think.
    The weird thing about all of this is the brand new test blog I made works just fine with the standard Mid-Century templates. I’m glad to be rid of the AJAX, though.
    The tip I’ve learned with CSS is to put your changes or additions in a separate file and include it in the main file, just like the main Mid-Century CSS is. That way your changes are separate from the Mid-Century file.

  6. I’m not the most methodical of fiddlers, and I’ve thought about the pain in the ass it will be if there’s a new version of Mid-Century, considering the changes I’ve made. I’ll look into a separate CSS file.
    Is there something you’d recommend to compare the two CSS files so that I can easily separate my changes?

  7. I use EditPad Pro for my text editor. It has a free version(EditPad Lite) but I ponied up for the Pro version that gives you syntax highlighting, spell checker and some other stuff. It allows you to compare two files in various ways. It’ll highlight the lines in each file that are different.
    I started customizing Mid-Century here. I moved the search & Feed links to the nav bar. I’m using a separate CSS file, you can grab it here. You’ll see the commented original sections of the file with line numbers noted and then the custom bits after. That way I know what I changed without digging back through the original file. I may write up what I did when I’m done or as I go, I haven’t decided.

  8. Found a tiny bug in your Javascript.js
    For this block of code:
    function mtSetCommentParentID() {
    var checkbox = document.getElementById(‘comment-reply’);
    var parent_id_field = document.getElementById(‘comment-parent-id‘);
    if (!checkbox || !parent_id_field) return;
    var pid = 0;
    if (checkbox.checked == true)
    pid = checkbox.value;
    parent_id_field.value = pid;
    comment-parent-id should be comment-parent_id instead.
    I think it’s important especially if you wanna make use of the “Reply” function in your comments.

  9. Hmmm, that’s odd since I didn’t edit any of the javascript, it’s the default straight out of MT.
    I tried using the reply function here, let’s see if it worked..

  10. You’re right, the “reply to” didn’t work. Odd, I’ll look into it, thanks, but it’s pretty low on my priority list. 😀

  11. Thanks for this! I had some problems getting this to work and have never been a big fan of AJAX stuff, so this was really helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *

On This Day

Recent Posts

Recent Comments