issuable_context.js 2.82 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-new, comma-dangle, quotes, prefer-arrow-callback, consistent-return, one-var, no-var, one-var-declaration-per-line, no-underscore-dangle, max-len */
2
/* global UsersSelect */
3 4
/* global Cookies */
/* global bp */
5

Fatih Acet's avatar
Fatih Acet committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
(function() {
  this.IssuableContext = (function() {
    function IssuableContext(currentUser) {
      this.initParticipants();
      new UsersSelect(currentUser);
      $('select.select2').select2({
        width: 'resolve',
        dropdownAutoWidth: true
      });
      $(".issuable-sidebar .inline-update").on("change", "select", function() {
        return $(this).submit();
      });
      $(".issuable-sidebar .inline-update").on("change", ".js-assignee", function() {
        return $(this).submit();
      });
      $(document).off('click', '.issuable-sidebar .dropdown-content a').on('click', '.issuable-sidebar .dropdown-content a', function(e) {
        return e.preventDefault();
      });
      $(document).off('click', '.edit-link').on('click', '.edit-link', function(e) {
        var $block, $selectbox;
        e.preventDefault();
        $block = $(this).parents('.block');
        $selectbox = $block.find('.selectbox');
        if ($selectbox.is(':visible')) {
          $selectbox.hide();
          $block.find('.value').show();
        } else {
          $selectbox.show();
          $block.find('.value').hide();
        }
        if ($selectbox.is(':visible')) {
          return setTimeout(function() {
            return $block.find('.dropdown-menu-toggle').trigger('click');
          }, 0);
        }
      });
42 43 44 45 46 47 48
      window.addEventListener('beforeunload', function() {
        // collapsed_gutter cookie hides the sidebar
        var bpBreakpoint = bp.getBreakpointSize();
        if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm') {
          Cookies.set('collapsed_gutter', true);
        }
      });
Fatih Acet's avatar
Fatih Acet committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
      $(".right-sidebar").niceScroll();
    }

    IssuableContext.prototype.initParticipants = function() {
      var _this;
      _this = this;
      $(document).on("click", ".js-participants-more", this.toggleHiddenParticipants);
      return $(".js-participants-author").each(function(i) {
        if (i >= _this.PARTICIPANTS_ROW_COUNT) {
          return $(this).addClass("js-participants-hidden").hide();
        }
      });
    };

    IssuableContext.prototype.toggleHiddenParticipants = function(e) {
      var currentText, lessText, originalText;
      e.preventDefault();
      currentText = $(this).text().trim();
      lessText = $(this).data("less-text");
      originalText = $(this).data("original-text");
      if (currentText === originalText) {
        $(this).text(lessText);
      } else {
        $(this).text(originalText);
      }
      return $(".js-participants-hidden").toggle();
    };

    return IssuableContext;
  })();
}).call(this);