From 4dfa5a2e59ca4f20110a277535ec680a2083b6bc Mon Sep 17 00:00:00 2001 From: Dan Rosart Date: Tue, 6 Feb 2018 00:02:35 -0800 Subject: [PATCH 1/5] Make breadcrumbs persist when you go up the chain. --- client/header.coffee | 57 +++++++++++++++++- header.html | 135 +++++++++++++++++++++++++++++-------------- header.less | 29 ++++++++-- 3 files changed, 170 insertions(+), 51 deletions(-) diff --git a/client/header.coffee b/client/header.coffee index b9071e28b..1c1d3d1e6 100644 --- a/client/header.coffee +++ b/client/header.coffee @@ -39,7 +39,7 @@ Template.registerHelper 'link', (args) -> link += '' return new Spacebars.SafeString(link) -$(document).on 'click', 'a.puzzles-link, a.rounds-link, a.chat-link, a.home-link, a.oplogs-link, a.quips-link', (event) -> +$(document).on 'click', 'a.puzzles-link, a.rounds-link, a.chat-link, a.home-link, a.oplogs-link, a.quips-link, a.callins-link, a.facts-link', (event) -> return unless event.button is 0 # check right-click return if event.ctrlKey or event.shiftKey or event.altKey # check alt/ctrl/shift clicks return if /^https?:/.test($(event.currentTarget).attr('href')) @@ -200,7 +200,62 @@ Template.header_loginmute.events editing: undefined # abort current edit, whatever it is ############## breadcrumbs ####################### +Tracker.autorun -> + breadcrumbs = Session.get 'breadcrumbs' + currentpage = Session.get 'currentPage' + currenttype = Session.get 'type' + currentid = Session.get 'id' + # Regenerate breadcrumbs + base = [{page: 'blackboard', type: 'general', id: '0'}] + if currenttype is 'puzzles' + round = model.Rounds.findOne puzzles: currentid + if round? + base.push {page: 'round', type: 'rounds', id: round._id} + base.push {page: 'puzzle', type: 'puzzles', id: currentid} + else if currenttype is 'rounds' + base.push {page: 'round', type: 'rounds', id: currentid} + else if currentpage isnt 'chat' and currentpage isnt 'blackboard' + base.push {page: currentpage, type: currenttype, id: currentid} + # If the new breadcrumbs are a prefix of the old ones, keep the old ones. + if breadcrumbs? and base.length <= breadcrumbs.length + return if do -> + for crumb, i in base + oldcrumb = breadcrumbs[i] + if crumb.page isnt oldcrumb.page or crumb.type isnt oldcrumb.type or crumb.id isnt oldcrumb.id + return false + return true + Session.set 'breadcrumbs', base + +Template.header_breadcrumb_chat.helpers + inThisRoom: -> + return false unless Session.equals 'currentPage', 'chat' + return false unless Session.equals 'type', @type + Session.equals 'id', @id + +Template.header_breadcrumb_round.onCreated -> + @autorun => + @subscribe 'round-by-id', Template.currentData().id +Template.header_breadcrumb_round.helpers + round: -> + model.Rounds.findOne @id if @id + +Template.header_breadcrumb_puzzle.onCreated -> + @autorun => + @subscribe 'puzzle-by-id', Template.currentData().id + @subscribe 'round-for-puzzle', Template.currentData().id +Template.header_breadcrumb_puzzle.helpers + puzzle: -> + model.Puzzles.findOne @id if @id + +Template.header_breadcrumb_quip.onCreated -> + @autorun => @subscribe 'quips' +Template.header_breadcrumb_quip.helpers -> + idIsNew: -> 'new' is @id + quip: -> model.Quips.findOne @id unless @id is 'new' + Template.header_breadcrumbs.helpers + breadcrumbs: -> Session.get 'breadcrumbs' + crumb_template: -> "header_breadcrumb_#{this.page}" round: -> if Session.equals('type', 'puzzles') model.Rounds.findOne puzzles: Session.get("id") diff --git a/header.html b/header.html index bc690f03a..6b6e92408 100644 --- a/header.html +++ b/header.html @@ -10,65 +10,112 @@ {{> header_breadcrumbs}} + + -