From 7f6474b269a5cfa454d28c0c0da969490c9eb33e Mon Sep 17 00:00:00 2001 From: Jared Deckard Date: Tue, 26 Jul 2016 22:32:10 -0500 Subject: Restore comments lost when converting CoffeeScript to JavaScript --- app/assets/javascripts/user_tabs.js | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'app/assets/javascripts/user_tabs.js') diff --git a/app/assets/javascripts/user_tabs.js b/app/assets/javascripts/user_tabs.js index e5e75701fee..8a657780eb6 100644 --- a/app/assets/javascripts/user_tabs.js +++ b/app/assets/javascripts/user_tabs.js @@ -1,3 +1,61 @@ +// UserTabs +// +// Handles persisting and restoring the current tab selection and lazily-loading +// content on the Users#show page. +// +// ### Example Markup +// +// +// +//
+//
+// Activity Content +//
+//
+// Groups Content +//
+//
+// Contributed projects content +//
+//
+// Projects content +//
+//
+// Snippets content +//
+//
+// +//
+//
+// Loading Animation +//
+//
+// (function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; @@ -6,18 +64,23 @@ this.tabShown = bind(this.tabShown, this); var i, item, len, ref, ref1, ref2, ref3; this.action = (ref = opts.action) != null ? ref : 'activity', this.defaultAction = (ref1 = opts.defaultAction) != null ? ref1 : 'activity', this.parentEl = (ref2 = opts.parentEl) != null ? ref2 : $(document); + // Make jQuery object if selector is provided if (typeof this.parentEl === 'string') { this.parentEl = $(this.parentEl); } + // Store the `location` object, allowing for easier stubbing in tests this._location = location; + // Set tab states this.loaded = {}; ref3 = this.parentEl.find('.nav-links a'); for (i = 0, len = ref3.length; i < len; i++) { item = ref3[i]; this.loaded[$(item).attr('data-action')] = false; } + // Actions this.actions = Object.keys(this.loaded); this.bindEvents(); + // Set active tab if (this.action === 'show') { this.action = this.defaultAction; } @@ -25,6 +88,7 @@ } UserTabs.prototype.bindEvents = function() { + // Toggle event listeners return this.parentEl.off('shown.bs.tab', '.nav-links a[data-toggle="tab"]').on('shown.bs.tab', '.nav-links a[data-toggle="tab"]', this.tabShown); }; @@ -74,6 +138,7 @@ tabSelector = 'div#' + action; _this.parentEl.find(tabSelector).html(data.html); _this.loaded[action] = true; + // Fix tooltips return gl.utils.localTimeAgo($('.js-timeago', tabSelector)); }; })(this) @@ -97,13 +162,17 @@ UserTabs.prototype.setCurrentAction = function(action) { var new_state, regExp; + // Remove possible actions from URL regExp = new RegExp('\/(' + this.actions.join('|') + ')(\.html)?\/?$'); new_state = this._location.pathname; + // remove trailing slashes new_state = new_state.replace(/\/+$/, ""); new_state = new_state.replace(regExp, ''); + // Append the new action if we're on a tab other than 'activity' if (action !== this.defaultAction) { new_state += "/" + action; } + // Ensure parameters and hash come along for the ride new_state += this._location.search + this._location.hash; history.replaceState({ turbolinks: true, -- cgit v1.2.1