application.js 3.77 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2 3 4 5 6 7
// 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.
//
//= require jquery
8
//= require jquery.ui.all
gitlabhq's avatar
gitlabhq committed
9
//= require jquery_ujs
10
//= require jquery.cookie
11
//= require jquery.endless-scroll
12
//= require jquery.highlight
13
//= require jquery.waitforimages
14
//= require bootstrap-modal
15
//= require modernizr
Nihad Abbasov's avatar
Nihad Abbasov committed
16
//= require chosen-jquery
17
//= require raphael
Valery Sizov's avatar
Valery Sizov committed
18
//= require branch-graph
gitlabhq's avatar
gitlabhq committed
19 20
//= require_tree .

21
$(document).ready(function(){
22

23
  $(".one_click_select").live("click", function(){
gitlabhq's avatar
gitlabhq committed
24 25 26
    $(this).select();
  });

27 28 29 30 31 32 33 34 35 36 37 38 39 40
  $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
    var buttons = $('[type="submit"]', this);
    switch( e.type ){
      case 'ajax:beforeSend':
      case 'submit':
        buttons.attr('disabled', 'disabled');
      break;
      case ' ajax:complete':
      default:
        buttons.removeAttr('disabled');
      break;
    }
  })

41 42
  $(".account-box").mouseenter(showMenu);
  $(".account-box").mouseleave(resetMenu);
43

44 45 46 47 48 49 50 51
  $("#projects-list .project").live('click', function(e){
    if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") {
      location.href = $(this).attr("url");
      e.stopPropagation();
      return false;
    }
  });

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
52 53 54
  /**
   * Focus search field by pressing 's' key
   */
55 56 57 58 59 60 61
  $(document).keypress(function(e) {
    if( $(e.target).is(":input") ) return;
    switch(e.which)  {
      case 115:  focusSearch();
        e.preventDefault();
    }
  });
62 63 64

  /**
   * Commit show suppressed diff
65
   *
66 67 68
   */
  $(".supp_diff_link").bind("click", function() {
    showDiff(this);
randx's avatar
randx committed
69
  });
Nihad Abbasov's avatar
Nihad Abbasov committed
70 71 72 73 74

  /**
   * Note markdown preview
   *
   */
75
  $(document).on('click', '#preview-link', function(e) {
76
    $('#preview-note').text('Loading...');
Nihad Abbasov's avatar
Nihad Abbasov committed
77 78 79 80

    var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview');
    $(this).text(previewLinkText);

81 82 83 84 85 86
    var note = $('#note_note').val();
    if (note.trim().length === 0) { note = 'Nothing to preview'; }
    $.post($(this).attr('href'), {note: note}, function(data) {
      $('#preview-note').html(data);
    });

Nihad Abbasov's avatar
Nihad Abbasov committed
87 88 89
    $('#preview-note, #note_note').toggle();
    e.preventDefault();
  });
90
});
91

92 93 94 95
function focusSearch() {
  $("#search").focus();
}

gitlabhq's avatar
gitlabhq committed
96 97
function updatePage(data){
  $.ajax({type: "GET", url: location.href, data: data, dataType: "script"});
gitlabhq's avatar
gitlabhq committed
98
}
Ricardo Rauch's avatar
Ricardo Rauch committed
99 100

function showMenu() {
101
  $(this).toggleClass('hover');
Ricardo Rauch's avatar
Ricardo Rauch committed
102 103 104
}

function resetMenu() {
105
  $(this).removeClass("hover");
Valery Sizov's avatar
Valery Sizov committed
106
}
107 108 109 110

function slugify(text) {
  return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase();
}
111

112 113 114 115 116
function showDiff(link) {
  $(link).next('table').show();
  $(link).remove();
}

117 118 119 120 121 122 123 124 125
(function($){
    var _chosen = $.fn.chosen;
    $.fn.extend({
        chosen: function(options) {
            var default_options = {'search_contains' : 'true'};
            $.extend(default_options, options);
            return _chosen.apply(this, [default_options]);
    }})
})(jQuery);
126 127


Nihad Abbasov's avatar
Nihad Abbasov committed
128 129
function ajaxGet(url) {
  $.ajax({type: "GET", url: url, dataType: "script"});
130
}
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

/**
 * Disable button if text field is empty
 */
function disableButtonIfEmtpyField(field_selector, button_selector) { 
  field = $(field_selector);
  if(field.val() == "") { 
    field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
  }

  field.on('keyup', function(){
    var field = $(this);
    var closest_submit = field.closest("form").find(button_selector);
    if(field.val() == "") { 
      closest_submit.attr("disabled", "disabled").addClass("disabled");
    } else { 
      closest_submit.removeAttr("disabled").removeClass("disabled");
    }
  })
}