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

Single page support? #127

Open
thelonecabbage opened this issue Dec 9, 2012 · 9 comments
Open

Single page support? #127

thelonecabbage opened this issue Dec 9, 2012 · 9 comments

Comments

@thelonecabbage
Copy link

Is there a way to use the push.js transition features with a single page system (ie backbone)?

Transitioning in a new div?

@sindresorhus
Copy link

I was surprised there was no mention on this in the docs. Seems like a fairly common pattern these days. There should be a programmatic way to change pages.

@akre54
Copy link

akre54 commented Jan 14, 2013

totally agree. coupling a widget framework to a particular brand of page fetching can only lead to bad things. Can we get some dev love for this?

@jakiestfu
Copy link

Push.js hardly solved what I needed for my mobile web app, but it is an awesome start nonetheless. Some things I added include an 'beforepush' event, a 'filter' event for the data, a data-ignore="push-history" attribute, and I'm currently working on a prefetching method.

@epegzz
Copy link

epegzz commented Sep 3, 2013

👍

@n321203
Copy link

n321203 commented Nov 11, 2013

+1

This pattern is taking over the multi-page approach!

@romanbsd
Copy link

I guess that the first step would be making the swapContent function public. Not sure if it's enough, though.

@romanbsd
Copy link

FWIMC - the following proof of concept slides the provided Backbone view into view:

  PUSH.replaceWithView = function(view) {
    var dom = view.el, key, selector, barElement, newBarElement;

    for (key in bars) {
      selector = bars[key];
      barElement = document.querySelector(selector);
      newBarElement = dom.querySelector(selector);

      if (newBarElement) {
        swapContent(newBarElement, barElement);
        newBarElement.parentNode.removeChild(newBarElement);
      }
      else if (barElement) {
        barElement.parentNode.removeChild(barElement);
      }
    }

    selector = '.content';
    swapContent(dom.querySelector(selector), document.querySelector(selector), 'slidein');
  }

@jgillich
Copy link

jgillich commented Aug 6, 2014

I did this by extracting the code out of push.js (I don't use any of Ratchet's JavaScript so far). This sets the target variable to the link that has been clicked:

var isScrolling,
    target;

var findTarget = function(target) {
    var i;
    var toggles = document.querySelectorAll('a');

    for (; target && target !== document; target = target.parentNode) {
        for (i = toggles.length; i--;) {
            if (toggles[i] === target) {
                return target;
            }
        }
    }
};


var getTarget = function(e) {
    var target = findTarget(e.target);

    if (!target ||
        e.which > 1 ||
        e.metaKey ||
        e.ctrlKey ||
        isScrolling ||
        location.protocol !== target.protocol ||
        location.host !== target.host ||
        !target.hash && /#/.test(target.href)
       ) {
        return;
    }

    return target;
};

window.addEventListener('touchstart', function() {
    isScrolling = false;
});
window.addEventListener('touchmove', function() {
    isScrolling = true;
});
window.addEventListener('click', function(e) {
    var t = getTarget(e);
    if(t) target = t;
});

With that, it is easy to do the transition manually. First, remove the footer since it does not support transitions. Then apply the classes to the old content like:

oldContent.classList.add('sliding');
oldContent.classList.add(target && target.dataset.transition === 'slide-out' ? 'right' : 'left');
oldContent.addEventListener('transitionend', cb);

This requires you to have data-transition set to slide-in or slide-out on your links, just like with push.

@ndelage
Copy link

ndelage commented Oct 1, 2014

Just found this old thread. I've submitted a pull request to extract & expose the transition functionality from push.js to a new global function.

#684

Luiz-Not added a commit to Luiz-Not/ratchet that referenced this issue Dec 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants