Commit d941aee4 authored by Alfredo Sumaran's avatar Alfredo Sumaran
Browse files


parent 99d75a27
class @UserTabs
actions: ['activity', 'groups', 'contributed', 'personal'],
defaultAction: 'activity',
constructor: ->
# Store the `location` object, allowing for easier stubbing in tests
@_location = location
bindEvents: ->
$(document).on '', '.nav-links a[data-toggle="tab"]', @tabShown
tabShown: (event) =>
$target = $(
action = $'action')
source = $target.attr('href')
@loadTab(source, action)
loadTab: (source, action) ->
url: "#{source}.json"
success: (data) =>
tabSelector = 'div#' + action
document.querySelector(tabSelector).innerHTML = data.html
toggleLoading: (status) ->
$('.loading-status .loading').toggle(status)
_get: (options) ->
defaults = {
beforeSend: => @toggleLoading(true)
complete: => @toggleLoading(false)
dataType: 'json'
type: 'GET'
options = $.extend({}, defaults, options)
setCurrentAction: (action) ->
# Remove possible actions from URL
regExp = new RegExp('\/(' + @actions.join('|') + ')(\.html)?\/?$')
new_state = @_location.pathname.replace(regExp, '')
# Append the new action if we're on a tab other than 'activity'
unless action == @defaultAction
new_state += "/#{action}"
# Ensure parameters and hash come along for the ride
new_state += + @_location.hash
history.replaceState {turbolinks: true, url: new_state}, document.title, new_state
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment