'
).prepend(
beginElement('code-widen-button', 'Widen code container') +
'' +
''
);
// Check if notifications button is empty
var notifications = links.find('.js-header-notifications');
if (notifications.length && notifications.text().trim() === '') {
notifications.remove();
}
// Toggle code container width on click
$('#code-widen-button').click(function() {
var container = $('.container.new-discussion-timeline.experiment-repo-nav');
var expanded = $(window).width() * 0.95;
if ($('.repository-content').find('.file').is(':visible') || ($('#files').is(':visible') && $('meta[name="diff-view"]').attr('content') === 'unified')) {
// Only widen if viewing a single file or changes in unified mode
container.css('width', (container.width() < expanded) ? expanded : 980);
} else if (container.width() >= expanded) {
// Reduce the width on a page if needed
container.css('width', 980);
}
$(this).blur();
});
// Toggle page with the w=1 query param in the url to show/hide whitespace
$('#hide-whitespace-button').click(function() {
if ($('#files').is(':visible')) {
var url = window.location.href;
if (url.includes('?w=1')) {
// Check if there is more to the query and remove the whitespace query param
window.location.href = url.replace((url.includes('&') ? /w=1\&/ : /\?w=1/), '');
} else if (url.includes('&w=1')) {
// Remove the appended whitespace query param
window.location.href = url.replace(/\&w=1/, '');
} else {
// Add the whitespace query param
var query = url.includes('?') ? '&w=1' : '?w=1';
if (url.includes('#')) {
// Insert before any anchors in the url
window.location.href = url.slice(0, url.indexOf('#')) + query + url.substr(url.indexOf('#'));
} else {
// Append to the url
window.location.href = url + query;
}
}
}
$(this).blur();
});
}
});