diff --git a/client/header.coffee b/client/header.coffee index b9071e28b..5d4d6c1d9 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,44 +200,75 @@ Template.header_loginmute.events editing: undefined # abort current edit, whatever it is ############## breadcrumbs ####################### -Template.header_breadcrumbs.helpers +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: -> - if Session.equals('type', 'puzzles') - model.Rounds.findOne puzzles: Session.get("id") - else if Session.equals('type', 'rounds') - model.Rounds.findOne Session.get('id') - else null + 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: -> - if Session.equals('type', 'puzzles') - model.Puzzles.findOne Session.get('id') - else null - quip: -> - if Session.equals('type', 'quips') - model.Quips.findOne Session.get('id') - else null - type: -> Session.get('type') - id: -> Session.get('id') - idIsNew: -> Session.equals('id', 'new') - drive: -> switch Session.get('type') + 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}" + drive: -> switch Session.get 'type' when 'general' Session.get 'RINGHUNTERS_FOLDER' when 'rounds', 'puzzles' - model.collection(Session.get('type'))?.findOne(Session.get('id'))?.drive + model.collection(Session.get 'type')?.findOne(Session.get 'id')?.drive Template.header_breadcrumbs.events - "mouseup .fake-link[data-href]": (event, template) -> - # we work hard to try to make middle-click, shift-click, etc still work. - a = $(event.currentTarget).closest('a') - href = $(event.currentTarget).attr('data-href') - oldhref = a.attr('href') - a.attr('href', href) - Meteor.setTimeout (-> a.attr('href', oldhref)), 100 "click .bb-upload-file": (event, template) -> - folder = switch Session.get('type') + folder = switch Session.get 'type' when 'general' Session.get 'RINGHUNTERS_FOLDER' when 'rounds', 'puzzles' - model.collection(Session.get('type'))?.findOne(Session.get('id'))?.drive + model.collection(Session.get 'type')?.findOne(Session.get 'id')?.drive return unless folder uploadToDriveFolder folder, (docs) -> message = "uploaded "+(for doc in docs diff --git a/header.html b/header.html index bc690f03a..5a161f426 100644 --- a/header.html +++ b/header.html @@ -10,65 +10,112 @@ {{> header_breadcrumbs}} + + -