Beispiel #1
0
page('/proposal/:id', citizen.optional, load, function(ctx) {
  bus.emit('page:change');

  // Render sidebar list
  sidebar.render('aside.nav-proposal');
  sidebar.ready(function() {
    sidebar.select(ctx.law.id);
  });

  // Get content's container
  var contentContainer = document.querySelector('section.app-content');

  // Build page's content
  var article = new Article(ctx.proposal); // !!MUST be aware of citizen's data too
  var options = new Options(ctx.proposal, ctx.citizen);
  var comments = new Comments('proposal', ctx.proposal.id);
  comments.initialize();

  // Empty container before render
  empty(contentContainer);

  // Render page's content
  contentContainer.appendChild(article.render());
  contentContainer.appendChild(options.render());
  contentContainer.appendChild(comments.render());
});
Beispiel #2
0
page('/law/:id', citizen.optional, load, loadSidebar, function(ctx, next) {
  function validUrl() {
    var pathname = window.location.pathname;
    return pathname == '/' ||  /^\/(law|proposal)/.test(pathname);
  }

  if (!validUrl()) return classes(document.body).remove('browser-page');

  bus.emit('page:render');

  if (!ctx.law) {
    log('Law %s not found', ctx.params.id);
    return next();
  }

  ctx.sidebar.replace('aside.nav-proposal');

  // Clean page's content
  empty(o('section.app-content'))


  // Build article's content container
  // and render to section.app-content
  var article = new Article(ctx.law, nextLaw);
  article.render('section.app-content');

  // Build article's meta
  // and render to section.app-content
  var options = new Options(ctx.law, ctx.citizen);
  options.render('section.app-content');

  var nextLaw = new NextLaw(ctx);
  nextLaw.appendTo('section.app-content');


  // Build article's comments, feth them
  // and render to section.app-content
  if (ctx.law.votable) {
    var comments = new Comments('law', ctx.law.id);
    comments.render('section.app-content');
    comments.initialize();
  }

  classes(document.body).add('browser-page');
  title(ctx.law.mediaTitle);

  log('render %s', ctx.params.id);

  bus.once('page:change', pagechange);
  function pagechange(url) {
    // restore page's original title
    title();

    // lock article's section
    locker.lock();

    // hide it from user
    classes(o('section.app-content')).add('hide');

    // once render, unlock and show
    bus.once('page:render', function() {
      locker.unlock();
      classes(o('section.app-content')).remove('hide');
    });

    // check if loading to same page
    // and if not, scroll to top
    if (url !== ctx.path) o('section#browser').scrollTop = 0;

    // don't remove 'browser-page' body class
    // if we still are in a browsing laws page
    if (/^\/law/.test(url)) return;
    classes(document.body).remove('browser-page');
  };
});