2014-07-25 23:24:27 -05:00
|
|
|
// @codekit-prepend "lib/jquery-1.11.1.min.js"
|
2014-07-26 22:53:16 -05:00
|
|
|
// @codekit-prepend "lib/lib.js"
|
2014-09-25 08:52:58 -05:00
|
|
|
// @codekit-prepend "utils/tabs.js"
|
|
|
|
// @codekit-prepend "utils/preview.js"
|
2014-12-07 08:29:37 -05:00
|
|
|
// @codekit-prepend "gogs/issue_label.js"
|
2014-09-22 13:47:47 -05:00
|
|
|
// @codekit-prepend "lib/jquery.tipsy.js"
|
2014-07-25 23:24:27 -05:00
|
|
|
|
2014-07-26 22:53:16 -05:00
|
|
|
var Gogs = {};
|
|
|
|
|
2014-07-25 23:24:27 -05:00
|
|
|
(function ($) {
|
2014-07-26 22:53:16 -05:00
|
|
|
// Extend jQuery ajax, set CSRF token value.
|
2014-07-25 23:24:27 -05:00
|
|
|
var ajax = $.ajax;
|
|
|
|
$.extend({
|
|
|
|
ajax: function (url, options) {
|
|
|
|
if (typeof url === 'object') {
|
|
|
|
options = url;
|
|
|
|
url = undefined;
|
|
|
|
}
|
|
|
|
options = options || {};
|
|
|
|
url = options.url;
|
|
|
|
var csrftoken = $('meta[name=_csrf]').attr('content');
|
|
|
|
var headers = options.headers || {};
|
|
|
|
var domain = document.domain.replace(/\./ig, '\\.');
|
|
|
|
if (!/^(http:|https:).*/.test(url) || eval('/^(http:|https:)\\/\\/(.+\\.)*' + domain + '.*/').test(url)) {
|
|
|
|
headers = $.extend(headers, {'X-Csrf-Token': csrftoken});
|
|
|
|
}
|
|
|
|
options.headers = headers;
|
|
|
|
var callback = options.success;
|
|
|
|
options.success = function (data) {
|
|
|
|
if (data.once) {
|
|
|
|
// change all _once value if ajax data.once exist
|
|
|
|
$('[name=_once]').val(data.once);
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return ajax(url, options);
|
|
|
|
},
|
|
|
|
|
|
|
|
changeHash: function (hash) {
|
|
|
|
if (history.pushState) {
|
|
|
|
history.pushState(null, null, hash);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
location.hash = hash;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deSelect: function () {
|
|
|
|
if (window.getSelection) {
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
} else {
|
|
|
|
document.selection.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-08-07 05:40:05 -05:00
|
|
|
$.fn.extend({
|
|
|
|
toggleHide: function () {
|
2015-09-04 22:39:23 -05:00
|
|
|
$(this).each(function(n, v) { $(v).addClass("hidden"); });
|
2014-08-07 05:40:05 -05:00
|
|
|
},
|
|
|
|
toggleShow: function () {
|
2015-09-04 22:39:23 -05:00
|
|
|
$(this).each(function(n, v) { $(v).removeClass("hidden"); });
|
2014-08-07 05:40:05 -05:00
|
|
|
},
|
|
|
|
toggleAjax: function (successCallback, errorCallback) {
|
|
|
|
var url = $(this).data("ajax");
|
|
|
|
var method = $(this).data('ajax-method') || 'get';
|
|
|
|
var ajaxName = $(this).data('ajax-name');
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
if (ajaxName.endsWith("preview")) {
|
|
|
|
data["mode"] = "gfm";
|
|
|
|
data["context"] = $(this).data('ajax-context');
|
|
|
|
}
|
|
|
|
|
|
|
|
$('[data-ajax-rel=' + ajaxName + ']').each(function () {
|
|
|
|
var field = $(this).data("ajax-field");
|
|
|
|
var t = $(this).data("ajax-val");
|
|
|
|
if (t == "val") {
|
|
|
|
data[field] = $(this).val();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "txt") {
|
|
|
|
data[field] = $(this).text();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "html") {
|
|
|
|
data[field] = $(this).html();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "data") {
|
|
|
|
data[field] = $(this).data("ajax-data");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
console.log("toggleAjax:", method, url, data);
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
method: method.toUpperCase(),
|
|
|
|
data: data,
|
|
|
|
error: errorCallback,
|
|
|
|
success: function (d) {
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-07-25 23:24:27 -05:00
|
|
|
}(jQuery));
|
|
|
|
|
2014-07-26 22:53:16 -05:00
|
|
|
(function ($) {
|
|
|
|
// Render markdown.
|
|
|
|
Gogs.renderMarkdown = function () {
|
|
|
|
var $md = $('.markdown');
|
|
|
|
var $pre = $md.find('pre > code').parent();
|
2014-07-31 23:06:19 -05:00
|
|
|
$pre.addClass('prettyprint');
|
2014-07-26 22:53:16 -05:00
|
|
|
prettyPrint();
|
|
|
|
|
|
|
|
// Set anchor.
|
|
|
|
var headers = {};
|
|
|
|
$md.find('h1, h2, h3, h4, h5, h6').each(function () {
|
|
|
|
var node = $(this);
|
|
|
|
var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-'));
|
|
|
|
var name = val;
|
|
|
|
if (headers[val] > 0) {
|
|
|
|
name = val + '-' + headers[val];
|
|
|
|
}
|
|
|
|
if (headers[val] == undefined) {
|
|
|
|
headers[val] = 1;
|
|
|
|
} else {
|
|
|
|
headers[val] += 1;
|
|
|
|
}
|
|
|
|
node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>');
|
|
|
|
node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Render code view.
|
|
|
|
Gogs.renderCodeView = function () {
|
2015-02-04 19:52:31 -05:00
|
|
|
function selectRange($list, $select, $from) {
|
|
|
|
$list.removeClass('active');
|
|
|
|
if ($from) {
|
|
|
|
var a = parseInt($select.attr('rel').substr(1));
|
|
|
|
var b = parseInt($from.attr('rel').substr(1));
|
|
|
|
var c;
|
|
|
|
if (a != b) {
|
|
|
|
if (a > b) {
|
|
|
|
c = a;
|
|
|
|
a = b;
|
|
|
|
b = c;
|
|
|
|
}
|
|
|
|
var classes = [];
|
|
|
|
for (i = a; i <= b; i++) {
|
|
|
|
classes.push('.L' + i);
|
|
|
|
}
|
|
|
|
$list.filter(classes.join(',')).addClass('active');
|
|
|
|
$.changeHash('#L' + a + '-' + 'L' + b);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$select.addClass('active');
|
|
|
|
$.changeHash('#' + $select.attr('rel'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on('click', '.lines-num span', function (e) {
|
|
|
|
var $select = $(this);
|
|
|
|
var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
|
|
|
|
selectRange($list, $list.filter('[rel=' + $select.attr('rel') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
|
|
|
|
$.deSelect();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.code-view .lines-code > pre').each(function () {
|
|
|
|
var $pre = $(this);
|
|
|
|
var $lineCode = $pre.parent();
|
|
|
|
var $lineNums = $lineCode.siblings('.lines-num');
|
|
|
|
if ($lineNums.length > 0) {
|
|
|
|
var nums = $pre.find('ol.linenums > li').length;
|
|
|
|
for (var i = 1; i <= nums; i++) {
|
|
|
|
$lineNums.append('<span id="L' + i + '" rel="L' + i + '">' + i + '</span>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).on('hashchange', function (e) {
|
|
|
|
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
|
|
|
var $list = $('.code-view ol.linenums > li');
|
|
|
|
var $first;
|
|
|
|
if (m) {
|
|
|
|
$first = $list.filter('.' + m[1]);
|
|
|
|
selectRange($list, $first, $list.filter('.' + m[2]));
|
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m = window.location.hash.match(/^#(L\d+)$/);
|
|
|
|
if (m) {
|
|
|
|
$first = $list.filter('.' + m[1]);
|
|
|
|
selectRange($list, $first);
|
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
|
|
|
}
|
|
|
|
}).trigger('hashchange');
|
|
|
|
};
|
|
|
|
|
|
|
|
// Render diff view.
|
|
|
|
Gogs.renderDiffView = function () {
|
2014-07-26 22:53:16 -05:00
|
|
|
function selectRange($list, $select, $from) {
|
|
|
|
$list.removeClass('active');
|
2015-02-05 02:49:04 -05:00
|
|
|
$list.parents('tr').removeClass('end-selected-line');
|
2015-02-03 15:53:34 -05:00
|
|
|
$list.parents('tr').find('td').removeClass('selected-line');
|
2014-07-26 22:53:16 -05:00
|
|
|
if ($from) {
|
2015-02-19 03:08:47 -05:00
|
|
|
var expr = new RegExp(/diff-(\w+)([LR]\d+)/);
|
2015-02-05 02:49:04 -05:00
|
|
|
var selectMatches = $select.attr('rel').match(expr)
|
|
|
|
var fromMatches = $from.attr('rel').match(expr)
|
2015-02-19 03:08:47 -05:00
|
|
|
var selectTop = $select.offset().top;
|
|
|
|
var fromTop = $from.offset().top;
|
|
|
|
var hash;
|
2015-02-05 02:49:04 -05:00
|
|
|
|
2015-02-19 03:08:47 -05:00
|
|
|
if (selectMatches[2] != fromMatches[2]) {
|
|
|
|
if ((selectTop > fromTop)) {
|
|
|
|
$startElem = $from;
|
|
|
|
$endElem = $select;
|
|
|
|
hash = fromMatches[1]+fromMatches[2] + '-' + selectMatches[2];
|
|
|
|
} else {
|
|
|
|
$startElem = $select;
|
|
|
|
$endElem = $from;
|
|
|
|
hash = selectMatches[1]+selectMatches[2] + '-' + fromMatches[2];
|
2014-07-26 22:53:16 -05:00
|
|
|
}
|
2015-02-19 03:08:47 -05:00
|
|
|
$endElem.parents('tr').next().addClass('end-selected-line');
|
|
|
|
var $selectedLines = $startElem.parents('tr').nextUntil('.end-selected-line').andSelf();
|
2015-02-05 02:49:04 -05:00
|
|
|
$selectedLines.find('td.lines-num > span').addClass('active')
|
|
|
|
$selectedLines.find('td').addClass('selected-line');
|
2015-02-19 03:08:47 -05:00
|
|
|
$.changeHash('#diff-'+hash);
|
2014-07-26 22:53:16 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$select.addClass('active');
|
2015-02-03 15:53:34 -05:00
|
|
|
$select.parents('tr').find('td').addClass('selected-line');
|
2014-07-26 22:53:16 -05:00
|
|
|
$.changeHash('#' + $select.attr('rel'));
|
|
|
|
}
|
|
|
|
|
2015-02-04 19:52:31 -05:00
|
|
|
$(document).on('click', '.code-diff .lines-num span', function (e) {
|
2014-07-26 22:53:16 -05:00
|
|
|
var $select = $(this);
|
2015-02-03 15:53:34 -05:00
|
|
|
var $list = $select.parent().siblings('.lines-code').parents().find('td.lines-num > span');
|
|
|
|
selectRange(
|
|
|
|
$list,
|
|
|
|
$list.filter('[rel=' + $select.attr('rel') + ']'),
|
|
|
|
(e.shiftKey && $list.filter('.active').length ? $list.filter('.active').eq(0) : null)
|
|
|
|
);
|
2014-07-26 22:53:16 -05:00
|
|
|
$.deSelect();
|
|
|
|
});
|
|
|
|
|
2015-02-04 19:52:31 -05:00
|
|
|
$('.code-diff .lines-code > pre').each(function () {
|
2014-07-26 22:53:16 -05:00
|
|
|
var $pre = $(this);
|
|
|
|
var $lineCode = $pre.parent();
|
|
|
|
var $lineNums = $lineCode.siblings('.lines-num');
|
|
|
|
if ($lineNums.length > 0) {
|
|
|
|
var nums = $pre.find('ol.linenums > li').length;
|
|
|
|
for (var i = 1; i <= nums; i++) {
|
|
|
|
$lineNums.append('<span id="L' + i + '" rel="L' + i + '">' + i + '</span>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(window).on('hashchange', function (e) {
|
2015-02-18 16:52:22 -05:00
|
|
|
var m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)\-([LR]\d+)$/);
|
2015-02-04 19:52:31 -05:00
|
|
|
var $list = $('.code-diff td.lines-num > span');
|
2014-07-30 09:02:31 -05:00
|
|
|
var $first;
|
2014-07-26 22:53:16 -05:00
|
|
|
if (m) {
|
2015-02-05 02:49:04 -05:00
|
|
|
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
|
|
|
|
selectRange($list, $first, $list.filter('[rel=diff-' + m[1] + m[3] + ']'));
|
2014-07-26 22:53:16 -05:00
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-18 16:52:22 -05:00
|
|
|
m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)$/);
|
2014-07-26 22:53:16 -05:00
|
|
|
if (m) {
|
2015-02-05 02:49:04 -05:00
|
|
|
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
|
2014-07-26 22:53:16 -05:00
|
|
|
selectRange($list, $first);
|
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
|
|
|
}
|
|
|
|
}).trigger('hashchange');
|
|
|
|
};
|
2014-08-07 05:40:05 -05:00
|
|
|
|
|
|
|
// Search users by keyword.
|
|
|
|
Gogs.searchUsers = function (val, $target) {
|
2014-12-02 09:55:52 -05:00
|
|
|
var notEmpty = function (str) {
|
|
|
|
return str && str.length > 0;
|
|
|
|
}
|
2014-08-07 05:40:05 -05:00
|
|
|
$.ajax({
|
2014-09-22 13:47:47 -05:00
|
|
|
url: Gogs.AppSubUrl + '/api/v1/users/search?q=' + val,
|
2014-08-07 05:40:05 -05:00
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (json.ok && json.data.length) {
|
|
|
|
var html = '';
|
|
|
|
$.each(json.data, function (i, item) {
|
2014-12-22 03:44:49 -05:00
|
|
|
html += '<li><a><img src="' + item.avatar_url + '"><span class="username">' + item.username + '</span>';
|
2014-12-02 09:55:52 -05:00
|
|
|
if (notEmpty(item.full_name)) {
|
|
|
|
html += ' (' + item.full_name + ')';
|
|
|
|
}
|
|
|
|
html += '</a></li>';
|
2014-08-07 05:40:05 -05:00
|
|
|
});
|
|
|
|
$target.html(html);
|
|
|
|
$target.toggleShow();
|
|
|
|
} else {
|
|
|
|
$target.toggleHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-26 05:11:15 -05:00
|
|
|
|
|
|
|
// Search repositories by keyword.
|
|
|
|
Gogs.searchRepos = function (val, $target, $param) {
|
|
|
|
$.ajax({
|
2014-09-22 13:47:47 -05:00
|
|
|
url: Gogs.AppSubUrl + '/api/v1/repos/search?q=' + val + '&' + $param,
|
2014-08-26 05:11:15 -05:00
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (json.ok && json.data.length) {
|
|
|
|
var html = '';
|
|
|
|
$.each(json.data, function (i, item) {
|
2014-11-13 02:32:18 -05:00
|
|
|
html += '<li><a><span class="octicon octicon-repo"></span> ' + item.full_name + '</a></li>';
|
2014-08-26 05:11:15 -05:00
|
|
|
});
|
|
|
|
$target.html(html);
|
|
|
|
$target.toggleShow();
|
|
|
|
} else {
|
|
|
|
$target.toggleHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-31 08:03:16 -05:00
|
|
|
|
|
|
|
// Copy util.
|
|
|
|
Gogs.bindCopy = function (selector) {
|
|
|
|
if ($(selector).hasClass('js-copy-bind')) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-03 14:27:15 -05:00
|
|
|
|
|
|
|
if ( document.documentElement.classList.contains("is-copy-enabled") ) {
|
|
|
|
|
|
|
|
$(selector).click(function(event) {
|
2014-09-23 12:51:10 -05:00
|
|
|
var $this = $(this);
|
2015-08-03 14:27:15 -05:00
|
|
|
|
|
|
|
var cfrom = $this.attr('data-copy-from');
|
|
|
|
$(cfrom).select();
|
|
|
|
document.execCommand('copy');
|
|
|
|
getSelection().removeAllRanges();
|
|
|
|
|
2014-09-23 12:51:10 -05:00
|
|
|
$this.tipsy("hide").attr('original-title', $this.data('after-title'));
|
2014-09-22 13:47:47 -05:00
|
|
|
setTimeout(function () {
|
2014-09-23 12:51:10 -05:00
|
|
|
$this.tipsy("show");
|
2014-09-22 13:47:47 -05:00
|
|
|
}, 200);
|
|
|
|
setTimeout(function () {
|
2014-09-23 12:51:10 -05:00
|
|
|
$this.tipsy('hide').attr('original-title', $this.data('original-title'));
|
|
|
|
}, 2000);
|
2015-08-03 14:27:15 -05:00
|
|
|
|
|
|
|
this.blur();
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(selector).addClass("js-copy-bind");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$(selector).zclip({
|
|
|
|
path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf",
|
|
|
|
copy: function () {
|
|
|
|
var t = $(this).data("copy-val");
|
|
|
|
var to = $($(this).data("copy-from"));
|
|
|
|
var str = "";
|
|
|
|
if (t == "txt") {
|
|
|
|
str = to.text();
|
|
|
|
}
|
|
|
|
if (t == 'val') {
|
|
|
|
str = to.val();
|
|
|
|
}
|
|
|
|
if (t == 'html') {
|
|
|
|
str = to.html();
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
afterCopy: function () {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.tipsy("hide").attr('original-title', $this.data('after-title'));
|
|
|
|
setTimeout(function () {
|
|
|
|
$this.tipsy("show");
|
|
|
|
}, 200);
|
|
|
|
setTimeout(function () {
|
|
|
|
$this.tipsy('hide').attr('original-title', $this.data('original-title'));
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
}).addClass("js-copy-bind");
|
|
|
|
}
|
2014-08-31 08:03:16 -05:00
|
|
|
}
|
2014-07-26 22:53:16 -05:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
function initCore() {
|
|
|
|
Gogs.renderMarkdown();
|
2015-02-04 19:52:31 -05:00
|
|
|
|
|
|
|
if ($('.code-diff').length == 0) {
|
|
|
|
Gogs.renderCodeView();
|
|
|
|
} else {
|
|
|
|
Gogs.renderDiffView();
|
|
|
|
}
|
2014-09-23 12:47:54 -05:00
|
|
|
|
|
|
|
// Switch list.
|
|
|
|
$('.js-tab-nav').click(function (e) {
|
|
|
|
if (!$(this).hasClass('js-tab-nav-show')) {
|
|
|
|
$(this).parent().find('.js-tab-nav-show').each(function () {
|
|
|
|
$(this).removeClass('js-tab-nav-show');
|
|
|
|
$($(this).data('tab-target')).hide();
|
|
|
|
});
|
|
|
|
$(this).addClass('js-tab-nav-show');
|
|
|
|
$($(this).data('tab-target')).show();
|
|
|
|
}
|
2014-09-25 08:52:58 -05:00
|
|
|
e.preventDefault();
|
2014-09-23 12:47:54 -05:00
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
|
|
|
|
// Popup.
|
|
|
|
$(document).on('click', '.popup-modal-dismiss', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$.magnificPopup.close();
|
|
|
|
});
|
2014-10-10 20:40:51 -05:00
|
|
|
|
2014-11-12 06:48:50 -05:00
|
|
|
// Plugins.
|
2014-10-10 20:40:51 -05:00
|
|
|
$('.collapse').hide();
|
2014-11-12 06:48:50 -05:00
|
|
|
$('.tipsy-tooltip').tipsy({
|
|
|
|
fade: true
|
|
|
|
});
|
2014-07-26 22:53:16 -05:00
|
|
|
}
|
|
|
|
|
2014-08-14 01:12:21 -05:00
|
|
|
function initUserSetting() {
|
|
|
|
// Confirmation of change username in user profile page.
|
2014-09-26 21:33:30 -05:00
|
|
|
var $username = $('#username');
|
2014-09-28 00:38:25 -05:00
|
|
|
var $profile_form = $('#user-profile-form');
|
|
|
|
$('#change-username-btn').magnificPopup({
|
2014-09-26 21:33:30 -05:00
|
|
|
modal: true,
|
|
|
|
callbacks: {
|
|
|
|
open: function () {
|
|
|
|
if (($username.data('uname') == $username.val())) {
|
|
|
|
$.magnificPopup.close();
|
2014-09-28 00:38:25 -05:00
|
|
|
$profile_form.submit();
|
2014-09-26 21:33:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-28 00:38:25 -05:00
|
|
|
}).click(function () {
|
|
|
|
if (($username.data('uname') != $username.val())) {
|
2014-08-14 01:12:21 -05:00
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#change-username-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$profile_form.submit();
|
|
|
|
});
|
2014-08-14 01:12:21 -05:00
|
|
|
|
2014-11-12 06:48:50 -05:00
|
|
|
// Show panels.
|
|
|
|
$('.show-form-btn').click(function () {
|
|
|
|
$($(this).data('target-form')).removeClass("hide");
|
2014-08-14 01:12:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Confirmation of delete account.
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#delete-account-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
}).click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#delete-account-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$('#delete-account-form').submit();
|
2014-08-14 01:12:21 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-26 22:53:16 -05:00
|
|
|
function initRepoCreate() {
|
|
|
|
// Owner switch menu click.
|
|
|
|
$('#repo-create-owner-list').on('click', 'li', function () {
|
|
|
|
if (!$(this).hasClass('checked')) {
|
|
|
|
var uid = $(this).data('uid');
|
|
|
|
$('#repo-owner-id').val(uid);
|
|
|
|
$('#repo-owner-avatar').attr("src", $(this).find('img').attr("src"));
|
|
|
|
$('#repo-owner-name').text($(this).text().trim());
|
|
|
|
|
|
|
|
$(this).parent().find('.checked').removeClass('checked');
|
|
|
|
$(this).addClass('checked');
|
|
|
|
console.log("set repo owner to uid :", uid, $(this).text().trim());
|
|
|
|
}
|
|
|
|
});
|
2014-07-31 23:06:19 -05:00
|
|
|
|
|
|
|
$('#auth-button').click(function (e) {
|
|
|
|
$('#repo-migrate-auth').slideToggle('fast');
|
|
|
|
e.preventDefault();
|
|
|
|
})
|
|
|
|
console.log('initRepoCreate');
|
2014-07-26 22:53:16 -05:00
|
|
|
}
|
|
|
|
|
2014-08-31 08:03:16 -05:00
|
|
|
function initRepo() {
|
|
|
|
// Clone link switch button.
|
|
|
|
$('#repo-clone-ssh').click(function () {
|
|
|
|
$(this).removeClass('btn-gray').addClass('btn-blue');
|
|
|
|
$('#repo-clone-https').removeClass('btn-blue').addClass('btn-gray');
|
|
|
|
$('#repo-clone-url').val($(this).data('link'));
|
|
|
|
$('.clone-url').text($(this).data('link'))
|
|
|
|
});
|
|
|
|
$('#repo-clone-https').click(function () {
|
|
|
|
$(this).removeClass('btn-gray').addClass('btn-blue');
|
|
|
|
$('#repo-clone-ssh').removeClass('btn-blue').addClass('btn-gray');
|
|
|
|
$('#repo-clone-url').val($(this).data('link'));
|
|
|
|
$('.clone-url').text($(this).data('link'))
|
|
|
|
});
|
2014-09-23 12:47:54 -05:00
|
|
|
|
2014-08-31 08:03:16 -05:00
|
|
|
// Copy URL.
|
2014-09-22 13:47:47 -05:00
|
|
|
var $clone_btn = $('#repo-clone-copy');
|
|
|
|
$clone_btn.hover(function () {
|
2014-08-31 08:03:16 -05:00
|
|
|
Gogs.bindCopy($(this));
|
|
|
|
})
|
2014-09-22 13:47:47 -05:00
|
|
|
$clone_btn.tipsy({
|
|
|
|
fade: true
|
|
|
|
});
|
2014-12-10 16:37:54 -05:00
|
|
|
|
|
|
|
// Markdown preview.
|
|
|
|
$('.markdown-preview').click(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.toggleAjax(function (resp) {
|
|
|
|
$($this.data("preview")).html(resp);
|
|
|
|
}, function () {
|
|
|
|
$($this.data("preview")).html("no content");
|
|
|
|
})
|
|
|
|
});
|
2014-08-31 08:03:16 -05:00
|
|
|
}
|
|
|
|
|
2014-09-04 06:17:00 -05:00
|
|
|
// when user changes hook type, hide/show proper divs
|
|
|
|
function initHookTypeChange() {
|
2014-08-24 07:59:47 -05:00
|
|
|
// web hook type change
|
|
|
|
$('select#hook-type').on("change", function () {
|
2014-09-22 13:47:47 -05:00
|
|
|
hookTypes = ['Gogs', 'Slack'];
|
2014-08-24 07:59:47 -05:00
|
|
|
|
2014-09-22 13:47:47 -05:00
|
|
|
var curHook = $(this).val();
|
|
|
|
hookTypes.forEach(function (hookType) {
|
|
|
|
if (curHook === hookType) {
|
|
|
|
$('div#' + hookType.toLowerCase()).toggleShow();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('div#' + hookType.toLowerCase()).toggleHide();
|
|
|
|
}
|
|
|
|
});
|
2014-08-24 07:59:47 -05:00
|
|
|
});
|
2014-09-04 06:17:00 -05:00
|
|
|
}
|
|
|
|
|
2014-12-10 16:37:54 -05:00
|
|
|
function initRepoRelease() {
|
|
|
|
$('#release-new-target-branch-list li').click(function() {
|
2014-12-10 16:41:49 -05:00
|
|
|
if (!$(this).hasClass('checked')) {
|
|
|
|
$('#repo-branch-current').text($(this).text());
|
|
|
|
$('#tag-target').val($(this).text());
|
|
|
|
|
|
|
|
$(this).parent().find('.checked').removeClass('checked');
|
|
|
|
$(this).addClass('checked');
|
|
|
|
}
|
2014-12-10 16:37:54 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-09-04 06:17:00 -05:00
|
|
|
function initRepoSetting() {
|
|
|
|
// Options.
|
|
|
|
// Confirmation of changing repository name.
|
2014-09-28 00:38:25 -05:00
|
|
|
var $reponame = $('#repo_name');
|
|
|
|
var $setting_form = $('#repo-setting-form');
|
|
|
|
$('#change-reponame-btn').magnificPopup({
|
|
|
|
modal: true,
|
|
|
|
callbacks: {
|
|
|
|
open: function () {
|
|
|
|
if (($reponame.data('repo-name') == $reponame.val())) {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$setting_form.submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).click(function () {
|
|
|
|
if (($reponame.data('repo-name') != $reponame.val())) {
|
2014-09-04 06:17:00 -05:00
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#change-reponame-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$setting_form.submit();
|
|
|
|
});
|
2014-09-04 06:17:00 -05:00
|
|
|
|
|
|
|
initHookTypeChange();
|
2014-08-24 07:59:47 -05:00
|
|
|
|
2014-09-29 17:52:28 -05:00
|
|
|
// Transfer repository.
|
|
|
|
$('#transfer-repo-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
$('#transfer-repo-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$('#transfer-repo-form').submit();
|
2014-08-02 12:47:33 -05:00
|
|
|
});
|
2014-09-29 17:52:28 -05:00
|
|
|
|
|
|
|
// Delete repository.
|
|
|
|
$('#delete-repo-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
$('#delete-repo-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$('#delete-repo-form').submit();
|
2014-08-02 12:47:33 -05:00
|
|
|
});
|
2014-08-07 05:40:05 -05:00
|
|
|
|
|
|
|
// Collaboration.
|
|
|
|
$('#repo-collab-list hr:last-child').remove();
|
|
|
|
var $ul = $('#repo-collaborator').next().next().find('ul');
|
|
|
|
$('#repo-collaborator').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Gogs.searchUsers($this.val(), $ul);
|
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
} else {
|
|
|
|
$ul.toggleShow();
|
|
|
|
}
|
|
|
|
}).next().next().find('ul').on("click", 'li', function () {
|
2015-02-04 19:52:31 -05:00
|
|
|
$('#repo-collaborator').val($(this).find('.username').text());
|
2014-08-07 05:40:05 -05:00
|
|
|
$ul.toggleHide();
|
|
|
|
});
|
2014-08-02 12:47:33 -05:00
|
|
|
}
|
|
|
|
|
2014-08-14 01:12:21 -05:00
|
|
|
function initOrgSetting() {
|
|
|
|
// Options.
|
|
|
|
// Confirmation of changing organization name.
|
2014-09-28 00:38:25 -05:00
|
|
|
var $orgname = $('#orgname');
|
|
|
|
var $setting_form = $('#org-setting-form');
|
|
|
|
$('#change-orgname-btn').magnificPopup({
|
|
|
|
modal: true,
|
|
|
|
callbacks: {
|
|
|
|
open: function () {
|
|
|
|
if (($orgname.data('orgname') == $orgname.val())) {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$setting_form.submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).click(function () {
|
|
|
|
if (($orgname.data('orgname') != $orgname.val())) {
|
2014-08-14 01:12:21 -05:00
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#change-orgname-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$setting_form.submit();
|
|
|
|
});
|
|
|
|
|
2014-08-14 01:12:21 -05:00
|
|
|
// Confirmation of delete organization.
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#delete-org-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
}).click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#delete-org-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
$('#delete-org-form').submit();
|
2014-08-14 01:12:21 -05:00
|
|
|
});
|
2014-09-04 06:17:00 -05:00
|
|
|
|
|
|
|
initHookTypeChange();
|
2014-08-14 01:12:21 -05:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:37:33 -05:00
|
|
|
function initInvite() {
|
|
|
|
// Invitation.
|
|
|
|
var $ul = $('#org-member-invite-list');
|
|
|
|
$('#org-member-invite').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Gogs.searchUsers($this.val(), $ul);
|
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
} else {
|
|
|
|
$ul.toggleShow();
|
|
|
|
}
|
|
|
|
}).next().next().find('ul').on("click", 'li', function () {
|
2014-12-22 03:44:49 -05:00
|
|
|
$('#org-member-invite').val($(this).find('.username').text());
|
2014-08-15 10:37:33 -05:00
|
|
|
$ul.toggleHide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-24 08:09:05 -05:00
|
|
|
function initOrgTeamCreate() {
|
|
|
|
// Delete team.
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#org-team-delete').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
}).click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#delete-team-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
2014-08-26 05:11:15 -05:00
|
|
|
var $form = $('#team-create-form');
|
2014-08-24 08:09:05 -05:00
|
|
|
$form.attr('action', $form.data('delete-url'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initTeamMembersList() {
|
|
|
|
// Add team member.
|
|
|
|
var $ul = $('#org-team-members-list');
|
|
|
|
$('#org-team-members-add').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Gogs.searchUsers($this.val(), $ul);
|
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
} else {
|
|
|
|
$ul.toggleShow();
|
|
|
|
}
|
|
|
|
}).next().next().find('ul').on("click", 'li', function () {
|
2015-02-01 08:46:53 -05:00
|
|
|
$('#org-team-members-add').val($(this).find('.username').text());
|
2014-08-24 08:09:05 -05:00
|
|
|
$ul.toggleHide();
|
|
|
|
});
|
2014-08-26 05:11:15 -05:00
|
|
|
}
|
2014-08-24 08:09:05 -05:00
|
|
|
|
2014-08-26 05:11:15 -05:00
|
|
|
function initTeamRepositoriesList() {
|
|
|
|
// Add team repository.
|
|
|
|
var $ul = $('#org-team-repositories-list');
|
|
|
|
$('#org-team-repositories-add').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Gogs.searchRepos($this.val(), $ul, 'uid=' + $this.data('uid'));
|
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$ul.toggleHide();
|
|
|
|
} else {
|
|
|
|
$ul.toggleShow();
|
|
|
|
}
|
|
|
|
}).next().next().find('ul').on("click", 'li', function () {
|
|
|
|
$('#org-team-repositories-add').val($(this).text());
|
|
|
|
$ul.toggleHide();
|
|
|
|
});
|
2014-08-24 08:09:05 -05:00
|
|
|
}
|
|
|
|
|
2014-08-29 02:32:52 -05:00
|
|
|
function initAdmin() {
|
|
|
|
// Create account.
|
2014-08-29 07:50:43 -05:00
|
|
|
$('#login-type').on("change", function () {
|
2014-08-29 02:32:52 -05:00
|
|
|
var v = $(this).val();
|
2014-08-29 07:50:43 -05:00
|
|
|
if (v.indexOf("0-") + 1) {
|
2014-08-29 02:32:52 -05:00
|
|
|
$('.auth-name').toggleHide();
|
2014-08-29 07:50:43 -05:00
|
|
|
$(".pwd").find("input").attr("required", "required")
|
2014-08-29 02:32:52 -05:00
|
|
|
.end().toggleShow();
|
2014-08-29 07:50:43 -05:00
|
|
|
} else {
|
2014-08-29 02:32:52 -05:00
|
|
|
$(".pwd").find("input").removeAttr("required")
|
|
|
|
.end().toggleHide();
|
|
|
|
$('.auth-name').toggleShow();
|
|
|
|
}
|
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
|
2014-08-29 02:32:52 -05:00
|
|
|
// Delete account.
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#delete-account-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
}).click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#delete-account-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
2014-09-07 18:02:58 -05:00
|
|
|
var $form = $('#user-profile-form');
|
2014-08-29 02:32:52 -05:00
|
|
|
$form.attr('action', $form.data('delete-url'));
|
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
|
2015-09-04 22:39:23 -05:00
|
|
|
// Create authorization. Keep list in sync with models/login.go.
|
|
|
|
var all_auths = ['none', 'plain', 'ldap', 'dldap', 'smtp', 'pam'];
|
2014-08-29 07:50:43 -05:00
|
|
|
$('#auth-type').on("change", function () {
|
|
|
|
var v = $(this).val();
|
2015-09-04 22:39:23 -05:00
|
|
|
if (v >= all_auths.length) return;
|
|
|
|
|
|
|
|
// Hide all through their class names.
|
|
|
|
$.each(all_auths, function(i, type) {
|
|
|
|
$('.' + type).toggleHide();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Show the selected one.
|
|
|
|
var selected = all_auths[v];
|
|
|
|
$('.' + selected).toggleShow();
|
2014-08-29 07:50:43 -05:00
|
|
|
});
|
2014-09-28 00:38:25 -05:00
|
|
|
|
2014-08-29 07:50:43 -05:00
|
|
|
// Delete authorization.
|
2014-09-28 00:38:25 -05:00
|
|
|
$('#delete-auth-btn').magnificPopup({
|
|
|
|
modal: true
|
|
|
|
}).click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#delete-auth-submit').click(function () {
|
|
|
|
$.magnificPopup.close();
|
|
|
|
var $form = $('#auth-setting-form');
|
2014-08-29 07:50:43 -05:00
|
|
|
$form.attr('action', $form.data('delete-url'));
|
|
|
|
});
|
2014-08-29 02:32:52 -05:00
|
|
|
}
|
|
|
|
|
2014-09-07 18:02:58 -05:00
|
|
|
function initInstall() {
|
|
|
|
// Change database type.
|
|
|
|
(function () {
|
|
|
|
var mysql_default = '127.0.0.1:3306';
|
|
|
|
var postgres_default = '127.0.0.1:5432';
|
|
|
|
|
|
|
|
$('#install-database').on("change", function () {
|
|
|
|
var val = $(this).val();
|
|
|
|
if (val != "SQLite3") {
|
|
|
|
$('.server-sql').show();
|
|
|
|
$('.sqlite-setting').addClass("hide");
|
|
|
|
if (val == "PostgreSQL") {
|
|
|
|
$('.pgsql-setting').removeClass("hide");
|
|
|
|
|
|
|
|
// Change the host value to the Postgres default, but only
|
|
|
|
// if the user hasn't already changed it from the MySQL
|
|
|
|
// default.
|
|
|
|
if ($('#database-host').val() == mysql_default) {
|
|
|
|
$('#database-host').val(postgres_default);
|
|
|
|
}
|
|
|
|
} else if (val == 'MySQL') {
|
|
|
|
$('.pgsql-setting').addClass("hide");
|
|
|
|
if ($('#database-host').val() == postgres_default) {
|
|
|
|
$('#database-host').val(mysql_default);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('.pgsql-setting').addClass("hide");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('.server-sql').hide();
|
|
|
|
$('.pgsql-setting').hide();
|
|
|
|
$('.sqlite-setting').removeClass("hide");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
2014-09-25 18:33:39 -05:00
|
|
|
function initProfile() {
|
|
|
|
// Avatar.
|
|
|
|
$('#profile-avatar').tipsy({
|
|
|
|
fade: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-10 20:40:51 -05:00
|
|
|
function initTimeSwitch() {
|
|
|
|
// Time switch.
|
|
|
|
$(".time-since[title]").on("click", function () {
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
var title = $this.attr("title");
|
|
|
|
var text = $this.text();
|
|
|
|
|
|
|
|
$this.text(title);
|
|
|
|
$this.attr("title", text);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initDiff() {
|
|
|
|
$('.diff-detail-box>a').click(function () {
|
|
|
|
$($(this).data('target')).slideToggle(100);
|
|
|
|
})
|
2014-10-12 01:06:46 -05:00
|
|
|
|
2014-10-10 20:40:51 -05:00
|
|
|
var $counter = $('.diff-counter');
|
|
|
|
if ($counter.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$counter.each(function (i, item) {
|
|
|
|
var $item = $(item);
|
|
|
|
var addLine = $item.find('span[data-line].add').data("line");
|
|
|
|
var delLine = $item.find('span[data-line].del').data("line");
|
|
|
|
var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
|
|
|
|
$item.find(".bar .add").css("width", addPercent + "%");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-25 23:24:27 -05:00
|
|
|
$(document).ready(function () {
|
2014-09-25 21:11:51 -05:00
|
|
|
Gogs.AppSubUrl = $('head').data('suburl') || '';
|
2014-07-26 22:53:16 -05:00
|
|
|
initCore();
|
2014-08-14 01:12:21 -05:00
|
|
|
if ($('#user-profile-setting').length) {
|
|
|
|
initUserSetting();
|
|
|
|
}
|
2014-07-31 23:06:19 -05:00
|
|
|
if ($('#repo-create-form').length || $('#repo-migrate-form').length) {
|
2014-07-26 22:53:16 -05:00
|
|
|
initRepoCreate();
|
|
|
|
}
|
2014-08-31 08:03:16 -05:00
|
|
|
if ($('#repo-header').length) {
|
2014-12-10 16:37:54 -05:00
|
|
|
initTimeSwitch();
|
2014-08-31 08:03:16 -05:00
|
|
|
initRepo();
|
|
|
|
}
|
2014-12-10 16:37:54 -05:00
|
|
|
if ($('#release').length) {
|
|
|
|
initRepoRelease();
|
|
|
|
}
|
2014-08-02 12:47:33 -05:00
|
|
|
if ($('#repo-setting').length) {
|
|
|
|
initRepoSetting();
|
|
|
|
}
|
2014-08-14 01:12:21 -05:00
|
|
|
if ($('#org-setting').length) {
|
|
|
|
initOrgSetting();
|
|
|
|
}
|
2014-08-15 10:37:33 -05:00
|
|
|
if ($('#invite-box').length) {
|
|
|
|
initInvite();
|
|
|
|
}
|
2014-08-24 08:09:05 -05:00
|
|
|
if ($('#team-create-form').length) {
|
|
|
|
initOrgTeamCreate();
|
|
|
|
}
|
|
|
|
if ($('#team-members-list').length) {
|
|
|
|
initTeamMembersList();
|
|
|
|
}
|
2014-08-26 05:11:15 -05:00
|
|
|
if ($('#team-repositories-list').length) {
|
|
|
|
initTeamRepositoriesList();
|
|
|
|
}
|
2014-08-29 02:32:52 -05:00
|
|
|
if ($('#admin-setting').length) {
|
|
|
|
initAdmin();
|
|
|
|
}
|
2014-09-07 18:02:58 -05:00
|
|
|
if ($('#install-form').length) {
|
|
|
|
initInstall();
|
|
|
|
}
|
2014-09-25 18:33:39 -05:00
|
|
|
if ($('#user-profile-page').length) {
|
|
|
|
initProfile();
|
|
|
|
}
|
2014-10-10 20:40:51 -05:00
|
|
|
if ($('#diff-page').length) {
|
|
|
|
initTimeSwitch();
|
|
|
|
initDiff();
|
|
|
|
}
|
2014-07-26 22:53:16 -05:00
|
|
|
|
2014-09-25 08:52:58 -05:00
|
|
|
$('#dashboard-sidebar-menu').tabs();
|
|
|
|
$('#pull-issue-preview').markdown_preview(".issue-add-comment");
|
2014-07-25 23:24:27 -05:00
|
|
|
|
|
|
|
homepage();
|
2015-09-05 13:14:03 -05:00
|
|
|
emojify.setConfig({
|
2015-09-06 05:57:25 -05:00
|
|
|
img_dir: Gogs.AppSubUrl + '/img/emoji'
|
2015-09-05 13:14:03 -05:00
|
|
|
});
|
|
|
|
emojify.run();
|
2014-07-25 23:24:27 -05:00
|
|
|
|
|
|
|
// Fix language drop-down menu height.
|
|
|
|
var l = $('#footer-lang li').length;
|
|
|
|
$('#footer-lang .drop-down').css({
|
|
|
|
"top": (-31 * l) + "px",
|
|
|
|
"height": (31 * l - 3) + "px"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function homepage() {
|
|
|
|
// Change method to GET if no username input.
|
|
|
|
$('#promo-form').submit(function (e) {
|
|
|
|
if ($('#username').val() === "") {
|
|
|
|
e.preventDefault();
|
2014-09-22 13:47:47 -05:00
|
|
|
window.location.href = Gogs.AppSubUrl + '/user/login';
|
2014-07-25 23:24:27 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Redirect to register page.
|
|
|
|
$('#register-button').click(function (e) {
|
|
|
|
if ($('#username').val() === "") {
|
|
|
|
e.preventDefault();
|
2014-09-22 13:47:47 -05:00
|
|
|
window.location.href = Gogs.AppSubUrl + '/user/sign_up';
|
2014-07-25 23:24:27 -05:00
|
|
|
return true
|
|
|
|
}
|
2014-09-22 13:47:47 -05:00
|
|
|
$('#promo-form').attr('action', Gogs.AppSubUrl + '/user/sign_up');
|
2014-07-25 23:24:27 -05:00
|
|
|
});
|
2014-08-24 07:59:47 -05:00
|
|
|
}
|
2014-12-10 16:37:54 -05:00
|
|
|
|
|
|
|
String.prototype.endsWith = function (suffix) {
|
|
|
|
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
|
|
|
};
|