{"size": 3604, "ext": "js", "max_stars_repo_path": "app/static/js/user/account/AccountController.js", "max_stars_repo_name": "cipherboy/modern-paste", "max_stars_repo_stars_event_min_datetime": "2016-02-03T03:09:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-12T02:21:03.000Z", "max_issues_repo_path": "app/static/js/user/account/AccountController.js", "max_issues_repo_name": "cipherboy/modern-paste", "max_issues_repo_issues_event_min_datetime": "2016-02-03T07:20:16.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-09T00:10:10.000Z", "max_forks_repo_path": "app/static/js/user/account/AccountController.js", "max_forks_repo_name": "cipherboy/modern-paste", "max_forks_repo_forks_event_min_datetime": "2016-02-03T17:08:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-23T08:48:22.000Z"}
{"max_stars_count": 271, "max_issues_count": 65, "max_forks_count": 64, "avg_line_length": 43.9512195122, "max_line_length": 112, "alphanum_fraction": 0.7219755827}
goog.provide('modernPaste.user.account.AccountController');

goog.require('modernPaste.user.account.AccountPastesController');
goog.require('modernPaste.user.account.AccountAPIKeyController');


/**
 * This main controller handles transitions between settings sections in the UI.
 * It also handles displaying the appropriate section given the history push state.
 * Other controllers under this main controller handle each individual settings section.
 *
 * @constructor
 */
modernPaste.user.account.AccountController = function() {
    this.settingsLinks = $('.settings-item');
    this.settingsSectionContainers = $('.settings-section-container');
    this.desktopSettingsListGroup = $('.account-section-container .account-settings-list-group');
    this.mobileSettingsListGroup = $('.account-section-container .mobile-account-settings-list-group');

    var settingsContainersObjects = this.settingsLinks.map(function(link) {
        // Each settings-item has a data-section field which is the name of the class of the settings container.
        // This goes through each of the settings items, and creates a JQuery object of the settings container.
        return $('.' + $(this.settingsLinks[link]).data('section'));
    }.bind(this));
    this.settingsContainers = Object.keys(settingsContainersObjects).filter(function(key) {
        // Only consider numbers: these are objected directly selected by JQuery's query
        return !isNaN(key);
    }).map(function(key) {
        // Easier to treat this as an array than an object.
        return settingsContainersObjects[key];
    }.bind(this));

    modernPaste.user.account.AccountController.changeListGroupView.bind(this)();

    this.settingsLinks.on('click', modernPaste.user.account.AccountController.switchSettingsSection.bind(this));
    $(window).resize(modernPaste.user.account.AccountController.changeListGroupView.bind(this));
};

/**
 * There is some admittedly very complicated logic going on here.
 */
modernPaste.user.account.AccountController.switchSettingsSection = function(evt) {
    evt.preventDefault();

    this.settingsLinks.removeClass('active sans-serif semibold');
    var clickedSettingsLink = $('.' + $(evt.target).attr('class').split(/\s+/)[0]);
    var correspondingSettingsContainer = $('.' + clickedSettingsLink.data('section'))[0];
    this.settingsContainers.forEach(function(container) {
        if (container[0] === correspondingSettingsContainer) {
            $(container).show();
            clickedSettingsLink.addClass('active sans-serif semibold');
        } else {
            $(container).hide();
        }
    });
};

/**
 * Change the list group view type (desktop/mobile) depending on the current browser width.
 */
modernPaste.user.account.AccountController.changeListGroupView = function() {
    var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (width > 1250) {
        this.mobileSettingsListGroup.hide();
        this.desktopSettingsListGroup.show();
        this.settingsSectionContainers.css('margin-left', '400px');
    } else {
        this.mobileSettingsListGroup.show();
        this.desktopSettingsListGroup.hide();
        this.settingsSectionContainers.css('margin-left', 0);
    }
};


$(document).ready(function() {
    new modernPaste.user.account.AccountController();
    new modernPaste.user.account.AccountPastesController();
    new modernPaste.user.account.AccountUserProfileController();
    new modernPaste.user.account.AccountAPIKeyController();
    new modernPaste.user.account.AccountDeactivateController();
});
