Opened 13 years ago
Closed 13 years ago
#3279 closed defect (bug) (fixed)
Activity reply buttons have duplicate IDs
Reported by: | boonebgorges | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 1.5 | Priority: | minor |
Severity: | Version: | 1.2.8 | |
Component: | Activity | Keywords: | needs-patch |
Cc: |
Description
See some discussion on #3253
'Reply' buttons on activity items belonging to the same root activity item have the same ID, 'acomment-reply-x' (where x is the activity id). Duplicate IDs make for invalid markup.
This problem does not have an easy fix, because the button ID is used by the javascript to determine which root activity should be set as the item_id of the newly created activity item. See around line 305-308, line 327, and lines 344-350 of bp-default/_inc/global.js
A couple different strategies to fix:
- Add an additional hidden input field to the activity reply markup that contains the ID the root activity item, and modify the JS to use that that value
- In the JS, get the root activity ID by crawling up the tree using jQuery .parents() or .find() or something like that. (I did a preliminary test of this and it seemed to be quite slow, so ymmv.)
- Change the button ID so that it contains the root activity ID *in addition to* the replied-to activity ID. Thus something like acomment-reply-x-y, where x is the root activity id, and y is the immediate parent id. Then modify the JS to parse this correctly.
IMO this is not urgent because it has always been this way, and it's not affecting the way the page works. Any takers?
Attachments (1)
Change History (7)
#2
@
13 years ago
Good point about the JS remaining the same with your fix. That should be a fine fix for right now. Please go ahead and post a patch.
I don't mind introducing HTML5 into the markup where it will degrade gracefully in crappy browsers. But we shouldn't make changes to the JavaScript that will not be backward compatible. Let's stick with class and id for the moment, at least as far as jQuery selectors are concerned.
#3
@
13 years ago
@Boone I agree. I talked to Paul and he is opposed to using HMTL5 right now. I think once themes and plugins for WP start using it more and more we will see both WP and BP moving forward with html5.
Here is my patch with my basic fix. Tested on my site and working.
I'll take this.
There are a few solutions to this.
Firstly there is changing the ID field in the comments.php file created in the last patch(#3253)
id="acomment-reply-<?php bp_activity_id() ?>-from-<?php bp_activity_comment_id() ?>"
This would add which object it was coming from.
The JS is set up so that ANY object clicked triggers a multitude of events. In this case it reads the ID of the object clicked and pulls apart its ID. The ID is currently acomment-reply-x. When it does so it splits the string by each dash, so we get an array(acomment, reply, x). Where X is the activity ID that we are commenting on.
The script then pulls item [2] from the array, which in this case is the activity ID.
By adding -from-y (where Y is the ID of the comment the reply button is being clicked) the array now looks like (acomment, reply, x, from, y) This does not break the JS and currently works on my testing site. Without pulling apart the js just to make the ID's more semantic I think this is the fastest and best solution.
Note:
I think we are at a point where we could start thinking about HTML5 and what we could do with it. By using the data-x="" attribute we could simply write data-comment="" I'm writing other stuff and I have to think that hiding data in the ID of a element will become a faux pas when we can use data- much like tables were/are in the CSS era.
link to what I'm talking about: http://ejohn.org/blog/html-5-data-attributes/
Two things to note on this issue.
What use does this have you ask? with this reply button not much, besides limiting the use of insane ID's and odd code. The ID could be "acomment-reply-1" which is semantic and valid.
Just an idea I noticed when working on this.. Like I said, the quick fix is adding the little bit of code. The rest is just an idea I'm proposing..