inherit
197814
0
Apr 14, 2016 22:43:41 GMT -8
mildred
-w-
91
August 2013
mildr34d
|
Post by mildred on Nov 22, 2015 8:46:53 GMT -8
I tried searching around for a bit, but I only spent about ten minutes looking, so apologies if I missed this somewhere... Is there a quick way to tell if the thread is being viewed for the first time, or in other words, has just been created? I'd like to do a couple of things only when the thread is first created, but not specifically when the thread is created -- I need the url of the created thread, or otherwise I would have just tied my events to the create thread button. I'm open to changing how I'm approaching the problem (if, for example, I can get the url earlier, or something else I haven't thought of). I thought I was smart and tied the event to the thread only having one post, but that triggers every time the thread is viewed. Edit: I could, I suppose, make it time based... Edit 2: I'm second guessing myself and wondering if I should have posted this in the Headers/Footers area since this is really more of a general question about accessing pb stuff through javascript than related to plugins specifically. I could probably do this just as easily in the header/footer. Edit 3: It's super hacky and ugly and not safe at all, but I'm thinking about something like this when I say 'time based' $("[class^=lm-content-]").find(".recent_time").contents()[0].data === "a few seconds ago" Of course, that element's not even available immediately upon page load and so I'll have to handle that, but you get the gist...
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,986
December 2005
horace
Wormo's Mini-Profile
|
Post by Chris on Nov 23, 2015 20:43:07 GMT -8
Assuming I am understanding your intent here, which is to run some code only when a thread is being viewed by the thread creator for the first time then your better bet is to approach it using the underlying data rather than relying on the layout which will change from theme to theme and may not have the elements that you are trying to key in on. If you examine the page data ( pb.data("page") ) you'll see that when viewing a thread it will have info about the thread being viewed so the page data for this particular "Thread Creation" thread would yield: { "category": { "name": "Coding & Development", "id": 16 }, "board": { "show_announcements": "1", "name": "Plugin Development", "id": 96, "display_name": "Plugin Development", "description": "Plugin developers can come here to help and to discuss creating plugins.", "url": "/board/96/plugin-development", "hidden": "0", "disable_post_counts": "0", "disable_posting": "0", "posts": 1942, "threads": 197 }, "thread": { "id": 566454, "last_post_time": 1448210813, "board_id": 96, "is_falling": 0, "is_new": 0, "last_post_id": 6516522, "url": "/thread/566454/thread-creation", "is_announcement": 0, "created_by": 197814, "first_post_id": 6516522, "subject": "Thread Creation", "is_bookmarked": 0, "is_locked": 0, "is_sticky": 0, "is_poll": 0, "created_on": 1448210813 } }
The "created_by" will allow you to immediately discern if this thread was created by the user viewing it simply by comparing that value against the current user's ID and of course there is that coveted "url". Also pay attention to the "last_post_time" and how it matches the "created_on" which says that the last time this thread had a contribution is also the same time it was created indicating that the post in this thread is an only-child and perhaps a newborn. Now if you compare the creation time against the server time ( pb.data("serverDate") ) remembering to convert the serverDate value from milliseconds to seconds first before comparisons, you can see how much time has passed since this thread was created. You should also be aware that if this is for a thread/post key then Proboards has the set_on('thread_new'... event that will associate the data you pass in with the ID of the thread/post after it has been created (since the ID is determined after the data reaches the server not while writing) and once you have that ID in your key you can easily reconstruct the URL to the resource using that ID (e.g. <hostname>/thread/ID ) on pages where access to that data might not be readily available. Note: The ID of the thread will be inserted in a thread key and the ID of the first post will be inserted in a post key Note2: The time values are in epoch time (count of the seconds that have passed since January 1, 1970 @ midnight) and the serverDate is a count of the milliseconds (thousandths of a second) since January 1, 1970 @ midnight.
|
|
inherit
197814
0
Apr 14, 2016 22:43:41 GMT -8
mildred
-w-
91
August 2013
mildr34d
|
Post by mildred on Nov 24, 2015 11:59:18 GMT -8
That's exactly what I was looking for! Thank you
|
|