Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ping #176

Open
gilesbradshaw opened this issue Apr 25, 2014 · 1 comment
Open

Ping #176

gilesbradshaw opened this issue Apr 25, 2014 · 1 comment

Comments

@gilesbradshaw
Copy link
Collaborator

None of the beforeshow aftershow &c methods get called for a page when the route changes but the page remains displayed.

There maybe a better way of doing this in which case I'd be interested in feedback but I have introduced an onPing option. This will get called for each page in the current route whenever the hash changes. I use it to determine if a page has any sub pages displayed but there would be other use cases.

What I have done is this :

        p.showPage = function (route, pageRoute, originalRoute) {
            var m = this,
                currentId = m.currentId,
                params = m.pageRoute ? m.pageRoute.params : null,
                isVisible = m.isVisible();
            m.currentId = pageRoute ? (pageRoute.name || '') : '';
            m.getCurrentId(m.currentId);
            m.isVisible(true);
            if (originalRoute) {
                m.originalRoute(originalRoute);
            }
            m.route = route;
            m.pageRoute = pageRoute;
            // show if not already visible
            if (!isVisible) {
                m.setParams();
                m.show();
            } else {
                // show if wildcard got new ID
                if (m.getId() === '?' && currentId !== m.currentId) {
                    m.show();
                }
                // update params if they are updated
                if (pageRoute && params !== pageRoute.params) {
                    m.setParams();
                }
            }
            m.childManager.showChild(route);
            // new called to ping method for the page
            m.ping();
        };

and

        /** added by gb
        called whenever the hash changes and a page is on the current route
        **/
        p.ping = function () {
            var me = this;
            if (me.val('onPing'))
            {
                me.val('onPing')(me);

            }

        }

In the markup...

<div data-bind="page: {id: 'main', onPing:_onPing}">

@manzanotti
Copy link
Contributor

Might this not be better as a globally set option where it fires the usual show method, with the option of over-riding it on an element? That's certainly something I've been meaning to add to pager when I get the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants