1
2
3
4
5
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
42
43
44
45
46
47
48
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
/*
#--
# Copyright (C) 2007-2009 Johan Sørensen <johan@johansorensen.com>
# Copyright (C) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#--
*/
$(document).ready(function() {
// Project Sluggorizin'
$("form #project_title").keyup(function(event) {
var slug = $("form #project_slug");
if (slug.text() != "") return;
var lintName = function(val) {
var linted = val.replace(/\W+/g, ' ').replace(/\ +/g, '-');
linted = linted.toLowerCase().replace(/\-+$/g, '');
return linted;
}
slug.val( lintName(this.value) );
});
// Line highlighting/selection
$("#codeblob").highlightSelectedLines();
// no-op links
$("a.link_noop").click(function(event) {
event.preventDefault();
});
// Comment previewing
$("input#comment_preview_button").click(function(event){
var formElement = $(this).parents("form");
var url = formElement.attr("action");
url += "/preview"
$.post(url, formElement.serialize(), function(data, responseText){
if (responseText === "success") {
$("#comment_preview").html(data);
$("#comment_preview").fadeIn();
}
});
event.preventDefault();
});
// Project previewing
$("input#project_preview_button").click(function(event){
var formElement = $(this).parents("form");
var url = $(this).attr("gts:url");
$.post(url, formElement.serialize(), function(data, response) {
if (response === "success")
$("#project-preview").html(data).fadeIn();
});
event.preventDefault();
});
// Markdown help toggling
$(".markdown-help-toggler").click(function(event){
$(".markdown_help").toggle();
event.preventDefault();
});
$("a#advanced-search-toggler").click(function(event) {
$("#search_help").slideToggle();
event.preventDefault();
});
// Merge request status color picking
$("#merge_request_statuses input.color_pickable").SevenColorPicker();
// Toggle details of commit events
$("a.commit_event_toggler").click(function(event){
var callbackUrl = $(this).attr("gts:url");
var eventId = $(this).attr("gts:id");
$("#commits_in_event_" + eventId).toggle();
if ($("#commits_in_event_" + eventId).is(":visible")) {
$("#commits_in_event_" + eventId).load(callbackUrl);
}
event.preventDefault();
});
// frontpage for non-loggedin users
// Unobtrusively hooking the regular/OpenID login box stuff, so that it works
// in a semi-sensible way with javascript disabled.
$("#big_header_login_box_to_openid, #big_header_login_box_to_regular").click(function(e){
$("#big_header_login_box_openid").toggle("fast");
$("#big_header_login_box_regular").toggle("fast");
e.preventDefault();
});
// replace the search form input["submit"] with something fancier
$("#main_menu_search_form").each(function(){
var headerSearchForm = this;
var labelText = "Search...";
var searchInput = $(this).find("input[type=text]");
searchInput.val(labelText);
searchInput.click(function(event){
if (searchInput.val() == labelText) {
searchInput.val("");
searchInput.removeClass("unfocused");
}
});
searchInput.blur(function(event){
if (searchInput.val() == "") {
searchInput.val(labelText);
searchInput.addClass("unfocused");
}
});
// hide the 'native' submit button and replace it with our
// own awesome submit button
var nativeSubmitButton = $(this).find("input[type=submit]");
nativeSubmitButton.hide();
var awesomeSubmitButton = $(document.createElement("a"));
awesomeSubmitButton.attr({
'id':'main_menu_search_form_graphic_submit',
'href': '#'
});
awesomeSubmitButton.click(function(event){
headerSearchForm.submit();
event.preventDefault();
});
nativeSubmitButton.after(awesomeSubmitButton);
});
// Commment editing
$(".comment .edit_link a").live("click", function(){
var commentContainer = $(this).parents(".comment");
var formUrl = $(this).attr("gts:url");
var spinner = $(this).parent().next(".link-spinner").show();
var commentId = commentContainer.attr("gts:comment-id");
var commentLink = commentContainer.siblings("[name=comment_" + commentId + "]");
jQuery.ajax({url:formUrl, success:function(data) {
spinner.hide();
commentContainer.append(data);
commentContainer.find("form").submit(function(){
var url = $(this).attr("action");
var data = $(this).serialize();
jQuery.post(url, data, function(payload) {
commentLink.remove();
commentContainer.replaceWith(payload);
});
return false;
})
}, error: function(){
spinner.hide();
commentContainer.append(
"<p>We're sorry, but you're not allowed to edit the comment. " +
"Only the creator of a comment may edit it, and then only for " +
"a short period of time after it's been created</p>"
);
}});
});
$(".comment .comment_form .cancel").live("click", function(){
var theForm = $(this).parents(".comment_form");
theForm.remove();
});
// Relative times based on clients browser time
jQuery.extend(jQuery.timeago.settings.strings, {
seconds: "a minute",
minute: "a minute",
minutes: "%d minutes",
hour: "an hour",
hours: "%d hours",
day: "a day",
days: "%d days",
month: "a month",
months: "%d months",
year: "a year",
years: "%d years"
});
jQuery('abbr.timeago').timeago();
// Rails generates some quite obtrusive markup when
// :method => whatever is used in link_to etc.
jQuery("a[data-request-method]").replaceRailsGeneratedForm();
// watchable/favorite list filtering
$("#watchable-list").each(function() {
$this = $(this);
$this.find(".filters a.all").addClass("current")
$this.find(".filters a").css({'outline':'none'});
var makeCurrent = function(newCurrent) {
$this.find(".filters a").removeClass("current");
$(newCurrent).addClass("current");
};
var swapAndMakeCurrent = function(klass, current) {
$this.find(".favorite." + klass).show();
$this.find(".favorite:not(." + klass + ")").hide();
makeCurrent(current);
}
$this.find(".filters a.all").click(function() {
$this.find(".favorite").show();
makeCurrent(this);
return false;
});
$this.find(".filters a.repositories").click(function() {
swapAndMakeCurrent("repository", this);
return false;
});
$this.find(".filters a.merge-requests").click(function() {
swapAndMakeCurrent("merge_request");
return false;
});
$this.find(".filters a.mine").click(function() {
swapAndMakeCurrent("mine");
return false;
});
$this.find(".filters a.foreign").click(function() {
swapAndMakeCurrent("foreign");
return false;
});
});
// Favorite toggling and deletion on the /favorites page
$("#favorite-listing tr:odd").addClass("odd");
$("#favorite-listing td.notification .favorite.update a").click(function() {
$this = $(this);
payload = "_method=put&favorite[notify_by_email]=1";
$.post($this.attr("href"), payload, function(data, respTxt){
if ("success" === respTxt) {
if ("off" === $this.text()) {
$this.text("on").removeClass("disabled").addClass("enabled");
} else {
$this.text("off").removeClass("enabled").addClass("disabled")
}
}
});
return false;
});
$("#favorite-listing td.unwatch .favorite a.watch-link").click(function() {
$this = $(this);
payload = "_method=delete";
$.post($this.attr("href"), payload, function(data, respTxt){
if ("success" === respTxt) {
$this.parents("tr").fadeOut("normal", function(){
$(this).remove();
$("#favorite-listing tr").removeClass("odd");
$("#favorite-listing tr:odd").addClass("odd");
});
}
});
return false;
});
});
if (!Gitorious)
var Gitorious = {};
Gitorious.DownloadChecker = {
checkURL: function(url, container) {
var element = $("#" + container);
//element.absolutize();
var sourceLink = element.prev();
// Position the box
if (sourceLink) {
element.css({
'top': parseInt(element[0].style.top) - (element.height()+10) + "px",
'width': '175px',
'height': '70px',
'position': 'absolute'
});
}
element.html('<p class="spin"><img src="/images/spinner.gif" /></p>');
element.show();
// load the status
element.load(url, function(responseText, textStatus, XMLHttpRequest){
if (textStatus == "success") {
$(this).html(responseText);
}
});
return false;
}
};
// Gitorious.Wordwrapper = {
// wrap: function(elements) {
// elements.each(function(e) {
// //e.addClassName("softwrapped");
// e.removeClassName("unwrapped");
// });
// },
// unwrap: function(elements) {
// elements.each(function(e) {
// //e.removeClassName("softwrapped");
// e.addClassName("unwrapped");
// });
// },
// toggle: function(elements) {
// if (/unwrapped/.test(elements.first().className)) {
// Gitorious.Wordwrapper.wrap(elements);
// } else {
// Gitorious.Wordwrapper.unwrap(elements);
// }
// }
// }
// A class used for selecting ranges of objects
function CommitRangeSelector(commitListUrl, targetBranchesUrl, statusElement)
{
this.commitListUrl = commitListUrl
this.targetBranchesUrl = targetBranchesUrl;
this.statusElement = statusElement;
this.endsAt = null;
this.sourceBranchName = null;
this.targetBranchName = null;
this.REASONABLY_SANE_RANGE_SIZE = 50;
this.endSelected = function(el) {
this.endsAt = $(el);
this.update();
};
this.onSourceBranchChange = function(event) {
if (sourceBranch = $('#merge_request_source_branch')) {
this.sourceBranchSelected(sourceBranch);
}
};
this.onTargetRepositoryChange = function(event) {
$("#spinner").fadeIn();
$.post(this.targetBranchesUrl, $("#new_merge_request").serialize(),
function(data, responseText)
{
if (responseText === "success") {
$("#target_branch_selection").html(data);
$("#spinner").fadeOut();
}
});
this._updateCommitList();
};
this.onTargetBranchChange = function(event) {
if (targetBranch = $('#merge_request_target_branch').val()) {
this.targetBranchSelected(targetBranch);
}
};
this.targetBranchSelected = function(branchName) {
if (branchName != this.targetBranchName) {
this.targetBranchName = branchName;
this._updateCommitList();
}
};
this.sourceBranchSelected = function(branchName) {
if (branchName != this.sourceBranchName) {
this.sourceBranchName = branchName;
this._updateCommitList();
}
};
this.update = function() {
if (this.endsAt) {
$(".commit_row").each(function(){ $(this).removeClass("selected") });
var selectedTr = this.endsAt.parent().parent();
selectedTr.addClass('selected');
var selectedTrCount = 1;
selectedTr.nextAll().each(function() {
$(this).addClass('selected');
selectedTrCount++;
});
if (selectedTrCount > this.REASONABLY_SANE_RANGE_SIZE) {
$("#large_selection_warning").slideDown();
} else {
$("#large_selection_warning").slideUp();
}
// update the status field with the selected range
var to = selectedTr.find(".sha-abbrev a").html();
var from = $(".commit_row:last .sha-abbrev a").html();
$("." + this.statusElement).each(function() {
$(this).html(from + ".." + to);
});
}
};
this._updateCommitList = function() {
$("#commit_table").replaceWith('<p class="hint">Loading commits… ' +
'<img src="/images/spinner.gif"/></p>');
$.post(this.commitListUrl, $("#new_merge_request").serialize(),
function(data, responseText)
{
if (responseText === "success")
$("#commit_selection").html(data);
});
}
}
function toggle_wiki_preview(target_url) {
var wiki_preview = $('#page_preview');
var wiki_edit = $('#page_content');
var wiki_form = wiki_edit[0].form;
var toggler = $('#wiki_preview_toggler');
if (toggler.val() == "Hide preview") {
toggler.val("Show preview");
} else {
toggler.val("Hide preview");
wiki_preview.html("");
$.post(target_url, $(wiki_form).serialize(), function(data, textStatus){
if (textStatus == "success") {
wiki_preview.html(data);
}
});
}
jQuery.each([wiki_preview, wiki_edit], function(){ $(this).toggle() });
}
// function load_commit_status()
// {
// var merge_request_uri = document.location.pathname;
// ['merged','unmerged'].each(function(s)
// {
// var i1 = new Image();
// i1.src = "/images/merge_requests/" + s + ".png";
// });
// $$('tr.commit_row').each(function(commit_row)
// {
// id = commit_row.getAttribute('data-merge-request-commit-id');
// new Ajax.Request(merge_request_uri + "/commit_status?commit_id=" + id, {method:'get', onSuccess: function(transport){
// commit_row.removeClassName("unknown-status");
// if (transport.responseText == 'false'){
// commit_row.addClassName("unmerged");
// }
// else{
// commit_row.addClassName("merged");
// }
// }});
// });
// }
|