debian-mirror-gitlab/app/assets/javascripts/application.js

328 lines
10 KiB
JavaScript
Raw Normal View History

2016-09-29 09:46:39 +05:30
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
2016-09-13 17:45:13 +05:30
/*= require jquery2 */
/*= require jquery-ui/autocomplete */
/*= require jquery-ui/datepicker */
/*= require jquery-ui/draggable */
/*= require jquery-ui/effect-highlight */
/*= require jquery-ui/sortable */
/*= require jquery_ujs */
/*= require jquery.cookie */
/*= require jquery.endless-scroll */
/*= require jquery.highlight */
/*= require jquery.waitforimages */
/*= require jquery.atwho */
/*= require jquery.scrollTo */
/*= require jquery.turbolinks */
/*= require turbolinks */
/*= require autosave */
/*= require bootstrap/affix */
/*= require bootstrap/alert */
/*= require bootstrap/button */
/*= require bootstrap/collapse */
/*= require bootstrap/dropdown */
/*= require bootstrap/modal */
/*= require bootstrap/scrollspy */
/*= require bootstrap/tab */
/*= require bootstrap/transition */
/*= require bootstrap/tooltip */
/*= require bootstrap/popover */
/*= require select2 */
/*= require underscore */
/*= require dropzone */
/*= require mousetrap */
/*= require mousetrap/pause */
/*= require shortcuts */
/*= require shortcuts_navigation */
/*= require shortcuts_dashboard_navigation */
/*= require shortcuts_issuable */
/*= require shortcuts_network */
/*= require jquery.nicescroll */
/*= require date.format */
/*= require_directory ./behaviors */
/*= require_directory ./blob */
/*= require_directory ./templates */
/*= require_directory ./commit */
/*= require_directory ./extensions */
/*= require_directory ./lib/utils */
/*= require_directory ./u2f */
/*= require_directory . */
/*= require fuzzaldrin-plus */
(function() {
window.slugify = function(text) {
return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase();
};
window.ajaxGet = function(url) {
return $.ajax({
type: "GET",
url: url,
dataType: "script"
});
};
window.split = function(val) {
return val.split(/,\s*/);
};
window.extractLast = function(term) {
return split(term).pop();
};
window.rstrip = function(val) {
if (val) {
return val.replace(/\s+$/, '');
} else {
return val;
}
};
2016-09-29 09:46:39 +05:30
// Disable button if text field is empty
2016-09-13 17:45:13 +05:30
window.disableButtonIfEmptyField = function(field_selector, button_selector) {
var closest_submit, field;
field = $(field_selector);
closest_submit = field.closest('form').find(button_selector);
if (rstrip(field.val()) === "") {
closest_submit.disable();
}
return field.on('input', function() {
if (rstrip($(this).val()) === "") {
return closest_submit.disable();
} else {
return closest_submit.enable();
}
});
};
2016-09-29 09:46:39 +05:30
// Disable button if any input field with given selector is empty
2016-09-13 17:45:13 +05:30
window.disableButtonIfAnyEmptyField = function(form, form_selector, button_selector) {
var closest_submit, updateButtons;
closest_submit = form.find(button_selector);
updateButtons = function() {
var filled;
filled = true;
form.find('input').filter(form_selector).each(function() {
return filled = rstrip($(this).val()) !== "" || !$(this).attr('required');
});
if (filled) {
return closest_submit.enable();
} else {
return closest_submit.disable();
}
};
updateButtons();
return form.keyup(updateButtons);
};
window.sanitize = function(str) {
return str.replace(/<(?:.|\n)*?>/gm, '');
};
window.unbindEvents = function() {
return $(document).off('scroll');
};
document.addEventListener("page:fetch", unbindEvents);
2016-11-24 13:41:30 +05:30
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// https://github.com/twitter/bootstrap/issues/1768
window.adjustScroll = function() {
var navbar = document.querySelector('.navbar-gitlab');
var subnav = document.querySelector('.layout-nav');
var fixedTabs = document.querySelector('.js-tabs-affix');
adjustment = 0;
if (navbar) adjustment -= navbar.offsetHeight;
if (subnav) adjustment -= subnav.offsetHeight;
if (fixedTabs) adjustment -= fixedTabs.offsetHeight;
return scrollBy(0, adjustment);
};
window.addEventListener("hashchange", adjustScroll);
2016-09-13 17:45:13 +05:30
2016-11-24 13:41:30 +05:30
window.onload = function () {
2016-09-29 09:46:39 +05:30
// Scroll the window to avoid the topnav bar
// https://github.com/twitter/bootstrap/issues/1768
2016-09-13 17:45:13 +05:30
if (location.hash) {
2016-11-24 13:41:30 +05:30
return setTimeout(adjustScroll, 100);
2016-09-13 17:45:13 +05:30
}
};
$(function() {
var $body, $document, $sidebarGutterToggle, $window, bootstrapBreakpoint, checkInitialSidebarSize, fitSidebarForSize, flash;
$document = $(document);
$window = $(window);
$body = $('body');
gl.utils.preventDisabledButtons();
bootstrapBreakpoint = bp.getBreakpointSize();
$(".nav-sidebar").niceScroll({
cursoropacitymax: '0.4',
cursorcolor: '#FFF',
cursorborder: "1px solid #FFF"
});
$(".js-select-on-focus").on("focusin", function() {
return $(this).select().one('mouseup', function(e) {
return e.preventDefault();
});
2016-09-29 09:46:39 +05:30
// Click a .js-select-on-focus field, select the contents
// Prevent a mouseup event from deselecting the input
2016-09-13 17:45:13 +05:30
});
$('.remove-row').bind('ajax:success', function() {
2016-09-29 09:46:39 +05:30
$(this).tooltip('destroy')
.closest('li')
.fadeOut();
2016-09-13 17:45:13 +05:30
});
$('.js-remove-tr').bind('ajax:before', function() {
return $(this).hide();
});
$('.js-remove-tr').bind('ajax:success', function() {
return $(this).closest('tr').fadeOut();
});
$('select.select2').select2({
width: 'resolve',
2016-09-29 09:46:39 +05:30
// Initialize select2 selects
2016-09-13 17:45:13 +05:30
dropdownAutoWidth: true
});
$('.js-select2').bind('select2-close', function() {
return setTimeout((function() {
$('.select2-container-active').removeClass('select2-container-active');
return $(':focus').blur();
}), 1);
2016-09-29 09:46:39 +05:30
// Close select2 on escape
2016-09-13 17:45:13 +05:30
});
2016-09-29 09:46:39 +05:30
// Initialize tooltips
2016-09-13 17:45:13 +05:30
$body.tooltip({
selector: '.has-tooltip, [data-toggle="tooltip"]',
placement: function(_, el) {
2016-09-29 09:46:39 +05:30
return $(el).data('placement') || 'bottom';
2016-09-13 17:45:13 +05:30
}
});
$('.trigger-submit').on('change', function() {
return $(this).parents('form').submit();
2016-09-29 09:46:39 +05:30
// Form submitter
2016-09-13 17:45:13 +05:30
});
gl.utils.localTimeAgo($('abbr.timeago, .js-timeago'), true);
2016-09-29 09:46:39 +05:30
// Flash
2016-09-13 17:45:13 +05:30
if ((flash = $(".flash-container")).length > 0) {
flash.click(function() {
return $(this).fadeOut();
});
flash.show();
}
2016-09-29 09:46:39 +05:30
// Disable form buttons while a form is submitting
2016-09-13 17:45:13 +05:30
$body.on('ajax:complete, ajax:beforeSend, submit', 'form', function(e) {
var buttons;
buttons = $('[type="submit"]', this);
switch (e.type) {
case 'ajax:beforeSend':
case 'submit':
return buttons.disable();
default:
return buttons.enable();
}
});
$(document).ajaxError(function(e, xhrObj, xhrSetting, xhrErrorText) {
var ref;
if (xhrObj.status === 401) {
return new Flash('You need to be logged in.', 'alert');
} else if ((ref = xhrObj.status) === 404 || ref === 500) {
return new Flash('Something went wrong on our end.', 'alert');
}
});
$('.account-box').hover(function() {
2016-09-29 09:46:39 +05:30
// Show/Hide the profile menu when hovering the account box
2016-09-13 17:45:13 +05:30
return $(this).toggleClass('hover');
});
$document.on('click', '.diff-content .js-show-suppressed-diff', function() {
var $container;
$container = $(this).parent();
$container.next('table').show();
return $container.remove();
2016-09-29 09:46:39 +05:30
// Commit show suppressed diff
2016-09-13 17:45:13 +05:30
});
$('.navbar-toggle').on('click', function() {
$('.header-content .title').toggle();
$('.header-content .header-logo').toggle();
$('.header-content .navbar-collapse').toggle();
return $('.navbar-toggle').toggleClass('active');
});
2016-09-29 09:46:39 +05:30
// Show/hide comments on diff
2016-09-13 17:45:13 +05:30
$body.on("click", ".js-toggle-diff-comments", function(e) {
var $this = $(this);
$this.toggleClass('active');
var notesHolders = $this.closest('.diff-file').find('.notes_holder');
if ($this.hasClass('active')) {
2016-11-03 12:29:30 +05:30
notesHolders.show().find('.hide').show();
2016-09-13 17:45:13 +05:30
} else {
notesHolders.hide();
}
2016-09-29 09:46:39 +05:30
$this.trigger('blur');
2016-09-13 17:45:13 +05:30
return e.preventDefault();
});
$document.off("click", '.js-confirm-danger');
$document.on("click", '.js-confirm-danger', function(e) {
var btn, form, text;
e.preventDefault();
btn = $(e.target);
text = btn.data("confirm-danger-message");
form = btn.closest("form");
return new ConfirmDangerModal(form, text);
});
$document.on('click', 'button', function() {
return $(this).blur();
});
$('input[type="search"]').each(function() {
var $this;
$this = $(this);
$this.attr('value', $this.val());
});
$document.off('keyup', 'input[type="search"]').on('keyup', 'input[type="search"]', function(e) {
var $this;
$this = $(this);
return $this.attr('value', $this.val());
});
$sidebarGutterToggle = $('.js-sidebar-toggle');
$document.off('breakpoint:change').on('breakpoint:change', function(e, breakpoint) {
var $gutterIcon;
if (breakpoint === 'sm' || breakpoint === 'xs') {
$gutterIcon = $sidebarGutterToggle.find('i');
if ($gutterIcon.hasClass('fa-angle-double-right')) {
return $sidebarGutterToggle.trigger('click');
}
}
});
fitSidebarForSize = function() {
var oldBootstrapBreakpoint;
oldBootstrapBreakpoint = bootstrapBreakpoint;
bootstrapBreakpoint = bp.getBreakpointSize();
if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
}
};
checkInitialSidebarSize = function() {
bootstrapBreakpoint = bp.getBreakpointSize();
if (bootstrapBreakpoint === "xs" || "sm") {
return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
}
};
$window.off("resize.app").on("resize.app", function(e) {
return fitSidebarForSize();
});
gl.awardsHandler = new AwardsHandler();
checkInitialSidebarSize();
new Aside();
2016-09-29 09:46:39 +05:30
// bind sidebar events
new gl.Sidebar();
2016-09-13 17:45:13 +05:30
// Custom time ago
gl.utils.shortTimeAgo($('.js-short-timeago'));
});
}).call(this);