application.js 8.2 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, no-var, no-undef, quotes, consistent-return, prefer-arrow-callback, comma-dangle, object-shorthand, no-new, max-len */
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.
//
F
Fatih Acet 已提交
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 */
F
Fatih Acet 已提交
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 */
F
Fatih Acet 已提交
50 51 52 53 54 55
/*= require_directory ./commit */
/*= require_directory ./extensions */
/*= require_directory ./lib/utils */
/*= require_directory ./u2f */
/*= require_directory . */
/*= require fuzzaldrin-plus */
F
Filipa Lacerda 已提交
56
/*= require es6-promise.auto */
F
Fatih Acet 已提交
57

J
José Iván 已提交
58 59
(function () {
  document.addEventListener('page:fetch', gl.utils.cleanupBeforeFetch);
60 61 62 63 64
  window.addEventListener('hashchange', gl.utils.handleLocationHash);
  window.addEventListener('load', function onLoad() {
    window.removeEventListener('load', onLoad, false);
    if (window.location.hash) {
      setTimeout(gl.utils.handleLocationHash, 100);
F
Fatih Acet 已提交
65
    }
66
  }, false);
F
Fatih Acet 已提交
67

J
José Iván 已提交
68 69 70 71 72 73 74 75 76
  $(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;
77 78 79 80

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

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

    // bind sidebar events
    new gl.Sidebar();
236
  });
F
Fatih Acet 已提交
237
}).call(this);