BigW Consortium Gitlab

application.js 8.67 KB
Newer Older
1
/* eslint-disable */
2
// This is a manifest file that'll be compiled into including all the files listed below.
3
// Add new JavaScript code in separate files in this directory and they'll automatically
4 5 6 7
// 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.
//
Fatih Acet committed
8 9 10 11 12 13 14 15 16 17 18 19 20
/*= 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.endless-scroll */
/*= require jquery.highlight */
/*= require jquery.waitforimages */
/*= require jquery.atwho */
/*= require jquery.scrollTo */
/*= require jquery.turbolinks */
21
/*= require js.cookie */
Fatih Acet committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*= 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 */
49
/*= require_directory ./templates */
Fatih Acet committed
50 51 52 53 54 55 56
/*= require_directory ./commit */
/*= require_directory ./extensions */
/*= require_directory ./lib/utils */
/*= require_directory ./u2f */
/*= require_directory . */
/*= require fuzzaldrin-plus */

57 58 59
(function () {
  document.addEventListener('page:fetch', gl.utils.cleanupBeforeFetch);
  window.addEventListener('hashchange', gl.utils.shiftWindow);
Fatih Acet committed
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  // 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);

78
  window.onload = function () {
79 80
    // Scroll the window to avoid the topnav bar
    // https://github.com/twitter/bootstrap/issues/1768
Fatih Acet committed
81
    if (location.hash) {
82
      return setTimeout(adjustScroll, 100);
Fatih Acet committed
83 84 85
    }
  };

86 87 88 89 90 91 92 93 94
  $(function () {
    var $body = $('body');
    var $document = $(document);
    var $window = $(window);
    var $sidebarGutterToggle = $('.js-sidebar-toggle');
    var $flash = $('.flash-container');
    var bootstrapBreakpoint = bp.getBreakpointSize();
    var checkInitialSidebarSize;
    var fitSidebarForSize;
95 96 97 98

    // Set the default path for all cookies to GitLab's root directory
    Cookies.defaults.path = gon.relative_url_root || '/';

Fatih Acet committed
99
    gl.utils.preventDisabledButtons();
100
    $('.nav-sidebar').niceScroll({
Fatih Acet committed
101 102
      cursoropacitymax: '0.4',
      cursorcolor: '#FFF',
103
      cursorborder: '1px solid #FFF'
Fatih Acet committed
104
    });
105 106
    $('.js-select-on-focus').on('focusin', function () {
      return $(this).select().one('mouseup', function (e) {
Fatih Acet committed
107 108
        return e.preventDefault();
      });
109 110
    // Click a .js-select-on-focus field, select the contents
    // Prevent a mouseup event from deselecting the input
Fatih Acet committed
111
    });
112
    $('.remove-row').bind('ajax:success', function () {
113 114 115
      $(this).tooltip('destroy')
        .closest('li')
        .fadeOut();
Fatih Acet committed
116
    });
117
    $('.js-remove-tr').bind('ajax:before', function () {
Fatih Acet committed
118 119
      return $(this).hide();
    });
120
    $('.js-remove-tr').bind('ajax:success', function () {
Fatih Acet committed
121 122 123 124
      return $(this).closest('tr').fadeOut();
    });
    $('select.select2').select2({
      width: 'resolve',
125
      // Initialize select2 selects
Fatih Acet committed
126 127
      dropdownAutoWidth: true
    });
128 129
    $('.js-select2').bind('select2-close', function () {
      return setTimeout((function () {
Fatih Acet committed
130 131 132
        $('.select2-container-active').removeClass('select2-container-active');
        return $(':focus').blur();
      }), 1);
133
    // Close select2 on escape
Fatih Acet committed
134
    });
135
    // Initialize tooltips
136
    $.fn.tooltip.Constructor.DEFAULTS.trigger = 'hover';
Fatih Acet committed
137 138
    $body.tooltip({
      selector: '.has-tooltip, [data-toggle="tooltip"]',
139
      placement: function (_, el) {
140
        return $(el).data('placement') || 'bottom';
Fatih Acet committed
141 142
      }
    });
143
    $('.trigger-submit').on('change', function () {
Fatih Acet committed
144
      return $(this).parents('form').submit();
145
    // Form submitter
Fatih Acet committed
146 147
    });
    gl.utils.localTimeAgo($('abbr.timeago, .js-timeago'), true);
148
    // Flash
149 150
    if ($flash.length > 0) {
      $flash.click(function () {
Fatih Acet committed
151 152
        return $(this).fadeOut();
      });
153
      $flash.show();
Fatih Acet committed
154
    }
155
    // Disable form buttons while a form is submitting
156
    $body.on('ajax:complete, ajax:beforeSend, submit', 'form', function (e) {
Fatih Acet committed
157 158 159 160 161 162 163 164 165 166
      var buttons;
      buttons = $('[type="submit"]', this);
      switch (e.type) {
        case 'ajax:beforeSend':
        case 'submit':
          return buttons.disable();
        default:
          return buttons.enable();
      }
    });
167 168
    $(document).ajaxError(function (e, xhrObj) {
      var ref = xhrObj.status;
Fatih Acet committed
169 170
      if (xhrObj.status === 401) {
        return new Flash('You need to be logged in.', 'alert');
171
      } else if (ref === 404 || ref === 500) {
Fatih Acet committed
172 173 174
        return new Flash('Something went wrong on our end.', 'alert');
      }
    });
175
    $('.account-box').hover(function () {
176
      // Show/Hide the profile menu when hovering the account box
Fatih Acet committed
177 178
      return $(this).toggleClass('hover');
    });
179
    $document.on('click', '.diff-content .js-show-suppressed-diff', function () {
Fatih Acet committed
180 181 182 183
      var $container;
      $container = $(this).parent();
      $container.next('table').show();
      return $container.remove();
184
    // Commit show suppressed diff
Fatih Acet committed
185
    });
186
    $('.navbar-toggle').on('click', function () {
Fatih Acet committed
187 188 189 190 191
      $('.header-content .title').toggle();
      $('.header-content .header-logo').toggle();
      $('.header-content .navbar-collapse').toggle();
      return $('.navbar-toggle').toggleClass('active');
    });
192
    // Show/hide comments on diff
193
    $body.on('click', '.js-toggle-diff-comments', function (e) {
194 195
      var $this = $(this);
      var notesHolders = $this.closest('.diff-file').find('.notes_holder');
196
      $this.toggleClass('active');
197
      if ($this.hasClass('active')) {
198
        notesHolders.show().find('.hide').show();
199 200 201
      } else {
        notesHolders.hide();
      }
202
      $this.trigger('blur');
Fatih Acet committed
203 204
      return e.preventDefault();
    });
205 206 207 208 209
    $document.off('click', '.js-confirm-danger');
    $document.on('click', '.js-confirm-danger', function (e) {
      var btn = $(e.target);
      var form = btn.closest('form');
      var text = btn.data('confirm-danger-message');
Fatih Acet committed
210 211 212
      e.preventDefault();
      return new ConfirmDangerModal(form, text);
    });
213 214
    $('input[type="search"]').each(function () {
      var $this = $(this);
Fatih Acet committed
215 216
      $this.attr('value', $this.val());
    });
217
    $document.off('keyup', 'input[type="search"]').on('keyup', 'input[type="search"]', function () {
Fatih Acet committed
218 219 220 221
      var $this;
      $this = $(this);
      return $this.attr('value', $this.val());
    });
222
    $document.off('breakpoint:change').on('breakpoint:change', function (e, breakpoint) {
Fatih Acet committed
223 224 225 226 227 228 229 230
      var $gutterIcon;
      if (breakpoint === 'sm' || breakpoint === 'xs') {
        $gutterIcon = $sidebarGutterToggle.find('i');
        if ($gutterIcon.hasClass('fa-angle-double-right')) {
          return $sidebarGutterToggle.trigger('click');
        }
      }
    });
231
    fitSidebarForSize = function () {
Fatih Acet committed
232 233 234 235 236 237 238
      var oldBootstrapBreakpoint;
      oldBootstrapBreakpoint = bootstrapBreakpoint;
      bootstrapBreakpoint = bp.getBreakpointSize();
      if (bootstrapBreakpoint !== oldBootstrapBreakpoint) {
        return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
      }
    };
239
    checkInitialSidebarSize = function () {
Fatih Acet committed
240
      bootstrapBreakpoint = bp.getBreakpointSize();
241
      if (bootstrapBreakpoint === 'xs' || 'sm') {
Fatih Acet committed
242 243 244
        return $document.trigger('breakpoint:change', [bootstrapBreakpoint]);
      }
    };
245
    $window.off('resize.app').on('resize.app', function () {
Fatih Acet committed
246 247 248 249 250
      return fitSidebarForSize();
    });
    gl.awardsHandler = new AwardsHandler();
    checkInitialSidebarSize();
    new Aside();
251 252 253

    // bind sidebar events
    new gl.Sidebar();
254
  });
Fatih Acet committed
255
}).call(this);