Sha256: 648533ca9c1c4c7684cc0d868c2977436892c2a52928c80127e5e781398c8502

Contents?: true

Size: 1.21 KB

Versions: 29

Compression:

Stored size: 1.21 KB

Contents

pageflow.visited = (function() {

  var name, cookies = pageflow.cookies;

  $(function() {
    name = '_pageflow_' + pageflow.entryId + '_visited';

    if (pageflow.visited.enabled) {
      init();
    }
  });

  function init() {
    if (!cookies.hasItem(name)) {
      cookies.setItem(name, _getAllIds(), Infinity);
    }

    pageflow.ready.then(function() {
      pageflow.slides.on('pageactivate', function (e) {
        var id = e.target.getAttribute('id');
        var ids = _getCookieIds();

        if (ids.indexOf(id) < 0) {
          ids.push(id);
        }

        cookies.setItem(name, ids, Infinity);
      });
    });
  }

  function _getCookieIds() {
    if (cookies.hasItem(name) && !!cookies.getItem(name)) {
      return cookies.getItem(name).split(',').map(function(id) {
        return parseInt(id, 10);
      });
    }
    return [];
  }

  function _getAllIds() {
    return pageflow.pages.map(function(page) {
      return page.perma_id;
    });
  }

  return {
    getUnvisitedPages: function() {
      if (pageflow.visited.enabled) {
        var visitedIds = _getCookieIds();
        return visitedIds.length ? _.difference(_getAllIds(), visitedIds) : visitedIds;
      }
      return [];
    }
  };
}());

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
pageflow-12.1.0 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.4 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.3 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.2 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.1 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc7 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc6 app/assets/javascripts/pageflow/visited.js
pageflow-0.11.4 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc5 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc4 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc3 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc2 app/assets/javascripts/pageflow/visited.js
pageflow-12.0.0.rc1 app/assets/javascripts/pageflow/visited.js
pageflow-0.11.3 app/assets/javascripts/pageflow/visited.js
pageflow-0.11.2 app/assets/javascripts/pageflow/visited.js
pageflow-0.11.1 app/assets/javascripts/pageflow/visited.js
pageflow-0.11.0 app/assets/javascripts/pageflow/visited.js
pageflow-0.10.0 app/assets/javascripts/pageflow/visited.js
pageflow-0.9.2 app/assets/javascripts/pageflow/visited.js