inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,824
January 2015
msg
|
Post by Lynx on Apr 5, 2016 2:31:48 GMT -8
To check if your looking at a thread (actual posts in a thread, not the thread list), would that be:
if (pb.data('page').thread) {
Would that return true if viewing a thread, or is it something else?
Also, if the above is correct and returns true, would this get the thread ID:
var threadID = pb.data('page').thread_id
Thanks!
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Apr 5, 2016 3:31:03 GMT -8
Best way to work something like that out, is to simply run it in the console to see what you get. Do it on different pages and see the differences (i.e run it on this page and the reply page).
There are many different methods (some undocumented) you can use to determine what page you are on, most common is checking the route (cache it if you need to use it again later on).
Edit: I purposely made my post vague, as I know you are still learning. However, one thing I should point out is that pb.data("page").thread is not a Boolean.
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,824
January 2015
msg
|
Post by Lynx on Apr 5, 2016 12:42:53 GMT -8
So how would I test in the console? Would I put something like this in (using my incorrect one above):
var threadId = pb.data('page').thread_id; console.log('thread ID',threadId);
And see what it gives as the result so I can work on getting the correct statement?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Apr 6, 2016 1:15:09 GMT -8
I didn't say what you were doing in your first post was incorrect, you just need to be aware of some things, depending on what pages you are targeting. The "thread" object exists on other pages, whereas from reading your post, you want to target just the viewing of a thread. See the screen shots below, this is why I suggested that you run it in the console to see the differences. Viewing this thread: Reply page: Home page: You can see how I am running it in the console in the screen shots. You will also see there is a problem if you use it and wanting to target just the viewing of a thread. Let's make it even more clearer so you can see the problem... See any difference? Left one is when viewing a thread, right one is from the reply page. How do you tell which page is which when using that object? Now, there are a few different ways you can work out what page you are on, but for now, I would recommend sticking with checking the route of the page. It can be a pain as there can be multiple routes that you need to check depending on your plugin (i.e viewing a thread, recent posts, messages). This is where the console comes in handy, as you can then see what the route is of each page, so you can start filtering it for the ones you want to target. Take a look at the pb.data("route") object (you want to use the "name" property). Be careful though, it can fool you. Tip: You can combine different methods (i.e using the thread object and checking the route). If you are still confused, maybe take a look at other plugins that target just the thread viewing page, or if you want, I can give you a code example.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 6, 2016 4:12:46 GMT -8
To check if your looking at a thread (actual posts in a thread, not the thread list), would that be: if (pb.data('page').thread) { Would that return true if viewing a thread, or is it something else? Also, if the above is correct and returns true, would this get the thread ID: var threadID = pb.data('page').thread_id Thanks! Always stick to something static. pb.data('route').name is good for specifics Note: If pagination, search, moderations occur then the route is usually changed. So make sure to capture the route at the beginning of your code and store it in a variable. Otherwise it might say thread one minute and list_posts the next. document.location.href is what todge has used on his plugins because it is more general than route Examples: yourforum.freeforums.net/user/1 will bring you to your page. yourforum.freeforums.net/user will also display your page But the pb.data('route').name for /user/1 is 'user' and the route for /user is 'current_user' even though they bring up the same page. Not to mention moderations change the route after page load. Both can be evaluated with indexOf. Really depends on what you are doing. I think that pb.data('route') is more clean-cut but it can also make more trouble if there are multiple routes for the same page ---when you don't realize it. To Answer your Question: Yes it returns true only on threads and pb.data('page').thread.id returns the thread id as an integer (not pb.data('page').thread_id) My mention: Technically each item goes down a list of categorization. So if pb.data('page').thread contains your thread information you won't "back up" to pb.data('page') to find anything related to threads. Your example being: .thread_id And Peter gave you some great techniques on how to work with pb.data()
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,824
January 2015
msg
|
Post by Lynx on Apr 7, 2016 2:58:14 GMT -8
Okay, I'm lost. But, I've dropped this idea, so no response needed if you don't want to reply. I do want to thank you Peter and P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ for your replies - I guess I'm just too dumb to figure it out. Thanks anyways.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 7, 2016 3:00:04 GMT -8
Okay, I'm lost. But, I've dropped this idea, so no response needed if you don't want to reply. I do want to thank you Peter and P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ for your replies - I guess I'm just too dumb to figure it out. Thanks anyways. bro get on vent I'll teach you real quick
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,824
January 2015
msg
|
Post by Lynx on Apr 7, 2016 3:30:11 GMT -8
Been up since 11:00am yesterday morning and going to bed soon. I don't function well on 3 hours of sleep then being awake for the past 20.5 hours.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Apr 7, 2016 5:40:28 GMT -8
Okay, I'm lost. But, I've dropped this idea, so no response needed if you don't want to reply. I do want to thank you Peter and P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ for your replies - I guess I'm just too dumb to figure it out. Thanks anyways. Doesn't matter if you drop the idea, it's still important to know for the future. Sort out Skype, same goes for anyone else. Send me a PM with your Skype address, and we will chat.
|
|