Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-05-30 02:25:28

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Wrangling tab markup in an Ajax world

I’m hoping for some advice about modifying TXP admin tabs using pluggable_ui and/or jQuery. I’ve had a hack around the forums & TXP code but am failing to come up with anything.

At the moment I can successfully manipulate tab layout either by using pluggable_ui or, if none suitable exist, jQuery as well. These work fine on the initial visit to the tab in question.

However … on tabs such as, Edit Article, I’m hitting a problem where because there’s no page refresh my markup tweaking is not being actioned.

Here’s a test example to illustrate a simple pluggable_ui scenario:

register_callback('test_extend_title', 'article_ui', 'title');

function test_extend_title($event, $step, $default, $rs) {
	return $default.graf(strlen($rs['Title']).' characters');
}

On the initial visit to the edit article tab, all’s well. The code displays the correct number of characters. If, however, I change the title & save the article, then the above code doesn’t fire and my extended markup is not changed.

So, my questions are:
  1. How to get the pluggabe_ui callback to fire on, say, an article save?
  2. How to run some jQuery in a similar situation?

Suggestions would be gratefully received.

Offline

#2 2021-05-30 07:27:11

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Wrangling tab markup in an Ajax world

You’ll likely get a better answer from Stef or Oleg, but bot_wtc does this by hooking into the async save routine like this:

textpattern.Relay.register('txpAsyncForm.success', function() {
    // your javascript here
});

as Oleg mentions here.

If there’s a better way, I’d love to know as it may help make bot_wtc more reliable.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-05-30 09:00:25

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Wrangling tab markup in an Ajax world

Take a look at $partials array around l.470 of txp_article.php and try changing

        // 'Title' region.
        'title' => array(
            'mode'     => PARTIAL_STATIC,
            ...
        ),

to

        // 'Title' region.
        'title' => array(
            'mode'     => PARTIAL_VOLATILE,
            ...
        ),

Just an untested idea, but could work. This would not solve the plugin problem, but at least explain it.

Offline

#4 2021-05-30 22:12:48

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Wrangling tab markup in an Ajax world

jakob wrote #330311:

… as Oleg mentions here.

Excellent, thanks. Looks just the ticket. My forum searching skills have been brutally exposed again – if only I’d realised that “hoses” was the keyword to look for!

Offline

#5 2021-05-30 22:15:02

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Wrangling tab markup in an Ajax world

etc wrote #330313:

Take a look at $partials array around l.470 of txp_article.php and try changing …

Thanks Oleg. Unfortunately it doesn’t appear to have any affect.

Offline

#6 2021-05-31 08:04:25

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Wrangling tab markup in an Ajax world

gomedia wrote #330326:

Unfortunately it doesn’t appear to have any affect.

Yep, sorry. It actually has an effect: updated data is sent via ajax, but plugins block is attached outside div.title selector used for update. Seemingly, title wasn’t engineered to be updated dynamically, as well as other ‘static’ fields.

Offline

#7 2021-05-31 11:30:17

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Wrangling tab markup in an Ajax world

etc wrote #330329:

Seemingly, title wasn’t engineered to be updated dynamically, as well as other ‘static’ fields.

Thanks Oleg. Looks like I picked an awkward one as an example.

So in a situation such as this what might be the forward?

One could use pluggable_ui for the initial visit to the tab and fire some jQuery to update the markup on ‘txpAsyncForm.success’ when saving or duplicating. No access to $rs here though, so would have to glean data (in this case the new title) from page markup.

Or not bother with pluggable_ui and do everything in jQuery?

$rs is available via the ‘article_saved’ callback but I can’t think of a way in PHP to alter any markup at that point.

Offline

#8 2021-05-31 13:12:10

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Wrangling tab markup in an Ajax world

gomedia wrote #330330:

Looks like I picked an awkward one as an example.

At least, this one is announced as PARTIAL_STATIC, so no surprise here. There are worse examples, e.g. author is PARTIAL_VOLATILE, but to inject some updatable content, plugins need to rewrite $default block.

So in a situation such as this what might be the forward?

One could use pluggable_ui for the initial visit to the tab and fire some jQuery to update the markup on ‘txpAsyncForm.success’ when saving or duplicating. No access to $rs here though, so would have to glean data (in this case the new title) from page markup.

I think that’s the less hacky option, though it depends on $rs data and functions you need. Title length is trivial to calculate in JS (you can even do it on('#title', 'input') event), but if you needed to process, say, textiled body, then no luck.

Or not bother with pluggable_ui and do everything in jQuery?

That’s possible too, but could result in page jumps on slow devices while appending markup.

$rs is available via the ‘article_saved’ callback but I can’t think of a way in PHP to alter any markup at that point.

We could/should revise core partials update routine, but this is not a trivial task re bw compatibility. Say, making title block updatable would detach (on update) JS events eventually attached to title input by a plugin.

Offline

Board footer

Powered by FluxBB