WordPress.org

Support

Support » Plugins and Hacks » New Plugin: Expand Comments (w/ AJAX)

New Plugin: Expand Comments (w/ AJAX)

  • BitwiseMcgee
    Member

    @bitwisemcgee

    Hey guys,

    I just wrote my first plugin for WordPress, and it needs testing. I don’t have a huge amount of free time to test, so I’d love if people could tell me what they think. So far I’m sure it works on WP 2.0…

    Anyway, Expand Comments is a plugin that uses AJAX to provide a blog with a link on the bottom of each post. When the link is pressed, the comments (read from the RSS feed) will be appeneded immediately below the post, without any page refreshing. It really speeds up the reading of a site, and also gives it a sexy feel. The comments can then be hidden by clicking the same link. Each expansion/contraction of a comment section is only downloaded once. after that, CSS just hides/displays the comments.

    This is my first real time working with javascript, and first time ever with any php. I’m sure there’s a lot to improve upon, so I’m hoping you guys can help me with that.

    The plugin also degrades gracefully. If the user is not using javascript, the “Expand” link becomes the RSS link to that post.

    to see a working demo, go to my site: http://nymb.us

    You can find a bit more info + download at http://nymb.us/?page_id=45

    thanks

Viewing 15 replies - 1 through 15 (of 42 total)
  • Looks good, though one suggestion – would it be possible to make the expand link only appear if there is at least one comment? I found myself trying to expand a ‘no comments’ post and wondering why it was not working.

    BitwiseMcgee
    Member

    @bitwisemcgee

    Hm, I was thinking that myself. I suppose it wouldn’t be too hard to add that, I really just want to make sure that it works on most/all browsers before adding things. That’s definitely something I’m going to add though. Would it be better to remove the link entirely? or have it show up as the rss link instead?

    I would go for total removal, a link to the rss might be confusing for people.

    Kickass!

    *downloads*

    Edit: You need to loose the whitespace at the beginning and end in your plugin. 😉

    Edit #2: Mispelling on your page. You have an s in the function name: <?php expand_comments_link(); ?>

    BitwiseMcgee
    Member

    @bitwisemcgee

    whitespace? could you specify please?

    You have a line break before your first <?php and after your last ?>.

    Edit: You also have an s in the function name for the div on your install page too: <?php expand_comments_div(); ?>

    Edit #2: Hmm, when I click the link, it takes me to the feed for the post and doesn’t expand the comments. Yep, the JS is working as it’s replacing the “RSS” with “Expand Comments” and I see the plugin’s <div> in my source code, so weird…

    Uploaded / activated the plugin on my test site. Perhaps you can figure out what the problem is…

    http://test.viper007bond.com/wordpress-latest/#post-9

    BitwiseMcgee
    Member

    @bitwisemcgee

    ahh, you know what that is, its because the expand-comments.js include is just a relative url, not a full y qualified url. At least that’s my first guess, since firefox says makeAjaxRequest isn’t a defined js function.

    Give me a short while to fix, thanks

    BitwiseMcgee
    Member

    @bitwisemcgee

    alright, try redownloading it now. Also, I added the “no comments, no link” feature

    w.r.t. the invalid, I’ll have to fix that, but I don’t think that’s the problem. so far the plugin is XHTML 1.0 trans. validated, but I’m not up on all the specs, so I’ll have to look into that

    Sweet, works now! 😀

    Although IMO the expand_comment_link() function should accept parameters of what to output before and after the link (so that the stuff only shows up if the link is gonna show up).

    Also, the comments div shouldn’t show up if there’s 0 posts. Waste of HTML. 🙂

    BitwiseMcgee
    Member

    @bitwisemcgee

    Awesome! glad it works 🙂

    yeah, I want to expand upon expand_comment_link so the text isn’t hardcoded, etc. What do you mean by ‘so the stuff only shows up’? which stuff?

    also, I’ll fix the div part too so it uses the same if comment # > 0 code.

    finally, w.r.t. the XHTML 1.1, it looks like the name attribute doesn’t exist for anchor tags. Does the title attribute work similarly? IE: can I use the title attr to get those objects out of the DOM? right now the name attr is used so that the link can be ‘ajaxified’ by doing a document.getElementsByName() call. if Title can be used the same way, then this should be made XHTML 1.1 compliant very easily

    courtneyelizabeth
    Member

    @courtneyelizabeth

    Still having this issue as described by Bond:

    Edit #2: Hmm, when I click the link, it takes me to the feed for the post and doesn’t expand the comments. Yep, the JS is working as it’s replacing the “RSS” with “Expand Comments” and I see the plugin’s <div> in my source code, so weird…

    BitwiseMcgee
    Member

    @bitwisemcgee

    there’s also an issue with the nature of AJAX that’s noted in the readme, namely, if a person is on your site at, say, http://www.site.com, and the wordpress install and all the links are at site.com (no www.) then the browser security will stop ajax from retrieving anything. Basically browsers think that you don’t want it to get data from anywhere but where you’re currently browsing.

    I haven’t had time to look into it too much, but my ‘quick fix’ is to redirect requests to http://www.nymb.us to nymb.us, and all works.

    where are you trying to get this to work at?

    edit: to clarify, if your RSS link is, say, http://nymb.us/?feed=rss2&p=39 but the user is at http://www.nymb.us, when they click the link, the ajax request is made to http://nymb.us/?feed=rss2&p=39, and NOT http://www.nymb.us/?feed=rss2&p=39. since technically these represent different sites to the browser, it fails, and the RSS is displayed instead.

    courtneyelizabeth
    Member

    @courtneyelizabeth

    Hey Bitwise,

    Can you have a look at my site please *linked to my username*. The link is below the content.

    Thanks so much

Viewing 15 replies - 1 through 15 (of 42 total)
  • The topic ‘New Plugin: Expand Comments (w/ AJAX)’ is closed to new replies.