WordPress.org

Forums

New Plugin: Expand Comments (w/ AJAX) (43 posts)

  1. BitwiseMcgee
    Member
    Posted 9 years ago #

    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

  2. iand
    Member
    Posted 9 years ago #

    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.

  3. BitwiseMcgee
    Member
    Posted 9 years ago #

    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?

  4. iand
    Member
    Posted 9 years ago #

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

  5. 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(); ?>

  6. BitwiseMcgee
    Member
    Posted 9 years ago #

    whitespace? could you specify please?

  7. 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...

  8. 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

  9. BitwiseMcgee
    Member
    Posted 9 years ago #

    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

  10. BitwiseMcgee
    Member
    Posted 9 years ago #

    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

  11. Sweet, works now! :D

    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. :)

  12. BitwiseMcgee
    Member
    Posted 9 years ago #

    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

  13. courtneyelizabeth
    Member
    Posted 9 years ago #

    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...

  14. BitwiseMcgee
    Member
    Posted 9 years ago #

    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.

  15. courtneyelizabeth
    Member
    Posted 9 years ago #

    Hey Bitwise,

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

    Thanks so much

  16. BitwiseMcgee
    Member
    Posted 9 years ago #

    hm, I think you're having a similar problem as viper, if I try and use the Expand Comments it says that makeAjaxRequest isn't found (which lives in expand-comments.js). On your site, where is the plugin directory located? ie, I can browse directly to expand-comments.js by the following:
    http://nymb.us/wp-content/plugins/expand-comments/expand-comments.js
    but your is a 404, so I guess its a bit different for you.

    most likely I need to get the wp setting for plugin locations, rather than have it hard coded like I do. see if you can find how to browse to the javascript file, and post the url for it here

    thanks, and sorry for the trouble

  17. Stahn
    Member
    Posted 9 years ago #

    What about an plugin to "Expand More with AJAX"? :D

  18. courtneyelizabeth
    Member
    Posted 9 years ago #

    okay, i had it in the actual plugin folder. i can add it to expand-comments/

  19. courtneyelizabeth
    Member
    Posted 9 years ago #

    Okay, i updated and added the expand-comments/ folder and inserted the *.js , but instead of showing rss feeds, it just doesnt show anything at all.

  20. BitwiseMcgee
    Member
    Posted 9 years ago #

    hm, well, the js is working, and so is the ajax (since 'Loading...' is replaced, which is done by ajax) My first guess is that the js can't find the div to put the comments into. do you know javascript? you can try and edit the expand-comments.php file so that the javascript inside there will do an 'alert()' with some debug info in it, namely, what it thinks appendDiv is in line 88. Perhaps just add 'alert(appendDiv.id);' after that line, and see what the alert says when you click the link

  21. courtneyelizabeth
    Member
    Posted 9 years ago #

    didnt work. No alert. I placed it after the appendDIV line.

  22. BitwiseMcgee
    Member
    Posted 9 years ago #

    odd, my guess is that it might be a result of some other errors on your page. Try adding some 'alert("got here")' type of stuff to see where the code is bombing out. If you don't want to do that, try cleaning up the site until it validates, hopefully that will fix it.

    also, I've only tested this stuff in IE and FF, so other browsers might have issues. If you know it works for a certain browser, please let me know

  23. courtneyelizabeth
    Member
    Posted 9 years ago #

    *sigh* this looks really nice, but I'll wait until ya have something more concrete. starting to get frustrated from figuring it out. Great plugin though!

  24. BitwiseMcgee
    Member
    Posted 9 years ago #

    no worries, hopefully the solution will pop up soon :)

    Most likely I'll get to the other enhancements this weekend, namely:
    User defined link title (passed to the function)
    User defined 'intro' and 'outro' (non link items displayed before and after link)
    div is added only if comments exist

    if there are any other ideas, speak up!

  25. BillyG
    Member
    Posted 9 years ago #

    interesting, the "RSS feed for this thread" link right above the entry box on this WP forum page does not work for me but I get feeds from 57 other sites fine, oh well, at least now I can track this thru my profile here, can't wait to try your plugin Bit.

  26. BigDog
    Member
    Posted 9 years ago #

    I am having the same problem with the RSS feed page opening up instead of the js doing its magic.

    Has anyone figured out the problem? Viper, you have it working on your test blog, what did you do to fix it?

  27. BitwiseMcgee
    Member
    Posted 9 years ago #

    there was a problem with expand-comments.js being loaded via relativue url (/wp-content/plugins/expand-comments/expand-comments.js) but Viper's install dir was different. version 0.2 should fix this. If you are using firefox, open the javascript console and click the link. If you get the error 'makeAjaxRequest not defined', that means the expand-comments.js file wasn't sourced. could you post the link to the blog where the problem is?

  28. courtneyelizabeth
    Member
    Posted 9 years ago #

    subscribed to rss for this plugin.

  29. BigDog
    Member
    Posted 9 years ago #

    My site is
    http://onebigdog.net

    I know I will need to redirect to that but will wait until I get it working

    The error I get in the js console is:

    Error: [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags