Skip to content

Commit 4a6596a

Browse files
committed
Fixed bunch of js bugs with comments. Also added development tips
1 parent 92137b7 commit 4a6596a

File tree

12 files changed

+281
-212
lines changed

12 files changed

+281
-212
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ Email
3939

4040
## Contribute
4141

42+
[Development Tips](https://github.com/gitlabhq/gitlabhq/blob/master/doc/development.md)
4243
Want to help - send a pull request.
4344
We'll accept good pull requests.

app/assets/javascripts/application.js

+20
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,23 @@ function showDiff(link) {
128128
function ajaxGet(url) {
129129
$.ajax({type: "GET", url: url, dataType: "script"});
130130
}
131+
132+
/**
133+
* Disable button if text field is empty
134+
*/
135+
function disableButtonIfEmtpyField(field_selector, button_selector) {
136+
field = $(field_selector);
137+
if(field.val() == "") {
138+
field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled");
139+
}
140+
141+
field.on('keyup', function(){
142+
var field = $(this);
143+
var closest_submit = field.closest("form").find(button_selector);
144+
if(field.val() == "") {
145+
closest_submit.attr("disabled", "disabled").addClass("disabled");
146+
} else {
147+
closest_submit.removeAttr("disabled").removeClass("disabled");
148+
}
149+
})
150+
}

app/assets/javascripts/note.js

+137-137
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,160 @@
11
var NoteList = {
22

3-
notes_path: null,
4-
target_params: null,
5-
target_id: 0,
6-
target_type: null,
7-
first_id: 0,
8-
last_id: 0,
9-
disable:false,
10-
11-
init:
12-
function(tid, tt, path) {
13-
this.notes_path = path + ".js";
14-
this.target_id = tid;
15-
this.target_type = tt;
16-
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
17-
18-
// get notes
19-
this.getContent();
20-
21-
// get new notes every n seconds
22-
this.initRefresh();
23-
24-
$('.delete-note').live('ajax:success', function() {
25-
$(this).closest('li').fadeOut(); });
26-
27-
$('#note_note').on('keyup', function(){
28-
var field = $(this);
29-
var closest_submit = field.closest("form").find(".submit_note");
30-
if(field.val() == "") {
31-
closest_submit.attr("disabled", "disabled").addClass("disabled");
32-
} else {
33-
closest_submit.removeAttr("disabled").removeClass("disabled");
34-
}
35-
})
36-
37-
$("#new_note").live("ajax:before", function(){
38-
$(".submit_note").attr("disabled", "disabled");
39-
})
40-
41-
$("#new_note").live("ajax:complete", function(){
42-
$(".submit_note").removeAttr("disabled");
43-
})
44-
45-
$("#note_note").live("focus", function(){
46-
$(this).css("height", "80px");
47-
$('.note_advanced_opts').show();
48-
if($(this).val() == "") {
49-
$(this).closest("form").find(".submit_note").attr("disabled", "disabled").addClass("disabled");
50-
}
51-
});
52-
53-
$("#note_attachment").change(function(e){
3+
notes_path: null,
4+
target_params: null,
5+
target_id: 0,
6+
target_type: null,
7+
first_id: 0,
8+
last_id: 0,
9+
disable:false,
10+
11+
init:
12+
function(tid, tt, path) {
13+
this.notes_path = path + ".js";
14+
this.target_id = tid;
15+
this.target_type = tt;
16+
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
17+
18+
// get notes
19+
this.getContent();
20+
21+
// get new notes every n seconds
22+
this.initRefresh();
23+
24+
$('.delete-note').live('ajax:success', function() {
25+
$(this).closest('li').fadeOut(); });
26+
27+
$(".note-form-holder").live("ajax:before", function(){
28+
$(".submit_note").attr("disabled", "disabled");
29+
})
30+
31+
$(".note-form-holder").live("ajax:complete", function(){
32+
$(".submit_note").removeAttr("disabled");
33+
})
34+
35+
disableButtonIfEmtpyField(".note-text", ".submit_note");
36+
37+
$(".note-text").live("focus", function(){
38+
$(this).css("height", "80px");
39+
$('.note_advanced_opts').show();
40+
});
41+
42+
$("#note_attachment").change(function(e){
5443
var val = $('.input-file').val();
5544
var filename = val.replace(/^.*[\\\/]/, '');
5645
$(".file_name").text(filename);
57-
});
46+
});
5847

59-
},
48+
},
6049

6150

62-
/**
63-
* Load new notes to fresh list called 'new_notes_list':
64-
* - Replace 'new_notes_list' with new list every n seconds
65-
* - Append new notes to this list after submit
66-
*/
51+
/**
52+
* Load new notes to fresh list called 'new_notes_list':
53+
* - Replace 'new_notes_list' with new list every n seconds
54+
* - Append new notes to this list after submit
55+
*/
6756

68-
initRefresh:
69-
function() {
70-
// init timer
71-
var intNew = setInterval("NoteList.getNew()", 10000);
72-
},
57+
initRefresh:
58+
function() {
59+
// init timer
60+
var intNew = setInterval("NoteList.getNew()", 10000);
61+
},
7362

74-
replace:
75-
function(html) {
76-
$("#new_notes_list").html(html);
77-
},
63+
replace:
64+
function(html) {
65+
$("#new_notes_list").html(html);
66+
},
7867

79-
prepend:
80-
function(id, html) {
81-
if(id != this.last_id) {
82-
$("#new_notes_list").prepend(html);
83-
}
84-
},
68+
prepend:
69+
function(id, html) {
70+
if(id != this.last_id) {
71+
$("#new_notes_list").prepend(html);
72+
}
73+
},
8574

86-
getNew:
87-
function() {
88-
// refersh notes list
89-
$.ajax({
90-
type: "GET",
75+
getNew:
76+
function() {
77+
// refersh notes list
78+
$.ajax({
79+
type: "GET",
9180
url: this.notes_path,
9281
data: "last_id=" + this.last_id + this.target_params,
9382
dataType: "script"});
94-
},
83+
},
9584

96-
refresh:
97-
function() {
98-
// refersh notes list
99-
$.ajax({
100-
type: "GET",
85+
refresh:
86+
function() {
87+
// refersh notes list
88+
$.ajax({
89+
type: "GET",
10190
url: this.notes_path,
10291
data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params,
10392
dataType: "script"});
104-
},
93+
},
10594

10695

107-
/**
108-
* Init load of notes:
109-
* 1. Get content with ajax call
110-
* 2. Set content of notes list with loaded one
111-
*/
96+
/**
97+
* Init load of notes:
98+
* 1. Get content with ajax call
99+
* 2. Set content of notes list with loaded one
100+
*/
112101

113102

114-
getContent:
115-
function() {
116-
$.ajax({
117-
type: "GET",
103+
getContent:
104+
function() {
105+
$.ajax({
106+
type: "GET",
118107
url: this.notes_path,
119108
data: "?" + this.target_params,
120109
complete: function(){ $('.status').removeClass("loading")},
121110
beforeSend: function() { $('.status').addClass("loading") },
122111
dataType: "script"});
123-
},
112+
},
124113

125-
setContent:
126-
function(fid, lid, html) {
114+
setContent:
115+
function(fid, lid, html) {
127116
this.last_id = lid;
128117
this.first_id = fid;
129118
$("#notes-list").html(html);
130119

131120
// Init infinite scrolling
132121
this.initLoadMore();
133-
},
134-
135-
136-
/**
137-
* Paging for old notes when scroll to bottom:
138-
* 1. Init scroll events with 'initLoadMore'
139-
* 2. Load onlder notes with 'getOld' method
140-
* 3. append old notes to bottom of list with 'append'
141-
*
142-
*/
143-
144-
145-
getOld:
146-
function() {
147-
$('.loading').show();
148-
$.ajax({
149-
type: "GET",
150-
url: this.notes_path,
151-
data: "first_id=" + this.first_id + this.target_params,
152-
complete: function(){ $('.status').removeClass("loading")},
153-
beforeSend: function() { $('.status').addClass("loading") },
154-
dataType: "script"});
155-
},
156-
157-
append:
158-
function(id, html) {
159-
if(this.first_id == id) {
160-
this.disable = true;
161-
} else {
162-
this.first_id = id;
163-
$("#notes-list").append(html);
164-
}
165-
},
166-
122+
},
123+
124+
125+
/**
126+
* Paging for old notes when scroll to bottom:
127+
* 1. Init scroll events with 'initLoadMore'
128+
* 2. Load onlder notes with 'getOld' method
129+
* 3. append old notes to bottom of list with 'append'
130+
*
131+
*/
132+
getOld:
133+
function() {
134+
$('.loading').show();
135+
$.ajax({
136+
type: "GET",
137+
url: this.notes_path,
138+
data: "first_id=" + this.first_id + this.target_params,
139+
complete: function(){ $('.status').removeClass("loading")},
140+
beforeSend: function() { $('.status').addClass("loading") },
141+
dataType: "script"});
142+
},
143+
144+
append:
145+
function(id, html) {
146+
if(this.first_id == id) {
147+
this.disable = true;
148+
} else {
149+
this.first_id = id;
150+
$("#notes-list").append(html);
151+
}
152+
},
167153

168-
initLoadMore:
169-
function() {
170-
$(document).endlessScroll({
171-
bottomPixels: 400,
154+
initLoadMore:
155+
function() {
156+
$(document).endlessScroll({
157+
bottomPixels: 400,
172158
fireDelay: 1000,
173159
fireOnce:true,
174160
ceaseFire: function() {
@@ -177,6 +163,20 @@ initLoadMore:
177163
callback: function(i) {
178164
NoteList.getOld();
179165
}
180-
});
181-
}
166+
});
167+
}
168+
};
169+
170+
var PerLineNotes = {
171+
init:
172+
function() {
173+
$(".line_note_link, .line_note_reply_link").live("click", function(e) {
174+
var form = $(".per_line_form");
175+
$(this).closest("tr").after(form);
176+
form.find("#note_line_code").val($(this).attr("line_code"));
177+
form.show();
178+
return false;
179+
});
180+
disableButtonIfEmtpyField(".line-note-text", ".submit_inline_note");
181+
}
182182
}

app/assets/stylesheets/sections/notes.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
#new_note {
33-
#note_note {
33+
.note-text {
3434
height:25px;
3535
}
3636
.attach_holder {

app/views/commits/show.html.haml

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66

77
:javascript
8-
$(document).ready(function(){
9-
$(".line_note_link, .line_note_reply_link").live("click", function(e) {
10-
var form = $(".per_line_form");
11-
$(this).parent().parent().after(form);
12-
form.find("#note_line_code").val($(this).attr("line_code"));
13-
form.show();
14-
return false;
15-
});
8+
$(function(){
9+
PerLineNotes.init();
1610
});
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
- if note.valid?
22
:plain
3-
$("#new_note .error").remove();
4-
$('#new_note textarea').val("");
5-
$('#preview-link').text('Preview');
6-
$('#preview-note').hide(); $('#note_note').show();
3+
$(".note-form-holder .error").remove();
4+
$('.note-form-holder textarea').val("");
5+
$('.note-form-holder #preview-link').text('Preview');
6+
$('.note-form-holder #preview-note').hide();
7+
$('.note-form-holder').show();
78
NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}");
89
- else
910
:plain
10-
$("#new_note").replaceWith("#{escape_javascript(render('form'))}");
11+
$(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}");
1112

0 commit comments

Comments
 (0)