2014-03-06 20:25:32 +05:30
|
|
|
var Gogits = {
|
|
|
|
"PageIsSignup": false
|
|
|
|
};
|
2014-03-02 19:17:55 +05:30
|
|
|
|
2014-03-22 23:14:02 +05:30
|
|
|
(function($){
|
|
|
|
// extend jQuery ajax, set csrf token value
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}(jQuery));
|
|
|
|
|
2014-03-06 20:25:32 +05:30
|
|
|
(function ($) {
|
2014-03-10 14:24:52 +05:30
|
|
|
|
2014-03-02 19:17:55 +05:30
|
|
|
Gogits.showTab = function (selector, index) {
|
|
|
|
if (!index) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
$(selector).tab("show");
|
|
|
|
$(selector).find("li:eq(" + index + ") a").tab("show");
|
2014-03-06 20:25:32 +05:30
|
|
|
};
|
|
|
|
Gogits.validateForm = function (selector, options) {
|
|
|
|
var $form = $(selector);
|
|
|
|
options = options || {};
|
|
|
|
options.showErrors = function (map, list) {
|
|
|
|
var $error = $form.find('.form-error').addClass('hidden');
|
|
|
|
$('.has-error').removeClass("has-error");
|
|
|
|
$error.text(list[0].message).show().removeClass("hidden");
|
|
|
|
$(list[0].element).parents(".form-group").addClass("has-error");
|
|
|
|
};
|
|
|
|
$form.validate(options);
|
|
|
|
};
|
2014-03-10 14:24:52 +05:30
|
|
|
|
|
|
|
// ----- init elements
|
|
|
|
Gogits.initModals = function () {
|
|
|
|
var modals = $("[data-toggle=modal]");
|
|
|
|
if (modals.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.each(modals, function (i, item) {
|
2014-03-10 18:42:49 +05:30
|
|
|
var hide = $(item).data('modal');
|
|
|
|
$(item).modal(hide ? hide : "hide");
|
2014-03-10 14:24:52 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
Gogits.initTooltips = function () {
|
|
|
|
$("body").tooltip({
|
|
|
|
selector: "[data-toggle=tooltip]"
|
|
|
|
//container: "body"
|
|
|
|
});
|
|
|
|
};
|
2014-03-17 15:43:07 +05:30
|
|
|
Gogits.initPopovers = function () {
|
2014-03-20 17:42:31 +05:30
|
|
|
var hideAllPopovers = function () {
|
|
|
|
$('[data-toggle=popover]').each(function () {
|
2014-03-17 15:43:07 +05:30
|
|
|
$(this).popover('hide');
|
2014-03-20 17:42:31 +05:30
|
|
|
});
|
2014-03-17 15:43:07 +05:30
|
|
|
};
|
|
|
|
|
2014-03-20 17:42:31 +05:30
|
|
|
$(document).on('click', function (e) {
|
2014-03-17 15:43:07 +05:30
|
|
|
var $e = $(e.target);
|
2014-03-20 17:42:31 +05:30
|
|
|
if ($e.data('toggle') == 'popover' || $e.parents("[data-toggle=popover], .popover").length > 0) {
|
2014-03-17 15:43:07 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideAllPopovers();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").popover({
|
|
|
|
selector: "[data-toggle=popover]"
|
|
|
|
});
|
|
|
|
};
|
2014-03-10 18:42:49 +05:30
|
|
|
Gogits.initTabs = function () {
|
2014-03-13 11:38:49 +05:30
|
|
|
var $tabs = $('[data-init=tabs]');
|
|
|
|
$tabs.find("li:eq(0) a").tab("show");
|
2014-03-17 12:47:44 +05:30
|
|
|
};
|
2014-03-21 20:57:33 +05:30
|
|
|
// fix dropdown inside click
|
|
|
|
Gogits.initDropDown = function(){
|
2014-03-23 15:06:12 +05:30
|
|
|
$('.dropdown-menu.no-propagation').on('click',function(e){
|
2014-03-21 20:57:33 +05:30
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
};
|
2014-03-17 12:47:44 +05:30
|
|
|
|
|
|
|
// render markdown
|
|
|
|
Gogits.renderMarkdown = function () {
|
2014-03-20 14:55:48 +05:30
|
|
|
var $md = $('.markdown');
|
|
|
|
var $pre = $md.find('pre > code').parent();
|
2014-03-20 21:25:27 +05:30
|
|
|
$pre.addClass('prettyprint linenums');
|
2014-03-17 12:47:44 +05:30
|
|
|
prettyPrint();
|
2014-03-20 14:55:48 +05:30
|
|
|
|
2014-03-20 18:40:37 +05:30
|
|
|
var $lineNums = $pre.parent().siblings('.lines-num');
|
2014-03-20 19:02:08 +05:30
|
|
|
if ($lineNums.length > 0) {
|
2014-03-20 18:40:37 +05:30
|
|
|
var nums = $pre.find('ol.linenums > li').length;
|
2014-03-20 19:05:46 +05:30
|
|
|
for (var i = 1; i <= nums; i++) {
|
|
|
|
$lineNums.append('<span id="L' + i + '" rel=".L' + i + '">' + i + '</span>');
|
2014-03-20 18:40:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var last;
|
2014-03-20 19:02:08 +05:30
|
|
|
$(document).on('click', '.lines-num span', function () {
|
2014-03-20 18:40:37 +05:30
|
|
|
var $e = $(this);
|
2014-03-20 19:02:08 +05:30
|
|
|
if (last) {
|
2014-03-20 18:40:37 +05:30
|
|
|
last.removeClass('active');
|
|
|
|
}
|
|
|
|
last = $e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel'));
|
|
|
|
last.addClass('active');
|
|
|
|
window.location.href = '#' + $e.attr('id');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:55:48 +05:30
|
|
|
// 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;
|
2014-03-20 19:02:08 +05:30
|
|
|
if (headers[val] > 0) {
|
2014-03-20 14:55:48 +05:30
|
|
|
name = val + '-' + headers[val];
|
|
|
|
}
|
2014-03-20 19:02:08 +05:30
|
|
|
if (headers[val] == undefined) {
|
2014-03-20 14:55:48 +05:30
|
|
|
headers[val] = 1;
|
2014-03-20 19:02:08 +05:30
|
|
|
} else {
|
2014-03-20 14:55:48 +05:30
|
|
|
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>');
|
|
|
|
});
|
2014-03-10 18:42:49 +05:30
|
|
|
}
|
2014-03-17 12:47:44 +05:30
|
|
|
|
2014-03-10 18:42:49 +05:30
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
// ajax utils
|
|
|
|
(function ($) {
|
|
|
|
Gogits.ajaxDelete = function (url, data, success) {
|
|
|
|
data = data || {};
|
|
|
|
data._method = "DELETE";
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
method: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (success) {
|
|
|
|
success(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-03-03 20:10:22 +05:30
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
2014-03-06 20:25:32 +05:30
|
|
|
function initCore() {
|
2014-03-10 14:24:52 +05:30
|
|
|
Gogits.initTooltips();
|
2014-03-17 15:43:07 +05:30
|
|
|
Gogits.initPopovers();
|
2014-03-13 11:38:49 +05:30
|
|
|
Gogits.initTabs();
|
2014-03-10 14:24:52 +05:30
|
|
|
Gogits.initModals();
|
2014-03-21 20:57:33 +05:30
|
|
|
Gogits.initDropDown();
|
2014-03-17 12:47:44 +05:30
|
|
|
Gogits.renderMarkdown();
|
2014-03-06 20:25:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function initRegister() {
|
|
|
|
$.getScript("/js/jquery.validate.min.js", function () {
|
|
|
|
Gogits.validateForm("#gogs-login-card", {
|
|
|
|
rules: {
|
|
|
|
"username": {
|
|
|
|
required: true,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"email": {
|
|
|
|
required: true,
|
|
|
|
email: true
|
|
|
|
},
|
|
|
|
"passwd": {
|
|
|
|
required: true,
|
|
|
|
minlength: 6,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"re-passwd": {
|
|
|
|
required: true,
|
|
|
|
equalTo: "input[name=passwd]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-10 18:42:49 +05:30
|
|
|
}
|
|
|
|
|
2014-03-17 12:47:44 +05:30
|
|
|
function initUserSetting() {
|
2014-03-16 18:37:50 +05:30
|
|
|
$('#gogs-ssh-keys .delete').confirmation({
|
|
|
|
singleton: true,
|
2014-03-17 12:47:44 +05:30
|
|
|
onConfirm: function (e, $this) {
|
|
|
|
Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) {
|
|
|
|
if (json.ok) {
|
2014-03-16 18:37:50 +05:30
|
|
|
window.location.reload();
|
2014-03-17 12:47:44 +05:30
|
|
|
} else {
|
2014-03-16 18:37:50 +05:30
|
|
|
alert(json.err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-10 18:42:49 +05:30
|
|
|
});
|
2014-03-16 20:55:01 +05:30
|
|
|
}
|
|
|
|
|
2014-03-20 17:42:31 +05:30
|
|
|
function initRepository() {
|
2014-03-21 20:57:33 +05:30
|
|
|
// clone group button script
|
2014-03-20 19:02:08 +05:30
|
|
|
(function () {
|
2014-03-21 20:57:33 +05:30
|
|
|
var $clone = $('.clone-group-btn');
|
|
|
|
if ($clone.length) {
|
|
|
|
var $url = $('.clone-group-url');
|
|
|
|
$clone.find('button[data-link]').on("click",function (e) {
|
2014-03-20 19:02:08 +05:30
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.hasClass('btn-primary')) {
|
2014-03-21 20:57:33 +05:30
|
|
|
$clone.find('.btn-primary').removeClass('btn-primary').addClass("btn-default");
|
2014-03-20 19:02:08 +05:30
|
|
|
$(this).addClass('btn-primary').removeClass('btn-default');
|
|
|
|
$url.val($this.data("link"));
|
2014-03-21 20:57:33 +05:30
|
|
|
$clone.find('span.clone-url').text($this.data('link'));
|
2014-03-20 19:02:08 +05:30
|
|
|
}
|
|
|
|
}).eq(0).trigger("click");
|
|
|
|
// todo copy to clipboard
|
|
|
|
}
|
|
|
|
})();
|
2014-03-20 20:09:10 +05:30
|
|
|
|
|
|
|
// watching script
|
|
|
|
(function () {
|
|
|
|
var $watch = $('#gogs-repo-watching'),
|
|
|
|
watchLink = $watch.data("watch"),
|
|
|
|
unwatchLink = $watch.data("unwatch");
|
|
|
|
$watch.on('click', '.to-watch',function () {
|
|
|
|
if ($watch.hasClass("watching")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$.get(watchLink, function (json) {
|
|
|
|
if (json.ok) {
|
|
|
|
$watch.find('.text-primary').removeClass('text-primary');
|
|
|
|
$watch.find('.to-watch h4').addClass('text-primary');
|
|
|
|
$watch.find('.fa-eye-slash').removeClass('fa-eye-slash').addClass('fa-eye');
|
|
|
|
$watch.removeClass("no-watching").addClass("watching");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}).on('click', '.to-unwatch', function () {
|
|
|
|
if ($watch.hasClass("no-watching")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$.get(unwatchLink, function (json) {
|
|
|
|
if (json.ok) {
|
|
|
|
$watch.find('.text-primary').removeClass('text-primary');
|
|
|
|
$watch.find('.to-unwatch h4').addClass('text-primary');
|
|
|
|
$watch.find('.fa-eye').removeClass('fa-eye').addClass('fa-eye-slash');
|
|
|
|
$watch.removeClass("watching").addClass("no-watching");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
})();
|
2014-03-20 17:42:31 +05:30
|
|
|
}
|
|
|
|
|
2014-03-17 12:47:44 +05:30
|
|
|
(function ($) {
|
|
|
|
$(function () {
|
|
|
|
initCore();
|
|
|
|
var body = $("#gogs-body");
|
|
|
|
if (body.data("page") == "user-signup") {
|
|
|
|
initRegister();
|
|
|
|
}
|
|
|
|
if (body.data("page") == "user") {
|
|
|
|
initUserSetting();
|
|
|
|
}
|
2014-03-20 17:42:31 +05:30
|
|
|
if ($('.gogs-repo-nav').length) {
|
|
|
|
initRepository();
|
|
|
|
}
|
2014-03-16 20:55:01 +05:30
|
|
|
});
|
|
|
|
})(jQuery);
|