1 (edited by daris 2008-02-08 17:20)

Topic: [js] How get post message element

I tried port this my mod for punbb 1.3, but i don't know how get element which contain post message. In 1.2 i added id for this element, but how do this as extension for 1.3?

In 1.3 it's look like:

<div class="post-entry">
                        <h4 class="entry-title">Topic: Test post</h4>
                        <div class="entry-content">
                            <p>If you are looking at this (which I guess you are), the install of PunBB appears to have worked! Now log in and head over to the administration control panel to configure your forum.</p>
                        </div>
                    </div>

Re: [js] How get post message element

Yeah, that would be a bit more tricky. Say you're looking for the post contents of post ID 1234. First, you would do a

var temp = getElementById('p1234');

Then you would do a getElementsByClass('entry-content', temp.parentNode, 'div') to find the post data. However, there's no such thing as getElementsByClass() in the DOM, so you'll have to google for an implementation.

Edit: I would like to point out that I haven't tried this. I think it would work though smile

Edit2: I tried it quickly and it works. Only problem is you the signature div comes along with it, so you'll have to figure out some way of getting rid of it. Maybe iterate over the children and remove any div's that have class="sig-content".

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3

Re: [js] How get post message element

I did it like this:

        <hook id="ft_end"><![CDATA[
if (PUN_PAGE == 'viewtopic') {
    preg_match_all("/\<div\sid\=\"p(\d*)\"\s.*\>/", $tpl_main, $output);
    foreach($output[1] as $s) {
        $str = substr($tpl_main, strpos($tpl_main, '<div id="p'.$s.'"'));
        $str = substr($str, 0, strpos($str, '</p>'));
        $old = $str;
        $str = str_replace('<p>', '<p id="postmsg'.$s.'">', $str);
        $tpl_main = str_replace($old, $str, $tpl_main);
    }
}
]]></hook>

big_smile It was quick and easy to create tongue

Re: [js] How get post message element

While that's certainly possible to do, it is the least efficient way to do it, is likely to cause conflicts, and is in general discouraged wink
You would be much better off using Rickard's suggestion.

Re: [js] How get post message element

I thought you wanted to do it in Javascript?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: [js] How get post message element

He wanted to add an id element so he could just use getElementById.